From b41039767775169f0e049f0855dbc4bce7f6680a Mon Sep 17 00:00:00 2001 From: Johnothan King Date: Sun, 21 Mar 2021 11:34:04 -0700 Subject: [PATCH] Fix compile when using tcc >0.9.27 on Linux This allows ksh to be compiled with versions of tcc that define __dso_handle in libtcc1.a[*], although only on Linux. The two problems that remain are the following: 1) Older versions of tcc still fail to compile ksh, although now they fail after reaching the libdll feature test. I'm not sure if fixing that is feasible since even if I hack out the failing libdll feature test, ksh fails to link with a '__dso_handle' error. 2) tcc fails to build ksh on FreeBSD. For some reason tcc imitates GCC on FreeBSD but not on Linux. As a result the FreeBSD math.h header tries to define macros that call GCC/Clang builtins. This results in undefined symbol errors since tcc doesn't have those builtins. src/cmd/INIT/iffe.sh: compile(): - tcc forbids combining the -c compiler flag with -l* linker flags. Strip all -l* flags when -c was passed to the compiler. This is only done when tcc is the compiler to prevent build failures on some platforms (such as illumos). src/lib/libast/comp/atexit.c, src/lib/libast/features/lib, src/lib/libast/vmalloc/vmexit.c: - From what I've been able to gather the only OSes with support for on_exit are Linux and SunOS 4. However, on_exit takes two arguments, so the macro that defines it as taking one argument is incorrect. Since Solaris (SunOS 5) no longer has this call and the macro breaks on Linux, the clean fix is to remove it (atexit(3) is used instead). [*]: https://repo.or.cz/tinycc.git/commit/dd60b20c6e0d01df8e332b0234125abaa964d324 Progresses: https://github.com/ksh93/ksh/issues/232 --- src/cmd/INIT/iffe.sh | 18 ++++++++++++++++-- src/lib/libast/comp/atexit.c | 6 +----- src/lib/libast/features/lib | 2 +- src/lib/libast/vmalloc/vmexit.c | 2 +- 4 files changed, 19 insertions(+), 9 deletions(-) diff --git a/src/cmd/INIT/iffe.sh b/src/cmd/INIT/iffe.sh index 9c0426e5d2cf..932953500438 100644 --- a/src/cmd/INIT/iffe.sh +++ b/src/cmd/INIT/iffe.sh @@ -31,10 +31,24 @@ AIX) unset LIBPATH ;; esac command=iffe -version=2021-02-03 # update in USAGE too # +version=2021-03-21 # update in USAGE too # compile() # $cc ... { + # tcc can't combine -l* and -c + case "`$1 --version 2> /dev/null`" in + tcc*) if echo "$@" | grep ' -c' | grep -q ' -l' + then for arg + do shift + case $arg in + -l*) : ;; + *) set -- "$@" "$arg" + esac + done + fi + ;; + esac + "$@" 2>$tmp.err _compile_status=$? if test -s $tmp.err @@ -753,7 +767,7 @@ set= case `(getopts '[-][123:xyz]' opt --xyz; echo 0$opt) 2>/dev/null` in 0123) USAGE=$' [-? -@(#)$Id: iffe (ksh 93u+m) 2021-02-03 $ +@(#)$Id: iffe (ksh 93u+m) 2021-03-21 $ ] [-author?Glenn Fowler ] [-author?Phong Vo ] diff --git a/src/lib/libast/comp/atexit.c b/src/lib/libast/comp/atexit.c index d0df2d524b3f..c29ce5a73551 100644 --- a/src/lib/libast/comp/atexit.c +++ b/src/lib/libast/comp/atexit.c @@ -34,11 +34,7 @@ NoN(atexit) #else -#if _lib_onexit || _lib_on_exit - -#if !_lib_onexit -#define onexit on_exit -#endif +#if _lib_onexit extern int onexit(void(*)(void)); diff --git a/src/lib/libast/features/lib b/src/lib/libast/features/lib index 5a9a67b2cc21..007471d1bd86 100644 --- a/src/lib/libast/features/lib +++ b/src/lib/libast/features/lib @@ -28,7 +28,7 @@ lib getopt,getsubopt,getopt_long,getopt_long_only lib glob,index,iswblank,iswctype,killpg,link,localeconv,madvise lib mbtowc,mbrtowc,memalign,memchr,memcpy,memdup,memmove,memset lib mkdir,mkfifo,mktemp,mktime -lib mount,on_exit,onexit,opendir,pathconf +lib mount,onexit,opendir,pathconf lib readlink,remove,rename,rewinddir,rindex,rmdir,setlocale lib setpgid,setpgrp,setpgrp2,setreuid,setsid,setuid,sigaction lib sigprocmask,sigsetmask,sigunblock,sigvec,socketpair diff --git a/src/lib/libast/vmalloc/vmexit.c b/src/lib/libast/vmalloc/vmexit.c index c027fd56ca7b..7752e09676b2 100644 --- a/src/lib/libast/vmalloc/vmexit.c +++ b/src/lib/libast/vmalloc/vmexit.c @@ -93,7 +93,7 @@ int type; return type; } -#endif /* _lib_onexit || _lib_on_exit */ +#endif /* _lib_onexit */ #endif /*!PACKAGE_ast*/