Skip to content

[clang][llvm] Remove "implicit-section-name" attribute #87906

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion clang/lib/CodeGen/CodeGenModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2627,7 +2627,7 @@ void CodeGenModule::setNonAliasAttributes(GlobalDecl GD,
addUsedGlobal(F);
if (auto *SA = D->getAttr<PragmaClangTextSectionAttr>())
if (!D->getAttr<SectionAttr>())
F->addFnAttr("implicit-section-name", SA->getName());
F->setSection(SA->getName());

llvm::AttrBuilder Attrs(F->getContext());
if (GetCPUAndFeaturesAttributes(GD, Attrs)) {
Expand Down
3 changes: 0 additions & 3 deletions clang/test/CodeGen/clang-sections-attribute.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
18 changes: 8 additions & 10 deletions clang/test/CodeGenCXX/clang-sections.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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".*}} }
3 changes: 1 addition & 2 deletions llvm/lib/CodeGen/TargetInstrInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 1 addition & 10 deletions llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -797,10 +797,6 @@ static MCSection *selectExplicitSectionGlobal(
SectionName = Attrs.getAttribute("data-section").getValueAsString();
}
}
const Function *F = dyn_cast<Function>(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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -1298,11 +1294,6 @@ MCSection *TargetLoweringObjectFileMachO::getExplicitSectionGlobal(
}
}

const Function *F = dyn_cast<Function>(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;
Expand Down
8 changes: 8 additions & 0 deletions llvm/lib/IR/AutoUpgrade.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
5 changes: 0 additions & 5 deletions llvm/lib/Target/TargetLoweringObjectFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -334,11 +334,6 @@ MCSection *TargetLoweringObjectFile::SectionForGlobal(
}
}

if (auto *F = dyn_cast<Function>(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);
}
Expand Down
8 changes: 8 additions & 0 deletions llvm/test/Bitcode/upgrade-implicit-section-name.ll
Original file line number Diff line number Diff line change
@@ -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
}
22 changes: 0 additions & 22 deletions llvm/test/CodeGen/AArch64/clang-section-macho.ll

This file was deleted.

24 changes: 0 additions & 24 deletions llvm/test/CodeGen/ARM/clang-section.ll
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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" }

Expand All @@ -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:
Expand Down
27 changes: 3 additions & 24 deletions llvm/test/CodeGen/Generic/machine-function-splitter.ll
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -52,5 +52,3 @@ if.end: ; preds = %entry
}

declare dso_local void @exit(i32) local_unnamed_addr

attributes #0 = {"implicit-section-name"="foo_section" }