Rename alien-linkage-table-space (again)

It was previously renamed in rev 851cbd2b but the new name was too wordy.
The motivation here is the same: some pending changes for x86-64 that make
lisp-to-lisp calls go through a linkage table (almost doing away with
all FDEFNs) is nearly ready to be committed for real now.
This commit is contained in:
Douglas Katzman 2024-06-12 21:16:24 -04:00
parent 8c614de019
commit 7e9b907b11
29 changed files with 51 additions and 54 deletions

View file

@ -19,7 +19,7 @@ also utilized to allow references to as-of-yet unknown aliens.
The SBCL implementation is somewhat simplified from the CMUCL one by
Timothy Moore, but the basic idea and mechanism remain identical:
instead of having addresses from @code{dlsym(3)} in the core, we have
addresses to an mmapped memory area (@code{ALIEN_LINKAGE_TABLE_SPACE}) that
addresses to an mmapped memory area (@code{ALIEN_LINKAGE_SPACE}) that
is initialized at startup to contain jumps & references to the correct
addresses, based on information stored on the lisp side in
@code{*LINKAGE-INFO*}.
@ -72,7 +72,7 @@ is used by SB-POSIX.)
Find a memory area for the linkage-table, and add it for the OS in
@file{src/compiler/target/parms.lisp} by defining
@code{SB-VM:ALIEN-LINKAGE-TABLE-SPACE-START}. See existing ports and CMUCL for
@code{SB-VM:ALIEN-LINKAGE-SPACE-START}. See existing ports and CMUCL for
examples.
@subsubsection Porting to new architectures

View file

