[llvm] r320794 - [LLVMgold] Don't set undefined symbol as prevailing

Eugene Leviant via llvm-commits llvm-commits at lists.llvm.org
Fri Dec 15 01:18:21 PST 2017


Author: evgeny777
Date: Fri Dec 15 01:18:21 2017
New Revision: 320794

URL: http://llvm.org/viewvc/llvm-project?rev=320794&view=rev
Log:
[LLVMgold] Don't set undefined symbol as prevailing

Differential revision: https://reviews.llvm.org/D41113

Modified:
    llvm/trunk/lib/LTO/LTO.cpp
    llvm/trunk/test/LTO/X86/symver-asm.ll
    llvm/trunk/test/ThinLTO/X86/module_asm2.ll
    llvm/trunk/tools/gold/gold-plugin.cpp

Modified: llvm/trunk/lib/LTO/LTO.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/LTO/LTO.cpp?rev=320794&r1=320793&r2=320794&view=diff
==============================================================================
--- llvm/trunk/lib/LTO/LTO.cpp (original)
+++ llvm/trunk/lib/LTO/LTO.cpp Fri Dec 15 01:18:21 2017
@@ -416,8 +416,11 @@ void LTO::addModuleToGlobalRes(ArrayRef<
 
     auto &GlobalRes = GlobalResolutions[Sym.getName()];
     GlobalRes.UnnamedAddr &= Sym.isUnnamedAddr();
-    if (Res.Prevailing)
+    if (Res.Prevailing) {
+      assert((GlobalRes.IRName.empty() || !Sym.getIRName().empty()) &&
+             "Overriding existing resolution with undefined asm symbol");
       GlobalRes.IRName = Sym.getIRName();
+    }
 
     // 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

Modified: llvm/trunk/test/LTO/X86/symver-asm.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/LTO/X86/symver-asm.ll?rev=320794&r1=320793&r2=320794&view=diff
==============================================================================
--- llvm/trunk/test/LTO/X86/symver-asm.ll (original)
+++ llvm/trunk/test/LTO/X86/symver-asm.ll Fri Dec 15 01:18:21 2017
@@ -1,7 +1,7 @@
 ; RUN: llvm-as < %s >%t1
 ; RUN: llvm-lto -exported-symbol=io_cancel_0_4 -exported-symbol=io_cancel_weak_0_4 -exported-symbol=foo -o %t2 %t1
 ; RUN: llvm-nm %t2 | FileCheck %s
-; RUN: llvm-lto2 run -r %t1,io_cancel_0_4,plx -r %t1,io_cancel_0_4,plx -r %t1,io_cancel_local_0_4,plx -r %t1,io_cancel_weak_0_4,plx -r %t1,io_cancel_weak_0_4,plx -r %t1,io_cancel@@LIBAIO_0.4,plx -r %t1,io_cancel_weak@@LIBAIO_0.4,plx -r %t1,io_cancel_weak@@LIBAIO_0.4.1,plx -r %t1,foo,plx -r %t1,foo,plx -r %t1,foo@@VER1,plx -o %t3 %t1 -save-temps
+; RUN: llvm-lto2 run -r %t1,io_cancel_0_4,plx -r %t1,io_cancel_0_4,lx -r %t1,io_cancel_local_0_4,plx -r %t1,io_cancel_weak_0_4,plx -r %t1,io_cancel_weak_0_4,lx -r %t1,io_cancel@@LIBAIO_0.4,plx -r %t1,io_cancel_weak@@LIBAIO_0.4,plx -r %t1,io_cancel_weak@@LIBAIO_0.4.1,plx -r %t1,foo,plx -r %t1,foo,lx -r %t1,foo@@VER1,plx -o %t3 %t1 -save-temps
 ; RUN: llvm-nm %t3.0 | FileCheck %s
 ; RUN: llvm-dis %t3.0.2.internalize.bc -o - | FileCheck %s --check-prefix=INTERN
 

Modified: llvm/trunk/test/ThinLTO/X86/module_asm2.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/ThinLTO/X86/module_asm2.ll?rev=320794&r1=320793&r2=320794&view=diff
==============================================================================
--- llvm/trunk/test/ThinLTO/X86/module_asm2.ll (original)
+++ llvm/trunk/test/ThinLTO/X86/module_asm2.ll Fri Dec 15 01:18:21 2017
@@ -11,9 +11,9 @@
 ; RUN: llvm-lto2 run %t1.bc %t2.bc -o %t.o -save-temps \
 ; RUN:     -r=%t1.bc,foo,plx \
 ; RUN:     -r=%t1.bc,globalfunc,plx \
-; RUN:     -r=%t1.bc,globalfunc,plx \
-; RUN:     -r=%t1.bc,weakfunc,plx \
+; RUN:     -r=%t1.bc,globalfunc,lx \
 ; RUN:     -r=%t1.bc,weakfunc,plx \
+; RUN:     -r=%t1.bc,weakfunc,lx \
 ; RUN:     -r=%t1.bc,b,pl \
 ; RUN:     -r=%t1.bc,x,pl \
 ; RUN:     -r=%t1.bc,func1,pl \

Modified: llvm/trunk/tools/gold/gold-plugin.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/gold/gold-plugin.cpp?rev=320794&r1=320793&r2=320794&view=diff
==============================================================================
--- llvm/trunk/tools/gold/gold-plugin.cpp (original)
+++ llvm/trunk/tools/gold/gold-plugin.cpp Fri Dec 15 01:18:21 2017
@@ -619,6 +619,10 @@ static bool isValidCIdentifier(StringRef
                      [](char C) { return C == '_' || isAlnum(C); });
 }
 
+static bool isUndefined(ld_plugin_symbol &Sym) {
+  return Sym.def == LDPK_UNDEF || Sym.def == LDPK_WEAKUNDEF;
+}
+
 static void addModule(LTO &Lto, claimed_file &F, const void *View,
                       StringRef Filename) {
   MemoryBufferRef BufferRef(StringRef((const char *)View, F.filesize),
@@ -656,16 +660,16 @@ static void addModule(LTO &Lto, claimed_
       break;
 
     case LDPR_PREVAILING_DEF_IRONLY:
-      R.Prevailing = true;
+      R.Prevailing = !isUndefined(Sym);
       break;
 
     case LDPR_PREVAILING_DEF:
-      R.Prevailing = true;
+      R.Prevailing = !isUndefined(Sym);
       R.VisibleToRegularObj = true;
       break;
 
     case LDPR_PREVAILING_DEF_IRONLY_EXP:
-      R.Prevailing = true;
+      R.Prevailing = !isUndefined(Sym);
       if (!Res.CanOmitFromDynSym)
         R.VisibleToRegularObj = true;
       break;




More information about the llvm-commits mailing list