Skip to content
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

libcap: avoid %optflags macro #375

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from

Conversation

bcressey
Copy link
Contributor

Issue number:
Related: bottlerocket-os/bottlerocket-sdk#244

Description of changes:
%optflags is the result of augmenting %__global_compiler_flags with arch-specific flags. These may not work when cross-compiling as the target arch may not match the host arch.

Switch to the baseline %__global_compiler_flags instead. These flags are only relevant when compiling software for the host, which should not be included in the final set of packaged artifacts, so any missed optimizations are not a concern.

Testing done:
Before this change, cross-compiling for x86_64 on an aarch64 build host fails with this error:

  0.306 gcc -O2 -flto=auto -ffat-lto-objects -fexceptions -g -grecord-gcc-switches -pipe -Wall -Wno-complain-wrong-lang -Werror=format-security -Wp,-U_FORTIFY_SOURCE,-D_FORTIFY_SOURCE=3 -Wp,-D_GLIBCXX_ASSERTIONS -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -fstack-protector-strong -specs=/usr/lib/rpm/redhat/redhat-annobin-cc1  -m64 -march=x86-64 -mtune=generic -fasynchronous-unwind-tables -fstack-clash-protection -fcf-protection -mtls-dialect=gnu2 -fno-omit-frame-pointer -mno-omit-leaf-frame-pointer -Dlinux -Wall -Wwrite-strings -Wpointer-arith -Wcast-qual -Wcast-align -Wstrict-prototypes -Wmissing-prototypes -Wnested-externs -Winline -Wshadow -Wunreachable-code  -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 -I/home/builder/rpmbuild/BUILD/bottlerocket-libcap-2.70-build/libcap-2.70/libcap/../libcap/include/uapi -I/home/builder/rpmbuild/BUILD/bottlerocket-libcap-2.70-build/libcap-2.70/libcap/../libcap/include _makenames.c -o _makenames
  0.308 gcc: error: unrecognized argument in option ‘-mtls-dialect=gnu2’
  0.308 gcc: note: valid arguments to ‘-mtls-dialect=’ are: desc trad
  0.309 make[1]: *** [Makefile:79: _makenames] Error 1

After, the build succeeds.

Terms of contribution:

By submitting this pull request, I agree that this contribution is dual-licensed under the terms of both the Apache License, version 2.0, and the MIT license.

%optflags is the result of augmenting %__global_compiler_flags with
arch-specific flags. These may not work when cross-compiling as the
target arch may not match the host arch.

Switch to the baseline %__global_compiler_flags instead. These flags
are only relevant when compiling software for the host, which should
not be included in the final set of packaged artifacts, so any missed
optimizations are not a concern.

Signed-off-by: Ben Cressey <[email protected]>
@bcressey bcressey requested review from KCSesh and yeazelm February 13, 2025 18:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant