diff options
author | Fangrui Song <i@maskray.me> | 2020-12-30 20:52:01 -0800 |
---|---|---|
committer | Fangrui Song <i@maskray.me> | 2020-12-30 20:52:01 -0800 |
commit | 809a1e0ffd7af40ee27270ff8ba2ffc927330e71 (patch) | |
tree | 96719af42faea6821d71904be38c15f06331d769 /clang/lib/CodeGen/CodeGenModule.cpp | |
parent | 6b3351792c6c9a362a3e8b826bc1d96f8e1918e0 (diff) | |
download | llvm-809a1e0ffd7af40ee27270ff8ba2ffc927330e71.zip llvm-809a1e0ffd7af40ee27270ff8ba2ffc927330e71.tar.gz llvm-809a1e0ffd7af40ee27270ff8ba2ffc927330e71.tar.bz2 |
[CodeGenModule] Set dso_local for Mach-O GlobalValue
* static relocation model: always
* other relocation models: if isStrongDefinitionForLinker
This will make LLVM IR emitted for COFF/Mach-O and executable ELF similar.
Diffstat (limited to 'clang/lib/CodeGen/CodeGenModule.cpp')
-rw-r--r-- | clang/lib/CodeGen/CodeGenModule.cpp | 14 |
1 files changed, 10 insertions, 4 deletions
diff --git a/clang/lib/CodeGen/CodeGenModule.cpp b/clang/lib/CodeGen/CodeGenModule.cpp index 6d14298..bf0a38b 100644 --- a/clang/lib/CodeGen/CodeGenModule.cpp +++ b/clang/lib/CodeGen/CodeGenModule.cpp @@ -946,14 +946,20 @@ static bool shouldAssumeDSOLocal(const CodeGenModule &CGM, if (TT.isOSBinFormatCOFF() || (TT.isOSWindows() && TT.isOSBinFormatMachO())) return true; + const auto &CGOpts = CGM.getCodeGenOpts(); + llvm::Reloc::Model RM = CGOpts.RelocationModel; + const auto &LOpts = CGM.getLangOpts(); + + if (TT.isOSBinFormatMachO()) { + if (RM == llvm::Reloc::Static) + return true; + return GV->isStrongDefinitionForLinker(); + } + // Only handle COFF and ELF for now. if (!TT.isOSBinFormatELF()) return false; - // If this is not an executable, don't assume anything is local. - const auto &CGOpts = CGM.getCodeGenOpts(); - llvm::Reloc::Model RM = CGOpts.RelocationModel; - const auto &LOpts = CGM.getLangOpts(); if (RM != llvm::Reloc::Static && !LOpts.PIE) { // On ELF, if -fno-semantic-interposition is specified, we can set dso_local // if using a local alias is preferable (can avoid GOT indirection). |