diff --git a/clang/lib/CodeGen/CodeGenModule.cpp b/clang/lib/CodeGen/CodeGenModule.cpp index e9635356e26f267248ced7f1bd5303ee1905bdcd..02776d55228e131fa7f454dec7976dfcd9f89b55 100644 --- a/clang/lib/CodeGen/CodeGenModule.cpp +++ b/clang/lib/CodeGen/CodeGenModule.cpp @@ -2251,8 +2251,12 @@ void CodeGenModule::setNonAliasAttributes(GlobalDecl GD, if (const auto *CSA = D->getAttr()) GO->setSection(CSA->getName()); - else if (const auto *SA = D->getAttr()) + else if (const auto *SA = D->getAttr()) { GO->setSection(SA->getName()); + if ("_hilog_" == SA->getName()) + cast(GO)->setUnnamedAddr( + llvm::GlobalValue::UnnamedAddr::Global); + } } getTargetCodeGenInfo().setTargetAttributes(D, GO, *this); diff --git a/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp b/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp index 407ad034c18edcdfb537db705fa2b161b8fe5f11..06b055a036fbc41b05ada4c1588ed97eebc1dd88 100644 --- a/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp +++ b/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp @@ -450,6 +450,9 @@ static SectionKind getELFKindForNamedSection(StringRef Name, SectionKind K) { // // .section .eh_frame,"a",@progbits + if (Name == "_hilog_") + return SectionKind::getMergeable1ByteCString(); + if (Name == getInstrProfSectionName(IPSK_covmap, Triple::ELF, /*AddSegmentInfo=*/false) || Name == getInstrProfSectionName(IPSK_covfun, Triple::ELF, diff --git a/llvm/test/CodeGen/X86/elf-unique-sections-by-flags.ll b/llvm/test/CodeGen/X86/elf-unique-sections-by-flags.ll index 0ca08d4b3feade0047b6d773b8e6c558cd3f93a0..142f2316c22f97b9b15755e5757560322fab2cf5 100644 --- a/llvm/test/CodeGen/X86/elf-unique-sections-by-flags.ll +++ b/llvm/test/CodeGen/X86/elf-unique-sections-by-flags.ll @@ -53,6 +53,10 @@ define i32 @fn2_s2() section "s2" { ; CHECK: .globl fn2_s2 ; CHECK: fn2_s2: +; Check if the "_hilog_" section is set as mergeable +@hilog_var = global [14 x i8] c"Hello world!\0A\00", section "_hilog_" +; CHECK: .section _hilog_,"aMS",@progbits,1,unique,1 + ; Values that share a section name with a function are placed in different sections without executable flag @rw_s1 = global i32 10, section "s1", align 4 @ro_s2 = constant i32 10, section "s2", align 4