I can tried to investigate this with a cliched sample code, you know...the usual
suspect:

    #include <stdio.h>

    int main(void)
    {
        puts("Hello...");
        return 0;
    }

With both TCC and GCC I wanted to get some actual output, what gets loaded and
what not; but of course, we care only for TCC, therefore I will skip GCC
entirely.

First, I run the following command: `tcc -M src/tmp.c`

Here's the output:

tmp.o: \
  src/tmp.c \
  /usr/include/stdio.h \
  /usr/include/x86_64-linux-gnu/bits/libc-header-start.h \
  /usr/include/features.h \
  /usr/include/features-time64.h \
  /usr/include/x86_64-linux-gnu/bits/wordsize.h \
  /usr/include/x86_64-linux-gnu/bits/timesize.h \
  /usr/include/stdc-predef.h \
  /usr/include/x86_64-linux-gnu/sys/cdefs.h \
  /usr/include/x86_64-linux-gnu/bits/long-double.h \
  /usr/include/x86_64-linux-gnu/gnu/stubs.h \
  /usr/include/x86_64-linux-gnu/gnu/stubs-64.h \
  /usr/local/lib/tcc/include/stddef.h \
  /usr/local/lib/tcc/include/stdarg.h \
  /usr/include/x86_64-linux-gnu/bits/types.h \
  /usr/include/x86_64-linux-gnu/bits/typesizes.h \
  /usr/include/x86_64-linux-gnu/bits/time64.h \
  /usr/include/x86_64-linux-gnu/bits/types/__fpos_t.h \
  /usr/include/x86_64-linux-gnu/bits/types/__mbstate_t.h \
  /usr/include/x86_64-linux-gnu/bits/types/__fpos64_t.h \
  /usr/include/x86_64-linux-gnu/bits/types/__FILE.h \
  /usr/include/x86_64-linux-gnu/bits/types/FILE.h \
  /usr/include/x86_64-linux-gnu/bits/types/struct_FILE.h \
  /usr/include/x86_64-linux-gnu/bits/types/cookie_io_functions_t.h \
  /usr/include/x86_64-linux-gnu/bits/stdio_lim.h \
  /usr/include/x86_64-linux-gnu/bits/floatn.h \
  /usr/include/x86_64-linux-gnu/bits/floatn-common.h


If we open the header file at /usr/local/lib/tcc/include/stddef.h we can see
that in there we have

typedef __PTRDIFF_TYPE__ ptrdiff_t;
typedef __WCHAR_TYPE__ wchar_t;

and a bit lower in that file, we can clearly find

#undef offsetof
#define offsetof(type, field) __builtin_offsetof(type, field)

A rather shorter way to get the same findings, but unfortunately not the macro
method, is by running the following command:


    $ tcc -E -P src/tmp.c | grep -E '(ptrdiff_t|wchar_t)'

You should get the final preprocessed output as

typedef int wchar_t;
typedef long ptrdiff_t;


Now, what's more interesting, is that if we open the standard stdio.h
located at /usr/include/, at least in GNU / Linux Debian's case, we will
notice at the very top, right after __BEGIN_DECLS that we have

#define __need_size_t
#define __need_NULL
#include <stddef.h>

Thus, the implicit inclusion you were looking for.

Now, how TCC parses this specific stddef.h header file to point at
/usr/local/lib/tcc/include/stddef.h goes beyond my knowledge.

I hope this answers your question.

Regards,

Stefanos

_______________________________________________
Tinycc-devel mailing list
[email protected]
https://lists.nongnu.org/mailman/listinfo/tinycc-devel

Reply via email to