arch-x86_64-ifunc-alias still fails with custom GCC compiled with march=native #1397
Closed
Description
I've used the following PKGBUILD for my custom GCC build:
pkgname=(gcc gcc-libs lib32-gcc-libs lto-dump libgccjit)
pkgver=14.2.1
_majorver=${pkgver%%.*}
_islver=0.26
pkgrel=7.1
pkgdesc='The GNU Compiler Collection'
arch=(x86_64)
license=(GPL LGPL FDL custom)
CHOST=x86_64-pc-linux-gnu
url='https://gcc.gnu.org'
makedepends=(
binutils
git
lib32-glibc
libmpc
libxcrypt
python
zstd
isl
)
options=(!emptydirs !lto)
_libdir=usr/lib/gcc/$CHOST/${pkgver%_*}
source=(
"git+https://gcc.gnu.org/git/gcc.git#branch=releases/gcc-$_majorver"
c89
c99
clearlinux.patch
)
sha256sums=(
'SKIP'
'de48736f6e4153f03d0a5d38ceb6c6fdb7f054e8f47ddd6af0a3dbf14f27b931'
'2513c6d9984dd0a2058557bf00f06d8d5181734e41dcfe07be7ed86f2959622a'
'c86372c207d174c0918d4aedf1cb79f7fc093649eb1ad8d9450dccc46849d308'
'5f895579c097f061d97745979b7556d81098d4a7756b8ff85d75d90462d07172'
)
# Common function for stripping and license installation
_install_common() {
local pkg="$1"
# Standardized debug symbol stripping
find "$pkgdir" -type f \( -executable -or -name "*.so*" \) \
-exec file {} + | grep ELF | cut -d: -f1 | \
xargs -r strip --strip-unneeded
# Standardized license installation
install -dm755 "$pkgdir/usr/share/licenses/$pkg"
ln -sf /usr/share/licenses/gcc-libs/RUNTIME.LIBRARY.EXCEPTION \
"$pkgdir/usr/share/licenses/$pkg/"
}
_patch() {
echo -e "\E[1;33m Apply patch: ${1}\E[0m"
patch --forward --strip=1 --input="${srcdir:?}/${1}"
}
prepare() {
cd "gcc"
# Do not run fixincludes
sed -i 's@\./fixinc\.sh@-c true@' gcc/Makefile.in
# Arch Linux installs x86_64 libraries /lib
sed -i '/m64=/s/lib64/lib/' gcc/config/i386/t-linux64
# Create build directories outside of srcdir
mkdir -p "$srcdir/gcc-build"
mkdir -p "$srcdir/libgccjit-build"
_patch clearlinux.patch
}
build() {
local _common_confflags=(
--prefix=/usr
--libdir=/usr/lib
--libexecdir=/usr/lib
--mandir=/usr/share/man
--infodir=/usr/share/info
--enable-default-hash-style=gnu
--with-system-zlib
--with-zstd
--with-ppl
--with-isl
--enable-__cxa_atexit
--disable-cet
--disable-libssp
--disable-libunwind-exceptions
--disable-vtable-verify
--disable-libmpx
--disable-checking
--enable-clocale=gnu
--disable-default-pie
--disable-default-ssp
--enable-gnu-indirect-function
--enable-gnu-unique-object
--disable-link-serialization
--enable-linker-build-id
--enable-lto
--enable-multilib
--with-multilib-list=m32,m64
--enable-plugin
--enable-shared
--enable-threads=posix
--enable-libstdcxx-pch
--disable-libstdcxx-backtrace
--with-build-config=bootstrap-lto
--disable-werror
--with-tune=native
--with-arch=native
--enable-linux-futex
--with-glibc-version=2.40
)
cd "$srcdir/gcc-build"
# Use a more conservative optimization level for Stage 1
local _bootstrap_cflags="-O3 -march=native"
"$srcdir/gcc/configure" \
--enable-languages=c,c++,lto \
--enable-bootstrap-lto \
"${_common_confflags[@]}"
make -j$(nproc) \
BOOT_CFLAGS="$CFLAGS" \
BOOT_CXXFLAGS="$CXXFLAGS" \
BOOT_LDFLAGS="$LDFLAGS" \
CFLAGS_FOR_TARGET="$CFLAGS" \
CXXFLAGS_FOR_TARGET="$CXXFLAGS" \
LDFLAGS_FOR_TARGET="$LDFLAGS" \
profiledbootstrap
# Build libgccjit separately, with consistent flags
cd "$srcdir/libgccjit-build"
"$srcdir/gcc/configure" \
--enable-languages=jit \
--disable-bootstrap \
--enable-host-shared \
"${_common_confflags[@]}"
make -j$(nproc) \
BOOT_CFLAGS="$CFLAGS" \
BOOT_CXXFLAGS="$CXXFLAGS" \
BOOT_LDFLAGS="$LDFLAGS" \
CFLAGS_FOR_TARGET="$CFLAGS" \
CXXFLAGS_FOR_TARGET="$CXXFLAGS" \
LDFLAGS_FOR_TARGET="$LDFLAGS" \
all-gcc
cp -a gcc/libgccjit.so* "$srcdir/gcc-build/gcc/"
}
package_gcc-libs() {
pkgdesc='Runtime libraries shipped by GCC'
depends=('glibc>=2.40')
provides=("${pkgname}-multilib" libgo.so libgfortran.so libgphobos.so
libubsan.so libasan.so libtsan.so liblsan.so)
replaces=("${pkgname}-multilib" libgphobos)
options=(!emptydirs !strip)
cd "$srcdir/gcc-build"
# Install shared libraries
make -C $CHOST/libgcc DESTDIR="$pkgdir" install-shared
# Explicitly handle OpenMP installation
if [[ -d "$CHOST/libgomp" ]]; then
make -C $CHOST/libgomp DESTDIR="$pkgdir" install
install -dm755 "$pkgdir/usr/lib/gcc/$CHOST/${pkgver%_*}/include/"
cp -a "$srcdir/gcc-build/$CHOST/libgomp/omp.h" \
"$pkgdir/usr/lib/gcc/$CHOST/${pkgver%_*}/include/"
cp -a "$srcdir/gcc-build/$CHOST/libgomp/libgomp.spec" \
"$pkgdir/usr/lib/gcc/$CHOST/${pkgver%_*}/"
fi
# Install other runtime libraries
for lib in libatomic \
libitm \
libquadmath \
libsanitizer/{a,l,ub,t}san \
libstdc++-v3/src \
libvtv; do
if [[ -d "$CHOST/$lib" ]]; then
make -C $CHOST/$lib DESTDIR="$pkgdir" install-toolexeclibLTLIBRARIES || \
make -C $CHOST/$lib DESTDIR="$pkgdir" install || true
fi
done
# Install Runtime Library Exception
install -dm755 "$pkgdir/usr/share/licenses/gcc-libs"
install -m644 "$srcdir/gcc/COPYING.RUNTIME" \
"$pkgdir/usr/share/licenses/gcc-libs/RUNTIME.LIBRARY.EXCEPTION"
_install_common gcc-libs
}
package_gcc() {
pkgdesc="The GNU Compiler Collection - C and C++ frontends"
depends=("gcc-libs=$pkgver-$pkgrel" "binutils>=2.28" libmpc zstd libisl.so)
groups=(base-devel)
optdepends=('lib32-gcc-libs: for generating code for 32-bit ABI')
provides=("${pkgname}-multilib")
replaces=("${pkgname}-multilib")
options=(!emptydirs)
cd "$srcdir/gcc-build"
# Core compiler installation
local _core_components=(
'gcc install-driver'
'gcc install-cpp'
'gcc install-gcc-ar'
'gcc install-headers'
'gcc install-plugin'
'gcc install-lto-wrapper'
)
for comp in "${_core_components[@]}"; do
make -C "${comp% *}" DESTDIR="$pkgdir" "${comp#* }"
done
# Install C++ components
make -C $CHOST/libstdc++-v3 DESTDIR="$pkgdir" install
make -C gcc DESTDIR="$pkgdir" install-common
# Install g++ from xg++
install -Dm755 "$srcdir/gcc-build/gcc/xg++" "$pkgdir"/usr/bin/g++
# Create necessary symlinks with force flag
ln -sf g++ "$pkgdir"/usr/bin/c++
ln -sf g++ "$pkgdir"/usr/bin/${CHOST}-g++
ln -sf g++ "$pkgdir"/usr/bin/${CHOST}-c++
# Install additional tools
local _tools=(
gcc/gcov
gcc/gcov-tool
gcc/cc1
gcc/cc1plus
gcc/collect2
gcc/lto1
)
for tool in "${_tools[@]}"; do
install -Dm755 "$tool" "$pkgdir/${_libdir}/$(basename $tool)"
done
# Install libraries and headers
local _64bit_lib_components=(
"$CHOST/libgcc"
"$CHOST/libstdc++-v3/src"
"$CHOST/libstdc++-v3/include"
"$CHOST/libstdc++-v3/libsupc++"
"$CHOST/libstdc++-v3/python"
)
for comp in "${_64bit_lib_components[@]}"; do
make -C "$comp" DESTDIR="$pkgdir" install
done
# Handle special cases
make DESTDIR="$pkgdir" install-libcc1
make -C gcc DESTDIR="$pkgdir" install-mkheaders
make -C lto-plugin DESTDIR="$pkgdir" install
# Setup symlinks
ln -s gcc "$pkgdir"/usr/bin/cc
install -Dm755 "$srcdir/c89" "$pkgdir/usr/bin/c89"
install -Dm755 "$srcdir/c99" "$pkgdir/usr/bin/c99"
# LTO plugin symlink
install -dm755 "$pkgdir"/usr/lib/bfd-plugins/
ln -s /${_libdir}/liblto_plugin.so \
"$pkgdir/usr/lib/bfd-plugins/"
_install_common gcc
}
package_lib32-gcc-libs() {
pkgdesc='32-bit runtime libraries shipped by GCC'
depends=('lib32-glibc>=2.37')
provides=("lib32-gcc-libs=$pkgver-$pkgrel" libgo.so libgfortran.so libubsan.so libasan.so)
groups=(multilib-devel)
options=(!emptydirs !strip)
cd gcc-build
make -C $CHOST/32/libgcc DESTDIR="$pkgdir" install-shared
rm -f "$pkgdir/$_libdir/32/libgcc_eh.a"
for lib in libatomic \
libgomp \
libitm \
libquadmath \
libsanitizer/{a,l,ub}san \
libstdc++-v3/src \
libvtv; do
make -C $CHOST/32/$lib DESTDIR="$pkgdir" install-toolexeclibLTLIBRARIES
done
# remove files provided by gcc-libs
rm -rf "$pkgdir"/usr/lib
# Strip debug symbols
find "$pkgdir" -type f \( -executable -or -name "*.so*" \) -exec file {} + | grep ELF | cut -d: -f1 | xargs -r strip --strip-all
# Install Runtime Library Exception
install -Dm644 "$srcdir/gcc/COPYING.RUNTIME" \
"$pkgdir/usr/share/licenses/lib32-gcc-libs/RUNTIME.LIBRARY.EXCEPTION"
}
package_lto-dump() {
pkgdesc="Dump link time optimization object files"
depends=("gcc=$pkgver-$pkgrel" libisl.so)
options=(!emptydirs)
cd "$srcdir/gcc-build"
# Install LTO dump components
local _lto_components=(
'gcc/lto.install-common'
'gcc/lto.install-info'
)
for comp in "${_lto_components[@]}"; do
make -C ${comp%/*} DESTDIR="$pkgdir" ${comp##*/}
done
_install_common lto-dump
}
package_libgccjit() {
pkgdesc="Just-In-Time Compilation with GCC backend"
depends=("gcc=$pkgver-$pkgrel")
options=(!emptydirs)
cd "$srcdir/gcc-build"
# Install JIT components
local _jit_components=(
'gcc/jit.install-common'
'gcc/jit.install-info'
)
for comp in "${_jit_components[@]}"; do
make -C ${comp%/*} DESTDIR="$pkgdir" ${comp##*/}
done
_install_common libgccjit
}
After seeing a fix for that test in 37e6d2f, I thought that this could have been the source of my issue, but I still get:
++ dirname /tmp/makepkg/mold-git/src/mold/test/arch-x86_64-ifunc-alias.sh
+ . /tmp/makepkg/mold-git/src/mold/test/common.inc
++ export LC_ALL=C
++ LC_ALL=C
++ '[' -z x86_64 ']'
++ '[' -z '' ']'
++ TESTDIR=out/test/x86_64
++ CC=cc
++ CXX=c++
++ GCC=gcc
++ GXX=g++
++ OBJDUMP=objdump
++ OBJCOPY=objcopy
++ STRIP=strip
++ QEMU=
++ case $MACHINE in
++ tlsdesc_opt=-mtls-dialect=gnu2
+++ uname
++ '[' Linux = FreeBSD ']'
++ trap 'on_error $LINENO' ERR
++ trap on_exit EXIT
+++ basename /tmp/makepkg/mold-git/src/mold/test/arch-x86_64-ifunc-alias.sh .sh
++ testname=arch-x86_64-ifunc-alias
++ echo -n 'Testing arch-x86_64-ifunc-alias ... '
Testing arch-x86_64-ifunc-alias ... ++ t=out/test/x86_64/arch-x86_64-ifunc-alias
++ mkdir -p out/test/x86_64/arch-x86_64-ifunc-alias
++ set -x
+ supports_ifunc
+ is_musl
+ ldd --version
+ grep -q musl
+ echo 'void x() __attribute__((ifunc("y"))); void *y() { return 0; }'
+ cc -c -o /dev/null -xc -
+ test_cflags -static
+ echo 'int main() {}'
+ cc -B. -static -o /dev/null -xc -
+ cat
+ c++ -march=x86-64 -o out/test/x86_64/arch-x86_64-ifunc-alias/a.o -c -xc++ - -fno-PIE
+ c++ -B. -o out/test/x86_64/arch-x86_64-ifunc-alias/exe out/test/x86_64/arch-x86_64-ifunc-alias/a.o -static
mold: fatal: library not found: stdc++
collect2: error: ld returned 1 exit status
++ on_error 29
++ code=1
++ echo 'command failed: 29: $CXX -B. -o $t/exe $t/a.o -static'
command failed: 29: $CXX -B. -o $t/exe $t/a.o -static
++ trap - EXIT
++ exit 1
I've used these FLAGS in my /etc/makepkg.conf for compiling Mold:
CPPFLAGS="-D_FORTIFY_SOURCE=0"
CFLAGS="-O3 -march=native -mtune=native -fno-semantic-interposition -falign-functions=32 -fipa-pta -flive-range-shrinkage -fno-math-errno -fno-trapping-math -mtls-dialect=gnu2 -feliminate-unused-debug-types -floop-nest-optimize -fgraphite-identity -fcf-protection=none -mharden-sls=none -funroll-loops -malign-data=cacheline -fomit-frame-pointer -mprefer-vector-width=256 -fivopts -fmodulo-sched -fdata-sections -ffunction-sections -Wl,-zmax-page-size=0x200000 -fprofile-use=/home/marcus/Downloads/gcc-pgo/mold-pgo -fprofile-correction -fno-plt -flto=auto -fdevirtualize-at-ltrans -w"
CXXFLAGS="$CFLAGS -Wp,-U_GLIBCXX_ASSERTIONS"
LDFLAGS="-Wl,-O3,--as-needed,-Bsymbolic-functions,--sort-common -flto=auto -fuse-ld=mold -Wl,--gc-sections -march=native -mtune=native -Wl,-zmax-page-size=0x200000 -Wl,-z,relro -Wl,-z,now -Wl,-z,pack-relative-relocs -fprofile-use=/home/marcus/Downloads/gcc-pgo/mold-pgo -fprofile-correction -Wl,--push-state -Wl,-whole-archive -lmimalloc -Wl,--pop-state -lpthread -lstdc++ -lm -ldl"
ASFLAGS="-D__AVX__=1 -D__AVX2__=1 -msse2avx -D__FMA__=1"
Metadata
Assignees
Labels
No labels