Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save Yanis002/f02b7234e1b01148ef2c9c095c254a65 to your computer and use it in GitHub Desktop.

Select an option

Save Yanis002/f02b7234e1b01148ef2c9c095c254a65 to your computer and use it in GitHub Desktop.
working mips binutils for arch users (dynamic linking)
From 8ebe62f3f0d27806b1bf69f301f5e188b4acd2b4 Mon Sep 17 00:00:00 2001
From: Sam James <sam@gentoo.org>
Date: Sat, 16 Nov 2024 05:03:52 +0000
Subject: [PATCH] opcodes: fix -std=gnu23 compatibility wrt static_assert
static_assert is declared in C23 so we can't reuse that identifier:
* Define our own static_assert conditionally;
* Rename "static assert" hacks to _N as we do already in some places
to avoid a conflict.
ChangeLog:
PR ld/32372
* i386-gen.c (static_assert): Define conditionally.
* mips-formats.h (MAPPED_INT): Rename identifier.
(MAPPED_REG): Rename identifier.
(OPTIONAL_MAPPED_REG): Rename identifier.
* s390-opc.c (static_assert): Define conditionally.
---
opcodes/i386-gen.c | 2 ++
opcodes/mips-formats.h | 6 +++---
opcodes/s390-opc.c | 2 ++
3 files changed, 7 insertions(+), 3 deletions(-)
--- a/opcodes/i386-gen.c
+++ b/opcodes/i386-gen.c
@@ -30,7 +30,9 @@
/* Build-time checks are preferrable over runtime ones. Use this construct
in preference where possible. */
+#ifndef static_assert
#define static_assert(e) ((void)sizeof (struct { int _:1 - 2 * !(e); }))
+#endif
static const char *program_name = NULL;
static int debug = 0;
--- a/opcodes/mips-formats.h
+++ b/opcodes/mips-formats.h
@@ -49,7 +49,7 @@
#define MAPPED_INT(SIZE, LSB, MAP, PRINT_HEX) \
{ \
typedef char ATTRIBUTE_UNUSED \
- static_assert[(1 << (SIZE)) == ARRAY_SIZE (MAP)]; \
+ static_assert_3[(1 << (SIZE)) == ARRAY_SIZE (MAP)]; \
static const struct mips_mapped_int_operand op = { \
{ OP_MAPPED_INT, SIZE, LSB }, MAP, PRINT_HEX \
}; \
@@ -83,7 +83,7 @@
#define MAPPED_REG(SIZE, LSB, BANK, MAP) \
{ \
typedef char ATTRIBUTE_UNUSED \
- static_assert[(1 << (SIZE)) == ARRAY_SIZE (MAP)]; \
+ static_assert_4[(1 << (SIZE)) == ARRAY_SIZE (MAP)]; \
static const struct mips_reg_operand op = { \
{ OP_REG, SIZE, LSB }, OP_REG_##BANK, MAP \
}; \
@@ -93,7 +93,7 @@
#define OPTIONAL_MAPPED_REG(SIZE, LSB, BANK, MAP) \
{ \
typedef char ATTRIBUTE_UNUSED \
- static_assert[(1 << (SIZE)) == ARRAY_SIZE (MAP)]; \
+ static_assert_5[(1 << (SIZE)) == ARRAY_SIZE (MAP)]; \
static const struct mips_reg_operand op = { \
{ OP_OPTIONAL_REG, SIZE, LSB }, OP_REG_##BANK, MAP \
}; \
--- a/opcodes/s390-opc.c
+++ b/opcodes/s390-opc.c
@@ -36,7 +36,9 @@
/* Build-time checks are preferrable over runtime ones. Use this construct
in preference where possible. */
+#ifndef static_assert
#define static_assert(e) ((void)sizeof (struct { int _:1 - 2 * !(e); }))
+#endif
#define ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0]))
# Maintainer: AltoXorg <machinademoniko AT gmail DOT com>
# Contributor: Moon Sungjoon <sumoon at seoulsaram dot org>
# Contributor: Alex Bates <hi@imalex.xyz>
#
# modified from https://aur.archlinux.org/packages/mips-linux-gnu-binutils
# you will need the following patch if building with GCC 15: https://github.com/hauke/openwrt/blob/main/toolchain/binutils/patches/2.42/003-PR-32372-opcodes-fix-std-gnu23-compatibility-wrt-static_asser.patch
# place that patch file in the src/binutils-2.42 folder
_target=mips-linux-gnu
pkgname=$_target-binutils
pkgver=2.42
pkgrel=1
pkgdesc='A set of programs to assemble and manipulate binary and object files for the MIPS target'
arch=('x86_64' 'aarch64')
url='http://www.gnu.org/software/binutils/'
license=('GPL')
depends=('zlib' 'libelf')
source=(https://ftp.gnu.org/gnu/binutils/binutils-$pkgver.tar.bz2{,.sig})
sha512sums=('d2c6d264bbeaaaf2aad1fa3fc417c1841a5dd4a299fa47c47d15adb821c22dae733e58f19ebcfea3b0c5890ba56e4a5f92ab55128a572d585bcd5172b63f456c'
'SKIP')
validpgpkeys=('3A24BC1E8FB409FA9F14371813FCEF89DD9E3C4F') # Nick Clifton (Chief Binutils Maintainer) <nickc@redhat.com>
prepare() {
cd binutils-${pkgver}
sed -i "/ac_cpp=/s/\$CPPFLAGS/\$CPPFLAGS -O2/" libiberty/configure
git apply 003-PR-32372-opcodes-fix-std-gnu23-compatibility-wrt-static_asser.patch
}
build() {
cd binutils-${pkgver}
if [ "${CARCH}" != "i686" ];
then
# enabling gold linker at i686 makes the install fail
enable_gold='--enable-gold'
fi
./configure --target=${_target} \
--with-sysroot="/usr/${_target}" \
--prefix='/usr' \
--disable-multilib \
--with-gnu-as \
--with-gnu-ld \
--disable-nls \
--enable-ld='default' \
$enable_gold \
--enable-plugins \
--enable-deterministic-archives \
make
}
check() {
cd binutils-${pkgver}
# unset LDFLAGS as testsuite makes assumptions about which ones are active
# do not abort on errors - manually check log files
make -k LDFLAGS="" check || true
}
package() {
cd binutils-${pkgver}
make DESTDIR="${pkgdir}" install
# Remove file conflicting with host binutils and manpages for MS Windows tools
rm "${pkgdir}"/usr/share/man/man1/${_target}-{dlltool,windres,windmc}*
rm "${pkgdir}"/usr/lib/bfd-plugins/libdep.so
# Remove info documents that conflict with host version
rm -r "${pkgdir}"/usr/share/info
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment