Skip to content

Commit

Permalink
[ELF] --warn-backrefs: --defsym does not make a backward reference
Browse files Browse the repository at this point in the history
The interaction between --warn-backrefs was not tested, but if
--defsym-created reference causes archive member extraction, it seems
reasonable to suppress the diagnostic, which was the behavior before #78944.

(cherry picked from commit 9a1ca24)
  • Loading branch information
MaskRay authored and tstellar committed Feb 2, 2024
1 parent 284570a commit 2fe0bca
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
7 changes: 6 additions & 1 deletion lld/ELF/InputFiles.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1788,7 +1788,12 @@ void BinaryFile::parse() {
}

InputFile *elf::createInternalFile(StringRef name) {
return make<InputFile>(InputFile::InternalKind, MemoryBufferRef("", name));
auto *file =
make<InputFile>(InputFile::InternalKind, MemoryBufferRef("", name));
// References from an internal file do not lead to --warn-backrefs
// diagnostics.
file->groupId = 0;
return file;
}

ELFFileBase *elf::createObjFile(MemoryBufferRef mb, StringRef archiveName,
Expand Down
4 changes: 4 additions & 0 deletions lld/test/ELF/warn-backrefs.s
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,10 @@
## -u does not make a backward reference.
# RUN: ld.lld --fatal-warnings --warn-backrefs -u foo %t2.a %t1.o -o /dev/null

## --defsym does not make a backward reference, but it does not suppress the warning due to another file.
# RUN: ld.lld --fatal-warnings --warn-backrefs --defsym=x=foo -e 0 %t2.a -o /dev/null
# RUN: ld.lld --warn-backrefs --defsym=x=foo %t2.a %t1.o -o /dev/null 2>&1 | FileCheck %s

# RUN: not ld.lld --warn-backrefs-exclude='[' 2>&1 | FileCheck --check-prefix=INVALID %s
# INVALID: error: --warn-backrefs-exclude: invalid glob pattern, unmatched '[': [

Expand Down

0 comments on commit 2fe0bca

Please sign in to comment.