Bug 2192118 - .spec file niggle: please do not reference /usr/include/bfd.h in RPM spec file: think '%define _prefix ...'
Summary: .spec file niggle: please do not reference /usr/include/bfd.h in RPM spec fil...
Keywords:
Status: CLOSED ERRATA
Alias: None
Product: Fedora
Classification: Fedora
Component: binutils
Version: rawhide
Hardware: Unspecified
OS: Linux
unspecified
high
Target Milestone: ---
Assignee: Nick Clifton
QA Contact: Fedora Extras Quality Assurance
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2023-04-29 17:56 UTC by Jason Vas Dias
Modified: 2023-10-18 01:45 UTC (History)
6 users (show)

Fixed In Version: binutils-2.39-12.fc38 binutils-2.38-27.fc37 binutils-2.39-15.fc38
Clone Of:
Environment:
Last Closed: 2023-05-09 01:38:32 UTC
Type: ---
Embargoed:


Attachments (Terms of Use)

Description Jason Vas Dias 2023-04-29 17:56:18 UTC
Here is an excerpt from a binutils-2.40 rpmbuild log, where I have defined:
 $ rpmbuild --define '_prefix /usr/local' ... -ba SPECS/binutils.spec ...
:
+ grep '^#define BFD_ARCH_SIZE 64$' /home/adm-jason/rpmbuild/BUILDROOT/binutils-2.40-7.el8.x86_64/usr/include/bfd.h
grep: /home/adm-jason/rpmbuild/BUILDROOT/binutils-2.40-7.el8.x86_64/usr/include/bfd.h: No such file or directory
error: Bad exit status from /var/tmp/rpm-tmp.G6bnwz (%install)

Somehow the test scripts are not picking up redefined $PREFIX .

Also, (separate issue), all 'slice' tests fail on the platform I am building on:
Rocky RHEL 8.


Reproducible: Always

Steps to Reproduce:
1. Try to build rawhide binutils with different '%_prefix' definition.

Actual Results:  
Build fails with above error.

Expected Results:  
Build should succeed.

Comment 1 Jason Vas Dias 2023-04-29 18:08:53 UTC
This is @ line 986 of .spec file :

	# Sanity check --enable-64-bit-bfd really works.
        grep '^#define BFD_ARCH_SIZE 64$' $local_incdir/bfd.h
        # Fix multilib conflicts of generated values by __WORDSIZE-based expressions.


why isn't $local_incdir being set correctly ? :

@ line 898: 

%install

