llvm.org GIT mirror llvm / 36935fd
[X86] Use the correct alignment for COMDAT constant pool entries COFF doesn't have sections with mergeable contents. Instead, each constant pool entry ends up in a COMDAT section. The linker, when choosing between COMDAT sections, doesn't choose the max alignment of the two sections. You just get whatever alignment was on the section. If one constant needed a higher alignment in one object file from another one, then we will get into trouble if the linker chooses the lower alignment one. Instead, lets promote the alignment of the constant pool entry to make sure we don't use an under aligned constant with an instruction which assumed otherwise. This fixes PR26680. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@261462 91177308-0d34-0410-b5e6-96231b3b80d8 David Majnemer 4 years ago
9 changed file(s) with 43 addition(s) and 19 deletion(s). Raw diff Collapse all Expand all
4646 /// Given a constant with the SectionKind, return a section that it should be
4747 /// placed in.
4848 MCSection *getSectionForConstant(const DataLayout &DL, SectionKind Kind,
49 const Constant *C) const override;
49 const Constant *C,
50 unsigned &Align) const override;
5051
5152 MCSection *getExplicitSectionGlobal(const GlobalValue *GV, SectionKind Kind,
5253 Mangler &Mang,
103104 const TargetMachine &TM) const override;
104105
105106 MCSection *getSectionForConstant(const DataLayout &DL, SectionKind Kind,
106 const Constant *C) const override;
107 const Constant *C,
108 unsigned &Align) const override;
107109
108110 /// The mach-o version of this method defaults to returning a stub reference.
109111 const MCExpr *
7070 /// placed in.
7171 virtual MCSection *getSectionForConstant(const DataLayout &DL,
7272 SectionKind Kind,
73 const Constant *C) const;
73 const Constant *C,
74 unsigned &Align) const;
7475
7576 /// Classify the specified global variable into a set of target independent
7677 /// categories embodied in SectionKind.
11931193
11941194 // Emit __morestack address if needed for indirect calls.
11951195 if (MMI->usesMorestackAddr()) {
1196 unsigned Align = 1;
11961197 MCSection *ReadOnlySection = getObjFileLowering().getSectionForConstant(
11971198 getDataLayout(), SectionKind::getReadOnly(),
1198 /*C=*/nullptr);
1199 /*C=*/nullptr, Align);
11991200 OutStreamer->SwitchSection(ReadOnlySection);
12001201
12011202 MCSymbol *AddrSymbol =
12851286 if (!CPE.isMachineConstantPoolEntry())
12861287 C = CPE.Val.ConstVal;
12871288
1288 MCSection *S =
1289 getObjFileLowering().getSectionForConstant(getDataLayout(), Kind, C);
1289 MCSection *S = getObjFileLowering().getSectionForConstant(getDataLayout(),
1290 Kind, C, Align);
12901291
12911292 // The number of sections are small, just do a linear search from the
12921293 // last section to the first.
350350 /// Given a mergeable constant with the specified size and relocation
351351 /// information, return a section that it should be placed in.
352352 MCSection *TargetLoweringObjectFileELF::getSectionForConstant(
353 const DataLayout &DL, SectionKind Kind, const Constant *C) const {
353 const DataLayout &DL, SectionKind Kind, const Constant *C,
354 unsigned &Align) const {
354355 if (Kind.isMergeableConst4() && MergeableConst4Section)
355356 return MergeableConst4Section;
356357 if (Kind.isMergeableConst8() && MergeableConst8Section)
635636 }
636637
637638 MCSection *TargetLoweringObjectFileMachO::getSectionForConstant(
638 const DataLayout &DL, SectionKind Kind, const Constant *C) const {
639 const DataLayout &DL, SectionKind Kind, const Constant *C,
640 unsigned &Align) const {
639641 // If this constant requires a relocation, we have to put it in the data
640642 // segment, not in the text segment.
641643 if (Kind.isData() || Kind.isReadOnlyWithRel())
251251
252252 MCSection *TargetLoweringObjectFile::getSectionForJumpTable(
253253 const Function &F, Mangler &Mang, const TargetMachine &TM) const {
254 unsigned Align = 0;
254255 return getSectionForConstant(F.getParent()->getDataLayout(),
255 SectionKind::getReadOnly(), /*C=*/nullptr);
256 SectionKind::getReadOnly(), /*C=*/nullptr,
257 Align);
256258 }
257259
258260 bool TargetLoweringObjectFile::shouldPutJumpTableInFunctionSection(
276278 /// Given a mergable constant with the specified size and relocation
277279 /// information, return a section that it should be placed in.
278280 MCSection *TargetLoweringObjectFile::getSectionForConstant(
279 const DataLayout &DL, SectionKind Kind, const Constant *C) const {
281 const DataLayout &DL, SectionKind Kind, const Constant *C,
282 unsigned &Align) const {
280283 if (Kind.isReadOnly() && ReadOnlySection != nullptr)
281284 return ReadOnlySection;
282285
567567 const DataLayout &DL = MF->getDataLayout();
568568 SectionKind Kind = CPE.getSectionKind(&DL);
569569 const Constant *C = CPE.Val.ConstVal;
570 unsigned Align = CPE.Alignment;
570571 if (const MCSectionCOFF *S = dyn_cast(
571 getObjFileLowering().getSectionForConstant(DL, Kind, C))) {
572 getObjFileLowering().getSectionForConstant(DL, Kind, C, Align))) {
572573 if (MCSymbol *Sym = S->getCOMDATSymbol()) {
573574 if (Sym->isUndefined())
574575 OutStreamer->EmitSymbolAttribute(Sym, MCSA_Global);
153153 }
154154
155155 MCSection *X86WindowsTargetObjectFile::getSectionForConstant(
156 const DataLayout &DL, SectionKind Kind, const Constant *C) const {
156 const DataLayout &DL, SectionKind Kind, const Constant *C,
157 unsigned &Align) const {
157158 if (Kind.isMergeableConst() && C) {
158159 const unsigned Characteristics = COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
159160 COFF::IMAGE_SCN_MEM_READ |
160161 COFF::IMAGE_SCN_LNK_COMDAT;
161162 std::string COMDATSymName;
162 if (Kind.isMergeableConst4() || Kind.isMergeableConst8())
163 COMDATSymName = "__real@" + scalarConstantToHexString(C);
164 else if (Kind.isMergeableConst16())
165 COMDATSymName = "__xmm@" + scalarConstantToHexString(C);
163 if (Kind.isMergeableConst4()) {
164 if (Align <= 4) {
165 COMDATSymName = "__real@" + scalarConstantToHexString(C);
166 Align = 4;
167 }
168 } else if (Kind.isMergeableConst8()) {
169 if (Align <= 8) {
170 COMDATSymName = "__real@" + scalarConstantToHexString(C);
171 Align = 8;
172 }
173 } else if (Kind.isMergeableConst16()) {
174 if (Align <= 16) {
175 COMDATSymName = "__xmm@" + scalarConstantToHexString(C);
176 Align = 16;
177 }
178 }
166179
167180 if (!COMDATSymName.empty())
168181 return getContext().getCOFFSection(".rdata", Characteristics, Kind,
170183 COFF::IMAGE_COMDAT_SELECT_ANY);
171184 }
172185
173 return TargetLoweringObjectFile::getSectionForConstant(DL, Kind, C);
186 return TargetLoweringObjectFile::getSectionForConstant(DL, Kind, C, Align);
174187 }
5858 /// \brief Given a mergeable constant with the specified size and relocation
5959 /// information, return a section that it should be placed in.
6060 MCSection *getSectionForConstant(const DataLayout &DL, SectionKind Kind,
61 const Constant *C) const override;
61 const Constant *C,
62 unsigned &Align) const override;
6263 };
6364
6465 } // end namespace llvm
7272
7373 ; CHECK: .globl __real@bf8000003f800000
7474 ; CHECK-NEXT: .section .rdata,"dr",discard,__real@bf8000003f800000
75 ; CHECK-NEXT: .p2align 2
75 ; CHECK-NEXT: .p2align 3
7676 ; CHECK-NEXT: __real@bf8000003f800000:
7777 ; CHECK-NEXT: .long 1065353216
7878 ; CHECK-NEXT: .long 3212836864