diff options
author | Fangrui Song <maskray@google.com> | 2020-05-25 15:05:35 -0700 |
---|---|---|
committer | Fangrui Song <maskray@google.com> | 2020-05-25 20:48:18 -0700 |
commit | 9d55e4ee1367b440bb8402ce3a33d5a8b99aee06 (patch) | |
tree | 1024ddefbaea1a434eba08774b01235d08303a47 /llvm/lib/IR/Module.cpp | |
parent | 793cc518b9428a0b7a40c59d4ecd5939a7bc84f7 (diff) | |
download | llvm-9d55e4ee1367b440bb8402ce3a33d5a8b99aee06.zip llvm-9d55e4ee1367b440bb8402ce3a33d5a8b99aee06.tar.gz llvm-9d55e4ee1367b440bb8402ce3a33d5a8b99aee06.tar.bz2 |
Make explicit -fno-semantic-interposition (in -fpic mode) infer dso_local
-fno-semantic-interposition is currently the CC1 default. (The opposite
disables some interprocedural optimizations.) However, it does not infer
dso_local: on most targets accesses to ExternalLinkage functions/variables
defined in the current module still need PLT/GOT.
This patch makes explicit -fno-semantic-interposition infer dso_local,
so that PLT/GOT can be eliminated if targets implement local aliases
for AsmPrinter::getSymbolPreferLocal (currently only x86).
Currently we check whether the module flag "SemanticInterposition" is 0.
If yes, infer dso_local. In the future, we can infer dso_local unless
"SemanticInterposition" is 1: frontends other than clang will also
benefit from the optimization if they don't bother setting the flag.
(There will be risks if they do want ELF interposition: they need to set
"SemanticInterposition" to 1.)
Diffstat (limited to 'llvm/lib/IR/Module.cpp')
-rw-r--r-- | llvm/lib/IR/Module.cpp | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/llvm/lib/IR/Module.cpp b/llvm/lib/IR/Module.cpp index 9ac1edb..1416cdc 100644 --- a/llvm/lib/IR/Module.cpp +++ b/llvm/lib/IR/Module.cpp @@ -600,6 +600,13 @@ void Module::setSemanticInterposition(bool SI) { addModuleFlag(ModFlagBehavior::Error, "SemanticInterposition", SI); } +bool Module::noSemanticInterposition() const { + // Conservatively require an explicit zero value for now. + Metadata *MF = getModuleFlag("SemanticInterposition"); + auto *Val = cast_or_null<ConstantAsMetadata>(MF); + return Val && cast<ConstantInt>(Val->getValue())->getZExtValue() == 0; +} + void Module::setOwnedMemoryBuffer(std::unique_ptr<MemoryBuffer> MB) { OwnedMemoryBuffer = std::move(MB); } |