Thursday, January 26, 2023

www/seamonkey: xonly amd64 assembly fix

www/seamonkey builds an embedded copy of libffi. On amd64, this
includes some assembly code that puts two jump tables into the .text
segment, which semarie@'s warning diff helpfully pointed out:

/usr/obj/ports/seamonkey-2.53.14/seamonkey-2.53.14/config/external/ffi/../../../js/src/ctypes/libffi/src/x86/unix64.S:94:8: warning: directive value inside .text section: directive '.long', section '.text'
.long .Lst_void-.Lstore_table
^

The patch below moves the tables into .rodata. The tables contain
a list of offsets from a rip-relative starting point. I've left
the original label names to keep the diff small. As far as I can
tell, i.e. from looking at other code our compiler generates,
referencing data in .rodata with rip-relative addressing should be
fine and we don't need to go through the GOT.

It builds. I haven't been able to run it yet, since seamonkey
doesn't appear to be amenable to SSH X11 forwaring.

Okay/comments/tests?


Index: Makefile
===================================================================
RCS file: /cvs/ports/www/seamonkey/Makefile,v
retrieving revision 1.283
diff -u -p -r1.283 Makefile
--- Makefile 24 Jan 2023 08:41:55 -0000 1.283
+++ Makefile 26 Jan 2023 15:34:50 -0000
@@ -13,6 +13,7 @@ MULTI_PACKAGES = -main -lightning
PKGNAME-main = ${PKGNAME}
PKGNAME-lightning = lightning-seamonkey-5.8.15
EPOCH-lightning = 0
+REVISION-main = 0

HOMEPAGE = https://www.seamonkey-project.org/

Index: patches/patch-js_src_ctypes_libffi_src_x86_unix64_S
===================================================================
RCS file: patches/patch-js_src_ctypes_libffi_src_x86_unix64_S
diff -N patches/patch-js_src_ctypes_libffi_src_x86_unix64_S
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ patches/patch-js_src_ctypes_libffi_src_x86_unix64_S 26 Jan 2023 15:34:50 -0000
@@ -0,0 +1,55 @@
+Index: js/src/ctypes/libffi/src/x86/unix64.S
+--- js/src/ctypes/libffi/src/x86/unix64.S.orig
++++ js/src/ctypes/libffi/src/x86/unix64.S
+@@ -85,12 +85,16 @@ ffi_call_unix64:
+
+ /* The first byte of the flags contains the FFI_TYPE. */
+ movzbl %cl, %r10d
+- leaq .Lstore_table(%rip), %r11
++ leaq .Lstore_offsets(%rip), %r11
+ movslq (%r11, %r10, 4), %r10
++ leaq .Lstore_table(%rip), %r11
+ addq %r11, %r10
+ jmp *%r10
+
+ .Lstore_table:
++
++ .section .rodata
++.Lstore_offsets:
+ .long .Lst_void-.Lstore_table /* FFI_TYPE_VOID */
+ .long .Lst_sint32-.Lstore_table /* FFI_TYPE_INT */
+ .long .Lst_float-.Lstore_table /* FFI_TYPE_FLOAT */
+@@ -106,6 +110,7 @@ ffi_call_unix64:
+ .long .Lst_int64-.Lstore_table /* FFI_TYPE_SINT64 */
+ .long .Lst_struct-.Lstore_table /* FFI_TYPE_STRUCT */
+ .long .Lst_int64-.Lstore_table /* FFI_TYPE_POINTER */
++ .previous
+
+ .align 2
+ .Lst_void:
+@@ -234,12 +239,16 @@ ffi_closure_unix64:
+
+ /* The first byte of the return value contains the FFI_TYPE. */
+ movzbl %al, %r10d
+- leaq .Lload_table(%rip), %r11
++ leaq .Lload_offsets(%rip), %r11
+ movslq (%r11, %r10, 4), %r10
++ leaq .Lload_table(%rip), %r11
+ addq %r11, %r10
+ jmp *%r10
+
+ .Lload_table:
++
++ .section .rodata
++.Lload_offsets:
+ .long .Lld_void-.Lload_table /* FFI_TYPE_VOID */
+ .long .Lld_int32-.Lload_table /* FFI_TYPE_INT */
+ .long .Lld_float-.Lload_table /* FFI_TYPE_FLOAT */
+@@ -255,6 +264,7 @@ ffi_closure_unix64:
+ .long .Lld_int64-.Lload_table /* FFI_TYPE_SINT64 */
+ .long .Lld_struct-.Lload_table /* FFI_TYPE_STRUCT */
+ .long .Lld_int64-.Lload_table /* FFI_TYPE_POINTER */
++ .previous
+
+ .align 2
+ .Lld_void:
--
Christian "naddy" Weisgerber naddy@mips.inka.de

No comments:

Post a Comment