Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This commit re-adds support for building a dynamically linked ksh with libast, libdll, libcmd, and libshell available as dynamic libraries for other applications to use. Previously, this required nmake; as of this commit, we use a helper script dylink.sh instead, which does all the necessary platform-specific things and can be easily extended to add support for new platforms. Currently tested and supported platforms are Linux, Android, macOS, FreeBSD, NetBSD, OpenBSD, and illumos/Solaris. Summary of important changes: src/cmd/ksh93/SHOPT.sh: - Enable SHOPT_DYNAMIC by default. This enables the '-f' option to the 'builtin' command, making it possible to load builtins from dynamic/shared libraries. This mostly makes sense for a dynamically linked ksh, as that is needed to allow ksh and builtins to share the same libraries such as libast. src/cmd/INIT/dylink.sh: - Added. This is a dynamic linking tool to invoke from Mamfiles. - Disable dynamic libraries if AST_NO_DYLIB is exported. - Disable dynamic libraries on untested systems unless AST_DYLIB_TEST is exported. bin/package: - Add support for $INSTALLROOT/dyn subdirectory. - Set LD_LIBRARY_PATH, etc. to point to dyn/lib. - Prefix dyn/bin to $PATH. - do_install(): - Prefer dynamically linked versions for installing, if they have been built. - If dyn/lib exists, install not only the dynamic libraries but also the dev stuff: AST headers and section 3 manual pages. - Remove generation of .paths file. It causes regression test failures because of how built-ins are bound to different paths when found via a .paths file. This functionality is deprecated and may be removed from ksh 93u+m/1.1 and up. bin/shtests: - Relaunch self via 'bin/package use' to pull in the necessary environment stuff to make the pre-installed dynamically linked binaries work. src/cmd/INIT/make.probe: - Add probe for the --as-needed and --no-as-needed linker options. To make dynamic libraries work on Linux arm64, we need to pass --no-as-needed to the linker on Linux to avoid glibc interfering with libast in identically named functions like AST regcomp(3). Linux systems vary as to whether --as-needed is on by default. Thanks to Lukáš Zaoral at Red Hat for finding the key to the fix. src/cmd/INIT/mamprobe.sh: - Update version number. This change causes mamake to redo the probe (it checks for a change in mamprobe but not in make.probe; I should probably fix that at some point). We need mamake to redo the probe for the --no-as-needed addition to take effect. **/Mamfile: - Use the --no-as-needed probe result (either -Wl,-no-as-needed or empty) from ${mam_cc_LD_NOASNEEDED} whenever linking anything; add it to LDFLAGS before invoking dylink. - ksh and shcomp also need the results of the existing --export-dynamic probe; this option is needed on Linux as without it ksh fails to export symbols to loadable builtins. See: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=821806 Thanks to Johnothan King. src/lib/libast/features/map.c, src/lib/libast/regex/regexec.c, src/lib/libast/regex/regnexec.c, src/lib/libast/regex/regrexec.c, src/lib/libast/regex/regsubexec.c: - Map regcomp and all the other AST regex functions via macros so they get an _ast_ prefix. This allows a functional dynamically linked executable to exist under ASan because the regcomp function gets overriden by ASan, despite linking with --no-as-needed. Thanks to Johnothan King. src/lib/libast/comp/errno.c: - Make one trivial change (copyright year) to force libast to relink -- which then triggers a relink of everything else. Co-authored-by: Johnothan King <[email protected]> Co-authored-by: Lukáš Zaoral <[email protected]>
- Loading branch information