@@ -236,22 +236,28 @@ void LinkerDriver::addFile(StringRef path, bool withLOption) {
236236 // user is attempting LTO and using a default ar command that doesn't
237237 // understand the LLVM bitcode file. Treat the archive as a group of lazy
238238 // object files.
239- if (!file->isEmpty () && !file->hasSymbolTable ()) {
240- for (const std::pair<MemoryBufferRef, uint64_t > &p :
241- getArchiveMembers (mbref)) {
242- auto magic = identify_magic (p.first .getBuffer ());
243- if (magic == file_magic::bitcode ||
244- magic == file_magic::elf_relocatable)
245- files.push_back (createLazyFile (p.first , path, p.second ));
246- else
247- error (path + " : archive member '" + p.first .getBufferIdentifier () +
248- " ' is neither ET_REL nor LLVM bitcode" );
249- }
239+ if (file->isEmpty () || file->hasSymbolTable ()) {
240+ // Handle the regular case.
241+ files.push_back (make<ArchiveFile>(std::move (file)));
250242 return ;
251243 }
252244
253- // Handle the regular case.
254- files.push_back (make<ArchiveFile>(std::move (file)));
245+ // All files within the archive get the same group ID to allow mutual
246+ // references for --warn-backrefs.
247+ bool saved = InputFile::isInGroup;
248+ InputFile::isInGroup = true ;
249+ for (const std::pair<MemoryBufferRef, uint64_t > &p :
250+ getArchiveMembers (mbref)) {
251+ auto magic = identify_magic (p.first .getBuffer ());
252+ if (magic == file_magic::bitcode || magic == file_magic::elf_relocatable)
253+ files.push_back (createLazyFile (p.first , path, p.second ));
254+ else
255+ error (path + " : archive member '" + p.first .getBufferIdentifier () +
256+ " ' is neither ET_REL nor LLVM bitcode" );
257+ }
258+ InputFile::isInGroup = saved;
259+ if (!saved)
260+ ++InputFile::nextGroupId;
255261 return ;
256262 }
257263 case file_magic::elf_shared_object:
0 commit comments