Quuxplusone / LLVMBugzillaTest

0 stars 0 forks source link

LLDB confuses multiple global variables with the same name (even when they are in different namespace) #51549

Open Quuxplusone opened 2 years ago

Quuxplusone commented 2 years ago
Bugzilla Link PR52582
Status NEW
Importance P enhancement
Reported by Vy Nguyen (vyng@google.com)
Reported on 2021-11-22 09:12:07 -0800
Last modified on 2021-11-22 09:57:24 -0800
Version unspecified
Hardware PC All
CC dblaikie@gmail.com, jdevlieghere@apple.com, llvm-bugs@lists.llvm.org, vyng@google.com
Fixed by commit(s)
Attachments
Blocks
Blocked by
See also

Background Our binary has multiple global variables with the same basename but in different namespaces. (Eg., lld::macho::symtab vs lld::elf::symtab, lld::macho::in vs lld::elf::in, ...)

Repro: Run the LLD linker under LLDB: (best to use MachO port to demonstrate this bug):

lldb -- ld64.lld.darwninnew <... rest of args>

Set a breakpoint anywhere - but for best effect, here: https://github.com/llvm/llvm-project/blob/2782cb8da0b3c180fa7c8627cb255a026f3d25a2/lld/MachO/Driver.cpp#L1141

(ie., right after symtab is set)

Try and print symtab or in.got:

(lldb) b Driver.cpp:1139
Breakpoint 1: 3 locations.
(lldb) run
Process 13244 launched: '/Users/vyng/repo/llvm-project/build_lld/bin/ld64.lld.darwinnew' (x86_64)
Process 13244 stopped
* thread #1, queue = 'com.apple.main-thread', stop reason = breakpoint 1.2
    frame #0: 0x0000000100a0856f ld64.lld.darwinnew`lld::macho::link(argsArr=ArrayRef<const char *> @ 0x00007ff7bfefeeb0, canExitEarly=true, stdoutOS=0x00000001093b83a8, stderrOS=0x00000001093b8410) at Driver.cpp:1139:12
   1136 
   1137   config = make<Configuration>();
   1138   symtab = make<SymbolTable>();
-> 1139   target = createTargetInfo(args);
   1140   depTracker =
   1141       make<DependencyTracker>(args.getLastArgValue(OPT_dependency_info));
   1142   if (errorCount())
Target 0: (ld64.lld.darwinnew) stopped.
(lldb) print symtab
(lld::elf::SymbolTable *) $0 = nullptr
(lldb) print in.got
(lld::elf::GotSection *) $1 = nullptr
(lldb) print lld::macho::in.got

Expected: Since the code that the breakpoint stopped on referred to the variable as simply symtab, I would have expected LLDB's print to allow me to also use symtab.

What actually happened: LLDB always picked the globals from lld::elf . (presumably because it's alphabetically before ::macho)


(Tested this with GDB and it didn't have this issue)