-fembed-bitcode will put bitcode into special sections within object
files, but this is not meant to be used by LTO, so the gold plugin
should ignore it.
Details
Diff Detail
- Repository
- rG LLVM Github Monorepo
Event Timeline
A few comments and questions.
First, it looks like lld works because it has a similar check guarding its call of InputFile::create (which is embedded in the BitcodeFile constructor).
Note though I am seeing inconsistent info online as to what embedded bitcode is meant to be used for. It would be good to document this somewhere, like where fembed-bitcode is documented (which I am not finding). The initial submitter text when bcsection.ll was added suggests it was intended to be useful for LTO (https://reviews.llvm.org/D4371). I did find this recent discussion which indicates it was added for Apple recompilation: https://groups.google.com/g/llvm-dev/c/d1WSRvLefHQ/m/Iwm39FboAAAJ. I also found official ARM documentation online that points to the embedded .llvmbc section as being there to support LTO: https://developer.arm.com/documentation/dui0773/i/sbu1510240545830.
But in any case, as noted above, lld does not support its use in LTO links, so I think this is just in need of clear documentation somewhere.
Can you add a test?
If bcsection.ll is deleted, its input file bcsection.s should as well.
This discussion from rust is also relevant: https://github.com/rust-lang/rust/issues/90326
But in any case, as noted above, lld does not support its use in LTO links, so I think this is just in need of clear documentation somewhere.
Can you add a test?
If bcsection.ll is deleted, its input file bcsection.s should as well.
The documentation here: https://llvm.org/docs/BitCodeFormat.html#native-object-file-wrapper-format also says that the section is useful for LTO.
As you can see from the linked issue, there are some cases where adding the .llvmbc section causes ld.bfd to fail to link, when it was able to link successfully without the section. I originally tried to fix the failures in the plugin, but after reading the comments on https://github.com/rust-lang/rust/issues/90326 it seemed like it might be better to just ignore these sections if they aren't intended to be use this way.
@jyknight You commented here that -fembed-bitcode was not intended for LTO, but the llvm documentation says the .llvmbc section is useful for LTO. Do you have any more background on the history of the .llvmbc section and do you think the gold plugin should try to use it for LTO?
-fembed-bitcode was originally added by Apple to enable them to recompile
3rd-party-developers' software with a newer compiler, or for new CPU
targets, without the source code. It uses the normal non-LTO optimization
pipeline, and emits bitcode corresponding to the binary object also
emitted.
For LTO bitcode generation, we use a different pass manager configuration.
That said, various other people seem to have had various other ideas about
how things should work over time. So, I couldn't say conclusively that
nobody will complain if we have gold not try to parse these sections...but
it seems potentially reasonable to me.
I agree. I think for Mach-O the section is for LTO use. For ELF there are two usage:
- lld/LLVMgold.so: the section should be ignored. This patch makes LLVMgold.so behavior match lld, therefore LGTM. The use case is similar to something like https://github.com/travitch/whole-program-llvm ; .llvmbc is to collect bitcode files, not for doing LTO.
- llgo (https://reviews.llvm.org/D4371): it places the bitcode for LTO into a special section .llvmbc.
llvm/docs/ReleaseNotes.rst | ||
---|---|---|
248 | ||
llvm/tools/gold/gold-plugin.cpp | ||
546 | special sections => .llvmbc Be specific. | |
547 | "not meant for LTO use " when using LLVMgold.so. For llgo(?) it was for LTO use: https://reviews.llvm.org/D4371 |
LGTM but should https://llvm.org/docs/BitCodeFormat.html#native-object-file-wrapper-format also be updated?
llvm/docs/ReleaseNotes.rst | ||
---|---|---|
248 | The LLVM gold plugin now ignores bitcode ... |
llvm/docs/GoldPlugin.rst | ||
---|---|---|
20 |