Skip to content

Commit

Permalink
s390x: Hard code the link register for ElfTlsGetOffset (#9361)
Browse files Browse the repository at this point in the history
* s390x: Hard code the link register for ElfTlsGetOffset

The ElfTlsGetOffset pseudo-instruction already hard codes the rest of
the abi anyway and if another abi is ever needed, adding another
pseudo-instruction or an enum field to the existing one would likely be
necessary anyway.

* Remove a couple of dead_code allows
  • Loading branch information
bjorn3 authored Oct 17, 2024
1 parent 09e0b08 commit f401069
Show file tree
Hide file tree
Showing 6 changed files with 6 additions and 17 deletions.
1 change: 0 additions & 1 deletion cranelift/bforest/src/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ use core::fmt;
///
/// An inner node contains at least M/2 node references unless it is the right-most node at its
/// level. A leaf node contains at least N/2 keys unless it is the right-most leaf.
#[allow(dead_code)] // workaround for https://github.com/rust-lang/rust/issues/64362
pub(super) enum NodeData<F: Forest> {
Inner {
/// The number of keys in this node.
Expand Down
1 change: 0 additions & 1 deletion cranelift/codegen/src/isa/riscv64/inst/imms.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

// Some variants are never constructed, but we still want them as options in the future.
use super::Inst;
#[allow(dead_code)]
use std::fmt::{Debug, Display, Formatter, Result};

#[derive(Copy, Clone, Debug, Default)]
Expand Down
1 change: 0 additions & 1 deletion cranelift/codegen/src/isa/s390x/inst.isle
Original file line number Diff line number Diff line change
Expand Up @@ -1020,7 +1020,6 @@
(tls_offset WritableReg)
(got Reg)
(got_offset Reg)
(link WritableReg)
(symbol BoxSymbolReloc))
))

Expand Down
6 changes: 2 additions & 4 deletions cranelift/codegen/src/isa/s390x/inst/emit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3250,9 +3250,7 @@ impl Inst {
put(sink, &enc_rr(opcode, gpr(15), rn));
sink.add_call_site();
}
&Inst::ElfTlsGetOffset {
ref symbol, link, ..
} => {
&Inst::ElfTlsGetOffset { ref symbol, .. } => {
let opcode = 0xc05; // BRASL

// Add relocation for target function. This has to be done
Expand All @@ -3265,7 +3263,7 @@ impl Inst {
_ => unreachable!(),
}

put(sink, &enc_ril_b(opcode, link.to_reg(), 0));
put(sink, &enc_ril_b(opcode, gpr(14), 0));
sink.add_call_site();
}
&Inst::Args { .. } => {}
Expand Down
12 changes: 3 additions & 9 deletions cranelift/codegen/src/isa/s390x/inst/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -923,15 +923,14 @@ fn s390x_get_operands(inst: &mut Inst, collector: &mut DenyReuseVisitor<impl Ope
tls_offset,
got,
got_offset,
link,
..
} => {
collector.reg_fixed_use(got, gpr(12));
collector.reg_fixed_use(got_offset, gpr(2));
collector.reg_fixed_def(tls_offset, gpr(2));

let mut clobbers = S390xMachineDeps::get_regs_clobbered_by_call(CallConv::SystemV);
clobbers.add(link.to_reg().to_real_reg().unwrap().into());
clobbers.add(gpr_preg(14));
clobbers.remove(gpr_preg(2));
collector.reg_clobbers(clobbers);
}
Expand Down Expand Up @@ -3164,19 +3163,14 @@ impl Inst {
};
format!("return_call_ind {rn}{callee_pop_size}")
}
&Inst::ElfTlsGetOffset {
ref symbol,
ref link,
..
} => {
let link = link.to_reg();
&Inst::ElfTlsGetOffset { ref symbol, .. } => {
let dest = match &**symbol {
SymbolReloc::TlsGd { name } => {
format!("tls_gdcall:{}", name.display(None))
}
_ => unreachable!(),
};
format!("brasl {}, {}", show_reg(link), dest)
format!("brasl {}, {}", show_reg(gpr(14)), dest)
}
&Inst::Args { ref args } => {
let mut s = "args".to_string();
Expand Down
2 changes: 1 addition & 1 deletion cranelift/codegen/src/isa/s390x/lower.isle
Original file line number Diff line number Diff line change
Expand Up @@ -2279,7 +2279,7 @@
(rule (lib_call_tls_get_offset got got_offset symbol)
(let ((tls_offset WritableReg (temp_writable_reg $I64))
(_ Unit (abi_for_elf_tls_get_offset))
(_ Unit (emit (MInst.ElfTlsGetOffset tls_offset got got_offset (writable_link_reg) symbol))))
(_ Unit (emit (MInst.ElfTlsGetOffset tls_offset got got_offset symbol))))
tls_offset))

(decl abi_for_elf_tls_get_offset () Unit)
Expand Down

0 comments on commit f401069

Please sign in to comment.