Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions docs/userguide/documentation/linker_faq.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
=====================
Expand Down Expand Up @@ -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.*)
Expand Down
4 changes: 2 additions & 2 deletions lib/Readers/ELFReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -425,7 +425,7 @@ eld::Expected<bool> ELFReader<ELFT>::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>(plugin::DiagnosticEntry(
Diag::err_unrecognized_input_file,
{inputFile.getInput()->getResolvedPath().native(),
Expand All @@ -436,7 +436,7 @@ eld::Expected<bool> ELFReader<ELFT>::isCompatible() const {
if (!expCheckFlags.value())
return false;

if (!checkClass())
if (!config.options().noWarnMismatch() && !checkClass())
return std::make_unique<plugin::DiagnosticEntry>(plugin::DiagnosticEntry(
Diag::invalid_elf_class,
{inputFile.getInput()->decoratedPath(), config.targets().getArch()}));
Expand Down
14 changes: 11 additions & 3 deletions test/Common/standalone/WrongArchObject/WrongArchInput.test
Original file line number Diff line number Diff line change
@@ -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.
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion test/RISCV/standalone/Emulation/Emulation.test
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading