summaryrefslogtreecommitdiff
path: root/lib/LTO/LTOBackend.cpp
diff options
context:
space:
mode:
authorDavide Italiano <davide@freebsd.org>2016-09-16 16:05:25 +0000
committerDavide Italiano <davide@freebsd.org>2016-09-16 16:05:25 +0000
commit3284f278cd4c93188a608ab813094f02f4f8b717 (patch)
tree699970416cfb26dc18e5cdaa3e0f8cb6cfdff99d /lib/LTO/LTOBackend.cpp
parentc49f5e8a930294c02c94731950b6e7e2c94160e5 (diff)
[LTO] Prevent asm references to be dropped from the output.
Differential Revision: https://reviews.llvm.org/D24617 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@281741 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/LTO/LTOBackend.cpp')
-rw-r--r--lib/LTO/LTOBackend.cpp18
1 files changed, 18 insertions, 0 deletions
diff --git a/lib/LTO/LTOBackend.cpp b/lib/LTO/LTOBackend.cpp
index 28b55a000af..76b20b5130f 100644
--- a/lib/LTO/LTOBackend.cpp
+++ b/lib/LTO/LTOBackend.cpp
@@ -25,6 +25,7 @@
#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/Passes/PassBuilder.h"
#include "llvm/Support/Error.h"
@@ -275,6 +276,19 @@ Expected<const Target *> initAndLookupTarget(Config &C, Module &Mod) {
}
+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;
+ object::IRObjectFile::CollectAsmUndefinedRefs(
+ Triple(Mod.getTargetTriple()), Mod.getModuleInlineAsm(),
+ [&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, AddOutputFn AddOutput,
unsigned ParallelCodeGenParallelismLevel,
std::unique_ptr<Module> Mod) {
@@ -285,6 +299,8 @@ Error lto::backend(Config &C, AddOutputFn AddOutput,
std::unique_ptr<TargetMachine> TM =
createTargetMachine(C, Mod->getTargetTriple(), *TOrErr);
+ handleAsmUndefinedRefs(*Mod, *TM);
+
if (!C.CodeGenOnly)
if (!opt(C, TM.get(), 0, *Mod, /*IsThinLto=*/false))
return Error();
@@ -310,6 +326,8 @@ Error lto::thinBackend(Config &Conf, unsigned Task, AddOutputFn AddOutput,
std::unique_ptr<TargetMachine> TM =
createTargetMachine(Conf, Mod.getTargetTriple(), *TOrErr);
+ handleAsmUndefinedRefs(Mod, *TM);
+
if (Conf.CodeGenOnly) {
codegen(Conf, TM.get(), AddOutput, Task, Mod);
return Error();