cyrusimap / cyrus-sasl

Other
128 stars 146 forks source link

Non-portable and (likely) redudant compile time flag passed to AM_CPPFLAGS #798

Closed michael-o closed 10 months ago

michael-o commented 11 months ago

When compiling version 2.1.28 on HP-UX I see the following warnings:

libtool: compile:  /opt/aCC/bin/aCC -Ae -DHAVE_CONFIG_H -I. -I.. -fPIC -I../include -I../include -I/opt/ports/include -I/opt/openssl/include -I/opt/ports/include +We901 -c +Maked crypto-compat.c  -DPIC -o .libs/crypto-compat.o
aCC: warning 901: unknown option: `-fPIC': use +help for online documentation.

-fPIC is not valid for HP aCC, one needs to pass another flag (+z). The source of it is in

$ grep -r fPIC .
./common/Makefile.am:AM_CPPFLAGS=-fPIC -I$(top_srcdir)/include -I$(top_builddir)/include
./sasldb/Makefile.am:AM_CPPFLAGS=-DLIBSASL_EXPORTS=1 -fPIC -I$(top_srcdir)/include -I$(top_builddir)/include @SASL_DB_INC@

-fPIC isn't a preprocessor flag, but rather a compiler flag. Regardless of this, I consider it redunant since it affects only libtool calls and m4/libtool.m4 will properly determine the required PIC flag for the platform and compiler and supply it to $pic_flag:

./libtool:pic_flag=" -fPIC -DPIC"
./libtool:archive_cmds="\$CC -shared \$pic_flag \$libobjs \$deplibs \$compiler_flags \$wl-soname \$wl\$soname -o \$lib"
./libtool:archive_expsym_cmds="\$CC -shared \$pic_flag \$libobjs \$deplibs \$compiler_flags \$wl-soname \$wl\$soname \$wl-retain-symbols-file \$wl\$export_symbols -o \$lib"
./libtool:      command="$base_compile $qsrcfile $pic_flag"
./libtool:      command="$base_compile $qsrcfile $pic_flag"
./libtool:      pic_flag_for_symtable=
./libtool:        # compiling the symbol table file with pic_flag works around
./libtool:        # pic_flag when linking with -static.  The problem exists in
./libtool:          pic_flag_for_symtable=" $pic_flag -DFREEBSD_WORKAROUND" ;;
./libtool:          pic_flag_for_symtable=" $pic_flag"  ;;
./libtool:          $my_pic_p && pic_flag_for_symtable=" $pic_flag"
./libtool:      func_show_eval '(cd $output_objdir && $LTCC$symtab_cflags -c$no_builtin_flag$pic_flag_for_symtable "$my_dlsyms")' 'exit $?'
./libtool:        if test -z "$pic_flag" && test -n "$link_static_flag"; then
./libtool:        if test -z "$pic_flag" && test -n "$link_static_flag"; then
./libtool:      test -z "$pic_flag" && libobjs=`$ECHO "$libobjs" | $SP2NL | $SED "$lo2o" | $NL2SP`
./libtool:      if test -n "$pic_flag" || test default != "$pic_mode"; then

I have removed th flag in question on FreeBSD and here is a diff of the make invocation output:

--- out 2023-08-21 21:49:05.032630000 +0200
+++ out 2023-08-21 21:57:48.413123000 +0200
@@ -16 +16 @@
-/bin/sh ../libtool  --tag=CC   --mode=compile cc -DHAVE_CONFIG_H -I. -I..  -DLIBSASL_EXPORTS=1 -fPIC -I../include -I../include  -DOBSOLETE_CRAM_ATTR=1 -DOBSOLETE_DIGEST_ATTR=1  -Wall -W -g -O2 -MT allockey.lo -MD -MP -MF $depbase.Tpo -c -o allockey.lo allockey.c &&\
+/bin/sh ../libtool  --tag=CC   --mode=compile cc -DHAVE_CONFIG_H -I. -I..  -DLIBSASL_EXPORTS=1 -I../include -I../include  -DOBSOLETE_CRAM_ATTR=1 -DOBSOLETE_DIGEST_ATTR=1  -Wall -W -g -O2 -MT allockey.lo -MD -MP -MF $depbase.Tpo -c -o allockey.lo allockey.c &&\
@@ -18 +18 @@
-libtool: compile:  cc -DHAVE_CONFIG_H -I. -I.. -DLIBSASL_EXPORTS=1 -fPIC -I../include -I../include -DOBSOLETE_CRAM_ATTR=1 -DOBSOLETE_DIGEST_ATTR=1 -Wall -W -g -O2 -MT allockey.lo -MD -MP -MF .deps/allockey.Tpo -c allockey.c  -fPIC -DPIC -o .libs/allockey.o
+libtool: compile:  cc -DHAVE_CONFIG_H -I. -I.. -DLIBSASL_EXPORTS=1 -I../include -I../include -DOBSOLETE_CRAM_ATTR=1 -DOBSOLETE_DIGEST_ATTR=1 -Wall -W -g -O2 -MT allockey.lo -MD -MP -MF .deps/allockey.Tpo -c allockey.c  -fPIC -DPIC -o .libs/allockey.o
@@ -20 +20 @@
-/bin/sh ../libtool  --tag=CC   --mode=compile cc -DHAVE_CONFIG_H -I. -I..  -DLIBSASL_EXPORTS=1 -fPIC -I../include -I../include  -DOBSOLETE_CRAM_ATTR=1 -DOBSOLETE_DIGEST_ATTR=1  -Wall -W -g -O2 -MT db_ndbm.lo -MD -MP -MF $depbase.Tpo -c -o db_ndbm.lo db_ndbm.c &&\
+/bin/sh ../libtool  --tag=CC   --mode=compile cc -DHAVE_CONFIG_H -I. -I..  -DLIBSASL_EXPORTS=1 -I../include -I../include  -DOBSOLETE_CRAM_ATTR=1 -DOBSOLETE_DIGEST_ATTR=1  -Wall -W -g -O2 -MT db_ndbm.lo -MD -MP -MF $depbase.Tpo -c -o db_ndbm.lo db_ndbm.c &&\
@@ -22 +22 @@
-libtool: compile:  cc -DHAVE_CONFIG_H -I. -I.. -DLIBSASL_EXPORTS=1 -fPIC -I../include -I../include -DOBSOLETE_CRAM_ATTR=1 -DOBSOLETE_DIGEST_ATTR=1 -Wall -W -g -O2 -MT db_ndbm.lo -MD -MP -MF .deps/db_ndbm.Tpo -c db_ndbm.c  -fPIC -DPIC -o .libs/db_ndbm.o
+libtool: compile:  cc -DHAVE_CONFIG_H -I. -I.. -DLIBSASL_EXPORTS=1 -I../include -I../include -DOBSOLETE_CRAM_ATTR=1 -DOBSOLETE_DIGEST_ATTR=1 -Wall -W -g -O2 -MT db_ndbm.lo -MD -MP -MF .deps/db_ndbm.Tpo -c db_ndbm.c  -fPIC -DPIC -o .libs/db_ndbm.o
@@ -31 +31 @@
-/bin/sh ../libtool  --tag=CC   --mode=compile cc -DHAVE_CONFIG_H -I. -I..  -fPIC -I../include -I../include -DOBSOLETE_CRAM_ATTR=1 -DOBSOLETE_DIGEST_ATTR=1  -Wall -W -g -O2 -MT plugin_common.lo -MD -MP -MF $depbase.Tpo -c -o plugin_common.lo plugin_common.c &&\
+/bin/sh ../libtool  --tag=CC   --mode=compile cc -DHAVE_CONFIG_H -I. -I..  -I../include -I../include -DOBSOLETE_CRAM_ATTR=1 -DOBSOLETE_DIGEST_ATTR=1  -Wall -W -g -O2 -MT plugin_common.lo -MD -MP -MF $depbase.Tpo -c -o plugin_common.lo plugin_common.c &&\
@@ -33 +33 @@
-libtool: compile:  cc -DHAVE_CONFIG_H -I. -I.. -fPIC -I../include -I../include -DOBSOLETE_CRAM_ATTR=1 -DOBSOLETE_DIGEST_ATTR=1 -Wall -W -g -O2 -MT plugin_common.lo -MD -MP -MF .deps/plugin_common.Tpo -c plugin_common.c  -fPIC -DPIC -o .libs/plugin_common.o
+libtool: compile:  cc -DHAVE_CONFIG_H -I. -I.. -I../include -I../include -DOBSOLETE_CRAM_ATTR=1 -DOBSOLETE_DIGEST_ATTR=1 -Wall -W -g -O2 -MT plugin_common.lo -MD -MP -MF .deps/plugin_common.Tpo -c plugin_common.c  -fPIC -DPIC -o .libs/plugin_common.o
@@ -40 +40 @@
-/bin/sh ../libtool  --tag=CC   --mode=compile cc -DHAVE_CONFIG_H -I. -I..  -fPIC -I../include -I../include -DOBSOLETE_CRAM_ATTR=1 -DOBSOLETE_DIGEST_ATTR=1  -Wall -W -g -O2 -MT crypto-compat.lo -MD -MP -MF $depbase.Tpo -c -o crypto-compat.lo crypto-compat.c &&\
+/bin/sh ../libtool  --tag=CC   --mode=compile cc -DHAVE_CONFIG_H -I. -I..  -I../include -I../include -DOBSOLETE_CRAM_ATTR=1 -DOBSOLETE_DIGEST_ATTR=1  -Wall -W -g -O2 -MT crypto-compat.lo -MD -MP -MF $depbase.Tpo -c -o crypto-compat.lo crypto-compat.c &&\
@@ -42 +42 @@
-libtool: compile:  cc -DHAVE_CONFIG_H -I. -I.. -fPIC -I../include -I../include -DOBSOLETE_CRAM_ATTR=1 -DOBSOLETE_DIGEST_ATTR=1 -Wall -W -g -O2 -MT crypto-compat.lo -MD -MP -MF .deps/crypto-compat.Tpo -c crypto-compat.c  -fPIC -DPIC -o .libs/crypto-compat.o
+libtool: compile:  cc -DHAVE_CONFIG_H -I. -I.. -I../include -I../include -DOBSOLETE_CRAM_ATTR=1 -DOBSOLETE_DIGEST_ATTR=1 -Wall -W -g -O2 -MT crypto-compat.lo -MD -MP -MF .deps/crypto-compat.Tpo -c crypto-compat.c  -fPIC -DPIC -o .libs/crypto-compat.o

As you can see, -fPIC -DPIC are still present because generated libtool does contain it.

I believe it can be safely removed and improve portability. A PR has been provided.