opensvc / multipath-tools

Other
60 stars 48 forks source link

Support -D_FORTIFY_SOURCE=3 #29

Closed marxin closed 2 years ago

marxin commented 2 years ago

I'm experimenting with -D_FORTIFY_SOURCE=3 that will be available since GCC 12.1 and I see the following error:

[   18s] cc --std=gnu99  -O2 -Wall -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=3 -fstack-protector-strong -funwind-tables -fasynchronous-unwind-tables -fstack-clash-protection -Werror=return-type  -g -Werror -Wall -Wextra -Wformat=2 -Wformat-overflow=2 -Werror=implicit-int -Werror=implicit-function-declaration -Werror=format-security -Wno-clobbered -Wno-error=clobbered -Werror=cast-qual -Werror=discarded-qualifiers -pipe -DBIN_DIR=\"/usr/sbin\" -DLIB_STRING=\"lib64\" -DRUN_DIR=\"run\" -MMD -MP -fPIE -DPIE -I. -I../libmultipath -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 -DLIBDM_API_COOKIE -Wp,-D_FORTIFY_SOURCE=2 -c -o unixware.o unixware.c
[   18s] <command-line>: error: "_FORTIFY_SOURCE" redefined [-Werror]
[   18s] <command-line>: note: this is the location of the previous definition

Note I pass the -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=3 as part of make OPTFLAGS=...

@siddhesh

mwilck commented 2 years ago

Well, it's not exactly an "OPTFLAG", right? Perhaps you need to patch Makefile.inc.

marxin commented 2 years ago

I think the simplest patch would be changing -Wp,-D_FORTIFY_SOURCE=2 to -D_FORTIFY_SOURCE=2. Then one would be able to unset it with U_FORTIFY_SOURCE.

mwilck commented 2 years ago

Sounds ok. Would you send a patch to dm-devel (cc me & bmarzins at redhat.com)?

marxin commented 2 years ago

Sure, I've just done that.

mwilck commented 2 years ago

@bmarzins , FTR: the -Wp syntax has been added by your commit 1fce669 ("multipath: Build with standard rpm cflags") a long time ago. Any idea why you were using this rather than simply -D_FORTIFY_SOURCE=2 ?

bmarzins commented 2 years ago

Don't recall, and I have no objection to changing it.

siddhesh commented 2 years ago

Since it is rpm cflags, it may be because the default flags set in redhat-rpm-config in Fedora has the flags with the -Wp syntax. FWIW, it should be possible to unset and reset the macro with -Wp too, e.g. with -Wp,-U_FORTIFY_SOURCE,-D_FORTIFY_SOURCE=3

marxin commented 2 years ago

I can confirm that gcc -Wp,-D_FORTIFY_SOURCE=2 -Wp,-U_FORTIFY_SOURCE,-D_FORTIFY_SOURCE=3 a.c -Werror works, but still, I would like to have a unified approach for enabling of -D_FORTIFY_SOURCE=3. So please accept my patch.

mwilck commented 2 years ago

pushed to openSUSE/multipath-tools (queue). Will be included in next bunch of fixes.

marxin commented 2 years ago

@mwilck Please close this issue once the queue lands to master.

mwilck commented 2 years ago

It turns out that the proposed patch didn't work as intended. Updated the fix for #29 to d13d154.