Skip to content

Commit a83e08b

Browse files
committed
Simplify unreferenced class error message and only report once
1 parent 1cc3eab commit a83e08b

File tree

2 files changed

+16
-11
lines changed

2 files changed

+16
-11
lines changed

lld/ELF/LinkerScript.cpp

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -808,13 +808,18 @@ void LinkerScript::processSectionCommands() {
808808

809809
// Input sections cannot have a section class parent past this point; they
810810
// must have been assigned to an output section.
811-
for (const auto &[_, sc] : sectionClasses)
812-
for (InputSectionDescription *isd : sc->sc.commands)
813-
for (InputSectionBase *sec : isd->sectionBases)
814-
if (sec->parent && isa<SectionClass>(sec->parent))
815-
errorOrWarn("section '" + sec->name + "' assigned to class '" +
816-
sec->parent->name +
817-
"' but unreferenced by any output section");
811+
for (const auto &[_, sc] : sectionClasses) {
812+
for (InputSectionDescription *isd : sc->sc.commands) {
813+
for (InputSectionBase *sec : isd->sectionBases) {
814+
if (sec->parent && isa<SectionClass>(sec->parent)) {
815+
errorOrWarn("section class '" + sec->parent->name +
816+
"' is unreferenced");
817+
goto nextClass;
818+
}
819+
}
820+
}
821+
nextClass:;
822+
}
818823
}
819824

820825
void LinkerScript::processSymbolAssignments() {

lld/test/ELF/linkerscript/section-class.test

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -142,12 +142,12 @@ SECTIONS {
142142
}
143143

144144
# RUN: not ld.lld -T unreferenced.lds matching.o 2>&1 | \
145-
# RUN: FileCheck %s --check-prefix=UNREFERENCED
145+
# RUN: FileCheck %s --check-prefix=UNREFERENCED -implicit-check-not=error:
146146
# RUN: ld.lld -T unreferenced.lds matching.o -o out --noinhibit-exec 2>&1 | \
147-
# RUN: FileCheck %s --check-prefix=UNREFERENCED-WARN
147+
# RUN: FileCheck %s --check-prefix=UNREFERENCED-WARN -implicit-check-not=error:
148148

149-
# UNREFERENCED: error: section '.rodata.a' assigned to class 'a' but unreferenced by any output section
150-
# UNREFERENCED-WARN: warning: section '.rodata.a' assigned to class 'a' but unreferenced by any output section
149+
# UNREFERENCED: error: section class 'a' is unreferenced
150+
# UNREFERENCED-WARN: warning: section class 'a' is unreferenced
151151

152152
#--- class-references-class.lds
153153
## One section class references another.

0 commit comments

Comments
 (0)