[PATCH] D36267: [ELF] Explicitly write null bytes in string tables
Rafael Avila de Espindola via llvm-commits
llvm-commits at lists.llvm.org
Thu Aug 3 16:31:07 PDT 2017
LGTM
Thanks!
James Henderson via Phabricator <reviews at reviews.llvm.org> writes:
> jhenderson created this revision.
> Herald added a subscriber: emaste.
>
> Following https://reviews.llvm.org/rL309829, 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.
>
>
> https://reviews.llvm.org/D36267
>
> Files:
> ELF/SyntheticSections.cpp
> test/ELF/dynstr-no-rosegment.s
>
>
> Index: test/ELF/dynstr-no-rosegment.s
> ===================================================================
> --- test/ELF/dynstr-no-rosegment.s
> +++ test/ELF/dynstr-no-rosegment.s
> @@ -0,0 +1,12 @@
> +# Verify that a .dynstr in the .text segment has null byte separators
> +
> +# 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
> Index: ELF/SyntheticSections.cpp
> ===================================================================
> --- ELF/SyntheticSections.cpp
> +++ ELF/SyntheticSections.cpp
> @@ -990,6 +990,7 @@
> void StringTableSection::writeTo(uint8_t *Buf) {
> for (StringRef S : Strings) {
> memcpy(Buf, S.data(), S.size());
> + Buf[S.size()] = '\0';
> Buf += S.size() + 1;
> }
> }
>
>
> Index: test/ELF/dynstr-no-rosegment.s
> ===================================================================
> --- test/ELF/dynstr-no-rosegment.s
> +++ test/ELF/dynstr-no-rosegment.s
> @@ -0,0 +1,12 @@
> +# Verify that a .dynstr in the .text segment has null byte separators
> +
> +# 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
> Index: ELF/SyntheticSections.cpp
> ===================================================================
> --- ELF/SyntheticSections.cpp
> +++ ELF/SyntheticSections.cpp
> @@ -990,6 +990,7 @@
> void StringTableSection::writeTo(uint8_t *Buf) {
> for (StringRef S : Strings) {
> memcpy(Buf, S.data(), S.size());
> + Buf[S.size()] = '\0';
> Buf += S.size() + 1;
> }
> }
More information about the llvm-commits
mailing list