================ @@ -1075,6 +1089,135 @@ void CIRGenModule::emitTentativeDefinition(const VarDecl *d) { emitGlobalVarDefinition(d); } +static bool shouldAssumeDSOLocal(const CIRGenModule &cgm, + cir::CIRGlobalValueInterface gv) { + if (gv.hasLocalLinkage()) + return true; + + if (!gv.hasDefaultVisibility() && !gv.hasExternalWeakLinkage()) + return true; + + // DLLImport explicitly marks the GV as external. + // so it shouldn't be dso_local + // But we don't have the info set now + assert(!cir::MissingFeatures::opGlobalDLLImportExport()); + + const llvm::Triple &tt = cgm.getTriple(); + const auto &cgOpts = cgm.getCodeGenOpts(); + if (tt.isWindowsGNUEnvironment()) { + // In MinGW, variables without DLLImport can still be automatically + // imported from a DLL by the linker; don't mark variables that + // potentially could come from another DLL as DSO local. + + // With EmulatedTLS, TLS variables can be autoimported from other DLLs + // (and this actually happens in the public interface of libstdc++), so + // such variables can't be marked as DSO local. (Native TLS variables + // can't be dllimported at all, though.) + cgm.errorNYI("shouldAssumeDSOLocal: MinGW"); + } + + // On COFF, don't mark 'extern_weak' symbols as DSO local. If these symbols + // remain unresolved in the link, they can be resolved to zero, which is + // outside the current DSO. + if (tt.isOSBinFormatCOFF() && gv.hasExternalWeakLinkage()) + return false; + + // Every other GV is local on COFF. + // Make an exception for windows OS in the triple: Some firmware builds use + // *-win32-macho triples. This (accidentally?) produced windows relocations + // without GOT tables in older clang versions; Keep this behaviour. + // FIXME: even thread local variables? + if (tt.isOSBinFormatCOFF() || (tt.isOSWindows() && tt.isOSBinFormatMachO())) + return true; + + // Only handle COFF and ELF for now. + if (!tt.isOSBinFormatELF()) + return false; + + llvm::Reloc::Model rm = cgOpts.RelocationModel; + const auto &lOpts = cgm.getLangOpts(); ---------------- bcardosolopes wrote:
and here. https://github.com/llvm/llvm-project/pull/141973 _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits