diff --git a/crates/fiber/src/arch/aarch64.S b/crates/fiber/src/arch/aarch64.S index 96db800291d1..f38be926b260 100644 --- a/crates/fiber/src/arch/aarch64.S +++ b/crates/fiber/src/arch/aarch64.S @@ -8,12 +8,10 @@ // Also at this time this file is heavily based off the x86_64 file, so you'll // probably want to read that one as well. -#define GLOBL(fnname) .globl fnname -#define TYPE(fnname) .type fnname,@function -#define FUNCTION(fnname) fnname -#define SIZE(fnname) .size fnname,.-fnname +#include "header.h" // fn(top_of_stack(%x0): *mut u8) +HIDDEN(wasmtime_fiber_switch) GLOBL(wasmtime_fiber_switch) .p2align 2 TYPE(wasmtime_fiber_switch) @@ -58,11 +56,12 @@ SIZE(wasmtime_fiber_switch) // entry_point(%x1): extern fn(*mut u8, *mut u8), // entry_arg0(%x2): *mut u8, // ) +HIDDEN(wasmtime_fiber_init) GLOBL(wasmtime_fiber_init) .p2align 2 TYPE(wasmtime_fiber_init) FUNCTION(wasmtime_fiber_init): - adr x8, wasmtime_fiber_start + adr x8, FUNCTION(wasmtime_fiber_start) stp x0, x8, [x0, -0x28] // x0 => x19, x8 => lr stp x2, x1, [x0, -0x38] // x1 => x20, x2 => x21 @@ -114,5 +113,10 @@ FUNCTION(wasmtime_fiber_start): .cfi_endproc SIZE(wasmtime_fiber_start) -.section .note.GNU-stack,"",%progbits - +// This omits the `.subsections_via_symbols` directive on macOS which means we +// can't GC specific intrinsics from this file, but it enables usage of the +// `adr` instruction above in lieu of figuring out a slightly more complicated +// way of implementing that. +#ifndef CFG_TARGET_OS_macos +FOOTER +#endif diff --git a/crates/fiber/src/arch/arm.S b/crates/fiber/src/arch/arm.S index 9b034c9eb4e4..54eb507aba56 100644 --- a/crates/fiber/src/arch/arm.S +++ b/crates/fiber/src/arch/arm.S @@ -8,11 +8,13 @@ // Also at this time this file is heavily based off the x86_64 file, so you'll // probably want to read that one as well. -#define SIZE(fnname) .size fnname,.-fnname +#include "header.h" // fn(top_of_stack(%r0): *mut u8) -.globl wasmtime_fiber_switch -wasmtime_fiber_switch: +HIDDEN(wasmtime_fiber_switch) +GLOBL(wasmtime_fiber_switch) +TYPE(wasmtime_fiber_switch) +FUNCTION(wasmtime_fiber_switch): // Save callee-saved registers push {r4-r11,lr} @@ -31,9 +33,11 @@ SIZE(wasmtime_fiber_switch) // entry_point(%r1): extern fn(*mut u8, *mut u8), // entry_arg0(%r2): *mut u8, // ) -.globl wasmtime_fiber_init -wasmtime_fiber_init: - adr r3, wasmtime_fiber_start +HIDDEN(wasmtime_fiber_init) +GLOBL(wasmtime_fiber_init) +TYPE(wasmtime_fiber_init) +FUNCTION(wasmtime_fiber_init): + adr r3, FUNCTION(wasmtime_fiber_start) str r3, [r0, #-0x0c] // => lr str r0, [r0, #-0x10] // => r11 str r1, [r0, #-0x14] // => r10 @@ -44,7 +48,7 @@ wasmtime_fiber_init: bx lr SIZE(wasmtime_fiber_init) -wasmtime_fiber_start: +FUNCTION(wasmtime_fiber_start): .cfi_startproc simple // See the x86_64 file for more commentary on what these CFI directives are // doing. Like over there note that the relative offsets to registers here @@ -76,4 +80,4 @@ wasmtime_fiber_start: .cfi_endproc SIZE(wasmtime_fiber_start) -.section .note.GNU-stack,"",%progbits +FOOTER diff --git a/crates/fiber/src/arch/header.h b/crates/fiber/src/arch/header.h new file mode 100644 index 000000000000..5afc28e2ab12 --- /dev/null +++ b/crates/fiber/src/arch/header.h @@ -0,0 +1,36 @@ +#ifndef __wasmtime_common_h +#define __wasmtime_common_h + +#if CFG_TARGET_OS_macos + +.section __TEXT,__text,regular,pure_instructions + +#define GLOBL(fnname) .globl _##fnname +#define HIDDEN(fnname) .private_extern _##fnname +#define TYPE(fnname) +#define FUNCTION(fnname) _##fnname +#define SIZE(fnname) + +// Tells the linker it's safe to gc symbols away if not used. +#define FOOTER .subsections_via_symbols + +#else + +.text + +#define GLOBL(fnname) .globl fnname +#define HIDDEN(fnname) .hidden fnname +#ifdef CFG_TARGET_ARCH_arm +#define TYPE(fnname) .type fnname,%function +#else +#define TYPE(fnname) .type fnname,@function +#endif +#define FUNCTION(fnname) fnname +#define SIZE(fnname) .size fnname,.-fnname + +// Mark that we don't need executable stack. +#define FOOTER .section .note.GNU-stack,"",%progbits + +#endif + +#endif // __wasmtime_common_h diff --git a/crates/fiber/src/arch/x86.S b/crates/fiber/src/arch/x86.S index 3e480330c7a2..c147289a314a 100644 --- a/crates/fiber/src/arch/x86.S +++ b/crates/fiber/src/arch/x86.S @@ -10,14 +10,13 @@ // different so the reserved space at the top of the stack is 8 bytes, not 16 // bytes. Still two pointers though. -.text - -#define SIZE(fnname) .size fnname,.-fnname +#include "header.h" // fn(top_of_stack: *mut u8) -.globl wasmtime_fiber_switch -.type wasmtime_fiber_switch,@function -wasmtime_fiber_switch: +HIDDEN(wasmtime_fiber_switch) +GLOBL(wasmtime_fiber_switch) +TYPE(wasmtime_fiber_switch) +FUNCTION(wasmtime_fiber_switch): // Load our stack-to-use mov 0x4(%esp), %eax mov -0x8(%eax), %ecx @@ -45,9 +44,10 @@ SIZE(wasmtime_fiber_switch) // entry_point: extern fn(*mut u8, *mut u8), // entry_arg0: *mut u8, // ) -.globl wasmtime_fiber_init -.type wasmtime_fiber_init,@function -wasmtime_fiber_init: +HIDDEN(wasmtime_fiber_init) +GLOBL(wasmtime_fiber_init) +TYPE(wasmtime_fiber_init) +FUNCTION(wasmtime_fiber_init): mov 4(%esp), %eax // move top_of_stack to the 2nd argument @@ -59,7 +59,7 @@ wasmtime_fiber_init: // Move our start function to the return address which the `ret` in // `wasmtime_fiber_start` will return to. - lea wasmtime_fiber_start, %ecx + lea FUNCTION(wasmtime_fiber_start), %ecx mov %ecx, -0x14(%eax) // And move `entry_point` to get loaded into `%ebp` through the context @@ -82,8 +82,8 @@ wasmtime_fiber_init: ret SIZE(wasmtime_fiber_init) -.type wasmtime_fiber_start,@function -wasmtime_fiber_start: +TYPE(wasmtime_fiber_start) +FUNCTION(wasmtime_fiber_start): .cfi_startproc simple .cfi_escape 0x0f, /* DW_CFA_def_cfa_expression */ \ 5, /* the byte length of this expression */ \ @@ -104,6 +104,4 @@ wasmtime_fiber_start: .cfi_endproc SIZE(wasmtime_fiber_start) -// Mark that we don't need executable stack. -.section .note.GNU-stack,"",%progbits - +FOOTER diff --git a/crates/fiber/src/arch/x86_64.S b/crates/fiber/src/arch/x86_64.S index 1eae5d1da911..89e20b1aeee4 100644 --- a/crates/fiber/src/arch/x86_64.S +++ b/crates/fiber/src/arch/x86_64.S @@ -5,25 +5,10 @@ // all the other bits. Documentation tries to reference various bits here and // there but try to make sure to read over everything before tweaking things! -.text - -#if CFG_TARGET_OS_macos - -#define GLOBL(fnname) .globl _##fnname -#define TYPE(fnname) -#define FUNCTION(fnname) _##fnname -#define SIZE(fnname) - -#else - -#define GLOBL(fnname) .globl fnname -#define TYPE(fnname) .type fnname,@function -#define FUNCTION(fnname) fnname -#define SIZE(fnname) .size fnname,.-fnname - -#endif +#include "header.h" // fn(top_of_stack(%rdi): *mut u8) +HIDDEN(wasmtime_fiber_switch) GLOBL(wasmtime_fiber_switch) .align 16 TYPE(wasmtime_fiber_switch) @@ -63,6 +48,7 @@ SIZE(wasmtime_fiber_switch) // entry_point(%rsi): extern fn(*mut u8, *mut u8), // entry_arg0(%rdx): *mut u8, // ) +HIDDEN(wasmtime_fiber_init) GLOBL(wasmtime_fiber_init) .align 16 TYPE(wasmtime_fiber_init) @@ -169,7 +155,5 @@ FUNCTION(wasmtime_fiber_start): .cfi_endproc SIZE(wasmtime_fiber_start) -// Mark that we don't need executable stack. -#if defined(__ELF__) -.section .note.GNU-stack,"",%progbits -#endif +FOOTER +