Skip to content

Commit d7bfc26

Browse files
authored
Merge branch 'main' into bti
2 parents fb71d22 + 80c77da commit d7bfc26

File tree

112 files changed

+5046
-2620
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

112 files changed

+5046
-2620
lines changed

Cargo.lock

Lines changed: 17 additions & 17 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,12 +51,12 @@ test-programs = { path = "crates/test-programs" }
5151
wasmtime-runtime = { path = "crates/runtime" }
5252
tokio = { version = "1.8.0", features = ["rt", "time", "macros", "rt-multi-thread"] }
5353
tracing-subscriber = "0.3.1"
54-
wast = "45.0.0"
54+
wast = "46.0.0"
5555
criterion = "0.3.4"
5656
num_cpus = "1.13.0"
5757
memchr = "2.4"
5858
async-trait = "0.1"
59-
wat = "1.0.47"
59+
wat = "1.0.48"
6060
once_cell = "1.9.0"
6161
rayon = "1.5.0"
6262
component-macro-test = { path = "crates/misc/component-macro-test" }

cranelift/codegen/src/isa/aarch64/inst.isle

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -780,6 +780,11 @@
780780
(Pacisp
781781
(key APIKey))
782782

783+
;; Strip pointer authentication code from instruction address in LR;
784+
;; equivalent to a no-op if Pointer authentication (FEAT_PAuth) is not
785+
;; supported.
786+
(Xpaclri)
787+
783788
;; Branch target identification; equivalent to a no-op if Branch Target
784789
;; Identification (FEAT_BTI) is not supported.
785790
(Bti
@@ -1370,6 +1375,9 @@
13701375
))
13711376

13721377
;; Extractors for target features ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1378+
(decl pure sign_return_address_disabled () Unit)
1379+
(extern constructor sign_return_address_disabled sign_return_address_disabled)
1380+
13731381
(decl use_lse () Inst)
13741382
(extern extractor use_lse use_lse)
13751383

@@ -2591,4 +2599,11 @@
25912599

25922600
(decl aarch64_link () Reg)
25932601
(rule (aarch64_link)
2602+
(if (sign_return_address_disabled))
25942603
(mov_preg (preg_link)))
2604+
2605+
(rule (aarch64_link)
2606+
;; This constructor is always used for non-leaf functions, so it is safe
2607+
;; to clobber LR.
2608+
(let ((_ Unit (emit (MInst.Xpaclri))))
2609+
(mov_preg (preg_link))))

