@@ -788,29 +788,35 @@ getGlobalObjectInfo(const GlobalObject *GO, const TargetMachine &TM) {
788
788
return {Group, IsComdat, Flags};
789
789
}
790
790
791
- static MCSection *selectExplicitSectionGlobal (
792
- const GlobalObject *GO, SectionKind Kind, const TargetMachine &TM,
793
- MCContext &Ctx, Mangler &Mang, unsigned &NextUniqueID,
794
- bool Retain, bool ForceUnique) {
795
- StringRef SectionName = GO->getSection ();
796
-
791
+ static StringRef handlePragmaClangSection (const GlobalObject *GO,
792
+ SectionKind Kind) {
797
793
// Check if '#pragma clang section' name is applicable.
798
794
// Note that pragma directive overrides -ffunction-section, -fdata-section
799
795
// and so section name is exactly as user specified and not uniqued.
800
796
const GlobalVariable *GV = dyn_cast<GlobalVariable>(GO);
801
797
if (GV && GV->hasImplicitSection ()) {
802
798
auto Attrs = GV->getAttributes ();
803
- if (Attrs.hasAttribute (" bss-section" ) && Kind.isBSS ()) {
804
- SectionName = Attrs.getAttribute (" bss-section" ).getValueAsString ();
805
- } else if (Attrs.hasAttribute (" rodata-section" ) && Kind.isReadOnly ()) {
806
- SectionName = Attrs.getAttribute (" rodata-section" ).getValueAsString ();
807
- } else if (Attrs.hasAttribute (" relro-section" ) && Kind.isReadOnlyWithRel ()) {
808
- SectionName = Attrs.getAttribute (" relro-section" ).getValueAsString ();
809
- } else if (Attrs.hasAttribute (" data-section" ) && Kind.isData ()) {
810
- SectionName = Attrs.getAttribute (" data-section" ).getValueAsString ();
811
- }
799
+ if (Attrs.hasAttribute (" bss-section" ) && Kind.isBSS ())
800
+ return Attrs.getAttribute (" bss-section" ).getValueAsString ();
801
+ else if (Attrs.hasAttribute (" rodata-section" ) && Kind.isReadOnly ())
802
+ return Attrs.getAttribute (" rodata-section" ).getValueAsString ();
803
+ else if (Attrs.hasAttribute (" relro-section" ) && Kind.isReadOnlyWithRel ())
804
+ return Attrs.getAttribute (" relro-section" ).getValueAsString ();
805
+ else if (Attrs.hasAttribute (" data-section" ) && Kind.isData ())
806
+ return Attrs.getAttribute (" data-section" ).getValueAsString ();
812
807
}
813
808
809
+ return GO->getSection ();
810
+ }
811
+
812
+ static MCSection *selectExplicitSectionGlobal (const GlobalObject *GO,
813
+ SectionKind Kind,
814
+ const TargetMachine &TM,
815
+ MCContext &Ctx, Mangler &Mang,
816
+ unsigned &NextUniqueID,
817
+ bool Retain, bool ForceUnique) {
818
+ StringRef SectionName = handlePragmaClangSection (GO, Kind);
819
+
814
820
// Infer section flags from the section name if we can.
815
821
Kind = getELFKindForNamedSection (SectionName, Kind);
816
822
@@ -1291,21 +1297,7 @@ static void checkMachOComdat(const GlobalValue *GV) {
1291
1297
MCSection *TargetLoweringObjectFileMachO::getExplicitSectionGlobal (
1292
1298
const GlobalObject *GO, SectionKind Kind, const TargetMachine &TM) const {
1293
1299
1294
- StringRef SectionName = GO->getSection ();
1295
-
1296
- const GlobalVariable *GV = dyn_cast<GlobalVariable>(GO);
1297
- if (GV && GV->hasImplicitSection ()) {
1298
- auto Attrs = GV->getAttributes ();
1299
- if (Attrs.hasAttribute (" bss-section" ) && Kind.isBSS ()) {
1300
- SectionName = Attrs.getAttribute (" bss-section" ).getValueAsString ();
1301
- } else if (Attrs.hasAttribute (" rodata-section" ) && Kind.isReadOnly ()) {
1302
- SectionName = Attrs.getAttribute (" rodata-section" ).getValueAsString ();
1303
- } else if (Attrs.hasAttribute (" relro-section" ) && Kind.isReadOnlyWithRel ()) {
1304
- SectionName = Attrs.getAttribute (" relro-section" ).getValueAsString ();
1305
- } else if (Attrs.hasAttribute (" data-section" ) && Kind.isData ()) {
1306
- SectionName = Attrs.getAttribute (" data-section" ).getValueAsString ();
1307
- }
1308
- }
1300
+ StringRef SectionName = handlePragmaClangSection (GO, Kind);
1309
1301
1310
1302
// Parse the section specifier and create it if valid.
1311
1303
StringRef Segment, Section;
@@ -1674,7 +1666,7 @@ static int getSelectionForCOFF(const GlobalValue *GV) {
1674
1666
1675
1667
MCSection *TargetLoweringObjectFileCOFF::getExplicitSectionGlobal (
1676
1668
const GlobalObject *GO, SectionKind Kind, const TargetMachine &TM) const {
1677
- StringRef Name = GO-> getSection ( );
1669
+ StringRef Name = handlePragmaClangSection (GO, Kind );
1678
1670
if (Name == getInstrProfSectionName (IPSK_covmap, Triple::COFF,
1679
1671
/* AddSegmentInfo=*/ false ) ||
1680
1672
Name == getInstrProfSectionName (IPSK_covfun, Triple::COFF,
@@ -1684,6 +1676,7 @@ MCSection *TargetLoweringObjectFileCOFF::getExplicitSectionGlobal(
1684
1676
Name == getInstrProfSectionName (IPSK_covname, Triple::COFF,
1685
1677
/* AddSegmentInfo=*/ false ))
1686
1678
Kind = SectionKind::getMetadata ();
1679
+
1687
1680
int Selection = 0 ;
1688
1681
unsigned Characteristics = getCOFFSectionFlags (Kind, TM);
1689
1682
StringRef COMDATSymName = " " ;
0 commit comments