@@ -781,29 +781,32 @@ getGlobalObjectInfo(const GlobalObject *GO, const TargetMachine &TM) {
781
781
return {Group, IsComdat, Flags};
782
782
}
783
783
784
- static MCSection *selectExplicitSectionGlobal (
785
- const GlobalObject *GO, SectionKind Kind, const TargetMachine &TM,
786
- MCContext &Ctx, Mangler &Mang, unsigned &NextUniqueID,
787
- bool Retain, bool ForceUnique) {
788
- StringRef SectionName = GO->getSection ();
789
-
784
+ static StringRef handlePragmaClangSection (const GlobalObject *GO, SectionKind Kind) {
790
785
// Check if '#pragma clang section' name is applicable.
791
786
// Note that pragma directive overrides -ffunction-section, -fdata-section
792
787
// and so section name is exactly as user specified and not uniqued.
793
788
const GlobalVariable *GV = dyn_cast<GlobalVariable>(GO);
794
789
if (GV && GV->hasImplicitSection ()) {
795
790
auto Attrs = GV->getAttributes ();
796
- if (Attrs.hasAttribute (" bss-section" ) && Kind.isBSS ()) {
797
- SectionName = Attrs.getAttribute (" bss-section" ).getValueAsString ();
798
- } else if (Attrs.hasAttribute (" rodata-section" ) && Kind.isReadOnly ()) {
799
- SectionName = Attrs.getAttribute (" rodata-section" ).getValueAsString ();
800
- } else if (Attrs.hasAttribute (" relro-section" ) && Kind.isReadOnlyWithRel ()) {
801
- SectionName = Attrs.getAttribute (" relro-section" ).getValueAsString ();
802
- } else if (Attrs.hasAttribute (" data-section" ) && Kind.isData ()) {
803
- SectionName = Attrs.getAttribute (" data-section" ).getValueAsString ();
804
- }
791
+ if (Attrs.hasAttribute (" bss-section" ) && Kind.isBSS ())
792
+ return Attrs.getAttribute (" bss-section" ).getValueAsString ();
793
+ else if (Attrs.hasAttribute (" rodata-section" ) && Kind.isReadOnly ())
794
+ return Attrs.getAttribute (" rodata-section" ).getValueAsString ();
795
+ else if (Attrs.hasAttribute (" relro-section" ) && Kind.isReadOnlyWithRel ())
796
+ return Attrs.getAttribute (" relro-section" ).getValueAsString ();
797
+ else if (Attrs.hasAttribute (" data-section" ) && Kind.isData ())
798
+ return Attrs.getAttribute (" data-section" ).getValueAsString ();
805
799
}
806
800
801
+ return GO->getSection ();
802
+ }
803
+
804
+ static MCSection *selectExplicitSectionGlobal (
805
+ const GlobalObject *GO, SectionKind Kind, const TargetMachine &TM,
806
+ MCContext &Ctx, Mangler &Mang, unsigned &NextUniqueID,
807
+ bool Retain, bool ForceUnique) {
808
+ StringRef SectionName = handlePragmaClangSection (GO, Kind);
809
+
807
810
// Infer section flags from the section name if we can.
808
811
Kind = getELFKindForNamedSection (SectionName, Kind);
809
812
@@ -1284,21 +1287,7 @@ static void checkMachOComdat(const GlobalValue *GV) {
1284
1287
MCSection *TargetLoweringObjectFileMachO::getExplicitSectionGlobal (
1285
1288
const GlobalObject *GO, SectionKind Kind, const TargetMachine &TM) const {
1286
1289
1287
- StringRef SectionName = GO->getSection ();
1288
-
1289
- const GlobalVariable *GV = dyn_cast<GlobalVariable>(GO);
1290
- if (GV && GV->hasImplicitSection ()) {
1291
- auto Attrs = GV->getAttributes ();
1292
- if (Attrs.hasAttribute (" bss-section" ) && Kind.isBSS ()) {
1293
- SectionName = Attrs.getAttribute (" bss-section" ).getValueAsString ();
1294
- } else if (Attrs.hasAttribute (" rodata-section" ) && Kind.isReadOnly ()) {
1295
- SectionName = Attrs.getAttribute (" rodata-section" ).getValueAsString ();
1296
- } else if (Attrs.hasAttribute (" relro-section" ) && Kind.isReadOnlyWithRel ()) {
1297
- SectionName = Attrs.getAttribute (" relro-section" ).getValueAsString ();
1298
- } else if (Attrs.hasAttribute (" data-section" ) && Kind.isData ()) {
1299
- SectionName = Attrs.getAttribute (" data-section" ).getValueAsString ();
1300
- }
1301
- }
1290
+ StringRef SectionName = handlePragmaClangSection (GO, Kind);
1302
1291
1303
1292
// Parse the section specifier and create it if valid.
1304
1293
StringRef Segment, Section;
@@ -1667,7 +1656,7 @@ static int getSelectionForCOFF(const GlobalValue *GV) {
1667
1656
1668
1657
MCSection *TargetLoweringObjectFileCOFF::getExplicitSectionGlobal (
1669
1658
const GlobalObject *GO, SectionKind Kind, const TargetMachine &TM) const {
1670
- StringRef Name = GO-> getSection ( );
1659
+ StringRef Name = handlePragmaClangSection (GO, Kind );
1671
1660
if (Name == getInstrProfSectionName (IPSK_covmap, Triple::COFF,
1672
1661
/* AddSegmentInfo=*/ false ) ||
1673
1662
Name == getInstrProfSectionName (IPSK_covfun, Triple::COFF,
@@ -1677,6 +1666,7 @@ MCSection *TargetLoweringObjectFileCOFF::getExplicitSectionGlobal(
1677
1666
Name == getInstrProfSectionName (IPSK_covname, Triple::COFF,
1678
1667
/* AddSegmentInfo=*/ false ))
1679
1668
Kind = SectionKind::getMetadata ();
1669
+
1680
1670
int Selection = 0 ;
1681
1671
unsigned Characteristics = getCOFFSectionFlags (Kind, TM);
1682
1672
StringRef COMDATSymName = " " ;
0 commit comments