llvm.org GIT mirror llvm / 0cb2a45
Emit the ctors in the proper order on ARM/EABI. Maybe some targets should use this as well. Patch by Evgeniy Stepanov! git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@145781 91177308-0d34-0410-b5e6-96231b3b80d8 Anton Korobeynikov 8 years ago
8 changed file(s) with 53 addition(s) and 19 deletion(s). Raw diff Collapse all Expand all
3535 enum LCOMMType { None, NoAlignment, ByteAlignment };
3636 }
3737
38 namespace Structors {
39 enum OutputOrder { None, PriorityOrder, ReversePriorityOrder };
40 }
41
4238 /// MCAsmInfo - This class is intended to be used as a base class for asm
4339 /// properties and features specific to the target.
4440 class MCAsmInfo {
7167 /// the macho-specific .tbss directive for emitting thread local BSS Symbols
7268 bool HasMachoTBSSDirective; // Default is false.
7369
74 /// StructorOutputOrder - Whether the static ctor/dtor list should be output
75 /// in no particular order, in order of increasing priority or the reverse:
76 /// in order of decreasing priority (the default).
77 Structors::OutputOrder StructorOutputOrder; // Default is reverse order.
78
7970 /// HasStaticCtorDtorReferenceInStaticMode - True if the compiler should
8071 /// emit a ".reference .constructors_used" or ".reference .destructors_used"
8172 /// directive after the a static ctor/dtor list. This directive is only
427418 //
428419 bool hasMachoZeroFillDirective() const { return HasMachoZeroFillDirective; }
429420 bool hasMachoTBSSDirective() const { return HasMachoTBSSDirective; }
430 Structors::OutputOrder getStructorOutputOrder() const {
431 return StructorOutputOrder;
432 }
433421 bool hasStaticCtorDtorReferenceInStaticMode() const {
434422 return HasStaticCtorDtorReferenceInStaticMode;
435423 }
1818 #include "llvm/MC/SectionKind.h"
1919
2020 namespace llvm {
21 class MCContext;
22 class MCSection;
23 class Triple;
24
21 class MCContext;
22 class MCSection;
23 class Triple;
24
25 namespace Structors {
26 enum OutputOrder { None, PriorityOrder, ReversePriorityOrder };
27 }
28
2529 class MCObjectFileInfo {
2630 protected:
2731 /// CommDirectiveSupportsAlignment - True if .comm supports alignment. This
163167 const MCSection *PDataSection;
164168 const MCSection *XDataSection;
165169
170 /// StructorOutputOrder - Whether the static ctor/dtor list should be output
171 /// in no particular order, in order of increasing priority or the reverse:
172 /// in order of decreasing priority (the default).
173 Structors::OutputOrder StructorOutputOrder; // Default is reverse order.
174
166175 public:
167176 void InitMCObjectFileInfo(StringRef TT, Reloc::Model RM, CodeModel::Model CM,
168177 MCContext &ctx);
290299 return EHFrameSection;
291300 }
292301
302 Structors::OutputOrder getStructorOutputOrder() const {
303 return StructorOutputOrder;
304 }
305
293306 private:
294307 enum Environment { IsMachO, IsELF, IsCOFF };
295308 Environment Env;
12901290 }
12911291
12921292 // Emit the function pointers in reverse priority order.
1293 switch (MAI->getStructorOutputOrder()) {
1293 switch (getObjFileLowering().getStructorOutputOrder()) {
12941294 case Structors::None:
12951295 break;
12961296 case Structors::PriorityOrder:
2828 HasSubsectionsViaSymbols = false;
2929 HasMachoZeroFillDirective = false;
3030 HasMachoTBSSDirective = false;
31 StructorOutputOrder = Structors::ReversePriorityOrder;
3231 HasStaticCtorDtorReferenceInStaticMode = false;
3332 LinkerRequiresNonEmptyDwarfLines = false;
3433 MaxInstLength = 4;
3838 ZeroDirective = "\t.space\t"; // ".space N" emits N zeros.
3939 HasMachoZeroFillDirective = true; // Uses .zerofill
4040 HasMachoTBSSDirective = true; // Uses .tbss
41 StructorOutputOrder = Structors::PriorityOrder;
4241 HasStaticCtorDtorReferenceInStaticMode = true;
4342
4443 CodeBegin = "L$start$code$";
2929 // .comm doesn't support alignment before Leopard.
3030 if (T.isMacOSX() && T.isMacOSXVersionLT(10, 5))
3131 CommDirectiveSupportsAlignment = false;
32
33 StructorOutputOrder = Structors::PriorityOrder;
3234
3335 TextSection // .text
3436 = Ctx->getMachOSection("__TEXT", "__text",
257259 }
258260 }
259261
262 StructorOutputOrder = Structors::ReversePriorityOrder;
263
260264 // ELF
261265 BSSSection =
262266 Ctx->getELFSection(".bss", ELF::SHT_NOBITS,
384388
385389 void MCObjectFileInfo::InitCOFFMCObjectFileInfo(Triple T) {
386390 // COFF
391 StructorOutputOrder = Structors::ReversePriorityOrder;
392
387393 TextSection =
388394 Ctx->getCOFFSection(".text",
389395 COFF::IMAGE_SCN_CNT_CODE |
3535 ELF::SHF_WRITE |
3636 ELF::SHF_ALLOC,
3737 SectionKind::getDataRel());
38 StructorOutputOrder = Structors::PriorityOrder;
3839 LSDASection = NULL;
3940 }
4041
0 ; RUN: llc < %s -mtriple=arm-apple-darwin | FileCheck %s -check-prefix=DARWIN
1 ; RUN: llc < %s -mtriple=arm-linux-gnu | FileCheck %s -check-prefix=ELF
2 ; RUN: llc < %s -mtriple=arm-linux-gnueabi | FileCheck %s -check-prefix=GNUEABI
3
4 ; DARWIN: .section __DATA,__mod_init_func,mod_init_funcs
5 ; DARWIN: .long _f151
6 ; DARWIN-NEXT: .long _f152
7
8 ; ELF: .section .ctors,"aw",%progbits
9 ; ELF: .long f152
10 ; ELF-NEXT: .long f151
11
12 ; GNUEABI: .section .init_array,"aw",%init_array
13 ; GNUEABI: .long f151
14 ; GNUEABI-NEXT: .long f152
15
16
17 @llvm.global_ctors = appending global [2 x { i32, void ()* }] [ { i32, void ()* } { i32 151, void ()* @f151 }, { i32, void ()* } { i32 152, void ()* @f152 } ]
18
19 define void @f151() {
20 entry:
21 ret void
22 }
23
24 define void @f152() {
25 entry:
26 ret void
27 }