// user is attempting LTO and using a default ar command that doesn't
// understand the LLVM bitcode file. Treat the archive as a group of lazy
// object files.
- if (!file->isEmpty() && !file->hasSymbolTable()) {
- for (const std::pair<MemoryBufferRef, uint64_t> &p :
- getArchiveMembers(mbref)) {
- auto magic = identify_magic(p.first.getBuffer());
- if (magic == file_magic::bitcode ||
- magic == file_magic::elf_relocatable)
- files.push_back(createLazyFile(p.first, path, p.second));
- else
- error(path + ": archive member '" + p.first.getBufferIdentifier() +
- "' is neither ET_REL nor LLVM bitcode");
- }
+ if (file->isEmpty() || file->hasSymbolTable()) {
+ // Handle the regular case.
+ files.push_back(make<ArchiveFile>(std::move(file)));
return;
}
- // Handle the regular case.
- files.push_back(make<ArchiveFile>(std::move(file)));
+ // All files within the archive get the same group ID to allow mutual
+ // references for --warn-backrefs.
+ bool saved = InputFile::isInGroup;
+ InputFile::isInGroup = true;
+ for (const std::pair<MemoryBufferRef, uint64_t> &p :
+ getArchiveMembers(mbref)) {
+ auto magic = identify_magic(p.first.getBuffer());
+ if (magic == file_magic::bitcode || magic == file_magic::elf_relocatable)
+ files.push_back(createLazyFile(p.first, path, p.second));
+ else
+ error(path + ": archive member '" + p.first.getBufferIdentifier() +
+ "' is neither ET_REL nor LLVM bitcode");
+ }
+ InputFile::isInGroup = saved;
+ if (!saved)
+ ++InputFile::nextGroupId;
return;
}
case file_magic::elf_shared_object:
# RUN: echo '.globl bar; bar:' | llvm-mc -filetype=obj -triple=x86_64 - -o %t3.o
# RUN: echo '.globl foo; foo: call bar' | llvm-mc -filetype=obj -triple=x86_64 - -o %t4.o
# RUN: ld.lld --fatal-warnings --warn-backrefs %t1.o --start-lib %t3.o %t4.o --end-lib -o /dev/null
+# RUN: rm -f %t34.a && llvm-ar rcS %t34.a %t3.o %t4.o
+# RUN: ld.lld --fatal-warnings --warn-backrefs %t1.o %t34.a -o /dev/null
## We don't report backward references to weak symbols as they can be overridden later.
# RUN: echo '.weak foo; foo:' | llvm-mc -filetype=obj -triple=x86_64 - -o %tweak.o