[all-commits] [llvm/llvm-project] b2f7b5: [CodeGen] Support bitcode input containing multipl...
Fangrui Song via All-commits
all-commits at lists.llvm.org
Fri Jul 21 20:05:49 PDT 2023
Branch: refs/heads/main
Home: https://github.com/llvm/llvm-project
Commit: b2f7b5dbaefe4f2e3f8f279735ea3509a796693f
https://github.com/llvm/llvm-project/commit/b2f7b5dbaefe4f2e3f8f279735ea3509a796693f
Author: Fangrui Song <i at maskray.me>
Date: 2023-07-21 (Fri, 21 Jul 2023)
Changed paths:
M clang/lib/CodeGen/CodeGenAction.cpp
A clang/test/CodeGen/split-lto-unit-input.cpp
Log Message:
-----------
[CodeGen] Support bitcode input containing multiple modules
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 (not ThinLTO backend compilation)
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.
```
There are multiple ways to have just one module in a bitcode file
output: `-Xclang -fno-lto-unit`, not using features like `-fsanitize=cfi`,
using `-fsanitize=cfi` with `-fno-split-lto-unit`. I think whether a
bitcode input file contains 2 modules (internal implementation strategy)
should not be a criterion to require an additional driver option when
the user seek for a non-LTO compile action.
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
```
Reviewed By: ormris
Differential Revision: https://reviews.llvm.org/D154923
More information about the All-commits
mailing list