diff --git a/glibc.spec b/glibc.spec index b784655..ffb4260 100644 --- a/glibc.spec +++ b/glibc.spec @@ -78,7 +78,7 @@ %endif # We do our own build flags management. In particular, see -# rpm_inherit_flags below. +# glibc_shell_* below. %undefine _auto_set_build_flags ############################################################################## @@ -1192,78 +1192,97 @@ cat /proc/sysinfo 2>/dev/null || true cat /proc/meminfo df -# We build using the native system compilers. -GCC=gcc -GXX=g++ - -# Part of rpm_inherit_flags. Is overridden below. -rpm_append_flag () -{ - BuildFlags="$BuildFlags $*" -} - -# Propagates the listed flags to rpm_append_flag if supplied by -# redhat-rpm-config. -BuildFlags="-O2 -g" -rpm_inherit_flags () -{ - local reference=" $* " - local flag - for flag in $RPM_OPT_FLAGS $RPM_LD_FLAGS ; do - 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" \ - "-fno-omit-frame-pointer" \ - "-funwind-tables" \ - "-m31" \ - "-m32" \ - "-m64" \ - "-march=armv8-a+lse" \ - "-march=armv8.1-a" \ - "-march=haswell" \ - "-march=i686" \ - "-march=x86-64" \ - "-march=x86-64-v2" \ - "-march=x86-64-v3" \ - "-march=x86-64-v4" \ - "-march=z13" \ - "-march=z14" \ - "-march=z15" \ - "-march=zEC12" \ - "-mbackchain" \ - "-mbranch-protection=standard" \ - "-mcpu=power10" \ - "-mcpu=power8" \ - "-mcpu=power9" \ - "-mfpmath=sse" \ - "-mno-omit-leaf-frame-pointer" \ - "-msse2" \ - "-mstackrealign" \ - "-mtune=generic" \ - "-mtune=power10" \ - "-mtune=power8" \ - "-mtune=power9" \ - "-mtune=z13" \ - "-mtune=z14" \ - "-mtune=z15" \ - "-mtune=zEC12" \ - "-specs=/usr/lib/rpm/redhat/redhat-annobin-cc1" \ +%{lua: +-- Split the string argument into keys of an associate array. +-- The values are set to true. +local function string_to_array(s) + local result = {} + for e in string.gmatch(s, "%S+") do + result[e] = true + end + return result +end + +local inherit_flags = {} + +-- These flags are put into the CC and CXX arguments to configure. +-- Alternate builds do not use the flags listed here, only the main build does. +inherit_flags.cc_main = string_to_array [[ +-march=armv8-a+lse +-march=armv8.1-a +-march=haswell +-march=i686 +-march=x86-64 +-march=x86-64-v2 +-march=x86-64-v3 +-march=x86-64-v4 +-march=z13 +-march=z14 +-march=z15 +-march=zEC12 +-mcpu=power10 +-mcpu=power8 +-mcpu=power9 +-mtune=generic +-mtune=power10 +-mtune=power8 +-mtune=power9 +-mtune=z13 +-mtune=z14 +-mtune=z15 +-mtune=zEC12 +]] + +-- Like inherit_flags_cc_main, but also used for alternate builds. +inherit_flags.cc = string_to_array [[ +-m31 +-m32 +-m64 +]] + +-- These flags are passed through CFLAGS and CXXFLAGS. +inherit_flags.cflags = string_to_array [[ +-O2 +-O3 +-Wall +-Wp,-D_GLIBCXX_ASSERTIONS +-fasynchronous-unwind-tables +-fno-omit-frame-pointer +-fstack-clash-protection +-funwind-tables +-g +-mbackchain +-mbranch-protection=standard +-mfpmath=sse +-mno-omit-leaf-frame-pointer +-msse2 +-mstackrealign +-specs=/usr/lib/rpm/redhat/redhat-annobin-cc1 +]] + +-- Iterate over the build_cflags RPM variable and emit a shell +-- variable that contains the inherited flags of the indicated variant. +local function shell_build_flags(variant) + local result = {} + local inherit = assert(inherit_flags[variant]) + for f in string.gmatch(rpm.expand("%build_cflags"), "%S+") do + if inherit[f] then + result[#result + 1] = f + end + end + print("glibc_flags_" .. variant .. "=\"" .. table.concat(result, " ") + .. "\"\n") +end + +shell_build_flags('cc_main') -- Set $glibc_flags_cc_main. +shell_build_flags('cc') -- Set $glibc_flags_cc. +shell_build_flags('cflags') -- Set $glibc_flags_cflags. +} %if 0%{?_annotated_build} > 0 # libc_nonshared.a cannot be built with the default hardening flags @@ -1285,34 +1304,29 @@ BuildFlagsNonshared="-fplugin=annobin -fplugin-arg-annobin-disable -Wa,--generat # %%build - Generic options. ############################################################################## EnableKernel="--enable-kernel=%{enablekernel}" -# Save the used compiler and options into the file "Gcc" for use later -# by %%install. -echo "$GCC" > Gcc ############################################################################## # build() -# Build glibc in `build-%{target}$1', passing the rest of the arguments -# as CFLAGS to the build (not the same as configure CFLAGS). Several +# Build glibc in the directory $1, passing the rest of the arguments +# as additional configure arguments. Several # global values are used to determine build flags, kernel version, # system tap support, etc. ############################################################################## build() { - local builddir=build-%{target}${1:+-$1} - ${1+shift} + local builddir=$1 + shift rm -rf $builddir mkdir $builddir pushd $builddir - ../configure CC="$GCC" CXX="$GXX" CFLAGS="$BuildFlags $*" \ + ../configure "$@" \ --prefix=%{_prefix} \ --with-headers=%{_prefix}/include $EnableKernel \ --with-nonshared-cflags="$BuildFlagsNonshared" \ --enable-bind-now \ --build=%{target} \ - ${configure_host} \ --enable-stack-protector=strong \ --enable-systemtap \ - ${core_with_options} \ %ifarch %{ix86} --disable-multi-arch \ %endif @@ -1347,17 +1361,23 @@ build() %ifarch x86_64 # Build for the glibc32 package. -GCC="$GCC -m32" GXX="$GXX -m32" BuildFlags="${BuildFlags/-m64/-m32}" configure_host="--host=i686-linux-gnu" build 32 -%endif - -configure_host="" - -%ifarch x86_64 -configure_host="--enable-cet" +build build-%{target}-32 \ + CC="gcc -m32" \ + CXX="g++ -m32" \ + CFLAGS="${glibc_flags_cflags/-m64/-m32}" \ + --host=i686-linux-gnu \ +# %endif # Default set of compiler options. -build +build build-%{target} \ + CC="gcc $glibc_flags_cc $glibc_flags_cc_main" \ + CXX="gcc $glibc_flags_cc $glibc_flags_cc_main" \ + CFLAGS="$glibc_flags_cflags" \ +%ifarch x86_64 + --enable-cet \ +%endif +# ############################################################################## # Install glibc... @@ -1373,9 +1393,6 @@ build # Remove existing file lists. find . -type f -name '*.filelist' -exec rm -rf {} \; -# Reload compiler and build options that were used during %%build. -GCC=`cat Gcc` - %ifarch riscv64 # RISC-V ABI wants to install everything in /lib64/lp64d or /usr/lib64/lp64d. # Make these be symlinks to /lib64 or /usr/lib64 respectively. See: