Skip to content

Commit 079ee2a

Browse files
committed
[lld/ELF] Warn on conflicting SHF_X86_64_LARGE flag
There's no proper way to mix small and large x86-64 sections, so warn on it.
1 parent c2b57a0 commit 079ee2a

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

lld/ELF/OutputSections.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,15 @@ void OutputSection::commitSection(InputSection *isec) {
149149
error("incompatible section flags for " + name + "\n>>> " +
150150
toString(isec) + ": 0x" + utohexstr(isec->flags) +
151151
"\n>>> output section " + name + ": 0x" + utohexstr(flags));
152+
if (config->emachine == EM_X86_64) {
153+
if ((flags ^ isec->flags) & SHF_X86_64_LARGE) {
154+
InputSection *conflictISec = getFirstInputSection(this);
155+
warn("incompatible SHF_X86_64_LARGE section flag for '" + name +
156+
"'\n>>> " + toString(conflictISec) + ": 0x" +
157+
utohexstr(conflictISec->flags) + "\n>>> " + toString(isec) +
158+
": 0x" + utohexstr(isec->flags));
159+
}
160+
}
152161
}
153162

154163
isec->parent = this;
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# REQUIRES: x86
2+
# RUN: split-file %s %t
3+
# RUN: llvm-mc -filetype=obj -triple=x86_64 %t/a.s -o %t/a.o
4+
# RUN: llvm-mc -filetype=obj -triple=x86_64 %t/b.s -o %t/b.o
5+
# RUN: ld.lld %t/a.o %t/b.o -o /dev/null 2>&1 | FileCheck %s
6+
7+
# CHECK: warning: incompatible SHF_X86_64_LARGE section flag for 'foo'
8+
# CHECK-NEXT: >>> {{.*}}a.o:(foo): 0x10000003
9+
# CHECK-NEXT: >>> {{.*}}b.o:(foo): 0x3
10+
11+
#--- a.s
12+
.section foo,"awl",@progbits
13+
14+
#--- b.s
15+
.section foo,"aw",@progbits
16+

0 commit comments

Comments
 (0)