From 22dbcfe84e6eb926e4f77dcd4716e02cf9583f7f Mon Sep 17 00:00:00 2001 From: Steven Wu Date: Wed, 11 May 2016 16:26:03 +0000 Subject: [PATCH] Embed bitcode in object file (clang cc1 part) Summary: Teach clang to embed bitcode inside bitcode. When -fembed-bitcode cc1 option is used, clang will embed both the input bitcode and cc1 commandline into the bitcode in special sections before compiling to the object file. Using -fembed-bitcode-marker will only introduce a marker in both sections. Depends on D17390 Reviewers: rsmith Subscribers: yaron.keren, vsk, cfe-commits Differential Revision: http://reviews.llvm.org/D17392 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@269202 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/CodeGen/BackendUtil.h | 4 + include/clang/Driver/Options.td | 7 +- include/clang/Frontend/CodeGenOptions.def | 2 + include/clang/Frontend/CodeGenOptions.h | 11 +++ lib/CodeGen/BackendUtil.cpp | 90 +++++++++++++++++++++++ lib/CodeGen/CodeGenAction.cpp | 6 ++ lib/Driver/Driver.cpp | 21 ++++-- lib/Driver/Tools.cpp | 12 ++- lib/Frontend/CompilerInvocation.cpp | 39 ++++++++++ test/Driver/embed-bitcode.c | 15 +++- test/Frontend/embed-bitcode.ll | 59 +++++++++++++++ 11 files changed, 251 insertions(+), 15 deletions(-) create mode 100644 test/Frontend/embed-bitcode.ll diff --git a/include/clang/CodeGen/BackendUtil.h b/include/clang/CodeGen/BackendUtil.h index a3e3824508..f88057bfe6 100644 --- a/include/clang/CodeGen/BackendUtil.h +++ b/include/clang/CodeGen/BackendUtil.h @@ -16,6 +16,7 @@ namespace llvm { class Module; + class MemoryBufferRef; } namespace clang { @@ -37,6 +38,9 @@ namespace clang { const TargetOptions &TOpts, const LangOptions &LOpts, const llvm::DataLayout &TDesc, llvm::Module *M, BackendAction Action, raw_pwrite_stream *OS); + + void EmbedBitcode(llvm::Module *M, const CodeGenOptions &CGOpts, + llvm::MemoryBufferRef Buf); } #endif diff --git a/include/clang/Driver/Options.td b/include/clang/Driver/Options.td index e367b8c0bb..602e8fa7de 100644 --- a/include/clang/Driver/Options.td +++ b/include/clang/Driver/Options.td @@ -450,11 +450,14 @@ def fno_autolink : Flag <["-"], "fno-autolink">, Group, Flags<[DriverOption, CC1Option]>, HelpText<"Disable generation of linker directives for automatic library linking">; +def fembed_bitcode_EQ : Joined<["-"], "fembed-bitcode=">, + Group, Flags<[DriverOption, CC1Option]>, MetaVarName<"