r362052 - [Driver] Render target options (e.g. -fuse-init-array) for -fembed-bitcode

Fangrui Song via cfe-commits cfe-commits at lists.llvm.org
Wed May 29 19:30:04 PDT 2019


Author: maskray
Date: Wed May 29 19:30:04 2019
New Revision: 362052

URL: http://llvm.org/viewvc/llvm-project?rev=362052&view=rev
Log:
[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

Modified:
    cfe/trunk/lib/Driver/ToolChains/Clang.cpp
    cfe/trunk/test/Driver/fembed-bitcode.c

Modified: cfe/trunk/lib/Driver/ToolChains/Clang.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/ToolChains/Clang.cpp?rev=362052&r1=362051&r2=362052&view=diff
==============================================================================
--- cfe/trunk/lib/Driver/ToolChains/Clang.cpp (original)
+++ cfe/trunk/lib/Driver/ToolChains/Clang.cpp Wed May 29 19:30:04 2019
@@ -3666,6 +3666,9 @@ void Clang::ConstructJob(Compilation &C,
     // 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[] = {

Modified: cfe/trunk/test/Driver/fembed-bitcode.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/fembed-bitcode.c?rev=362052&r1=362051&r2=362052&view=diff
==============================================================================
--- cfe/trunk/test/Driver/fembed-bitcode.c (original)
+++ cfe/trunk/test/Driver/fembed-bitcode.c Wed May 29 19:30:04 2019
@@ -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"




More information about the cfe-commits mailing list