Skip to content

Commit e0e8577

Browse files
committed
Bringing back shareable compilation for linux.
1 parent 89eb540 commit e0e8577

2 files changed

Lines changed: 39 additions & 19 deletions

File tree

langs/outlaw/a86/interp.rkt

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
(require "printer.rkt" "ast.rkt" "callback.rkt"
88
(rename-in ffi/unsafe [-> _->]))
99

10-
1110
;; Assembly code is linked with object files in this parameter
1211
(define current-objs
1312
(make-parameter '()))
@@ -42,8 +41,8 @@
4241
(with-output-to-file t.s
4342
#:exists 'truncate
4443
(λ ()
45-
; (parameterize ((current-shared? #t))
46-
(displayln (asm-string a))))
44+
(begin (current-shared? #t)
45+
(displayln (asm-string a)))))
4746

4847
(nasm t.s t.o)
4948
(ld t.o t.so)

langs/outlaw/a86/printer.rkt

Lines changed: 37 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
11
#lang racket
2-
(provide asm-string)
2+
(provide asm-string current-shared?)
33
(require "ast.rkt")
44

5+
(define current-shared?
6+
(let ((x (box #f)))
7+
(case-lambda
8+
[() (unbox x)]
9+
[(y) (set-box! x y)])))
10+
511
;; Any -> Boolean
612
(define (reg? x)
713
(register? x))
@@ -17,7 +23,14 @@
1723
['macosx
1824
(λ (s) (string-append "_" (symbol->string s)))]
1925
[_
20-
symbol->string]))
26+
(if (current-shared?)
27+
(λ (s)
28+
(if (memq s external-labels)
29+
; hack for ELF64 shared libraries in service of
30+
; calling external functions in asm-interp
31+
(string-append (symbol->string s) " wrt ..plt")
32+
(symbol->string s)))
33+
symbol->string)]))
2134

2235
;; (U Label Reg) -> String
2336
(define (jump-target->string t)
@@ -50,6 +63,9 @@
5063

5164
(define tab (make-string 8 #\space))
5265

66+
67+
(define external-labels (box '()))
68+
5369
;; Instruction -> String
5470
(define (instr->string i)
5571
(match i
@@ -58,7 +74,10 @@
5874
[(Ret) (string-append tab "ret")]
5975
[(Label l) (string-append (label-symbol->string l) ":")]
6076
[(Global x) (string-append tab "global " (label-symbol->string x))]
61-
[(Extern l) (string-append tab "extern " (label-symbol->string l))]
77+
[(Extern l) (let ((r (string-append tab "extern " (label-symbol->string l))))
78+
(begin
79+
(set-box! external-labels (cons l (unbox external-labels)))
80+
r))]
6281
[(Mov a1 a2)
6382
(string-append tab "mov "
6483
(arg->string a1) ", "
@@ -154,16 +173,18 @@
154173
(string-append (instr->string i) "\n" (instrs->string a))]))
155174

156175
;; Asm -> String
157-
(define (asm-string a)
158-
;; entry point will be first label
159-
(match (findf Label? a)
160-
[(Label g)
161-
(string-append
162-
tab "global " (label-symbol->string g) "\n"
163-
tab "default rel\n"
164-
tab "section .text\n"
165-
(instrs->string a))]
166-
[_
167-
(instrs->string a)
168-
#;
169-
(error "program does not have an initial label")]))
176+
(define (asm-string a)
177+
(begin
178+
(set-box! external-labels '())
179+
;; entry point will be first label
180+
(match (findf Label? a)
181+
[(Label g)
182+
(string-append
183+
tab "global " (label-symbol->string g) "\n"
184+
tab "default rel\n"
185+
tab "section .text\n"
186+
(instrs->string a))]
187+
[_
188+
(instrs->string a)
189+
#;
190+
(error "program does not have an initial label")])))

0 commit comments

Comments
 (0)