From 9e6088555da8b8b080a8f36a22aef698fc43cba8 Mon Sep 17 00:00:00 2001 From: Steven Ramirez Rosa Date: Tue, 19 May 2026 13:34:18 -0700 Subject: [PATCH] Add support for --no-warn-mismatch Allow users to suppress warnings about incompatible or mismatched input files using the --no-warn-mismatch option. This change disables mismatch diagnostics while preserving normal link behavior and outcomes. Fix: qualcomm#1098 Signed-off-by: Steven Ramirez Rosa --- docs/userguide/documentation/linker_faq.rst | 5 +++-- lib/Readers/ELFReader.cpp | 4 ++-- .../standalone/WrongArchObject/WrongArchInput.test | 14 +++++++++++--- .../32bit/EFlags/Map/FloatABI/FloatABI.test | 2 +- test/RISCV/standalone/Emulation/Emulation.test | 2 +- 5 files changed, 18 insertions(+), 9 deletions(-) diff --git a/docs/userguide/documentation/linker_faq.rst b/docs/userguide/documentation/linker_faq.rst index 9d583d6ea..39763c78c 100644 --- a/docs/userguide/documentation/linker_faq.rst +++ b/docs/userguide/documentation/linker_faq.rst @@ -1323,7 +1323,8 @@ If any object file differs, the linker cannot interpret it correctly and will produce this error. **How to verify:** You can inspect the object file using by using tools like -llvm-readelf. +llvm-readelf. You can enable/disable this message by using the +*--[no-]warn-mismatch* flag Input File to Linker ===================== @@ -1417,7 +1418,7 @@ specification to do the following: .. list-table:: Input section patterns :widths: 35 65 :header-rows: 1 - + * - Specification - Description * - dir/subdir/init.lib:init.o(.text.*) diff --git a/lib/Readers/ELFReader.cpp b/lib/Readers/ELFReader.cpp index 4dab105df..2f9974b9d 100644 --- a/lib/Readers/ELFReader.cpp +++ b/lib/Readers/ELFReader.cpp @@ -425,7 +425,7 @@ eld::Expected ELFReader::isCompatible() const { const InputFile &inputFile = this->m_InputFile; LinkerConfig &config = this->m_Module.getConfig(); - if (!checkMachine()) + if (!config.options().noWarnMismatch() && !checkMachine()) return std::make_unique(plugin::DiagnosticEntry( Diag::err_unrecognized_input_file, {inputFile.getInput()->getResolvedPath().native(), @@ -436,7 +436,7 @@ eld::Expected ELFReader::isCompatible() const { if (!expCheckFlags.value()) return false; - if (!checkClass()) + if (!config.options().noWarnMismatch() && !checkClass()) return std::make_unique(plugin::DiagnosticEntry( Diag::invalid_elf_class, {inputFile.getInput()->decoratedPath(), config.targets().getArch()})); diff --git a/test/Common/standalone/WrongArchObject/WrongArchInput.test b/test/Common/standalone/WrongArchObject/WrongArchInput.test index 005fd9060..96baa69d4 100644 --- a/test/Common/standalone/WrongArchObject/WrongArchInput.test +++ b/test/Common/standalone/WrongArchObject/WrongArchInput.test @@ -1,11 +1,19 @@ +#BEGIN_COMMENT +# The --no-warn-mismatch test for dynamic is crashing in the DynamicELFReader. +# Add test as soon as this is fixed. +#END_COMMENT RUN: %yaml2obj %p/Inputs/1.yaml -o %t.1.o RUN: %clang %clangopts -c %p/Inputs/2.c -o %t1.o -RUN: %not %link %emulation %linkopts %t.1.o %t1.o -o %t2.out 2>&1 | %filecheck %s +RUN: %not %link %emulation %linkopts --warn-mismatch %t.1.o %t1.o -o %t2.out 2>&1 | %filecheck %s +RUN: %link %emulation %linkopts --no-warn-mismatch %t.1.o %t1.o -o %t2.out 2>&1 | %filecheck %s -check-prefix=NOERR --allow-empty RUN: %ar cr %aropts %t1.a %t.1.o -RUN: %not %link %emulation %linkopts %t1.o --whole-archive %t1.a -o %t3.out 2>&1 | %filecheck %s -check-prefix=ARCHIVE +RUN: %not %link %emulation %linkopts --warn-mismatch %t1.o --whole-archive %t1.a -o %t3.out 2>&1 | %filecheck %s -check-prefix=ARCHIVE +RUN: %link %emulation %linkopts --no-warn-mismatch %t1.o --whole-archive %t1.a -o %t3.out 2>&1 | %filecheck %s -check-prefix=ARCHIVE_NOERR --allow-empty RUN: %yaml2obj %p/Inputs/1.yaml -DTYPE=ET_DYN -o %t.lib.so -RUN: %not %link %emulation -Bdynamic %t1.o -L%p/Inputs %t.lib.so 2>&1 | %filecheck %s -check-prefix=DYNAMIC +RUN: %not %link %emulation -Bdynamic --warn-mismatch %t1.o -L%p/Inputs %t.lib.so 2>&1 | %filecheck %s -check-prefix=DYNAMIC CHECK: Error: cannot recognize the format of file {{[` -\(\)_A-Za-z0-9.\\/:]+}}1.o'. object format or given target machine ({{[` -\(\)_A-Za-z0-9.\\/:]+}}) is incompatible. +NOERR-NOT: Error: cannot recognize the format of file ARCHIVE: Error: cannot recognize the format of file {{[` -\(\)_A-Za-z0-9.\\/:]+}}.a'. object format or given target machine ({{[` -\(\)_A-Za-z0-9.\\/:]+}}) is incompatible. +ARCHIVE_NOERR-NOT: Error: cannot recognize the format of file DYNAMIC: Error: cannot recognize the format of file {{[` -\(\)_A-Za-z0-9.\\/:]+}}lib.so'. object format or given target machine ({{[` -\(\)_A-Za-z0-9.\\/:]+}}) is incompatible. \ No newline at end of file diff --git a/test/RISCV/standalone/32bit/EFlags/Map/FloatABI/FloatABI.test b/test/RISCV/standalone/32bit/EFlags/Map/FloatABI/FloatABI.test index 23bab5216..6f29cb94e 100644 --- a/test/RISCV/standalone/32bit/EFlags/Map/FloatABI/FloatABI.test +++ b/test/RISCV/standalone/32bit/EFlags/Map/FloatABI/FloatABI.test @@ -5,7 +5,7 @@ #END_COMMENT RUN: %yaml2obj %p/Inputs/float.yaml -o %t.o RUN: %link %linkopts %t.o -o %t1.out -M 2>&1 | %filecheck --check-prefix=FLOATABI %s -RUN: %not %link -m elf64lriscv -march riscv64 %t.o -o %t1.out -M 2>&1 | %filecheck --check-prefix=ERROR %s +RUN: %not %link -m elf64lriscv -march riscv64 %t.o -o %t1.out -M --warn-mismatch 2>&1 | %filecheck --check-prefix=ERROR %s #FLOATABI: Single #ERROR: riscv64 diff --git a/test/RISCV/standalone/Emulation/Emulation.test b/test/RISCV/standalone/Emulation/Emulation.test index 26a168ca0..19862e876 100644 --- a/test/RISCV/standalone/Emulation/Emulation.test +++ b/test/RISCV/standalone/Emulation/Emulation.test @@ -7,7 +7,7 @@ RUN: %clang %clangopts -o %t1.1.32.o %p/Inputs/1.c -c -target riscv32 RUN: %eld -o %t1.1.32.out %t1.1.32.o -m elf32lriscv RUN: %readelf -h %t1.1.32.out | %filecheck %s --check-prefix RISCV32 RUN: %clang %clangopts -o %t1.1.64.o %p/Inputs/1.c -c -target riscv64 -RUN: %not %eld -o %t1.1.64.out %t1.1.64.o -m elf32lriscv 2>&1 | %filecheck %s --check-prefix RISCV64ERR +RUN: %not %eld -o %t1.1.64.out %t1.1.64.o -m elf32lriscv --warn-mismatch 2>&1 | %filecheck %s --check-prefix RISCV64ERR RUN: %eld -o %t1.1.64.out %t1.1.64.o -m elf64lriscv RUN: %readelf -h %t1.1.64.out | %filecheck %s --check-prefix RISCV64 #END_TEST