From: Fangrui Song Date: Wed, 9 Feb 2022 05:45:55 +0000 (-0800) Subject: [ELF] --warn-backrefs: suppress warnings for backward references within the archive X-Git-Tag: upstream/15.0.7~17259 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=99580e29d821beeaf75345deb3e4cc2c6808bfc0;p=platform%2Fupstream%2Fllvm.git [ELF] --warn-backrefs: suppress warnings for backward references within the archive --- diff --git a/lld/ELF/Driver.cpp b/lld/ELF/Driver.cpp index 3a480fc..e6a7731 100644 --- a/lld/ELF/Driver.cpp +++ b/lld/ELF/Driver.cpp @@ -236,22 +236,28 @@ void LinkerDriver::addFile(StringRef path, bool withLOption) { // 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 &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(std::move(file))); return; } - // Handle the regular case. - files.push_back(make(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 &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: diff --git a/lld/test/ELF/warn-backrefs.s b/lld/test/ELF/warn-backrefs.s index a686686..907f042 100644 --- a/lld/test/ELF/warn-backrefs.s +++ b/lld/test/ELF/warn-backrefs.s @@ -63,6 +63,8 @@ # 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