I'm doing a GCC Plugin to check a coding style for C and header files. I check the coding style at the compilation with :
register_callback(plugin_info->base_name, PLUGIN_START_UNIT, start_unit_callback, NULL);
register_callback(plugin_info->base_name, PLUGIN_INCLUDE_FILE, include_file_callback, NULL);
The first line is only to check C
files and the second one is to check headers files (.h
).
But then I have performance issue when it come to the header check. In fact, it checks the system headers too ! And I would like it does not do that. This is the list of headers file that GCC gets :
/usr/include/stdio.h
/usr/include/bits/libc-header-start.h
/usr/include/features.h
/usr/include/features-time64.h
/usr/include/bits/wordsize.h
/usr/include/bits/timesize.h
/usr/include/bits/wordsize.h
/usr/include/sys/cdefs.h
/usr/include/bits/wordsize.h
/usr/include/bits/long-double.h
/usr/include/gnu/stubs.h
/usr/include/gnu/stubs-64.h
/usr/lib/gcc/x86_64-pc-linux-gnu/13.1.1/include/stddef.h
/usr/lib/gcc/x86_64-pc-linux-gnu/13.1.1/include/stdarg.h
/usr/include/bits/types.h
/usr/include/bits/wordsize.h
/usr/include/bits/timesize.h
/usr/include/bits/wordsize.h
/usr/include/bits/typesizes.h
/usr/include/bits/time64.h
/usr/include/bits/types/__fpos_t.h
/usr/include/bits/types/__mbstate_t.h
/usr/include/bits/types/__fpos64_t.h
/usr/include/bits/types/__FILE.h
/usr/include/bits/types/FILE.h
/usr/include/bits/types/struct_FILE.h
/usr/include/bits/stdio_lim.h
/usr/include/bits/floatn.h
/usr/include/bits/floatn-common.h
/usr/include/bits/long-double.h
test.h
The only include that I've made myself is the test.h
, so it must not check the others files.
So do you know a way to extract all the system files included ?
I've tried to just skip all the includes from /usr/
and /lib/
but that is not a good practice.
I've tried to see if I could make the callback at another moment of the compilation, but it did not make well (It does not check for headers).
Thank you for reading me ! Hoping you could help me :)
on freebsd for example there are users' homes located in '/usr/home' and '/home' is symlink to '/usr/home' (at least at last time I've installed it) – yvs2014 Jun 10 '23 at 16:44
Suppose there should be a bit more direct way to get system include directories with some gcc specific function, but sorry I've not gone deep into c preproprecossor details. – yvs2014 Jun 10 '23 at 17:41