A lightweight WebAssembly runtime that is fast, secure, and standards-compliant
Implement PIC for s390x (#14772)
Jimmy Brisson7845edc6d784
diff --git a/cranelift/codegen/src/binemit/mod.rs b/cranelift/codegen/src/binemit/mod.rsindex 9d06df6caa..5859ef784e 100644--- a/cranelift/codegen/src/binemit/mod.rs+++ b/cranelift/codegen/src/binemit/mod.rs@@ -52,6 +52,12 @@ pub enum Reloc {S390xPCRel32Dbl,/// s390x PC-relative 4-byte offset to PLTS390xPLTRel32Dbl,+ /// s390x PC-relative 4-byte doubled offset to GOT entry (R_390_GOTENT).+ ///+ /// Applied to the 32-bit doubled-offset field of a LARL instruction.+ /// The linker fills in the PC-relative distance (in doublewords) to the+ /// GOT entry for the referenced symbol.+ S390xGOTRel32Dbl,/// Elf x86_64 32 bit signed PC relative offset to two GOT entries for GD symbol.ElfX86_64TlsGd,@@ -165,6 +171,7 @@ impl Reloc {| Self::Arm64Call| Self::S390xPCRel32Dbl| Self::S390xPLTRel32Dbl+ | Self::S390xGOTRel32Dbl| Self::MachOX86_64Tlv| Self::MachOAarch64TlsAdrPage21| Self::MachOAarch64TlsAdrPageOff12@@ -202,6 +209,7 @@ impl fmt::Display for Reloc {Self::Abs8 => write!(f, "Abs8"),Self::S390xPCRel32Dbl => write!(f, "PCRel32Dbl"),Self::S390xPLTRel32Dbl => write!(f, "PLTRel32Dbl"),+ Self::S390xGOTRel32Dbl => write!(f, "GOTRel32Dbl"),Self::X86PCRel4 => write!(f, "PCRel4"),Self::X86CallPCRel4 => write!(f, "CallPCRel4"),Self::X86CallPLTRel4 => write!(f, "CallPLTRel4"),diff --git a/cranelift/codegen/src/isa/s390x/inst.isle b/cranelift/codegen/src/isa/s390x/inst.isleindex fa5869e977..ac1fad486a 100644--- a/cranelift/codegen/src/isa/s390x/inst.isle+++ b/cranelift/codegen/src/isa/s390x/inst.isle@@ -1105,8 +1105,17 @@(offset i64));; Reference to a TLS symbol in general-dynamic mode.(TlsGd+ (name ExternalName))+ ;; GOT-indirect reference for PIC mode (R_390_GOTENT).+ ;; Emitted as LARL + LG only; offset is always 0 (other rules add any offset).+ ;; Used for data symbols.+ (Got(name ExternalName))))+;; Returns true when generating position-independent code.+(decl pure is_pic () bool)+(extern constructor is_pic is_pic)+;; Boxed version of SymbolReloc to save space.(type BoxSymbolReloc (primitive BoxSymbolReloc))(decl box_symbol_reloc (SymbolReloc) BoxSymbolReloc)diff --git a/cranelift/codegen/src/isa/s390x/inst/emit.rs b/cranelift/codegen/src/isa/s390x/inst/emit.rsindex bf73306d9d..fd0bf2f250 100644--- a/cranelift/codegen/src/isa/s390x/inst/emit.rs+++ b/cranelift/codegen/src/isa/s390x/inst/emit.rs@@ -76,6 +76,7 @@ const OPCODE_BRAS: u16 = 0xa75;const OPCODE_BCR: u16 = 0xa74;const OPCODE_LDR: u16 = 0x28;const OPCODE_VLR: u16 = 0xe756;+const OPCODE_LGRL: u16 = 0xc48;/// Type(s) of memory instructions available for mem_finalize.pub struct MemInstType {@@ -2491,16 +2492,16 @@ impl Inst {&Inst::Load32SExt8 { .. } => (None, Some(0xe376), None), // LB&Inst::Load32ZExt16 { .. } => (None, Some(0xe395), Some(0xc42)), // LLH, LLHRL&Inst::Load32SExt16 { .. } => (Some(0x48), Some(0xe378), Some(0xc45)), // LH(Y), LHRL- &Inst::Load64 { .. } => (None, Some(0xe304), Some(0xc48)), // LG, LGRL- &Inst::Load64ZExt8 { .. } => (None, Some(0xe390), None), // LLGC- &Inst::Load64SExt8 { .. } => (None, Some(0xe377), None), // LGB+ &Inst::Load64 { .. } => (None, Some(0xe304), Some(OPCODE_LGRL)), // LG, LGRL+ &Inst::Load64ZExt8 { .. } => (None, Some(0xe390), None), // LLGC+ &Inst::Load64SExt8 { .. } => (None, Some(0xe377), None), // LGB&Inst::Load64ZExt16 { .. } => (None, Some(0xe391), Some(0xc46)), // LLGH, LLGHRL&Inst::Load64SExt16 { .. } => (None, Some(0xe315), Some(0xc44)), // LGH, LGHRL&Inst::Load64ZExt32 { .. } => (None, Some(0xe316), Some(0xc4e)), // LLGF, LLGFRL&Inst::Load64SExt32 { .. } => (None, Some(0xe314), Some(0xc4c)), // LGF, LGFRL- &Inst::LoadRev16 { .. } => (None, Some(0xe31f), None), // LRVH- &Inst::LoadRev32 { .. } => (None, Some(0xe31e), None), // LRV- &Inst::LoadRev64 { .. } => (None, Some(0xe30f), None), // LRVG+ &Inst::LoadRev16 { .. } => (None, Some(0xe31f), None), // LRVH+ &Inst::LoadRev32 { .. } => (None, Some(0xe31e), None), // LRV+ &Inst::LoadRev64 { .. } => (None, Some(0xe30f), None), // LRVG_ => unreachable!(),};let rd = rd.to_reg();@@ -2740,19 +2741,39 @@ impl Inst {rd,ref symbol_reloc,} => {- let reg = writable_spilltmp_reg().to_reg();- put(sink, &enc_ri_b(OPCODE_BRAS, reg, 12));- let (reloc, name, offset) = match &**symbol_reloc {- SymbolReloc::Absolute { name, offset } => (Reloc::Abs8, name, *offset),- SymbolReloc::TlsGd { name } => (Reloc::S390xTlsGd64, name, 0),- };- sink.add_reloc(reloc, name, offset);- sink.put8(0);- let inst = Inst::Load64 {- rd,- mem: MemArg::reg(reg, MemFlagsData::trusted()),- };- inst.emit(sink, emit_info, state);+ // Helper: emit BRAS %r1, 12 ; .8byte <reloc> ; LG rd, 0(%r1)+ let mut emit_bras_literal =+ |sink: &mut MachBuffer<Inst>,+ reloc: Reloc,+ name: &ExternalName,+ addend: i64| {+ let reg = writable_spilltmp_reg().to_reg();+ put(sink, &enc_ri_b(OPCODE_BRAS, reg, 12));+ sink.add_reloc(reloc, name, addend);+ sink.put8(0);+ Inst::Load64 {+ rd,+ mem: MemArg::reg(reg, MemFlagsData::trusted()),+ }+ .emit(sink, emit_info, state);+ };++ match &**symbol_reloc {+ // PIC GOT-indirect load:+ // LGRL rd, sym@GOTENT (R_390_GOTENT: PC-relative load from GOT entry)+ SymbolReloc::Got { name } => {+ let reloc_offset = sink.cur_offset() + 2;+ sink.add_reloc_at_offset(reloc_offset, Reloc::S390xGOTRel32Dbl, name, 2);+ put(sink, &enc_ril_b(OPCODE_LGRL, rd.to_reg(), 0));+ }+ // Non-PIC: BRAS over an embedded 8-byte absolute literal.+ SymbolReloc::Absolute { name, offset } => {+ emit_bras_literal(sink, Reloc::Abs8, name, *offset);+ }+ SymbolReloc::TlsGd { name } => {+ emit_bras_literal(sink, Reloc::S390xTlsGd64, name, 0);+ }+ }}&Inst::FpuMove32 { rd, rn } => {diff --git a/cranelift/codegen/src/isa/s390x/inst/mod.rs b/cranelift/codegen/src/isa/s390x/inst/mod.rsindex ef6b417ecd..5944d634fd 100644--- a/cranelift/codegen/src/isa/s390x/inst/mod.rs+++ b/cranelift/codegen/src/isa/s390x/inst/mod.rs@@ -1054,9 +1054,17 @@ fn s390x_get_operands(inst: &mut Inst, collector: &mut DenyReuseVisitor<impl Opecollector.reg_use(ridx);collector.reg_fixed_nonallocatable(gpr_preg(1));}- Inst::LoadSymbolReloc { rd, .. } => {+ Inst::LoadSymbolReloc { rd, symbol_reloc } => {collector.reg_def(rd);- collector.reg_fixed_nonallocatable(gpr_preg(1));+ if matches!(+ &**symbol_reloc,+ SymbolReloc::Absolute { .. } | SymbolReloc::TlsGd { .. }+ ) {+ // BRAS %r1, 12 ; .8byte literal ; LG rd, 0(%r1)+ // The spilltmp register (%r1, gpr 1) is written by BRAS and read+ // by the subsequent LG, so it must be declared as clobbered.+ collector.reg_fixed_nonallocatable(gpr_preg(1));+ }}Inst::LoadAddr { rd, mem } => {collector.reg_def(rd);@@ -3586,14 +3594,25 @@ impl Inst {ref symbol_reloc,} => {let rd = pretty_print_reg(rd.to_reg());- let tmp = pretty_print_reg(writable_spilltmp_reg().to_reg());- let symbol = match &**symbol_reloc {+ match &**symbol_reloc {+ SymbolReloc::Got { name } => {+ format!("lgrl {rd}, {}@GOTENT", name.display(None))+ }SymbolReloc::Absolute { name, offset } => {- format!("{} + {}", name.display(None), offset)+ let tmp = pretty_print_reg(writable_spilltmp_reg().to_reg());+ format!(+ "bras {tmp}, 12 ; data {} + {offset} ; lg {rd}, 0({tmp})",+ name.display(None)+ )}- SymbolReloc::TlsGd { name } => format!("{}@tlsgd", name.display(None)),- };- format!("bras {tmp}, 12 ; data {symbol} ; lg {rd}, 0({tmp})")+ SymbolReloc::TlsGd { name } => {+ let tmp = pretty_print_reg(writable_spilltmp_reg().to_reg());+ format!(+ "bras {tmp}, 12 ; data {}@tlsgd ; lg {rd}, 0({tmp})",+ name.display(None)+ )+ }+ }}&Inst::LoadAddr { rd, ref mem } => {let rd = pretty_print_reg(rd.to_reg());diff --git a/cranelift/codegen/src/isa/s390x/lower.isle b/cranelift/codegen/src/isa/s390x/lower.isleindex 467fb3a757..ebef3b3b9d 100644--- a/cranelift/codegen/src/isa/s390x/lower.isle+++ b/cranelift/codegen/src/isa/s390x/lower.isle@@ -2815,25 +2815,52 @@;;;; Rules for `func_addr` ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;+;; PIC: load the address of a function via the PLT.+(rule 2 (lower (func_addr _ (func_ref_data _ name _ _)))+ (if-let true (is_pic))+ (load_symbol_reloc (SymbolReloc.Got name)))+;; Load the address of a function, target reachable via PC-relative instruction.(rule 1 (lower (func_addr _ (func_ref_data _ name (RelocDistance.Near) _)))(load_addr (memarg_symbol name 0 (memflags_trusted))))-;; Load the address of a function, general case.+;; Load the address of a function, general case (non-PIC).(rule (lower (func_addr _ (func_ref_data _ name _ _)))+ (if-let false (is_pic))(load_symbol_reloc (SymbolReloc.Absolute name 0)));;;; Rules for `symbol_value` ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;+;; PIC: load the address of a symbol through the GOT (zero offset).+(rule 4 (lower (symbol_value _ (symbol_value_data name _ 0)))+ (if-let true (is_pic))+ (load_symbol_reloc (SymbolReloc.Got name)))++;; PIC: load the address of a symbol through the GOT with a signed 16-bit offset.+(rule 3 (lower (symbol_value _ (symbol_value_data name _ (i16_from_i64 off))))+ (if-let true (is_pic))+ (add_simm16 $I64 (load_symbol_reloc (SymbolReloc.Got name)) off))++;; PIC: load the address of a symbol through the GOT with a signed 32-bit offset.+(rule 2 (lower (symbol_value _ (symbol_value_data name _ (i32_from_i64 off))))+ (if-let true (is_pic))+ (add_simm32 $I64 (load_symbol_reloc (SymbolReloc.Got name)) off))++;; PIC: load the address of a symbol through the GOT with a large (>32-bit) offset.+(rule (lower (symbol_value _ (symbol_value_data name _ off)))+ (if-let true (is_pic))+ (add_reg $I64 (load_symbol_reloc (SymbolReloc.Got name)) (imm $I64 (i64_cast_unsigned off))))+;; Load the address of a symbol, target reachable via PC-relative instruction.(rule 1 (lower (symbol_value _ (symbol_value_data name (RelocDistance.Near)off)))(if-let offset (memarg_symbol_offset off))(load_addr (memarg_symbol name offset (memflags_trusted))))-;; Load the address of a symbol, general case.+;; Load the address of a symbol (non-PIC).(rule (lower (symbol_value _ (symbol_value_data name _ offset)))+ (if-let false (is_pic))(load_symbol_reloc (SymbolReloc.Absolute name offset)))@@ -4625,8 +4652,23 @@(_ Unit (emit_side_effect (call_impl (writable_link_reg) info))))output))-;; Direct call to an out-of-range function (implicitly via pointer).++;; PIC: direct call to an out-of-range function via GOT.+(rule 2 (lower (call (func_ref_data sig_ref name _ false) args))+ (if-let true (is_pic))+ (let ((output ValueRegsVec (gen_call_output sig_ref))+ (abi Sig (abi_sig sig_ref))+ (_ Unit (abi_emit_call_adjust_stack abi))+ (uses CallArgList (gen_call_args abi (abi_prepare_args abi args)))+ (defs CallRetList (gen_call_rets abi output))+ (target Reg (load_symbol_reloc (SymbolReloc.Got name)))+ (info BoxCallInfo (gen_call_info abi target uses defs (try_call_none) false))+ (_ Unit (emit_side_effect (call_impl (writable_link_reg) info))))+ output))++;; Direct call to an out-of-range function (implicitly via pointer, non-PIC).(rule (lower (call (func_ref_data sig_ref name _ false) args))+ (if-let false (is_pic))(let ((output ValueRegsVec (gen_call_output sig_ref))(abi Sig (abi_sig sig_ref))(_ Unit (abi_emit_call_adjust_stack abi))@@ -4659,8 +4701,19 @@(info BoxReturnCallInfo (gen_return_call_info abi name uses)))(side_effect (return_call_impl info))))-;; Direct tail call to an out-of-range function (implicitly via pointer).+;; PIC: direct tail call to an out-of-range function via Got.+(rule 2 (lower (return_call (func_ref_data sig_ref name _ false) args))+ (if-let true (is_pic))+ (let ((abi Sig (abi_sig sig_ref))+ (_ Unit (abi_emit_return_call_adjust_stack abi))+ (uses CallArgList (gen_return_call_args abi (abi_prepare_args abi args)))+ (target Reg (load_symbol_reloc (SymbolReloc.Got name)))+ (info BoxReturnCallInfo (gen_return_call_info abi target uses)))+ (side_effect (return_call_impl info))))++;; Direct tail call to an out-of-range function (implicitly via pointer, non-PIC).(rule (lower (return_call (func_ref_data sig_ref name _ false) args))+ (if-let false (is_pic))(let ((abi Sig (abi_sig sig_ref))(_ Unit (abi_emit_return_call_adjust_stack abi))(uses CallArgList (gen_return_call_args abi (abi_prepare_args abi args)))@@ -4690,8 +4743,21 @@(info BoxCallInfo (gen_call_info abi name uses defs trycall patchable)))(emit_side_effect (call_impl (writable_link_reg) info))))-;; Direct call to an out-of-range function (implicitly via pointer).+;; PIC: direct try_call to an out-of-range function via Got.+(rule 2 (lower_branch (try_call (func_ref_data sig_ref name _ false) args et) targets)+ (if-let true (is_pic))+ (let ((abi Sig (abi_sig sig_ref))+ (trycall OptionTryCallInfo (try_call_info et targets))+ (_ Unit (abi_emit_call_adjust_stack abi))+ (uses CallArgList (gen_call_args abi (abi_prepare_args abi args)))+ (defs CallRetList (gen_try_call_rets abi))+ (target Reg (load_symbol_reloc (SymbolReloc.Got name)))+ (info BoxCallInfo (gen_call_info abi target uses defs trycall false)))+ (emit_side_effect (call_impl (writable_link_reg) info))))++;; Direct call to an out-of-range function (implicitly via pointer, non-PIC).(rule (lower_branch (try_call (func_ref_data sig_ref name _ false) args et) targets)+ (if-let false (is_pic))(let ((abi Sig (abi_sig sig_ref))(trycall OptionTryCallInfo (try_call_info et targets))(_ Unit (abi_emit_call_adjust_stack abi))diff --git a/cranelift/codegen/src/isa/s390x/lower/isle.rs b/cranelift/codegen/src/isa/s390x/lower/isle.rsindex 268ef56f7e..3a75e36de3 100644--- a/cranelift/codegen/src/isa/s390x/lower/isle.rs+++ b/cranelift/codegen/src/isa/s390x/lower/isle.rs@@ -740,6 +740,11 @@ impl generated_code::Context for IsleContext<'_, '_, MInst, S390xBackend> {}}+ #[inline]+ fn is_pic(&mut self) -> bool {+ self.backend.flags.is_pic()+ }+#[inline]fn memarg_const(&mut self, constant: VCodeConstant) -> MemArg {MemArg::Constant { constant }diff --git a/cranelift/filetests/filetests/isa/s390x/call-pic.clif b/cranelift/filetests/filetests/isa/s390x/call-pic.clifnew file mode 100644index 0000000000..5ffcf96988--- /dev/null+++ b/cranelift/filetests/filetests/isa/s390x/call-pic.clif@@ -0,0 +1,140 @@+test compile precise-output+set unwind_info=false+set is_pic+set enable_multi_ret_implicit_sret+target s390x++function %call_far(i64) -> i64 {+ fn0 = %callee(i64) -> i64++block0(v0: i64):+ v1 = call fn0(v0)+ return v1+}++; VCode:+; stmg %r14, %r15, 112(%r15)+; aghi %r15, -160+; block0:+; lgrl %r3, %callee@GOTENT+; basr %r14, %r3+; lmg %r14, %r15, 272(%r15)+; br %r14+;+; Disassembled:+; block0: ; offset 0x0+; stmg %r14, %r15, 0x70(%r15)+; aghi %r15, -0xa0+; block1: ; offset 0xa+; lgrl %r3, 0xa ; reloc_external GOTRel32Dbl %callee 2+; basr %r14, %r3+; lmg %r14, %r15, 0x110(%r15)+; br %r14++function %return_call_far(i64) -> i64 tail {+ fn0 = %callee(i64) -> i64 tail++block0(v0: i64):+ return_call fn0(v0)+}++; VCode:+; block0:+; lgrl %r3, %callee@GOTENT+; br %r3+;+; Disassembled:+; block0: ; offset 0x0+; lgrl %r3, 0 ; reloc_external GOTRel32Dbl %callee 2+; br %r3++function %try_call_far(i64) -> i64 {+ sig0 = (i64) -> i64 tail+ fn0 = %callee(i64) -> i64 tail++block0(v0: i64):+ try_call fn0(v0), sig0, block1(ret0), [ default: block2(exn0) ]++block1(v1: i64):+ return v1++block2(v2: i64):+ return v2+}++; VCode:+; stmg %r6, %r15, 48(%r15)+; aghi %r15, -224+; std %f8, 160(%r15)+; std %f9, 168(%r15)+; std %f10, 176(%r15)+; std %f11, 184(%r15)+; std %f12, 192(%r15)+; std %f13, 200(%r15)+; std %f14, 208(%r15)+; std %f15, 216(%r15)+; block0:+; lgrl %r3, %callee@GOTENT+; basr %r14, %r3; jg MachLabel(1); catch [default: MachLabel(2)]+; block1:+; ld %f8, 160(%r15)+; ld %f9, 168(%r15)+; ld %f10, 176(%r15)+; ld %f11, 184(%r15)+; ld %f12, 192(%r15)+; ld %f13, 200(%r15)+; ld %f14, 208(%r15)+; ld %f15, 216(%r15)+; lmg %r6, %r15, 272(%r15)+; br %r14+; block2:+; lgr %r2, %r6+; ld %f8, 160(%r15)+; ld %f9, 168(%r15)+; ld %f10, 176(%r15)+; ld %f11, 184(%r15)+; ld %f12, 192(%r15)+; ld %f13, 200(%r15)+; ld %f14, 208(%r15)+; ld %f15, 216(%r15)+; lmg %r6, %r15, 272(%r15)+; br %r14+;+; Disassembled:+; block0: ; offset 0x0+; stmg %r6, %r15, 0x30(%r15)+; aghi %r15, -0xe0+; std %f8, 0xa0(%r15)+; std %f9, 0xa8(%r15)+; std %f10, 0xb0(%r15)+; std %f11, 0xb8(%r15)+; std %f12, 0xc0(%r15)+; std %f13, 0xc8(%r15)+; std %f14, 0xd0(%r15)+; std %f15, 0xd8(%r15)+; block1: ; offset 0x2a+; lgrl %r3, 0x2a ; reloc_external GOTRel32Dbl %callee 2+; basr %r14, %r3+; block2: ; offset 0x32+; ld %f8, 0xa0(%r15)+; ld %f9, 0xa8(%r15)+; ld %f10, 0xb0(%r15)+; ld %f11, 0xb8(%r15)+; ld %f12, 0xc0(%r15)+; ld %f13, 0xc8(%r15)+; ld %f14, 0xd0(%r15)+; ld %f15, 0xd8(%r15)+; lmg %r6, %r15, 0x110(%r15)+; br %r14+; block3: ; offset 0x5a+; lgr %r2, %r6+; ld %f8, 0xa0(%r15)+; ld %f9, 0xa8(%r15)+; ld %f10, 0xb0(%r15)+; ld %f11, 0xb8(%r15)+; ld %f12, 0xc0(%r15)+; ld %f13, 0xc8(%r15)+; ld %f14, 0xd0(%r15)+; ld %f15, 0xd8(%r15)+; lmg %r6, %r15, 0x110(%r15)+; br %r14diff --git a/cranelift/filetests/filetests/isa/s390x/symbol-value-pic.clif b/cranelift/filetests/filetests/isa/s390x/symbol-value-pic.clifnew file mode 100644index 0000000000..71b2fcac75--- /dev/null+++ b/cranelift/filetests/filetests/isa/s390x/symbol-value-pic.clif@@ -0,0 +1,159 @@+test compile precise-output+set unwind_info=false+set is_pic+target s390x++function %func_addr() -> i64 {+ fn0 = %my_func(i64) -> i64++block0:+ v0 = func_addr.i64 fn0+ return v0+}++; VCode:+; block0:+; lgrl %r2, %my_func@GOTENT+; br %r14+;+; Disassembled:+; block0: ; offset 0x0+; lgrl %r2, 0 ; reloc_external GOTRel32Dbl %my_func 2+; br %r14++function %colocated_func_addr() -> i64 {+ fn0 = colocated %my_func(i64) -> i64++block0:+ v0 = func_addr.i64 fn0+ return v0+}++; VCode:+; block0:+; lgrl %r2, %my_func@GOTENT+; br %r14+;+; Disassembled:+; block0: ; offset 0x0+; lgrl %r2, 0 ; reloc_external GOTRel32Dbl %my_func 2+; br %r14++function %symbol_value() -> i64 {+ gv0 = symbol %my_global++block0:+ v0 = symbol_value.i64 gv0+ return v0+}++; VCode:+; block0:+; lgrl %r2, %my_global@GOTENT+; br %r14+;+; Disassembled:+; block0: ; offset 0x0+; lgrl %r2, 0 ; reloc_external GOTRel32Dbl %my_global 2+; br %r14++function %colocated_symbol_value() -> i64 {+ gv0 = symbol colocated %my_global++block0:+ v0 = symbol_value.i64 gv0+ return v0+}++; VCode:+; block0:+; lgrl %r2, %my_global@GOTENT+; br %r14+;+; Disassembled:+; block0: ; offset 0x0+; lgrl %r2, 0 ; reloc_external GOTRel32Dbl %my_global 2+; br %r14++function %symbol_value_plus_offset() -> i64 {+ gv0 = symbol %my_global+123++block0:+ v0 = symbol_value.i64 gv0+ return v0+}++; VCode:+; block0:+; lgrl %r2, %my_global@GOTENT+; aghi %r2, 123+; br %r14+;+; Disassembled:+; block0: ; offset 0x0+; lgrl %r2, 0 ; reloc_external GOTRel32Dbl %my_global 2+; aghi %r2, 0x7b+; br %r14++function %symbol_value_minus_offset() -> i64 {+ gv0 = symbol %my_global-123++block0:+ v0 = symbol_value.i64 gv0+ return v0+}++; VCode:+; block0:+; lgrl %r2, %my_global@GOTENT+; aghi %r2, -123+; br %r14+;+; Disassembled:+; block0: ; offset 0x0+; lgrl %r2, 0 ; reloc_external GOTRel32Dbl %my_global 2+; aghi %r2, -0x7b+; br %r14++function %symbol_value_i32_offset() -> i64 {+ gv0 = symbol %my_global+65536++block0:+ v0 = symbol_value.i64 gv0+ return v0+}++; VCode:+; block0:+; lgrl %r2, %my_global@GOTENT+; agfi %r2, 65536+; br %r14+;+; Disassembled:+; block0: ; offset 0x0+; lgrl %r2, 0 ; reloc_external GOTRel32Dbl %my_global 2+; agfi %r2, 0x10000+; br %r14++function %symbol_value_large_offset() -> i64 {+ gv0 = symbol %my_global+4294967296++block0:+ v0 = symbol_value.i64 gv0+ return v0+}++; VCode:+; block0:+; lgrl %r2, %my_global@GOTENT+; llihl %r3, 1+; agr %r2, %r3+; br %r14+;+; Disassembled:+; block0: ; offset 0x0+; lgrl %r2, 0 ; reloc_external GOTRel32Dbl %my_global 2+; llihl %r3, 1+; agr %r2, %r3+; br %r14+diff --git a/cranelift/jit/src/compiled_blob.rs b/cranelift/jit/src/compiled_blob.rsindex e23e6f5cbe..b92c415f2a 100644--- a/cranelift/jit/src/compiled_blob.rs+++ b/cranelift/jit/src/compiled_blob.rs@@ -256,6 +256,9 @@ impl CompiledBlob {}}}+ Reloc::S390xGOTRel32Dbl => {+ panic!("GOT relocation shouldn't be generated when !is_pic");+ }Reloc::S390xPCRel32Dbl | Reloc::S390xPLTRel32Dbl => {let what = relocation_target_addr(name, addend);let pcrel = i32::try_from(((what as isize) - (at as isize)) >> 1).unwrap();diff --git a/cranelift/object/src/backend.rs b/cranelift/object/src/backend.rsindex 7be9012d80..849c1df2a2 100644--- a/cranelift/object/src/backend.rs+++ b/cranelift/object/src/backend.rs@@ -1030,6 +1030,16 @@ impl ObjectModule {encoding: RelocationEncoding::S390xDbl,size: 32,},+ Reloc::S390xGOTRel32Dbl => {+ assert_eq!(+ self.object.format(),+ object::BinaryFormat::Elf,+ "S390xGOTRel32Dbl is only supported for ELF"+ );+ RelocationFlags::Elf {+ r_type: object::elf::R_390_GOTENT,+ }+ }Reloc::S390xTlsGd64 => {assert_eq!(self.object.format(),