diff --git a/clang/lib/CodeGen/CodeGenModule.cpp b/clang/lib/CodeGen/CodeGenModule.cpp index 00b3bfcaa0bc2..f4dbfe7a21f83 100644 --- a/clang/lib/CodeGen/CodeGenModule.cpp +++ b/clang/lib/CodeGen/CodeGenModule.cpp @@ -2627,7 +2627,7 @@ void CodeGenModule::setNonAliasAttributes(GlobalDecl GD, addUsedGlobal(F); if (auto *SA = D->getAttr()) if (!D->getAttr()) - F->addFnAttr("implicit-section-name", SA->getName()); + F->setSection(SA->getName()); llvm::AttrBuilder Attrs(F->getContext()); if (GetCPUAndFeaturesAttributes(GD, Attrs)) { diff --git a/clang/test/CodeGen/clang-sections-attribute.c b/clang/test/CodeGen/clang-sections-attribute.c index 70ed24ed07a28..768bdd4d87649 100644 --- a/clang/test/CodeGen/clang-sections-attribute.c +++ b/clang/test/CodeGen/clang-sections-attribute.c @@ -69,8 +69,5 @@ static int int_zvar; // CHECK: define internal void @int_fun() #0 section ".int_fun_attr" // CHECK: define internal void @int_fun2() #0 section ".int_fun2_attr" // -// Function attributes should not include implicit-section-name. -// CHECK-NOT: attributes #0 = {{.*}}implicit-section-name -// // No other attribute group should be present in the file. // CHECK-NOT: attributes #1 diff --git a/clang/test/CodeGenCXX/clang-sections.cpp b/clang/test/CodeGenCXX/clang-sections.cpp index a444f2d0cae59..aa159e552b1b3 100644 --- a/clang/test/CodeGenCXX/clang-sections.cpp +++ b/clang/test/CodeGenCXX/clang-sections.cpp @@ -81,24 +81,22 @@ int hoo(void) { //CHECK: @p ={{.*}} constant i32 7, align 4 //CHECK: @_ZL5fptrs = internal constant [2 x ptr] [ptr @foo, ptr @goo], align {{4|8}} #3 -//CHECK: define{{.*}} i32 @foo() #5 { -//CHECK: define{{.*}} i32 @goo() #6 { -//CHECK: declare i32 @zoo(ptr noundef, ptr noundef) #7 -//CHECK: define{{.*}} i32 @hoo() #8 { +//ELF: define{{.*}} i32 @foo(){{.*}} section "my_text.1" { +//ELF: define{{.*}} i32 @goo(){{.*}} section "my_text.2" { +//MACHO: define{{.*}} i32 @foo(){{.*}} section "__TEXT,__mytext1" { +//MACHO: define{{.*}} i32 @goo(){{.*}} section "__TEXT,__mytext2" { + +// ensure zoo/hoo don't have a section +//CHECK: declare i32 @zoo(ptr noundef, ptr noundef) #6{{$}} +//CHECK: define{{.*}} i32 @hoo() #5 { //ELF: attributes #0 = { "bss-section"="my_bss.1" "data-section"="my_data.1" "rodata-section"="my_rodata.1" } //ELF: attributes #1 = { "data-section"="my_data.1" "rodata-section"="my_rodata.1" } //ELF: attributes #2 = { "bss-section"="my_bss.2" "rodata-section"="my_rodata.1" } //ELF: attributes #3 = { "bss-section"="my_bss.2" "data-section"="my_data.2" "relro-section"="my_relro.2" "rodata-section"="my_rodata.2" } //ELF: attributes #4 = { "relro-section"="my_relro.2" } -//ELF: attributes #5 = { {{.*"implicit-section-name"="my_text.1".*}} } -//ELF: attributes #6 = { {{.*"implicit-section-name"="my_text.2".*}} } //MACHO: attributes #0 = { "bss-section"="__BSS,__mybss1" "data-section"="__DATA,__mydata1" "rodata-section"="__RODATA,__myrodata1" } //MACHO: attributes #1 = { "data-section"="__DATA,__mydata1" "rodata-section"="__RODATA,__myrodata1" } //MACHO: attributes #2 = { "bss-section"="__BSS,__mybss2" "rodata-section"="__RODATA,__myrodata1" } //MACHO: attributes #3 = { "bss-section"="__BSS,__mybss2" "data-section"="__DATA,__mydata2" "relro-section"="__RELRO,__myrelro2" "rodata-section"="__RODATA,__myrodata2" } //MACHO: attributes #4 = { "relro-section"="__RELRO,__myrelro2" } -//MACHO: attributes #5 = { {{.*"implicit-section-name"="__TEXT,__mytext1".*}} } -//MACHO: attributes #6 = { {{.*"implicit-section-name"="__TEXT,__mytext2".*}} } -//CHECK-NOT: attributes #7 = { {{.*"implicit-section-name".*}} } -//CHECK-NOT: attributes #8 = { {{.*"implicit-section-name".*}} } diff --git a/llvm/lib/CodeGen/TargetInstrInfo.cpp b/llvm/lib/CodeGen/TargetInstrInfo.cpp index 9fbd516acea8e..d532128fa7351 100644 --- a/llvm/lib/CodeGen/TargetInstrInfo.cpp +++ b/llvm/lib/CodeGen/TargetInstrInfo.cpp @@ -1470,8 +1470,7 @@ bool TargetInstrInfo::isFunctionSafeToSplit(const MachineFunction &MF) const { // since the split part may not be placed in a contiguous region. It may also // be more beneficial to augment the linker to ensure contiguous layout of // split functions within the same section as specified by the attribute. - if (MF.getFunction().hasSection() || - MF.getFunction().hasFnAttribute("implicit-section-name")) + if (MF.getFunction().hasSection()) return false; // We don't want to proceed further for cold functions diff --git a/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp b/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp index 15b59421a0f44..2a77a683a901f 100644 --- a/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp +++ b/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp @@ -797,10 +797,6 @@ static MCSection *selectExplicitSectionGlobal( SectionName = Attrs.getAttribute("data-section").getValueAsString(); } } - const Function *F = dyn_cast(GO); - if (F && F->hasFnAttribute("implicit-section-name")) { - SectionName = F->getFnAttribute("implicit-section-name").getValueAsString(); - } // Infer section flags from the section name if we can. Kind = getELFKindForNamedSection(SectionName, Kind); @@ -934,7 +930,7 @@ MCSection *TargetLoweringObjectFileELF::getUniqueSectionForFunction( unsigned Flags = getELFSectionFlags(Kind); // If the function's section names is pre-determined via pragma or a // section attribute, call selectExplicitSectionGlobal. - if (F.hasSection() || F.hasFnAttribute("implicit-section-name")) + if (F.hasSection()) return selectExplicitSectionGlobal( &F, Kind, TM, getContext(), getMangler(), NextUniqueID, Used.count(&F), /* ForceUnique = */true); @@ -1298,11 +1294,6 @@ MCSection *TargetLoweringObjectFileMachO::getExplicitSectionGlobal( } } - const Function *F = dyn_cast(GO); - if (F && F->hasFnAttribute("implicit-section-name")) { - SectionName = F->getFnAttribute("implicit-section-name").getValueAsString(); - } - // Parse the section specifier and create it if valid. StringRef Segment, Section; unsigned TAA = 0, StubSize = 0; diff --git a/llvm/lib/IR/AutoUpgrade.cpp b/llvm/lib/IR/AutoUpgrade.cpp index 0f8c984d5e3c7..2c480fb76ee4d 100644 --- a/llvm/lib/IR/AutoUpgrade.cpp +++ b/llvm/lib/IR/AutoUpgrade.cpp @@ -5267,6 +5267,14 @@ void llvm::UpgradeFunctionAttributes(Function &F) { F.removeRetAttrs(AttributeFuncs::typeIncompatible(F.getReturnType())); for (auto &Arg : F.args()) Arg.removeAttrs(AttributeFuncs::typeIncompatible(Arg.getType())); + + // Older versions of LLVM treated an "implicit-section-name" attribute + // similarly to directly setting the section on a Function. + if (Attribute A = F.getFnAttribute("implicit-section-name"); + A.isValid() && A.isStringAttribute()) { + F.setSection(A.getValueAsString()); + F.removeFnAttr("implicit-section-name"); + } } static bool isOldLoopArgument(Metadata *MD) { diff --git a/llvm/lib/Target/TargetLoweringObjectFile.cpp b/llvm/lib/Target/TargetLoweringObjectFile.cpp index 8db68466490bd..26e9f9eb3f327 100644 --- a/llvm/lib/Target/TargetLoweringObjectFile.cpp +++ b/llvm/lib/Target/TargetLoweringObjectFile.cpp @@ -334,11 +334,6 @@ MCSection *TargetLoweringObjectFile::SectionForGlobal( } } - if (auto *F = dyn_cast(GO)) { - if (F->hasFnAttribute("implicit-section-name")) - return getExplicitSectionGlobal(GO, Kind, TM); - } - // Use default section depending on the 'type' of global return SelectSectionForGlobal(GO, Kind, TM); } diff --git a/llvm/test/Bitcode/upgrade-implicit-section-name.ll b/llvm/test/Bitcode/upgrade-implicit-section-name.ll new file mode 100644 index 0000000000000..f22e6a57fa616 --- /dev/null +++ b/llvm/test/Bitcode/upgrade-implicit-section-name.ll @@ -0,0 +1,8 @@ +; RUN: llvm-as < %s | llvm-dis - | FileCheck %s + +; CHECK: define void @f() section "foo_section" +; CHECK-NOT: "implicit-section-name" + +define void @f() "implicit-section-name"="foo_section" { + ret void +} diff --git a/llvm/test/CodeGen/AArch64/clang-section-macho.ll b/llvm/test/CodeGen/AArch64/clang-section-macho.ll deleted file mode 100644 index 406c584af62a9..0000000000000 --- a/llvm/test/CodeGen/AArch64/clang-section-macho.ll +++ /dev/null @@ -1,22 +0,0 @@ -;RUN: llc -mtriple=arm64-apple-ios %s -o - | FileCheck %s - -define dso_local void @foo() #0 { -entry: - ret void -} - -attributes #0 = { "implicit-section-name"="__TEXT,__mytext" } - -; CHECK: .section __TEXT,__mytext -; CHECK-NEXT: .globl _foo - - -define dso_local void @bar() #1 { -entry: - ret void -} - -attributes #1 = { "implicit-section-name"="__EDATA,zerofill" } - -; CHECK: .section __EDATA,zerofill -; CHECK-NEXT: .globl _bar diff --git a/llvm/test/CodeGen/ARM/clang-section.ll b/llvm/test/CodeGen/ARM/clang-section.ll index 4e896a2447dd4..9277d90dba65b 100644 --- a/llvm/test/CodeGen/ARM/clang-section.ll +++ b/llvm/test/CodeGen/ARM/clang-section.ll @@ -22,20 +22,6 @@ target triple = "armv7-arm-none-eabi" @o = global i32 6, align 4 @p = constant i32 7, align 4 -; Function Attrs: noinline nounwind -define i32 @foo() #4 { -entry: - %0 = load i32, ptr @b, align 4 - ret i32 %0 -} - -; Function Attrs: noinline -define i32 @goo() #5 { -entry: - %call = call i32 @zoo(ptr @_ZL1g, ptr @_ZZ3gooE7lstat_h) - ret i32 %call -} - declare i32 @zoo(ptr, ptr) #6 ; Function Attrs: noinline nounwind @@ -49,8 +35,6 @@ attributes #0 = { "bss-section"="my_bss.1" "data-section"="my_data.1" "rodata-se attributes #1 = { "data-section"="my_data.1" "rodata-section"="my_rodata.1" } attributes #2 = { "bss-section"="my_bss.2" "rodata-section"="my_rodata.1" } attributes #3 = { "bss-section"="my_bss.2" "data-section"="my_data.2" "rodata-section"="my_rodata.2" } -attributes #4 = { noinline nounwind "correctly-rounded-divide-sqrt-fp-math"="false" "denormal-fp-math"="preserve-sign,preserve-sign" "disable-tail-calls"="false" "implicit-section-name"="my_text.1" "less-precise-fpmad"="false" "frame-pointer"="none" "no-infs-fp-math"="true" "no-jump-tables"="false" "no-nans-fp-math"="true" "no-signed-zeros-fp-math"="true" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="cortex-a9" "target-features"="+dsp,+fp16,+neon,+vfp3" "unsafe-fp-math"="false" "use-soft-float"="false" } -attributes #5 = { noinline "correctly-rounded-divide-sqrt-fp-math"="false" "denormal-fp-math"="preserve-sign,preserve-sign" "disable-tail-calls"="false" "implicit-section-name"="my_text.2" "less-precise-fpmad"="false" "frame-pointer"="none" "no-infs-fp-math"="true" "no-jump-tables"="false" "no-nans-fp-math"="true" "no-signed-zeros-fp-math"="true" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="cortex-a9" "target-features"="+dsp,+fp16,+neon,+vfp3" "unsafe-fp-math"="false" "use-soft-float"="false" } attributes #6 = { "correctly-rounded-divide-sqrt-fp-math"="false" "denormal-fp-math"="preserve-sign,preserve-sign" "disable-tail-calls"="false" "less-precise-fpmad"="false" "frame-pointer"="none" "no-infs-fp-math"="true" "no-nans-fp-math"="true" "no-signed-zeros-fp-math"="true" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="cortex-a9" "target-features"="+dsp,+fp16,+neon,+vfp3" "unsafe-fp-math"="false" "use-soft-float"="false" } attributes #7 = { noinline nounwind "correctly-rounded-divide-sqrt-fp-math"="false" "denormal-fp-math"="preserve-sign,preserve-sign" "disable-tail-calls"="false" "less-precise-fpmad"="false" "frame-pointer"="none" "no-infs-fp-math"="true" "no-jump-tables"="false" "no-nans-fp-math"="true" "no-signed-zeros-fp-math"="true" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="cortex-a9" "target-features"="+dsp,+fp16,+neon,+vfp3" "unsafe-fp-math"="false" "use-soft-float"="false" } @@ -61,14 +45,6 @@ attributes #7 = { noinline nounwind "correctly-rounded-divide-sqrt-fp-math"="fal !2 = !{i32 1, !"enumsize_buildattr", i32 2} !3 = !{i32 1, !"armlib_unavailable", i32 0} -;CHECK: .section my_text.1,"ax",%progbits -;CHECK: .type foo,%function -;CHECK: foo: - -;CHECK: .section my_text.2,"ax",%progbits -;CHECK: .type goo,%function -;CHECK: goo: - ;CHECK: .text ;CHECK: .type hoo,%function ;CHECK: hoo: diff --git a/llvm/test/CodeGen/Generic/machine-function-splitter.ll b/llvm/test/CodeGen/Generic/machine-function-splitter.ll index d7cc3941ee7a3..2097523a61c5f 100644 --- a/llvm/test/CodeGen/Generic/machine-function-splitter.ll +++ b/llvm/test/CodeGen/Generic/machine-function-splitter.ll @@ -260,25 +260,6 @@ exit: ret i32 %5 } -define void @foo9(i1 zeroext %0) nounwind #0 !prof !14 { -;; Check that function with section attribute is not split. -; MFS-DEFAULTS-LABEL: foo9 -; MFS-DEFAULTS-NOT: foo9.cold: - br i1 %0, label %2, label %4, !prof !17 - -2: ; preds = %1 - %3 = call i32 @bar() - br label %6 - -4: ; preds = %1 - %5 = call i32 @baz() - br label %6 - -6: ; preds = %4, %2 - %7 = tail call i32 @qux() - ret void -} - define i32 @foo10(i1 zeroext %0) personality ptr @__gxx_personality_v0 !prof !14 { ;; Check that nop is inserted just before the EH pad if it's beginning a section. ; MFS-DEFAULTS-LABEL: foo10 @@ -564,10 +545,10 @@ define i32 @foo19(i32 %in) !prof !14 !section_prefix !15 { ; MFS-DEFAULTS-LABEL: foo19 ; MFS-DEFAULTS: .section .text.split.foo19 ; MFS-DEFAULTS-NEXT: foo19.cold: -; MFS-DEFAULTS-X86: .LJTI18_0 -; MFS-DEFAULTS-AARCH64-NOT: .LJTI18_0 +; MFS-DEFAULTS-X86: .LJTI17_0 +; MFS-DEFAULTS-AARCH64-NOT: .LJTI17_0 ; MFS-DEFAULTS: .section .rodata -; MFS-DEFAULTS: .LJTI18_0 +; MFS-DEFAULTS: .LJTI17_0 %cmp = icmp sgt i32 %in, 3 br i1 %cmp, label %hot, label %cold_switch, !prof !17 @@ -638,8 +619,6 @@ declare i32 @__gxx_personality_v0(...) @_ZTIi = external constant ptr -attributes #0 = { "implicit-section-name"="nosplit" } - !llvm.module.flags = !{!0} !0 = !{i32 1, !"ProfileSummary", !1} !1 = !{!2, !3, !4, !5, !6, !7, !8, !9} diff --git a/llvm/test/CodeGen/X86/basic-block-sections-pragma-sections.ll b/llvm/test/CodeGen/X86/basic-block-sections-pragma-sections.ll index 13a4607100a05..da3b4f253147b 100644 --- a/llvm/test/CodeGen/X86/basic-block-sections-pragma-sections.ll +++ b/llvm/test/CodeGen/X86/basic-block-sections-pragma-sections.ll @@ -38,7 +38,7 @@ ;; return 0; ;; } -define dso_local i32 @_Z3fooi(i32 %n) local_unnamed_addr #0 { +define dso_local i32 @_Z3fooi(i32 %n) local_unnamed_addr section "foo_section" { entry: %cmp = icmp slt i32 %n, 0 br i1 %cmp, label %if.then, label %if.end @@ -52,5 +52,3 @@ if.end: ; preds = %entry } declare dso_local void @exit(i32) local_unnamed_addr - -attributes #0 = {"implicit-section-name"="foo_section" }