[PATCH] D89257: [lld-macho] Emit STABS symbols for debugging, and drop debug sections

Jez Ng via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Oct 12 11:28:59 PDT 2020


int3 created this revision.
int3 added reviewers: lld-macho, clayborg.
Herald added subscribers: llvm-commits, mgorny.
Herald added a reviewer: JDevlieghere.
Herald added a project: LLVM.
int3 requested review of this revision.
Herald added a reviewer: jdoerfert.
Herald added subscribers: sstefan1, ormris.

Debug sections contain a large amount of data. In order not to bloat the size
of the final binary, we remove them and instead emit STABS symbols for
`dsymutil` and the debugger to locate their contents in the object files.

With this diff, `dsymutil` is able to locate the debug info. However, we need
a few more features before `lldb` is able to work well with our binaries --
e.g. having `LC_DYSYMTAB` accurately reflect the number of local symbols,
emitting `LC_UUID`, and more. Those will be handled in follow-up diffs.

Note also that the STABS we emit differ slightly from what ld64 does. First, we
emit the path to the source file as one `N_SO` symbol instead of two. (`ld64`
emits one `N_SO` for the dirname and one of the basename.) Second, we do not
emit `N_BNSYM` and `N_ENSYM` STABS to mark the start and end of functions,
because the `N_FUN` STABS already serve that purpose. @clayborg recommended
these changes based on his knowledge of what the debugging tools look for.

Additionally, this current implementation doesn't accurately reflect the size
of function symbols. It uses the size of their containing sectioins as a proxy,
but that is only accurate if `.subsections_with_symbols` is set, and if there
isn't an `N_ALT_ENTRY` in that particular subsection. I think we have two
options to solve this:

1. We can split up subsections by symbol even if `.subsections_with_symbols` is not set, but include constraints to ensure those subsections retain their order in the final output. This is `ld64`'s approach.
2. We could just add a `size` field to our `Symbol` class. This seems simpler, and I'm more inclined toward it, but I'm not sure if there are use cases that it doesn't handle well. As such I'm punting on the decision for now.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D89257

Files:
  lld/MachO/CMakeLists.txt
  lld/MachO/Dwarf.cpp
  lld/MachO/Dwarf.h
  lld/MachO/InputFiles.cpp
  lld/MachO/InputFiles.h
  lld/MachO/InputSection.h
  lld/MachO/OutputSegment.h
  lld/MachO/SyntheticSections.cpp
  lld/MachO/SyntheticSections.h
  lld/MachO/Writer.cpp
  lld/test/MachO/stabs.s

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D89257.297649.patch
Type: text/x-patch
Size: 18776 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20201012/69362945/attachment.bin>


More information about the llvm-commits mailing list