From 809a1e0ffd7af40ee27270ff8ba2ffc927330e71 Mon Sep 17 00:00:00 2001 From: Fangrui Song Date: Wed, 30 Dec 2020 20:52:01 -0800 Subject: [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. --- clang/lib/CodeGen/CodeGenModule.cpp | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) (limited to 'clang/lib/CodeGen/CodeGenModule.cpp') diff --git a/clang/lib/CodeGen/CodeGenModule.cpp b/clang/lib/CodeGen/CodeGenModule.cpp index 6d14298d9f5f..bf0a38bf83ab 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). -- cgit v1.2.3