Skip to content

Commit 2fe0bca

Browse files
MaskRaytstellar
authored andcommitted
[ELF] --warn-backrefs: --defsym does not make a backward reference
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)
1 parent 284570a commit 2fe0bca

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

lld/ELF/InputFiles.cpp

+6-1
Original file line numberDiff line numberDiff line change
@@ -1788,7 +1788,12 @@ void BinaryFile::parse() {
17881788
}
17891789

17901790
InputFile *elf::createInternalFile(StringRef name) {
1791-
return make<InputFile>(InputFile::InternalKind, MemoryBufferRef("", name));
1791+
auto *file =
1792+
make<InputFile>(InputFile::InternalKind, MemoryBufferRef("", name));
1793+
// References from an internal file do not lead to --warn-backrefs
1794+
// diagnostics.
1795+
file->groupId = 0;
1796+
return file;
17921797
}
17931798

17941799
ELFFileBase *elf::createObjFile(MemoryBufferRef mb, StringRef archiveName,

lld/test/ELF/warn-backrefs.s

+4
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,10 @@
100100
## -u does not make a backward reference.
101101
# RUN: ld.lld --fatal-warnings --warn-backrefs -u foo %t2.a %t1.o -o /dev/null
102102

103+
## --defsym does not make a backward reference, but it does not suppress the warning due to another file.
104+
# RUN: ld.lld --fatal-warnings --warn-backrefs --defsym=x=foo -e 0 %t2.a -o /dev/null
105+
# RUN: ld.lld --warn-backrefs --defsym=x=foo %t2.a %t1.o -o /dev/null 2>&1 | FileCheck %s
106+
103107
# RUN: not ld.lld --warn-backrefs-exclude='[' 2>&1 | FileCheck --check-prefix=INVALID %s
104108
# INVALID: error: --warn-backrefs-exclude: invalid glob pattern, unmatched '[': [
105109

0 commit comments

Comments
 (0)