@@ -1677,6 +1677,22 @@ MCSection *TargetLoweringObjectFileCOFF::getExplicitSectionGlobal(
1677
1677
Name == getInstrProfSectionName (IPSK_covname, Triple::COFF,
1678
1678
/* AddSegmentInfo=*/ false ))
1679
1679
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
+
1680
1696
int Selection = 0 ;
1681
1697
unsigned Characteristics = getCOFFSectionFlags (Kind, TM);
1682
1698
StringRef COMDATSymName = " " ;
@@ -2378,13 +2394,28 @@ MCSection *TargetLoweringObjectFileXCOFF::getExplicitSectionGlobal(
2378
2394
StringRef SectionName = GO->getSection ();
2379
2395
2380
2396
// 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)) {
2382
2398
if (GVar->hasAttribute (" toc-data" ))
2383
2399
return getContext ().getXCOFFSection (
2384
2400
SectionName, Kind,
2385
2401
XCOFF::CsectProperties (/* MappingClass*/ XCOFF::XMC_TD, XCOFF::XTY_SD),
2386
2402
/* MultiSymbolsAllowed*/ true );
2387
2403
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
+
2388
2419
XCOFF::StorageMappingClass MappingClass;
2389
2420
if (Kind.isText ())
2390
2421
MappingClass = XCOFF::XMC_PR;
0 commit comments