Skip to content

Commit c556e4d

Browse files
committed
Use PIC in JIT mode too
1 parent 510616f commit c556e4d

File tree

6 files changed

+18
-19
lines changed

6 files changed

+18
-19
lines changed

src/backend.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ impl AddConstructor for ObjectProduct {
162162
}
163163

164164
pub(crate) fn with_object(sess: &Session, name: &str, f: impl FnOnce(&mut Object)) -> Vec<u8> {
165-
let triple = crate::build_isa(sess, true).triple().clone();
165+
let triple = crate::build_isa(sess).triple().clone();
166166

167167
let binary_format = match triple.binary_format {
168168
target_lexicon::BinaryFormat::Elf => object::BinaryFormat::Elf,
@@ -193,7 +193,7 @@ pub(crate) fn with_object(sess: &Session, name: &str, f: impl FnOnce(&mut Object
193193

194194
pub(crate) fn make_module(sess: &Session, name: String) -> ObjectModule {
195195
let mut builder = ObjectBuilder::new(
196-
crate::build_isa(sess, true),
196+
crate::build_isa(sess),
197197
name + ".o",
198198
cranelift_module::default_libcall_names(),
199199
)

src/debuginfo/unwind.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@ pub(crate) struct UnwindContext<'tcx> {
1515
}
1616

1717
impl<'tcx> UnwindContext<'tcx> {
18-
pub(crate) fn new(tcx: TyCtxt<'tcx>, isa: &dyn TargetIsa) -> Self {
18+
pub(crate) fn new(tcx: TyCtxt<'tcx>, isa: &dyn TargetIsa, pic_eh_frame: bool) -> Self {
1919
let mut frame_table = FrameTable::default();
2020

2121
let cie_id = if let Some(mut cie) = isa.create_systemv_cie() {
22-
if isa.flags().is_pic() {
22+
if pic_eh_frame {
2323
cie.fde_address_encoding =
2424
gimli::DwEhPe(gimli::DW_EH_PE_pcrel.0 | gimli::DW_EH_PE_sdata4.0);
2525
}

src/driver/aot.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,12 @@ fn module_codegen(tcx: TyCtxt<'_>, cgu_name: rustc_span::Symbol) -> ModuleCodege
146146
}
147147
}
148148

149-
let mut cx = crate::CodegenCx::new(tcx, module, tcx.sess.opts.debuginfo != DebugInfo::None);
149+
let mut cx = crate::CodegenCx::new(
150+
tcx,
151+
module,
152+
tcx.sess.opts.debuginfo != DebugInfo::None,
153+
true,
154+
);
150155
super::predefine_mono_items(&mut cx, &mono_items);
151156
for (mono_item, (linkage, visibility)) in mono_items {
152157
let linkage = crate::linkage::get_clif_linkage(mono_item, linkage, visibility);
@@ -254,7 +259,7 @@ pub(super) fn run_aot(
254259
tcx.sess.abort_if_errors();
255260

256261
let mut allocator_module = new_module(tcx, "allocator_shim".to_string());
257-
let mut allocator_unwind_context = UnwindContext::new(tcx, allocator_module.isa());
262+
let mut allocator_unwind_context = UnwindContext::new(tcx, allocator_module.isa(), true);
258263
let created_alloc_shim =
259264
crate::allocator::codegen(tcx, &mut allocator_module, &mut allocator_unwind_context);
260265

src/driver/jit.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ pub(super) fn run_jit(tcx: TyCtxt<'_>) -> ! {
3737
let imported_symbols = load_imported_symbols_for_jit(tcx);
3838

3939
let mut jit_builder = JITBuilder::with_isa(
40-
crate::build_isa(tcx.sess, false),
40+
crate::build_isa(tcx.sess),
4141
cranelift_module::default_libcall_names(),
4242
);
4343
jit_builder.symbols(imported_symbols);
@@ -67,7 +67,7 @@ pub(super) fn run_jit(tcx: TyCtxt<'_>) -> ! {
6767
.into_iter()
6868
.collect::<Vec<(_, (_, _))>>();
6969

70-
let mut cx = crate::CodegenCx::new(tcx, jit_module, false);
70+
let mut cx = crate::CodegenCx::new(tcx, jit_module, false, false);
7171

7272
let (mut jit_module, global_asm, _debug, mut unwind_context) =
7373
super::time(tcx, "codegen mono items", || {

src/lib.rs

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -141,8 +141,8 @@ struct CodegenCx<'tcx, M: Module> {
141141
}
142142

143143
impl<'tcx, M: Module> CodegenCx<'tcx, M> {
144-
fn new(tcx: TyCtxt<'tcx>, module: M, debug_info: bool) -> Self {
145-
let unwind_context = UnwindContext::new(tcx, module.isa());
144+
fn new(tcx: TyCtxt<'tcx>, module: M, debug_info: bool, pic_eh_frame: bool) -> Self {
145+
let unwind_context = UnwindContext::new(tcx, module.isa(), pic_eh_frame);
146146
let debug_context = if debug_info {
147147
Some(DebugContext::new(tcx, module.isa()))
148148
} else {
@@ -250,17 +250,13 @@ fn target_triple(sess: &Session) -> target_lexicon::Triple {
250250
sess.target.llvm_target.parse().unwrap()
251251
}
252252

253-
fn build_isa(sess: &Session, enable_pic: bool) -> Box<dyn isa::TargetIsa + 'static> {
253+
fn build_isa(sess: &Session) -> Box<dyn isa::TargetIsa + 'static> {
254254
use target_lexicon::BinaryFormat;
255255

256256
let target_triple = crate::target_triple(sess);
257257

258258
let mut flags_builder = settings::builder();
259-
if enable_pic {
260-
flags_builder.enable("is_pic").unwrap();
261-
} else {
262-
flags_builder.set("is_pic", "false").unwrap();
263-
}
259+
flags_builder.enable("is_pic").unwrap();
264260
flags_builder.set("enable_probestack", "false").unwrap(); // __cranelift_probestack is not provided
265261
flags_builder
266262
.set(

src/pretty_clif.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -263,9 +263,7 @@ pub(crate) fn write_clif_file<'tcx>(
263263
&mut clif,
264264
&context.func,
265265
&DisplayFunctionAnnotations {
266-
isa: Some(&*crate::build_isa(
267-
tcx.sess, true, /* PIC doesn't matter here */
268-
)),
266+
isa: Some(&*crate::build_isa(tcx.sess)),
269267
value_ranges: value_ranges.as_ref(),
270268
},
271269
)

0 commit comments

Comments
 (0)