Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion lld/ELF/OutputSections.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -253,8 +253,22 @@ void OutputSection::finalizeInputSections() {
for (InputSection *s : isd->sections)
commitSection(s);
}
for (auto *ms : mergeSections)
for (auto *ms : mergeSections) {
// Merging may have increased the alignment of a spillable section. Update
// the alignment of potential spill sections and their containing output
// sections.
if (!script->potentialSpillLists.empty()) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The empty() test is redundant

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed.

if (auto it = script->potentialSpillLists.find(ms);
it != script->potentialSpillLists.end()) {
for (PotentialSpillSection *s = it->second.head; s; s = s->next) {
s->addralign = std::max(s->addralign, ms->addralign);
s->parent->addralign = std::max(s->parent->addralign, s->addralign);
}
}
}

ms->finalizeContents();
}
}

static void sortByOrder(MutableArrayRef<InputSection *> in,
Expand Down
10 changes: 6 additions & 4 deletions lld/test/ELF/linkerscript/section-class.test
Original file line number Diff line number Diff line change
Expand Up @@ -310,17 +310,19 @@ SECTIONS {
.byte 0x12, 0x34

.section .b,"aM",@progbits,1
.p2align 1
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

An alignment of 2 works, but a larger alignment makes the effect clearer.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We also need to dump the section content (e.g. -x second )

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

.byte 0x12

# RUN: llvm-mc -n -filetype=obj -triple=x86_64 merge.s -o merge.o

#--- spill-merge.lds
## SHF_MERGE sections are spilled according to the class refs of the first
## merged input section (the one giving the resulting section its name).
## Spills take into account increases in section alignment due to merging.
MEMORY {
a : ORIGIN = 0, LENGTH = 1
b : ORIGIN = 1, LENGTH = 2
c : ORIGIN = 3, LENGTH = 2
b : ORIGIN = 1, LENGTH = 4
c : ORIGIN = 5, LENGTH = 4
}

SECTIONS {
Expand All @@ -336,8 +338,8 @@ SECTIONS {

# SPILL-MERGE: Name Type Address Off Size
# SPILL-MERGE: .first PROGBITS 0000000000000000 000190 000000
# SPILL-MERGE-NEXT: .second PROGBITS 0000000000000001 001001 000002
# SPILL-MERGE-NEXT: .third PROGBITS 0000000000000003 001003 000000
# SPILL-MERGE-NEXT: .second PROGBITS 0000000000000002 001002 000003
# SPILL-MERGE-NEXT: .third PROGBITS 0000000000000006 001006 000000

#--- link-order.s
.section .a,"a",@progbits
Expand Down
Loading