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://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));
}
type = SHT_PROGBITS;
} else {
# 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://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: 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",@progbits