File: 0006-make-arm32-return-address-encoding-montonic-w.r.t.-o.patch

package info (click to toggle)
chezscheme 9.5.4%2Bdfsg-4
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, sid
  • size: 61,640 kB
  • sloc: ansic: 17,508; sh: 759; makefile: 509; csh: 423
file content (44 lines) | stat: -rw-r--r-- 1,706 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
From: Matthew Flatt <mflatt@racket-lang.org>
Date: Thu, 3 Sep 2020 05:56:20 -0600
Subject: make arm32 return-address encoding montonic w.r.t. offset
Forwarded: https://github.com/cisco/ChezScheme/pull/532

---
 s/arm32.ss | 14 ++++++++++++--
 1 file changed, 12 insertions(+), 2 deletions(-)

diff --git a/s/arm32.ss b/s/arm32.ss
index 9edb2ff..11b09e5 100644
--- a/s/arm32.ss
+++ b/s/arm32.ss
@@ -1679,6 +1679,16 @@
                          (bitwise-arithmetic-shift-left (logand n #xffffff) 8)
                          (bitwise-arithmetic-shift-right n 24)))))))))
 
+  ;; restrict funky12 so that an code offset n will not fit
+  ;; if a smaller offset wouldn't fit, which prevents bouncing
+  ;; in the loop that computes label offsets
+  (define code-offset-funky12
+    (lambda (n)
+      (safe-assert (and (fixnum? n) (fx= 0 (fxand n 3))))
+      (and (fixnum? n)
+           (#%$fxu< n #x400)
+           (funky12 n))))
+
   (define shift-count?
     (lambda (imm)
       ; can also allow 0 for lsl and 32 (represented as 0) for lsr, asr
@@ -2144,11 +2154,11 @@
                (lambda (offset)
                  (let ([disp (fx- next-addr (fx- offset incr-offset) 4)])
                    (cond
-                     [(funky12 disp)
+                     [(code-offset-funky12 disp)
                       (Trivit (dest)
                         ; aka adr, encoding A1
                         (emit addi #f dest `(reg . ,%pc) disp '()))]
-                     [(funky12 (- disp))
+                     [(code-offset-funky12 (- disp))
                       (Trivit (dest)
                         ; aka adr, encoding A2
                         (emit subi #f dest `(reg . ,%pc) (- disp) '()))]