Skip to content

[BUG]: Need to use different compile flags on Fedora/RHEL systems fP #873

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
smooge opened this issue Mar 26, 2025 · 3 comments
Open

[BUG]: Need to use different compile flags on Fedora/RHEL systems fP #873

smooge opened this issue Mar 26, 2025 · 3 comments
Labels

Comments

@smooge
Copy link

smooge commented Mar 26, 2025

vSomeip Version

v3.5.5

Boost Version

1.83

Environment

Fedora Linux > 33, RHEL-9, RHEL-10 gcc > 11.5.0

Describe the bug

When compiling on Red Hat associated systems, the end compile will error out unless the -fPIE option is changed to -fPIC -pie -Wl,-z,relro,-z,now [The last part may be superfluous to the bug bit the -fPIC -pie are required.] This is probably due to the overall compiler options that Fedora and RHEL packages have but I have needed to carry a patch like the following for a while:

$ less vsomeip-compiler-flags.patch
diff -up ./CMakeLists.txt.compiler-flags ./CMakeLists.txt
--- ./CMakeLists.txt.compiler-flags     2025-01-17 11:25:57.000000000 +0000
+++ ./CMakeLists.txt    2025-03-14 20:29:38.052779251 +0000
@@ -78,7 +78,7 @@ endif()
   if(NOT DEFINED _FORTIFY_SOURCE)
       set(_FORTIFY_SOURCE 2)
   endif()
-    set(OS_CXX_FLAGS "${OS_CXX_FLAGS} -D_GLIBCXX_USE_NANOSLEEP -pthread -O -Wall -Wextra -Wformat -Wformat-security -Wconversion -fexceptions -fstrict-aliasing -fstack-protector-strong -fasynchronous-unwind-tables -fno-omit-frame-pointer -D_FORTIFY_SOURCE=${_FORTIFY_SOURCE} -Wformat -Wformat-security -Wpedantic -Werror -fPIE")
+    set(OS_CXX_FLAGS "${OS_CXX_FLAGS} -D_GLIBCXX_USE_NANOSLEEP -pthread -O -Wall -Wextra -Wformat -Wformat-security -Wconversion -fexceptions -fstrict-aliasing -fstack-protector-strong -fasynchronous-unwind-tables -fno-omit-frame-pointer -D_FORTIFY_SOURCE=${_FORTIFY_SOURCE} -Wformat -Wformat-security -Wpedantic -fPIC -pie -Wl,-z,relro,-z,now")

     # force all use of std::mutex and std::recursive_mutex to use runtime init
     # instead of static initialization so mutexes can be hooked to enable PI as needed

Reproduction Steps

When trying to build an RPM of vsomeip for EPEL or Fedora ends up with errors unless the above patch is applied. Steps to redo:

  1. Install a Fedora or CentOS Stream VM.
  2. Install mock and needed required packages for vsomeip
  3. Download src.rpm from dl.fedoraproject.org which matches the needs , the older https://dl.fedoraproject.org/pub/fedora/linux/releases/41/Everything/source/tree/Packages/v/vsomeip3-3.3.8-4.fc41.src.rpm also shows this. The newer 3.5.5 is in updates-testing so may move before anyone can test this.
  4. rpm -ivh vsomeip3*src.rpm
  5. cd rpmbuild/SPECS/
  6. comment out the 'compile-time patch' which fixes this.
  7. rpmbuild -bp vsomeip3.spec
    8 mock -r fedora-41-x86_64 ../SRPMS/vsome3*src.rpm

What it fail to build

Expected behaviour

What I would like is that the CMake tests for the operating system and for specific ones (Fedora and RHEL) sets up the compile flags one way and defaults to the other elsewhere. However I am not sure if that is overall desired or wanted.

Logs and Screenshots

No response

@smooge smooge added the bug label Mar 26, 2025
@smooge
Copy link
Author

smooge commented Mar 26, 2025

I have a couple other 'bugs' which I carry patches for in the src.rpm but I want to make sure i am opening things as the project expects (aka should they be bugs to track or just PRs)

@smooge
Copy link
Author

smooge commented Mar 28, 2025

Weak attempt at a patch (it works for me but not sure if it is correct or not)

diff -up ./CMakeLists.txt.compiler-flags ./CMakeLists.txt
--- ./CMakeLists.txt.compiler-flags     2025-03-24 17:03:35.000000000 +0000
+++ ./CMakeLists.txt    2025-03-27 16:19:38.731702096 +0000
@@ -67,18 +67,20 @@ set(CMAKE_CXX_STANDARD 17)
 if (${CMAKE_SYSTEM_NAME} MATCHES "Linux")
     set(DL_LIBRARY "dl")

-if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
+  if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
     # This is only relevant for GCC and causes warnings on Clang
     set(EXPORTSYMBOLS "-Wl,-export-dynamic -Wl,--version-script=${CMAKE_CURRENT_SOURCE_DIR}/exportmap.gcc")
-    set(OS_CXX_FLAGS "${OS_CXX_FLAGS} -pie -Wno-tsan -Wl,-z,relro,-z,now")
-endif()
+    set(OS_CXX_FLAGS "${OS_CXX_FLAGS} -fPIC -pie -Wno-tsan -Wl,-z,relro,-z,now")
+  else()
+    set(OS_CXX_FLAGS "${OS_CXX_FLAGS} -fPIE")
+  endif()

     set(NO_DEPRECATED "")
     set(OPTIMIZE "")
   if(NOT DEFINED _FORTIFY_SOURCE)
       set(_FORTIFY_SOURCE 2)
   endif()
-    set(OS_CXX_FLAGS "${OS_CXX_FLAGS} -D_GLIBCXX_USE_NANOSLEEP -pthread -O -Wall -Wextra -Wformat -Wformat-security -Wconversion -fexceptions -fstrict-aliasing -fstack-protector-strong -fasynchronous-unwind-tables -fno-omit-frame-pointer -D_FORTIFY_SOURCE=${_FORTIFY_SOURCE} -Wformat -Wformat-security -Wpedantic -Werror -fPIE")
+    set(OS_CXX_FLAGS "${OS_CXX_FLAGS} -D_GLIBCXX_USE_NANOSLEEP -pthread -O -Wall -Wextra -Wformat -Wformat-security -Wconversion -fexceptions -fstrict-aliasing -fstack-protector-strong -fasynchronous-unwind-tables -fno-omit-frame-pointer -D_FORTIFY_SOURCE=${_FORTIFY_SOURCE} -Wformat -Wformat-security -Wpedantic ")

     # force all use of std::mutex and std::recursive_mutex to use runtime init
     # instead of static initialization so mutexes can be hooked to enable PI as needed

@smooge
Copy link
Author

smooge commented Apr 3, 2025

#879 is an attempt to fix this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant