llvm-project icon indicating copy to clipboard operation
llvm-project copied to clipboard

Symbolization does not work with -pie

Open KernelAddress opened this issue 14 years ago • 9 comments

Bugzilla Link 12355
Resolution INVALID
Resolved on Sep 26, 2016 08:28
Version unspecified
OS Linux
Attachments test program source and binary
CC @labath

Extended Description

When I build the lookup example as $ clang++ main.cpp -I../../include -llldb -g -frtti It works. However when I build it as: $ clang++ main.cpp -I../../include -llldb -g -frtti -fPIE -pie It fails to symbolize itself. While objdump -dSl symbolizes it (shows line numbers inside of functions). If I build a program with gcc with -fPIE -pie, it also able to symbolize itself (with lldb). So, the problem seems to be in tricky interaction of clang, lldb and -pie. The platform is Linux/Amd64.

KernelAddress avatar Mar 26 '12 11:03 KernelAddress

The bug report is old and the test program does not compile anymore. Please refile if the problem still persists (I think it shouldn't as linux support is much better now).

labath avatar Sep 26 '16 15:09 labath

So is the test binary up to date and one that will fail the lookup with LLDB if you follow the command line instructions above? If so, can you give me an address within that binary that fails? I can take a look if you can give me one of the failing addresses.

llvmbot avatar Apr 10 '12 19:04 llvmbot

Symbols have nothing to do with debug info, they come from the object file itself. CompileUnit, Function, Block, LineTable, LineEntry objects come from debug info. So the symbol is just looking at the symbol table and finding the closest symbol, which indicates something is wrong with the symbol table as well?

Sorry, by symbols I meant functions/lines here. I had not seen any problems with symbols. Here is how our reports look with lldb:

================== WARNING: ThreadSanitizer: data race Write of size 1 at 0x7fff58cd0c41 by thread 3: #​0 0x7fb8d03c8c00: (null) tsanv2/v2/third_party/googletest/build/../include/gtest/internal/gtest-death-test-internal.h:80 #​1 0x7fb8d03b7aee: (null) tsanv2/v2/third_party/googletest/build/../include/gtest/internal/gtest-death-test-internal.h:80 #​2 0x7fb8d03ca8d5: (null) tsanv2/v2/third_party/googletest/build/../include/gtest/internal/gtest-death-test-internal.h:80 Previous Write of size 1 at 0x7fff58cd0c41 by thread 2: #​0 0x7fb8d03c8c00: (null) tsanv2/v2/third_party/googletest/build/../include/gtest/internal/gtest-death-test-internal.h:80 #​1 0x7fb8d03b7aee: (null) tsanv2/v2/third_party/googletest/build/../include/gtest/internal/gtest-death-test-internal.h:80 #​2 0x7fb8d03ca8d5: (null) tsanv2/v2/third_party/googletest/build/../include/gtest/internal/gtest-death-test-internal.h:80 Thread 3 (running) created at: #​0 0x7fb8d03cab00: (null) tsanv2/v2/third_party/googletest/build/../include/gtest/internal/gtest-death-test-internal.h:80 #​1 0x7fb8d03b8611: (null) tsanv2/v2/third_party/googletest/build/../include/gtest/internal/gtest-death-test-internal.h:80 #​2 0x7fb8d03b54b1: (null) tsanv2/v2/third_party/googletest/build/../include/gtest/internal/gtest-death-test-internal.h:80 #​3 0x7fb8cbba3c4d: (null) (null):0 Thread 2 (running) created at: #​0 0x7fb8d03cab00: (null) tsanv2/v2/third_party/googletest/build/../include/gtest/internal/gtest-death-test-internal.h:80 #​1 0x7fb8d03b8611: (null) tsanv2/v2/third_party/googletest/build/../include/gtest/internal/gtest-death-test-internal.h:80 #​2 0x7fb8d03b54b1: (null) tsanv2/v2/third_party/googletest/build/../include/gtest/internal/gtest-death-test-internal.h:80 #​3 0x7fb8cbba3c4d: (null) (null):0

And here is how they ought to look:

================== WARNING: ThreadSanitizer: data race Write of size 1 at 0x7fffffffe0d1 by thread 3: #​0 0x7ffff7f65880: memcpy tsanv2/v2/tsan_interceptors.cc:252 #​1 0x7ffff7f5476e: ScopedThread::Impl::HandleEvent(Event*) tsanv2/v2/tsan_test_util_linux.cc:293 Previous Write of size 1 at 0x7fffffffe0d1 by thread 2: #​0 0x7ffff7f65880: memcpy tsanv2/v2/tsan_interceptors.cc:252 #​1 0x7ffff7f5476e: ScopedThread::Impl::HandleEvent(Event*) tsanv2/v2/tsan_test_util_linux.cc:293 Thread 3 (running) created at: #​0 0x7ffff7f67780: pthread_create tsanv2/v2/tsan_interceptors.cc:555 #​1 0x7ffff7f55291: ScopedThread::ScopedThread(bool, bool) tsanv2/v2/tsan_test_util_linux.cc:360 #​2 0x7ffff7f52131: main tsanv2/v2/tsan_test.cc:31 Thread 2 (running) created at: #​0 0x7ffff7f67780: pthread_create tsanv2/v2/tsan_interceptors.cc:555 #​1 0x7ffff7f55291: ScopedThread::ScopedThread(bool, bool) tsanv2/v2/tsan_test_util_linux.cc:360 #​2 0x7ffff7f52131: main tsanv2/v2/tsan_test.cc:31

I agree that LLDB should NOT be saying that an address belongs to a compile unit if no function was found. I thought I fixed this with revision 153693 where I set sc. comp_unit to NULL if no function was found.

I am on revision 154315, and it seems to be not fixed, the "tsanv2/v2/third_party/googletest/build/../include/gtest/internal/gtest-death-test-internal.h:80" string comes from lldb. googletest is the library complied with gcc and the only having .debug_aranges (it is "third party" for us, so not easily fixable). You see that lldb provides exactly the same info for all addresses, address falls outside the compile unit and lldb choose the first function in it.

Humm... do I need to pass some special flags? I build as: clang++ -fPIE -g -fno-exceptions -c source.cc

No, -g should be enough. If you remove "-fPIE" does the aranges section show up?

Nope:

$ clang++ -Wall -fPIE -Werror -g -DTSAN_DEBUG=1 -Wno-attributes -c tsan_string.cc $ objdump --dwarf=aranges tsan_string.o

tsan_string.o: file format elf64-x86-64

Contents of the .debug_aranges section:

$ clang++ -Wall -Werror -g -DTSAN_DEBUG=1 -Wno-attributes -c tsan_string.cc $ objdump --dwarf=aranges tsan_string.o

tsan_string.o: file format elf64-x86-64

Contents of the .debug_aranges section:

$ g++ -Wall -fPIE -Werror -g -DTSAN_DEBUG=1 -Wno-attributes -c tsan_string.cc $ objdump --dwarf=aranges tsan_string.o

tsan_string.o: file format elf64-x86-64

Contents of the .debug_aranges section:

Length: 1628 Version: 2 Offset into .debug_info: 0x0 Pointer Size: 8 Segment Size: 0

Address            Length
0000000000000000 0000000000001f74 
0000000000000000 0000000000000024 
0000000000000000 0000000000000014 
0000000000000000 000000000000000c 

...

KernelAddress avatar Apr 10 '12 09:04 KernelAddress

Symbols have nothing to do with debug info, they come from the object file itself. CompileUnit, Function, Block, LineTable, LineEntry objects come from debug info. So the symbol is just looking at the symbol table and finding the closest symbol, which indicates something is wrong with the symbol table as well?

I agree that LLDB should NOT be saying that an address belongs to a compile unit if no function was found. I thought I fixed this with revision 153693 where I set sc. comp_unit to NULL if no function was found.

Humm... do I need to pass some special flags? I build as: clang++ -fPIE -g -fno-exceptions -c source.cc

No, -g should be enough. If you remove "-fPIE" does the aranges section show up?

llvmbot avatar Apr 09 '12 20:04 llvmbot

---------- Forwarded message ---------- From: Dmitry Vyukov [email protected] Date: Mon, Apr 9, 2012 at 10:19 PM Subject: Re: [Bug 12355] Symbolization does not work with -pie To: [email protected]

On Mon, Apr 9, 2012 at 10:08 PM, [email protected] wrote:

http://llvm.org/bugs/show_bug.cgi?id=12355

--- Comment #​5 from Greg Clayton [email protected] 2012-04-09 13:08:40 CDT --- The downsides are debugging performance when looking up an address for a PC (like an address for a frame). If you don't have reliable accelerator tables, then you have to generate them by looking through the DWARF manually which happens will call DWARFCompileUnit::Index() for all compile units. This is a very slow function that we always try and avoid using. We could modify the DWARF parser to check if there are any arranges entries for a compile unit, and if there aren't, then do the manual index (call DWARFCompileUnit::Index()).

Sounds good. I think you may parse compile units iff the address is not found in the .debug_aranges table. This is actually happens in my case, the symbol that lldb gives me is the first (or the last) symbol from the compile unit that has .debug_aranges, and the address clearly falls outside of the compile unit, but lldb silently ignores this fact and still thinks that the address belongs to the compile unit. In either case this situation is better handled gracefully, that is, say that the address is not resolved rather than saying that is the first/last symbol in an arbitrary compilation unit.

This is also a problem on systems where the linkers don't understand DWARF and link it intelligently. On MacOSX, we have a smart DWARF linker that doesn't rely upon the accelerator tables in the .o files, it regenerates them as it links the DWARF.

Are you symbolicating code that was already built and have build servers that contain these mixed .o files?

Our Makefile builds some libraries with gcc, because clang fails to compile them.  

The clang I have does generate the .debug_aranges, so this might be a clang bug.

Humm... do I need to pass some special flags? I build as: clang++ -fPIE -g -fno-exceptions -c source.cc

KernelAddress avatar Apr 09 '12 20:04 KernelAddress

The downsides are debugging performance when looking up an address for a PC (like an address for a frame). If you don't have reliable accelerator tables, then you have to generate them by looking through the DWARF manually which happens will call DWARFCompileUnit::Index() for all compile units. This is a very slow function that we always try and avoid using. We could modify the DWARF parser to check if there are any arranges entries for a compile unit, and if there aren't, then do the manual index (call DWARFCompileUnit::Index()).

This is also a problem on systems where the linkers don't understand DWARF and link it intelligently. On MacOSX, we have a smart DWARF linker that doesn't rely upon the accelerator tables in the .o files, it regenerates them as it links the DWARF.

Are you symbolicating code that was already built and have build servers that contain these mixed .o files?

The clang I have does generate the .debug_aranges, so this might be a clang bug.

llvmbot avatar Apr 09 '12 20:04 llvmbot

Hi Greg,

Sorry for the delay. The reason why it was not working for us is actually quite hairy. The problem was with the .debug_aranges DWARF section and was not related to -pie flag. Clang seems to not emit the .debug_aranges at all. However we have several object files built with gcc, and it does emit the section. So the resulting binary has the section with info for several uninteresting third_party object files only. DWARFDebugInfo::GetCompileUnitAranges() first checks presence of the sections, and if it's present then uses it, otherwise parses compile units. So the binary it uses the .debug_aranges section, but fails to find there relevant info. I've tried 2 things. (1) build everything with clang and (2) comment out part of DWARFDebugInfo::GetCompileUnitAranges() that uses .debug_aranges. In both cases the symbolization works. I think mixed compilation may be quite frequent in real-life, for example everything is built with clang but some third_party library comes compiled with gcc (in our case clang just fails to compile to library and so we use gcc). So what do you think? What are downsides of using only compile units information and not using .debug_aranges at all?

KernelAddress avatar Apr 09 '12 18:04 KernelAddress

Hi Greg,

I've tried to build fresh lldb at several revisions, but I always hit some compilation errors. Is there some stable revision that includes this changes (and preferably the changes related to thread-local sections)?

KernelAddress avatar Mar 28 '12 06:03 KernelAddress

I made a few fixes for the ELF symbol file reader where we now recognize mangled names and the symbols will now show up correctly demangled. I also fixed a few issues with the DWARF parser where we weren't using the dwarf section file size (we were using the vm size). I also fixed the sections that are registered to not have a VM size if they won't ever be loaded by the program. This means we won't end up with overlapping sections. The current LLDB was incorrectly giving the ".comment", all ".debug", and the ".shstrtab", ".symtab" and ".strtab" sections valid addresses that would be resolved when the shared library was loaded. To see this we can see the section list for a.out:

% lldb a.out Current executable set to 'a.out' (x86_64). (lldb) image dump sections Dumping sections for 1 modules. Sections for '/private/tmp/lookup/a.out' (x86_64): SectID Type File Address File Off. File Size Flags Section Name


0x00000001 regular 0x00000000 0x00000000 0x00000000 a.out. 0x00000002 regular [0x0000000000000238-0x0000000000000254) 0x00000238 0x0000001c 0x00000002 a.out..interp 0x00000003 regular [0x0000000000000254-0x0000000000000274) 0x00000254 0x00000020 0x00000002 a.out..note.ABI-tag 0x00000004 regular [0x0000000000000274-0x0000000000000298) 0x00000274 0x00000024 0x00000002 a.out..note.gnu.build-id 0x00000005 regular [0x0000000000000298-0x0000000000000528) 0x00000298 0x00000290 0x00000002 a.out..hash 0x00000006 regular [0x0000000000000528-0x0000000000000584) 0x00000528 0x0000005c 0x00000002 a.out..gnu.hash 0x00000007 regular [0x0000000000000588-0x0000000000000e70) 0x00000588 0x000008e8 0x00000002 a.out..dynsym 0x00000008 regular [0x0000000000000e70-0x0000000000001973) 0x00000e70 0x00000b03 0x00000002 a.out..dynstr 0x00000009 regular [0x0000000000001974-0x0000000000001a32) 0x00001974 0x000000be 0x00000002 a.out..gnu.version 0x0000000a regular [0x0000000000001a38-0x0000000000001ac8) 0x00001a38 0x00000090 0x00000002 a.out..gnu.version_r 0x0000000b regular [0x0000000000001ac8-0x0000000000001e70) 0x00001ac8 0x000003a8 0x00000002 a.out..rela.dyn 0x0000000c regular [0x0000000000001e70-0x0000000000002578) 0x00001e70 0x00000708 0x00000002 a.out..rela.plt 0x0000000d regular [0x0000000000002578-0x0000000000002590) 0x00002578 0x00000018 0x00000006 a.out..init 0x0000000e regular [0x0000000000002590-0x0000000000002a50) 0x00002590 0x000004c0 0x00000006 a.out..plt 0x0000000f code [0x0000000000002a50-0x0000000000004988) 0x00002a50 0x00001f38 0x00000006 a.out..text 0x00000010 regular [0x0000000000004988-0x0000000000004996) 0x00004988 0x0000000e 0x00000006 a.out..fini 0x00000011 regular [0x00000000000049a0-0x0000000000004b34) 0x000049a0 0x00000194 0x00000002 a.out..rodata 0x00000012 regular [0x0000000000004b34-0x0000000000004ca8) 0x00004b34 0x00000174 0x00000002 a.out..eh_frame_hdr 0x00000013 eh-frame [0x0000000000004ca8-0x0000000000005244) 0x00004ca8 0x0000059c 0x00000002 a.out..eh_frame 0x00000014 regular [0x0000000000005244-0x00000000000058e0) 0x00005244 0x0000069c 0x00000002 a.out..gcc_except_table 0x00000015 regular [0x0000000000205c48-0x0000000000205c58) 0x00005c48 0x00000010 0x00000003 a.out..ctors 0x00000016 regular [0x0000000000205c58-0x0000000000205c68) 0x00005c58 0x00000010 0x00000003 a.out..dtors 0x00000017 regular [0x0000000000205c68-0x0000000000205c70) 0x00005c68 0x00000008 0x00000003 a.out..jcr 0x00000018 regular [0x0000000000205c70-0x0000000000205d88) 0x00005c70 0x00000118 0x00000003 a.out..data.rel.ro 0x00000019 regular [0x0000000000205d88-0x0000000000205f88) 0x00005d88 0x00000200 0x00000003 a.out..dynamic 0x0000001a regular [0x0000000000205f88-0x0000000000205fe0) 0x00005f88 0x00000058 0x00000003 a.out..got 0x0000001b regular [0x0000000000205fe8-0x0000000000206258) 0x00005fe8 0x00000270 0x00000003 a.out..got.plt 0x0000001c data [0x0000000000206258-0x0000000000206270) 0x00006258 0x00000018 0x00000003 a.out..data 0x0000001d zero-fill [0x0000000000206270-0x0000000000207280) 0x00006270 0x00000000 0x00000003 a.out..bss 0x0000001e regular [0x0000000000000000-0x0000000000000048) 0x00006270 0x00000048 0x00000030 a.out..comment 0x0000001f dwarf-info [0x0000000000000000-0x000000000000dd7b) 0x000062b8 0x0000dd7b 0x00000000 a.out..debug_info 0x00000020 dwarf-abbrev [0x0000000000000000-0x0000000000000502) 0x00014033 0x00000502 0x00000000 a.out..debug_abbrev 0x00000021 dwarf-line [0x0000000000000000-0x0000000000000c33) 0x00014535 0x00000c33 0x00000000 a.out..debug_line 0x00000022 dwarf-str [0x0000000000000000-0x0000000000013d9f) 0x00015168 0x00013d9f 0x00000030 a.out..debug_str 0x00000023 dwarf-pubtypes [0x0000000000000000-0x0000000000000ba1) 0x00028f07 0x00000ba1 0x00000000 a.out..debug_pubtypes 0x00000024 dwarf-ranges [0x0000000000000000-0x00000000000000f0) 0x00029aa8 0x000000f0 0x00000000 a.out..debug_ranges 0x00000025 regular [0x0000000000000000-0x000000000000016c) 0x00029b98 0x0000016c 0x00000000 a.out..shstrtab 0x00000026 regular [0x0000000000000000-0x0000000000001410) 0x0002a6c8 0x00001410 0x00000000 a.out..symtab 0x00000027 regular [0x0000000000000000-0x0000000000001b0c) 0x0002bad8 0x00001b0c 0x00000000 a.out..strtab

After the my recent checking, we correctly disallow any sections that don't have the SHF_ALLOC bit set if the flags from having a valid VM address. Now the sections look like:

lldb a.out Current executable set to 'a.out' (x86_64). (lldb) image dump sections Dumping sections for 1 modules. Sections for '/private/tmp/lookup/a.out' (x86_64): SectID Type File Address File Off. File Size Flags Section Name


0x00000001 regular 0x00000000 0x00000000 0x00000000 a.out. 0x00000002 regular [0x0000000000000238-0x0000000000000254) 0x00000238 0x0000001c 0x00000002 a.out..interp 0x00000003 regular [0x0000000000000254-0x0000000000000274) 0x00000254 0x00000020 0x00000002 a.out..note.ABI-tag 0x00000004 regular [0x0000000000000274-0x0000000000000298) 0x00000274 0x00000024 0x00000002 a.out..note.gnu.build-id 0x00000005 regular [0x0000000000000298-0x0000000000000528) 0x00000298 0x00000290 0x00000002 a.out..hash 0x00000006 regular [0x0000000000000528-0x0000000000000584) 0x00000528 0x0000005c 0x00000002 a.out..gnu.hash 0x00000007 regular [0x0000000000000588-0x0000000000000e70) 0x00000588 0x000008e8 0x00000002 a.out..dynsym 0x00000008 regular [0x0000000000000e70-0x0000000000001973) 0x00000e70 0x00000b03 0x00000002 a.out..dynstr 0x00000009 regular [0x0000000000001974-0x0000000000001a32) 0x00001974 0x000000be 0x00000002 a.out..gnu.version 0x0000000a regular [0x0000000000001a38-0x0000000000001ac8) 0x00001a38 0x00000090 0x00000002 a.out..gnu.version_r 0x0000000b regular [0x0000000000001ac8-0x0000000000001e70) 0x00001ac8 0x000003a8 0x00000002 a.out..rela.dyn 0x0000000c regular [0x0000000000001e70-0x0000000000002578) 0x00001e70 0x00000708 0x00000002 a.out..rela.plt 0x0000000d regular [0x0000000000002578-0x0000000000002590) 0x00002578 0x00000018 0x00000006 a.out..init 0x0000000e regular [0x0000000000002590-0x0000000000002a50) 0x00002590 0x000004c0 0x00000006 a.out..plt 0x0000000f code [0x0000000000002a50-0x0000000000004988) 0x00002a50 0x00001f38 0x00000006 a.out..text 0x00000010 regular [0x0000000000004988-0x0000000000004996) 0x00004988 0x0000000e 0x00000006 a.out..fini 0x00000011 regular [0x00000000000049a0-0x0000000000004b34) 0x000049a0 0x00000194 0x00000002 a.out..rodata 0x00000012 regular [0x0000000000004b34-0x0000000000004ca8) 0x00004b34 0x00000174 0x00000002 a.out..eh_frame_hdr 0x00000013 eh-frame [0x0000000000004ca8-0x0000000000005244) 0x00004ca8 0x0000059c 0x00000002 a.out..eh_frame 0x00000014 regular [0x0000000000005244-0x00000000000058e0) 0x00005244 0x0000069c 0x00000002 a.out..gcc_except_table 0x00000015 regular [0x0000000000205c48-0x0000000000205c58) 0x00005c48 0x00000010 0x00000003 a.out..ctors 0x00000016 regular [0x0000000000205c58-0x0000000000205c68) 0x00005c58 0x00000010 0x00000003 a.out..dtors 0x00000017 regular [0x0000000000205c68-0x0000000000205c70) 0x00005c68 0x00000008 0x00000003 a.out..jcr 0x00000018 regular [0x0000000000205c70-0x0000000000205d88) 0x00005c70 0x00000118 0x00000003 a.out..data.rel.ro 0x00000019 regular [0x0000000000205d88-0x0000000000205f88) 0x00005d88 0x00000200 0x00000003 a.out..dynamic 0x0000001a regular [0x0000000000205f88-0x0000000000205fe0) 0x00005f88 0x00000058 0x00000003 a.out..got 0x0000001b regular [0x0000000000205fe8-0x0000000000206258) 0x00005fe8 0x00000270 0x00000003 a.out..got.plt 0x0000001c data [0x0000000000206258-0x0000000000206270) 0x00006258 0x00000018 0x00000003 a.out..data 0x0000001d zero-fill [0x0000000000206270-0x0000000000207280) 0x00006270 0x00000000 0x00000003 a.out..bss 0x0000001e regular 0x00006270 0x00000048 0x00000030 a.out..comment 0x0000001f dwarf-info 0x000062b8 0x0000dd7b 0x00000000 a.out..debug_info 0x00000020 dwarf-abbrev 0x00014033 0x00000502 0x00000000 a.out..debug_abbrev 0x00000021 dwarf-line 0x00014535 0x00000c33 0x00000000 a.out..debug_line 0x00000022 dwarf-str 0x00015168 0x00013d9f 0x00000030 a.out..debug_str 0x00000023 dwarf-pubtypes 0x00028f07 0x00000ba1 0x00000000 a.out..debug_pubtypes 0x00000024 dwarf-ranges 0x00029aa8 0x000000f0 0x00000000 a.out..debug_ranges 0x00000025 regular 0x00029b98 0x0000016c 0x00000000 a.out..shstrtab 0x00000026 regular 0x0002a6c8 0x00001410 0x00000000 a.out..symtab 0x00000027 regular 0x0002bad8 0x00001b0c 0x00000000 a.out..strtab

Note from the ".comment" section on down, they no longer show file addresses.

Now we can try some symbolication with LLDB on the binary:

% lldb a.out Current executable set to 'a.out' (x86_64). (lldb) target modules lo Available completions: load lookup (lldb) image lookup -va 0x0000000000002d90 Address: a.out[0x0000000000002d90] (a.out..text + 832) Summary: a.out`main + 32 at main.cpp:176 Module: file = "/private/tmp/lookup/a.out", arch = "x86_64" CompileUnit: id = {0x00000000}, file = "/usr/local/google/home/dvyukov/llvm/tools/lldb/examples/lookup/main.cpp", language = "ISO C++:1998" Function: id = {0x000018c2}, name = "main", range = [0x0000000000002d70-0x000000000000332c) FuncType: id = {0x000018c2}, decl = main.cpp:155, clang_type = "int (int, const char **)" Blocks: id = {0x000018c2}, range = [0x00002d70-0x0000332c) id = {0x000018fc}, ranges = [0x00002d90-0x000032e8)[0x000032f4-0x0000332c) LineEntry: [0x0000000000002d90-0x0000000000002de6): /usr/local/google/home/dvyukov/llvm/tools/lldb/examples/lookup/main.cpp:176:68 Symbol: uid={ 167}, range = [0x0000000000002d70-0x000000000000332c), name="main" Variable: id = {0x00001901}, name = "ls", type= "StreamSP", location = DW_OP_fbreg(-80), decl = main.cpp:176 Variable: id = {0x00001910}, name = "la", type= "const char *", location = DW_OP_fbreg(-104), decl = main.cpp:177 Variable: id = {0x0000191f}, name = "log", type= "LogSP", location = DW_OP_fbreg(-120), decl = main.cpp:178 Variable: id = {0x0000192e}, name = "exe_file_path", type= "const char *", location = DW_OP_fbreg(-128), decl = main.cpp:185 Variable: id = {0x0000193d}, name = "file_addr", type= "addr_t", location = DW_OP_fbreg(-136), decl = main.cpp:187 Variable: id = {0x0000194c}, name = "debugger", type= "SBDebugger", location = DW_OP_fbreg(-168), decl = main.cpp:193 Variable: id = {0x000018e0}, name = "argc", type= "int", location = DW_OP_fbreg(-56), decl = main.cpp:154 Variable: id = {0x000018ee}, name = "argv", type= "const char **", location = DW_OP_fbreg(-64), decl = main.cpp:154

Not this lookup succeeded before we set the load address. In your main.cpp that is attached to the bug, you then slide all of the sections by a given address using:

  target.SetModuleLoadAddress(module, (lldb::addr_t)info->dlpi_addr);

I can simulate sliding the entire image by 0x1000 by using the "target modules load --slide " command:

(lldb) target modules load --file a.out --slide 0x1000

Now if we dump the sections we see them at their "load" address:

(lldb) image dump sections Dumping sections for 1 modules. Sections for '/private/tmp/lookup/a.out' (x86_64): SectID Type Load Address File Off. File Size Flags Section Name


0x00000001 regular 0x00000000 0x00000000 0x00000000 a.out. 0x00000002 regular [0x0000000000001238-0x0000000000001254) 0x00000238 0x0000001c 0x00000002 a.out..interp 0x00000003 regular [0x0000000000001254-0x0000000000001274) 0x00000254 0x00000020 0x00000002 a.out..note.ABI-tag 0x00000004 regular [0x0000000000001274-0x0000000000001298) 0x00000274 0x00000024 0x00000002 a.out..note.gnu.build-id 0x00000005 regular [0x0000000000001298-0x0000000000001528) 0x00000298 0x00000290 0x00000002 a.out..hash 0x00000006 regular [0x0000000000001528-0x0000000000001584) 0x00000528 0x0000005c 0x00000002 a.out..gnu.hash 0x00000007 regular [0x0000000000001588-0x0000000000001e70) 0x00000588 0x000008e8 0x00000002 a.out..dynsym 0x00000008 regular [0x0000000000001e70-0x0000000000002973) 0x00000e70 0x00000b03 0x00000002 a.out..dynstr 0x00000009 regular [0x0000000000002974-0x0000000000002a32) 0x00001974 0x000000be 0x00000002 a.out..gnu.version 0x0000000a regular [0x0000000000002a38-0x0000000000002ac8) 0x00001a38 0x00000090 0x00000002 a.out..gnu.version_r 0x0000000b regular [0x0000000000002ac8-0x0000000000002e70) 0x00001ac8 0x000003a8 0x00000002 a.out..rela.dyn 0x0000000c regular [0x0000000000002e70-0x0000000000003578) 0x00001e70 0x00000708 0x00000002 a.out..rela.plt 0x0000000d regular [0x0000000000003578-0x0000000000003590) 0x00002578 0x00000018 0x00000006 a.out..init 0x0000000e regular [0x0000000000003590-0x0000000000003a50) 0x00002590 0x000004c0 0x00000006 a.out..plt 0x0000000f code [0x0000000000003a50-0x0000000000005988) 0x00002a50 0x00001f38 0x00000006 a.out..text 0x00000010 regular [0x0000000000005988-0x0000000000005996) 0x00004988 0x0000000e 0x00000006 a.out..fini 0x00000011 regular [0x00000000000059a0-0x0000000000005b34) 0x000049a0 0x00000194 0x00000002 a.out..rodata 0x00000012 regular [0x0000000000005b34-0x0000000000005ca8) 0x00004b34 0x00000174 0x00000002 a.out..eh_frame_hdr 0x00000013 eh-frame [0x0000000000005ca8-0x0000000000006244) 0x00004ca8 0x0000059c 0x00000002 a.out..eh_frame 0x00000014 regular [0x0000000000006244-0x00000000000068e0) 0x00005244 0x0000069c 0x00000002 a.out..gcc_except_table 0x00000015 regular [0x0000000000206c48-0x0000000000206c58) 0x00005c48 0x00000010 0x00000003 a.out..ctors 0x00000016 regular [0x0000000000206c58-0x0000000000206c68) 0x00005c58 0x00000010 0x00000003 a.out..dtors 0x00000017 regular [0x0000000000206c68-0x0000000000206c70) 0x00005c68 0x00000008 0x00000003 a.out..jcr 0x00000018 regular [0x0000000000206c70-0x0000000000206d88) 0x00005c70 0x00000118 0x00000003 a.out..data.rel.ro 0x00000019 regular [0x0000000000206d88-0x0000000000206f88) 0x00005d88 0x00000200 0x00000003 a.out..dynamic 0x0000001a regular [0x0000000000206f88-0x0000000000206fe0) 0x00005f88 0x00000058 0x00000003 a.out..got 0x0000001b regular [0x0000000000206fe8-0x0000000000207258) 0x00005fe8 0x00000270 0x00000003 a.out..got.plt 0x0000001c data [0x0000000000207258-0x0000000000207270) 0x00006258 0x00000018 0x00000003 a.out..data 0x0000001d zero-fill [0x0000000000207270-0x0000000000208280) 0x00006270 0x00000000 0x00000003 a.out..bss 0x0000001e regular 0x00006270 0x00000048 0x00000030 a.out..comment 0x0000001f dwarf-info 0x000062b8 0x0000dd7b 0x00000000 a.out..debug_info 0x00000020 dwarf-abbrev 0x00014033 0x00000502 0x00000000 a.out..debug_abbrev 0x00000021 dwarf-line 0x00014535 0x00000c33 0x00000000 a.out..debug_line 0x00000022 dwarf-str 0x00015168 0x00013d9f 0x00000030 a.out..debug_str 0x00000023 dwarf-pubtypes 0x00028f07 0x00000ba1 0x00000000 a.out..debug_pubtypes 0x00000024 dwarf-ranges 0x00029aa8 0x000000f0 0x00000000 a.out..debug_ranges 0x00000025 regular 0x00029b98 0x0000016c 0x00000000 a.out..shstrtab 0x00000026 regular 0x0002a6c8 0x00001410 0x00000000 a.out..symtab 0x00000027 regular 0x0002bad8 0x00001b0c 0x00000000 a.out..strtab

And if we lookup an address in main again, we see the correct results:

(lldb) image lookup -va 0x0000000000003d90 Address: a.out[0x0000000000002d90] (a.out..text + 832) Summary: a.out`main + 32 at main.cpp:176 Module: file = "/private/tmp/lookup/a.out", arch = "x86_64" CompileUnit: id = {0x00000000}, file = "/usr/local/google/home/dvyukov/llvm/tools/lldb/examples/lookup/main.cpp", language = "ISO C++:1998" Function: id = {0x000018c2}, name = "main", range = [0x0000000000003d70-0x000000000000432c) FuncType: id = {0x000018c2}, decl = main.cpp:155, clang_type = "int (int, const char **)" Blocks: id = {0x000018c2}, range = [0x00003d70-0x0000432c) id = {0x000018fc}, ranges = [0x00003d90-0x000042e8)[0x000042f4-0x0000432c) LineEntry: [0x0000000000003d90-0x0000000000003de6): /usr/local/google/home/dvyukov/llvm/tools/lldb/examples/lookup/main.cpp:176:68 Symbol: uid={ 167}, range = [0x0000000000003d70-0x000000000000432c), name="main" Variable: id = {0x00001901}, name = "ls", type= "StreamSP", location = DW_OP_fbreg(-80), decl = main.cpp:176 Variable: id = {0x00001910}, name = "la", type= "const char *", location = DW_OP_fbreg(-104), decl = main.cpp:177 Variable: id = {0x0000191f}, name = "log", type= "LogSP", location = DW_OP_fbreg(-120), decl = main.cpp:178 Variable: id = {0x0000192e}, name = "exe_file_path", type= "const char *", location = DW_OP_fbreg(-128), decl = main.cpp:185 Variable: id = {0x0000193d}, name = "file_addr", type= "addr_t", location = DW_OP_fbreg(-136), decl = main.cpp:187 Variable: id = {0x0000194c}, name = "debugger", type= "SBDebugger", location = DW_OP_fbreg(-168), decl = main.cpp:193 Variable: id = {0x000018e0}, name = "argc", type= "int", location = DW_OP_fbreg(-56), decl = main.cpp:154 Variable: id = {0x000018ee}, name = "argv", type= "const char **", location = DW_OP_fbreg(-64), decl = main.cpp:154

Dmitry: are you seeing an address not work correctly when you look it up? If you can print out the address you are using to load your PIE executable by uncommenting:

//printf("LOADING '%s' at %p\n", info->dlpi_name, (void*)info->dlpi_addr);

And send me the addresses that you then are looking up, I might be able to help, but from what I see this is working as expected (after my fixes):

% svn commit Sending source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp Sending source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp Sending source/Symbol/ObjectFile.cpp Transmitting file data ... Committed revision 153496.

Let me know if this now works for you?

llvmbot avatar Mar 27 '12 04:03 llvmbot