[lld] r273451 - [LTO] Include ASM undefs in llvm.compiler_used.
Davide Italiano via llvm-commits
llvm-commits at lists.llvm.org
Wed Jun 22 11:09:23 PDT 2016
Author: davide
Date: Wed Jun 22 13:09:23 2016
New Revision: 273451
URL: http://llvm.org/viewvc/llvm-project?rev=273451&view=rev
Log:
[LTO] Include ASM undefs in llvm.compiler_used.
This fixes PR28218. Thanks to Rafael for spotting a failure in
the SHARED_LIBS build!
Differential Revision: http://reviews.llvm.org/D21577
Added:
lld/trunk/test/ELF/lto/asmundef.ll
Modified:
lld/trunk/ELF/CMakeLists.txt
lld/trunk/ELF/LTO.cpp
lld/trunk/ELF/LTO.h
Modified: lld/trunk/ELF/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/CMakeLists.txt?rev=273451&r1=273450&r2=273451&view=diff
==============================================================================
--- lld/trunk/ELF/CMakeLists.txt (original)
+++ lld/trunk/ELF/CMakeLists.txt Wed Jun 22 13:09:23 2016
@@ -31,6 +31,7 @@ add_lld_library(lldELF
Core
IPO
Linker
+ LTO
Object
Option
Passes
Modified: lld/trunk/ELF/LTO.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/LTO.cpp?rev=273451&r1=273450&r2=273451&view=diff
==============================================================================
--- lld/trunk/ELF/LTO.cpp (original)
+++ lld/trunk/ELF/LTO.cpp Wed Jun 22 13:09:23 2016
@@ -25,6 +25,7 @@
#include "llvm/IR/LegacyPassManager.h"
#include "llvm/IR/PassManager.h"
#include "llvm/IR/Verifier.h"
+#include "llvm/LTO/UpdateCompilerUsed.h"
#include "llvm/Linker/IRMover.h"
#include "llvm/Passes/PassBuilder.h"
#include "llvm/Support/StringSaver.h"
@@ -153,6 +154,21 @@ static void undefine(Symbol *S) {
replaceBody<Undefined>(S, S->body()->getName(), STV_DEFAULT, S->body()->Type);
}
+static void handleUndefinedAsmRefs(const BasicSymbolRef &Sym, GlobalValue *GV,
+ StringSet<> &AsmUndefinedRefs) {
+ // GV associated => not an assembly symbol, bail out.
+ if (GV)
+ return;
+
+ // This is an undefined reference to a symbol in asm. We put that in
+ // compiler.used, so that we can preserve it from being dropped from
+ // the output, without necessarily preventing its internalization.
+ SmallString<64> Name;
+ raw_svector_ostream OS(Name);
+ Sym.printName(OS);
+ AsmUndefinedRefs.insert(Name.str());
+}
+
void BitcodeCompiler::add(BitcodeFile &F) {
std::unique_ptr<IRObjectFile> Obj = std::move(F.Obj);
std::vector<GlobalValue *> Keep;
@@ -181,8 +197,10 @@ void BitcodeCompiler::add(BitcodeFile &F
if (BitcodeFile::shouldSkip(Flags))
continue;
Symbol *S = Syms[BodyIndex++];
- if (Flags & BasicSymbolRef::SF_Undefined)
+ if (Flags & BasicSymbolRef::SF_Undefined) {
+ handleUndefinedAsmRefs(Sym, GV, AsmUndefinedRefs);
continue;
+ }
auto *B = dyn_cast<DefinedBitcode>(S->body());
if (!B || B->File != &F)
continue;
@@ -271,9 +289,6 @@ std::vector<std::unique_ptr<InputFile>>
internalize(*GV);
}
- if (Config->SaveTemps)
- saveBCFile(*Combined, ".lto.bc");
-
std::string Msg;
const Target *T = TargetRegistry::lookupTarget(TheTriple, Msg);
if (!T)
@@ -291,6 +306,14 @@ std::vector<std::unique_ptr<InputFile>>
};
std::unique_ptr<TargetMachine> TM = CreateTargetMachine();
+
+ // Update llvm.compiler.used so that optimizations won't strip
+ // off AsmUndefinedReferences.
+ UpdateCompilerUsed(*Combined, *TM, AsmUndefinedRefs);
+
+ if (Config->SaveTemps)
+ saveBCFile(*Combined, ".lto.bc");
+
runLTOPasses(*Combined, *TM);
if (HasError)
return {};
Modified: lld/trunk/ELF/LTO.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/LTO.h?rev=273451&r1=273450&r2=273451&view=diff
==============================================================================
--- lld/trunk/ELF/LTO.h (original)
+++ lld/trunk/ELF/LTO.h Wed Jun 22 13:09:23 2016
@@ -47,6 +47,7 @@ private:
llvm::IRMover Mover;
std::vector<SmallString<0>> OwningData;
llvm::StringSet<> InternalizedSyms;
+ llvm::StringSet<> AsmUndefinedRefs;
std::string TheTriple;
};
}
Added: lld/trunk/test/ELF/lto/asmundef.ll
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/lto/asmundef.ll?rev=273451&view=auto
==============================================================================
--- lld/trunk/test/ELF/lto/asmundef.ll (added)
+++ lld/trunk/test/ELF/lto/asmundef.ll Wed Jun 22 13:09:23 2016
@@ -0,0 +1,25 @@
+; REQUIRES: x86
+; RUN: llvm-as %s -o %t.o
+; RUN: ld.lld -m elf_x86_64 %t.o -o %t -save-temps
+; RUN: llvm-dis %t.lto.bc -o - | FileCheck %s
+
+target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
+target triple = "x86_64-unknown-linux-gnu"
+
+module asm ".weak patatino"
+module asm ".equ patatino, foo"
+
+declare void @patatino()
+
+define void @foo() {
+ ret void
+}
+
+define void @_start() {
+ call void @patatino()
+ ret void
+}
+
+; CHECK: @llvm.compiler.used = appending global [1 x i8*] [i8* bitcast (void ()* @foo to i8*)], section "llvm.metadata"
+; CHECK: define internal void @foo
+
More information about the llvm-commits
mailing list