Skip to content

Commit

Permalink
remove SHOPT_REGRESS (re: 506bd2b); tweak build system
Browse files Browse the repository at this point in the history
SHOPT_REGRESS is the ksh compile-time option that enables
instrumented intercepts of system calls and the like. It was an
experiment that was quietly added in 93t+ 2009-04-15 and then
apparently forgotten about, as no change was ever made after that.

By 93u+ 2012-08-01 (which we forked), enabling it was crashing the
shell, which was fixed in commit 506bd2b, but it still doesn't
really work consistently: in my experiments with the associated
ksh-regress.rt regression tests, I noticed that the output varies
based on (a) the operating system, and (b) the presence of profile
scripts such as /etc/ksh.kshrc on the system. No one has time to
look into this further, so this commit removes that dead weight.

____
This commit also makes related tweaks to the build system:

The statically linked shell was crashing after removing regress.c,
because regress.o with its intercepts was still present in
libshell.a. To avoid similar in future, the code to link a static
library (currently repeated in five Mamfiles) is consolidated into
a new MAM include file, src/cmd/INIT/include/link_ar.mam, and
extended with code to remove object files whose sources are no
longer part of the code base. In addition, the 'ar' command usage
is updated to conform with the POSIX standard (options start with
a '-'), and the obsolete `ranlib` invocation is removed.

In mamake, the 'incl' command (added in 2757793) no longer
saves/clears and restores the automatic variables, as we need them
to work normally for link_ar.mam. They are now once again saved and
restored only when the 'bind' command includes a file.
  • Loading branch information
