Description
LLVM 13 has removed support for setting custom section flags in https://reviews.llvm.org/D100944. LLVM 13 carries a revert of the problematic change (https://reviews.llvm.org/D107216). However, LLVM 14 will no longer carry it, and we need to use alternative ways to set custom section flags.
There are currently two places affected by this. The .llvmbc
bitcode section created in
.rustc
metadata section created in
. In both cases, section flags are used to ensure that the section is not linked into the final binary or loaded into memory.
There are two ways to address this. The first one is to define the section entirely in module-level assembly. Rather than only emitting .section
, we should also emit .ascii "ENCODED_SECTION_CONTENTS"
, as well as the symbol name and any other necessary directives (e.g. for visibility). I'm not sure exactly what is needed on different platforms here.
The second one is to use the object crate to create the object file containing the section. The cranelift backend already implements this for the .rustc
section in
The suggested course of action is to use the object crate for .rustc
and inline assembly for .llvmbc
. The reason for the latter is that the section is part of a larger object file emitted by LLVM, and the object
crate doesn't seem great for modifying existing object files (as opposed to creating one from scratch). Though if we can use the object crate for everything, that would of course be great.