[PATCH] D154923: [CodeGen] Support bitcode input containing multiple modules

Fangrui Song via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Jul 10 23:45:35 PDT 2023


MaskRay created this revision.
MaskRay added reviewers: ormris, efriedma, rjmccall, aaron.ballman.
Herald added subscribers: steven_wu, hiraditya.
Herald added a project: All.
MaskRay requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

When using -fsplit-lto-unit (explicitly specified or due to using
-fsanitize=cfi/-fwhole-program-vtables), the emitted LLVM IR contains a module
flag metadata `"EnableSplitLTOUnit"`. If a module contains both type metadata and
`"EnableSplitLTOUnit"`, `ThinLTOBitcodeWriter.cpp` will write two modules into
the bitcode file. Compiling the bitcode will lead to an error due to `parseIR`
requiring a single module.

  % clang -flto=thin a.cc -c -o a.bc
  % clang -c a.bc
  % clang -fsplit-lto-unit -flto=thin a.cc -c -o a.bc
  % clang -c a.bc
  error: Expected a single module
  1 error generated.

Let's place the extra module (if present) into CodeGenOptions::LinkBitcodeFiles
(originally for -cc1 -mlink-bitcode-file). Linker::linkModules will link the two
modules together. This patch makes the following commands work:

  clang -S -emit-llvm a.bc
  clang -S a.bc
  clang -c a.bc


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D154923

Files:
  clang/lib/CodeGen/CodeGenAction.cpp
  clang/test/CodeGen/split-lto-unit-input.cpp

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D154923.538926.patch
Type: text/x-patch
Size: 4065 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230711/b1ebd989/attachment-0001.bin>


More information about the cfe-commits mailing list