[PATCH] D38580: [ELF] - Do not produce broken .dynamic section with --no-rosegment

George Rimar via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Oct 5 04:14:29 PDT 2017


grimar created this revision.
Herald added subscribers: sdardis, emaste.

LLD produces broken .dynamic section when --no-rosegment and at least one
of following options is present:

1. -z rodynamic is given.
2. MIPS target.

That happens because code that writes .dynamic assumes target buffer is zero-filled,
what can be not true after LLD fills it with trap-instructions. With one of two options
above, .dynamic becomes SHF_ALLOC section, so can be affected.


https://reviews.llvm.org/D38580

Files:
  ELF/SyntheticSections.cpp
  test/ELF/dynamic-no-rosegment.s


Index: test/ELF/dynamic-no-rosegment.s
===================================================================
--- test/ELF/dynamic-no-rosegment.s
+++ test/ELF/dynamic-no-rosegment.s
@@ -0,0 +1,22 @@
+# REQUIRES: x86
+# RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t.o
+# RUN: ld.lld -shared --no-rosegment -z rodynamic -o %t %t.o
+# RUN: llvm-readobj -dynamic-table -s %t | FileCheck %s
+
+# CHECK:      DynamicSection [ (10 entries)
+# CHECK-NEXT:   Tag                Type                 Name/Value
+# CHECK-NEXT:   0x0000000000000017 JMPREL               0x278
+# CHECK-NEXT:   0x0000000000000002 PLTRELSZ             24 (bytes)
+# CHECK-NEXT:   0x0000000000000003 PLTGOT               0x1000
+# CHECK-NEXT:   0x0000000000000014 PLTREL               RELA
+# CHECK-NEXT:   0x0000000000000006 SYMTAB               0x160
+# CHECK-NEXT:   0x000000000000000B SYMENT               24 (bytes)
+# CHECK-NEXT:   0x0000000000000005 STRTAB               0x268
+# CHECK-NEXT:   0x000000000000000A STRSZ                12 (bytes)
+# CHECK-NEXT:   0x0000000000000004 HASH                 0x1A8
+# CHECK-NEXT:   0x0000000000000000 NULL                 0x0
+# CHECK-NEXT: ]
+
+.globl _start
+_start:
+ callq foo at PLT
Index: ELF/SyntheticSections.cpp
===================================================================
--- ELF/SyntheticSections.cpp
+++ ELF/SyntheticSections.cpp
@@ -1171,10 +1171,10 @@
       add({DT_MIPS_RLD_MAP, InX::MipsRldMap});
   }
 
-  getParent()->Link = this->Link;
+  add({DT_NULL, 0ULL});
 
-  // +1 for DT_NULL
-  this->Size = (Entries.size() + 1) * this->Entsize;
+  getParent()->Link = this->Link;
+  this->Size = Entries.size() * this->Entsize;
 }
 
 template <class ELFT> void DynamicSection<ELFT>::writeTo(uint8_t *Buf) {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D38580.117794.patch
Type: text/x-patch
Size: 1753 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20171005/14c2bf96/attachment.bin>


More information about the llvm-commits mailing list