Skip to content

Commit a25a3c9

Browse files
committed
INIT: mkreq: eliminate error message scanning hack
This resolves a TODO by removing the clever AT&T hack to scan for an error message containing an arbitrary library name, which was evidently a workaround for compilers that exit with status 0 (success) on error. I'm pretty sure that in 2026 it's safe to assume that compilers exit with a nonzero exit status on error. But even if there is still a compiler that exits with status 0 on error, we now attempt to actually run the test binary. This should catch any failure to compile/link that wasn't caught by the exit status check, provided we delete any previous test binary first.
1 parent 606ca5a commit a25a3c9

1 file changed

Lines changed: 5 additions & 14 deletions

File tree

src/cmd/INIT/mkreq.sh

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# #
33
# This file is part of the ksh 93u+m package #
44
# Copyright (c) 1984-2012 AT&T Intellectual Property #
5-
# Copyright (c) 2020-2024 Contributors to ksh 93u+m #
5+
# Copyright (c) 2020-2026 Contributors to ksh 93u+m #
66
# and is licensed under the #
77
# Eclipse Public License, Version 2.0 #
88
# #
@@ -49,26 +49,17 @@ shift
4949
# Setup.
5050
trap 'set +o noglob; rm -rf mkreq.$$.*' 0
5151
echo 'int main(void) { return 0; }' > mkreq.$$.c
52-
53-
# Clever hack alert: obtain error message for library not found by trying to
54-
# link to a library called '*'; the * is presumed repeated in the error message
55-
# and thus serves as a wildcard for 'case' in try_to_link. This is evidently
56-
# a workaround for compilers that exit with status 0 (success) on error.
57-
# TODO: in 2023, is that still a thing at all?
5852
$allcc -c mkreq.$$.c || exit
59-
error_msg=$($allcc $ldflags -o mkreq.$$.x mkreq.$$.o -l'*' 2>&1 | sed -e 's/[][()+@?]/#/g')
6053

6154
# Function: try to link the test program with possible extra linker flags.
6255
try_to_link()
6356
{
6457
_lib=$1
6558
shift
66-
_out=$( { $allcc ${1+"$@"} $ldflags -o mkreq.$$.x mkreq.$$.o -l${_lib} 2>&1 || echo '' "$error_msg"
67-
} | sed -e 's/[][()+@?]/#/g')
68-
case ${_out} in
69-
*$error_msg*)
70-
return 1 ;;
71-
esac
59+
# Delete any previous test binary (including any OS-specific extra files).
60+
test -e mkreq.$$.x && (set +o noglob; rm -rf mkreq.$$.x*)
61+
# Try to link.
62+
$allcc ${1+"$@"} $ldflags -o mkreq.$$.x mkreq.$$.o -l${_lib} 2>/dev/null || return
7263
# To work around possible linker breakage, we have to
7364
# actually run the test program, not merely link it.
7465
./mkreq.$$.x

0 commit comments

Comments
 (0)