diff options
author | Warren Ristow <warren.ristow@sony.com> | 2018-10-10 22:54:31 +0000 |
---|---|---|
committer | Warren Ristow <warren.ristow@sony.com> | 2018-10-10 22:54:31 +0000 |
commit | febfc4e89b61bc51526ce5a54e149f64c62f95ba (patch) | |
tree | 13f94ac3959ea5415817fea23a1051d87d3a886f /llvm/lib/LTO/UpdateCompilerUsed.cpp | |
parent | 335315697ac4079a9ec4a2e9911373ab4ba9dc2f (diff) | |
download | bcm5719-llvm-febfc4e89b61bc51526ce5a54e149f64c62f95ba.tar.gz bcm5719-llvm-febfc4e89b61bc51526ce5a54e149f64c62f95ba.zip |
[LTO] Account for overriding lib calls via the alias attribute
Given a library call that is represented as an llvm intrinsic call, but
later transformed to an actual call, if an overriding definition of that
library routine is provided indirectly via an alias, prevent LTO from
eliminating the definition.
This is a fix for PR38547.
Differential Revision: https://reviews.llvm.org/D52836
llvm-svn: 344198
Diffstat (limited to 'llvm/lib/LTO/UpdateCompilerUsed.cpp')
-rw-r--r-- | llvm/lib/LTO/UpdateCompilerUsed.cpp | 16 |
1 files changed, 11 insertions, 5 deletions
diff --git a/llvm/lib/LTO/UpdateCompilerUsed.cpp b/llvm/lib/LTO/UpdateCompilerUsed.cpp index c982a5b0e5a..00482dee6e1 100644 --- a/llvm/lib/LTO/UpdateCompilerUsed.cpp +++ b/llvm/lib/LTO/UpdateCompilerUsed.cpp @@ -95,12 +95,18 @@ private: if (GV.hasPrivateLinkage()) return; - // Conservatively append user-supplied runtime library functions to - // llvm.compiler.used. These could be internalized and deleted by - // optimizations like -globalopt, causing problems when later optimizations - // add new library calls (e.g., llvm.memset => memset and printf => puts). + // Conservatively append user-supplied runtime library functions (supplied + // either directly, or via a function alias) to llvm.compiler.used. These + // could be internalized and deleted by optimizations like -globalopt, + // causing problems when later optimizations add new library calls (e.g., + // llvm.memset => memset and printf => puts). // Leave it to the linker to remove any dead code (e.g. with -dead_strip). - if (isa<Function>(GV) && Libcalls.count(GV.getName())) { + GlobalValue *FuncAliasee = nullptr; + if (isa<GlobalAlias>(GV)) { + auto *A = cast<GlobalAlias>(&GV); + FuncAliasee = dyn_cast<Function>(A->getAliasee()); + } + if ((isa<Function>(GV) || FuncAliasee) && Libcalls.count(GV.getName())) { LLVMUsed.push_back(&GV); return; } |