[llvm] r304719 - Symbols re-defined with -wrap and -defsym need to be excluded from inter-
Dmitry Mikulin via llvm-commits
llvm-commits at lists.llvm.org
Mon Jun 5 09:24:26 PDT 2017
Author: dmikulin
Date: Mon Jun 5 11:24:25 2017
New Revision: 304719
URL: http://llvm.org/viewvc/llvm-project?rev=304719&view=rev
Log:
Symbols re-defined with -wrap and -defsym need to be excluded from inter-
procedural optimizations to prevent dropping symbols and allow the linker
to process re-directs.
PR33145: --wrap doesn't work with lto.
Differential Revision: https://reviews.llvm.org/D33621
Added:
llvm/trunk/test/LTO/Resolution/X86/linker-redef.ll
Modified:
llvm/trunk/include/llvm/LTO/LTO.h
llvm/trunk/lib/LTO/LTO.cpp
llvm/trunk/tools/llvm-lto2/llvm-lto2.cpp
Modified: llvm/trunk/include/llvm/LTO/LTO.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/LTO/LTO.h?rev=304719&r1=304718&r2=304719&view=diff
==============================================================================
--- llvm/trunk/include/llvm/LTO/LTO.h (original)
+++ llvm/trunk/include/llvm/LTO/LTO.h Mon Jun 5 11:24:25 2017
@@ -366,8 +366,9 @@ private:
/// each global symbol based on its internal resolution of that symbol.
struct SymbolResolution {
SymbolResolution()
- : Prevailing(0), FinalDefinitionInLinkageUnit(0), VisibleToRegularObj(0) {
- }
+ : Prevailing(0), FinalDefinitionInLinkageUnit(0), VisibleToRegularObj(0),
+ LinkerRedefined(0) {}
+
/// The linker has chosen this definition of the symbol.
unsigned Prevailing : 1;
@@ -377,6 +378,10 @@ struct SymbolResolution {
/// The definition of this symbol is visible outside of the LTO unit.
unsigned VisibleToRegularObj : 1;
+
+ /// Linker redefined version of the symbol which appeared in -wrap or -defsym
+ /// linker option.
+ unsigned LinkerRedefined : 1;
};
} // namespace lto
Modified: llvm/trunk/lib/LTO/LTO.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/LTO/LTO.cpp?rev=304719&r1=304718&r2=304719&view=diff
==============================================================================
--- llvm/trunk/lib/LTO/LTO.cpp (original)
+++ llvm/trunk/lib/LTO/LTO.cpp Mon Jun 5 11:24:25 2017
@@ -405,10 +405,11 @@ void LTO::addSymbolToGlobalRes(const Inp
if (Res.Prevailing)
GlobalRes.IRName = Sym.getIRName();
- // Set the partition to external if we know it is used elsewhere, e.g.
- // it is visible to a regular object, is referenced from llvm.compiler_used,
- // or was already recorded as being referenced from a different partition.
- if (Res.VisibleToRegularObj || Sym.isUsed() ||
+ // Set the partition to external if we know it is re-defined by the linker
+ // with -defsym or -wrap options, used elsewhere, e.g. it is visible to a
+ // regular object, is referenced from llvm.compiler_used, or was already
+ // recorded as being referenced from a different partition.
+ if (Res.LinkerRedefined || Res.VisibleToRegularObj || Sym.isUsed() ||
(GlobalRes.Partition != GlobalResolution::Unknown &&
GlobalRes.Partition != Partition)) {
GlobalRes.Partition = GlobalResolution::External;
@@ -439,6 +440,8 @@ static void writeToResolutionFile(raw_os
OS << 'l';
if (Res.VisibleToRegularObj)
OS << 'x';
+ if (Res.LinkerRedefined)
+ OS << 'r';
OS << '\n';
}
OS.flush();
@@ -543,6 +546,12 @@ Error LTO::addRegularLTO(BitcodeModule B
if (Sym.isUndefined())
continue;
Keep.push_back(GV);
+ // For symbols re-defined with linker -wrap and -defsym options,
+ // set the linkage to weak to inhibit IPO. The linkage will be
+ // restored by the linker.
+ if (Res.LinkerRedefined)
+ GV->setLinkage(GlobalValue::WeakAnyLinkage);
+
GlobalValue::LinkageTypes OriginalLinkage = GV->getLinkage();
if (GlobalValue::isLinkOnceLinkage(OriginalLinkage))
GV->setLinkage(GlobalValue::getWeakLinkage(
Added: llvm/trunk/test/LTO/Resolution/X86/linker-redef.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/LTO/Resolution/X86/linker-redef.ll?rev=304719&view=auto
==============================================================================
--- llvm/trunk/test/LTO/Resolution/X86/linker-redef.ll (added)
+++ llvm/trunk/test/LTO/Resolution/X86/linker-redef.ll Mon Jun 5 11:24:25 2017
@@ -0,0 +1,16 @@
+; RUN: llvm-as %s -o %t.o
+; RUN: llvm-lto2 run -o %t1.o %t.o -r %t.o,bar,pr
+; RUN: llvm-readobj -t %t1.o.0 | FileCheck %s
+
+; CHECK: Name: bar
+; CHECK-NEXT: Value:
+; CHECK-NEXT: Size:
+; CHECK-NEXT: Binding: Weak
+; CHECK-NEXT: Type: Function
+
+target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
+target triple = "x86_64-unknown-linux-gnu"
+
+define void @bar() {
+ ret void
+}
Modified: llvm/trunk/tools/llvm-lto2/llvm-lto2.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-lto2/llvm-lto2.cpp?rev=304719&r1=304718&r2=304719&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-lto2/llvm-lto2.cpp (original)
+++ llvm/trunk/tools/llvm-lto2/llvm-lto2.cpp Mon Jun 5 11:24:25 2017
@@ -162,6 +162,8 @@ static int run(int argc, char **argv) {
Res.FinalDefinitionInLinkageUnit = true;
else if (C == 'x')
Res.VisibleToRegularObj = true;
+ else if (C == 'r')
+ Res.LinkerRedefined = true;
else {
llvm::errs() << "invalid character " << C << " in resolution: " << R
<< '\n';
More information about the llvm-commits
mailing list