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

Arthur Eubanks via llvm-commits llvm-commits at lists.llvm.org
Tue Jan 9 21:54:19 PST 2024


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

>From 079ee2a567465971a9de143568f6b6be409a19fc Mon Sep 17 00:00:00 2001
From: Arthur Eubanks <aeubanks at google.com>
Date: Tue, 14 Nov 2023 19:07:34 -0800
Subject: [PATCH] [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.
---
 lld/ELF/OutputSections.cpp                   |  9 +++++++++
 lld/test/ELF/x86-64-warn-mix-large-section.s | 16 ++++++++++++++++
 2 files changed, 25 insertions(+)
 create mode 100644 lld/test/ELF/x86-64-warn-mix-large-section.s

diff --git a/lld/ELF/OutputSections.cpp b/lld/ELF/OutputSections.cpp
index ee937418678707..12ddc82283a6cf 100644
--- a/lld/ELF/OutputSections.cpp
+++ b/lld/ELF/OutputSections.cpp
@@ -149,6 +149,15 @@ 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/x86-64-warn-mix-large-section.s b/lld/test/ELF/x86-64-warn-mix-large-section.s
new file mode 100644
index 00000000000000..a4aeeba3fe1be7
--- /dev/null
+++ b/lld/test/ELF/x86-64-warn-mix-large-section.s
@@ -0,0 +1,16 @@
+# 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
+
+#--- b.s
+.section foo,"aw", at progbits
+



More information about the llvm-commits mailing list