g-ir-scanner should not use system-provided CFLAGS
Submitted by Thomas Haller
Link to original bug (#757934)
Description
g-ir-scanner invokes the CC compiler with both the CFLAGS and the flags from the python installation. These flags can conflict and g-ir-scanner should only rely on the externally passed in CFLAGS.
This is easily reproducible when building NetworkManager from source (on Fedora23):
export CFLAGS='-O0' ./autogen.sh make
this will call g-ir-scanner via Makefile.introspection like:
CPPFLAGS=""
CFLAGS="[] -O0 [...]"
LDFLAGS="[...]" CC=""
/usr/bin/g-ir-scanner [...]
g-ir-scanner then will eventually call:
gcc -fno-strict-aliasing -O2 -g -pipe -Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -m64 -mtune=generic -D_GNU_SOURCE -fPIC -fwrapv -DNDEBUG -O2 -g -pipe -Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -m64 -mtune=generic -D_GNU_SOURCE -fPIC -fwrapv -Wall -std=gnu89 -Werror -Wshadow -Wmissing-declarations -Wmissing-prototypes -Wdeclaration-after-statement -Wformat-security -Wfloat-equal -Wno-unused-parameter -Wno-sign-compare -fno-strict-aliasing -Wno-unused-but-set-variable -Wundef -Wimplicit-function-declaration -Wpointer-arith -Winit-self -Wmissing-include-dirs -Wno-pragmas -O0 -DNMTST_TEST_QUICK=TRUE -Warray-bounds -Wunused-value -fPIC -DNMTST_TEST_QUICK=TRUE -I/usr/include/gudev-1.0 -I/usr/include/gio-unix-2.0 -I/usr/include/glib-2.0 -I/usr/lib64/glib-2.0/include -I/usr/include/gudev-1.0 -I/usr/include/glib-2.0 -I/usr/lib64/glib-2.0/include -c /data/src/NetworkManager/libnm/tmp-introspectQKWvRm/NM-1.0.c -o tmp-introspectQKWvRm/data/src/NetworkManager/libnm/tmp-introspectQKWvRm/NM-1.0.o -Wno-deprecated-declarations -pthread
Note that this effectively specifies "-D_FORTIFY_SOURCE=2 ... -O0", which leads to a compiler error:
/usr/include/features.h:328:4: error: #warning _FORTIFY_SOURCE requires compiling with optimization (-O) [-Werror=cpp]
warning _FORTIFY_SOURCE requires compiling with optimization (-O)
cc1: all warnings being treated as errors Caught exception: <class 'distutils.errors.CompileError'> CompileError(DistutilsExecError("command 'gcc' failed with exit status 1",),)
/usr/lib64/python2.7/distutils/unixccompiler.py(132)_compile() -> raise CompileError, msg (Pdb) bt /usr/bin/g-ir-scanner(58)
<module>
() -> sys.exit(scanner_main(sys.argv)) /usr/lib64/gobject-introspection/giscanner/scannermain.py(530)scanner_main() -> shlibs = create_binary(transformer, options, args) /usr/lib64/gobject-introspection/giscanner/scannermain.py(412)create_binary() -> gdump_parser.get_error_quark_functions()) /usr/lib64/gobject-introspection/giscanner/dumper.py(321)compile_introspection_binary() -> return dc.run() /usr/lib64/gobject-introspection/giscanner/dumper.py(162)run() -> introspection_obj = self._compile(c_path) /usr/lib64/gobject-introspection/giscanner/dumper.py(201)_compile() -> self._options.init_sections) /usr/lib64/gobject-introspection/giscanner/ccompiler.py(239)compile() -> source_str.rfind(os.sep)]) /usr/lib64/python2.7/distutils/ccompiler.py(574)compile() -> self._compile(obj, src, ext, cc_args, extra_postargs, pp_opts) /usr/lib64/python2.7/distutils/unixccompiler.py(132)_compile() -> raise CompileError, msg
But the problem is, that g-ir-scanner uses the CFLAGS from ccompiler.py which are are incompatible with what we want to specify and there is no way to turn that off.
Currently, we worked around this via: http://cgit.freedesktop.org/NetworkManager/NetworkManager/commit/?id=f6272144e98c00db18cf6708aceab96e6e7b1705