diff options
author | Sam Clegg <sbc@chromium.org> | 2019-07-03 02:29:02 +0000 |
---|---|---|
committer | Sam Clegg <sbc@chromium.org> | 2019-07-03 02:29:02 +0000 |
commit | 99745896cedbbee5ec9c0343a055e12ccd5d5113 (patch) | |
tree | 6f12788427dc5e896d564dd71ce3a1d9a858b445 | |
parent | ba5a72ff8dc7486d7101c0190bb29d716b75a402 (diff) | |
download | llvm-99745896cedbbee5ec9c0343a055e12ccd5d5113.zip llvm-99745896cedbbee5ec9c0343a055e12ccd5d5113.tar.gz llvm-99745896cedbbee5ec9c0343a055e12ccd5d5113.tar.bz2 |
[ELF] Error on archive with missing index
This matches the wasm lld and GNU ld behavior.
The ELF linker has special handling for bitcode archives but if that
doesn't kick in we probably want to error out rather than silently
ignore the library.
Differential Revision: https://reviews.llvm.org/D63781
llvm-svn: 364998
-rw-r--r-- | lld/ELF/Driver.cpp | 4 | ||||
-rw-r--r-- | lld/test/ELF/archive-no-index.s | 13 | ||||
-rw-r--r-- | lld/test/ELF/lto/archive-no-index.ll | 2 |
3 files changed, 17 insertions, 2 deletions
diff --git a/lld/ELF/Driver.cpp b/lld/ELF/Driver.cpp index 008a6cd..af5bd24 100644 --- a/lld/ELF/Driver.cpp +++ b/lld/ELF/Driver.cpp @@ -223,8 +223,10 @@ void LinkerDriver::addFile(StringRef Path, bool WithLOption) { // default action without the LTO hack described above. for (const std::pair<MemoryBufferRef, uint64_t> &P : getArchiveMembers(MBRef)) - if (identify_magic(P.first.getBuffer()) != file_magic::bitcode) + if (identify_magic(P.first.getBuffer()) != file_magic::bitcode) { + error(Path + ": archive has no index; run ranlib to add one"); return; + } for (const std::pair<MemoryBufferRef, uint64_t> &P : getArchiveMembers(MBRef)) diff --git a/lld/test/ELF/archive-no-index.s b/lld/test/ELF/archive-no-index.s new file mode 100644 index 0000000..adaeaf9 --- /dev/null +++ b/lld/test/ELF/archive-no-index.s @@ -0,0 +1,13 @@ +# REQUIRES: x86 +# Tests error on archive file without a symbol table +# RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux -o %t.o %s +# RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux -o %t.archive.o %S/Inputs/archive.s +# RUN: rm -f %t.a +# RUN: llvm-ar crS %t.a %t.archive.o + +# RUN: not ld.lld -o out.wasm %t.o %t.a 2>&1 | FileCheck %s + +.globl _start +_start: + +# CHECK: error: {{.*}}.a: archive has no index; run ranlib to add one diff --git a/lld/test/ELF/lto/archive-no-index.ll b/lld/test/ELF/lto/archive-no-index.ll index c4dd89a..f7a2cf8 100644 --- a/lld/test/ELF/lto/archive-no-index.ll +++ b/lld/test/ELF/lto/archive-no-index.ll @@ -26,7 +26,7 @@ define i32 @main() { ; RUN: rm -f %t3.a ; RUN: llvm-ar crS %t3.a %t3.o ; RUN: not ld.lld -o /dev/null -emain %t1.o %t3.a 2>&1 | FileCheck -check-prefix=ERR1 %s -; ERR1: error: undefined symbol: f +; ERR1: error: {{.*}}.a: archive has no index; run ranlib to add one ; RUN: rm -f %t4.a ; RUN: llvm-ar cr %t4.a |