[lld] r364998 - [ELF] Error on archive with missing index

Sam Clegg via llvm-commits llvm-commits at lists.llvm.org
Tue Jul 2 19:29:03 PDT 2019


Author: sbc
Date: Tue Jul  2 19:29:02 2019
New Revision: 364998

URL: http://llvm.org/viewvc/llvm-project?rev=364998&view=rev
Log:
[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

Added:
    lld/trunk/test/ELF/archive-no-index.s
Modified:
    lld/trunk/ELF/Driver.cpp
    lld/trunk/test/ELF/lto/archive-no-index.ll

Modified: lld/trunk/ELF/Driver.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Driver.cpp?rev=364998&r1=364997&r2=364998&view=diff
==============================================================================
--- lld/trunk/ELF/Driver.cpp (original)
+++ lld/trunk/ELF/Driver.cpp Tue Jul  2 19:29:02 2019
@@ -223,8 +223,10 @@ void LinkerDriver::addFile(StringRef Pat
       // 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))

Added: lld/trunk/test/ELF/archive-no-index.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/archive-no-index.s?rev=364998&view=auto
==============================================================================
--- lld/trunk/test/ELF/archive-no-index.s (added)
+++ lld/trunk/test/ELF/archive-no-index.s Tue Jul  2 19:29:02 2019
@@ -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

Modified: lld/trunk/test/ELF/lto/archive-no-index.ll
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/lto/archive-no-index.ll?rev=364998&r1=364997&r2=364998&view=diff
==============================================================================
--- lld/trunk/test/ELF/lto/archive-no-index.ll (original)
+++ lld/trunk/test/ELF/lto/archive-no-index.ll Tue Jul  2 19:29:02 2019
@@ -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




More information about the llvm-commits mailing list