[PATCH] D85651: [LLD][ELF] - Do not produce an invalid dynamic relocation order with --shuffle-sections.
George Rimar via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue Aug 11 05:22:39 PDT 2020
grimar updated this revision to Diff 284670.
grimar marked an inline comment as done.
grimar edited the summary of this revision.
grimar added a comment.
- Addressed Peter's comment (fixed typo).
- Rebased after landing parent revision.
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D85651/new/
https://reviews.llvm.org/D85651
Files:
lld/ELF/Writer.cpp
lld/test/ELF/gnu-ifunc-plt.s
Index: lld/test/ELF/gnu-ifunc-plt.s
===================================================================
--- lld/test/ELF/gnu-ifunc-plt.s
+++ lld/test/ELF/gnu-ifunc-plt.s
@@ -77,6 +77,20 @@
// DISASM-NEXT: 201386: pushq $0x1
// DISASM-NEXT: 20138b: jmp 0x201340 <.plt>
+// Test that --shuffle-sections does not affect the order of relocations and that
+// we still place IRELATIVE relocations last. Check both random seed (0) and an
+// arbitrary seed that was known to break the order of relocations previously (3).
+// RUN: ld.lld --shuffle-sections=3 %t.so %t.o -o %tout2
+// RUN: llvm-readobj --relocations %tout2 | FileCheck %s --check-prefix=SHUFFLE
+// RUN: ld.lld --shuffle-sections=0 %t.so %t.o -o %tout3
+// RUN: llvm-readobj --relocations %tout3 | FileCheck %s --check-prefix=SHUFFLE
+
+// SHUFFLE: Section {{.*}} .rela.dyn {
+// SHUFFLE-NEXT: R_X86_64_GLOB_DAT
+// SHUFFLE-NEXT: R_X86_64_IRELATIVE
+// SHUFFLE-NEXT: R_X86_64_IRELATIVE
+// SHUFFLE-NEXT: }
+
.text
.type foo STT_GNU_IFUNC
.globl foo
Index: lld/ELF/Writer.cpp
===================================================================
--- lld/ELF/Writer.cpp
+++ lld/ELF/Writer.cpp
@@ -1437,6 +1437,14 @@
if (name == ".init" || name == ".fini")
return;
+ // IRelative relocations that usually live in the .rel[a].dyn section should
+ // be proccessed last by the dynamic loader. To achieve that we add synthetic
+ // sections in the required order from the begining so that the in.relaIplt
+ // section is placed last in an output section. Here we just do not apply
+ // sorting for an output section which holds the in.relaIplt section.
+ if (in.relaIplt->getParent() == sec)
+ return;
+
// Sort input sections by priority using the list provided by
// --symbol-ordering-file or --shuffle-sections=. This is a least significant
// digit radix sort. The sections may be sorted stably again by a more
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D85651.284670.patch
Type: text/x-patch
Size: 1935 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200811/6d2722d1/attachment.bin>
More information about the llvm-commits
mailing list