Bug #5401
Unable to compile on Gentoo - getting error: "_FORTIFY_SOURCE" redefined
0%
Description
Couple of revisions back I'm not able to compile pulled source on Gentoo.
After doing "./configure --prefix=/opt/tvheadend" and "make" after a while I'll get this:
Building src/webui/static/intl/tvh.uk.js.gz
Building src/webui/static/intl/tvh.zh.js.gz
Building src/webui/static/intl/tvh.zh-Hans.js.gz
WEBUI std finished
make[3]: Leaving directory '/opt/tvheadend/src-new'
make -f Makefile.webui WEBUI=debug compile-debug
make[3]: Entering directory '/opt/tvheadend/src-new'
WEBUI debug finished
make[3]: Leaving directory '/opt/tvheadend/src-new'
make[2]: Leaving directory '/opt/tvheadend/src-new'
CC src/version.o
<command-line>:0:0: error: "_FORTIFY_SOURCE" redefined [-Werror]
<built-in>: note: this is the location of the previous definition
cc1: error: unrecognized command line option '-Wno-stringop-truncation' [-Werror]
cc1: all warnings being treated as errors
make[1]: *** [Makefile:714: /opt/tvheadend/src-new/build.linux/src/version.o] Error 1
I'm able to fix that by doing this:
diff --git a/Makefile b/Makefile
index 007a35e77..783d9a9a0 100644
--- a/Makefile
+++ b/Makefile
@@ -36,7 +36,7 @@ CFLAGS += -g
ifeq ($(CONFIG_CCDEBUG),yes)
CFLAGS += -O0
else
-CFLAGS += -O2 -D_FORTIFY_SOURCE=2
+CFLAGS += -O2
endif
ifeq ($(CONFIG_PIE),yes)
CFLAGS += -fPIE
@@ -53,7 +53,7 @@ CFLAGS += -Wall -Wwrite-strings -Wno-deprecated-declarations
CFLAGS += -Wmissing-prototypes
CFLAGS += -fms-extensions -funsigned-char -fno-strict-aliasing
ifeq ($(COMPILER), gcc)
-CFLAGS += -Wno-stringop-truncation -Wno-stringop-overflow
+#CFLAGS += -Wno-stringop-truncation -Wno-stringop-overflow
endif
CFLAGS += -D_FILE_OFFSET_BITS=64
CFLAGS += -I${BUILDDIR} -I${ROOTDIR}/src -I${ROOTDIR}
but I'm not sure if that is a correct approach.
This is with gcc 7.3.0/glibc 2.27.
I think this broke somewhere around here 75074cb.
Thank you.
History
Updated by Em Smith over 5 years ago
I believe it's an issue with Gentoo itself.
For example one page I read states that Gentoo has patched their compiler to automatically enable FORTIFY if optimization is enabled and links to this
https://sources.gentoo.org/cgi-bin/viewvc.cgi/gentoo/src/patchsets/gcc/4.9.3/gentoo/10_all_default-fortify-source.patch?view=markup
Also mentions it here:
https://wiki.gentoo.org/wiki/Hardened/FAQ
To me, it seems broken for them to patch the compiler to be inconsistent with other OSes and have it with the same name.
I think that FAQ suggests you can set your compiler using "gcc-config -l" to list the variants and then using the compiler named "vanilla" to just compile tvheadend.
That might also fix your issue with the warning since I can't reproduce it on a non-Gentoo system since gcc (since v4.4) has ignored any "-Wabcdef" flags it does not understand. So, although the "-Wno-stringop-truncation" is gcc8, earlier versions would just ignore the flags since they know it's for a warning they can't emit.
For example, on my system if you type this at the command line then it doesn't complain that "-Wno-abcdefghij" isn't known, but I'm guessing on your system it might due to some Gentoo-specific patches.
echo 'int main() { return 0; }' | gcc7 -Werror -Wall -Wno-stringop-truncation -Wno-abcdefghij -x c -
The easiest approach is what you did and just comment out the lines.