Skip to content

Work around custom section flag regression in LLVM #90326

Closed

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

unsafe fn embed_bitcode(
and the .rustc metadata section created in
pub fn write_compressed_metadata<'tcx>(
. 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

pub(crate) fn new_metadata_object(
. A nice side benefit of this is that the handling would be codegen-backend agnostic and could be shared between the llvm/cranelift/gcc backends.

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

Labels

A-LLVMArea: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions