tinycc-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Tinycc-devel] [FreeBSD support] __aligned(n) + __pure issues


From: Christian Jullien
Subject: Re: [Tinycc-devel] [FreeBSD support] __aligned(n) + __pure issues
Date: Sun, 16 Oct 2016 06:50:46 +0200

Ok Michael,
It is defined in sys/cdefs.h as:

#if __GNUC_PREREQ__(2, 7) || defined(__INTEL_COMPILER)
#define __dead2         __attribute__((__noreturn__))
#define __pure2         __attribute__((__const__))
#define __unused        __attribute__((__unused__))
#define __used          __attribute__((__used__))
#define __packed        __attribute__((__packed__))
#define __aligned(x)    __attribute__((__aligned__(x)))
#define __section(x)    __attribute__((__section__(x)))
#endif

So just tried:
--- a/libtcc.c
+++ b/libtcc.c
@@ -903,7 +903,7 @@ LIBTCCAPI TCCState *tcc_new(void)
 # if 1
     /* define __GNUC__ to have some useful stuff from sys/cdefs.h */
     tcc_define_symbol(s, "__GNUC__", "2");
-    tcc_define_symbol(s, "__GNUC_MINOR__", "1");
+    tcc_define_symbol(s, "__GNUC_MINOR__", "7");
     tcc_define_symbol(s, "__builtin_alloca", "alloca");
     tcc_define_symbol(s, "__builtin_memcpy", "memcpy");
     tcc_define_symbol(s, "__USER_LABEL_PREFIX__", "");

And it helps a little bit, now I get the same result as if I define
__aligned(x) __attribute__((__aligned__(x))) i.e. code compiles (with
__aligned defined) but std C library is not found.

------------ test3 ------------
../tcc -B.. -I../include -I.. -I.. -DTCC_TARGET_I386 -DONE_SOURCE -run
../tcc.c -B.. -I../include -I.. -I.. -DTCC_TARGET_I386 -DONE_SOURCE -run
../tcc.c -B.. -I../include -I.. -I.. -DTCC_TARGET_I386 -DONE_SOURCE -run
../tcc.c -B.. -I../include -I.. -I.. -run tcctest.c > test.out3
tcc: error: undefined symbol 'memcpy'
tcc: error: undefined symbol 'strlen'
tcc: error: undefined symbol 'memmove'
tcc: error: undefined symbol 'memset'
tcc: error: undefined symbol 'memcmp'
tcc: error: undefined symbol 'sprintf'
...

$ ./tcc -vv
tcc version 0.9.26 (i386 FreeBSD)
install: /usr/local/lib/tcc
include:
  /usr/local/lib/tcc/include
  /usr/local/include
  /usr/include
libraries:
  /usr/lib
  /lib
  /usr/local/lib
crt:
  /usr/lib
elfinterp:
  /libexec/ld-elf.so.1

$ sudo find /usr -name 'crt*o'
/usr/lib/crti.o
/usr/lib/crtend.o
/usr/lib/crtbeginS.o
/usr/lib/crtn.o
/usr/lib/crtbegin.o
/usr/lib/crtendS.o
/usr/lib/crtbeginT.o
/usr/lib/crt1.o
/usr/local/lib/gcc48/gcc/i386-portbld-freebsd11.0/4.8.5/crtbegin.o
/usr/local/lib/gcc48/gcc/i386-portbld-freebsd11.0/4.8.5/crtendS.o
/usr/local/lib/gcc48/gcc/i386-portbld-freebsd11.0/4.8.5/crtend.o
/usr/local/lib/gcc48/gcc/i386-portbld-freebsd11.0/4.8.5/crtbeginS.o


-----Original Message-----
From: Tinycc-devel [mailto:address@hidden
On Behalf Of Michael Matz
Sent: dimanche 16 octobre 2016 00:05
To: address@hidden
Subject: Re: [Tinycc-devel] [FreeBSD support] __aligned(n) + __pure issues

Hi,

On Sat, 15 Oct 2016, grischka wrote:

> Christian Jullien wrote:
>> Ok,
>> The point is that it compiles ROOTB but then a single line program 
>> using only ISO include and std C library fails because of __aligned 
>> in a
>> **system** header.
>> I agree that __aligned is a probably a macro or a gcc FreeBSD 
>> specific extension, but no one wants to change it source file (or 
>> Makefile) when he the switch from gcc to tcc To be more clear, let me 
>> start again from scratch (Don't miss *Linux* in banner with -v and 
>> -vv)
>
> Please!  You were clear.  Anyway, maybe this helps:
>   
> http://repo.or.cz/tinycc.git/commitdiff/f3c1ea6c2d7dca7883985820e46ec5
> 36e2d7e8cc It is expected that this could break system xyz whatever.

Ugh.  TCC doesn't support enough of GNU C to be able to sensibly define
__GNUC__.  I've privately started to support more of it, but it's nowhere
complete.  I don't think that's going to work very well.

Christian: you were completely clear in your initial mail.  I was trying to
make you look into FreeBSDs headers to find out _where_ the __aligned macro
is defined, under which conditions.  I wanted to know this so that I can
suggest an acceptable and least intrusive way for TCC to work around the
problem in FreeBSDs standard headers.

> Some background research:
>
> - obviously FreeBSD headers expect __GNUC__
>  http://pcc.ludd.ltu.se/jira/browse/PCC-18

Meeh.

> - patch for sys/cdefs.h suggested by PCC  
> http://pcc.ludd.ltu.se/ftp/pub/patches/openbsd-include-sys-081220.diff
>
> - __GNUC__ nowadays seems to mean the C dialect rather than the 
> compiler  https://gcc.gnu.org/ml/gcc/2008-07/msg00026.html
>
> Not sure whether we really want to define __GNUC__.  This might cause 
> all kind of problems.  However if we don't then sys/cdefs.h does
>    #define __attribute__(xyz)

So, FreeBSDs problem really.  Well, we could add work arounds in TCC of
course, and possibly defining __GNUC__ is the most sensible work around. 
But please, then only for the BSDs, not for all the rest.  The other
possibility is to define __aligned ourself (also only on *BSD), if that's
the only missing thing breaking otherwise standard-conforming programs on
FreeBSD.  The compat define should come from some header IMHO, e.g. 
stddef.h, not pre-defined by TCC itself.


Ciao,
Michael.




reply via email to

[Prev in Thread] Current Thread [Next in Thread]