This is an archive of the discontinued LLVM Phabricator instance.

[lld-macho] Don't attempt to emit rebase opcodes for debug sections
ClosedPublic

Authored by int3 on Dec 8 2020, 6:35 PM.

Details

Summary

This was causing a crash as we were attempting to look up the
nonexistent parent OutputSection of the debug sections. We didn't detect
it earlier because there was no test for PIEs with debug info (PIEs
require us to emit rebases for X86_64_RELOC_UNSIGNED).

This diff filters out the debug sections while loading the ObjFiles. In
addition to fixing the above problem, it also lets us avoid doing
redundant work -- we no longer parse / apply relocations / attempt to
emit dyld opcodes for these sections that we don't emit.

Fixes llvm.org/PR48392.

Diff Detail

Event Timeline

int3 created this revision.Dec 8 2020, 6:35 PM
int3 requested review of this revision.Dec 8 2020, 6:35 PM
Herald added a project: Restricted Project. · View Herald TranscriptDec 8 2020, 6:35 PM
thakis accepted this revision.Dec 9 2020, 6:31 AM

This looks like a much nicer design, thanks!

lld/MachO/Dwarf.cpp
24

I would find a comment here helpful why these are the isDebugSection sections that get a DwarfObject. It's not obvious to me why __debug_line and __debug_ranges aren't listed here (or why we do any filtering at all). I don't know much debug information and I can believe that it's obvious to domain experts :)

lld/test/MachO/stabs.s
141

Does this have "interesting enough" debug info? The .o file rom comment 8 in http://llvm.org/pr48392 :

$ out/gn/bin/llvm-objdump -h test.o | grep debug
  4 __debug_abbrev   000000ae 0000000000000078 DATA
  5 __debug_info     00000108 0000000000000126 DATA
  6 __debug_ranges   00000040 000000000000022e DATA
  7 __debug_str      0000009c 000000000000026e DATA
 13 __debug_line     00000066 0000000000000540 DATA

This file:

$ out/gn/bin/llvm-objdump -h out/gn/obj/lld/test/MachO/Output/stabs.s.tmp/foo.o | grep debug
  1 __debug_str    00000009 0000000000000001 DATA
  2 __debug_abbrev 0000000c 000000000000000a DATA
  3 __debug_info   00000021 0000000000000016 DATA
  4 __debug_line   00000000 0000000000000037 DATA

(ie no __debug_ranges)

This revision is now accepted and ready to land.Dec 9 2020, 6:31 AM
thakis added a comment.Dec 9 2020, 6:33 AM

(ps: I think "Fixes PR48392" is slightly more common than "Fixes bug 48392", because with the former you can double-click that, ctrl-c, browser tab, llvm.org/<ctrl-v> to open that bug, while you have to manually type the "PR" bit. Hmm, thinking this through, I suppose "Fixes llvm.org/PR48392" would be even more convenient, but I haven't' seen that being used :) )

tschuett added inline comments.
lld/MachO/Dwarf.cpp
24

llvm does not provide a isDwarfSection function?

I used -glldb. Does -ggdb create different sections?

int3 added a subscriber: clayborg.Dec 9 2020, 2:45 PM

I think "Fixes PR48392" is slightly more common

TIL about PR shortlinks. Thanks!

I used -glldb. Does -ggdb create different sections?

It appears to omit a bunch of __apple_* sections, but __debug_ranges is present. But I as mentioned in the other comments, I don't think that section is critical to reproducing this bug.

lld/MachO/Dwarf.cpp
24

I'm not a domain expert on debug info either, so maybe @clayborg can help fill in some details / correct any misconceptions :)

It's not obvious to me why debug_line and debug_ranges aren't listed here (or why we do any filtering at all)

We filter out the debug sections because the debugger can locate the debug info via the STABS symbols that point to the corresponding source & object files. So all lld needs from the debug info is the source file path. Thus, I initialized the DwarfObject with just the sections that were required to obtain this info. __debug_line and __debug_ranges are presumably used by LLDB.

llvm does not provide a isDwarfSection function?

Nope, or at least I haven't seen any that fits this use case.

lld/test/MachO/stabs.s
141

I don't think the presence of __debug_ranges is important to reproducing this bug. The important thing is the presence of X86_64_RELOC_UNSIGNED relocations that target debug sections, which are indeed generated by this test input.

int3 updated this revision to Diff 310682.Dec 9 2020, 3:21 PM
int3 edited the summary of this revision. (Show Details)

add comment

thakis accepted this revision.Dec 10 2020, 5:59 AM

Great comment, thanks!

This revision was landed with ongoing or failed builds.Dec 10 2020, 3:58 PM
This revision was automatically updated to reflect the committed changes.