[PATCH] D145381: [ELF] Add REVERSE input section description keyword
Justin Cady via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue Mar 7 09:45:49 PST 2023
This revision was automatically updated to reflect the committed changes.
Closed by commit rG447aa48b4a02: [ELF] Add REVERSE input section description keyword (authored by justincady).
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D145381/new/
https://reviews.llvm.org/D145381
Files:
lld/ELF/Config.h
lld/ELF/LinkerScript.cpp
lld/ELF/ScriptParser.cpp
lld/test/ELF/linkerscript/sort-init.s
Index: lld/test/ELF/linkerscript/sort-init.s
===================================================================
--- lld/test/ELF/linkerscript/sort-init.s
+++ lld/test/ELF/linkerscript/sort-init.s
@@ -9,6 +9,14 @@
# CHECK: Hex dump of section '.init_array':
# CHECK-NEXT: 0x00000001 00010203 04050607
+## Test REVERSE can be used to reverse the order of .init_array and .ctors
+
+# RUN: ld.lld -T %t/reverse.lds %t.o -o %t2.out
+# RUN: llvm-readelf -x .init_array %t2.out | FileCheck %s --check-prefix=CHECK2
+
+# CHECK2: Hex dump of section '.init_array':
+# CHECK2-NEXT: 0x00000001 04030201 00050706
+
#--- asm
.globl _start
_start:
@@ -41,3 +49,11 @@
*(.init_array .ctors)
}
}
+
+#--- reverse.lds
+SECTIONS {
+ .init_array : {
+ *(REVERSE(SORT_BY_INIT_PRIORITY(.init_array.* .ctors.*)) SORT_BY_INIT_PRIORITY(foo*))
+ *(REVERSE(.init_array .ctors))
+ }
+}
Index: lld/ELF/ScriptParser.cpp
===================================================================
--- lld/ELF/ScriptParser.cpp
+++ lld/ELF/ScriptParser.cpp
@@ -660,6 +660,7 @@
SortSectionPolicy ScriptParser::peekSortKind() {
return StringSwitch<SortSectionPolicy>(peek())
+ .Case("REVERSE", SortSectionPolicy::Reverse)
.Cases("SORT", "SORT_BY_NAME", SortSectionPolicy::Name)
.Case("SORT_BY_ALIGNMENT", SortSectionPolicy::Alignment)
.Case("SORT_BY_INIT_PRIORITY", SortSectionPolicy::Priority)
Index: lld/ELF/LinkerScript.cpp
===================================================================
--- lld/ELF/LinkerScript.cpp
+++ lld/ELF/LinkerScript.cpp
@@ -457,6 +457,8 @@
return llvm::stable_sort(vec, nameComparator);
case SortSectionPolicy::Priority:
return llvm::stable_sort(vec, priorityComparator);
+ case SortSectionPolicy::Reverse:
+ return std::reverse(vec.begin(), vec.end());
}
}
Index: lld/ELF/Config.h
===================================================================
--- lld/ELF/Config.h
+++ lld/ELF/Config.h
@@ -73,7 +73,14 @@
enum class OrphanHandlingPolicy { Place, Warn, Error };
// For --sort-section and linkerscript sorting rules.
-enum class SortSectionPolicy { Default, None, Alignment, Name, Priority };
+enum class SortSectionPolicy {
+ Default,
+ None,
+ Alignment,
+ Name,
+ Priority,
+ Reverse,
+};
// For --target2
enum class Target2Policy { Abs, Rel, GotRel };
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D145381.503075.patch
Type: text/x-patch
Size: 2353 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230307/c99cebf2/attachment.bin>
More information about the llvm-commits
mailing list