[lld] r326911 - Improve --warn-symbol-ordering.
Rui Ueyama via llvm-commits
llvm-commits at lists.llvm.org
Wed Mar 7 09:15:06 PST 2018
Author: ruiu
Date: Wed Mar 7 09:15:06 2018
New Revision: 326911
URL: http://llvm.org/viewvc/llvm-project?rev=326911&view=rev
Log:
Improve --warn-symbol-ordering.
Summary:
I originally tried to simplify code and then noticed that lld doesn't
do what it tells to the user by warn(). It says "unable to order
discarded symbol" but it actually can for sections eliminated by ICF.
With this patch, lld doesn't sort such sections.
Reviewers: jhenderson, rafael
Subscribers: emaste, arichardson, llvm-commits
Differential Revision: https://reviews.llvm.org/D44180
Modified:
lld/trunk/ELF/Writer.cpp
lld/trunk/test/ELF/symbol-ordering-file-icf.s
lld/trunk/test/ELF/symbol-ordering-file-warnings.s
Modified: lld/trunk/ELF/Writer.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Writer.cpp?rev=326911&r1=326910&r2=326911&view=diff
==============================================================================
--- lld/trunk/ELF/Writer.cpp (original)
+++ lld/trunk/ELF/Writer.cpp Wed Mar 7 09:15:06 2018
@@ -1045,28 +1045,35 @@ static DenseMap<const InputSectionBase *
SymbolOrderEntry &Ent = It->second;
Ent.Present = true;
- auto *D = dyn_cast<Defined>(Sym);
- if (Config->WarnSymbolOrdering) {
- if (Sym->isUndefined())
- warn(File->getName() +
- ": unable to order undefined symbol: " + Sym->getName());
- else if (Sym->isShared())
- warn(File->getName() +
- ": unable to order shared symbol: " + Sym->getName());
- else if (D && !D->Section)
- warn(File->getName() +
- ": unable to order absolute symbol: " + Sym->getName());
- else if (D && !D->Section->Live)
- warn(File->getName() +
- ": unable to order discarded symbol: " + Sym->getName());
+ auto Warning = [&](StringRef Msg) {
+ if (Config->WarnSymbolOrdering)
+ warn(File->getName() + ": " + Msg + ": " + Sym->getName());
+ };
+
+ if (Sym->isUndefined()) {
+ Warning("unable to order undefined symbol");
+ continue;
}
- if (!D)
+ if (Sym->isShared()) {
+ Warning("unable to order shared symbol");
continue;
+ }
- if (auto *Sec = dyn_cast_or_null<InputSectionBase>(D->Section)) {
- int &Priority = SectionOrder[cast<InputSectionBase>(Sec->Repl)];
- Priority = std::min(Priority, Ent.Priority);
+ auto *Sec = dyn_cast_or_null<InputSectionBase>(cast<Defined>(Sym)->Section);
+ if (!Sec) {
+ Warning("unable to order absolute symbol");
+ continue;
}
+ if (!Sec->Live) {
+ if (Sec->Repl == Sec)
+ Warning("unable to order discarded symbol");
+ else
+ Warning("unable to order a symbol merged by ICF");
+ continue;
+ }
+
+ int &Priority = SectionOrder[cast<InputSectionBase>(Sec->Repl)];
+ Priority = std::min(Priority, Ent.Priority);
}
}
Modified: lld/trunk/test/ELF/symbol-ordering-file-icf.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/symbol-ordering-file-icf.s?rev=326911&r1=326910&r2=326911&view=diff
==============================================================================
--- lld/trunk/test/ELF/symbol-ordering-file-icf.s (original)
+++ lld/trunk/test/ELF/symbol-ordering-file-icf.s Wed Mar 7 09:15:06 2018
@@ -6,11 +6,10 @@
# RUN: ld.lld --icf=all --symbol-ordering-file %t.order -shared %t.o -o %t.so
# RUN: llvm-nm %t.so | FileCheck %s
-## Check that after ICF merges 'foo' and 'zed' we still
-## place them before 'bar', in according to ordering file.
-# CHECK-DAG: 0000000000001000 T foo
-# CHECK-DAG: 0000000000001000 T zed
-# CHECK-DAG: 0000000000001004 T bar
+## Check that we do not sort ICF'ed symbols 'foo' and 'zed'.
+# CHECK-DAG: 0000000000001000 T bar
+# CHECK-DAG: 0000000000001004 T foo
+# CHECK-DAG: 0000000000001004 T zed
.section .text.foo,"ax", at progbits
.align 4
Modified: lld/trunk/test/ELF/symbol-ordering-file-warnings.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/symbol-ordering-file-warnings.s?rev=326911&r1=326910&r2=326911&view=diff
==============================================================================
--- lld/trunk/test/ELF/symbol-ordering-file-warnings.s (original)
+++ lld/trunk/test/ELF/symbol-ordering-file-warnings.s Wed Mar 7 09:15:06 2018
@@ -109,7 +109,7 @@
# WARN-NOT: warning:
# MISSING: warning: symbol ordering file: no such symbol: missing
# MISSING2: warning: symbol ordering file: no such symbol: missing_sym
-# ICF: warning: {{.*}}1.o: unable to order discarded symbol: icf2
+# ICF: warning: {{.*}}1.o: unable to order a symbol merged by ICF: icf2
# COMDAT: warning: {{.*}}1.o: unable to order discarded symbol: comdat
# COMDAT-NEXT: warning: {{.*}}2.o: unable to order discarded symbol: comdat
# MULTI: warning: {{.*}}2.o: unable to order absolute symbol: multi
More information about the llvm-commits
mailing list