64-bit transition part 13: the rest of ksh93 (#973)
This is the thirteenth of the thickfold patch series, which enables ksh93 to operate within a 64-bit address space.
This patch applies the rest of the changes to ksh93 necessary for 64-bit memory allocation, along with the usual warning fixes.
Notable changes:
- parse.c: Fixed a build error when using SHOPT_KIA (re: 63366e34).
- sh_pipe(): Fix broken SOCK_CLOEXEC check. The !SOCK_CLOEXEC check in the #if directive apparently didn’t work[*], as strace was showing unnecessary fcntl calls were still getting compiled in. Check for SOCK_CLOEXEC==0 in a non-preprocessor if statement and let the compiler optimize it away, which actually works correctly.
- Also removed some unnecessary ptrdiff_t casts.
- Add a (Linux-specific) regression test for allocating 5GB (we check if plenty of RAM is available via /proc/meminfo).
- locale.sh: Disable a test that requires SHOPT_MULTIBYTE to work correctly.
Change in the number of warnings on Linux when compiling with clang using -Wsign-compare -Wshorten-64-to-32 -Wsign-conversion -Wimplicit-int-conversion: 352 => 37 (progression from part 12 => part 13)
The nvflags warnings that remain will be addressed in a separate follow-up patch of their own (which doesn’t affect memory allocation).
Resolves: https://github.com/ksh93/ksh/issues/592
[] (Martijn adds) On Linux, the SOCK_ macros defined in /usr/include/bits/socket_type.h are bizarrely defined as their own names (which refer to members of an enum type), which kills the #if logic in the preprocessor. This could be an issue with other macros on other systems too, so it’s something to look out for in future.
版权所有:中国计算机学会技术支持:开源发展技术委员会
京ICP备13000930号-9
京公网安备 11010802032778号
KornShell 93u+m
Welcome to the repository where the KornShell is under active development. This is where we develop bugfixes and new features for the shell, and where users can download the latest releases or the current development version in source code form. The project started off from last stable release (93u+ 2012-08-01) of ksh93, formerly developed by AT&T Software Technology (AST). The sources in this repository were forked from the GitHub AST repository which is no longer under active development.
For user-visible fixes, see NEWS and click on commit messages for full details. For all fixes, see the commit log. To see what’s left to fix, see the issue tracker.
Table of contents
Policy
posixmode only to avoid breaking legacy scripts./*…*/.Why?
Between 2017 and 2020 there was an ultimately unsuccessful attempt to breathe new life into the KornShell by extensively refactoring the last unstable AST beta version (93v-). While that ksh2020 effort is now abandoned and still has many critical bugs, it also had a lot of bugs fixed. More importantly, the AST issue tracker now contains a lot of documentation on how to fix those bugs, which made it possible to backport many of them to the last stable release instead. This ksh 93u+m reboot now incorporates many of these bugfixes, plus patches from OpenSUSE, Red Hat, and Solaris, as well as many new fixes from the community (1, 2). Though there are many bugs left to fix, we are confident at this point that 93u+m is already the least buggy version of ksh93 ever released. As of late 2021, distributions such as Debian and Slackware have begun to package it as their default version of ksh93.
Installing from source
You can download a release tarball, or clone the current code from your preferred branch. New features for the future release series are developed on the
devbranch. Stable releases are currently based on the1.0branch.Supported systems
KornShell 93u+m is currently known to build and run on:
Systems that may work, but that we have not been able to test lately, include:
KornShell 93u+m supports systems that use the ASCII character set as the lowest common denominator. This includes Linux on IBM zSeries, but not z/OS. Support for the EBCDIC character set has been removed, as we do not have access to a mainframe with z/OS to test and maintain it.
Prepare
The build system requires only a basic POSIX-compatible shell, utilities and compiler environment. The
cc,arandgetconfcommands are needed at build time. Thetputandgetconfcommands are used at runtime if available (for multiline editing and to complete thegetconfbuilt-in, respectively). Not all systems come with all of these preinstalled. Here are system-specific instructions for making them available:pkg install.clang,binutils,getconfncurses-utils,getconfxcode-select --installBuild
To build ksh with a custom configuration of features, edit
src/cmd/ksh93/SHOPT.sh.On systems such as NetBSD and OpenBSD, where
/bin/kshis not ksh93 and the preinstalled/etc/ksh.kshrcprofile script is incompatible with ksh93, you’ll want to disableSHOPT_SYSRCto avoid loading it on startup – unless you can edit it to make it compatible with ksh93. This generally involves differences in the declaration and usage of local variables in functions.Then
cdto the top directory and run:To suppress compiler output, use
quiet makeinstead ofmake.In some non-POSIX shells you might need to prepend
shto all calls tobin/package.Parallel building is supported by appending
-jfollowed by the desired maximum number of concurrent jobs, e.g.,bin/package make -j4. This speeds up building on systems with more than one CPU core. (Typebin/package host cputo find out how many CPU cores your system has.)The compiled binaries are stored in the
archdirectory, in a subdirectory that corresponds to your architecture. The commandbin/package host typeoutputs the name of this subdirectory.Dynamically linked binaries, if supported for your system, are stored in
dyn/binanddyn/libsubdirectories of your architecture directory. If built, they are built in addition to the statically linked versions. ExportAST_NO_DYLIBto deactivate building dynamically linked versions.If you have trouble or want to tune the binaries, you may pass additional compiler and linker flags. It is usually best to export these as environment variables before running
bin/packageas they could change the name of the build subdirectory of thearchdirectory, so exporting them is a convenient way to keep them consistent between build and test commands. Note that this system usesCCFLAGSinstead of the usualCFLAGS. An example that makes Solaris Studio cc produce a 64-bit binary:Alternatively you can append these to the command, and they will only be used for that command. You can also specify an alternative shell in which to run the build scripts this way. For example:
Note: Do not add compiler flags that cause the compiler to emit terminal escape codes, such as
-fdiagnostics-color=always; this will cause the build to fail as the probing code greps compiler diagnostics. Additionally, do not add the-ffast-mathcompiler flag; arithmetic bugs will occur when using that flag.For more information run
Many other commands in this repo self-document via the
--help,--manand--htmloptions; those that do have no separate manual page.Test
After compiling, you can run the regression tests. To run the default test sets for ksh and the build system, use:
For ksh, use the
shtestscommand directly to control the regression test runs. Start by reading the information printed by:To hand-test ksh (as well as the utilities and the autoloadable functions that come with it) without installing, run:
Install
Usage:
bin/package installinstall_root_directory [ command … ]Any command from the
archdirectory can be installed. If no command is specified,kshandshcompare assumed.The install_root_directory is the directory from which the command(s) will actually be run. It will be created if it does not exist. Commands are installed into its
binsubdirectory, any shared libraries intolib, C development header files intoinclude/ast, and each command’s manual page, if available, is installed intoshare/man.If a dynamically linked version of ksh and associated commands has been built, then the
installsubcommand will prefer that: commands, dynamic libraries and associated header files will be installed then. To install the statically linked version instead (and skip the header files), either delete thedynsubdirectory, or exportAST_NO_DYLIB=ybefore building to prevent it from being created in the first place.An additional install prefix directory path can be passed in
DESTDIR, which can be either passed as an environment variable or specified on the comannd line as an extra assignment-like argument. The value ofDESTDIRwill be prefixed to the path of every destination file when installing it, but not when configuring the install root directory in the installed files (as may be required by individual systems, e.g., to find dynamic libraries). This feature is designed for packagers who need to install ksh into a directory other than the one from which it will be run in order to package it.What is ksh93?
The following is the official AT&T description from 1993 that came with the ast-open distribution. The text is original, but hyperlinks were added here.
KSH-93 is the most recent version of the KornShell Language described in “The KornShell Command and Programming Language,” by Morris Bolsky and David Korn of AT&T Bell Laboratories, ISBN 0-13-182700-6. The KornShell is a shell programming language, which is upward compatible with “sh” (the Bourne Shell), and is intended to conform to the IEEE P1003.2/ISO 9945.2 Shell and Utilities standard. KSH-93 provides an enhanced programming environment in addition to the major command-entry features of the BSD shell “csh”. With KSH-93, medium-sized programming tasks can be performed at shell-level without a significant loss in performance. In addition, “sh” scripts can be run on KSH-93 without modification.
The code should conform to the IEEE POSIX 1003.1 standard and to the proposed ANSI C standard so that it should be portable to all such systems. Like the previous version, KSH-88, it is designed to accept eight bit character sets transparently, thereby making it internationally compatible. It can support multi-byte characters sets with some characteristics of the character set given at run time.
KSH-93 provides the following features, many of which were also inherent in KSH-88:
Documentation for KSH-93 consists of an “Introduction to KSH-93”, “Compatibility with the Bourne Shell” and a manual page and a README file. In addition, the “New KornShell Command and Programming Language” book is available from Prentice Hall.