[lld] [lld/ELF] Warn on conflicting SHF_X86_64_LARGE flag (PR #72335)

via llvm-commits llvm-commits at lists.llvm.org
Tue Nov 14 19:09:41 PST 2023


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-lld-elf

@llvm/pr-subscribers-lld

Author: Arthur Eubanks (aeubanks)

<details>
<summary>Changes</summary>

There's no proper way to mix small and large x86-64 sections, so warn on it.


---
Full diff: https://github.com/llvm/llvm-project/pull/72335.diff


2 Files Affected:

- (modified) lld/ELF/OutputSections.cpp (+10) 
- (added) lld/test/ELF/warn-mix-large-section.s (+25) 


``````````diff
diff --git a/lld/ELF/OutputSections.cpp b/lld/ELF/OutputSections.cpp
index ee937418678707c..ab59432da7e8039 100644
--- a/lld/ELF/OutputSections.cpp
+++ b/lld/ELF/OutputSections.cpp
@@ -149,6 +149,16 @@ void OutputSection::commitSection(InputSection *isec) {
       error("incompatible section flags for " + name + "\n>>> " +
             toString(isec) + ": 0x" + utohexstr(isec->flags) +
             "\n>>> output section " + name + ": 0x" + utohexstr(flags));
+    if (config->emachine == EM_X86_64) {
+      if ((flags ^ isec->flags) & SHF_X86_64_LARGE) {
+        InputSection *conflictISec = getFirstInputSection(this);
+        warn("incompatible SHF_X86_64_LARGE section flag for " + name +
+             "\n>>> " + toString(conflictISec) + ": 0x" +
+             utohexstr(conflictISec->flags) + "\n>>> " + toString(isec) +
+             ": 0x" + utohexstr(isec->flags)
+        );
+      }
+    }
   }
 
   isec->parent = this;
diff --git a/lld/test/ELF/warn-mix-large-section.s b/lld/test/ELF/warn-mix-large-section.s
new file mode 100644
index 000000000000000..91fbeb5f64f6874
--- /dev/null
+++ b/lld/test/ELF/warn-mix-large-section.s
@@ -0,0 +1,25 @@
+# REQUIRES: x86
+# RUN: split-file %s %t
+# RUN: llvm-mc -filetype=obj -triple=x86_64 %t/a.s -o %t/a.o
+# RUN: llvm-mc -filetype=obj -triple=x86_64 %t/b.s -o %t/b.o
+# RUN: ld.lld %t/a.o %t/b.o -o /dev/null 2>&1 | FileCheck %s
+
+# CHECK: warning: incompatible SHF_X86_64_LARGE section flag for foo
+# CHECK-NEXT: >>> {{.*}}a.o:(foo): 0x10000003
+# CHECK-NEXT: >>> {{.*}}b.o:(foo): 0x3
+
+#--- a.s
+.section foo,"awl", at progbits
+
+.type   hello, @object
+.globl  hello
+hello:
+.long   1
+
+#--- b.s
+.section foo,"aw", at progbits
+
+.type   hello2, @object
+.globl  hello2
+hello2:
+.long   1

``````````

</details>


https://github.com/llvm/llvm-project/pull/72335


More information about the llvm-commits mailing list