Hi, I've been attempting to build nodejs Node-API addons using the tiny c compiler. When doing this I noticed that the addons were failing to self register on load in nodejs as the constructors were failing to run. gcc worked fine, but tcc failed. Node-API addons use __attribute__((constructor)) in order to register themselves on load. I've worked around this in my project by moving the use of __attribute__((constructor)) before other includes https://github.com/cosinusoidally/mishmashvm/blob/dev/tests/nodejs/stub.c . Having said that there does seem to be a more general issue with attributes at play.
Reproduction case on Linux (every version of tcc I've tried seems to have this issue, but I've tested on mob in this case). I'm on Ubuntu 18.04, but also repros on other distros: $ cat repro.c static void foo(void) __attribute__((constructor)); #include <string.h> static void bar(void) __attribute__((constructor)); I then run this through the preprocessor: $ tcc -E repro.c |grep constructor static void foo(void) __attribute__((constructor)); Note __attribute__((constructor)) has been stripped off bar and not foo. Digging a bit further, it seems to be due to sys/cdefs.h (which is included by string.h and many other standard headers). In sys/cdefs.h I found this: /* GCC has various useful declarations that can be made with the `__attribute__' syntax. All of the ways we use this do fine if they are omitted for compilers that don't understand it. */ #if !defined __GNUC__ || __GNUC__ < 2 # define __attribute__(xyz) /* Ignore */ #endif Which seems to be a work around for GCC 1.x? An even more minimal test case is: static void foo(void) __attribute__((constructor)); #if !defined __GNUC__ || __GNUC__ < 2 # define __attribute__(xyz) /* Ignore */ #endif static void bar(void) __attribute__((constructor)); That code seems to have been there since 1995: https://github.com/bminor/glibc/blob/28f540f45bbacd939bfd07f213bcad2bf730b1bf/misc/sys/cdefs.h#L97 Is there a work around for this issue? I can define __GNUC__ but presumably that may cause other issues? Thanks Liam _______________________________________________ Tinycc-devel mailing list Tinycc-devel@nongnu.org https://lists.nongnu.org/mailman/listinfo/tinycc-devel