Skip to content

Commit 9b8e3d3

Browse files
committed
[Solaris] emit .init_array instead of .ctors on Solaris (Sparc/x86)
Patch by Fedor Sergeev. Differential Revision: https://reviews.llvm.org/D33868 llvm-svn: 305948
1 parent 798feb4 commit 9b8e3d3

File tree

7 files changed

+52
-0
lines changed

7 files changed

+52
-0
lines changed

llvm/lib/Target/Sparc/SparcTargetObjectFile.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,12 @@
1515

1616
using namespace llvm;
1717

18+
void SparcELFTargetObjectFile::Initialize(MCContext &Ctx,
19+
const TargetMachine &TM) {
20+
TargetLoweringObjectFileELF::Initialize(Ctx, TM);
21+
InitializeELF(TM.Options.UseInitArray);
22+
}
23+
1824
const MCExpr *SparcELFTargetObjectFile::getTTypeGlobalReference(
1925
const GlobalValue *GV, unsigned Encoding, const TargetMachine &TM,
2026
MachineModuleInfo *MMI, MCStreamer &Streamer) const {

llvm/lib/Target/Sparc/SparcTargetObjectFile.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ class SparcELFTargetObjectFile : public TargetLoweringObjectFileELF {
2323
TargetLoweringObjectFileELF()
2424
{}
2525

26+
void Initialize(MCContext &Ctx, const TargetMachine &TM) override;
27+
2628
const MCExpr *getTTypeGlobalReference(const GlobalValue *GV,
2729
unsigned Encoding,
2830
const TargetMachine &TM,

llvm/lib/Target/X86/X86TargetMachine.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,8 @@ static std::unique_ptr<TargetLoweringObjectFile> createTLOF(const Triple &TT) {
9191
return llvm::make_unique<X86FreeBSDTargetObjectFile>();
9292
if (TT.isOSLinux() || TT.isOSNaCl() || TT.isOSIAMCU())
9393
return llvm::make_unique<X86LinuxNaClTargetObjectFile>();
94+
if (TT.isOSSolaris())
95+
return llvm::make_unique<X86SolarisTargetObjectFile>();
9496
if (TT.isOSFuchsia())
9597
return llvm::make_unique<X86FuchsiaTargetObjectFile>();
9698
if (TT.isOSBinFormatELF())

llvm/lib/Target/X86/X86TargetObjectFile.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,12 @@ X86LinuxNaClTargetObjectFile::Initialize(MCContext &Ctx,
8686
InitializeELF(TM.Options.UseInitArray);
8787
}
8888

89+
void X86SolarisTargetObjectFile::Initialize(MCContext &Ctx,
90+
const TargetMachine &TM) {
91+
TargetLoweringObjectFileELF::Initialize(Ctx, TM);
92+
InitializeELF(TM.Options.UseInitArray);
93+
}
94+
8995
const MCExpr *X86WindowsTargetObjectFile::lowerRelativeReference(
9096
const GlobalValue *LHS, const GlobalValue *RHS,
9197
const TargetMachine &TM) const {

llvm/lib/Target/X86/X86TargetObjectFile.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,11 @@ namespace llvm {
6666
void Initialize(MCContext &Ctx, const TargetMachine &TM) override;
6767
};
6868

69+
/// \brief This implementation is used for Solaris on x86/x86-64.
70+
class X86SolarisTargetObjectFile : public X86ELFTargetObjectFile {
71+
void Initialize(MCContext &Ctx, const TargetMachine &TM) override;
72+
};
73+
6974
/// \brief This implementation is used for Windows targets on x86 and x86-64.
7075
class X86WindowsTargetObjectFile : public TargetLoweringObjectFileCOFF {
7176
const MCExpr *
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
; RUN: llc -mtriple sparc-sun-solaris2.11 -use-ctors < %s | FileCheck --check-prefix=CTOR %s
2+
; RUN: llc -mtriple sparc-sun-solaris2.11 < %s | FileCheck --check-prefix=INIT-ARRAY %s
3+
@llvm.global_ctors = appending global [2 x { i32, void ()*, i8* }] [{ i32, void ()*, i8* } { i32 65535, void ()* @f, i8* null}, { i32, void ()*, i8* } { i32 15, void ()* @g, i8* @v }]
4+
5+
@v = weak_odr global i8 0
6+
7+
define void @f() {
8+
entry:
9+
ret void
10+
}
11+
12+
define void @g() {
13+
entry:
14+
ret void
15+
}
16+
17+
; CTOR: .section .ctors.65520,#alloc,#write
18+
; CTOR-NEXT: .p2align 2
19+
; CTOR-NEXT: .word g
20+
; CTOR-NEXT: .section .ctors,#alloc,#write
21+
; CTOR-NEXT: .p2align 2
22+
; CTOR-NEXT: .word f
23+
24+
; INIT-ARRAY: .section .init_array.15,#alloc,#write
25+
; INIT-ARRAY-NEXT: .p2align 2
26+
; INIT-ARRAY-NEXT: .word g
27+
; INIT-ARRAY-NEXT: .section .init_array,#alloc,#write
28+
; INIT-ARRAY-NEXT: .p2align 2
29+
; INIT-ARRAY-NEXT: .word f

llvm/test/CodeGen/X86/constructor.ll

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
; RUN: llc -mtriple x86_64-pc-linux -use-ctors < %s | FileCheck --check-prefix=CTOR %s
22
; RUN: llc -mtriple x86_64-unknown-freebsd -use-ctors < %s | FileCheck --check-prefix=CTOR %s
3+
; RUN: llc -mtriple x86_64-pc-solaris2.11 -use-ctors < %s | FileCheck --check-prefix=CTOR %s
34
; RUN: llc -mtriple x86_64-pc-linux < %s | FileCheck --check-prefix=INIT-ARRAY %s
45
; RUN: llc -mtriple x86_64-unknown-freebsd < %s | FileCheck --check-prefix=INIT-ARRAY %s
6+
; RUN: llc -mtriple x86_64-pc-solaris2.11 < %s | FileCheck --check-prefix=INIT-ARRAY %s
57
; RUN: llc -mtriple x86_64-unknown-nacl < %s | FileCheck --check-prefix=NACL %s
68
; RUN: llc -mtriple i586-intel-elfiamcu -use-ctors < %s | FileCheck %s --check-prefix=MCU-CTORS
79
; RUN: llc -mtriple i586-intel-elfiamcu < %s | FileCheck %s --check-prefix=MCU-INIT-ARRAY

0 commit comments

Comments
 (0)