[PATCH] D43038: [ELF] Don't sort non reorderable sections with --symbol-ordering-file

Phabricator via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Feb 8 14:05:13 PST 2018


This revision was not accepted when it landed; it landed in state "Needs Review".
This revision was automatically updated to reflect the committed changes.
Closed by commit rL324656: [ELF] Don't sort non reorderable sections with --symbol-ordering-file (authored by mspencer, committed by ).

Changed prior to commit:
  https://reviews.llvm.org/D43038?vs=133282&id=133485#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D43038

Files:
  lld/trunk/ELF/Writer.cpp
  lld/trunk/test/ELF/symbol-ordering-file.s


Index: lld/trunk/test/ELF/symbol-ordering-file.s
===================================================================
--- lld/trunk/test/ELF/symbol-ordering-file.s
+++ lld/trunk/test/ELF/symbol-ordering-file.s
@@ -5,6 +5,8 @@
 
 # BEFORE:      Contents of section .foo:
 # BEFORE-NEXT:  201000 11223344 5566
+# BEFORE:      Contents of section .init:
+# BEFORE-NEXT:  201006 1122
 
 # RUN: echo "_foo4  " > %t_order.txt
 # RUN: echo "  _foo3" >> %t_order.txt
@@ -14,12 +16,16 @@
 # RUN: echo "_foo4" >> %t_order.txt
 # RUN: echo "_bar1" >> %t_order.txt
 # RUN: echo "_foo1" >> %t_order.txt
+# RUN: echo "_init2" >> %t_order.txt
+# RUN: echo "_init1" >> %t_order.txt
 
 # RUN: ld.lld --symbol-ordering-file %t_order.txt %t.o -o %t2.out
 # RUN: llvm-objdump -s %t2.out| FileCheck %s --check-prefix=AFTER
 
 # AFTER:      Contents of section .foo:
 # AFTER-NEXT:  201000 44335566 2211
+# AFTER:      Contents of section .init:
+# AFTER-NEXT:  201006 1122
 
 .section .foo,"ax", at progbits,unique,1
 _foo1:
@@ -42,3 +48,11 @@
  .byte 0x55
 _bar1:
  .byte 0x66
+
+.section .init,"ax", at progbits,unique,1
+_init1:
+ .byte 0x11
+
+.section .init,"ax", at progbits,unique,2
+_init2:
+ .byte 0x22
Index: lld/trunk/ELF/Writer.cpp
===================================================================
--- lld/trunk/ELF/Writer.cpp
+++ lld/trunk/ELF/Writer.cpp
@@ -1048,6 +1048,13 @@
   return SectionOrder;
 }
 
+static bool isKnownNonreorderableSection(const OutputSection *OS) {
+  return llvm::StringSwitch<bool>(OS->Name)
+      .Cases(".init", ".fini", ".init_array", ".fini_array", ".ctors",
+             ".dtors", true)
+      .Default(false);
+}
+
 // If no layout was provided by linker script, we want to apply default
 // sorting for special input sections. This also handles --symbol-ordering-file.
 template <class ELFT> void Writer<ELFT>::sortInputSections() {
@@ -1057,7 +1064,7 @@
   if (!Order.empty())
     for (BaseCommand *Base : Script->SectionCommands)
       if (auto *Sec = dyn_cast<OutputSection>(Base))
-        if (Sec->Live)
+        if (Sec->Live && !isKnownNonreorderableSection(Sec))
           Sec->sort([&](InputSectionBase *S) { return Order.lookup(S); });
 
   if (Script->HasSectionsCommand)


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D43038.133485.patch
Type: text/x-patch
Size: 2208 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180208/c66f386c/attachment.bin>


More information about the llvm-commits mailing list