MLton / mlton

The MLton repository
http://mlton.org
Other
960 stars 127 forks source link

mlton-script: OpenBSD link-opt for no xonly text #555

Closed dancrossnyc closed 7 months ago

dancrossnyc commented 7 months ago

Add a -target-link-opt for OpenBSD that disables "xonly" text.

OpenBSD's linker, by default, makes a program's text segment executable-only ("xonly"): that is, executable but not readable. However, MLton needs to be able to read the text segment when mapping return addresses to stack frame indices, possibly among other things. This causes programs compiled with MLton's native code generator to fault and die with SIGSEGV.

However, the default "xonly" behavior can be disabled with a linker option (--no-execute-only), so we can turn it off with a -target-link-opt specific to OpenBSD in mlton-script. Binaries built in this configuration run as expected.

Fixes #538