I am trying to run the unit tests for an application (that is only header files) in the%check section of the RPM spec file, running cmake on both gcc and clang with %optflags macro on Fedora rawhide.
According to the guideline https://docs.fedoraproject.org/en-US/packaging-guidelines/#_compiler_flags , it seems %optflags macro works with both gcc and clang without the restriction for a specific compiler.
This cmake command for gcc works.
``` CC=gcc CXX=g++ cmake .. \ -DCMAKE_VERBOSE_MAKEFILE:BOOL=ON \ -DCMAKE_C_FLAGS="%{optflags}" \ -DCMAKE_CXX_FLAGS="%{optflags}" %make_build ```
But this cmake command for clang does not work with the error "clang-10: error: unknown argument: '-fstack-clash-protection'". The used clang version is 10.0.0. Should %{optflags} work for both gcc and clang? Is it a bug of the %optflags macro?
``` CC=clang CXX=clang++ cmake .. \ -DCMAKE_VERBOSE_MAKEFILE:BOOL=ON \ -DCMAKE_C_FLAGS="%{optflags}" \ -DCMAKE_CXX_FLAGS="%{optflags}" %make_build ```
The log is here.
``` + CC=clang + CXX=clang++ + cmake .. -DCMAKE_VERBOSE_MAKEFILE:BOOL=ON '-DCMAKE_C_FLAGS=-O2 -g -pipe -Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -Wp,-D_GLIBCXX_ASSERTIONS -fexceptions -fstack-protector-strong -grecord-gcc-switches -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -specs=/usr/lib/rpm/redhat/redhat-annobin-cc1 -m64 -mtune=generic -fasynchronous-unwind-tables -fstack-clash-protection -fcf-protection' '-DCMAKE_CXX_FLAGS=-O2 -g -pipe -Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -Wp,-D_GLIBCXX_ASSERTIONS -fexceptions -fstack-protector-strong -grecord-gcc-switches -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -specs=/usr/lib/rpm/redhat/redhat-annobin-cc1 -m64 -mtune=generic -fasynchronous-unwind-tables -fstack-clash-protection -fcf-protection' -- The C compiler identification is Clang 10.0.0 -- The CXX compiler identification is Clang 10.0.0 -- Check for working C compiler: /usr/bin/clang -- Check for working C compiler: /usr/bin/clang - broken CMake Error at /usr/share/cmake/Modules/CMakeTestCCompiler.cmake:60 (message): The C compiler "/usr/bin/clang" is not able to compile a simple test program. It fails with the following output: Change Dir: /builddir/build/BUILD/simde-0d632e1e0bd0a258ce3d3e240fbec4dd71234819/test/build-clang/CMakeFiles/CMakeTmp ---- Run Build Command(s):/usr/bin/gmake cmTC_686bc/fast && /usr/bin/gmake -f CMakeFiles/cmTC_686bc.dir/build.make CMakeFiles/cmTC_686bc.dir/build gmake[1]: Entering directory '/builddir/build/BUILD/simde-0d632e1e0bd0a258ce3d3e240fbec4dd71234819/test/build-clang/CMakeFiles/CMakeTmp' Building C object CMakeFiles/cmTC_686bc.dir/testCCompiler.c.o /usr/bin/clang -O2 -g -pipe -Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -Wp,-D_GLIBCXX_ASSERTIONS -fexceptions -fstack-protector-strong -grecord-gcc-switches -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -specs=/usr/lib/rpm/redhat/redhat-annobin-cc1 -m64 -mtune=generic -fasynchronous-unwind-tables -fstack-clash-protection -fcf-protection -o CMakeFiles/cmTC_686bc.dir/testCCompiler.c.o -c /builddir/build/BUILD/simde-0d632e1e0bd0a258ce3d3e240fbec4dd71234819/test/build-clang/CMakeFiles/CMakeTmp/testCCompiler.c clang-10: error: unknown argument: '-fstack-clash-protection' gmake[1]: *** [CMakeFiles/cmTC_686bc.dir/build.make:83: CMakeFiles/cmTC_686bc.dir/testCCompiler.c.o] Error 1 gmake[1]: Leaving directory '/builddir/build/BUILD/simde-0d632e1e0bd0a258ce3d3e240fbec4dd71234819/test/build-clang/CMakeFiles/CMakeTmp' gmake: *** [Makefile:138: cmTC_686bc/fast] Error 2 ```
Thanks.
On Sat, Apr 4, 2020 at 5:41 PM Jun Aruga jaruga@redhat.com wrote:
I am trying to run the unit tests for an application (that is only header files) in the%check section of the RPM spec file, running cmake on both gcc and clang with %optflags macro on Fedora rawhide.
According to the guideline https://docs.fedoraproject.org/en-US/packaging-guidelines/#_compiler_flags , it seems %optflags macro works with both gcc and clang without the restriction for a specific compiler.
The compiler flags Fedora sets are not compatible with Clang without you doing filtering. Unfortunately, Clang hasn't been very good at implementing some of the security features that we rely on in Fedora from the system compiler, and it also does not support the specs we pass to force certain build and link behaviors. Finally, of course it doesn't support annobin.
The specific flags enabled are documented here: https://src.fedoraproject.org/rpms/redhat-rpm-config/blob/master/f/buildflag...
-- 真実はいつも一つ!/ Always, there's only one truth!
The compiler flags Fedora sets are not compatible with Clang without you doing filtering. Unfortunately, Clang hasn't been very good at implementing some of the security features that we rely on in Fedora from the system compiler, and it also does not support the specs we pass to force certain build and link behaviors. Finally, of course it doesn't support annobin.
The specific flags enabled are documented here: https://src.fedoraproject.org/rpms/redhat-rpm-config/blob/master/f/buildflag...
Thanks for sharing the info.
I confirmed that the following commands worked by filtering %optflags.
``` optflags_clang=$(echo "%{optflags}" | sed -e 's| -fstack-clash-protection||' -e 's| -specs=[^ ]*||g') CC=clang CXX=clang++ cmake .. \ -DCMAKE_VERBOSE_MAKEFILE:BOOL=ON \ -DCMAKE_C_FLAGS="${optflags_clang}" \ -DCMAKE_CXX_FLAGS="${optflags_clang}" %make_build ```
What do you think about adding the following macros in rpms/redhat-rpm-config? I think it's useful for people who want to build their RPM package not by gcc but for some reasons. rpms/ruby might be the case to build with clang near feature, because gcc's PIE is not compatible with Ruby's just-in-time (JIT) feature using pre-compiler-header (PCH) [1].
``` %{build_clang_cflags} %{build_clang_cxxflags} %{clang_optflags} ```
[1] https://bugzilla.redhat.com/show_bug.cgi?id=1721553#c34
-- Jun | He - His - Him
* Jun Aruga:
What do you think about adding the following macros in rpms/redhat-rpm-config? I think it's useful for people who want to build their RPM package not by gcc but for some reasons. rpms/ruby might be the case to build with clang near feature, because gcc's PIE is not compatible with Ruby's just-in-time (JIT) feature using pre-compiler-header (PCH) [1].
%{build_clang_cflags} %{build_clang_cxxflags} %{clang_optflags}
I don't think the flag-based approach can be made to work if we support different system compilers. We will need something else instead. While the flag names largely overlap, their behavior differs. And due to lack of compiler specs file support in Clang, the PIE flag handling simply cannot be implemented in Clang directly, while still having Clang to default to non-PIE.
I don't know what the current state of Fedora multi-compiler support is. Has there been a change that allows packages to build with Clang instead of Clang even if there is no immediate technical requirement to do so? (If yes, it has not been reflected in the packaging guidelines.)
Thanks, Florian
Hi Guys,
FYI: I have already opened a pull request to enhance redhat-rpm-config to allow packages to build with clang instead of gcc if they so wish:
https://src.fedoraproject.org/rpms/redhat-rpm-config/pull-request/82
The patch makes use of clang's CCC_OVERIDE_OPTIONS to process the options that are normally passed to gcc as well loading clang specific options from a configuration file. The patch also creates variables called __cc, __cxx and __cpp which are initialised as might be expected, but which a package could override to point to some other compiler should it wish to do so.
Cheers Nick
On Mon, Apr 06, 2020 at 11:50:53AM +0100, Nick Clifton wrote:
Hi Guys,
FYI: I have already opened a pull request to enhance redhat-rpm-config to allow packages to build with clang instead of gcc if they so wish:
https://src.fedoraproject.org/rpms/redhat-rpm-config/pull-request/82
The patch makes use of clang's CCC_OVERIDE_OPTIONS to process the options that are normally passed to gcc as well loading clang specific options from a configuration file. The patch also creates variables called __cc, __cxx and __cpp which are initialised as might be expected, but which a package could override to point to some other compiler should it wish to do so.
keep in mind https://docs.fedoraproject.org/en-US/packaging-guidelines/#compiler
kevin
FYI: I have already opened a pull request to enhance redhat-rpm-config to allow packages to build with clang instead of gcc if they so wish:
https://src.fedoraproject.org/rpms/redhat-rpm-config/pull-request/82
The `%define with_cc_clang 1` approach in the PR looks better than the flag-based approach. Thanks for work!
keep in mind https://docs.fedoraproject.org/en-US/packaging-guidelines/#compiler
We might also need to add the note about %{build_cflags}, %{build_cxxflags} and etc in the guidelines that are written in https://src.fedoraproject.org/rpms/redhat-rpm-config/blob/master/f/buildflag... .
Cheers, Jun
* Jun Aruga:
We might also need to add the note about %{build_cflags}, %{build_cxxflags} and etc in the guidelines that are written in https://src.fedoraproject.org/rpms/redhat-rpm-config/blob/master/f/buildflag... .
Please do. It's been more than two years:
https://pagure.io/packaging-committee/issue/743
Thanks, Florian
On Mon, Apr 20, 2020 at 10:51 AM Florian Weimer fweimer@redhat.com wrote:
- Jun Aruga:
We might also need to add the note about %{build_cflags}, %{build_cxxflags} and etc in the guidelines that are written in https://src.fedoraproject.org/rpms/redhat-rpm-config/blob/master/f/buildflag... .
Please do. It's been more than two years:
Note that I included a link to buildflags.md when I rewrote the RPMMacros page in the Packaging Guidelines a while back: https://docs.fedoraproject.org/en-US/packaging-guidelines/RPMMacros/#_macros...
The section about compiler flags in the general Packaging Guidelines seems to be outdated, though: https://docs.fedoraproject.org/en-US/packaging-guidelines/#_compiler_flags
Without any concrete proposals for changes it's hard for FPC to "just know" what needs to be done, or how. If you could open a PR against the Packaging Guidelines for the changes you want, that would be great.
Thanks, Fabio
Thanks, Florian _______________________________________________ packaging mailing list -- packaging@lists.fedoraproject.org To unsubscribe send an email to packaging-leave@lists.fedoraproject.org Fedora Code of Conduct: https://docs.fedoraproject.org/en-US/project/code-of-conduct/ List Guidelines: https://fedoraproject.org/wiki/Mailing_list_guidelines List Archives: https://lists.fedoraproject.org/archives/list/packaging@lists.fedoraproject....
packaging@lists.fedoraproject.org