McDutchie committed Dec 3, 2024
1 parent 45a1538 commit 57f51b6
Show file tree
Hide file tree
Showing 22 changed files with 90 additions and 23,144 deletions.
18 changes: 16 additions & 2 deletions src/cmd/INIT/README-mamake.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ the language to facilitate human maintenance of the `Mamfile`s.
* [...while scanning and sorting leaf directories](#user-content-while-scanning-and-sorting-leaf-directories)
* [...while building the current directory](#user-content-while-building-the-current-directory)
* [Repeatedly iterating through a block](#user-content-repeatedly-iterating-through-a-block)
* [Including a MAM file](#user-content-including-a-mam-file)
* [Provided include files](#user-content-provided-include-files)
* [Parallel processing](#user-content-parallel-processing)
* [Debugging mamake](#user-content-debugging-mamake)
* [Appendix: Main changes from the AT&T version](#user-content-appendix-main-changes-from-the-att-version)
Expand Down Expand Up @@ -502,8 +504,20 @@ iteration *variable*.
`incl` *filename*

The `incl` command reads a file with MAM commands from *filename* as if
those commands had appeared in place of the `incl` command, except that the
automatic variables are saved before and restored after reading.
those commands had appeared in place of the `incl` command.
If *filename* does not contain a `/`, mamake will look for the file in the
current directory first, then in `%{PACKAGEROOT}/src/cmd/INIT/include`.

#### Provided include files ####

The following are provided in `%{PACKAGEROOT}/src/cmd/INIT/include`:

* `link_ar.mam`: A shell action (see `exec` above) for linking a static
library archive (`lib`*name*`.a`) based on the contents of the automatic
variables, for including at the end of a `make lib`*name*`.a`...`done`
rule. All the child rules are expected to be `*.o` object files. The
action also deletes object files that no longer have a matching source
from the archive.

## Parallel processing ##

Expand Down
34 changes: 34 additions & 0 deletions src/cmd/INIT/include/link_ar.mam
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
note * Shell action for linking an archive (static library) from previously
note * compiled object files, based on the current MAM automatic variables.
note *
note * - %{@} - name of archive (like libfoo.a)
note * - %{^} - all the *.o files
note * - %{?} - the *.o files that changed in this run
note *
note * This code avoids rebuilding the archive from scratch on each run,
note * updating only the object files that have changed.

exec - if test -f %{@}
exec - then ar -r -c %{@} %{?} # add changed *.o
exec - else ar -r -c %{@} %{^} # add all *.o
exec - fi || exit

note * Sometimes, obsolete object files can interfere due to intercepts, so
note * delete any old object files that we no longer build from the archive

exec - to_delete=
exec - for o in $(ar -t %{@})
exec - do case $o in
exec - *.o) case ' %{^} ' in
exec - *" $o "*)
exec - ;;
exec - *) to_delete="${to_delete-} $o"
exec - ;;
exec - esac
exec - ;;
exec - esac
exec - done
exec - case ${to_delete:+y} in
exec - y) ar -d %{@} $to_delete
exec - ;;
exec - esac
39 changes: 26 additions & 13 deletions src/cmd/INIT/mamake.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
* coded for portability
*/

#define RELEASE_DATE "2024-11-26"
#define RELEASE_DATE "2024-12-03"
static char id[] = "\n@(#)$Id: mamake (ksh 93u+m) " RELEASE_DATE " $\0\n";

#if _PACKAGE_ast
Expand Down Expand Up @@ -1767,21 +1767,12 @@ static int include(Rule_t *r, Makestate_t *stp, char *file, int pushflags)
int rv;
if (rv = push(file, NULL, pushflags))
{
/* save automatic variables */
char *s1 = auto_prev->value, *s2 = auto_allprev->value, *s3 = auto_updprev->value;
auto_prev->value = auto_allprev->value = auto_updprev->value = empty;
/* read the file */
report(-1, file, "include", NULL);
state.indent++;
make(r, stp);
state.indent--;
report(-1, file, "end of", NULL);
pop();
/* restore automatic variables */
if (auto_prev->value != empty)
free(auto_prev->value);
if (auto_allprev->value != empty)
free(auto_allprev->value);
if (auto_updprev->value != empty)
free(auto_updprev->value);
auto_prev->value = s1, auto_allprev->value = s2, auto_updprev->value = s3;
}
return rv;
}
Expand Down Expand Up @@ -2167,6 +2158,7 @@ static void make(Rule_t *r, Makestate_t *parentstate)
}
if (s = require(t, !strcmp(v, "dontcare")))
{
char *s1, *s2, *s3;
char *libname = t + 2;
/*
* bind to the *.a files that require() just derived from $INSTALLROOT/lib/lib/NAME
Expand Down Expand Up @@ -2216,10 +2208,22 @@ static void make(Rule_t *r, Makestate_t *parentstate)
continue;
}
/* otherwise, include the rules file if it exists */
/* save automatic variables */
s1 = auto_prev->value, s2 = auto_allprev->value, s3 = auto_updprev->value;
auto_prev->value = auto_allprev->value = auto_updprev->value = empty;
/* read the file */
append(buf, state.installroot);
append(buf, "/lib/mam/");
append(buf, libname);
include(r, &st, use(buf), 0);
/* restore automatic variables */
if (auto_prev->value != empty)
free(auto_prev->value);
if (auto_allprev->value != empty)
free(auto_allprev->value);
if (auto_updprev->value != empty)
free(auto_updprev->value);
auto_prev->value = s1, auto_allprev->value = s2, auto_updprev->value = s3;
}
continue;

Expand Down Expand Up @@ -2307,6 +2311,15 @@ static void make(Rule_t *r, Makestate_t *parentstate)
case KEY('i','n','c','l'):
if (!*t || *v)
error_out("syntax error", u);
if (!strchr(t,'/'))
{
if (include(r, &st, t, 0))
continue;
append(buf, state.packageroot);
append(buf, "/src/cmd/INIT/include/");
append(buf, t);
t = use(buf);
}
include(r, &st, t, STREAM_MUST);
continue;

Expand Down
24 changes: 2 additions & 22 deletions src/cmd/ksh93/Mamfile
Original file line number Diff line number Diff line change
Expand Up @@ -223,14 +223,10 @@ make install virtual
prev %{INCLUDE_AST}/option.h
done

make include/regress.h
done

make include/argnod.h
done

make include/defs.h
prev include/regress.h
prev include/shtable.h
prev include/shell.h
prev %{INCLUDE_AST}/endian.h
Expand Down Expand Up @@ -657,16 +653,6 @@ make install virtual
prev shopt.h
done

make bltins/regress.c
prev %{INCLUDE_AST}/tmx.h
prev include/builtins.h
prev include/io.h
prev %{INCLUDE_AST}/ls.h
prev %{INCLUDE_AST}/error.h
prev include/defs.h
prev shopt.h
done

make sh/fault.c
prev include/ulimit.h
prev include/builtins.h
Expand Down Expand Up @@ -1070,14 +1056,8 @@ make install virtual
exec - %{compile} %{<}
done

note *
note * Link the library
note *
exec - if test -f %{@}
exec - then %{AR} rc %{@} %{?} # add changed *.o
exec - else %{AR} rc %{@} %{^} # add all *.o
exec - fi || exit
exec - ranlib %{@} >/dev/null 2>&1 || true
note * include shell action for linking the library
incl link_ar.mam

note * save for dylink
setv _libshell_object_files_ %{^}
Expand Down
3 changes: 0 additions & 3 deletions src/cmd/ksh93/README
Original file line number Diff line number Diff line change
Expand Up @@ -128,9 +128,6 @@ The options have the following defaults and meanings:
P_SUID 0 If set, all real UIDs greater than or equal to this value
will require the -p option to run the shell setuid/setgid.

REGRESS off Enable the __regress__ built-in command and instrumented
intercepts for testing.

REMOTE off Set --rc (read profile scripts) even if ksh was invoked
with standard input on a socket, i.e. as a remote shell.

Expand Down
1 change: 0 additions & 1 deletion src/cmd/ksh93/SHOPT.sh
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ SHOPT NOECHOE=0 # turn off 'echo -e' when SHOPT_ECHOPRINT is disabled
SHOPT OPTIMIZE=1 # optimize loop invariants
SHOPT P_SUID=0 # real UIDs >= this value require -p for set[ug]id (to turn off, use empty, not 0)
SHOPT PRINTF_LEGACY= # allow noncompliant printf(1) syntax (format arg starting with '-' without prior '--')
SHOPT REGRESS= # enable __regress__ builtin and instrumented intercepts for testing
SHOPT REMOTE= # enable --rc if running as a remote shell
SHOPT SCRIPTONLY=0 # build ksh for running scripts only; compile out the interactive shell
SHOPT SPAWN= # use spawnveg for fork/exec
Expand Down
Loading

0 comments on commit 57f51b6

Please sign in to comment.