[lld] r310042 - [ELF] Explicitly write null bytes in string tables
James Henderson via llvm-commits
llvm-commits at lists.llvm.org
Fri Aug 4 02:07:55 PDT 2017
Author: jhenderson
Date: Fri Aug 4 02:07:55 2017
New Revision: 310042
URL: http://llvm.org/viewvc/llvm-project?rev=310042&view=rev
Log:
[ELF] Explicitly write null bytes in string tables
Following r309829, if a string table appears in an executable segment, the strings
will not be null terminated. This is a problem, for example, for the .dynstr
section when using -no-rosegment. The strings end up being terminated with 0xcc
because prior to this patch, LLD did not explicitly write the null terminators.
This change fixes that by always writing the null terminators.
Reviewers: rafael
Differential Revision: https://reviews.llvm.org/D36267
Added:
lld/trunk/test/ELF/dynstr-no-rosegment.s
Modified:
lld/trunk/ELF/SyntheticSections.cpp
Modified: lld/trunk/ELF/SyntheticSections.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/SyntheticSections.cpp?rev=310042&r1=310041&r2=310042&view=diff
==============================================================================
--- lld/trunk/ELF/SyntheticSections.cpp (original)
+++ lld/trunk/ELF/SyntheticSections.cpp Fri Aug 4 02:07:55 2017
@@ -990,6 +990,7 @@ unsigned StringTableSection::addString(S
void StringTableSection::writeTo(uint8_t *Buf) {
for (StringRef S : Strings) {
memcpy(Buf, S.data(), S.size());
+ Buf[S.size()] = '\0';
Buf += S.size() + 1;
}
}
Added: lld/trunk/test/ELF/dynstr-no-rosegment.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/dynstr-no-rosegment.s?rev=310042&view=auto
==============================================================================
--- lld/trunk/test/ELF/dynstr-no-rosegment.s (added)
+++ lld/trunk/test/ELF/dynstr-no-rosegment.s Fri Aug 4 02:07:55 2017
@@ -0,0 +1,12 @@
+# Verify that a .dynstr in the .text segment has null byte terminators
+
+# REQUIRES: x86
+# RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t.o
+# RUN: ld.lld %t.o -no-rosegment -o %t.so -shared
+# RUN: llvm-objdump %t.so -s -j .dynstr | FileCheck %s
+
+# CHECK: 00666f6f 00 .foo.
+
+.globl foo
+foo:
+ ret
More information about the llvm-commits
mailing list