@@ -422,39 +422,44 @@ static StringRef getSectionPrefixForGlobal(SectionKind Kind) {
422
422
return " .data.rel.ro" ;
423
423
}
424
424
425
+ static unsigned getEntrySizeForKind (SectionKind Kind) {
426
+ if (Kind.isMergeable1ByteCString ())
427
+ return 1 ;
428
+ else if (Kind.isMergeable2ByteCString ())
429
+ return 2 ;
430
+ else if (Kind.isMergeable4ByteCString ())
431
+ return 4 ;
432
+ else if (Kind.isMergeableConst4 ())
433
+ return 4 ;
434
+ else if (Kind.isMergeableConst8 ())
435
+ return 8 ;
436
+ else if (Kind.isMergeableConst16 ())
437
+ return 16 ;
438
+ else if (Kind.isMergeableConst32 ())
439
+ return 32 ;
440
+ else {
441
+ // We shouldn't have mergeable C strings or mergeable constants that we
442
+ // didn't handle above.
443
+ assert (!Kind.isMergeableCString () && " unknown string width" );
444
+ assert (!Kind.isMergeableConst () && " unknown data width" );
445
+ return 0 ;
446
+ }
447
+ }
448
+
425
449
static MCSectionELF *selectELFSectionForGlobal (
426
450
MCContext &Ctx, const GlobalObject *GO, SectionKind Kind, Mangler &Mang,
427
451
const TargetMachine &TM, bool EmitUniqueSection, unsigned Flags,
428
452
unsigned *NextUniqueID, const MCSymbolELF *AssociatedSymbol) {
429
- unsigned EntrySize = 0 ;
430
- if (Kind.isMergeableCString ()) {
431
- if (Kind.isMergeable2ByteCString ()) {
432
- EntrySize = 2 ;
433
- } else if (Kind.isMergeable4ByteCString ()) {
434
- EntrySize = 4 ;
435
- } else {
436
- EntrySize = 1 ;
437
- assert (Kind.isMergeable1ByteCString () && " unknown string width" );
438
- }
439
- } else if (Kind.isMergeableConst ()) {
440
- if (Kind.isMergeableConst4 ()) {
441
- EntrySize = 4 ;
442
- } else if (Kind.isMergeableConst8 ()) {
443
- EntrySize = 8 ;
444
- } else if (Kind.isMergeableConst16 ()) {
445
- EntrySize = 16 ;
446
- } else {
447
- assert (Kind.isMergeableConst32 () && " unknown data width" );
448
- EntrySize = 32 ;
449
- }
450
- }
451
453
452
454
StringRef Group = " " ;
453
455
if (const Comdat *C = getELFComdat (GO)) {
454
456
Flags |= ELF::SHF_GROUP;
455
457
Group = C->getName ();
456
458
}
457
459
460
+ // Get the section entry size based on the kind.
461
+ unsigned EntrySize = getEntrySizeForKind (Kind);
462
+
458
463
SmallString<128 > Name;
459
464
if (Kind.isMergeableCString ()) {
460
465
// We also need alignment here.
0 commit comments