[PATCH] D32543: [X86] Clang option -fuse-init-array has no effect when generating for MCU target
Andrei via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Wed Apr 26 09:15:55 PDT 2017
AndreiGrischenko created this revision.
Our runtime for MCU X86 target supports .init_array section for globals that should be dynamically initialized.
But default Clang generates .ctors section and even if it has option -fuse-init-array, the option has no effect if set explicitly in a command-line.
The problem is in lack of -fuse-array-init option initialization in CodeGen
void
X86LinuxNaClTargetObjectFile::Initialize(MCContext &Ctx,
const TargetMachine &TM) {
TargetLoweringObjectFileELF::Initialize(Ctx, TM);
InitializeELF(TM.Options.UseInitArray);
}
https://reviews.llvm.org/D32543
Files:
llvm/lib/Target/X86/X86TargetMachine.cpp
llvm/tools/clang/test/CodeGen/init_array_sectionMCU.c
Index: llvm/tools/clang/test/CodeGen/init_array_sectionMCU.c
===================================================================
--- llvm/tools/clang/test/CodeGen/init_array_sectionMCU.c
+++ llvm/tools/clang/test/CodeGen/init_array_sectionMCU.c
@@ -0,0 +1,18 @@
+// REQUIRES: x86-registered-target
+
+// RUN: %clang_cc1 -triple i586-intel-elfiamcu -S -o - < %s | FileCheck %s --check-prefix=CTORS
+// RUN: %clang_cc1 -triple i586-intel-elfiamcu -S -fuse-init-array -o - < %s | FileCheck %s --check-prefix=INIT_ARR
+// RUN: %clang_cc1 -triple i586-intel-elfiamcu -S -fno-use-init-array -o - < %s | FileCheck %s --check-prefix=CTORS
+
+
+int a = 1;
+
+void __attribute__((constructor)) foo()
+{
+ a = 0;
+}
+
+// INIT_ARR: .init_array
+// CTORS-NOT: .init_array
+// CTORS: .ctors
+// CTORS-NOT: .init_array
Index: llvm/lib/Target/X86/X86TargetMachine.cpp
===================================================================
--- llvm/lib/Target/X86/X86TargetMachine.cpp
+++ llvm/lib/Target/X86/X86TargetMachine.cpp
@@ -56,7 +56,7 @@
if (TT.isOSFreeBSD())
return make_unique<X86FreeBSDTargetObjectFile>();
- if (TT.isOSLinux() || TT.isOSNaCl())
+ if (TT.isOSLinux() || TT.isOSNaCl() || TT.isOSIAMCU())
return make_unique<X86LinuxNaClTargetObjectFile>();
if (TT.isOSFuchsia())
return make_unique<X86FuchsiaTargetObjectFile>();
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D32543.96747.patch
Type: text/x-patch
Size: 1680 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170426/10930098/attachment.bin>
More information about the llvm-commits
mailing list