[lld-macho] Partial support for weak definitions
authorJez Ng <jezng@fb.com>
Fri, 24 Jul 2020 22:55:25 +0000 (15:55 -0700)
committerJez Ng <jezng@fb.com>
Fri, 24 Jul 2020 22:55:25 +0000 (15:55 -0700)
commit31d58858425f6021d380eff879dd8983e25a5715
tree238c41711adae4c6d43a68764a5f6c3ca6601636
parent8bf4c1f4fb257774f66c8cda07adc6c5e8668326
[lld-macho] Partial support for weak definitions

This diff adds support for weak definitions, though it doesn't handle weak
symbols in dylibs quite correctly -- we need to emit binding opcodes for them
in the weak binding section rather than the lazy binding section.

What *is* covered in this diff:

1. Reading the weak flag from symbol table / export trie, and writing it to the
   export trie
2. Refining the symbol table's rules for choosing one symbol definition over
   another. Wrote a few dozen test cases to make sure we were matching ld64's
   behavior.

We can now link basic C++ programs.

Reviewed By: #lld-macho, compnerd

Differential Revision: https://reviews.llvm.org/D83532
lld/MachO/Arch/X86_64.cpp
lld/MachO/ExportTrie.cpp
lld/MachO/InputFiles.cpp
lld/MachO/SymbolTable.cpp
lld/MachO/SymbolTable.h
lld/MachO/Symbols.h
lld/MachO/SyntheticSections.cpp
lld/test/MachO/weak-definition-direct-fetch.s [new file with mode: 0644]
lld/test/MachO/weak-definition-indirect-fetch.s [new file with mode: 0644]
lld/test/MachO/weak-definition-order.s [new file with mode: 0644]
lld/test/MachO/weak-definition-over-dysym.s [new file with mode: 0644]