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