-
Notifications
You must be signed in to change notification settings - Fork 10.9k
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
[Clang] -fseparate-named-sections option #91028
Changes from 3 commits
78193f6
ff14d32
cafbf6f
5b7aaa6
1ce6653
63a8296
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
// REQUIRES: x86-registered-target | ||
|
||
// RUN: %clang_cc1 -triple x86_64-pc-linux -S -o - < %s | FileCheck %s | ||
// RUN: %clang_cc1 -triple x86_64-pc-linux -S -fseparate-named-sections -o - < %s | FileCheck %s --check-prefix=SEPARATE | ||
|
||
__attribute__((section("custom_text"))) void f(void) {} | ||
__attribute__((section("custom_text"))) void g(void) {} | ||
|
||
// CHECK: .section custom_text,"ax",@progbits{{$}} | ||
// CHECK: f: | ||
// CHECK: g: | ||
|
||
// SEPARATE: .section custom_text,"ax",@progbits,unique,1{{$}} | ||
// SEPARATE: f: | ||
// SEPARATE: .section custom_text,"ax",@progbits,unique,2{{$}} | ||
// SEPARATE: g: | ||
|
||
__attribute__((section("custom_data"))) int i = 0; | ||
__attribute__((section("custom_data"))) int j = 0; | ||
|
||
// CHECK: .section custom_data,"aw",@progbits{{$}} | ||
// CHECK: i: | ||
// CHECK: j: | ||
|
||
// SEPARATE: .section custom_data,"aw",@progbits,unique,3{{$}} | ||
// SEPARATE: i: | ||
// SEPARATE: .section custom_data,"aw",@progbits,unique,4{{$}} | ||
// SEPARATE: j: |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -144,15 +144,15 @@ namespace llvm { | |
DisableIntegratedAS(false), FunctionSections(false), | ||
DataSections(false), IgnoreXCOFFVisibility(false), | ||
XCOFFTracebackTable(true), UniqueSectionNames(true), | ||
UniqueBasicBlockSectionNames(false), TrapUnreachable(false), | ||
NoTrapAfterNoreturn(false), TLSSize(0), EmulatedTLS(false), | ||
EnableTLSDESC(false), EnableIPRA(false), EmitStackSizeSection(false), | ||
EnableMachineOutliner(false), EnableMachineFunctionSplitter(false), | ||
SupportsDefaultOutlining(false), EmitAddrsig(false), BBAddrMap(false), | ||
EmitCallSiteInfo(false), SupportsDebugEntryValues(false), | ||
EnableDebugEntryValues(false), ValueTrackingVariableLocations(false), | ||
ForceDwarfFrameSection(false), XRayFunctionIndex(true), | ||
DebugStrictDwarf(false), Hotpatch(false), | ||
UniqueBasicBlockSectionNames(false), SeparateNamedSections(false), | ||
TrapUnreachable(false), NoTrapAfterNoreturn(false), TLSSize(0), | ||
EmulatedTLS(false), EnableTLSDESC(false), EnableIPRA(false), | ||
EmitStackSizeSection(false), EnableMachineOutliner(false), | ||
EnableMachineFunctionSplitter(false), SupportsDefaultOutlining(false), | ||
EmitAddrsig(false), BBAddrMap(false), EmitCallSiteInfo(false), | ||
SupportsDebugEntryValues(false), EnableDebugEntryValues(false), | ||
ValueTrackingVariableLocations(false), ForceDwarfFrameSection(false), | ||
XRayFunctionIndex(true), DebugStrictDwarf(false), Hotpatch(false), | ||
PPCGenScalarMASSEntries(false), JMCInstrument(false), | ||
EnableCFIFixup(false), MisExpect(false), XCOFFReadOnlyPointers(false), | ||
FPDenormalMode(DenormalMode::IEEE, DenormalMode::IEEE) {} | ||
|
@@ -277,6 +277,8 @@ namespace llvm { | |
/// Use unique names for basic block sections. | ||
unsigned UniqueBasicBlockSectionNames : 1; | ||
|
||
unsigned SeparateNamedSections : 1; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Almost all of the other flags have Doxygen comments. Worth something like: There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done |
||
|
||
/// Emit target-specific trap instruction for 'unreachable' IR instructions. | ||
unsigned TrapUnreachable : 1; | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -733,16 +733,22 @@ calcUniqueIDUpdateFlagsAndSize(const GlobalObject *GO, StringRef SectionName, | |
Ctx.isELFGenericMergeableSection(SectionName); | ||
// If this is the first ocurrence of this section name, treat it as the | ||
// generic section | ||
if (!SymbolMergeable && !SeenSectionNameBefore) | ||
return MCContext::GenericSectionID; | ||
if (!SymbolMergeable && !SeenSectionNameBefore) { | ||
if (TM.getSeparateNamedSections()) | ||
return NextUniqueID++; | ||
else | ||
return MCContext::GenericSectionID; | ||
} | ||
|
||
// Symbols must be placed into sections with compatible entry sizes. Generate | ||
// unique sections for symbols that have not been assigned to compatible | ||
// sections. | ||
const auto PreviousID = | ||
Ctx.getELFUniqueIDForEntsize(SectionName, Flags, EntrySize); | ||
if (PreviousID) | ||
if (PreviousID && (!TM.getSeparateNamedSections() || | ||
*PreviousID == MCContext::GenericSectionID)) { | ||
return *PreviousID; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. drop braces for one-line single statement There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done. |
||
} | ||
|
||
// If the user has specified the same section name as would be created | ||
// implicitly for this symbol e.g. .rodata.str1.1, then we don't need | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
; Test that global values with explicit sections are placed into unique sections. | ||
|
||
; RUN: llc < %s 2>&1 | FileCheck %s | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Drop unused There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done. |
||
; RUN: llc -separate-named-sections < %s 2>&1 | FileCheck %s --check-prefix=SEPARATE | ||
target triple="x86_64-unknown-unknown-elf" | ||
|
||
define i32 @f() section "custom_text" { | ||
entry: | ||
ret i32 0 | ||
} | ||
|
||
define i32 @g() section "custom_text" { | ||
entry: | ||
ret i32 0 | ||
} | ||
|
||
; CHECK: .section custom_text,"ax",@progbits{{$}} | ||
; CHECK: f: | ||
; CHECK: g: | ||
|
||
; SEPARATE: .section custom_text,"ax",@progbits,unique,1{{$}} | ||
; SEPARATE: f: | ||
; SEPARATE: .section custom_text,"ax",@progbits,unique,2{{$}} | ||
; SEPARATE: g: | ||
|
||
@i = global i32 0, section "custom_data", align 8 | ||
@j = global i32 0, section "custom_data", align 8 | ||
|
||
; CHECK: .section custom_data,"aw",@progbits{{$}} | ||
; CHECK: i: | ||
; CHECK: j: | ||
|
||
; SEPARATE: .section custom_data,"aw",@progbits,unique,3{{$}} | ||
; SEPARATE: i: | ||
; SEPARATE: .section custom_data,"aw",@progbits,unique,4{{$}} | ||
; SEPARATE: j: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should it be "This enables linker GC to collect ..."
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done