@@ -1677,6 +1677,22 @@ MCSection *TargetLoweringObjectFileCOFF::getExplicitSectionGlobal(
16771677 Name == getInstrProfSectionName (IPSK_covname, Triple::COFF,
16781678 /* AddSegmentInfo=*/ false ))
16791679 Kind = SectionKind::getMetadata ();
1680+
1681+ const GlobalVariable *GV = dyn_cast<GlobalVariable>(GO);
1682+ if (GV && GV->hasImplicitSection ()) {
1683+ auto Attrs = GV->getAttributes ();
1684+ if (Attrs.hasAttribute (" bss-section" ) && Kind.isBSS ()) {
1685+ Name = Attrs.getAttribute (" bss-section" ).getValueAsString ();
1686+ } else if (Attrs.hasAttribute (" rodata-section" ) && Kind.isReadOnly ()) {
1687+ Name = Attrs.getAttribute (" rodata-section" ).getValueAsString ();
1688+ } else if (Attrs.hasAttribute (" relro-section" ) &&
1689+ Kind.isReadOnlyWithRel ()) {
1690+ Name = Attrs.getAttribute (" relro-section" ).getValueAsString ();
1691+ } else if (Attrs.hasAttribute (" data-section" ) && Kind.isData ()) {
1692+ Name = Attrs.getAttribute (" data-section" ).getValueAsString ();
1693+ }
1694+ }
1695+
16801696 int Selection = 0 ;
16811697 unsigned Characteristics = getCOFFSectionFlags (Kind, TM);
16821698 StringRef COMDATSymName = " " ;
@@ -2378,13 +2394,28 @@ MCSection *TargetLoweringObjectFileXCOFF::getExplicitSectionGlobal(
23782394 StringRef SectionName = GO->getSection ();
23792395
23802396 // Handle the XCOFF::TD case first, then deal with the rest.
2381- if (const GlobalVariable *GVar = dyn_cast<GlobalVariable>(GO))
2397+ if (const GlobalVariable *GVar = dyn_cast<GlobalVariable>(GO)) {
23822398 if (GVar->hasAttribute (" toc-data" ))
23832399 return getContext ().getXCOFFSection (
23842400 SectionName, Kind,
23852401 XCOFF::CsectProperties (/* MappingClass*/ XCOFF::XMC_TD, XCOFF::XTY_SD),
23862402 /* MultiSymbolsAllowed*/ true );
23872403
2404+ if (GVar->hasImplicitSection ()) {
2405+ auto Attrs = GVar->getAttributes ();
2406+ if (Attrs.hasAttribute (" bss-section" ) && Kind.isBSS ()) {
2407+ SectionName = Attrs.getAttribute (" bss-section" ).getValueAsString ();
2408+ } else if (Attrs.hasAttribute (" rodata-section" ) && Kind.isReadOnly ()) {
2409+ SectionName = Attrs.getAttribute (" rodata-section" ).getValueAsString ();
2410+ } else if (Attrs.hasAttribute (" relro-section" ) &&
2411+ Kind.isReadOnlyWithRel ()) {
2412+ SectionName = Attrs.getAttribute (" relro-section" ).getValueAsString ();
2413+ } else if (Attrs.hasAttribute (" data-section" ) && Kind.isData ()) {
2414+ SectionName = Attrs.getAttribute (" data-section" ).getValueAsString ();
2415+ }
2416+ }
2417+ }
2418+
23882419 XCOFF::StorageMappingClass MappingClass;
23892420 if (Kind.isText ())
23902421 MappingClass = XCOFF::XMC_PR;
0 commit comments