Skip to contentSkip to conversation

multipath-tools: fix build failures on GCC 4.8

PATCH In review Mauricio Faria de Oliveira 2 participants 5 messages Jul 30, 2018

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

cover multipath-tools: fix build failures on GCC 4.8

This series fixes a couple of build failures hit on GCC 4.8 (one actually due to dash/bash differences) on Ubuntu 14.04.

Also tested on Ubuntu 18.04 (GCC 7.3) for (no) regressions.

Before:

    $ make 
    cc: error: unrecognized command line option ‘-fstack-protector-strong’
    make[1]: Entering directory `/home/ubuntu/git/multipath-tools/libmpathcmd'
    building mpath_cmd.o because of mpath_cmd.c
    cc -O2 -g -pipe -Wall -Wextra -Wformat=2 -Werror=implicit-int -Werror=implicit-function-declaration -Werror=format-security -Wno-sign-compare -Wno-unused-parameter -Wno-clobbered -Werror=cast-qual -Werror=discarded-qualifiers -Wp,-D_FORTIFY_SOURCE=2 -fstack-protector-strong --param=ssp-buffer-size=4 -DBIN_DIR=\"/sbin\" -DLIB_STRING=\"lib64\" -DRUN_DIR=\"run\" -MMD -MP  -fPIC -c -o mpath_cmd.o mpath_cmd.c
    cc: error: unrecognized command line option ‘-fstack-protector-strong’
    make[1]: *** [mpath_cmd.o] Error 1

After Patch 1:

    $ make 
    make[1]: Entering directory `/home/ubuntu/git/multipath-tools/libmpathcmd'
    building mpath_cmd.o because of mpath_cmd.c
    cc -O2 -g -pipe -Wall -Wextra -Wformat=2 -Werror=implicit-int -Werror=implicit-function-declaration -Werror=format-security -Wno-sign-compare -Wno-unused-parameter -Wno-clobbered -Werror=cast-qual -Werror=discarded-qualifiers -Wp,-D_FORTIFY_SOURCE=2 -fstack-protector --param=ssp-buffer-size=4 -DBIN_DIR=\"/sbin\" -DLIB_STRING=\"lib64\" -DRUN_DIR=\"run\" -MMD -MP  -fPIC -c -o mpath_cmd.o mpath_cmd.c
    cc1: error: -Werror=discarded-qualifiers: no option -Wdiscarded-qualifiers
    make[1]: *** [mpath_cmd.o] Error 1

After Patch 2:

    $ make
    make[1]: Entering directory `/home/ubuntu/git/multipath-tools/libmpathcmd'
    building mpath_cmd.o because of mpath_cmd.c
    cc -O2 -g -pipe -Wall -Wextra -Wformat=2 -Werror=implicit-int -Werror=implicit-function-declaration -Werror=format-security -Wno-sign-compare -Wno-unused-parameter -Wno-clobbered -Werror=cast-qual  -Wp,-D_FORTIFY_SOURCE=2 -fstack-protector --param=ssp-buffer-size=4 -DBIN_DIR=\"/sbin\" -DLIB_STRING=\"lib64\" -DRUN_DIR=\"run\" -MMD -MP  -fPIC -c -o mpath_cmd.o mpath_cmd.c
    cc -Wl,-z,relro -Wl,-z,now -shared -Wl,-soname=libmpathcmd.so.0 -o libmpathcmd.so.0 mpath_cmd.o 
    ln -sf libmpathcmd.so.0 libmpathcmd.so
    make[1]: Leaving directory `/home/ubuntu/git/multipath-tools/libmpathcmd'

Mauricio Faria de Oliveira (2):
multipath-tools: fix compilation with gcc < 4.9 on dash shell
multipath-tools: check for C compiler option
-Werror=discarded-qualifiers

 Makefile.inc | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
Signature · 6 lines
2.17.1

--
dm-devel mailing list
[email protected]
https://www.redhat.com/mailman/listinfo/dm-devel
#1 lore raw

PATCH 1/2 multipath-tools: fix compilation with gcc < 4.9 on dash shell

The dash shell does not interpret '&>' as bash does, so instead of stdout/stderr redirect, it runs the command in background [1].

    $ for shell in bash dash; do
        echo -n "$shell rc = "
        $shell -c 'echo "int main(void){return 0;}" \
                     | gcc -o /dev/null -c -fFAIL -xc - &>/dev/null; echo $?';
      done
    bash rc = 1
    dash rc = 0
    $ gcc: error: unrecognized command line option ‘-fFAIL’

