[PATCH] D68213: [LTO] Support for embedding bitcode section during LTO

Josef Eisl via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Sep 30 05:58:44 PDT 2019


zapster created this revision.
zapster added reviewers: LLVM, clang, rsmith, pcc.
Herald added subscribers: llvm-commits, cfe-commits, dang, dexonsmith, steven_wu, aheejin, hiraditya, inglorion, mehdi_amini.
Herald added a reviewer: alexshap.
Herald added projects: clang, LLVM.
zapster updated this revision to Diff 222401.
zapster added a comment.

re-ran clang format


This adds support for embedding bitcode in a binary during LTO. The libLTO gains supports the `-lto-embed-bitcode` option which accepts `off`, `all`, `bitcode`, and `marker`. The semantics are the same as for clangs `-fembed-bitcode`. The option allows users of the LTO library to embed a bitcode section. For example, LLD can pass the option via `ld.lld -mllvm=-lto-embed-bitcode=all`.

This feature allows doing something comparable to `clang -c -fembed-bitcode`, but on the (LTO) linker level. Having bitcode alongside native code has many use-cases. To give an example, the MacOS linker can create a `-bitcode_bundle` section containing bitcode. Also, having this feature built into LLVM is an alternative to 3rd party tools such as wllvm <https://github.com/travitch/whole-program-llvm> or gllvm <https://github.com/SRI-CSL/gllvm>. As with these tools, this feature simplifies creating "whole-program" llvm bitcode files, but in contrast to wllvm/gllvm it does not rely on a specific llvm frontend/driver.

I originally proposed this feature as an addition to LLD <http://lists.llvm.org/pipermail/llvm-dev/2019-January/129657.html>. It turned out, however, that doing this purely on LLVM/LTO side is more general and might be useful to a broader audience.

The implementation is quite straight forward. The embedding logic moved from clang to llvm/lib/Bitcode and llvm/lib/LTO gained the `-lto-embed-bitcode` option. Most code just moved.


https://reviews.llvm.org/D68213

Files:
  clang/lib/CodeGen/BackendUtil.cpp
  clang/test/Frontend/x86-embed-bitcode.ll
  llvm/include/llvm/Bitcode/BitcodeWriter.h
  llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
  llvm/lib/LTO/LTOBackend.cpp
  llvm/test/LTO/X86/Inputs/start-lib1.ll
  llvm/test/LTO/X86/Inputs/start-lib2.ll
  llvm/test/LTO/X86/embed-bitcode.ll

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D68213.222401.patch
Type: text/x-patch
Size: 20207 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20190930/6d1d96a9/attachment-0001.bin>


More information about the cfe-commits mailing list