[PATCH] D62509: [Driver] Render -fuse-init-array for -fembed-bitcode

Fangrui Song via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon May 27 21:51:04 PDT 2019


MaskRay created this revision.
MaskRay added reviewers: compnerd, rsmith, t.p.northover.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Modern ELF platforms use -fuse-init-array to emit .init_array instead of
.ctors .  ld.bfd and gold 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.


Repository:
  rC Clang

https://reviews.llvm.org/D62509

Files:
  lib/Driver/ToolChains/Clang.cpp
  test/Driver/fembed-bitcode.c


Index: test/Driver/fembed-bitcode.c
===================================================================
--- test/Driver/fembed-bitcode.c
+++ test/Driver/fembed-bitcode.c
@@ -26,3 +26,6 @@
 // CHECK-AARCH64: "darwinpcs"
 // CHECK-AARCH64-NOT: "-fdebug-compilation-dir"
 
+// RUN: %clang -target x86_64-pc-freebsd12 -fembed-bitcode=all -c %s -o /dev/null -### 2>&1 \
+// RUN:     | FileCheck -check-prefix CHECK-INITARRAY %s
+// CHECK-INITARRAY: "-fuse-init-array"
Index: lib/Driver/ToolChains/Clang.cpp
===================================================================
--- lib/Driver/ToolChains/Clang.cpp
+++ lib/Driver/ToolChains/Clang.cpp
@@ -3671,6 +3671,9 @@
     // 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[] = {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D62509.201609.patch
Type: text/x-patch
Size: 1082 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20190528/9e09e15e/attachment.bin>


More information about the cfe-commits mailing list