forked from OSchip/llvm-project
[WebAssembly] Error on archives without a symbol index
This is fairly common with wasm since GNU ar (most likely the system ar) doesn't support the wasm object format so user who don't override AR will end up with archives without an index. We don't want to silently ignore this issue. In the future we could choose to instead behave like the ELF backend and read the symbols from each object file in the archive if they are all of the same type. However, error'ing out seem like a conservative approach for now. Fixes: PR42376 Differential Revision: https://reviews.llvm.org/D63739 llvm-svn: 364338
This commit is contained in:
parent
4577b8c17c
commit
61d70e4a93
|
@ -0,0 +1,13 @@
|
|||
; Tests error on archive file without a symbol table
|
||||
; RUN: llvm-as -o %t.o %s
|
||||
; RUN: llvm-as -o %t.archive.o %S/Inputs/archive1.ll
|
||||
; RUN: rm -f %t.a
|
||||
; RUN: llvm-ar crS %t.a %t.archive.o
|
||||
|
||||
; RUN: not wasm-ld -o out.wasm %t.o %t.a 2>&1 | FileCheck %s
|
||||
|
||||
define i32 @_start() {
|
||||
ret i32 0
|
||||
}
|
||||
|
||||
; CHECK: archive has no index; run ranlib to add one
|
|
@ -225,6 +225,11 @@ void LinkerDriver::addFile(StringRef Path) {
|
|||
|
||||
switch (identify_magic(MBRef.getBuffer())) {
|
||||
case file_magic::archive: {
|
||||
SmallString<128> ImportFile = Path;
|
||||
path::replace_extension(ImportFile, ".imports");
|
||||
if (fs::exists(ImportFile))
|
||||
readImportFile(ImportFile.str());
|
||||
|
||||
// Handle -whole-archive.
|
||||
if (InWholeArchive) {
|
||||
for (MemoryBufferRef &M : getArchiveMembers(MBRef))
|
||||
|
@ -232,10 +237,13 @@ void LinkerDriver::addFile(StringRef Path) {
|
|||
return;
|
||||
}
|
||||
|
||||
SmallString<128> ImportFile = Path;
|
||||
path::replace_extension(ImportFile, ".imports");
|
||||
if (fs::exists(ImportFile))
|
||||
readImportFile(ImportFile.str());
|
||||
std::unique_ptr<Archive> File =
|
||||
CHECK(Archive::create(MBRef), Path + ": failed to parse archive");
|
||||
|
||||
if (!File->isEmpty() && !File->hasSymbolTable()) {
|
||||
error(MBRef.getBufferIdentifier() +
|
||||
": archive has no index; run ranlib to add one");
|
||||
}
|
||||
|
||||
Files.push_back(make<ArchiveFile>(MBRef));
|
||||
return;
|
||||
|
|
Loading…
Reference in New Issue