# install_binutils()
#       Install the binutils.
#        $1 is the target architecture
#        $2 is 1 if this is a native build
#        $3 is 1 if shared libraries should be built
#
install_binutils()
{
    local target="$1"
    local native="$2"
    local shared="$3"

    local local_root=%{buildroot}/usr
                                 ^--  Oops! should be %{buildroot}/%{_prefix} !

Comment 2 Jason Vas Dias 2023-04-29 18:23:31 UTC
With the above change, the build succeeds.

How I am building:

  $  export RPM_OPT_FLAGS=`rpm --eval '%{echo: %{_native_opt_flags_x86_64_}}'`
  $  rpm --eval '%{echo: %{_native_opt_flags_x86_64_}}' 
    -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  -fasynchronous-unwind-tables -fstack-clash-protection -fcf-protection -march=x86-64 -mtune=native -O3 -g

  $ which gcc
  /opt/rh/gcc-toolset-12/root/usr/bin/gcc
   
  $ rpmbuild --define 'optflags '"$RPM_OPT_FLAGS" --define '_prefix /usr/local' -bi --noclean --noprep --nocheck --short-circuit SPECS/binutils.spec 2>&1 | tee LOGS/binutils-2.40.el8.bi.log

 (my ~/.rpmmacros contains:
  $ cat ~/.rpmmacros
# There is no way to redefine 'optflags' to this without infinite recursion, insided same rpm instance ! :
%_native_opt_flags_x86_64_ %(echo %{optflags x86_64} | sed -r 's/[[:space:]]?-m(tune|arch)=[^[:space:]]+/ /;s/[[:space:]]?-O[0-5]?[[:space:]]/ /g;s/[[:space:]]?-g[0-5]?[[:space:]]/ /g') -march=x86-64 -mtune=native -O3 -g

   I have built glibc and cross-gcc(12) and cross-binutils(2.38) with these flags, all tests pass, glibc performs about 20% faster with these flags.
 ).

 (short circuit must be added to redo install with edited .spec file) - this now works, as does producing the RPMs if '-bb' is substituted for '-bi' .


adm-jason@devbox01:~/rpmbuild] [966314] 19:13:40 [#:475!:13201]{0}	
$ declare -p
declare -- BASH="/usr/bin/bash"
declare -r BASHOPTS="cmdhist:complete_fullquote:expand_aliases:extquote:force_fignore:histappend:hostcomplete:interactive_comments:lithist:progcomp:promptvars:sourcepath"
declare -ir BASHPID
declare -A BASH_ALIASES=()
declare -a BASH_ARGC=()
declare -a BASH_ARGV=()
declare -A BASH_CMDS=()
declare -- BASH_COMMAND
declare -a BASH_LINENO=()
declare -a BASH_SOURCE=()
declare -- BASH_SUBSHELL
declare -ar BASH_VERSINFO=([0]="4" [1]="4" [2]="20" [3]="1" [4]="release" [5]="x86_64-redhat-linux-gnu")
declare -- BASH_VERSION="4.4.20(1)-release"
declare -x CC="gcc"
declare -x CFLAGS="-std=gnu17 -march=x86-64 -mtune=native -O3 -g -fPIC -DPIC -pipe"
declare -x CLANG="clang"
declare -- COLUMNS="159"
declare -- COMP_WORDBREAKS
declare -x CXX="g++"
declare -x CXXFLAGS="-std=gnu++17 -march=x86-64 -mtune=native -O3 -g -fPIC -DPIC -pipe"
declare -a DIRSTACK=()
declare -x DISPLAY=":6"
declare -x EDITOR="emacs -nw -l ~adm-jason/emacs-text-mode.el"
declare -ir EUID="1003"
declare -a FUNCNAME
declare -a GROUPS=()
declare -i HISTCMD
declare -- HISTFILE="/home/adm-jason/.bash_history"
declare -- HISTFILESIZE="1000000000"
declare -x HISTSIZE="1000000000"
declare -x HOME="/home/adm-jason"
declare -x HOST=""
declare -- HOSTNAME="devbox01"
declare -- HOSTTYPE="x86_64"
declare -- IFS=" 	
"
declare -x LDFLAGS="-O3 -g -flto -fpic -L/opt/rh/gcc-toolset-12/root/usr/lib64 -L/opt/rh/gcc-toolset-12/root/usr/lib/gcc/x86_64-redhat-linux/12 -B/opt/rh/gcc-toolset-12/root/usr/lib/gcc/x86_64-redhat-linux/12 -Wl,-rpath,/opt/rh/gcc-toolset-12/root/usr/lib64:/opt/rh/gcc-toolset-12/root/usr/lib/gcc/x86_64-redhat-linux/12"
declare -i LINENO
declare -- LINES="55"
declare -- MACHTYPE="x86_64-redhat-linux-gnu"
declare -i MAILCHECK="60"
declare -x OLDPWD="/home/adm-jason/rpmbuild/SRPMS"
declare -- OPTERR="1"
declare -i OPTIND="1"
declare -- OSTYPE="linux-gnu"
declare -x PAGER="less -Xr"
declare -x PATH="/opt/rh/gcc-toolset-12/root/usr/bin:/usr/bin:/usr/sbin"
declare -a PIPESTATUS=([0]="0")
declare -ir PPID="10484"
declare -x PROMPT_COMMAND="printf \"\\033]0;%s@%s:%s\\007\" \"\${USER}\" \"\${HOSTNAME}\" \"\${PWD/#\$HOME/~} [\$\$]\""
declare -x PS1="\${_fc_}[\${USER}@\${HOSTNAME}\${_fn_}:\${_fg_}\\w] [\$\$] \\t [#:\\#!:\\!]{\$?}\${_tab_}\${_fcy_}\$(__git_ps1)\${_fn_}
\$ "
declare -- PS2="> "
declare -- PS4="+ "
declare -x PWD="/home/adm-jason/rpmbuild"
declare -i RANDOM
declare -x RPM_OPT_FLAGS="  -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  -fasynchronous-unwind-tables -fstack-clash-protection -fcf-protection -march=x86-64 -mtune=native -O3 -g"
declare -- SECONDS
declare -- SHELL="/bin/bash"
declare -r SHELLOPTS="braceexpand:emacs:hashall:histexpand:history:interactive-comments:monitor"
declare -x SHLVL="1"
declare -x TERM="xterm-256color"
declare -ir UID="1003"
declare -x USER="adm-jason"
declare -x V="1"
declare -x VERBOSE="255"
declare -i WITH_GIT_PS1="0"
declare -x XDG_RUNTIME_DIR="/run/user/1003"
declare -- _="%{echo: %{_native_opt_flags_x86_64_}}"
declare -x _fc_=""
declare -x _fcy_=""
declare -x _fg_=""
declare -x _fn_=""
declare -x _fpnk_=""
declare -x _tab_="	"
declare -- fn=""
[adm-jason@devbox01:~/rpmbuild] [966314] 19:13:52 [#:476!:13202]{0}	
$ ^C
[adm-jason@devbox01:~/rpmbuild] [966314] 19:14:41 [#:476!:13202]{130}	
$

Comment 3 Jason Vas Dias 2023-04-29 18:31:39 UTC
Oh, and I had to create the symlink:
  $ ls -l /opt/rh/gcc-toolset-12/root/usr/lib/gcc/x86_64-redhat-linux/12/plugin/
total 1376
-rw-r--r-- 1 root root      24 Oct  2  2022 annobin-plugin-version-info
lrwxrwxrwx 1 root root      16 Oct  2  2022 annobin.so -> annobin.so.0.0.0
lrwxrwxrwx 1 root root      16 Oct  2  2022 annobin.so.0 -> annobin.so.0.0.0
-rwxr-xr-x 1 root root   49376 Oct  2  2022 annobin.so.0.0.0
lrwxrwxrwx 1 root root      16 Apr 29 00:13 gcc-annobin.so -> annobin.so.0.0.0
                                            ^-- this symlink must exist, and didn't !
-rw-r--r-- 1 root root 1330361 Jan 12 11:20 gtype.state
drwxr-xr-x 9 root root   16384 Mar 21 01:23 include

Comment 4 Jason Vas Dias 2023-04-29 18:43:04 UTC
a bit off topic : Changes necessary to glibc.spec to compile with :
  -march=native -mtune=intel
 (GCC-12+ / Fedora)
or
  -march=x86-64 -mtune=native
 (GCC-8+ / RHEL 8)
:

# Propagates the listed flags to rpm_append_flag if supplied by
# redhat-rpm-config.
BuildFlags="-O2 -g"
rpm_inherit_flags ()
{
	local reference=" $* "
	local flag
	local seen_mtune=0;
	local seen_march=0;
	for flag in $CFLAGS $RPM_OPT_FLAGS $RPM_LD_FLAGS ; do
	        case "$flag" in
	           (-mtune*)
		      if (( $seen_mtune == 1 )); then
			 continue;
		      fi
		      seen_mtune=1;
		      ;;
	           (-march*)
		      if (( $seen_march == 1 )); then
			 continue;
		      fi
		      seen_march=1;
		      ;;
		esac
		if echo "$reference" | grep -q -F " $flag " ; then
			rpm_append_flag "$flag"
		fi
	done
}

# Propgate select compiler flags from redhat-rpm-config.  These flags
# are target-dependent, so we use only those which are specified in
# redhat-rpm-config.  We keep the -m32/-m32/-m64 flags to support
# multilib builds.
#
# Note: For building alternative run-times, care is required to avoid
# overriding the architecture flags which go into CC/CXX.  The flags
# below are passed in CFLAGS.

rpm_inherit_flags \
	"-Wp,-D_GLIBCXX_ASSERTIONS" \
	"-fasynchronous-unwind-tables" \
	"-fstack-clash-protection" \
	"-funwind-tables" \
	"-m31" \
	"-m32" \
	"-m64" \
        "-march=native" \
	"-march=i686" \
	"-march=x86-64" \
	"-march=x86-64-v2" \
	"-march=x86-64-v4" \
	"-march=z13" \
	"-march=z14" \
	"-march=zEC12" \
	"-mfpmath=sse" \
	"-msse2" \
	"-mstackrealign" \
	"-mtune=intel" \
        "-mtune=native" \
	"-mtune=generic" \
	"-mtune=z13" \
	"-mtune=z14" \
	"-mtune=zEC12" \
	"-specs=/usr/lib/rpm/redhat/redhat-annobin-cc1" \


Building and installing glibc with these flags on Fedora 36 and RHEL8 works and passes test suite during build,
and results in a MUCH faster glibc. It would be great if RedHat would provide a global 'RPM_INSTALL_NATIVE_RPMS' option
that would result in best optimized glibc for native processor / platform being installed.

Comment 5 Nick Clifton 2023-05-02 15:18:56 UTC
Fixed in binutils-2.40-8.fc39 and binutils-2.39-12.fc38

Comment 6 Fedora Update System 2023-05-04 14:51:04 UTC
FEDORA-2023-fb366d5ed5 has been submitted as an update to Fedora 38. https://bodhi.fedoraproject.org/updates/FEDORA-2023-fb366d5ed5

Comment 7 Fedora Update System 2023-05-04 14:51:05 UTC
FEDORA-2023-14607e274c has been submitted as an update to Fedora 37. https://bodhi.fedoraproject.org/updates/FEDORA-2023-14607e274c

Comment 8 Fedora Update System 2023-05-04 14:51:05 UTC
FEDORA-2023-eafe3fad16 has been submitted as an update to Fedora 36. https://bodhi.fedoraproject.org/updates/FEDORA-2023-eafe3fad16

Comment 9 Fedora Update System 2023-05-05 01:30:42 UTC
FEDORA-2023-fb366d5ed5 has been pushed to the Fedora 38 testing repository.
Soon you'll be able to install the update with the following command:
`sudo dnf upgrade --enablerepo=updates-testing --refresh --advisory=FEDORA-2023-fb366d5ed5`
You can provide feedback for this update here: https://bodhi.fedoraproject.org/updates/FEDORA-2023-fb366d5ed5

See also https://fedoraproject.org/wiki/QA:Updates_Testing for more information on how to test updates.

Comment 10 Fedora Update System 2023-05-05 01:30:44 UTC
FEDORA-2023-eafe3fad16 has been pushed to the Fedora 36 testing repository.
Soon you'll be able to install the update with the following command:
`sudo dnf upgrade --enablerepo=updates-testing --refresh --advisory=FEDORA-2023-eafe3fad16`
You can provide feedback for this update here: https://bodhi.fedoraproject.org/updates/FEDORA-2023-eafe3fad16

See also https://fedoraproject.org/wiki/QA:Updates_Testing for more information on how to test updates.

Comment 11 Fedora Update System 2023-05-05 02:22:57 UTC
FEDORA-2023-14607e274c has been pushed to the Fedora 37 testing repository.
Soon you'll be able to install the update with the following command:
`sudo dnf upgrade --enablerepo=updates-testing --refresh --advisory=FEDORA-2023-14607e274c`
You can provide feedback for this update here: https://bodhi.fedoraproject.org/updates/FEDORA-2023-14607e274c

See also https://fedoraproject.org/wiki/QA:Updates_Testing for more information on how to test updates.

Comment 12 Fedora Update System 2023-05-09 01:38:32 UTC
FEDORA-2023-14607e274c has been pushed to the Fedora 37 stable repository.
If problem still persists, please make note of it in this bug report.

Comment 13 Fedora Update System 2023-08-17 01:30:04 UTC
FEDORA-2023-fb366d5ed5 has been pushed to the Fedora 38 testing repository.
Soon you'll be able to install the update with the following command:
`sudo dnf upgrade --enablerepo=updates-testing --refresh --advisory=FEDORA-2023-fb366d5ed5`
You can provide feedback for this update here: https://bodhi.fedoraproject.org/updates/FEDORA-2023-fb366d5ed5

See also https://fedoraproject.org/wiki/QA:Updates_Testing for more information on how to test updates.

Comment 14 Fedora Update System 2023-08-18 07:40:21 UTC
FEDORA-2023-fb366d5ed5 has been pushed to the Fedora 38 testing repository.
Soon you'll be able to install the update with the following command:
`sudo dnf upgrade --enablerepo=updates-testing --refresh --advisory=FEDORA-2023-fb366d5ed5`
You can provide feedback for this update here: https://bodhi.fedoraproject.org/updates/FEDORA-2023-fb366d5ed5

See also https://fedoraproject.org/wiki/QA:Updates_Testing for more information on how to test updates.

Comment 15 Fedora Update System 2023-08-19 01:43:58 UTC
FEDORA-2023-fb366d5ed5 has been pushed to the Fedora 38 testing repository.
Soon you'll be able to install the update with the following command:
`sudo dnf upgrade --enablerepo=updates-testing --refresh --advisory=FEDORA-2023-fb366d5ed5`
You can provide feedback for this update here: https://bodhi.fedoraproject.org/updates/FEDORA-2023-fb366d5ed5

See also https://fedoraproject.org/wiki/QA:Updates_Testing for more information on how to test updates.

Comment 16 Fedora Update System 2023-10-18 01:45:40 UTC
FEDORA-2023-fb366d5ed5 has been pushed to the Fedora 38 stable repository.
If problem still persists, please make note of it in this bug report.


Note You need to log in before you can comment on or make changes to this bug.