diff options
author | Alexander Shaposhnikov <alexshap@fb.com> | 2020-10-22 18:03:40 -0700 |
---|---|---|
committer | Alexander Shaposhnikov <alexshap@fb.com> | 2020-10-22 19:19:41 -0700 |
commit | 27e11d7120c0caa20a167b44ba29828446a525c0 (patch) | |
tree | ca9615138ef03e6044aa0de385286c243e8e9a8c /llvm/lib/MC/StringTableBuilder.cpp | |
parent | a89297feb5770c5cd8253fcb976035b0a76deb83 (diff) | |
download | llvm-27e11d7120c0caa20a167b44ba29828446a525c0.zip llvm-27e11d7120c0caa20a167b44ba29828446a525c0.tar.gz llvm-27e11d7120c0caa20a167b44ba29828446a525c0.tar.bz2 |
[MC] Adjust StringTableBuilder for linked Mach-O binaries
LD64 emits string tables which start with a space and a zero byte.
This diff adjusts StringTableBuilder for linked Mach-O binaries to match LD64's behavior.
Test plan: make check-all
Differential revision: https://reviews.llvm.org/D89561
Diffstat (limited to 'llvm/lib/MC/StringTableBuilder.cpp')
-rw-r--r-- | llvm/lib/MC/StringTableBuilder.cpp | 15 |
1 files changed, 14 insertions, 1 deletions
diff --git a/llvm/lib/MC/StringTableBuilder.cpp b/llvm/lib/MC/StringTableBuilder.cpp index c9c88ec..973c590 100644 --- a/llvm/lib/MC/StringTableBuilder.cpp +++ b/llvm/lib/MC/StringTableBuilder.cpp @@ -33,7 +33,12 @@ void StringTableBuilder::initSize() { case DWARF: Size = 0; break; + case MachOLinked: + case MachO64Linked: + Size = 2; + break; case MachO: + case MachO64: case ELF: // Start the table with a NUL byte. Size = 1; @@ -161,8 +166,16 @@ void StringTableBuilder::finalizeStringTable(bool Optimize) { } } - if (K == MachO) + if (K == MachO || K == MachOLinked) Size = alignTo(Size, 4); // Pad to multiple of 4. + if (K == MachO64 || K == MachO64Linked) + Size = alignTo(Size, 8); // Pad to multiple of 8. + + // According to ld64 the string table of a final linked Mach-O binary starts + // with " ", i.e. the first byte is ' ' and the second byte is zero. In + // 'initSize()' we reserved the first two bytes for holding this string. + if (K == MachOLinked || K == MachO64Linked) + StringIndexMap[CachedHashStringRef(" ")] = 0; // The first byte in an ELF string table must be null, according to the ELF // specification. In 'initSize()' we reserved the first byte to hold null for |