From 9ce426a8c418e54cbda9dc33df64db7039f45d8e Mon Sep 17 00:00:00 2001 From: Martijn Dekker Date: Sat, 9 Jul 2022 05:21:37 +0200 Subject: [PATCH] Disable SHOPT_DYNAMIC by default Dynamically loadable built-ins do not work well with a statically linked ksh; they cannot use ksh's statically linked copies of libast and libshell, so they would need to bring their own, but multiple copies of those don't play well together. So dynamically loaded built-ins cannot interface with the shell. Only non-AST, non-SFIO built-ins are possible. Which is something that perhaps five people in the world know how to do as this is not documented anywhere (hint: your built-in needs the BLT_NOSFIO attribute to use stdio without problems). And those five people are also able to compile their own ksh with SHOPT_DYNAMIC reenabled. Plus, the SHOPT_DYNAMIC code causes strange $PATH search regressions on a few systems. The cause of that bug has eluded me so far, but disabling this is effectively a fix on those systems. src/cmd/ksh93/SHOPT.sh: - Turn off SHOPT_DYNAMIC by default. src/cmd/ksh93/data/builtins.c: - Do not compile in irrelevant sh_optbuiltin[] (builtin --man) documentation if SHOPT_DYNAMIC is disabled. --- src/cmd/ksh93/README | 3 ++- src/cmd/ksh93/SHOPT.sh | 2 +- src/cmd/ksh93/data/builtins.c | 18 ++++++++++++------ 3 files changed, 15 insertions(+), 8 deletions(-) diff --git a/src/cmd/ksh93/README b/src/cmd/ksh93/README index 567fbb86e..8ac8e10f5 100644 --- a/src/cmd/ksh93/README +++ b/src/cmd/ksh93/README @@ -59,7 +59,8 @@ The options have the following defaults and meanings: DEVFD Use the more secure /dev/fd mechanism instead of FIFOs for process substitutions. On by default on OSs with /dev/fd. - DYNAMIC on Dynamic loading of builtins. (Requires dlopen() interface.) + DYNAMIC off Dynamic loading of builtins. Requires dlopen() interface + and dynamic libshell, libdll and libast libraries. ECHOPRINT off Make echo equivalent to print. diff --git a/src/cmd/ksh93/SHOPT.sh b/src/cmd/ksh93/SHOPT.sh index 1380de49c..e0cb0a8b2 100644 --- a/src/cmd/ksh93/SHOPT.sh +++ b/src/cmd/ksh93/SHOPT.sh @@ -15,7 +15,7 @@ SHOPT CMDLIB_HDR= # '' # custom -lcmd list for path-bound builtins SHOPT CMDLIB_DIR= # '"/opt/ast/bin"' # virtual directory prefix for path-bound builtins SHOPT CRNL= # accept MS Windows newlines () for SHOPT DEVFD= # use /dev/fd instead of FIFOs for process substitutions -SHOPT DYNAMIC=1 # dynamic loading for builtins +SHOPT DYNAMIC=0 # dynamic loading for builtins SHOPT ECHOPRINT= # make echo equivalent to print SHOPT EDPREDICT=0 # History pattern search menu (type #, then ESC TAB). Experimental. SHOPT ESH=1 # emacs/gmacs edit mode diff --git a/src/cmd/ksh93/data/builtins.c b/src/cmd/ksh93/data/builtins.c index 1db58a843..ac175f0b9 100644 --- a/src/cmd/ksh93/data/builtins.c +++ b/src/cmd/ksh93/data/builtins.c @@ -397,7 +397,7 @@ const char sh_optalias[] = ; const char sh_optbuiltin[] = -"[-1c?\n@(#)$Id: builtin (AT&T Research) 2010-08-04 $\n]" +"[-1c?\n@(#)$Id: builtin (ksh 93u+m) 2022-07-03 $\n]" "[--catalog?" SH_DICT "]" "[+NAME?builtin - add, delete, or display shell built-ins]" "[+DESCRIPTION?\bbuiltin\b can be used to add, delete, or display " @@ -418,6 +418,7 @@ const char sh_optbuiltin[] = "the current list of built-ins, or just the special built-ins if \b-s\b " "is specified, on standard output. The full pathname for built-ins that " "are bound to pathnames are displayed.]" +#if SHOPT_DYNAMIC "[+?Libraries containing built-ins can be specified with the \b-f\b " "option. If the library contains a function named \blib_init\b(), this " "function will be invoked with argument \b0\b when the library is " @@ -426,20 +427,25 @@ const char sh_optbuiltin[] = "the C level function name.]" "[+?The C level function will be invoked with three arguments. The first " "two are the same as \bmain\b() and the third one is a pointer.]" +#endif /* SHOPT_DYNAMIC */ "[+?\bbuiltin\b cannot be invoked from a restricted shell.]" "[d?Deletes each of the specified built-ins. Special built-ins cannot be " "deleted.]" -"[f]:[lib?On systems with dynamic linking, \alib\a names a shared " - "library to load and search for built-ins. Libraries are searched for " - "in \b../lib/ksh\b and \b../lib\b on \b$PATH\b and in system dependent " - "library directories. The system " - "dependent shared library prefix and/or suffix may be omitted. Once a " +#if SHOPT_DYNAMIC +"[f]:[lib?\alib\a names a shared library to load and search for built-ins. " + "Libraries are searched for in \b../lib/ksh\b and \b../lib\b on \b$PATH\b " + "and in system-dependent library directories. The system-dependent " + "shared library prefix and/or suffix may be omitted. Once a " "library is loaded, its symbols become available for the current and " "subsequent invocations of \bbuiltin\b. Multiple libraries can be " "specified with separate invocations of \bbuiltin\b. Libraries are " "searched in the reverse order in which they are specified.]" "[l?List the library base name, plugin YYYYMMDD version stamp, and full " "path for \b-f\b\alib\a on one line on the standard output.]" +#else +"[f]:[lib?Not supported.]" +"[l?No effect.]" +#endif /* SHOPT_DYNAMIC */ "[s?Display only the special built-ins.]" "\n" "\n[pathname ...]\n"