llvm.org GIT mirror llvm / 147272b
Darwin wants ctors/dtors to be ordered the other way round to linux. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@139015 91177308-0d34-0410-b5e6-96231b3b80d8 Duncan Sands 8 years ago
5 changed file(s) with 40 addition(s) and 10 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
3842 /// MCAsmInfo - This class is intended to be used as a base class for asm
3943 /// properties and features specific to the target.
4044 class MCAsmInfo {
6771 /// the macho-specific .tbss directive for emitting thread local BSS Symbols
6872 bool HasMachoTBSSDirective; // Default is false.
6973
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
7079 /// HasStaticCtorDtorReferenceInStaticMode - True if the compiler should
7180 /// emit a ".reference .constructors_used" or ".reference .destructors_used"
7281 /// directive after the a static ctor/dtor list. This directive is only
394403 //
395404 bool hasMachoZeroFillDirective() const { return HasMachoZeroFillDirective; }
396405 bool hasMachoTBSSDirective() const { return HasMachoTBSSDirective; }
406 Structors::OutputOrder getStructorOutputOrder() const {
407 return StructorOutputOrder;
408 }
397409 bool hasStaticCtorDtorReferenceInStaticMode() const {
398410 return HasStaticCtorDtorReferenceInStaticMode;
399411 }
12641264 }
12651265
12661266 // Emit the function pointers in reverse priority order.
1267 std::sort(Structors.rbegin(), Structors.rend(), priority_order);
1267 switch (MAI->getStructorOutputOrder()) {
1268 case Structors::None:
1269 break;
1270 case Structors::PriorityOrder:
1271 std::sort(Structors.begin(), Structors.end(), priority_order);
1272 break;
1273 case Structors::ReversePriorityOrder:
1274 std::sort(Structors.rbegin(), Structors.rend(), priority_order);
1275 break;
1276 }
12681277 for (unsigned i = 0, e = Structors.size(); i != e; ++i)
12691278 EmitGlobalConstant(Structors[i].second);
12701279 }
2828 HasSubsectionsViaSymbols = false;
2929 HasMachoZeroFillDirective = false;
3030 HasMachoTBSSDirective = false;
31 StructorOutputOrder = Structors::ReversePriorityOrder;
3132 HasStaticCtorDtorReferenceInStaticMode = false;
3233 LinkerRequiresNonEmptyDwarfLines = false;
3334 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;
4142 HasStaticCtorDtorReferenceInStaticMode = true;
4243
4344 // FIXME: Darwin 10 and newer don't need this.
None ; RUN: llc < %s -mtriple=i386-linux-gnu | FileCheck %s
0 ; RUN: llc < %s -mtriple=i386-linux-gnu | FileCheck %s --check-prefix=CHECK-DEFAULT
1 ; RUN: llc < %s -mtriple=i386-apple-darwin | FileCheck %s --check-prefix=CHECK-DARWIN
12 ; PR5329
23
34 @llvm.global_ctors = appending global [3 x { i32, void ()* }] [{ i32, void ()* } { i32 2000, void ()* @construct_2 }, { i32, void ()* } { i32 3000, void ()* @construct_3 }, { i32, void ()* } { i32 1000, void ()* @construct_1 }]
4 ; CHECK: ctors
5 ; CHECK: construct_3
6 ; CHECK: construct_2
7 ; CHECK: construct_1
5 ; CHECK-DEFAULT: construct_3
6 ; CHECK-DEFAULT: construct_2
7 ; CHECK-DEFAULT: construct_1
8
9 ; CHECK-DARWIN: construct_1
10 ; CHECK-DARWIN: construct_2
11 ; CHECK-DARWIN: construct_3
812
913 @llvm.global_dtors = appending global [3 x { i32, void ()* }] [{ i32, void ()* } { i32 2000, void ()* @destruct_2 }, { i32, void ()* } { i32 1000, void ()* @destruct_1 }, { i32, void ()* } { i32 3000, void ()* @destruct_3 }]
10 ; CHECK: dtors
11 ; CHECK: destruct_3
12 ; CHECK: destruct_2
13 ; CHECK: destruct_1
14 ; CHECK-DEFAULT: destruct_3
15 ; CHECK-DEFAULT: destruct_2
16 ; CHECK-DEFAULT: destruct_1
17
18 ; CHECK-DARWIN: destruct_1
19 ; CHECK-DARWIN: destruct_2
20 ; CHECK-DARWIN: destruct_3
1421
1522 declare void @construct_1()
1623 declare void @construct_2()