This is an archive of the discontinued LLVM Phabricator instance.

[lld-macho][nfc] Give every SyntheticSection a fake InputSection
ClosedPublic

Authored by int3 on Mar 12 2021, 11:59 AM.

Details

Summary

Previously, it was difficult to write code that handled both synthetic
and regular sections generically. We solve this problem by creating a
fake InputSection at the start of every SyntheticSection.

This refactor allows us to handle DSOHandle like a regular Defined
symbol (since Defined symbols must be attached to an InputSection), and
paves the way for supporting __mh_*header symbols. Additionally, it
simplifies our binding/rebase code.

I did have to extend Defined a little -- it now has a linkerInternal
flag, to indicate that ___dso_handle should not be in the final symbol
table.

I've also added some additional testing for ___dso_handle.

Diff Detail

Event Timeline

int3 created this revision.Mar 12 2021, 11:59 AM
Herald added a project: Restricted Project. · View Herald TranscriptMar 12 2021, 11:59 AM
int3 requested review of this revision.Mar 12 2021, 11:59 AM
Herald added a project: Restricted Project. · View Herald TranscriptMar 12 2021, 11:59 AM
oontvoo added inline comments.Mar 12 2021, 1:01 PM
lld/MachO/SymbolTable.cpp
164

clang-tidy: warning: 'auto s' can be declared as 'auto *s' [llvm-qualified-auto]

lld/MachO/SyntheticSections.cpp
770–771

This is true for dso_handle, but probably not for the mh_* symbols?

int3 marked 2 inline comments as done.Mar 12 2021, 1:03 PM
int3 added inline comments.
lld/MachO/SyntheticSections.cpp
770–771

Indeed. That's why addSynthetic takes linkerInternal as a parameter -- so that mh_* symbols can set it to false :)

oontvoo accepted this revision.Mar 12 2021, 1:15 PM

LGTM - thanks!

lld/MachO/SyntheticSections.cpp
770–771

Ah! Sorry I've missed that.

This revision is now accepted and ready to land.Mar 12 2021, 1:15 PM
This revision was landed with ongoing or failed builds.Mar 12 2021, 2:26 PM
This revision was automatically updated to reflect the committed changes.
int3 marked an inline comment as done.