diff --git a/README.md b/README.md index 392c364..254d17f 100644 --- a/README.md +++ b/README.md @@ -149,6 +149,8 @@ able to just push. * `bisect-binutils`: Ditto. +* `bisect-gdb`: Ditto. + * `miscompile-reduce.sh`: Script for reducing miscompilations w/ cvise. ### llvm diff --git a/gcc/bisect-gdb b/gcc/bisect-gdb new file mode 100755 index 0000000..1e2ce66 --- /dev/null +++ b/gcc/bisect-gdb @@ -0,0 +1,171 @@ +#!/usr/bin/env bash +# https://wiki.gentoo.org/wiki/Bisecting_with_live_ebuilds +# GPL-3+ +. /lib/gentoo/functions.sh || { echo "Failed to source functions.sh!" ; exit 1 ; } + +esyslog() { + : No need. +} + +die() { + eerror "$@" + exit 255 # Abort the bisect process +} + +fatal() { + einfo Running "$@" + "$@" || die "$@" +} + +skip() { + einfo Running "$@" + if ! "$@"; then + ewarn Build failed, skipping: "$@" + exit 125 + fi +} + +export CBUILD="${CBUILD:-$(portageq envvar CBUILD)}" +export CHOST="${CHOST:-$(portageq envvar CHOST)}" +export CTARGET="${CTARGET:-$(portageq envvar CTARGET)}" + +if [[ -z ${CHOST} ]] ; then + die "No CHOST set!" +fi + +# +# Configuration +# + +# Sensible defaults for sam +if [[ ${LOGNAME} == sam ]] ; then + prefix="/tmp/gdb-bisect" + builddir=$(mktemp -t -d binutils.XXXXXXX) + srcdir="/home/sam/git/binutils-gdb" + #srcdir="/var/tmp/portage/sys-devel/binutils-2.42-r2/work/binutils-2.42" +else + prefix="/tmp/binutils-prefix" + builddir=$(mktemp -t -d binutils.XXXXXXX) + srcdir="/tmp/binutils-gdb" +fi + +if [[ -z ${prefix} ]] ; then + die "No prefix set!" +fi + +if [[ -z ${builddir} ]] ; then + die "No builddir set (or empty)!" +fi + +if [[ -z ${srcdir} || ! -d ${srcdir} ]] ; then + die "No srcdir set (or empty)!" +fi + +# +# End configuration +# + +fatal mkdir -p "${builddir}" +fatal cd "${builddir}" +fatal mkdir -p ${prefix} + +#export CFLAGS="-O3 -march=native -mtls-dialect=gnu2 -pipe" +#export CXXFLAGS="-O3 -march=native -mtls-dialect=gnu2 -pipe" +export CFLAGS="-O2 -fpermissive" +export CXXFLAGS="-O2" +export LDFLAGS="-Wl,-O1 -Wl,--as-needed" + +export STAGE1_CFLAGS="${STAGE1_CFLAGS:-${CFLAGS}}" +export STAGE1_LDFLAGS="${STAGE1_LDFLAGS:-${LDFLAGS}}" +export BOOT_CFLAGS="${BOOT_CFLAGS:-${CFLAGS}}" +export BOOT_LDFLAGS="${BOOT_LDFLAGS:-${LDFLAGS}}" +export CFLAGS_FOR_TARGET="${CFLAGS_FOR_TARGET:-${CFLAGS}}" +export LDFLAGS_FOR_TARGET="${LDFLAGS_FOR_TARGET:-${LDFLAGS}}" + +cd "${builddir}" || exit 1 +einfo "srcdir: ${srcdir}" +einfo "builddir: ${builddir}" + +gdb_make_args=( + -Oline + -j$(nproc) -l$(nproc) + V=1 + CFLAGS="${CFLAGS}" + CXXFLAGS="${CXXFLAGS}" + LDFLAGS="${LDFLAGS}" + STAGE1_CFLAGS="${STAGE1_CFLAGS}" + STAGE1_LDFLAGS="${STAGE1_LDFLAGS}" + BOOT_CFLAGS="${BOOT_CFLAGS}" + BOOT_LDFLAGS="${BOOT_LDFLAGS}" + CFLAGS_FOR_TARGET="${CFLAGS_FOR_TARGET}" + LDFLAGS_FOR_TARGET="${LDFLAGS_FOR_TARGET}" + CFLAGS="${CFLAGS}" + CXXFLAGS="${CXXFLAGS}" + LDFLAGS="${LDFLAGS}" +) + +gdb_config_args=( + --prefix="${prefix}" + + --build="${CBUILD}" + --host="${CHOST}" + --target="${CTARGET}" + + --enable-plugins + --without-included-gettext + --with-system-zlib + #--enable-targets=all + #--enable-64-bit-bfd + --enable-secureplt + --enable-default-hash-style=gnu + --disable-dependency-tracking + --disable-silent-rules + --enable-obsolete + --enable-shared + --enable-threads + --enable-relro + #--enable-install-libiberty + #--enable-textrel-check=error + --enable-new-dtags + + --disable-jansson + --disable-werror + #--disable-static + + --disable-ld + --disable-{binutils,etc,gas,gold,gprof,gprofng,ld} + #--disable-cet + --enable-gdb + --disable-gdbserver + --disable-gprofng + #--disable-libbacktrace + #--disable-libdecnumber + --enable-readline + --disable-sim + --with-python=python3.11 + + --without-stage1-ldflags + --without-debuginfod + --without-msgpack + --without-zstd + + #--enable-warn-execstack=yes + #--enable-warn-rwx-segments=yes + #--enable-default-execstack=no + --disable-pgo-build + #--enable-colored-disassembly +) + +skip "${srcdir}"/configure "${gdb_config_args[@]}" +skip make "${gdb_make_args[@]}" all # all-ld +#make "${gdb_make_args[@]}" check-ld || exit 1 # RUNTESTFLAGS="input-remap.exp" || exit 1 +skip make "${gdb_make_args[@]}" -Oline install +GUALITY_GDB_NAME=/tmp/gdb-bisect/bin/gdb GDB=/tmp/gdb-bisect/bin/gdb make -C /tmp/bisect-gcc-bld/x86_64-pc-linux-gnu/libstdc++-v3 check RUNTESTFLAGS="prettyprinters.exp='simple*.cc debug.cc'" -j1 -Onone || exit 1 + +if grep -q -rsin ^FAIL /tmp/bisect-gcc-bld/x86_64-pc-linux-gnu/libstdc++-v3/testsuite/libstdc++.sum ; then + exit 1 +fi + +#${builddir}/gas/as-new /tmp/foo.s -O2 || exit 1 + +exit 0