aboutsummaryrefslogtreecommitdiff
path: root/lld/ELF
diff options
context:
space:
mode:
authorFangrui Song <i@maskray.me>2024-06-06 12:13:19 -0700
committerFangrui Song <i@maskray.me>2024-06-06 12:13:19 -0700
commit9ad0175ea0099351050e1dfb0074d9938f469404 (patch)
tree695fd7efeee97ec714678ae7ed8cfa5902439af5 /lld/ELF
parentc771b670eabbd38867d43475dacd35a1b572e9b5 (diff)
downloadllvm-9ad0175ea0099351050e1dfb0074d9938f469404.zip
llvm-9ad0175ea0099351050e1dfb0074d9938f469404.tar.gz
llvm-9ad0175ea0099351050e1dfb0074d9938f469404.tar.bz2
[ELF] Keep non-alloc orphan sections at the end
https://reviews.llvm.org/D85867 changed the way we assign file offsets (alloc sections first, then non-alloc sections). It also removed a non-alloc special case from `findOrphanPos`. Looking at the memory-nonalloc-no-warn.test change, which would be needed by #93761, it makes sense to restore the previous behavior: when placing non-alloc orphan sections, keep these sections at the end so that the section index order matches the file offset order. This change is cosmetic. In sections-nonalloc.s, GNU ld places the orphan `other3` in the middle and the orphan .symtab/.shstrtab/.strtab at the end. Pull Request: https://github.com/llvm/llvm-project/pull/94519
Diffstat (limited to 'lld/ELF')
-rw-r--r--lld/ELF/Writer.cpp4
1 files changed, 4 insertions, 0 deletions
diff --git a/lld/ELF/Writer.cpp b/lld/ELF/Writer.cpp
index 0295a65..544db20 100644
--- a/lld/ELF/Writer.cpp
+++ b/lld/ELF/Writer.cpp
@@ -921,7 +921,11 @@ static bool shouldSkip(SectionCommand *cmd) {
static SmallVectorImpl<SectionCommand *>::iterator
findOrphanPos(SmallVectorImpl<SectionCommand *>::iterator b,
SmallVectorImpl<SectionCommand *>::iterator e) {
+ // Place non-alloc orphan sections at the end. This matches how we assign file
+ // offsets to non-alloc sections.
OutputSection *sec = &cast<OutputDesc>(*e)->osec;
+ if (!(sec->flags & SHF_ALLOC))
+ return e;
// As a special case, place .relro_padding before the SymbolAssignment using
// DATA_SEGMENT_RELRO_END, if present.