dvidelabs/flatcc

Doesn't compile with TCC compiler

Elkantor opened this issue ยท 10 comments

cmake -G "MinGW Makefiles" -DCMAKE_C_COMPILER=tcc .
-- dist install dir D:/Projects/flatcc
-- lib install dir D:/Projects/flatcc/lib
-- Setting GNU C compiler options with c11 and Posix
-- GCC_VERSION: 7.3.0

-- Configured C_FLAGS:  -DFLATCC_REFLECTION=1 -D_CRT_SECURE_NO_WARNINGS -std=c11 -pedantic -Wall -Wextra -DPORTABLE_POSIX_MEMALIGN=1 -Werror -Wno-unused-function -Wsign-conversion
-- Configuring done
You have changed variables that require your cache to be deleted.
Configure will be re-run and you may have to reset some variables.
The following variables have changed:
CMAKE_C_COMPILER= tcc

-- The C compiler identification is TinyCC
-- The CXX compiler identification is GNU 7.3.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: C:/tools/tcc/tcc.exe - skipped
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: C:/tools/mingw64/bin/g++.exe - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- dist install dir D:/Projects/flatcc
-- lib install dir D:/Projects/flatcc/lib
-- Best effort settings for compiler: TinyCC
-- Configured C_FLAGS:  -DFLATCC_REFLECTION=1 -D_CRT_SECURE_NO_WARNINGS -Wall -DFLATCC_PORTABLE
-- Configuring done
-- Generating done
-- Build files have been written to: D:/Projects/flatcc

Then:

make
Scanning dependencies of target flatccrt
[  0%] Building C object src/runtime/CMakeFiles/flatccrt.dir/builder.c.obj
In file included from D:/Projects/flatcc/src/runtime/builder.c:19:
In file included from D:/Projects/flatcc/include/flatcc/flatcc_builder.h:68:
In file included from D:/Projects/flatcc/include/flatcc/flatcc_flatbuffers.h:20:
In file included from D:/Projects/flatcc/include/flatcc/flatcc_portable.h:8:
In file included from D:/Projects/flatcc/include/flatcc/portable/portable_basic.h:17:
D:/Projects/flatcc/include/flatcc/portable/pstdalign.h:129: error: #error please update pstdalign.h with support for current compiler and library
make[2]: *** [src/runtime/CMakeFiles/flatccrt.dir/builder.c.obj] Erreur 1
make[1]: *** [src/runtime/CMakeFiles/flatccrt.dir/all] Erreur 2
make: *** [all] Erreur 2

D:/Projects/flatcc/include/flatcc/portable/pstdalign.h:129: error: #error please update pstdalign.h with support for current compiler and library

https://github.com/dvidelabs/flatcc/blob/master/include/flatcc/portable/pstdalign.h

Please have a look at that file and consider contributing with support for your platform.

Background: flatcc uses C11 syntax but builds on other platforms through the portable library.
Alignas and alignof are particularly important to ensure that the memory layout is correct.
If you really cannot make it work, flatcc has ancient support for #pragma pack 1 and manual insertion of padding fields, but it hasn't been tested in ages since alignas works on all platforms tested until now.

Thanks for the insight. Actually tcc is a really really tiny compiler for windows/linux (which allows in memory compilation on the fly), but does only support until c99.
I will test it asap

I know about TCC but I don't use it because of licensing issues.

Also note the following comment in the pstdaligh.h header:

 * If stdalign.h is supported but heuristics in this file are
 * insufficient to detect this, try including <stdaligh.h> manually
 * or define HAVE_STDALIGN_H.

And

https://bellard.org/tcc/tcc-doc.html

The keyword __attribute__ is handled to specify variable or function attributes. The following attributes are supported:
aligned(n): align a variable or a structure field to n bytes (must be a power of two).

...

The __alignof__ keyword can be used as sizeof to get the alignment of a type or an expression.

I made a tcc branch.
Can you please test: https://github.com/dvidelabs/flatcc/blob/tcc/include/flatcc/portable/pstdalign.h

Note that this doesn't fully support alignas: alignas(4) should work but alignas(float) appears to not be supported according to the documentation.

I don't think that flatcc generates code in the latter form, so it should work.
You might want to build runtime only with FLATCC_RTONLY to reduce the surface area and possibly also enable FLATCC_PORTABLE in the build.

Merged tcc branch to master.

Im having this exact issue in commit 07ae7dc

any advice for how to fix?

@le91688

Assuming you are using TCC:

You can see the support added when this was closed. The above link is invalid as the branch has been deleted, but you can see the commit here:
7d565a8
and the full file here:
https://github.com/dvidelabs/flatcc/blob/master/include/flatcc/portable/pstdalign.h

You want to make sure that your build actually triggers the section

#elif defined(__TINYC__)
/* Supports `_Alignas(integer-expression)`, but not `_Alignas(type)`. */
#define _Alignas(t) __attribute__(aligned(t))
#define _Alignof(t) __alignof__(t)

You can do that by temporarily inserting an #error line in the header file.

If you are not triggering the section you need to figure out if your environment is correctly set up, and possibly contribute with an improved detector for your setup. You might want to consider the version of TCC and the TCC alignas support in your version as per the pstdalign.h commit, and my earlier comment on TCC doc above.

If you are triggering the section, but still get an error, you need to figure out exactly what alignas operation is triggering the problem. Maybe you can then find a fix based on the discussion in the above, or maybe there are cases that TCC does not support.

If all else fails, you might be able to use padding in structs instead of alignas, but this feature is so old and never used, that I woudn't bother. It is a flag in a config file. You could also consider contributing to TCC.

@mikkelfj my apologies. Issue was I was using release 0.6.0 , updating has fixed it

No problem. And I should have made a release already, so understandable.