This misleads the check for C compiler option in Makefile.inc on Ubuntu 14.04 at least, which uses dash as /bin/sh, and has GCC 4.8 (no -fstack-protector-strong), then the build fails.

So, replace '&>' with the equivalent '>' and '>&2'.

No regression on Ubuntu 18.04 (GCC 7.3, -fstack-protector-strong used).

Fixes a8dd838c

"multipath-tools: fix compilation with gcc < 4.9"

[1] https://wiki.ubuntu.com/DashAsBinSh (see '&>' section)

---
 Makefile.inc | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
Makefile.inc +1 -1
index af2f5bae09d3..a12b46ef315e 100644
@@ -78,7 +78,7 @@ INSTALL_PROGRAM	= install
 # Test if the C compiler supports the option.
 # Evaluates to "option" if yes, and "fallback" otherwise.
 TEST_CC_OPTION = $(shell \
-	if echo 'int main(void){return 0;}' | $(CC) -o /dev/null -c "$(1)" -xc - &>/dev/null; \
+	if echo 'int main(void){return 0;}' | $(CC) -o /dev/null -c "$(1)" -xc - >/dev/null 2>&1; \
 	then \
 		echo "$(1)"; \
 	else \
Signature · 6 lines
2.17.1

--
dm-devel mailing list
[email protected]
https://www.redhat.com/mailman/listinfo/dm-devel
Reviewed-by on v1 1/2
#2 lore raw

Re: [PATCH 1/2] multipath-tools: fix compilation with gcc < 4.9 on dash shell

Makefile.inc INSTALL_PROGRAM = install · line 84

Quoted 13 lines · Mauricio Faria de Oliveira
Makefile.inc +1 -1
index af2f5bae09d3..a12b46ef315e 100644
--- a/Makefile.inc
+-+-+- b/Makefile.inc

@@ -78,7 +-78,7 @@ INSTALL_PROGRAM = install
# Test if the C compiler supports the option.
# Evaluates to "option" if yes, and "fallback" otherwise. TEST_CC_OPTION = $(shell \

Makefile.inc +1 -1
-	if echo 'int main(void){return 0;}' | $(CC) -o /dev/null -c "$(1)" -xc - &>/dev/null; \
+-	if echo 'int main(void){return 0;}' | $(CC) -o /dev/null -c "$(1)" -xc - >/dev/null 2>&1; \
 	then \
 		echo "$(1)"; \
 	else \
#3 lore raw

PATCH 2/2 multipath-tools: check for C compiler option -Werror=discarded-qualifiers

In reply to Mauricio Faria de Oliveira

The -Werror=discarded-qualifiers option is not supported on GCC 4.8 (ships in Ubuntu 14.04 at least). Use TEST_CC_OPTION to detect that and fix a build failure.

No regression on Ubuntu 18.04 (GCC 7.3, -Werror=discarded-qualifiers used).

Fixes ff307801

"multipath-tools: Makefile.inc: use -Werror=cast-qual"

---
 Makefile.inc | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
Makefile.inc +2 -1
index a12b46ef315e..a83f02c72ed6 100644
@@ -86,11 +86,12 @@ TEST_CC_OPTION = $(shell \
 	fi)
 
 STACKPROT := $(call TEST_CC_OPTION,-fstack-protector-strong,-fstack-protector)
+ERROR_DISCARDED_QUALIFIERS := $(call TEST_CC_OPTION,-Werror=discarded-qualifiers,)
 
 OPTFLAGS	= -O2 -g -pipe -Wall -Wextra -Wformat=2 -Werror=implicit-int \
 		  -Werror=implicit-function-declaration -Werror=format-security \
 		  -Wno-sign-compare -Wno-unused-parameter -Wno-clobbered \
-		  -Werror=cast-qual -Werror=discarded-qualifiers \
+		  -Werror=cast-qual $(ERROR_DISCARDED_QUALIFIERS) \
 		  -Wp,-D_FORTIFY_SOURCE=2 $(STACKPROT) \
 		  --param=ssp-buffer-size=4
 
Signature · 1 line
2.17.1
Reviewed-by on v1 2/2
#4 lore raw

Re: [PATCH 2/2] multipath-tools: check for C compiler option -Werror=discarded-qualifiers

Quoted 3 lines · Mauricio Faria de Oliveira

The -Werror=discarded-qualifiers option is not supported on GCC 4.8 (ships in Ubuntu 14.04 at least). Use TEST_CC_OPTION to detect that and fix a build failure.