Bug #5401

Unable to compile on Gentoo - getting error: "_FORTIFY_SOURCE" redefined

Added by Jozef M 6 months ago. Updated 21 days ago.

Target version:
Start date:
Due date:
% Done:


Estimated time:
Found in version:
4.3-1529/commit c8bbae504 (probably even in previous ones) and later
Affected Versions:


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/
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
+CFLAGS  += -O2
 ifeq ($(CONFIG_PIE),yes)
@@ -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

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.


#1 Updated by Em Smith 21 days 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
Also mentions it here:

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.

Also available in: Atom PDF