[all-commits] [llvm/llvm-project] 3587de: [lld-macho] Support __dso_handle for C++

Jez Ng via All-commits all-commits at lists.llvm.org
Thu Jul 30 14:30:44 PDT 2020


  Branch: refs/heads/master
  Home:   https://github.com/llvm/llvm-project
  Commit: 3587de22819869a2925994d8bd75fa1386464660
      https://github.com/llvm/llvm-project/commit/3587de22819869a2925994d8bd75fa1386464660
  Author: Jez Ng <jezng at fb.com>
  Date:   2020-07-30 (Thu, 30 Jul 2020)

  Changed paths:
    M lld/MachO/Driver.cpp
    M lld/MachO/SymbolTable.cpp
    M lld/MachO/SymbolTable.h
    M lld/MachO/Symbols.cpp
    M lld/MachO/Symbols.h
    M lld/MachO/SyntheticSections.h
    M lld/MachO/Writer.cpp
    A lld/test/MachO/dso-handle.s
    A lld/test/MachO/invalid/dso-handle-duplicate.s

  Log Message:
  -----------
  [lld-macho] Support __dso_handle for C++

The C++ ABI requires dylibs to pass a pointer to __cxa_atexit which does
e.g. cleanup of static global variables. The C++ spec says that the pointer
can point to any address in one of the dylib's segments, but in practice
ld64 seems to set it to point to the header, so that's what's implemented
here.

Reviewed By: #lld-macho, smeenai

Differential Revision: https://reviews.llvm.org/D83603


  Commit: 22e6648a1834aa6680064eaf83e1e051a7248e17
      https://github.com/llvm/llvm-project/commit/22e6648a1834aa6680064eaf83e1e051a7248e17
  Author: Jez Ng <jezng at fb.com>
  Date:   2020-07-30 (Thu, 30 Jul 2020)

  Changed paths:
    M lld/Common/Args.cpp
    M lld/MachO/Config.h
    M lld/MachO/Driver.cpp
    M lld/MachO/Options.td
    M lld/MachO/SyntheticSections.cpp
    M lld/include/lld/Common/Args.h
    A lld/test/MachO/headerpad.s
    M lld/test/MachO/local-got.s
    M lld/test/MachO/relocations.s

  Log Message:
  -----------
  [lld-macho] Implement -headerpad

Tools like `install_name_tool` and `codesign` may modify the Mach-O
header and increase its size. The linker has to provide padding to make this
possible. This diff does that, plus sets its default value to 32 bytes (which
is what ld64 does).

Unlike ld64, however, we lay out our sections *exactly* `-headerpad` bytes from
the header, whereas ld64 just treats the padding requirement as a lower bound.
ld64 actually starts laying out the non-header sections in the __TEXT segment
from the end of the (page-aligned) segment rather than the front, so its
binaries typically have more than `-headerpad` bytes of actual padding.
We should consider implementing the same alignment behavior.

Reviewed By: #lld-macho, compnerd

Differential Revision: https://reviews.llvm.org/D84714


  Commit: 98210796e108b59bad56fed9df98e920359afc6b
      https://github.com/llvm/llvm-project/commit/98210796e108b59bad56fed9df98e920359afc6b
  Author: Jez Ng <jezng at fb.com>
  Date:   2020-07-30 (Thu, 30 Jul 2020)

  Changed paths:
    M lld/MachO/SyntheticSections.cpp
    M lld/MachO/SyntheticSections.h
    M lld/MachO/Writer.cpp
    A lld/test/MachO/linkedit-contiguity.s

  Log Message:
  -----------
  [lld-macho] Make __LINKEDIT sections contiguous

codesign (or more specifically libstuff) checks that each section in
__LINKEDIT ends where the next one starts -- no gaps are permitted. This
diff achieves it by aligning every section's start and end points to
WordSize.

Remarks: ld64 appears to satisfy the constraint by adding padding bytes
when generating the __LINKEDIT data, e.g. by emitting BIND_OPCODE_DONE
(which is a 0x0 byte) repeatedly. I think the approach this diff takes
is a bit more elegant, but I'm not sure if it's too restrictive. In
particular, it assumes padding always uses the zero byte. But we can
revisit this later.

Reviewed By: #lld-macho, compnerd

Differential Revision: https://reviews.llvm.org/D84718


Compare: https://github.com/llvm/llvm-project/compare/9ebeac678855...98210796e108


More information about the All-commits mailing list