[Bug]: tcc unhappy about system headers
Problem description
installed tcc from repo, tried to change CC to it.
got:
tcc -O1 -Wall -Wextra -pedantic -Wno-unused-parameter -Wno-unused-variable -std=c99 -DNDEBUG -DINLINE=inline -DAugmentation_7ch -march=native -Wall -c common.c -o common.o
In file included from common.c:1: In file included from common.h:10:
In file included from /data/data/com.termux/files/usr/include/stdio.h:47:
/data/data/com.termux/files/usr/include/string.h:177: error: ',' expected (got "__dst")
make: *** [Makefile:61: common.o] Error 1
What steps will reproduce the bug?
pkg in tcc get some simple project, try to replace cc=gcc in Makefile with cc=tcc
try make
What is the expected behavior?
tcc works
System information
termux-info:
Termux Variables:
TERMUX_API_VERSION=0.50.1
TERMUX_APK_RELEASE=F_DROID
TERMUX_APP_PACKAGE_MANAGER=apt
TERMUX_APP_PID=881
TERMUX_IS_DEBUGGABLE_BUILD=0
TERMUX_MAIN_PACKAGE_FORMAT=debian
TERMUX_VERSION=0.118.0
TERMUX__USER_ID=0
Packages CPU architecture:
aarch64
Subscribed repositories:
# sources.list
deb https://mirrors.zju.edu.cn/termux/apt/termux-main stable main
# x11-repo (sources.list.d/x11.list)
deb https://mirrors.zju.edu.cn/termux/apt/termux-x11 x11 main
# tur-repo (sources.list.d/tur.list)
deb https://tur.kcubeterm.com tur-packages tur tur-on-device tur-continuous
Updatable packages:
liborc/stable 0.4.35 aarch64 [upgradable from: 0.4.34]
termux-tools version:
1.40.5
Android version:
11
Kernel build information:
Linux localhost 4.14.193 #1 SMP PREEMPT Thu Jul 8 13:58:00 CST 2021 aarch64 Android
Device manufacturer:
DEXP
Device model:
K38
LD Variables:
LD_LIBRARY_PATH=
LD_PRELOAD=/data/data/com.termux/files/usr/lib/libtermux-exec.so
Installed termux plugins:
com.termux.api versionCode:51
This seems an issue with tcc. The following line shows where that error happened.
$ sed -n 177p /data/data/com.termux/files/usr/include/string.h
size_t strxfrm(char* __BIONIC_COMPLICATED_NULLNESS __dst, const char* _Nonnull __src, size_t __n);
And __BIONIC_COMPLICATED_NULLNESS macro is defined as
$ grep -ir "define __BIONIC_COMPLICATED_NULLNESS" /data/data/com.termux/files/usr/include/
/data/data/com.termux/files/usr/include/sys/cdefs.h:#define __BIONIC_COMPLICATED_NULLNESS _Null_unspecified
So, tcc could not recognize _Null_unspecified attribute.
Or, could you try with newer C standard. The clang docs suggests that _Null_unspecified attribute is available for c23 https://clang.llvm.org/docs/AttributeReference.html#null-unspecified
@Biswa96 I do not think tcc understands anything beyound c11 (but it IS small). Wil try to raise issue upstream (tinycc git also fails for me on termux)
This is because the headers in ndk-sysroot is only tested with clang. _Nonnull, _Nullable and _Null_unspecified are keywords that only exist in clang. You can define them manually in $PREFIX/include/sys/cdefs.h.
#if !defined(__clang__)
#define _Nonnull
#define _Nullable
#define _Null_unspecified
#endif
@licy183 thanks, manually editing this file and adding those defines fixes tcc! but I guess this will be overwritten by update at some point ...
I have no idea whether this issue should be fixed or not. Actually ndk-sysroot is only designed for clang because NDK has dropped support for GCC.
Maybe other maintainers have something to say?
Ask tcc to add the missing defines. It already got _Nonnull and _Nullable.
~/bin $ grep "define _Nonnull" -nHR $PREFIX/include
~/bin $ grep "define _Nullable" -nHR $PREFIX/include
~/bin $ echo | tcc -E -dM - | sort | grep "define _N"
#define _Nonnull
#define _Nullable
https://repo.or.cz/tinycc.git/blob/HEAD:/include/tccdefs.h#l129
#elif defined __ANDROID__
#define BIONIC_IOCTL_NO_SIGNEDNESS_OVERLOAD
#define __PRETTY_FUNCTION__ __FUNCTION__
#define __has_builtin(x) 0
#define __has_feature(x) 0
#define _Nonnull
#define _Nullable