summaryrefslogtreecommitdiffstats
path: root/llvm/lib/MC/StringTableBuilder.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'llvm/lib/MC/StringTableBuilder.cpp')
-rw-r--r--llvm/lib/MC/StringTableBuilder.cpp7
1 files changed, 7 insertions, 0 deletions
diff --git a/llvm/lib/MC/StringTableBuilder.cpp b/llvm/lib/MC/StringTableBuilder.cpp
index bd51aa413fb..cb3db8e2268 100644
--- a/llvm/lib/MC/StringTableBuilder.cpp
+++ b/llvm/lib/MC/StringTableBuilder.cpp
@@ -159,6 +159,13 @@ void StringTableBuilder::finalizeStringTable(bool Optimize) {
if (K == MachO)
Size = alignTo(Size, 4); // Pad to multiple of 4.
+
+ // 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
+ // this purpose and here we actually add the string to allow 'getOffset()' to
+ // be called on an empty string.
+ if (K == ELF)
+ StringIndexMap[CachedHashStringRef("")] = 0;
}
void StringTableBuilder::clear() {
OpenPOWER on IntegriCloud