mirror of
git://git.code.sf.net/p/cdesktopenv/code
synced 2025-03-09 15:50:02 +00:00
libast: fix memccpy(3) feature test
If you passed CC=/some/compiler, the build broke on macOS because the cc.darwin compiler wrapper wasn't used. Among other things, this wrapper adds a -D_lib_memccpy flag, defining _lib_memccpy as 1 during the build. That was used to override a false negative result of the lib_memccpy feature test. This commit fixes that feature test instead, so it correctly returns positive on macOS. Thanks to Ryan Smith (@ryandesign) for the bug report and for the fix to the lib_memccpy test. src/lib/libast/features/lib: - Fix the lib_memccpy feature test. It was checking the result of mmap(2) incorrectly, resulting in the test crashing on macOS. Failure does not return NULL, it returns MAP_FAILED which is usually -1. src/cmd/INIT/cc.darwin*: - Removed. Any other flags in these wrappers are either related to building dynamic libraries, which is not currently supported, or were determined to be unnecessary. See the GitHub issue for discussion. This now makes it possible to pass `CC` to use any compiler you like on the Mac. Notes: - Apple's -D_ast_int8_t=int64_t is a no-op; another AST feature test already defines _ast_int8_t a 64-bit integer type, even on 32-bit systems (on which it is defined as 'long long'). - The -search_paths_first linker flag is the default since 2010. But even on my museum-grade Power Mac G5 with Mac OS X 10.3 (from 2004), it builds and runs just fine without. - DCLK_TCK=100 is a no-op as even that ancient Mac system already defines it as 100. Plus, it's not even actually used. If a need is found for any of these, please report this in a new issue so I can special-case it elsewhere in the code. Resolves: https://github.com/ksh93/ksh/issues/373
This commit is contained in:
parent
65feb9641a
commit
0eb857041d
4 changed files with 6 additions and 197 deletions
|
@ -1,52 +0,0 @@
|
|||
: unix wrapper for macOS cc : 2020-07-17 :
|
||||
|
||||
HOSTTYPE=darwin.generic
|
||||
|
||||
case " $* " in
|
||||
*" -dumpmachine "*) echo $HOSTTYPE; exit ;;
|
||||
esac
|
||||
|
||||
CC=/usr/bin/cc
|
||||
op=init
|
||||
for arg
|
||||
do case $op in
|
||||
init) op=ld
|
||||
set ''
|
||||
;;
|
||||
esac
|
||||
case $arg in
|
||||
-c) op=cc
|
||||
;;
|
||||
-E) op=cpp
|
||||
continue
|
||||
;;
|
||||
-G) op=dll
|
||||
continue
|
||||
;;
|
||||
-lc) continue
|
||||
;;
|
||||
-lm) continue
|
||||
;;
|
||||
esac
|
||||
set "$@" "$arg"
|
||||
done
|
||||
case $# in
|
||||
0) ;;
|
||||
*) shift ;;
|
||||
esac
|
||||
case $* in
|
||||
-v) $CC "$@"; exit ;;
|
||||
esac
|
||||
case $op in
|
||||
init) echo "cc: arguments expected" >&2
|
||||
exit 1
|
||||
;;
|
||||
cpp) $CC -E "$@"
|
||||
;;
|
||||
cc) $CC -D_ast_int8_t=int64_t -D_lib_memccpy "$@"
|
||||
;;
|
||||
dll) $CC -Wl,-flat_namespace -dynamiclib -undefined dynamic_lookup "$@"
|
||||
;;
|
||||
ld) $CC -Wl,-search_paths_first "$@"
|
||||
;;
|
||||
esac
|
|
@ -1,71 +0,0 @@
|
|||
: unix wrapper for Mac OS X 10.3-10.6 (Darwin 7-10) cc : 2020-07-17 :
|
||||
|
||||
HOSTTYPE=darwin07.generic
|
||||
|
||||
case " $* " in
|
||||
*" -dumpmachine "*) echo $HOSTTYPE; exit ;;
|
||||
esac
|
||||
|
||||
CC=/usr/bin/cc
|
||||
op=init
|
||||
for arg
|
||||
do case $op in
|
||||
init) op=ld
|
||||
set ''
|
||||
;;
|
||||
esac
|
||||
case $arg in
|
||||
-c) op=cc
|
||||
;;
|
||||
-E) op=cpp
|
||||
continue
|
||||
;;
|
||||
-G) op=dll
|
||||
continue
|
||||
;;
|
||||
-lc) continue
|
||||
;;
|
||||
-lm) continue
|
||||
;;
|
||||
esac
|
||||
set "$@" "$arg"
|
||||
done
|
||||
case $# in
|
||||
0) ;;
|
||||
*) shift ;;
|
||||
esac
|
||||
case $* in
|
||||
-v) $CC "$@"; exit ;;
|
||||
esac
|
||||
case $op in
|
||||
init) echo "cc: arguments expected" >&2
|
||||
exit 1
|
||||
;;
|
||||
cpp) $CC -E "$@"
|
||||
;;
|
||||
cc) $CC -DCLK_TCK=100 "$@"
|
||||
;;
|
||||
dll) # what a compatibility mess -- surely they can get the apis to play nice
|
||||
tmp=/tmp/cc.${USER:-$LOGNAME}.$$.err
|
||||
trap "rm -f $tmp" EXIT
|
||||
case `MACOSX_DEPLOYMENT_TARGET=10.3 ld -undefined dynamic_lookup 2>&1` in
|
||||
*undefined*dynamic_lookup*)
|
||||
ld -m -flat_namespace -undefined suppress -dylib -dynamic \
|
||||
-ldylib1.o "$@" -lcc_dynamic -framework System >$tmp 2>&1
|
||||
status=$?
|
||||
;;
|
||||
*) MACOSX_DEPLOYMENT_TARGET=10.3 $CC -Wl,-flat_namespace -dynamiclib -undefined dynamic_lookup "$@" >$tmp 2>&1
|
||||
status=$?
|
||||
;;
|
||||
esac
|
||||
egrep -v ' (warning .*multiple definitions|definition) of ' $tmp >&2
|
||||
exit $status
|
||||
;;
|
||||
ld) tmp=/tmp/cc.${USER:-$LOGNAME}.$$.err
|
||||
trap "rm -f $tmp" EXIT
|
||||
$CC -Wl,-m -DCLK_TCK=100 "$@" >$tmp 2>&1
|
||||
status=$?
|
||||
egrep -v ' (warning .*multiple definitions of|definition of|as lazy binding|not from earlier dynamic) ' $tmp >&2
|
||||
exit $status
|
||||
;;
|
||||
esac
|
|
@ -1,71 +0,0 @@
|
|||
: unix wrapper for Mac OS X 10.7 (Darwin 11) cc : 2020-07-17 :
|
||||
|
||||
HOSTTYPE=darwin11.generic
|
||||
|
||||
case " $* " in
|
||||
*" -dumpmachine "*) echo $HOSTTYPE; exit ;;
|
||||
esac
|
||||
|
||||
CC=/usr/bin/cc
|
||||
op=init
|
||||
for arg
|
||||
do case $op in
|
||||
init) op=ld
|
||||
set ''
|
||||
;;
|
||||
esac
|
||||
case $arg in
|
||||
-c) op=cc
|
||||
;;
|
||||
-E) op=cpp
|
||||
continue
|
||||
;;
|
||||
-G) op=dll
|
||||
continue
|
||||
;;
|
||||
-lc) continue
|
||||
;;
|
||||
-lm) continue
|
||||
;;
|
||||
esac
|
||||
set "$@" "$arg"
|
||||
done
|
||||
case $# in
|
||||
0) ;;
|
||||
*) shift ;;
|
||||
esac
|
||||
case $* in
|
||||
-v) $CC "$@"; exit ;;
|
||||
esac
|
||||
case $op in
|
||||
init) echo "cc: arguments expected" >&2
|
||||
exit 1
|
||||
;;
|
||||
cpp) $CC -E "$@"
|
||||
;;
|
||||
cc) $CC -DCLK_TCK=100 "$@"
|
||||
;;
|
||||
dll) # what a compatibility mess -- surely they can get the apis to play nice
|
||||
tmp=/tmp/cc.${USER:-$LOGNAME}.$$.err
|
||||
trap "rm -f $tmp" EXIT
|
||||
case `MACOSX_DEPLOYMENT_TARGET=10.7 ld -undefined dynamic_lookup 2>&1` in
|
||||
*undefined*dynamic_lookup*)
|
||||
ld -m -flat_namespace -undefined suppress -dylib -dynamic \
|
||||
-ldylib1.o "$@" -lcc_dynamic -framework System >$tmp 2>&1
|
||||
status=$?
|
||||
;;
|
||||
*) MACOSX_DEPLOYMENT_TARGET=10.7 $CC -Wl,-flat_namespace -dynamiclib -undefined dynamic_lookup "$@" >$tmp 2>&1
|
||||
status=$?
|
||||
;;
|
||||
esac
|
||||
egrep -v ' (warning .*multiple definitions|definition) of ' $tmp >&2
|
||||
exit $status
|
||||
;;
|
||||
ld) tmp=/tmp/cc.${USER:-$LOGNAME}.$$.err
|
||||
trap "rm -f $tmp" EXIT
|
||||
$CC -Wl,-m -DCLK_TCK=100 "$@" >$tmp 2>&1
|
||||
status=$?
|
||||
egrep -v ' (warning .*multiple definitions of|definition of|as lazy binding|not from earlier dynamic) ' $tmp >&2
|
||||
exit $status
|
||||
;;
|
||||
esac
|
|
@ -446,6 +446,9 @@ tst lib_memcmp string.h note{ standard memcmp interface that works }end execute{
|
|||
}end
|
||||
|
||||
tst lib_memccpy string.h unistd.h stdlib.h fcntl.h signal.h sys/types.h sys/stat.h sys/mman.h fcntl.h note{ standard memccpy interface that works }end execute{
|
||||
#ifndef MAP_FAILED
|
||||
#define MAP_FAILED ((void*)-1) /* introduced in POSIX-1.2017 */
|
||||
#endif
|
||||
#if _STD_
|
||||
static void gotcha(int sig)
|
||||
#else
|
||||
|
@ -490,7 +493,7 @@ tst lib_memccpy string.h unistd.h stdlib.h fcntl.h signal.h sys/types.h sys/stat
|
|||
return 1;
|
||||
}
|
||||
m = n * (sizeof(x)-1);
|
||||
if (!(b = mmap((void*)0, m, PROT_READ|PROT_WRITE, MAP_PRIVATE, d, (off_t)0)))
|
||||
if ((b = mmap((void*)0, m, PROT_READ|PROT_WRITE, MAP_PRIVATE, d, (off_t)0)) == MAP_FAILED)
|
||||
{
|
||||
close(d);
|
||||
return 1;
|
||||
|
@ -544,9 +547,9 @@ tst lib_memccpy string.h unistd.h stdlib.h fcntl.h signal.h sys/types.h sys/stat
|
|||
return 0;
|
||||
if ((fd = open("/dev/zero", O_RDWR)) < 0)
|
||||
return 0;
|
||||
if (!(srcbuf = (char*)mmap(NULL, siz, PROT_READ|PROT_WRITE, MAP_PRIVATE, fd, 0)))
|
||||
if ((srcbuf = (char*)mmap(NULL, siz, PROT_READ|PROT_WRITE, MAP_PRIVATE, fd, 0)) == MAP_FAILED)
|
||||
return 0;
|
||||
if (!mmap(srcbuf + siz, siz, PROT_NONE, MAP_PRIVATE, fd, 0))
|
||||
if (mmap(srcbuf + siz, siz, PROT_NONE, MAP_PRIVATE, fd, 0) == MAP_FAILED)
|
||||
return 0;
|
||||
for (i = 0; i < siz; i++)
|
||||
srcbuf[i] = 'x';
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue