[PATCH] D151144: [lld][ELF] Do not emit warning for NOLOAD output sections

Leonard Chan via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon May 22 12:55:08 PDT 2023


leonardchan created this revision.
leonardchan added reviewers: phosek, peter.smith, MaskRay.
leonardchan added a project: lld.
Herald added subscribers: arichardson, emaste.
Herald added a project: All.
leonardchan requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Much of NOLOAD's intended use is to explicitly change the type of an output section, so we shouldn't flag these as warnings.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D151144

Files:
  lld/ELF/OutputSections.cpp
  lld/test/ELF/linkerscript/noload.s


Index: lld/test/ELF/linkerscript/noload.s
===================================================================
--- lld/test/ELF/linkerscript/noload.s
+++ lld/test/ELF/linkerscript/noload.s
@@ -22,7 +22,7 @@
 # RUN: ld.lld --script %t/lds %t.o %t/mismatch.o -o %t/out 2>&1 | FileCheck %s --check-prefix=WARN
 # RUN: llvm-readelf -S -l %t/out | FileCheck %s --check-prefix=CHECK2
 
-# WARN:   warning: section type mismatch for .data_noload_a
+# WARN-NOT:   warning: section type mismatch for .data_noload_a
 # CHECK2:      Name                 Type     Address          Off               Size
 # CHECK2:      .data_noload_a       NOBITS   0000000000000000 [[OFF:[0-9a-f]+]] 001001
 
Index: lld/ELF/OutputSections.cpp
===================================================================
--- lld/ELF/OutputSections.cpp
+++ lld/ELF/OutputSections.cpp
@@ -118,14 +118,14 @@
           !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));
+        // traditionally 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;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D151144.524443.patch
Type: text/x-patch
Size: 2081 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230522/5618fade/attachment.bin>


More information about the llvm-commits mailing list