[PATCH] D53056: [MC][ELF] compute entity size for global variables
Nick Desaulniers via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue Oct 9 17:26:49 PDT 2018
nickdesaulniers created this revision.
nickdesaulniers added reviewers: rnk, echristo.
Herald added a subscriber: llvm-commits.
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".
Fixes PR31828.
Repository:
rL LLVM
https://reviews.llvm.org/D53056
Files:
lib/CodeGen/TargetLoweringObjectFileImpl.cpp
test/CodeGen/Generic/section_mergeable_size.ll
Index: test/CodeGen/Generic/section_mergeable_size.ll
===================================================================
--- /dev/null
+++ test/CodeGen/Generic/section_mergeable_size.ll
@@ -0,0 +1,3 @@
+; RUN: llc < %s | FileCheck %s
+ at a = internal unnamed_addr constant [1 x [1 x i32]] zeroinitializer, section ".init.rodata", align 4
+; CHECK: .init.rodata,"aM", at progbits,4
Index: lib/CodeGen/TargetLoweringObjectFileImpl.cpp
===================================================================
--- lib/CodeGen/TargetLoweringObjectFileImpl.cpp
+++ lib/CodeGen/TargetLoweringObjectFileImpl.cpp
@@ -506,6 +506,30 @@
return OtherGO ? dyn_cast<MCSymbolELF>(TM.getSymbol(OtherGO)) : nullptr;
}
+static unsigned getEntrySizeForKind(SectionKind Kind) {
+ if (Kind.isMergeable1ByteCString())
+ return 1;
+ else if (Kind.isMergeable2ByteCString())
+ return 2;
+ else if (Kind.isMergeable4ByteCString())
+ return 4;
+ else if (Kind.isMergeableConst4())
+ return 4;
+ else if (Kind.isMergeableConst8())
+ return 8;
+ else if (Kind.isMergeableConst16())
+ return 16;
+ else if (Kind.isMergeableConst32())
+ return 32;
+ else {
+ // We shouldn't have mergeable C strings or mergeable constants that we
+ // didn't handle above.
+ assert(!Kind.isMergeableCString() && "unknown string width");
+ assert(!Kind.isMergeableConst() && "unknown data width");
+ return 0;
+ }
+}
+
MCSection *TargetLoweringObjectFileELF::getExplicitSectionGlobal(
const GlobalObject *GO, SectionKind Kind, const TargetMachine &TM) const {
StringRef SectionName = GO->getSection();
@@ -548,9 +572,10 @@
Flags |= ELF::SHF_LINK_ORDER;
}
+ unsigned EntrySize = getEntrySizeForKind(Kind);
MCSectionELF *Section = getContext().getELFSection(
SectionName, getELFSectionType(SectionName, Kind), Flags,
- /*EntrySize=*/0, Group, UniqueID, AssociatedSymbol);
+ EntrySize, Group, UniqueID, AssociatedSymbol);
// Make sure that we did not get some other section with incompatible sh_link.
// This should not be possible due to UniqueID code above.
assert(Section->getAssociatedSymbol() == AssociatedSymbol &&
@@ -577,30 +602,6 @@
return ".data.rel.ro";
}
-static unsigned getEntrySizeForKind(SectionKind Kind) {
- if (Kind.isMergeable1ByteCString())
- return 1;
- else if (Kind.isMergeable2ByteCString())
- return 2;
- else if (Kind.isMergeable4ByteCString())
- return 4;
- else if (Kind.isMergeableConst4())
- return 4;
- else if (Kind.isMergeableConst8())
- return 8;
- else if (Kind.isMergeableConst16())
- return 16;
- else if (Kind.isMergeableConst32())
- return 32;
- else {
- // We shouldn't have mergeable C strings or mergeable constants that we
- // didn't handle above.
- assert(!Kind.isMergeableCString() && "unknown string width");
- assert(!Kind.isMergeableConst() && "unknown data width");
- return 0;
- }
-}
-
static MCSectionELF *selectELFSectionForGlobal(
MCContext &Ctx, const GlobalObject *GO, SectionKind Kind, Mangler &Mang,
const TargetMachine &TM, bool EmitUniqueSection, unsigned Flags,
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D53056.168919.patch
Type: text/x-patch
Size: 3126 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20181010/98710cd1/attachment.bin>
More information about the llvm-commits
mailing list