From 32df82648d0d8f7687a22f470c7e56fccb5b4b2f Mon Sep 17 00:00:00 2001 From: Antoni Boucher Date: Thu, 14 Sep 2023 19:02:00 -0400 Subject: [PATCH] Handle static relocation model --- src/base.rs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/base.rs b/src/base.rs index 266d60da10ca..ef3db24f7087 100644 --- a/src/base.rs +++ b/src/base.rs @@ -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");