mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-10-25 10:27:04 +00:00
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
This commit is contained in:
@@ -36,10 +36,6 @@ namespace llvm {
|
|||||||
enum LCOMMType { None, NoAlignment, ByteAlignment };
|
enum LCOMMType { None, NoAlignment, ByteAlignment };
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace Structors {
|
|
||||||
enum OutputOrder { None, PriorityOrder, ReversePriorityOrder };
|
|
||||||
}
|
|
||||||
|
|
||||||
/// MCAsmInfo - This class is intended to be used as a base class for asm
|
/// MCAsmInfo - This class is intended to be used as a base class for asm
|
||||||
/// properties and features specific to the target.
|
/// properties and features specific to the target.
|
||||||
class MCAsmInfo {
|
class MCAsmInfo {
|
||||||
@@ -72,11 +68,6 @@ namespace llvm {
|
|||||||
/// the macho-specific .tbss directive for emitting thread local BSS Symbols
|
/// the macho-specific .tbss directive for emitting thread local BSS Symbols
|
||||||
bool HasMachoTBSSDirective; // Default is false.
|
bool HasMachoTBSSDirective; // Default is false.
|
||||||
|
|
||||||
/// StructorOutputOrder - Whether the static ctor/dtor list should be output
|
|
||||||
/// in no particular order, in order of increasing priority or the reverse:
|
|
||||||
/// in order of decreasing priority (the default).
|
|
||||||
Structors::OutputOrder StructorOutputOrder; // Default is reverse order.
|
|
||||||
|
|
||||||
/// HasStaticCtorDtorReferenceInStaticMode - True if the compiler should
|
/// HasStaticCtorDtorReferenceInStaticMode - True if the compiler should
|
||||||
/// emit a ".reference .constructors_used" or ".reference .destructors_used"
|
/// emit a ".reference .constructors_used" or ".reference .destructors_used"
|
||||||
/// directive after the a static ctor/dtor list. This directive is only
|
/// directive after the a static ctor/dtor list. This directive is only
|
||||||
@@ -428,9 +419,6 @@ namespace llvm {
|
|||||||
//
|
//
|
||||||
bool hasMachoZeroFillDirective() const { return HasMachoZeroFillDirective; }
|
bool hasMachoZeroFillDirective() const { return HasMachoZeroFillDirective; }
|
||||||
bool hasMachoTBSSDirective() const { return HasMachoTBSSDirective; }
|
bool hasMachoTBSSDirective() const { return HasMachoTBSSDirective; }
|
||||||
Structors::OutputOrder getStructorOutputOrder() const {
|
|
||||||
return StructorOutputOrder;
|
|
||||||
}
|
|
||||||
bool hasStaticCtorDtorReferenceInStaticMode() const {
|
bool hasStaticCtorDtorReferenceInStaticMode() const {
|
||||||
return HasStaticCtorDtorReferenceInStaticMode;
|
return HasStaticCtorDtorReferenceInStaticMode;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,10 +19,14 @@
|
|||||||
#include "llvm/MC/SectionKind.h"
|
#include "llvm/MC/SectionKind.h"
|
||||||
|
|
||||||
namespace llvm {
|
namespace llvm {
|
||||||
class MCContext;
|
class MCContext;
|
||||||
class MCSection;
|
class MCSection;
|
||||||
class Triple;
|
class Triple;
|
||||||
|
|
||||||
|
namespace Structors {
|
||||||
|
enum OutputOrder { None, PriorityOrder, ReversePriorityOrder };
|
||||||
|
}
|
||||||
|
|
||||||
class MCObjectFileInfo {
|
class MCObjectFileInfo {
|
||||||
protected:
|
protected:
|
||||||
/// CommDirectiveSupportsAlignment - True if .comm supports alignment. This
|
/// CommDirectiveSupportsAlignment - True if .comm supports alignment. This
|
||||||
@@ -164,6 +168,11 @@ protected:
|
|||||||
const MCSection *PDataSection;
|
const MCSection *PDataSection;
|
||||||
const MCSection *XDataSection;
|
const MCSection *XDataSection;
|
||||||
|
|
||||||
|
/// StructorOutputOrder - Whether the static ctor/dtor list should be output
|
||||||
|
/// in no particular order, in order of increasing priority or the reverse:
|
||||||
|
/// in order of decreasing priority (the default).
|
||||||
|
Structors::OutputOrder StructorOutputOrder; // Default is reverse order.
|
||||||
|
|
||||||
public:
|
public:
|
||||||
void InitMCObjectFileInfo(StringRef TT, Reloc::Model RM, CodeModel::Model CM,
|
void InitMCObjectFileInfo(StringRef TT, Reloc::Model RM, CodeModel::Model CM,
|
||||||
MCContext &ctx);
|
MCContext &ctx);
|
||||||
@@ -291,6 +300,10 @@ public:
|
|||||||
return EHFrameSection;
|
return EHFrameSection;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Structors::OutputOrder getStructorOutputOrder() const {
|
||||||
|
return StructorOutputOrder;
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
enum Environment { IsMachO, IsELF, IsCOFF };
|
enum Environment { IsMachO, IsELF, IsCOFF };
|
||||||
Environment Env;
|
Environment Env;
|
||||||
|
|||||||
@@ -1291,7 +1291,7 @@ void AsmPrinter::EmitXXStructorList(const Constant *List) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Emit the function pointers in reverse priority order.
|
// Emit the function pointers in reverse priority order.
|
||||||
switch (MAI->getStructorOutputOrder()) {
|
switch (getObjFileLowering().getStructorOutputOrder()) {
|
||||||
case Structors::None:
|
case Structors::None:
|
||||||
break;
|
break;
|
||||||
case Structors::PriorityOrder:
|
case Structors::PriorityOrder:
|
||||||
|
|||||||
@@ -29,7 +29,6 @@ MCAsmInfo::MCAsmInfo() {
|
|||||||
HasSubsectionsViaSymbols = false;
|
HasSubsectionsViaSymbols = false;
|
||||||
HasMachoZeroFillDirective = false;
|
HasMachoZeroFillDirective = false;
|
||||||
HasMachoTBSSDirective = false;
|
HasMachoTBSSDirective = false;
|
||||||
StructorOutputOrder = Structors::ReversePriorityOrder;
|
|
||||||
HasStaticCtorDtorReferenceInStaticMode = false;
|
HasStaticCtorDtorReferenceInStaticMode = false;
|
||||||
LinkerRequiresNonEmptyDwarfLines = false;
|
LinkerRequiresNonEmptyDwarfLines = false;
|
||||||
MaxInstLength = 4;
|
MaxInstLength = 4;
|
||||||
|
|||||||
@@ -39,7 +39,6 @@ MCAsmInfoDarwin::MCAsmInfoDarwin() {
|
|||||||
ZeroDirective = "\t.space\t"; // ".space N" emits N zeros.
|
ZeroDirective = "\t.space\t"; // ".space N" emits N zeros.
|
||||||
HasMachoZeroFillDirective = true; // Uses .zerofill
|
HasMachoZeroFillDirective = true; // Uses .zerofill
|
||||||
HasMachoTBSSDirective = true; // Uses .tbss
|
HasMachoTBSSDirective = true; // Uses .tbss
|
||||||
StructorOutputOrder = Structors::PriorityOrder;
|
|
||||||
HasStaticCtorDtorReferenceInStaticMode = true;
|
HasStaticCtorDtorReferenceInStaticMode = true;
|
||||||
|
|
||||||
CodeBegin = "L$start$code$";
|
CodeBegin = "L$start$code$";
|
||||||
|
|||||||
@@ -31,6 +31,8 @@ void MCObjectFileInfo::InitMachOMCObjectFileInfo(Triple T) {
|
|||||||
if (T.isMacOSX() && T.isMacOSXVersionLT(10, 5))
|
if (T.isMacOSX() && T.isMacOSXVersionLT(10, 5))
|
||||||
CommDirectiveSupportsAlignment = false;
|
CommDirectiveSupportsAlignment = false;
|
||||||
|
|
||||||
|
StructorOutputOrder = Structors::PriorityOrder;
|
||||||
|
|
||||||
TextSection // .text
|
TextSection // .text
|
||||||
= Ctx->getMachOSection("__TEXT", "__text",
|
= Ctx->getMachOSection("__TEXT", "__text",
|
||||||
MCSectionMachO::S_ATTR_PURE_INSTRUCTIONS,
|
MCSectionMachO::S_ATTR_PURE_INSTRUCTIONS,
|
||||||
@@ -258,6 +260,8 @@ void MCObjectFileInfo::InitELFMCObjectFileInfo(Triple T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
StructorOutputOrder = Structors::ReversePriorityOrder;
|
||||||
|
|
||||||
// ELF
|
// ELF
|
||||||
BSSSection =
|
BSSSection =
|
||||||
Ctx->getELFSection(".bss", ELF::SHT_NOBITS,
|
Ctx->getELFSection(".bss", ELF::SHT_NOBITS,
|
||||||
@@ -385,6 +389,8 @@ void MCObjectFileInfo::InitELFMCObjectFileInfo(Triple T) {
|
|||||||
|
|
||||||
void MCObjectFileInfo::InitCOFFMCObjectFileInfo(Triple T) {
|
void MCObjectFileInfo::InitCOFFMCObjectFileInfo(Triple T) {
|
||||||
// COFF
|
// COFF
|
||||||
|
StructorOutputOrder = Structors::ReversePriorityOrder;
|
||||||
|
|
||||||
TextSection =
|
TextSection =
|
||||||
Ctx->getCOFFSection(".text",
|
Ctx->getCOFFSection(".text",
|
||||||
COFF::IMAGE_SCN_CNT_CODE |
|
COFF::IMAGE_SCN_CNT_CODE |
|
||||||
|
|||||||
@@ -36,6 +36,7 @@ void ARMElfTargetObjectFile::Initialize(MCContext &Ctx,
|
|||||||
ELF::SHF_WRITE |
|
ELF::SHF_WRITE |
|
||||||
ELF::SHF_ALLOC,
|
ELF::SHF_ALLOC,
|
||||||
SectionKind::getDataRel());
|
SectionKind::getDataRel());
|
||||||
|
StructorOutputOrder = Structors::PriorityOrder;
|
||||||
LSDASection = NULL;
|
LSDASection = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
28
test/CodeGen/ARM/ctor_order.ll
Normal file
28
test/CodeGen/ARM/ctor_order.ll
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
; RUN: llc < %s -mtriple=arm-apple-darwin | FileCheck %s -check-prefix=DARWIN
|
||||||
|
; RUN: llc < %s -mtriple=arm-linux-gnu | FileCheck %s -check-prefix=ELF
|
||||||
|
; RUN: llc < %s -mtriple=arm-linux-gnueabi | FileCheck %s -check-prefix=GNUEABI
|
||||||
|
|
||||||
|
; DARWIN: .section __DATA,__mod_init_func,mod_init_funcs
|
||||||
|
; DARWIN: .long _f151
|
||||||
|
; DARWIN-NEXT: .long _f152
|
||||||
|
|
||||||
|
; ELF: .section .ctors,"aw",%progbits
|
||||||
|
; ELF: .long f152
|
||||||
|
; ELF-NEXT: .long f151
|
||||||
|
|
||||||
|
; GNUEABI: .section .init_array,"aw",%init_array
|
||||||
|
; GNUEABI: .long f151
|
||||||
|
; GNUEABI-NEXT: .long f152
|
||||||
|
|
||||||
|
|
||||||
|
@llvm.global_ctors = appending global [2 x { i32, void ()* }] [ { i32, void ()* } { i32 151, void ()* @f151 }, { i32, void ()* } { i32 152, void ()* @f152 } ]
|
||||||
|
|
||||||
|
define void @f151() {
|
||||||
|
entry:
|
||||||
|
ret void
|
||||||
|
}
|
||||||
|
|
||||||
|
define void @f152() {
|
||||||
|
entry:
|
||||||
|
ret void
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user