When compiling a program with -nostdlib and using va_arg(), TCC complains about
'__va_arg' being undefined:
$ tcc -nostdlib -D__STDC_HOSTED__=0 test.c
tcc: error: undefined symbol '__va_arg'
This is not fixed by telling it to link with libtcc1:
$ tcc -nostdlib -ltcc1 -D__STDC_HOSTED__=0 test.c
tcc: error: undefined symbol '__va_arg'
This is on amd64 (x86_64), using the mob version.
Another (minor) issue is __STDC_HOSTED__ macro not being defined. As specified
by C98 standard, 6.10.8 p1, it should be defined as 1 if the implementation is
a hosted implementation, and 0 if not. (Not sure if it is specified in C89.) In
GCC and CLang, it is 1 by default, and there is a helpful -ffreestanding switch
that toggles it to 0. I think it should be defined in TCC, and set to 0 when
-nostdlib switch is supplied, so my program can detect whether to provide the
'_start' entry point. But tell me what you think.
The test program is reproduced below:
#include <stdarg.h>
#include <stddef.h>
#if !__STDC_HOSTED__
void linux_amd64_exit_group( unsigned char status )
{
__asm volatile (
"mov $231, %%rax \n\t"
"syscall \n\t"
:
: "D"(status)
: "rax", /* "rdx", "rdi", */ "rsi", "rdx", "r10", "r8", "r9",
"r11", "rcx", "cc", "memory"
);
}
__asm(
".global _start \n\t"
"_start: \n\t"
"mov 0(%rsp), %edi \n\t"
"lea 8(%rsp), %rsi \n\t"
"call main \n\t"
"mov %eax, %edi \n\t"
"call linux_amd64_exit_group \n\t"
);
#endif
int add( int n, ... )
{
int acc = 0;
va_list args;
va_start( args, n );
while( n-- > 0 ) {
/* The problem seems to manifest only when using va_arg(). */
#if 1
acc += va_arg( args, int );
#endif
}
va_end(args);
return acc;
}
int main()
{
return add( 3, 5, 10, 3 );
}
_______________________________________________
Tinycc-devel mailing list
[email protected]
https://lists.nongnu.org/mailman/listinfo/tinycc-devel