[lld] r315054 - [ELF] - Do not produce broken .dynamic section with --no-rosegment
George Rimar via llvm-commits
llvm-commits at lists.llvm.org
Fri Oct 6 03:06:13 PDT 2017
Author: grimar
Date: Fri Oct 6 03:06:13 2017
New Revision: 315054
URL: http://llvm.org/viewvc/llvm-project?rev=315054&view=rev
Log:
[ELF] - Do not produce broken .dynamic section with --no-rosegment
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.
Differential revision: https://reviews.llvm.org/D38580
Added:
lld/trunk/test/ELF/dynamic-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=315054&r1=315053&r2=315054&view=diff
==============================================================================
--- lld/trunk/ELF/SyntheticSections.cpp (original)
+++ lld/trunk/ELF/SyntheticSections.cpp Fri Oct 6 03:06:13 2017
@@ -1171,10 +1171,10 @@ template <class ELFT> void DynamicSectio
add({DT_MIPS_RLD_MAP, InX::MipsRldMap});
}
- getParent()->Link = this->Link;
+ add({DT_NULL, (uint64_t)0});
- // +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) {
Added: lld/trunk/test/ELF/dynamic-no-rosegment.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/dynamic-no-rosegment.s?rev=315054&view=auto
==============================================================================
--- lld/trunk/test/ELF/dynamic-no-rosegment.s (added)
+++ lld/trunk/test/ELF/dynamic-no-rosegment.s Fri Oct 6 03:06:13 2017
@@ -0,0 +1,15 @@
+# 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 [ (7 entries)
+# CHECK-NEXT: Tag Type Name/Value
+# CHECK-NEXT: 0x0000000000000006 SYMTAB 0x120
+# CHECK-NEXT: 0x000000000000000B SYMENT 24 (bytes)
+# CHECK-NEXT: 0x0000000000000005 STRTAB 0x1D0
+# CHECK-NEXT: 0x000000000000000A STRSZ 1 (bytes)
+# CHECK-NEXT: 0x000000006FFFFEF5 GNU_HASH 0x138
+# CHECK-NEXT: 0x0000000000000004 HASH 0x150
+# CHECK-NEXT: 0x0000000000000000 NULL 0x0
+# CHECK-NEXT: ]
More information about the llvm-commits
mailing list