diff options
Diffstat (limited to 'llvm/lib/MC/StringTableBuilder.cpp')
-rw-r--r-- | llvm/lib/MC/StringTableBuilder.cpp | 20 |
1 files changed, 17 insertions, 3 deletions
diff --git a/llvm/lib/MC/StringTableBuilder.cpp b/llvm/lib/MC/StringTableBuilder.cpp index 34e7e6fdfbb..9de9363611e 100644 --- a/llvm/lib/MC/StringTableBuilder.cpp +++ b/llvm/lib/MC/StringTableBuilder.cpp @@ -36,12 +36,16 @@ void StringTableBuilder::finalize(Kind kind) { std::sort(Strings.begin(), Strings.end(), compareBySuffix); - if (kind == ELF) { + switch (kind) { + case ELF: + case MachO: // Start the table with a NUL byte. StringTable += '\x00'; - } else if (kind == WinCOFF) { + break; + case WinCOFF: // Make room to write the table size later. StringTable.append(4, '\x00'); + break; } StringRef Previous; @@ -60,11 +64,21 @@ void StringTableBuilder::finalize(Kind kind) { Previous = s; } - if (kind == WinCOFF) { + switch (kind) { + case ELF: + break; + case MachO: + // Pad to multiple of 4. + while (StringTable.size() % 4) + StringTable += '\x00'; + break; + case WinCOFF: + // Write the table size in the first word. assert(StringTable.size() <= std::numeric_limits<uint32_t>::max()); uint32_t size = static_cast<uint32_t>(StringTable.size()); support::endian::write<uint32_t, support::little, support::unaligned>( StringTable.data(), size); + break; } } |