From 3181e8ef22a8ace464f299b7a565b4e13351f8de Mon Sep 17 00:00:00 2001 From: David Chisnall Date: Sun, 31 Mar 2019 11:22:19 +0000 Subject: [PATCH] [objc-gnustep] Use .init_array not .ctors when requested. This doesn't make a difference most of the time but FreeBSD/ARM doesn't run anything in the .ctors array. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@357362 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/CodeGen/CGObjCGNU.cpp | 7 ++++++- test/CodeGenObjC/gnu-init.m | 2 ++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/lib/CodeGen/CGObjCGNU.cpp b/lib/CodeGen/CGObjCGNU.cpp index ccf73cbfc8..2957a89390 100644 --- a/lib/CodeGen/CGObjCGNU.cpp +++ b/lib/CodeGen/CGObjCGNU.cpp @@ -1514,7 +1514,12 @@ class CGObjCGNUstep2 : public CGObjCGNUstep { if (CGM.getTriple().isOSBinFormatCOFF()) InitVar->setSection(".CRT$XCLz"); else - InitVar->setSection(".ctors"); + { + if (CGM.getCodeGenOpts().UseInitArray) + InitVar->setSection(".init_array"); + else + InitVar->setSection(".ctors"); + } InitVar->setVisibility(llvm::GlobalValue::HiddenVisibility); InitVar->setComdat(TheModule.getOrInsertComdat(".objc_ctor")); CGM.addUsedGlobal(InitVar); diff --git a/test/CodeGenObjC/gnu-init.m b/test/CodeGenObjC/gnu-init.m index 1bec097a44..05ebec7b1d 100644 --- a/test/CodeGenObjC/gnu-init.m +++ b/test/CodeGenObjC/gnu-init.m @@ -1,6 +1,7 @@ // RUN: %clang_cc1 -triple x86_64-unknown-freebsd -S -emit-llvm -fobjc-runtime=gnustep-2.0 -o - %s | FileCheck %s -check-prefix=CHECK-NEW // RUN: %clang_cc1 -triple x86_64-pc-windows-msvc -S -emit-llvm -fobjc-runtime=gnustep-2.0 -o - %s | FileCheck %s -check-prefix=CHECK-WIN // RUN: %clang_cc1 -triple x86_64-unknown-freebsd -S -emit-llvm -fobjc-runtime=gnustep-1.8 -o - %s | FileCheck %s -check-prefix=CHECK-OLD +// RUN: %clang_cc1 -triple x86_64-unknown-freebsd -fuse-init-array -S -emit-llvm -fobjc-runtime=gnustep-2.0 -o - %s | FileCheck %s -check-prefix=CHECK-INIT_ARRAY // Almost minimal Objective-C file, check that it emits calls to the correct // runtime entry points. @@ -39,6 +40,7 @@ // Check that the load function is manually inserted into .ctors. // CHECK-NEW: @.objc_ctor = linkonce hidden constant void ()* @.objcv2_load_function, section ".ctors", comdat +// CHECK-INIT_ARRAY: @.objc_ctor = linkonce hidden constant void ()* @.objcv2_load_function, section ".init_array", comdat // Make sure that we provide null versions of everything so the __start / -- 2.40.0