From 2bbea54dc0bf95d2622f71ecc3e100eff3a19183 Mon Sep 17 00:00:00 2001 From: Arnold Schwaighofer Date: Fri, 3 Sep 2021 08:36:57 -0700 Subject: [PATCH] IRGen: Use llvm.compiler.used instead of llvm.used on ELF As of "ELF: Create unique SHF_GNU_RETAIN sections for llvm.used global objects" (https://reviews.llvm.org/D97448) LLVM will create separate sections for symbols marked as llvm.used. Use llvm.compiler.used instead. rdar://82681143 --- lib/IRGen/GenDecl.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/lib/IRGen/GenDecl.cpp b/lib/IRGen/GenDecl.cpp index 01807f942c61e..f2f33f29cb562 100644 --- a/lib/IRGen/GenDecl.cpp +++ b/lib/IRGen/GenDecl.cpp @@ -886,6 +886,15 @@ IRGenModule::getAddrOfParentContextDescriptor(DeclContext *from, /// /// This value must have a definition by the time the module is finalized. void IRGenModule::addUsedGlobal(llvm::GlobalValue *global) { + + // As of reviews.llvm.org/D97448 "ELF: Create unique SHF_GNU_RETAIN sections + // for llvm.used global objects" LLVM creates separate sections for globals in + // llvm.used on ELF. Therefore we use llvm.compiler.used on ELF instead. + if (TargetInfo.OutputObjectFormat == llvm::Triple::ELF) { + addCompilerUsedGlobal(global); + return; + } + LLVMUsed.push_back(global); }