#155 Pass --build-id=sha1 when building with clang on arm
Closed 2 years ago by tstellar. Opened 2 years ago by tstellar.
rpms/ tstellar/redhat-rpm-config clang-build-id  into  rawhide

file modified
+10
@@ -195,6 +195,16 @@ 

  side effects in ELF constructors, or for making them available to

  dynamically loaded plugins.

  

+ ### Specifying the build-id algorithm

+ 

+ If you want to specify a different build-id algorithm for your builds, you

+ can use the %_build_id_flags macro:

+ 

+     %_build_id_flags -Wl,--build-id=sha1

+ 

+ This is usually not needed, but if you link with lld instead of bfd,

+ then you need to set this flag.

+ 

  ### Strict symbol checks in the link editor (ld)

  

  Optionally, the link editor will refuse to link shared objects which

file modified
+8 -1
@@ -72,7 +72,7 @@ 

  # When clang is used as a linker driver, it does not auto-detect the LTO

  # bytecode and neither does bfd, so we need to explicitly pass the -flto

  # flag when linking.

- %build_ldflags -Wl,-z,relro %{_ld_as_needed_flags} %{_ld_symbols_flags} %{_hardened_ldflags} %{_annotation_ldflags} %[ "%{toolchain}" == "clang" ? "%{?_lto_cflags}" : "" ]

+ %build_ldflags -Wl,-z,relro %{_ld_as_needed_flags} %{_ld_symbols_flags} %{_hardened_ldflags} %{_annotation_ldflags} %[ "%{toolchain}" == "clang" ? "%{?_lto_cflags}" : "" ] %{_build_id_flags}

  

  # Expands to shell code to set the compiler/linker environment

  # variables CFLAGS, CXXFLAGS, FFLAGS, FCFLAGS, LDFLAGS if they have
@@ -325,6 +325,13 @@ 

  %_clang_lto_cflags	-flto

  %_lto_cflags		%{expand:%%{_%{toolchain}_lto_cflags}}

  

+ # Some linkers default to a build-id algoritim that is not supported by rpmbuild,

+ # so we need to specify the right algorithm to use.

+ %_gcc_build_id_flags	%{nil}

+ # Clang defaults to lld on arm, which defaults to an build-id that is too short.

+ %_clang_build_id_flags %[ "%{_target_cpu}" == "armv7hl" ? "-Wl,--build-id=sha1" : "%{nil}" ]

+ %_build_id_flags	%{expand:%%{_%{toolchain}_build_id_flags}}

+ 

  %_general_options       -O2 %{?_lto_cflags} -fexceptions -g -grecord-gcc-switches -pipe

  %_warning_options       -Wall -Werror=format-security

  %_preprocessor_defines  -Wp,-D_FORTIFY_SOURCE=2 -Wp,-D_GLIBCXX_ASSERTIONS

file modified
+4 -1
@@ -6,7 +6,7 @@ 

  

  Summary: Red Hat specific rpm configuration files

  Name: redhat-rpm-config

- Version: 204

+ Version: 205

  Release: 1%{?dist}

  # No version specified.

  License: GPL+
@@ -217,6 +217,9 @@ 

  %{_rpmconfigdir}/macros.d/macros.kmp

  

  %changelog

+ * Wed Nov 17 2021 Tom Stellard <tstellar@redhat.com> - 205-1

+ - Pass --build-id=sha1 when building with clang on arm

+ 

  * Tue Nov 16 2021 Miro Hrončok <mhroncok@redhat.com> - 204-1

  - Don't pull in Python to all buildroots

  - Remove llvm-lto-elf-check script

We need this now that clang defaults to linking with lld on arm.

Build failed. More information on how to proceed and troubleshoot errors available at https://fedoraproject.org/wiki/Zuul-based-ci

This seems fine, though the growing complexity makes me wonder if it might be time for a cleanup. (Use the same toolchain trick for `%_lto_cflags, for example, instead of having the conditional in there.)

In any case, I'll merge this manually tomorrow unless you'd like to rebase.

Please document the new linker flag in buildflags.md. Thanks.

Pull-Request has been closed by tstellar

2 years ago