From: Fangrui Song Date: Thu, 30 May 2019 02:30:04 +0000 (+0000) Subject: [Driver] Render target options (e.g. -fuse-init-array) for -fembed-bitcode X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=a59c51ceaf36b891acc3a98fa12e67819d7993df;p=clang [Driver] Render target options (e.g. -fuse-init-array) for -fembed-bitcode Modern ELF platforms use -fuse-init-array to emit .init_array instead of .ctors . ld.bfd and gold --ctors-in-init-array merge .init_array and .ctors into .init_array but lld doesn't do that. If crtbegin*.o crtend*.o don't provide .ctors/.dtors, such .ctors in user object files can lead to crash (see PR42002. The first and the last elements in .ctors/.dtors are ignored - they are traditionally provided by crtbegin*.o crtend*.o). Call addClangTargetOptions() to ensure -fuse-init-array is rendered on modern ELF platforms. On Hexagon, this renders -target-feature +reserved-r19 for -ffixed-r19. Reviewed By: compnerd Differential Revision: https://reviews.llvm.org/D62509 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@362052 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Driver/ToolChains/Clang.cpp b/lib/Driver/ToolChains/Clang.cpp index 3009bc8d29..650f73d36f 100644 --- a/lib/Driver/ToolChains/Clang.cpp +++ b/lib/Driver/ToolChains/Clang.cpp @@ -3666,6 +3666,9 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA, // Disable all llvm IR level optimizations. CmdArgs.push_back("-disable-llvm-passes"); + // Render target options such as -fuse-init-array on modern ELF platforms. + TC.addClangTargetOptions(Args, CmdArgs, JA.getOffloadingDeviceKind()); + // reject options that shouldn't be supported in bitcode // also reject kernel/kext static const constexpr unsigned kBitcodeOptionBlacklist[] = { diff --git a/test/Driver/fembed-bitcode.c b/test/Driver/fembed-bitcode.c index b0ec63f13f..c1f020b38a 100644 --- a/test/Driver/fembed-bitcode.c +++ b/test/Driver/fembed-bitcode.c @@ -26,3 +26,11 @@ // CHECK-AARCH64: "darwinpcs" // CHECK-AARCH64-NOT: "-fdebug-compilation-dir" +// RUN: %clang -target x86_64-pc-freebsd12 -fembed-bitcode=all -c %s -### 2>&1 \ +// RUN: | FileCheck --check-prefix=CHECK-INITARRAY %s +// CHECK-INITARRAY: "-fuse-init-array" + +// RUN: %clang -target hexagon-unknown-elf -ffixed-r19 -fembed-bitcode=all -c %s -### 2>&1 \ +// RUN: | FileCheck --check-prefix=CHECK-HEXAGON %s +// CHECK-HEXAGON: "-target-feature" +// CHECK-HEXAGON: "+reserved-r19"