intel / ledmon

Enclosure LED Utilities
GNU General Public License v2.0
72 stars 49 forks source link

configure.ac: use AX_CHECK_LINK_FLAG() to test gcc flags #244

Closed tpetazzoni closed 3 months ago

tpetazzoni commented 3 months ago

ledmon's configure.ac defines an AX_AM_CFLAGS_ADD() macro that allows to test if a flag is supported by gcc, and if so add it to AM_CFLAGS. In order to test if the flag works, it uses AX_CHECK_COMPILE_FLAG(), which only does a compile test, but not a link test. However, some flags such as -fstack-protector might appear to work at compile time, but not link time. Therefore -fstack-protector is considered functional:

checking whether C compiler accepts -fstack-protector-strong... yes

but the build later fails:

/home/buildroot/autobuild/instance-0/output-1/host/lib/gcc/m68k-buildroot-linux-uclibc/13.3.0/../../../../m68k-buildroot-linux-uclibc/bin/ld: cannot find -lssp_nonshared: No such file or directory /home/buildroot/autobuild/instance-0/output-1/host/lib/gcc/m68k-buildroot-linux-uclibc/13.3.0/../../../../m68k-buildroot-linux-uclibc/bin/ld: cannot find -lssp: No such file or directory collect2: error: ld returned 1 exit status

In order to fix this, we test all flags with AX_CHECK_LINK_FLAG() which does a full link of the test program. This allows to make sure that the flag is fully functional. In our test case, -fstack-protector-strong will be determined as being non-functional, and therefore won't be used.

mtkaczyk commented 3 months ago

Hello @tpetazzoni, Please rebase it to latest upstream because our review action is failing. LGTM.

Thanks for fix!

tpetazzoni commented 3 months ago

Sorry, I had based my patch on "master", not seeing that development is now happening in "main". I forced pushed the branch, now based on "main". Let me know if that works for you!

mtkaczyk commented 3 months ago

I rebased master to main right now. Sorry for that, I have to automatize syncing.