@ -60,7 +60,7 @@
#-sb-thread
(progn
;; Each of these loads of a fixup loads the address of a linkage table entry,
;; that is, if ALIEN-LINKAGE-TABLE-SPACE-START is #xF0200000, then the first load puts
;; that is, if ALIEN-LINKAGE-SPACE-START is #xF0200000, then the first load puts
;; #xF0200000+something, not the address of current_control_frame_pointer,
;; into register nl2.
;; This is kinda dumb because first of all we could have calculated the address

View file

@ -51,7 +51,7 @@
(or (with-system-mutex ((hash-table-lock ht))
(or (gethash key ht)
(let* ((index (hash-table-count ht))
(capacity (floor sb-vm:alien-linkage-table-space-size
(capacity (floor sb-vm:alien-linkage-space-size
sb-vm:alien-linkage-table-entry-size)))
(when (< index capacity)
(multiple-value-bind (defined real-address) (dlsym-wrapper t)
@ -176,9 +176,9 @@ symbol designates a variable. May enter the symbol into the linkage-table."
(declare (ignorable sap))
(let ((addr (sap-int sap)))
(declare (ignorable addr))
(when (<= sb-vm:alien-linkage-table-space-start
(when (<= sb-vm:alien-linkage-space-start
addr
(+ sb-vm:alien-linkage-table-space-start sb-vm:alien-linkage-table-space-size))
(+ sb-vm:alien-linkage-space-start sb-vm:alien-linkage-space-size))
(return-from sap-foreign-symbol
(alien-linkage-index-to-name
(sb-vm::alien-linkage-table-index-from-address addr))))

View file

@ -58,8 +58,8 @@
(define-alien-variable ("TEXT_SPACE_START" sb-vm:text-space-start) unsigned-long)
#+immobile-space
(define-symbol-macro sb-vm:alien-linkage-table-space-start
(extern-alien "ALIEN_LINKAGE_TABLE_SPACE_START" unsigned))
(define-symbol-macro sb-vm:alien-linkage-space-start
(extern-alien "ALIEN_LINKAGE_SPACE_START" unsigned))
#+darwin-jit
(define-alien-variable ("static_code_space_free_pointer" sb-vm:*static-code-space-free-pointer*)

View file

@ -3107,8 +3107,8 @@ structure representations")
"READ-ONLY-SPACE-START" "READ-ONLY-SPACE-END"
"STATIC-SPACE-START" "STATIC-SPACE-END" "*STATIC-SPACE-FREE-POINTER*"
"STATIC-CODE-SPACE-START" "STATIC-CODE-SPACE-END" "*STATIC-CODE-SPACE-FREE-POINTER*"
"ALIEN-LINKAGE-TABLE-SPACE-START"
"ALIEN-LINKAGE-TABLE-SPACE-SIZE"
"ALIEN-LINKAGE-SPACE-START"
"ALIEN-LINKAGE-SPACE-SIZE"
"ALIEN-LINKAGE-TABLE-ENTRY-SIZE"
#+sb-safepoint "GC-SAFEPOINT-TRAP-OFFSET"
"THREAD-STATE-WORD-SLOT"

View file

@ -148,7 +148,7 @@
(let ((stop (1- (ash 1 n-word-bits)))
(start dynamic-space-start))
(dolist (other-start (list read-only-space-start static-space-start
alien-linkage-table-space-start))
alien-linkage-space-start))
(declare (notinline <)) ; avoid dead code note
(when (< start other-start)
(setf stop (min stop other-start))))

View file

@ -2974,8 +2974,8 @@ Legal values for OFFSET are -4, -8, -12, ..."
#+cheneygc
(check sb-vm:dynamic-0-space-start sb-vm:dynamic-0-space-end :dynamic-0)
#-immobile-space
(let ((end (+ sb-vm:alien-linkage-table-space-start sb-vm:alien-linkage-table-space-size)))
(check sb-vm:alien-linkage-table-space-start end :linkage-table)))))
(let ((end (+ sb-vm:alien-linkage-space-start sb-vm:alien-linkage-space-size)))
(check sb-vm:alien-linkage-space-start end :linkage-table)))))
;;;; emitting C header file

View file

@ -38,7 +38,7 @@
#-sb-xc-host (symbol-value 'default-dynamic-space-size))
;; By happenstance this is the same as small-space-size.
(defconstant alien-linkage-table-space-size #x100000)
(defconstant alien-linkage-space-size #x100000)
;; Define START/END constants for GC spaces.
;; Assumptions:
@ -85,7 +85,7 @@
((spaces (append `((read-only ,ro-space-size)
#+(and win32 x86-64)
(seh-data ,(symbol-value '+backend-page-bytes+) win64-seh-data-addr)
#-immobile-space (alien-linkage-table ,alien-linkage-table-space-size)
#-immobile-space (alien-linkage ,alien-linkage-space-size)
;; safepoint on 64-bit uses a relocatable trap page just below the card mark
;; table, which works nicely assuming a register is wired to the card table
#+(and sb-safepoint (not x86-64))
@ -97,7 +97,7 @@
(static-code ,small-space-size))
#+immobile-space
`((fixedobj ,fixedobj-space-size*)
(alien-linkage-table ,alien-linkage-table-space-size)
(alien-linkage ,alien-linkage-space-size)
(text ,text-space-size*))))
(ptr small-spaces-start)
(small-space-forms
@ -107,7 +107,7 @@
(member space '(fixedobj text permgen
#+relocatable-static-space safepoint
#+relocatable-static-space static
#+immobile-space alien-linkage-table
#+immobile-space alien-linkage
read-only)))
(start ptr)
(end (+ ptr size)))

View file

@ -47,22 +47,18 @@
(- list-pointer-lowtag)))
0))
(symbol-macrolet ((alien-linkage-table-space-end
(+ alien-linkage-table-space-start alien-linkage-table-space-size)))
(symbol-macrolet ((space-end (+ alien-linkage-space-start alien-linkage-space-size)))
;;; the address of the linkage table entry for table index I.
(defun alien-linkage-table-entry-address (i)
(ecase alien-linkage-table-growth-direction
(:up (+ (* i alien-linkage-table-entry-size) alien-linkage-table-space-start))
(:down (- alien-linkage-table-space-end (* (1+ i) alien-linkage-table-entry-size)))))
(:up (+ (* i alien-linkage-table-entry-size) alien-linkage-space-start))
(:down (- space-end (* (1+ i) alien-linkage-table-entry-size)))))
#-sb-xc-host
(defun alien-linkage-table-index-from-address (addr)
(ecase alien-linkage-table-growth-direction
(:up
(floor (- addr alien-linkage-table-space-start) alien-linkage-table-entry-size))
(:down
(1- (floor (- alien-linkage-table-space-end addr) alien-linkage-table-space-end)))))
)
(:up (floor (- addr alien-linkage-space-start) alien-linkage-table-entry-size))
(:down (1- (floor (- space-end addr) space-end))))))
;;; Return absolute address of the 'fun' slot in static fdefn NAME.
(defun static-fdefn-fun-addr (name)

View file

@ -475,9 +475,9 @@
;; compilation to memory says it is all associated with
;; the symbol "lisp_jit_code" which is not useful.
(when (plusp addr)
(or (when (<= sb-vm:alien-linkage-table-space-start addr
(+ sb-vm:alien-linkage-table-space-start
(1- sb-vm:alien-linkage-table-space-size)))
(or (when (<= sb-vm:alien-linkage-space-start addr
(+ sb-vm:alien-linkage-space-start
(1- sb-vm:alien-linkage-space-size)))
(let* ((index (sb-vm::alien-linkage-table-index-from-address addr))
(name (sb-impl::alien-linkage-index-to-name index)))
(note (lambda (s) (format s "&~A" name)) dstate)))

View file

@ -108,7 +108,7 @@ void arch_write_linkage_table_entry(int index, void *target_addr, int datap)
{
// allocate successive entries downward
char *reloc_addr =
(char*)ALIEN_LINKAGE_TABLE_SPACE_END - (index + 1) * ALIEN_LINKAGE_TABLE_ENTRY_SIZE;
(char*)ALIEN_LINKAGE_SPACE_END - (index + 1) * ALIEN_LINKAGE_TABLE_ENTRY_SIZE;
if (datap) {
*(unsigned long *)reloc_addr = (unsigned long)target_addr;
return;

View file

@ -136,7 +136,7 @@ void arch_install_interrupt_handlers()
void arch_write_linkage_table_entry(int index, void *target_addr, int datap)
{
THREAD_JIT_WP(0);
char *reloc_addr = (char*)ALIEN_LINKAGE_TABLE_SPACE_START + index * ALIEN_LINKAGE_TABLE_ENTRY_SIZE;
char *reloc_addr = (char*)ALIEN_LINKAGE_SPACE_START + index * ALIEN_LINKAGE_TABLE_ENTRY_SIZE;
if (datap) {
*(unsigned long *)reloc_addr = (unsigned long)target_addr;

View file

@ -559,7 +559,7 @@ The system may fail to start.\n",
*/
getrlimit (RLIMIT_DATA, &rl);
if (dynamic_space_size + READ_ONLY_SPACE_SIZE + STATIC_SPACE_SIZE +
ALIEN_LINKAGE_TABLE_SPACE_SIZE + wantfree > rl.rlim_cur)
ALIEN_LINKAGE_SPACE_SIZE + wantfree > rl.rlim_cur)
fprintf (stderr,
"RUNTIME WARNING: data size resource limit may be too low,\n"
" try decreasing the dynamic space size with --dynamic-space-size\n"

View file

@ -692,8 +692,8 @@ static os_vm_address_t reserve_space(int space_id, int attr,
if (space_id == IMMOBILE_TEXT_CORE_SPACE_ID) {
// Carve out the text space from the earlier request that was made
// for the fixedobj space.
ALIEN_LINKAGE_TABLE_SPACE_START = FIXEDOBJ_SPACE_START + FIXEDOBJ_SPACE_SIZE;
return (os_vm_address_t)(ALIEN_LINKAGE_TABLE_SPACE_START + ALIEN_LINKAGE_TABLE_SPACE_SIZE);
ALIEN_LINKAGE_SPACE_START = FIXEDOBJ_SPACE_START + FIXEDOBJ_SPACE_SIZE;
return (os_vm_address_t)(ALIEN_LINKAGE_SPACE_START + ALIEN_LINKAGE_SPACE_SIZE);
}
#endif
if (size == 0) return addr;
@ -755,9 +755,9 @@ process_directory(int count, struct ndir_entry *entry,
#ifdef LISP_FEATURE_IMMOBILE_SPACE
// ELF core without immobile space has alien linkage space below static space.
ALIEN_LINKAGE_TABLE_SPACE_START =
ALIEN_LINKAGE_SPACE_START =
(uword_t)os_alloc_gc_space(ALIEN_LINKAGE_TABLE_CORE_SPACE_ID, 0, 0,
ALIEN_LINKAGE_TABLE_SPACE_SIZE);
ALIEN_LINKAGE_SPACE_SIZE);
#endif
} else
#endif
@ -766,7 +766,7 @@ process_directory(int count, struct ndir_entry *entry,
{
#ifdef LISP_FEATURE_IMMOBILE_SPACE
spaces[IMMOBILE_FIXEDOBJ_CORE_SPACE_ID].desired_size +=
text_space_size + ALIEN_LINKAGE_TABLE_SPACE_SIZE;
text_space_size + ALIEN_LINKAGE_SPACE_SIZE;
#endif
}

View file

@ -60,7 +60,7 @@ lispobj *static_code_space_free_pointer;
#ifdef LISP_FEATURE_IMMOBILE_SPACE
lispobj *fixedobj_free_pointer;
lispobj ALIEN_LINKAGE_TABLE_SPACE_START;
lispobj ALIEN_LINKAGE_SPACE_START;
#endif
os_vm_address_t anon_dynamic_space_start;
// The end of immobile text mapped from disk, equivalently the starting address

View file

@ -107,7 +107,7 @@ extern lispobj *static_code_space_free_pointer;
extern lispobj *text_space_highwatermark;
#ifdef LISP_FEATURE_IMMOBILE_SPACE
extern lispobj *fixedobj_free_pointer;
extern lispobj ALIEN_LINKAGE_TABLE_SPACE_START;
extern lispobj ALIEN_LINKAGE_SPACE_START;
#endif
extern os_vm_address_t anon_dynamic_space_start;
extern lispobj* tlsf_mem_start; // meaningful only if immobile space

View file

@ -495,7 +495,7 @@ arch_write_linkage_table_entry(int index, void *target_addr, int datap)
{
// allocate successive entries downward
char *reloc_addr =
(char*)ALIEN_LINKAGE_TABLE_SPACE_END - (index + 1) * ALIEN_LINKAGE_TABLE_ENTRY_SIZE;
(char*)ALIEN_LINKAGE_SPACE_END - (index + 1) * ALIEN_LINKAGE_TABLE_ENTRY_SIZE;
*(unsigned int *)reloc_addr = (unsigned int)target_addr;
}

View file

@ -596,7 +596,7 @@ ppc_flush_icache(os_vm_address_t address, os_vm_size_t length)
void
arch_write_linkage_table_entry(int index, void *target_addr, int datap)
{
char *reloc_addr = (char*)ALIEN_LINKAGE_TABLE_SPACE_START + index * ALIEN_LINKAGE_TABLE_ENTRY_SIZE;
char *reloc_addr = (char*)ALIEN_LINKAGE_SPACE_START + index * ALIEN_LINKAGE_TABLE_ENTRY_SIZE;
if (datap) {
*(unsigned long *)reloc_addr = (unsigned long)target_addr;
return;

View file

@ -146,7 +146,7 @@ void arch_write_linkage_table_entry(int index, void *target_addr, int datap)
{
// allocate successive entries downward
char *reloc_addr =
(char*)ALIEN_LINKAGE_TABLE_SPACE_END - (index + 1) * ALIEN_LINKAGE_TABLE_ENTRY_SIZE;
(char*)ALIEN_LINKAGE_SPACE_END - (index + 1) * ALIEN_LINKAGE_TABLE_ENTRY_SIZE;
if (datap) {
*(unsigned long *)reloc_addr = (unsigned long)target_addr;
return;

View file

@ -299,7 +299,7 @@ void arch_install_interrupt_handlers()
void
arch_write_linkage_table_entry(int index, void *target_addr, int datap)
{
char *reloc_addr = (char*)ALIEN_LINKAGE_TABLE_SPACE_START + index * ALIEN_LINKAGE_TABLE_ENTRY_SIZE;
char *reloc_addr = (char*)ALIEN_LINKAGE_SPACE_START + index * ALIEN_LINKAGE_TABLE_ENTRY_SIZE;
if (datap) {
*(unsigned long *)reloc_addr = (unsigned long)target_addr;
return;

View file

@ -943,7 +943,7 @@ alloc_thread_struct(void* spaces) {
tls[THREAD_T_NIL_CONSTANTS_SLOT] = (NIL << 32) | LISP_T;
#endif
#ifdef THREAD_ALIEN_LINKAGE_TABLE_BASE_SLOT
tls[THREAD_ALIEN_LINKAGE_TABLE_BASE_SLOT] = (lispobj)ALIEN_LINKAGE_TABLE_SPACE_START;
tls[THREAD_ALIEN_LINKAGE_TABLE_BASE_SLOT] = (lispobj)ALIEN_LINKAGE_SPACE_START;
#endif
#if defined LISP_FEATURE_X86_64 && defined LISP_FEATURE_LINUX
tls[THREAD_MSAN_XOR_CONSTANT_SLOT] = 0x500000000000;

View file

@ -91,7 +91,7 @@ bool allocate_hardwired_spaces(bool hard_failp)
} preinit_spaces[] = {
{ READ_ONLY_SPACE_START, READ_ONLY_SPACE_SIZE, READ_ONLY_CORE_SPACE_ID },
#ifndef LISP_FEATURE_IMMOBILE_SPACE
{ ALIEN_LINKAGE_TABLE_SPACE_START, ALIEN_LINKAGE_TABLE_SPACE_SIZE, ALIEN_LINKAGE_TABLE_CORE_SPACE_ID },
{ ALIEN_LINKAGE_SPACE_START, ALIEN_LINKAGE_SPACE_SIZE, ALIEN_LINKAGE_TABLE_CORE_SPACE_ID },
#endif
{ STATIC_SPACE_START, STATIC_SPACE_SIZE, STATIC_CORE_SPACE_ID },
#ifdef LISP_FEATURE_DARWIN_JIT

View file

@ -31,8 +31,7 @@
#define STATIC_CODE_SPACE_SIZE (STATIC_CODE_SPACE_END - STATIC_CODE_SPACE_START)
#endif
#define ALIEN_LINKAGE_TABLE_SPACE_END \
(ALIEN_LINKAGE_TABLE_SPACE_START + ALIEN_LINKAGE_TABLE_SPACE_SIZE)
#define ALIEN_LINKAGE_SPACE_END (ALIEN_LINKAGE_SPACE_START + ALIEN_LINKAGE_SPACE_SIZE)
#if !defined(__ASSEMBLER__)
#include <stdbool.h>

View file

@ -513,7 +513,7 @@ arch_install_interrupt_handlers()
void
arch_write_linkage_table_entry(int index, void *target_addr, int datap)
{
char *reloc_addr = (char*)ALIEN_LINKAGE_TABLE_SPACE_START + index * ALIEN_LINKAGE_TABLE_ENTRY_SIZE;
char *reloc_addr = (char*)ALIEN_LINKAGE_SPACE_START + index * ALIEN_LINKAGE_TABLE_ENTRY_SIZE;
if (datap) {
*(uword_t *)reloc_addr = (uword_t)target_addr;
return;

View file

@ -356,7 +356,7 @@ void
arch_write_linkage_table_entry(int index, void *target_addr, int datap)
{
// 'volatile' works around a spurious GCC warning
volatile char *reloc_addr = (char*)ALIEN_LINKAGE_TABLE_SPACE_START + index * ALIEN_LINKAGE_TABLE_ENTRY_SIZE;
volatile char *reloc_addr = (char*)ALIEN_LINKAGE_SPACE_START + index * ALIEN_LINKAGE_TABLE_ENTRY_SIZE;
if (datap) {
*(unsigned long *)reloc_addr = (unsigned long)target_addr;
return;

View file

@ -302,7 +302,7 @@
(assert (not (sb-kernel:immobile-space-addr-p
(+ sb-vm:fixedobj-space-start
sb-vm:fixedobj-space-size
sb-vm:alien-linkage-table-space-size
sb-vm:alien-linkage-space-size
sb-vm:text-space-size)))))
(with-test (:name :unique-code-serialno :skipped-on :interpreter)

View file

@ -310,7 +310,7 @@
(let ((text-space (get-space immobile-text-core-space-id spacemap)))
(if text-space
(let ((text-addr (space-addr text-space)))
(make-bounds (- text-addr alien-linkage-table-space-size) text-addr))
(make-bounds (- text-addr alien-linkage-space-size) text-addr))
(make-bounds 0 0))))
(linkage-entry-size
(symbol-global-value

View file

@ -1636,9 +1636,8 @@
(when (eq (second inst) 'call)
(let ((operand (third inst)))
(when (and (integerp operand)
(>= operand alien-linkage-table-space-start)
(< operand (+ alien-linkage-table-space-start
alien-linkage-table-space-size)))
(>= operand alien-linkage-space-start)
(< operand (+ alien-linkage-space-start alien-linkage-space-size)))
(let* ((index (position (int-sap operand) *c-linkage-redirects*
:key #'cdr :test #'sap=))
(branch-target (+ c-linkage-vector-vaddr

View file

@ -1421,6 +1421,9 @@
(#(246D4FD0 321B4470 42CAE6A9 55DFCE4E 59FE9825 F569D93E)
"(SB-VM::FIXEDOBJ SB-VM::TEXT SB-VM::PERMGEN SB-VM::SAFEPOINT SB-VM::STATIC SB-VM::READ-ONLY)"
"( (& (^ (>> val 1) (>> val 21)) 7))")
(#(246D4FD0 321B4470 42CAE6A9 55DFCE4E 73ECD70C)
"(SB-VM::FIXEDOBJ SB-VM::TEXT SB-VM::PERMGEN SB-VM::ALIEN-LINKAGE SB-VM::READ-ONLY)"
"( (& (- (>> val 3) (>> val 17)) 7))")
(#(246D4FD0 321B4470 42CAE6A9 55DFCE4E BBE26BAD)
"(SB-VM::FIXEDOBJ SB-VM::TEXT SB-VM::PERMGEN SB-VM::ALIEN-LINKAGE-TABLE SB-VM::READ-ONLY)"
"( (& (- val (>> val 8)) 7))")