tinycc-devel
[Top][All Lists]
Advanced

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

Re: [Tinycc-devel] minor patches + standard compliant inline functions


From: Christian Jullien
Subject: Re: [Tinycc-devel] minor patches + standard compliant inline functions
Date: Wed, 12 Jun 2019 16:49:26 +0200

Thank you Petr,
As far as I see, your patch allows me to compile tcc with bootstrapped tcc on 
Windows (aka reproducible build) and then compiling my BIG OpenLisp project and 
its regression test suite on Windows works as before.

As said, I'm still annoyed you changed the definition of __CRT_INLINE which 
comes from mingw64. The next time someone will get the latest version of 
Windows headers, it will break tcc on Windows.
I let other TinyCC developper give advices.

Christian

-----Original Message-----
From: Petr Skočík [mailto:address@hidden] 
Sent: Wednesday, June 12, 2019 15:50
To: address@hidden; address@hidden
Subject: Re: [Tinycc-devel] minor patches + standard compliant inline functions

After much struggle on an unfamiliar system, I figured out how to use
the lib-build.bat method to build tinycc on win.

Indeed, redefining __CRT_INLINE from `extern __inline__`  to `static
__inline__` does fix the problem, but it goes deeper.

It turns out the patch uncovers two assembly errors in
win32/include/winapi/winnt.h.
First:

    1477:     __asm__ __volatile__("xchgl %eax,%0 "

which should be
    1477:     __asm__ __volatile__("xchgl %%eax,%0 "

and second
    1489:     __asm__ __volatile__("int 0x2c ");
which should be
    1489:     __asm__ __volatile__("int $0x2c ");

The errors don't come up if the enclosing functions are static and
unused (the made them incorrectly static and only instantiated if used,
even though as per the standard they should be nonstatic and always
instantiated) but if they're used or extern, the assembly gets used and
the assembler screams.

IDK what the files are for or how they should be shared with mingw64 but
from the git history of mingw64 it looks like the tinycc version of the
header was adapted from a pre-2009 version of the mingw64 version; and
those two assembly errors were fixed in 2009.

I have now pushed a fix that replicates those fixes in tinycc.
Additionally I have also changed __CRT_INLINE from `extern __inline__`
to `static __inline__` (inline means the same thing as `inline` in both
gcc and tinycc). From scanning the tree, the macro is used exclusively
in header files and, as per the standard, `extern inline` would create
instatiations upon inclusion, and it just doesn't make sense for header
files to behave like that.

Thanks to Christian Julien for finding the problem!

Cheers,
Petr S.


On 6/12/19 12:00 PM, Christian Jullien wrote:
> Hi Petr,
> 
> I prefer to let __CRT_INLINE as is. TinyCC shares Windows header with 
> mingw64. I don't think it's a good idea to start to patch them.
> 
> Please note that TinyCC reports a syntax error " invalid operand reference 
> after %" which, to me, is not related to extern/static linkage.
> 
> C.
> 
> -----Original Message-----
> From: Petr Skočík [mailto:address@hidden] 
> Sent: Wednesday, June 12, 2019 11:49
> To: Christian Jullien; address@hidden
> Subject: Re: [Tinycc-devel] minor patches + standard compliant inline 
> functions
> 
> Hi, Christian Jullien.  Thanks for the feedback.
> 
> I don't have a Windows setup for tinycc to test it on right now, but
> from a cursory glance, __CRT_INLINE is defined as `extern __inline__` in
> ./win32/include/_mingw.h. Before the patch, extern __inline__ would
> create static functions (and only if the function was later referenced).
> After the patch, it'll unconditionally instantiate the function (as an
> extern). I think redefining it to `__CRT_INLINE` `static __inline__`
> might fix the problem.
> 
> I'll try and get a tinycc build working on windows and see if it helps.
> 
> Cheers,
> Petr S.
> 
> On 6/12/19 11:10 AM, Christian Jullien wrote:
>> More specifically this one: "standard conformant inline functions"
>>
>> -----Original Message-----
>> From: Tinycc-devel [mailto:tinycc-devel-bounces+eligis=address@hidden] On 
>> Behalf Of Christian Jullien
>> Sent: Wednesday, June 12, 2019 07:20
>> To: address@hidden; address@hidden
>> Subject: Re: [Tinycc-devel] minor patches + standard compliant inline 
>> functions
>>
>> Ooops, trying to compile tcc (after tcc has been compiled a first time) on 
>> Windows with your recent patch (and w/o uchar.h), I now get:
>>
>> Building lib/libtcc1-32.a with tcc -m32
>> ./include/winapi/winnt.h:1478: error: invalid operand reference after %
>>
>> Here:
>> #if(defined(_X86_) && !defined(__x86_64))
>>   __CRT_INLINE VOID MemoryBarrier(VOID) {
>>     LONG Barrier;
>>     __asm__ __volatile__("xchgl %eax,%0 "
>>       :"=r" (Barrier));
>>   }
>>
>>
>> Here is the final version of uchar.h I'll push if nobody complains
>>
>> win32/include/uchar.h:
>>
>> /**
>>  * This file has no copyright assigned and is placed in the Public Domain.
>>  * This file is part of the TinyCC package.
>>  * No warranty is given; refer to the file DISCLAIMER within this package.
>>  */
>>
>> #ifndef _INC_UCHAR
>> #define _INC_UCHAR
>>
>> /*
>>  * The following defines are only valid when C11 (-std=c11) is used.
>>  */
>>
>> #if __STDC_VERSION__ >= 201112L
>> /**
>>  * __STDC_UTF_16__ The integer constant 1, intended to indicate that
>>  * values of type char16_t are UTF-16 encoded.
>>  */
>> #define __STDC_UTF_16__ 1
>> /**
>>  * __STDC_UTF_32__ The integer constant 1, intended to indicate that
>>  * values of type char32_t are UTF-32 encoded.
>>  */
>> #define __STDC_UTF_32__ 1
>>
>> typedef unsigned short char16_t;
>> typedef unsigned int char32_t;
>> #endif /* __STDC_VERSION__ */
>> #endif /* _INC_UCHAR */
>>
>> -----Original Message-----
>> From: Tinycc-devel [mailto:tinycc-devel-bounces+eligis=address@hidden] On 
>> Behalf Of Christian Jullien
>> Sent: Wednesday, June 12, 2019 06:49
>> To: address@hidden
>> Subject: Re: [Tinycc-devel] minor patches + standard compliant inline 
>> functions
>>
>> Thanks for your patch,
>> FYI, for Windows compatibility:
>>
>> turn -fdollars-in-identifiers on by default is Ol as it also applies to cl 
>> on Windows (the old VMS days :o)
>> Also ok to remove __STDC_ISO_10646__ as is not defined on Windows too.
>>
>> Please note that a conforming C11 implementation should have <uchar.h> which 
>> is missing on Windows includes. Among others, on Windows it defines both:
>>
>> __STDC_UTF_16_ _ The integer constant 1, intended to indicate that values of 
>> type char16_t are UTF−16 encoded. If some other encoding is used, the macro 
>> shall not be defined and the actual encoding used is implementation defined.
>>
>> __STDC_UTF_32_ _ The integer constant 1, intended to indicate that values of 
>> type char32_t are UTF−32 encoded. If some other encoding is used, the macro 
>> shall not be defined and the actual encoding used is implementation defined.
>>
>> To make tcc more C11 compatible on Windows, I propose to add to the win32 
>> directory this file:
>>
>> win32/include/uchar.h:
>>
>> /**
>>  * This file has no copyright assigned and is placed in the Public Domain.
>>  * This file is part of the TinyCC package.
>>  * No warranty is given; refer to the file DISCLAIMER within this package.
>>  */
>>
>> /**
>>   * __STDC_UTF_16__ The integer constant 1, intended to indicate that values 
>> of type char16_t are UTF−16 encoded.
>>  */
>> #define __STDC_UTF_16__ 1
>> /**
>>  * __STDC_UTF_32__ The integer constant 1, intended to indicate that values 
>> of type char32_t are UTF−32 encoded.
>>  */
>> #define __STDC_UTF_32__ 1
>>
>>  typedef unsigned short char16_t;
>>  typedef unsigned int char32_t;
>>
>>
>>
>> -----Original Message-----
>> From: Tinycc-devel [mailto:tinycc-devel-bounces+eligis=address@hidden] On 
>> Behalf Of Petr Skocík
>> Sent: Tuesday, June 11, 2019 16:41
>> To: address@hidden
>> Subject: [Tinycc-devel] minor patches + standard compliant inline functions
>>
>> Hi,
>>
>> I've pushed a bunch of patches to tinycc.
>>
>>
>> The first three:
>>
>> - turn -fdollars-in-identifiers on by default        (gcc/clang do it too)
>> - in c11 mode, skip __STDC_ISO_10646__       (was causing a redefinition
>> warning in simple hello world programs compiled on linux with -std=c11)
>> - make -h|-hh succeed if the output is successfully written
>>
>> are small and should be noncontroversial.
>>
>> The last one is largish and I welcome any input on it.
>>
>> The issue was that tinycc's implementation of non-static inline
>> functions was very much nonconforming in terms of when
>> visible symbols would or would not be created. By looking at the at the
>> mailing list archive, it looks like it was discussed in 2013 but nothing
>> was done about it.
>>
>> The supplied patch should be fixing it.
>>
>> Best regards,
>>
>> Petr Skocik
>>
>> _______________________________________________
>> Tinycc-devel mailing list
>> address@hidden
>> https://lists.nongnu.org/mailman/listinfo/tinycc-devel
>>
>>
>> _______________________________________________
>> Tinycc-devel mailing list
>> address@hidden
>> https://lists.nongnu.org/mailman/listinfo/tinycc-devel
>>
>>
>> _______________________________________________
>> Tinycc-devel mailing list
>> address@hidden
>> https://lists.nongnu.org/mailman/listinfo/tinycc-devel
>>
>>
>> _______________________________________________
>> Tinycc-devel mailing list
>> address@hidden
>> https://lists.nongnu.org/mailman/listinfo/tinycc-devel
>>
> 




reply via email to

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