cranelift/codegen/src/isa/aarch64/inst/emit.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3121,6 +3121,7 @@ impl MachInstEmit for Inst {
31213121

31223122
sink.put4(0xd503233f | key << 6);
31233123
}
3124+
&Inst::Xpaclri => sink.put4(0xd50320ff),
31243125
&Inst::Bti { targets } => {
31253126
let targets = match targets {
31263127
BranchTargetType::None => 0b00,

cranelift/codegen/src/isa/aarch64/inst/emit_tests.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ fn test_aarch64_binemit() {
5757
"retab",
5858
));
5959
insns.push((Inst::Pacisp { key: APIKey::B }, "7F2303D5", "pacibsp"));
60+
insns.push((Inst::Xpaclri, "FF2003D5", "xpaclri"));
6061
insns.push((
6162
Inst::Bti {
6263
targets: BranchTargetType::J,

cranelift/codegen/src/isa/aarch64/inst/mod.rs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -981,12 +981,7 @@ fn aarch64_get_operands<F: Fn(VReg) -> VReg>(inst: &Inst, collector: &mut Operan
981981
collector.reg_def(rd);
982982
collector.reg_use(rn);
983983
}
984-
&Inst::Ret { ref rets } => {
985-
for &ret in rets {
986-
collector.reg_use(ret);
987-
}
988-
}
989-
&Inst::AuthenticatedRet { ref rets, .. } => {
984+
&Inst::Ret { ref rets } | &Inst::AuthenticatedRet { ref rets, .. } => {
990985
for &ret in rets {
991986
collector.reg_use(ret);
992987
}
@@ -1039,7 +1034,10 @@ fn aarch64_get_operands<F: Fn(VReg) -> VReg>(inst: &Inst, collector: &mut Operan
10391034
collector.reg_def(rd);
10401035
memarg_operands(mem, collector);
10411036
}
1042-
&Inst::Pacisp { .. } => {}
1037+
&Inst::Pacisp { .. } | &Inst::Xpaclri => {
1038+
// Neither LR nor SP is an allocatable register, so there is no need
1039+
// to do anything.
1040+
}
10431041
&Inst::Bti { .. } => {}
10441042
&Inst::VirtualSPOffsetAdj { .. } => {}
10451043

@@ -2729,6 +2727,7 @@ impl Inst {
27292727

27302728
"paci".to_string() + key + "sp"
27312729
}
2730+
&Inst::Xpaclri => "xpaclri".to_string(),
27322731
&Inst::Bti { targets } => {
27332732
let targets = match targets {
27342733
BranchTargetType::None => "",

cranelift/codegen/src/isa/aarch64/lower/isle.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,14 @@ pub struct SinkableAtomicLoad {
7171
impl generated_code::Context for IsleContext<'_, '_, MInst, Flags, IsaFlags, 6> {
7272
isle_prelude_methods!();
7373

74+
fn sign_return_address_disabled(&mut self) -> Option<()> {
75+
if self.isa_flags.sign_return_address() {
76+
None
77+
} else {
78+
Some(())
79+
}
80+
}
81+
7482
fn use_lse(&mut self, _: Inst) -> Option<()> {
7583
if self.isa_flags.has_lse() {
7684
Some(())

cranelift/codegen/src/isa/mod.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -317,6 +317,15 @@ impl<'a> dyn TargetIsa + 'a {
317317
}
318318
}
319319

320+
/// Returns the minimum symbol alignment for this ISA.
321+
pub fn symbol_alignment(&self) -> u64 {
322+
match self.triple().architecture {
323+
// All symbols need to be aligned to at least 2 on s390x.
324+
Architecture::S390x => 2,
325+
_ => 1,
326+
}
327+
}
328+
320329
/// Get the pointer type of this ISA.
321330
pub fn pointer_type(&self) -> ir::Type {
322331
ir::Type::int(self.pointer_bits() as u16).unwrap()

cranelift/codegen/src/isa/s390x/inst/emit.rs

Lines changed: 68 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,28 @@ use crate::trace;
1111
use core::convert::TryFrom;
1212
use regalloc2::Allocation;
1313

14+
/// Type(s) of memory instructions available for mem_finalize.
15+
pub struct MemInstType {
16+
/// True if 12-bit unsigned displacement is supported.
17+
pub have_d12: bool,
18+
/// True if 20-bit signed displacement is supported.
19+
pub have_d20: bool,
20+
/// True if PC-relative addressing is supported (memory access).
21+
pub have_pcrel: bool,
22+
/// True if PC-relative addressing is supported (load address).
23+
pub have_unaligned_pcrel: bool,
24+
/// True if an index register is supported.
25+
pub have_index: bool,
26+
}
27+
1428
/// Memory addressing mode finalization: convert "special" modes (e.g.,
1529
/// generic arbitrary stack offset) into real addressing modes, possibly by
1630
/// emitting some helper instructions that come immediately before the use
1731
/// of this amode.
1832
pub fn mem_finalize(
1933
mem: &MemArg,
2034
state: &EmitState,
21-
have_d12: bool,
22-
have_d20: bool,
23-
have_pcrel: bool,
24-
have_index: bool,
35+
mi: MemInstType,
2536
) -> (SmallVec<[Inst; 4]>, MemArg) {
2637
let mut insts = SmallVec::new();
2738

@@ -70,9 +81,10 @@ pub fn mem_finalize(
7081

7182
// If this addressing mode cannot be handled by the instruction, use load-address.
7283
let need_load_address = match &mem {
73-
&MemArg::Label { .. } | &MemArg::Symbol { .. } if !have_pcrel => true,
74-
&MemArg::BXD20 { .. } if !have_d20 => true,
75-
&MemArg::BXD12 { index, .. } | &MemArg::BXD20 { index, .. } if !have_index => {
84+
&MemArg::Label { .. } | &MemArg::Symbol { .. } if !mi.have_pcrel => true,
85+
&MemArg::Symbol { flags, .. } if !mi.have_unaligned_pcrel && !flags.aligned() => true,
86+
&MemArg::BXD20 { .. } if !mi.have_d20 => true,
87+
&MemArg::BXD12 { index, .. } | &MemArg::BXD20 { index, .. } if !mi.have_index => {
7688
index != zero_reg()
7789
}
7890
_ => false,
@@ -93,8 +105,8 @@ pub fn mem_finalize(
93105
index,
94106
disp,
95107
flags,
96-
} if !have_d12 => {
97-
assert!(have_d20);
108+
} if !mi.have_d12 => {
109+
assert!(mi.have_d20);
98110
MemArg::BXD20 {
99111
base,
100112
index,
@@ -122,10 +134,13 @@ pub fn mem_emit(
122134
let (mem_insts, mem) = mem_finalize(
123135
mem,
124136
state,
125-
opcode_rx.is_some(),
126-
opcode_rxy.is_some(),
127-
opcode_ril.is_some(),
128-
true,
137+
MemInstType {
138+
have_d12: opcode_rx.is_some(),
139+
have_d20: opcode_rxy.is_some(),
140+
have_pcrel: opcode_ril.is_some(),
141+
have_unaligned_pcrel: opcode_ril.is_some() && !add_trap,
142+
have_index: true,
143+
},
129144
);
130145
for inst in mem_insts.into_iter() {
131146
inst.emit(&[], sink, emit_info, state);
@@ -190,10 +205,13 @@ pub fn mem_rs_emit(
190205
let (mem_insts, mem) = mem_finalize(
191206
mem,
192207
state,
193-
opcode_rs.is_some(),
194-
opcode_rsy.is_some(),
195-
false,
196-
false,
208+
MemInstType {
209+
have_d12: opcode_rs.is_some(),
210+
have_d20: opcode_rsy.is_some(),
211+
have_pcrel: false,
212+
have_unaligned_pcrel: false,
213+
have_index: false,
214+
},
197215
);
198216
for inst in mem_insts.into_iter() {
199217
inst.emit(&[], sink, emit_info, state);
@@ -236,7 +254,17 @@ pub fn mem_imm8_emit(
236254
emit_info: &EmitInfo,
237255
state: &mut EmitState,
238256
) {
239-
let (mem_insts, mem) = mem_finalize(mem, state, true, true, false, false);
257+
let (mem_insts, mem) = mem_finalize(
258+
mem,
259+
state,
260+
MemInstType {
261+
have_d12: true,
262+
have_d20: true,
263+
have_pcrel: false,
264+
have_unaligned_pcrel: false,
265+
have_index: false,
266+
},
267+
);
240268
for inst in mem_insts.into_iter() {
241269
inst.emit(&[], sink, emit_info, state);
242270
}
@@ -274,7 +302,17 @@ pub fn mem_imm16_emit(
274302
emit_info: &EmitInfo,
275303
state: &mut EmitState,
276304
) {
277-
let (mem_insts, mem) = mem_finalize(mem, state, true, false, false, false);
305+
let (mem_insts, mem) = mem_finalize(
306+
mem,
307+
state,
308+
MemInstType {
309+
have_d12: true,
310+
have_d20: false,
311+
have_pcrel: false,
312+
have_unaligned_pcrel: false,
313+
have_index: false,
314+
},
315+
);
278316
for inst in mem_insts.into_iter() {
279317
inst.emit(&[], sink, emit_info, state);
280318
}
@@ -336,7 +374,17 @@ pub fn mem_vrx_emit(
336374
emit_info: &EmitInfo,
337375
state: &mut EmitState,
338376
) {
339-
let (mem_insts, mem) = mem_finalize(mem, state, true, false, false, true);
377+
let (mem_insts, mem) = mem_finalize(
378+
mem,
379+
state,
380+
MemInstType {
381+
have_d12: true,
382+
have_d20: false,
383+
have_pcrel: false,
384+
have_unaligned_pcrel: false,
385+
have_index: true,
386+
},
387+
);
340388
for inst in mem_insts.into_iter() {
341389
inst.emit(&[], sink, emit_info, state);
342390
}

0 commit comments

Comments
 (0)