Skip to content

Commit

Permalink
Fix compile when using tcc >0.9.27 on Linux
Browse files Browse the repository at this point in the history
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: ksh93#232
  • Loading branch information
JohnoKing committed Mar 21, 2021
1 parent 814b5c6 commit b410397
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 9 deletions.
18 changes: 16 additions & 2 deletions src/cmd/INIT/iffe.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 <[email protected]>]
[-author?Phong Vo <[email protected]>]
Expand Down
6 changes: 1 addition & 5 deletions src/lib/libast/comp/atexit.c
Original file line number Diff line number Diff line change
Expand Up @@ -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));

Expand Down
2 changes: 1 addition & 1 deletion src/lib/libast/features/lib
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/lib/libast/vmalloc/vmexit.c
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ int type;
return type;
}

#endif /* _lib_onexit || _lib_on_exit */
#endif /* _lib_onexit */

#endif /*!PACKAGE_ast*/

Expand Down

0 comments on commit b410397

Please sign in to comment.