[PATCH] D25240: [ELF] Emit warning instead of error, when undefined symbol is not really used.
Eugene Leviant via llvm-commits
llvm-commits at lists.llvm.org
Tue Oct 4 08:41:52 PDT 2016
evgeny777 created this revision.
evgeny777 added reviewers: ruiu, rafael.
evgeny777 added subscribers: grimar, ikudrin, llvm-commits.
evgeny777 set the repository for this revision to rL LLVM.
evgeny777 added a project: lld.
The situation when undefined symbol is not used often takes place, when compiler flags -ffunction-sections -fdata-sections are used in conjunction with linker flag --gc-sections.
In such case we can have undefined symbol which is used by some function collected by linker GC. Both gold and ld add undefined symbol to symtab without reporting any error or warning. This patch makes lld to emit warning instead of error in such cases.
Repository:
rL LLVM
https://reviews.llvm.org/D25240
Files:
ELF/Relocations.cpp
ELF/Symbols.h
ELF/Writer.cpp
test/ELF/libsearch.s
test/ELF/sysroot.s
Index: test/ELF/sysroot.s
===================================================================
--- test/ELF/sysroot.s
+++ test/ELF/sysroot.s
@@ -7,7 +7,7 @@
// REQUIRES: x86
// Should not link because of undefined symbol _bar
-// RUN: not ld.lld -o %t/r %t/m.o 2>&1 \
+// RUN: ld.lld -o %t/r %t/m.o 2>&1 \
// RUN: | FileCheck --check-prefix=UNDEFINED %s
// UNDEFINED: undefined symbol: _bar
Index: test/ELF/libsearch.s
===================================================================
--- test/ELF/libsearch.s
+++ test/ELF/libsearch.s
@@ -16,7 +16,7 @@
// NOLIBRARY: missing arg value for "-l", expected 1 argument.
// Should not link because of undefined symbol _bar
-// RUN: not ld.lld -o %t3 %t.o 2>&1 \
+// RUN: ld.lld -o %t3 %t.o 2>&1 \
// RUN: | FileCheck --check-prefix=UNDEFINED %s
// UNDEFINED: undefined symbol: _bar
Index: ELF/Writer.cpp
===================================================================
--- ELF/Writer.cpp
+++ ELF/Writer.cpp
@@ -317,9 +317,10 @@
std::string Msg = "undefined symbol: ";
Msg += Config->Demangle ? demangle(Sym->getName()) : Sym->getName().str();
+ bool Unused = !Sym->IsRelocTarget && !Sym->symbol()->includeInDynsym();
if (Sym->File)
Msg += " in " + getFilename(Sym->File);
- if (Config->UnresolvedSymbols == UnresolvedPolicy::Warn)
+ if (Config->UnresolvedSymbols == UnresolvedPolicy::Warn || Unused)
warn(Msg);
else
error(Msg);
Index: ELF/Symbols.h
===================================================================
--- ELF/Symbols.h
+++ ELF/Symbols.h
@@ -52,7 +52,7 @@
LazyObjectKind,
};
- SymbolBody(Kind K) : SymbolKind(K) {}
+ SymbolBody(Kind K) : SymbolKind(K), IsRelocTarget(false) {}
Symbol *symbol();
const Symbol *symbol() const {
@@ -121,6 +121,9 @@
// True if this symbol has an entry in the global part of MIPS GOT.
unsigned IsInGlobalMipsGot : 1;
+ // True if the symbol is relocation target.
+ unsigned IsRelocTarget : 1;
+
// The following fields have the same meaning as the ELF symbol attributes.
uint8_t Type; // symbol type
uint8_t StOther; // st_other field value
Index: ELF/Relocations.cpp
===================================================================
--- ELF/Relocations.cpp
+++ ELF/Relocations.cpp
@@ -557,6 +557,7 @@
const RelTy &RI = *I;
SymbolBody &Body = File.getRelocTargetSym(RI);
uint32_t Type = RI.getType(Config->Mips64EL);
+ Body.IsRelocTarget = true;
RelExpr Expr = Target->getRelExpr(Type, Body);
bool Preemptible = isPreemptible(Body, Type);
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D25240.73488.patch
Type: text/x-patch
Size: 2560 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20161004/7583c865/attachment-0001.bin>
More information about the llvm-commits
mailing list