Skip to content

Commit 3353156

Browse files
committedOct 10, 2018
[MC][ELF] compute entity size for explicit sections
Summary: Global variables might declare themselves to be in explicit sections. Calculate the entity size always to prevent assembler warnings "entity size for SHF_MERGE not specified" when sections are to be marked merge-able. Fixes PR31828. Reviewers: rnk, echristo Reviewed By: rnk Subscribers: llvm-commits, pirama, srhines Differential Revision: https://reviews.llvm.org/D53056 llvm-svn: 344197
1 parent 3c43448 commit 3353156

File tree

2 files changed

+28
-25
lines changed

2 files changed

+28
-25
lines changed
 

‎llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -506,6 +506,30 @@ static const MCSymbolELF *getAssociatedSymbol(const GlobalObject *GO,
506506
return OtherGO ? dyn_cast<MCSymbolELF>(TM.getSymbol(OtherGO)) : nullptr;
507507
}
508508

509+
static unsigned getEntrySizeForKind(SectionKind Kind) {
510+
if (Kind.isMergeable1ByteCString())
511+
return 1;
512+
else if (Kind.isMergeable2ByteCString())
513+
return 2;
514+
else if (Kind.isMergeable4ByteCString())
515+
return 4;
516+
else if (Kind.isMergeableConst4())
517+
return 4;
518+
else if (Kind.isMergeableConst8())
519+
return 8;
520+
else if (Kind.isMergeableConst16())
521+
return 16;
522+
else if (Kind.isMergeableConst32())
523+
return 32;
524+
else {
525+
// We shouldn't have mergeable C strings or mergeable constants that we
526+
// didn't handle above.
527+
assert(!Kind.isMergeableCString() && "unknown string width");
528+
assert(!Kind.isMergeableConst() && "unknown data width");
529+
return 0;
530+
}
531+
}
532+
509533
MCSection *TargetLoweringObjectFileELF::getExplicitSectionGlobal(
510534
const GlobalObject *GO, SectionKind Kind, const TargetMachine &TM) const {
511535
StringRef SectionName = GO->getSection();
@@ -550,7 +574,7 @@ MCSection *TargetLoweringObjectFileELF::getExplicitSectionGlobal(
550574

551575
MCSectionELF *Section = getContext().getELFSection(
552576
SectionName, getELFSectionType(SectionName, Kind), Flags,
553-
/*EntrySize=*/0, Group, UniqueID, AssociatedSymbol);
577+
getEntrySizeForKind(Kind), Group, UniqueID, AssociatedSymbol);
554578
// Make sure that we did not get some other section with incompatible sh_link.
555579
// This should not be possible due to UniqueID code above.
556580
assert(Section->getAssociatedSymbol() == AssociatedSymbol &&
@@ -577,30 +601,6 @@ static StringRef getSectionPrefixForGlobal(SectionKind Kind) {
577601
return ".data.rel.ro";
578602
}
579603

580-
static unsigned getEntrySizeForKind(SectionKind Kind) {
581-
if (Kind.isMergeable1ByteCString())
582-
return 1;
583-
else if (Kind.isMergeable2ByteCString())
584-
return 2;
585-
else if (Kind.isMergeable4ByteCString())
586-
return 4;
587-
else if (Kind.isMergeableConst4())
588-
return 4;
589-
else if (Kind.isMergeableConst8())
590-
return 8;
591-
else if (Kind.isMergeableConst16())
592-
return 16;
593-
else if (Kind.isMergeableConst32())
594-
return 32;
595-
else {
596-
// We shouldn't have mergeable C strings or mergeable constants that we
597-
// didn't handle above.
598-
assert(!Kind.isMergeableCString() && "unknown string width");
599-
assert(!Kind.isMergeableConst() && "unknown data width");
600-
return 0;
601-
}
602-
}
603-
604604
static MCSectionELF *selectELFSectionForGlobal(
605605
MCContext &Ctx, const GlobalObject *GO, SectionKind Kind, Mangler &Mang,
606606
const TargetMachine &TM, bool EmitUniqueSection, unsigned Flags,
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
; RUN: llc < %s | FileCheck %s
2+
@a = internal unnamed_addr constant [1 x [1 x i32]] zeroinitializer, section ".init.rodata", align 4
3+
; CHECK: .init.rodata,"aM",@progbits,4

0 commit comments

Comments
 (0)
Please sign in to comment.