diff options
author | Michael J. Spencer <bigcheesegs@gmail.com> | 2018-02-08 22:03:23 +0000 |
---|---|---|
committer | Michael J. Spencer <bigcheesegs@gmail.com> | 2018-02-08 22:03:23 +0000 |
commit | e43db0e89ecd18a30c8564491437472defb43048 (patch) | |
tree | fea344fb86433dafac9975a9d2d3203d35c167b5 | |
parent | 244cccfce80609dd1c1559a524dce1e25a33a021 (diff) | |
download | bcm5719-llvm-e43db0e89ecd18a30c8564491437472defb43048.tar.gz bcm5719-llvm-e43db0e89ecd18a30c8564491437472defb43048.zip |
[ELF] Don't sort non reorderable sections with --symbol-ordering-file
Differential Revision: https://reviews.llvm.org/D43038
llvm-svn: 324656
-rw-r--r-- | lld/ELF/Writer.cpp | 9 | ||||
-rw-r--r-- | lld/test/ELF/symbol-ordering-file.s | 14 |
2 files changed, 22 insertions, 1 deletions
diff --git a/lld/ELF/Writer.cpp b/lld/ELF/Writer.cpp index 9de734a1c0d..6bc34f0cf32 100644 --- a/lld/ELF/Writer.cpp +++ b/lld/ELF/Writer.cpp @@ -1048,6 +1048,13 @@ static DenseMap<SectionBase *, int> buildSectionOrder() { 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 @@ template <class ELFT> void Writer<ELFT>::sortInputSections() { 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) diff --git a/lld/test/ELF/symbol-ordering-file.s b/lld/test/ELF/symbol-ordering-file.s index 5a88b8c0827..177c22f2775 100644 --- a/lld/test/ELF/symbol-ordering-file.s +++ b/lld/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",@progbits,unique,1 _foo1: @@ -42,3 +48,11 @@ _foo5: .byte 0x55 _bar1: .byte 0x66 + +.section .init,"ax",@progbits,unique,1 +_init1: + .byte 0x11 + +.section .init,"ax",@progbits,unique,2 +_init2: + .byte 0x22 |