[lld] cb0a4bb - [ELF] Change (NOLOAD) section type mismatch error to warning

Yung, Douglas via llvm-commits llvm-commits at lists.llvm.org
Fri Feb 18 12:07:49 PST 2022


Hi,

Your change seems to have caused a test failure on the PS4 Windows bot:

https://lab.llvm.org/buildbot/#/builders/216/builds/126

******************** TEST 'lld :: ELF/linkerscript/noload.s' FAILED ********************
shell parser error on: ": 'RUN: at line 22';   c:\\buildbot-root\\llvm-clang-x86_64-sie-win\\build\\bin\\ld.lld.exe --script C:\\buildbot-root\\llvm-clang-x86_64-sie-win\\build\\tools\\lld\\test\\ELF\\linkerscript\\Output\\noload.s.tmp/lds C:\\buildbot-root\\llvm-clang-x86_64-sie-win\\build\\tools\\lld\\test\\ELF\\linkerscript\\Output\\noload.s.tmp.o C:\\buildbot-root\\llvm-clang-x86_64-sie-win\\build\\tools\\lld\\test\\ELF\\linkerscript\\Output\\noload.s.tmp/mismatch.o -o C:\\buildbot-root\\llvm-clang-x86_64-sie-win\\build\\tools\\lld\\test\\ELF\\linkerscript\\Output\\noload.s.tmp/out 2>&1 |& c:\\buildbot-root\\llvm-clang-x86_64-sie-win\\build\\bin\\filecheck.exe C:\\buildbot-root\\llvm-clang-x86_64-sie-win\\llvm-project\\lld\\test\\ELF\\linkerscript\\noload.s --check-prefix=WARN"
********************

Can you please take a look if you are not already?

Thanks!

Douglas Yunt

-----Original Message-----
From: llvm-commits <llvm-commits-bounces at lists.llvm.org> On Behalf Of Fangrui Song via llvm-commits
Sent: Friday, February 18, 2022 11:21
To: llvm-commits at lists.llvm.org
Subject: [lld] cb0a4bb - [ELF] Change (NOLOAD) section type mismatch error to warning


Author: Fangrui Song
Date: 2022-02-18T11:20:36-08:00
New Revision: cb0a4bb5be10636aaec3ecb56ed586dee3eb0b9e

URL: https://urldefense.com/v3/__https://github.com/llvm/llvm-project/commit/cb0a4bb5be10636aaec3ecb56ed586dee3eb0b9e__;!!JmoZiZGBv3RvKRSx!sTkInYMJoMcoTEjdez4hFDU1w_g-zN7rgpNUVv47JmxC1Alwmwa9G_io9E0XJv_qVA$
DIFF: https://urldefense.com/v3/__https://github.com/llvm/llvm-project/commit/cb0a4bb5be10636aaec3ecb56ed586dee3eb0b9e.diff__;!!JmoZiZGBv3RvKRSx!sTkInYMJoMcoTEjdez4hFDU1w_g-zN7rgpNUVv47JmxC1Alwmwa9G_io9E3pl4z9mA$ 

LOG: [ELF] Change (NOLOAD) section type mismatch error to warning

Making a (NOLOAD) section SHT_PROGBITS is fishy (the user may expect all-zero content, but the linker does not check that), but some projects (e.g. Linux kernel https://urldefense.com/v3/__https://github.com/ClangBuiltLinux/linux/issues/1597__;!!JmoZiZGBv3RvKRSx!sTkInYMJoMcoTEjdez4hFDU1w_g-zN7rgpNUVv47JmxC1Alwmwa9G_io9E3OD-ajEA$ ) traditionally rely on the behavior. Issue a warning to not break them.

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 2b5deecdcec7..252108b464b2 100644
--- a/lld/ELF/OutputSections.cpp
+++ b/lld/ELF/OutputSections.cpp
@@ -112,11 +112,16 @@ void OutputSection::commitSection(InputSection *isec) {
     if (hasInputSections || typeIsSet) {
       if (typeIsSet || !canMergeToProgbits(type) ||
           !canMergeToProgbits(isec->type)) {
-        errorOrWarn("section type mismatch for " + isec->name + "\n>>> " +
-                    toString(isec) + ": " +
-                    getELFSectionTypeName(config->emachine, isec->type) +
-                    "\n>>> output section " + name + ": " +
-                    getELFSectionTypeName(config->emachine, type));
+        // Changing the type of a (NOLOAD) section is fishy, but some projects
+        // (e.g. https://urldefense.com/v3/__https://github.com/ClangBuiltLinux/linux/issues/1597__;!!JmoZiZGBv3RvKRSx!sTkInYMJoMcoTEjdez4hFDU1w_g-zN7rgpNUVv47JmxC1Alwmwa9G_io9E3OD-ajEA$ )
+        // 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));
       }
       type = SHT_PROGBITS;
     } else {

diff  --git a/lld/test/ELF/linkerscript/noload.s b/lld/test/ELF/linkerscript/noload.s
index 92afadc9b263..1cc09670e8b1 100644
--- a/lld/test/ELF/linkerscript/noload.s
+++ b/lld/test/ELF/linkerscript/noload.s
@@ -17,9 +17,14 @@
 # CHECK:      00 .data_noload_a .data_noload_b .no_input_sec_noload {{$}}
 # CHECK:      01 .text {{$}}
 
-# RUN: not ld.lld --script %t/lds %t.o %t/mismatch.o -o /dev/null 2>&1 | FileCheck %s --check-prefix=ERR
-
-# ERR: error: section type mismatch for .data_noload_a
+## The output SHT_PROBITS is contrary to the user expectation of SHT_NOBITS.
+## Issue a warning. See 
+https://urldefense.com/v3/__https://github.com/ClangBuiltLinux/linux/is
+sues/1597__;!!JmoZiZGBv3RvKRSx!sTkInYMJoMcoTEjdez4hFDU1w_g-zN7rgpNUVv47
+JmxC1Alwmwa9G_io9E3OD-ajEA$ # 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
+# CHECK2:      Name                 Type     Address          Off               Size
+# CHECK2:      .data_noload_a       PROGBITS 0000000000000000 [[OFF:[0-9a-f]+]] 001001
 
 #--- asm
 .section .text,"ax", at progbits


        
_______________________________________________
llvm-commits mailing list
llvm-commits at lists.llvm.org
https://urldefense.com/v3/__https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits__;!!JmoZiZGBv3RvKRSx!sTkInYMJoMcoTEjdez4hFDU1w_g-zN7rgpNUVv47JmxC1Alwmwa9G_io9E3r_2nXxw$ 


More information about the llvm-commits mailing list