[lld-macho] Support binding dysyms to any section
authorJez Ng <jezng@fb.com>
Fri, 3 Jul 2020 04:19:55 +0000 (21:19 -0700)
committerJez Ng <jezng@fb.com>
Fri, 3 Jul 2020 04:21:01 +0000 (21:21 -0700)
commit53eb7fda51f27b1b098fd6d5c9385948e891e800
treea16a4d0ffb69a3d1701a0dbf94681e755afc8b2e
parent7ec6927badecae0adf63eb72c42194deb68a9685
[lld-macho] Support binding dysyms to any section

Previously, we only supported binding dysyms to the GOT. This
diff adds support for binding them to any arbitrary section. C++
programs appear to use this, I believe for vtables and type_info.

This diff also makes our bind opcode encoding a bit smarter -- we now
encode just the differences between bindings, which will make things
more compact.

I was initially concerned about the performance overhead of iterating
over these relocations, but it turns out that the number of such
relocations is small. A quick analysis of my llvm-project build
directory showed that < 1.3% out of ~7M relocations are RELOC_UNSIGNED
bindings to symbols (including both dynamic and static symbols).

Reviewed By: #lld-macho, smeenai

Differential Revision: https://reviews.llvm.org/D83103
lld/MachO/Arch/X86_64.cpp
lld/MachO/SyntheticSections.cpp
lld/MachO/SyntheticSections.h
lld/MachO/Target.h
lld/MachO/Writer.cpp
lld/test/MachO/dylink.s