gimli-rs / gimli

A library for reading and writing the DWARF debugging format
https://docs.rs/gimli/
Apache License 2.0
831 stars 105 forks source link

Gimli cannot parse multiple units in aarch64 #689

Closed liutao-liu closed 8 months ago

liutao-liu commented 8 months ago

As shown in the following figure, when there are multiple units, Gimli parses only the first unit from the ELF file. image

philipc commented 8 months ago

gimli definitely can parse multiple units, so you'll need to give more information on how to reproduce the problem you are seeing.

philipc commented 8 months ago

Can you provide an example file?

liutao-liu commented 8 months ago

My running environment: aarch64 + ubuntu 20.04 TSL Gimli version:0.28.1

The example in simple_line.rs attempt to parse all units in an object file. Then i run the example in simple_line.rs to parse my object. This object has two units, but simple_line.rs can only parse the first unit, as shown in the following figure.

image

My a.out comes out like this: test1.c

int func(){
    return 10;
}

test2.c

int main(int argc, char** argv)
{
  int ret = 1;
  return ret;
}

Compiling test1.c and test2.c using clang-16:

./clang+llvm-16.0.0-aarch64-linux-gnu/bin/clang -c -gdwarf-4 -emit-llvm test1.c -S -o test1.ll
./clang+llvm-16.0.0-aarch64-linux-gnu/bin/clang -c -gdwarf-4 -emit-llvm test2.c -S -o test2.ll
./clang+llvm-16.0.0-aarch64-linux-gnu/bin/llvm-link -o test.ll test1.ll test2.ll
./clang+llvm-16.0.0-aarch64-linux-gnu/bin/clang test.ll -c -o a.out
philipc commented 8 months ago

Please attach the binary a.out so that I can reproduce the issue.

liutao-liu commented 8 months ago

Sorry, I can't offer a.out. The example I've given is simple, and you can compile it very quickly by following the steps above. The problem can also be reproduced in the x86 environment.

philipc commented 8 months ago

It's simple to add the file to this issue, but okay, I'll have to wait until next week to look at it then.

liutao-liu commented 8 months ago

It's simple to add the file to this issue, but okay, I'll have to wait until next week to look at it then.

I don't have permission to upload files.

philipc commented 8 months ago

The problem is that you are building a relocatable object file, and the simple_line example does not process relocations, so various references in the DWARF are read as zeroes. If you build an executable then it works fine: clang test.ll -o a.out Alternatively, the dwarfdump example does process relocations.