aboutsummaryrefslogtreecommitdiff
path: root/contrib/llvm-project/llvm/lib/MC/StringTableBuilder.cpp
diff options
context:
space:
mode:
authorDimitry Andric <dim@FreeBSD.org>2021-06-13 19:31:46 +0000
committerDimitry Andric <dim@FreeBSD.org>2021-06-13 19:37:19 +0000
commite8d8bef961a50d4dc22501cde4fb9fb0be1b2532 (patch)
tree94f04805f47bb7c59ae29690d8952b6074fff602 /contrib/llvm-project/llvm/lib/MC/StringTableBuilder.cpp
parentbb130ff39747b94592cb26d71b7cb097b9a4ea6b (diff)
parentb60736ec1405bb0a8dd40989f67ef4c93da068ab (diff)
Diffstat (limited to 'contrib/llvm-project/llvm/lib/MC/StringTableBuilder.cpp')
-rw-r--r--contrib/llvm-project/llvm/lib/MC/StringTableBuilder.cpp15
1 files changed, 14 insertions, 1 deletions
diff --git a/contrib/llvm-project/llvm/lib/MC/StringTableBuilder.cpp b/contrib/llvm-project/llvm/lib/MC/StringTableBuilder.cpp
index c9c88ec58432..973c59057cb5 100644
--- a/contrib/llvm-project/llvm/lib/MC/StringTableBuilder.cpp
+++ b/contrib/llvm-project/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