| 1 | # Maintainer: Natanael Copa <[email protected]> |
| 2 | pkgname=binutils |
| 3 | pkgver=2.45.1 |
| 4 | _gold_ver=2.44 # last even version of $pkgver |
| 5 | pkgrel=1 |
| 6 | pkgdesc="Tools necessary to build programs" |
| 7 | url="https://www.gnu.org/software/binutils/" |
| 8 | makedepends_build="bison flex texinfo" |
| 9 | makedepends_host="zlib-dev" |
| 10 | arch="all" |
| 11 | license="GPL-2.0-or-later AND LGPL-2.1-or-later AND BSD-3-Clause" |
| 12 | subpackages="$pkgname-dev $pkgname-doc" |
| 13 | source="https://ftp.gnu.org/gnu/binutils/binutils-$pkgver.tar.xz |
| 14 | https://ftp.gnu.org/gnu/binutils/binutils-with-gold-$_gold_ver.tar.xz |
| 15 | 0001-Revert-PR25882-.gnu.attributes-are-not-checked-for-s.patch |
| 16 | binutils-ld-fix-static-linking.patch |
| 17 | s390x-pie.patch |
| 18 | " |
| 19 | options="!check" |
| 20 | builddir="$srcdir/$pkgname-$pkgver" |
| 21 | |
| 22 | if [ "$CBUILD" = "$CTARGET" ]; then |
| 23 | _alpine_archs=" |
| 24 | aarch64 |
| 25 | armhf |
| 26 | armv7 |
| 27 | loongarch64 |
| 28 | ppc64le |
| 29 | riscv64 |
| 30 | s390x |
| 31 | x86 |
| 32 | x86_64 |
| 33 | " |
| 34 | fi |
| 35 | |
| 36 | if [ -z "$BOOTSTRAP" ]; then |
| 37 | makedepends_host="$makedepends_host jansson-dev zstd-dev" |
| 38 | _noboot_configure="--enable-jansson --with-zstd" |
| 39 | |
| 40 | for _target_arch in $_alpine_archs; do |
| 41 | if [ "$_target_arch" != "$CARCH" ]; then |
| 42 | _cross_targets="$_cross_targets $_target_arch" |
| 43 | subpackages=" |
| 44 | $subpackages |
| 45 | $pkgname-$_target_arch:_cross_target |
| 46 | " |
| 47 | fi |
| 48 | done |
| 49 | fi |
| 50 | |
| 51 | if [ "$CHOST" != "$CTARGET" ]; then |
| 52 | pkgname="$pkgname-$CTARGET_ARCH" |
| 53 | subpackages="" |
| 54 | sonameprefix="$pkgname:" |
| 55 | fi |
| 56 | |
| 57 | _gold_configure="--disable-gold" |
| 58 | if [ "$CHOST" = "$CBUILD" ] && [ "$CBUILD" = "$CTARGET" ] && [ "$CTARGET_ARCH" != "riscv64" ] && [ "$CTARGET_ARCH" != "loongarch64" ]; then |
| 59 | subpackages="$subpackages $pkgname-gold" |
| 60 | _gold_configure="--enable-gold" |
| 61 | fi |
| 62 | |
| 63 | # secfixes: |
| 64 | # 2.44-r2: |
| 65 | # - CVE-2025-1153 |
| 66 | # - CVE-2025-3198 |
| 67 | # 2.44-r0: |
| 68 | # - CVE-2025-0840 |
| 69 | # 2.40-r10: |
| 70 | # - CVE-2023-1972 |
| 71 | # 2.40-r0: |
| 72 | # - CVE-2023-1579 |
| 73 | # 2.39-r2: |
| 74 | # - CVE-2022-38533 |
| 75 | # 2.39-r0: |
| 76 | # - CVE-2022-38126 |
| 77 | # 2.35.2-r1: |
| 78 | # - CVE-2021-3487 |
| 79 | # 2.32-r0: |
| 80 | # - CVE-2018-19931 |
| 81 | # - CVE-2018-19932 |
| 82 | # - CVE-2018-20002 |
| 83 | # - CVE-2018-20712 |
| 84 | # 2.28-r1: |
| 85 | # - CVE-2017-7614 |
| 86 | |
| 87 | prepare() { |
| 88 | default_prepare |
| 89 | rm -rf "$builddir"/gold "$builddir"/elfcpp |
| 90 | mv "$srcdir"/binutils-with-gold-*/gold "$builddir"/gold |
| 91 | mv "$srcdir"/binutils-with-gold-*/elfcpp "$builddir"/elfcpp |
| 92 | } |
| 93 | |
| 94 | build() { |
| 95 | _configure "$CTARGET" "$CTARGET_ARCH" "$_gold_configure" |
| 96 | local _target_arch |
| 97 | |
| 98 | for _target_arch in $_cross_targets; do |
| 99 | _configure \ |
| 100 | "$(arch_to_hostspec "$_target_arch")" \ |
| 101 | "$_target_arch" \ |
| 102 | "--disable-gold" & |
| 103 | done |
| 104 | wait |
| 105 | |
| 106 | for _builddir in "$srcdir"/build-*; do |
| 107 | make -C "$_builddir" |
| 108 | done |
| 109 | } |
| 110 | |
| 111 | _configure() { |
| 112 | local target="$1" target_arch="$2" _gold_configure="$3" |
| 113 | local _sysroot=/ |
| 114 | local _cross_configure="--enable-install-libiberty --enable-shared" |
| 115 | local _arch_configure="" |
| 116 | |
| 117 | if [ "$CHOST" != "$CTARGET" ]; then |
| 118 | _sysroot="$CBUILDROOT" |
| 119 | fi |
| 120 | if [ "$CARCH" != "$target_arch" ]; then |
| 121 | _cross_configure="--disable-install-libbfd --disable-install-libiberty" |
| 122 | fi |
| 123 | |
| 124 | if [ "$target_arch" = "x86_64" ]; then |
| 125 | _arch_configure="--enable-targets=x86_64-pep" |
| 126 | fi |
| 127 | |
| 128 | mkdir -p "$srcdir/build-$target_arch" |
| 129 | cd "$srcdir/build-$target_arch" |
| 130 | |
| 131 | CFLAGS="$CFLAGS -O2" \ |
| 132 | CXXFLAGS="$CXXFLAGS -O2" \ |
| 133 | "$builddir"/configure \ |
| 134 | --build=$CBUILD \ |
| 135 | --host=$CHOST \ |
| 136 | --target="$target" \ |
| 137 | --with-build-sysroot="$CBUILDROOT" \ |
| 138 | --with-sysroot=$_sysroot \ |
| 139 | --prefix=/usr \ |
| 140 | --mandir=/usr/share/man \ |
| 141 | --infodir=/usr/share/info \ |
| 142 | --sysconfdir=/etc \ |
| 143 | $_arch_configure \ |
| 144 | $_cross_configure \ |
| 145 | $_gold_configure \ |
| 146 | $_noboot_configure \ |
| 147 | --disable-gdb \ |
| 148 | --disable-gprofng \ |
| 149 | --disable-multilib \ |
| 150 | --disable-nls \ |
| 151 | --disable-werror \ |
| 152 | --enable-64-bit-bfd \ |
| 153 | --enable-colored-disassembly \ |
| 154 | --enable-default-execstack=no \ |
| 155 | --enable-default-hash-style=gnu \ |
| 156 | --enable-deterministic-archives \ |
| 157 | --enable-ld=default \ |
| 158 | --enable-new-dtags \ |
| 159 | --enable-plugins \ |
| 160 | --enable-relro \ |
| 161 | --enable-threads \ |
| 162 | --with-bugurl="https://gitlab.alpinelinux.org/alpine/aports/-/issues" \ |
| 163 | --with-mmap \ |
| 164 | --with-pic \ |
| 165 | --with-system-zlib |
| 166 | make configure-host configure-target |
| 167 | } |
| 168 | |
| 169 | package() { |
| 170 | for _target_arch in $_cross_targets; do |
| 171 | make -C "$srcdir/build-$_target_arch" install DESTDIR="$pkgdir" |
| 172 | if [ -d "$pkgdir"/usr/lib64 ]; then |
| 173 | mv "$pkgdir"/usr/lib64/* "$pkgdir"/usr/lib/ |
| 174 | rmdir "$pkgdir"/usr/lib64 |
| 175 | fi |
| 176 | rm -r "${pkgdir:?}"/usr/share "${pkgdir:?}"/usr/lib |
| 177 | done |
| 178 | |
| 179 | make -C "$srcdir/build-$CTARGET_ARCH" install DESTDIR="$pkgdir" |
| 180 | if [ "$CHOST" != "$CTARGET" ]; then |
| 181 | # creating cross tools: remove any files that would conflict |
| 182 | # with the native tools, or other cross tools |
| 183 | rm -r "${pkgdir:?}"/usr/share "${pkgdir:?}"/usr/lib |
| 184 | fi |
| 185 | } |
| 186 | |
| 187 | gold() { |
| 188 | pkgdesc="GNU binutils - gold linker (deprecated)" |
| 189 | |
| 190 | amove usr/bin/ld.gold |
| 191 | amove usr/$CTARGET/bin/ld.gold |
| 192 | } |
| 193 | |
| 194 | _cross_target() { |
| 195 | local target_arch="${subpkgname#*-}" |
| 196 | local target="$(arch_to_hostspec "$target_arch")" |
| 197 | pkgdesc="Tools necessary to build programs for $target_arch" |
| 198 | |
| 199 | amove \ |
| 200 | usr/bin/$target-* \ |
| 201 | usr/$target |
| 202 | } |
| 203 | |
| 204 | sha512sums=" |
| 205 | ea030419eba387579ab717be7e3223fc99e93b586860b06003c12489f93441640d4082736f76aa5e98233db4f46e232f536a45e471486de1f5b64e1b827c167e binutils-2.45.1.tar.xz |
| 206 | 1d8688f1b6f1bc64cfd1f82e3af05b8ace1d709d4fa819acb4d12d74e1b69b4314d98fb4281dacc9b5fa51ff7370d0249f540ec016fd137aa701502d72426301 binutils-with-gold-2.44.tar.xz |
| 207 | 70ec22bd72ef6dddecfd970613387dd4a8cdc8730dd3cbf03d5a0c3a7c4d839383167bb06dad21bf7c235329fd44b5dc4aefe762f68544f17155cf002bf1be4a 0001-Revert-PR25882-.gnu.attributes-are-not-checked-for-s.patch |
| 208 | ecee33b0e435aa704af1c334e560f201638ff79e199aa11ed78a72f7c9b46f85fbb227af5748e735fd681d1965fcc42ac81b0c8824e540430ce0c706c81e8b49 binutils-ld-fix-static-linking.patch |
| 209 | 762ee44a847d56467294adad113562ba0bafbb90828530f93e7e2ee383bf7d52be58c5def6a2ff0e1ae7d24ab6682f220f7c6fe2fecab2b55fd4d31ef55e0e58 s390x-pie.patch |
| 210 | " |