[lld] b9249a6 - [lld][ELF] Do not emit warning for NOLOAD output sections
Leonard Chan via llvm-commits
llvm-commits at lists.llvm.org
Tue May 23 13:41:47 PDT 2023
Author: Leonard Chan
Date: 2023-05-23T20:41:20Z
New Revision: b9249a69cc274b78f8783dcac95945edf2424ddd
URL: https://github.com/llvm/llvm-project/commit/b9249a69cc274b78f8783dcac95945edf2424ddd
DIFF: https://github.com/llvm/llvm-project/commit/b9249a69cc274b78f8783dcac95945edf2424ddd.diff
LOG: [lld][ELF] Do not emit warning for NOLOAD output sections
Much of NOLOAD's intended use is to explicitly change the type of an
output section, so we shouldn't flag these as warnings.
Differential Revision: https://reviews.llvm.org/D151144
Added:
Modified:
lld/ELF/OutputSections.cpp
lld/test/ELF/linkerscript/noload.s
Removed:
################################################################################
diff --git a/lld/ELF/OutputSections.cpp b/lld/ELF/OutputSections.cpp
index 97f676f000fdc..d45f6abd810f0 100644
--- a/lld/ELF/OutputSections.cpp
+++ b/lld/ELF/OutputSections.cpp
@@ -116,16 +116,18 @@ void OutputSection::commitSection(InputSection *isec) {
if (hasInputSections || typeIsSet) {
if (typeIsSet || !canMergeToProgbits(type) ||
!canMergeToProgbits(isec->type)) {
- // Changing the type of a (NOLOAD) section is fishy, but some projects
- // (e.g. https://github.com/ClangBuiltLinux/linux/issues/1597)
- // traditionally rely on the behavior. Issue a warning to not break
- // them. Other types get an error.
- auto diagnose = type == SHT_NOBITS ? warn : errorOrWarn;
- diagnose("section type mismatch for " + isec->name + "\n>>> " +
- toString(isec) + ": " +
- getELFSectionTypeName(config->emachine, isec->type) +
- "\n>>> output section " + name + ": " +
- getELFSectionTypeName(config->emachine, type));
+ // The (NOLOAD) changes the section type to SHT_NOBITS, the intention is
+ // that the contents at that address is provided by some other means.
+ // Some projects (e.g.
+ // https://github.com/ClangBuiltLinux/linux/issues/1597) rely on the
+ // behavior. Other types get an error.
+ if (type != SHT_NOBITS) {
+ errorOrWarn("section type mismatch for " + isec->name + "\n>>> " +
+ toString(isec) + ": " +
+ getELFSectionTypeName(config->emachine, isec->type) +
+ "\n>>> output section " + name + ": " +
+ getELFSectionTypeName(config->emachine, type));
+ }
}
if (!typeIsSet)
type = SHT_PROGBITS;
diff --git a/lld/test/ELF/linkerscript/noload.s b/lld/test/ELF/linkerscript/noload.s
index 5c9cff33e2359..998ccac0febe6 100644
--- a/lld/test/ELF/linkerscript/noload.s
+++ b/lld/test/ELF/linkerscript/noload.s
@@ -19,10 +19,10 @@
## The output SHT_PROBITS is contrary to the user expectation of SHT_NOBITS.
## Issue a warning. See https://github.com/ClangBuiltLinux/linux/issues/1597
-# RUN: ld.lld --script %t/lds %t.o %t/mismatch.o -o %t/out 2>&1 | FileCheck %s --check-prefix=WARN
+# RUN: ld.lld --script %t/lds %t.o %t/mismatch.o -o %t/out 2>&1 | FileCheck %s --check-prefix=WARN --allow-empty
# RUN: llvm-readelf -S -l %t/out | FileCheck %s --check-prefix=CHECK2
-# WARN: warning: section type mismatch for .data_noload_a
+# WARN-NOT: warning:
# CHECK2: Name Type Address Off Size
# CHECK2: .data_noload_a NOBITS 0000000000000000 [[OFF:[0-9a-f]+]] 001001
@@ -45,5 +45,8 @@ SECTIONS {
.data_noload_a (NOLOAD) : { *(.data_noload_a) }
.data_noload_b (0x10000) (NOLOAD) : { *(.data_noload_b) }
.no_input_sec_noload (NOLOAD) : { . += 1; }
- .text (0x20000) : { *(.text) }
+ .text (0x20000) : {
+ *(.text);
+ _start = .;
+ }
}
More information about the llvm-commits
mailing list