[lld] r315053 - [ELF] - Do not produce broken .dynsym with --no-rosegment.

George Rimar via llvm-commits llvm-commits at lists.llvm.org
Fri Oct 6 02:56:24 PDT 2017


Author: grimar
Date: Fri Oct  6 02:56:24 2017
New Revision: 315053

URL: http://llvm.org/viewvc/llvm-project?rev=315053&view=rev
Log:
[ELF] - Do not produce broken .dynsym with --no-rosegment.

We produce broken output currently.
Code that writes .dynsym assumes output buffer is zero-filled,
though that is not always true. When --no-rosegment is given,
buffer can be filled with trap instructions. Patch fixes the issue.

It is relative with PR34705.

Differential revision: https://reviews.llvm.org/D38579

Added:
    lld/trunk/test/ELF/dynsym-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=315053&r1=315052&r2=315053&view=diff
==============================================================================
--- lld/trunk/ELF/SyntheticSections.cpp (original)
+++ lld/trunk/ELF/SyntheticSections.cpp Fri Oct  6 02:56:24 2017
@@ -1386,6 +1386,7 @@ SymbolTableSection<ELFT>::SymbolTableSec
 // Write the internal symbol table contents to the output symbol table.
 template <class ELFT> void SymbolTableSection<ELFT>::writeTo(uint8_t *Buf) {
   // The first entry is a null entry as per the ELF spec.
+  memset(Buf, 0, sizeof(Elf_Sym));
   Buf += sizeof(Elf_Sym);
 
   auto *ESym = reinterpret_cast<Elf_Sym *>(Buf);
@@ -1394,6 +1395,7 @@ template <class ELFT> void SymbolTableSe
     SymbolBody *Body = Ent.Symbol;
 
     // Set st_info and st_other.
+    ESym->st_other = 0;
     if (Body->isLocal()) {
       ESym->setBindingAndType(STB_LOCAL, Body->Type);
     } else {
@@ -1410,13 +1412,17 @@ template <class ELFT> void SymbolTableSe
       ESym->st_shndx = SHN_ABS;
     else if (isa<DefinedCommon>(Body))
       ESym->st_shndx = SHN_COMMON;
+    else
+      ESym->st_shndx = SHN_UNDEF;
 
     // Copy symbol size if it is a defined symbol. st_size is not significant
     // for undefined symbols, so whether copying it or not is up to us if that's
     // the case. We'll leave it as zero because by not setting a value, we can
     // get the exact same outputs for two sets of input files that differ only
     // in undefined symbol size in DSOs.
-    if (ESym->st_shndx != SHN_UNDEF)
+    if (ESym->st_shndx == SHN_UNDEF)
+      ESym->st_size = 0;
+    else
       ESym->st_size = Body->getSize<ELFT>();
 
     // st_value is usually an address of a symbol, but that has a

Added: lld/trunk/test/ELF/dynsym-no-rosegment.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/dynsym-no-rosegment.s?rev=315053&view=auto
==============================================================================
--- lld/trunk/test/ELF/dynsym-no-rosegment.s (added)
+++ lld/trunk/test/ELF/dynsym-no-rosegment.s Fri Oct  6 02:56:24 2017
@@ -0,0 +1,27 @@
+# REQUIRES: x86
+# RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t.o
+# RUN: ld.lld -shared --no-rosegment -o %t %t.o
+# RUN: llvm-readobj -dyn-symbols -s %t | FileCheck %s
+
+# CHECK:      DynamicSymbols [
+# CHECK-NEXT:   Symbol {
+# CHECK-NEXT:     Name: @ (0)
+# CHECK-NEXT:     Value: 0x0
+# CHECK-NEXT:     Size: 0
+# CHECK-NEXT:     Binding: Local
+# CHECK-NEXT:     Type: None
+# CHECK-NEXT:     Other: 0
+# CHECK-NEXT:     Section: Undefined
+# CHECK-NEXT:   }
+# CHECK-NEXT:   Symbol {
+# CHECK-NEXT:     Name: undef@
+# CHECK-NEXT:     Value: 0x0
+# CHECK-NEXT:     Size: 0
+# CHECK-NEXT:     Binding: Global
+# CHECK-NEXT:     Type: None
+# CHECK-NEXT:     Other: 0
+# CHECK-NEXT:     Section: Undefined
+# CHECK-NEXT:   }
+# CHECK-NEXT: ]
+
+callq undef at PLT




More information about the llvm-commits mailing list