Merge pull request #331 from rust-lang/feature/static-relocation

Handle static relocation model
This commit is contained in:
antoyo 2023-09-14 19:54:24 -04:00 committed by GitHub
commit 067bfc077b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -140,6 +140,11 @@ pub fn compile_codegen_unit(tcx: TyCtxt<'_>, cgu_name: Symbol, target_info: Arc<
// NOTE: Rust relies on LLVM doing wrapping on overflow.
context.add_command_line_option("-fwrapv");
if tcx.sess.opts.cg.relocation_model == Some(rustc_target::spec::RelocModel::Static) {
context.add_command_line_option("-mcmodel=kernel");
context.add_command_line_option("-fno-pie");
}
if tcx.sess.opts.unstable_opts.function_sections.unwrap_or(tcx.sess.target.function_sections) {
context.add_command_line_option("-ffunction-sections");
context.add_command_line_option("-fdata-sections");