[llvm] r301438 - LTO: Mark undefined module asm symbols as used.
Peter Collingbourne via llvm-commits
llvm-commits at lists.llvm.org
Wed Apr 26 10:53:39 PDT 2017
Author: pcc
Date: Wed Apr 26 12:53:39 2017
New Revision: 301438
URL: http://llvm.org/viewvc/llvm-project?rev=301438&view=rev
Log:
LTO: Mark undefined module asm symbols as used.
Marking them as used causes them to be considered visible outside of LTO. This
prevents the symbols from being internalized or discarded, either by GlobalDCE
or by summary-based dead stripping in ThinLTO.
This change makes it unnecessary to add these symbols to llvm.compiler.used
in the backend, as the symbols are kept alive by virtue of being external,
so remove the backend code that handles that.
Fixes PR32798.
Differential Revision: https://reviews.llvm.org/D32544
Added:
llvm/trunk/test/LTO/Resolution/X86/Inputs/mod-asm-used.ll
llvm/trunk/test/LTO/Resolution/X86/mod-asm-used.ll
Modified:
llvm/trunk/lib/LTO/LTO.cpp
llvm/trunk/lib/LTO/LTOBackend.cpp
llvm/trunk/lib/Object/IRSymtab.cpp
llvm/trunk/test/tools/gold/X86/asm_undefined2.ll
Modified: llvm/trunk/lib/LTO/LTO.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/LTO/LTO.cpp?rev=301438&r1=301437&r2=301438&view=diff
==============================================================================
--- llvm/trunk/lib/LTO/LTO.cpp (original)
+++ llvm/trunk/lib/LTO/LTO.cpp Wed Apr 26 12:53:39 2017
@@ -415,7 +415,8 @@ void LTO::addSymbolToGlobalRes(const Inp
// Flag as visible outside of ThinLTO if visible from a regular object or
// if this is a reference in the regular LTO partition.
GlobalRes.VisibleOutsideThinLTO |=
- (Res.VisibleToRegularObj || (Partition == GlobalResolution::RegularLTO));
+ (Res.VisibleToRegularObj || Sym.isUsed() ||
+ Partition == GlobalResolution::RegularLTO);
}
static void writeToResolutionFile(raw_ostream &OS, InputFile *Input,
Modified: llvm/trunk/lib/LTO/LTOBackend.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/LTO/LTOBackend.cpp?rev=301438&r1=301437&r2=301438&view=diff
==============================================================================
--- llvm/trunk/lib/LTO/LTOBackend.cpp (original)
+++ llvm/trunk/lib/LTO/LTOBackend.cpp Wed Apr 26 12:53:39 2017
@@ -25,7 +25,6 @@
#include "llvm/IR/PassManager.h"
#include "llvm/IR/Verifier.h"
#include "llvm/LTO/LTO.h"
-#include "llvm/LTO/legacy/UpdateCompilerUsed.h"
#include "llvm/MC/SubtargetFeature.h"
#include "llvm/Object/ModuleSymbolTable.h"
#include "llvm/Passes/PassBuilder.h"
@@ -353,19 +352,6 @@ finalizeOptimizationRemarks(std::unique_
DiagOutputFile->os().flush();
}
-static void handleAsmUndefinedRefs(Module &Mod, TargetMachine &TM) {
- // Collect the list of undefined symbols used in asm and update
- // llvm.compiler.used to prevent optimization to drop these from the output.
- StringSet<> AsmUndefinedRefs;
- ModuleSymbolTable::CollectAsmSymbols(
- Mod,
- [&AsmUndefinedRefs](StringRef Name, object::BasicSymbolRef::Flags Flags) {
- if (Flags & object::BasicSymbolRef::SF_Undefined)
- AsmUndefinedRefs.insert(Name);
- });
- updateCompilerUsed(Mod, TM, AsmUndefinedRefs);
-}
-
Error lto::backend(Config &C, AddStreamFn AddStream,
unsigned ParallelCodeGenParallelismLevel,
std::unique_ptr<Module> Mod,
@@ -377,8 +363,6 @@ Error lto::backend(Config &C, AddStreamF
std::unique_ptr<TargetMachine> TM =
createTargetMachine(C, Mod->getTargetTriple(), *TOrErr);
- handleAsmUndefinedRefs(*Mod, *TM);
-
// Setup optimization remarks.
auto DiagFileOrErr = lto::setupOptimizationRemarks(
Mod->getContext(), C.RemarksFilename, C.RemarksWithHotness);
@@ -416,8 +400,6 @@ Error lto::thinBackend(Config &Conf, uns
std::unique_ptr<TargetMachine> TM =
createTargetMachine(Conf, Mod.getTargetTriple(), *TOrErr);
- handleAsmUndefinedRefs(Mod, *TM);
-
if (Conf.CodeGenOnly) {
codegen(Conf, TM.get(), AddStream, Task, Mod);
return Error::success();
Modified: llvm/trunk/lib/Object/IRSymtab.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Object/IRSymtab.cpp?rev=301438&r1=301437&r2=301438&view=diff
==============================================================================
--- llvm/trunk/lib/Object/IRSymtab.cpp (original)
+++ llvm/trunk/lib/Object/IRSymtab.cpp Wed Apr 26 12:53:39 2017
@@ -163,6 +163,9 @@ Error Builder::addSymbol(const ModuleSym
Sym.ComdatIndex = -1;
auto *GV = Msym.dyn_cast<GlobalValue *>();
if (!GV) {
+ // Undefined module asm symbols act as GC roots and are implicitly used.
+ if (Flags & object::BasicSymbolRef::SF_Undefined)
+ Sym.Flags |= 1 << storage::Symbol::FB_used;
setStr(Sym.IRName, "");
return Error::success();
}
Added: llvm/trunk/test/LTO/Resolution/X86/Inputs/mod-asm-used.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/LTO/Resolution/X86/Inputs/mod-asm-used.ll?rev=301438&view=auto
==============================================================================
--- llvm/trunk/test/LTO/Resolution/X86/Inputs/mod-asm-used.ll (added)
+++ llvm/trunk/test/LTO/Resolution/X86/Inputs/mod-asm-used.ll Wed Apr 26 12:53:39 2017
@@ -0,0 +1,4 @@
+target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
+target triple = "x86_64-unknown-linux-gnu"
+
+ at foo = global i32 1, align 4
Added: llvm/trunk/test/LTO/Resolution/X86/mod-asm-used.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/LTO/Resolution/X86/mod-asm-used.ll?rev=301438&view=auto
==============================================================================
--- llvm/trunk/test/LTO/Resolution/X86/mod-asm-used.ll (added)
+++ llvm/trunk/test/LTO/Resolution/X86/mod-asm-used.ll Wed Apr 26 12:53:39 2017
@@ -0,0 +1,10 @@
+; RUN: opt -module-summary -o %t.bc %s
+; RUN: opt -module-summary -o %t2.bc %S/Inputs/mod-asm-used.ll
+; RUN: llvm-lto2 run %t.bc -r %t.bc,foo,l %t2.bc -r %t2.bc,foo,pl -o %t3
+; RUN: llvm-nm %t3.1 | FileCheck %s
+
+target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
+target triple = "x86_64-unknown-linux-gnu"
+
+; CHECK: D foo
+module asm ".quad foo"
Modified: llvm/trunk/test/tools/gold/X86/asm_undefined2.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/gold/X86/asm_undefined2.ll?rev=301438&r1=301437&r2=301438&view=diff
==============================================================================
--- llvm/trunk/test/tools/gold/X86/asm_undefined2.ll (original)
+++ llvm/trunk/test/tools/gold/X86/asm_undefined2.ll Wed Apr 26 12:53:39 2017
@@ -11,8 +11,8 @@
; RUN: --plugin-opt=thinlto -o %t2 %t.o
; RUN: llvm-dis < %t.o.5.precodegen.bc | FileCheck %s
-; Check that foo is properly appended to llvm.compiler.used
-; CHECK: @llvm.compiler.used = appending global [1 x i8*] [i8* bitcast (void ()* @foo to i8*)], section "llvm.metadata"
+; Check that foo is not internalized
+; CHECK: define void @foo
target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"
More information about the llvm-commits
mailing list