# shellcheck shell=bash # The defaults of WASMLD_DYNAMIC_MAIN and WASMLD_DYNAMIC_MODULE for a glibc # link, set where the caller left them unset, and the form -static asks for. # # Sourced by brintcc-glibc; meta-brintos's guest ld wrapper sources it too. # # brintium_dynamic_defaults "$@" # brintium_line_is_static_link "$@" # status 0: -static on a final link # # A glibc main is a dynamic main and a dynamic module: it imports the shared # function table, so it can load a library at run time. Under the status # channel brintld refuses a dynamic module that does not consume libc.so's # partition, because without it a library loaded later cannot be checked # against the main for mixing check-emitting and nothrow code. A caller who # sets WASMLD_LIBC_IMPORT=0 has asked for libc to be linked into the program, # so under the channel that link is a self-contained image (both 0), as a # static status-channel recipe spells it. That default applies only where the # caller set neither knob: a caller who sets one keeps the old default, 1, for # the other, so WASMLD_DYNAMIC_MAIN=1 there is still a dynamic module and still # refused. A -shared link stays a dynamic module, and a -r link, which brintld # only combines, keeps the old default too. # # -static on a final link is the same self-contained image, whatever the # environment holds: libc and every library are linked in, nothing is # imported, and no libc.so is named. The command line wins over the knobs, as # an explicit flag wins over a default with gcc; the guest's environment and # the layer's dynamic-libc class set the knobs for every link, so they are # defaults, not the caller's choice. --static is the same flag. A -shared or # -r line keeps its own form, and a line that links nothing is left alone. # The flags read here are the compiler driver's: on an ld line -E, -S, -M and # -c mean other things, so an ld -static line carrying one keeps its defaults, # and ld's other spellings (-Bstatic, -dn, -non_shared) are not read. # # The channel is read as config.sh sets it: on unless the caller says # HWJS_STATUS_CHANNEL=0 or BRINTIUM_NO_CORO=1. The C driver runs after # config.sh, and the guest ld wrapper before it (bin/brintld sources it), so # both see the channel the link will have. brintium_line_is_static_link() { local _lf_a _lf_static=1 for _lf_a in "$@"; do case "$_lf_a" in -static|--static) _lf_static=0 ;; -c|-E|-S|-M|-MM|-fsyntax-only|--version|-dump*|-print-*|--print-*|-shared|--shared|-r|--relocatable) return 1 ;; esac done [ "$_lf_static" = 0 ] || return 1 # A line with no input is a query (line-kind.sh), where the drivers source it. if type brintium_line_is_query > /dev/null 2>&1 && brintium_line_is_query "$@"; then return 1; fi return 0 } brintium_dynamic_defaults() { local _lf_a _lf_main=1 _lf_sc="${HWJS_STATUS_CHANNEL-}" if brintium_line_is_static_link "$@"; then export WASMLD_LIBC_IMPORT=0 WASMLD_RT_IMPORT=0 WASMLD_DYNAMIC_MAIN=0 WASMLD_DYNAMIC_MODULE=0 unset WASMLD_LIBC_SO_PATH WASMLD_HWJS_XMOD_SUSPENDERS return 0 fi if [ -z "$_lf_sc" ]; then if [ "${BRINTIUM_NO_CORO:-0}" = 1 ]; then _lf_sc=0; else _lf_sc=1; fi fi if [ "$_lf_sc" = 1 ] && [ "${WASMLD_LIBC_IMPORT-}" = 0 ] \ && [ -z "${WASMLD_DYNAMIC_MAIN-}" ] && [ -z "${WASMLD_DYNAMIC_MODULE-}" ]; then _lf_main=0 for _lf_a in "$@"; do case "$_lf_a" in -shared|--shared|-r|--relocatable) _lf_main=1 ;; esac done fi export WASMLD_DYNAMIC_MAIN="${WASMLD_DYNAMIC_MAIN:-$_lf_main}" export WASMLD_DYNAMIC_MODULE="${WASMLD_DYNAMIC_MODULE:-$_lf_main}" }