1 |
1 |
# Copyright 1999-2025 Gentoo Authors
|
2 |
2 |
# Distributed under the terms of the GNU General Public License v2
|
3 |
3 |
|
4 |
|
EAPI=7
|
|
4 |
EAPI=8
|
5 |
5 |
|
6 |
|
inherit libtool flag-o-matic gnuconfig strip-linguas toolchain-funcs
|
|
6 |
inherit dot-a libtool flag-o-matic gnuconfig strip-linguas toolchain-funcs
|
7 |
7 |
|
8 |
8 |
DESCRIPTION="Tools necessary to build programs"
|
9 |
9 |
HOMEPAGE="https://sourceware.org/binutils/"
|
10 |
10 |
|
11 |
11 |
LICENSE="GPL-3+"
|
12 |
|
IUSE="cet debuginfod doc gold gprofng hardened multitarget +nls pgo +plugins static-libs test vanilla zstd"
|
|
12 |
IUSE="cet debuginfod doc gprofng hardened multitarget +nls pgo +plugins static-libs test vanilla xxhash zstd"
|
13 |
13 |
|
14 |
14 |
# Variables that can be set here (ignored for live ebuilds)
|
15 |
15 |
# PATCH_VER - the patchset version
|
... | ... | |
19 |
19 |
# PATCH_DEV - Use download URI https://dev.gentoo.org/~{PATCH_DEV}/distfiles/...
|
20 |
20 |
# for the patchsets
|
21 |
21 |
|
22 |
|
PATCH_VER=3
|
|
22 |
PATCH_VER=1
|
23 |
23 |
PATCH_DEV=dilfridge
|
24 |
24 |
|
25 |
25 |
if [[ ${PV} == 9999 ]]; then
|
... | ... | |
35 |
35 |
[[ -z ${PATCH_VER} ]] || SRC_URI="${SRC_URI}
|
36 |
36 |
https://dev.gentoo.org/~${PATCH_DEV}/distfiles/binutils-${PATCH_BINUTILS_VER}-patches-${PATCH_VER}.tar.xz"
|
37 |
37 |
SLOT=$(ver_cut 1-2)
|
38 |
|
KEYWORDS="~alpha amd64 arm arm64 hppa ~loong ~m68k ~mips ppc ppc64 ~riscv ~s390 sparc x86"
|
|
38 |
#KEYWORDS="~alpha ~amd64 ~arm ~arm64 ~hppa ~loong ~m68k ~mips ~ppc ~ppc64 ~riscv ~s390 ~sparc ~x86"
|
39 |
39 |
fi
|
40 |
40 |
|
41 |
41 |
#
|
... | ... | |
60 |
60 |
)
|
61 |
61 |
zstd? ( app-arch/zstd:= )
|
62 |
62 |
"
|
63 |
|
DEPEND="${RDEPEND}"
|
|
63 |
DEPEND="
|
|
64 |
${RDEPEND}
|
|
65 |
xxhash? ( dev-libs/xxhash )
|
|
66 |
"
|
64 |
67 |
BDEPEND="
|
65 |
68 |
doc? ( sys-apps/texinfo )
|
66 |
69 |
pgo? (
|
... | ... | |
83 |
86 |
|
84 |
87 |
src_unpack() {
|
85 |
88 |
if [[ ${PV} == *9999 ]] ; then
|
86 |
|
EGIT_REPO_URI="https://anongit.gentoo.org/git/proj/toolchain/binutils-patches.git"
|
|
89 |
EGIT_REPO_URI="
|
|
90 |
https://anongit.gentoo.org/git/proj/toolchain/binutils-patches.git
|
|
91 |
https://github.com/gentoo/binutils-patches
|
|
92 |
"
|
87 |
93 |
EGIT_CHECKOUT_DIR=${WORKDIR}/patches-git
|
88 |
94 |
git-r3_src_unpack
|
89 |
95 |
mv patches-git/9999 patch || die
|
... | ... | |
91 |
97 |
if [[ ${PV} != 9999 ]] ; then
|
92 |
98 |
EGIT_BRANCH=binutils-$(ver_cut 1)_$(ver_cut 2)-branch
|
93 |
99 |
fi
|
94 |
|
EGIT_REPO_URI="https://sourceware.org/git/binutils-gdb.git"
|
|
100 |
EGIT_REPO_URI="
|
|
101 |
https://sourceware.org/git/binutils-gdb.git
|
|
102 |
https://git.sr.ht/~sourceware/binutils-gdb
|
|
103 |
https://gitlab.com/x86-binutils/binutils-gdb.git
|
|
104 |
"
|
95 |
105 |
S=${WORKDIR}/binutils
|
96 |
106 |
EGIT_CHECKOUT_DIR=${S}
|
97 |
107 |
git-r3_src_unpack
|
... | ... | |
131 |
141 |
# This is applied conditionally for now just out of caution.
|
132 |
142 |
# It should be okay on non-prefix systems though. See bug #892549.
|
133 |
143 |
if is_cross || use prefix; then
|
134 |
|
eapply "${FILESDIR}"/binutils-2.40-linker-search-path.patch \
|
135 |
|
"${FILESDIR}"/binutils-2.41-linker-prefix.patch
|
|
144 |
eapply "${FILESDIR}"/binutils-2.43-linker-search-path.patch \
|
|
145 |
"${FILESDIR}"/binutils-2.43-linker-prefix.patch
|
136 |
146 |
fi
|
137 |
147 |
fi
|
138 |
148 |
fi
|
... | ... | |
184 |
194 |
strip-flags
|
185 |
195 |
use cet && filter-flags -mindirect-branch -mindirect-branch=*
|
186 |
196 |
use elibc_musl && append-ldflags -Wl,-z,stack-size=2097152
|
187 |
|
|
188 |
|
# https://sourceware.org/PR32372
|
189 |
|
append-cflags $(test-flags-CC -std=gnu17)
|
|
197 |
lto-guarantee-fat
|
190 |
198 |
|
191 |
199 |
local x
|
192 |
200 |
echo
|
... | ... | |
201 |
209 |
if use plugins ; then
|
202 |
210 |
myconf+=( --enable-plugins )
|
203 |
211 |
fi
|
204 |
|
# enable gold (installed as ld.gold) and ld's plugin architecture
|
205 |
|
if use gold ; then
|
206 |
|
myconf+=( --enable-gold )
|
207 |
|
fi
|
208 |
212 |
|
209 |
213 |
if use nls ; then
|
210 |
214 |
myconf+=( --without-included-gettext )
|
... | ... | |
269 |
273 |
--with-bugurl="$(toolchain-binutils_bugurl)"
|
270 |
274 |
--with-pkgversion="$(toolchain-binutils_pkgversion)"
|
271 |
275 |
$(use_enable static-libs static)
|
|
276 |
$(use_with xxhash)
|
272 |
277 |
$(use_with zstd)
|
273 |
278 |
|
274 |
279 |
# Disable modules that are in a combined binutils/gdb tree, bug #490566
|
... | ... | |
290 |
295 |
|
291 |
296 |
# We can enable this by default in future, but it's brand new
|
292 |
297 |
# in 2.39 with several bugs:
|
293 |
|
# - Doesn't build on musl (https://sourceware.org/bugzilla/show_bug.cgi?id=29477)
|
294 |
|
# - No man pages (https://sourceware.org/bugzilla/show_bug.cgi?id=29521)
|
295 |
|
# - Broken at runtime without Java (https://sourceware.org/bugzilla/show_bug.cgi?id=29479)
|
|
298 |
# - Doesn't build on musl (https://sourceware.org/PR29477)
|
|
299 |
# - No man pages (https://sourceware.org/PR29521)
|
|
300 |
# - Broken at runtime without Java (https://sourceware.org/PR29479)
|
296 |
301 |
# - binutils-config (and this ebuild?) needs adaptation first (https://bugs.gentoo.org/865113)
|
297 |
302 |
$(use_enable gprofng)
|
|
303 |
|
|
304 |
# Enables colored disassembly by default (equivalent to passing
|
|
305 |
# --disassembler-color=terminal to all objdump invocations).
|
|
306 |
--enable-colored-disassembly
|
298 |
307 |
)
|
299 |
308 |
|
300 |
309 |
case ${CTARGET} in
|
... | ... | |
302 |
311 |
# These hardening options are available from 2.39+ but
|
303 |
312 |
# they unconditionally enable the behaviour even on arches
|
304 |
313 |
# where e.g. execstacks can't be avoided.
|
305 |
|
# See https://sourceware.org/bugzilla/show_bug.cgi?id=29592.
|
|
314 |
# See https://sourceware.org/PR29592.
|
306 |
315 |
#
|
307 |
316 |
# TODO: Get the logic for this fixed upstream so it doesn't
|
308 |
317 |
# create impossible broken combinations on some arches, like mips.
|
... | ... | |
349 |
358 |
# with the testsuite.
|
350 |
359 |
filter-lto
|
351 |
360 |
|
|
361 |
# bug #637066
|
|
362 |
filter-flags -Wall -Wreturn-type
|
|
363 |
|
352 |
364 |
export BUILD_CFLAGS="${CFLAGS}"
|
353 |
365 |
fi
|
354 |
366 |
fi
|
... | ... | |
390 |
402 |
# Tests don't expect LTO
|
391 |
403 |
filter-lto
|
392 |
404 |
|
|
405 |
# If we have e.g. -mfpmath=sse -march=pentium4 in CFLAGS,
|
|
406 |
# we'll get lto1 warnings for some tests which cause
|
|
407 |
# spurious failures because -mfpmath isn't passed at
|
|
408 |
# link-time. Filter accordingly.
|
|
409 |
#
|
|
410 |
# Alternatively, we could pass C{C,XX}_FOR_TARGET with
|
|
411 |
# some (ideally not all, surely would break some tests)
|
|
412 |
# stuffed in.
|
|
413 |
filter-flags '-mfpmath=*'
|
|
414 |
|
393 |
415 |
# lto-wrapper warnings which confuse tests
|
394 |
416 |
filter-flags '-Wa,*'
|
395 |
417 |
|
... | ... | |
415 |
437 |
emake DESTDIR="${D}" tooldir="${EPREFIX}${LIBPATH}" install
|
416 |
438 |
rm -rf "${ED}"/${LIBPATH}/bin || die
|
417 |
439 |
use static-libs || find "${ED}" -name '*.la' -delete
|
|
440 |
# Explicit "${ED}" as we need it to do things even w/ USE=-static-libs
|
|
441 |
strip-lto-bytecode "${ED}"
|
418 |
442 |
|
419 |
443 |
# Newer versions of binutils get fancy with ${LIBPATH}, bug #171905
|
420 |
444 |
cd "${ED}"/${LIBPATH} || die
|
... | ... | |
502 |
526 |
find "${ED}" -depth -type d -exec rmdir {} + 2>/dev/null
|
503 |
527 |
}
|
504 |
528 |
|
|
529 |
# Simple test to make sure our new binutils isn't completely broken.
|
|
530 |
# Skip if this binutils is a cross compiler.
|
|
531 |
#
|
|
532 |
# If coreutils is built with USE=multicall, some of these files
|
|
533 |
# will just be wrapper scripts, not actual ELFs we can test.
|
|
534 |
binutils_sanity_check() {
|
|
535 |
pushd "${T}" >/dev/null
|
|
536 |
|
|
537 |
einfo "Last-minute run tests with binutils in ${ED}${BINPATH} ..."
|
|
538 |
|
|
539 |
cat <<-EOF > "${T}"/number.c
|
|
540 |
int get_magic_number() {
|
|
541 |
return 42;
|
|
542 |
}
|
|
543 |
EOF
|
|
544 |
|
|
545 |
cat <<-EOF > "${T}"/test.c
|
|
546 |
#include <stdio.h>
|
|
547 |
int get_magic_number();
|
|
548 |
|
|
549 |
int main() {
|
|
550 |
printf("Hello Gentoo! Your magic number is: %d\n", get_magic_number());
|
|
551 |
}
|
|
552 |
EOF
|
|
553 |
|
|
554 |
local -x LD_LIBRARY_PATH="${ED}${LIBPATH}${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}}"
|
|
555 |
|
|
556 |
local opt opt2
|
|
557 |
# TODO: test multilib variants?
|
|
558 |
for opt in '' '-O2' ; do
|
|
559 |
for opt2 in '-static' '-static-pie' '-fno-PIE -no-pie' ; do
|
|
560 |
$(tc-getCC) ${opt} ${opt2} -B"${ED}${BINPATH}" "${T}"/number.c "${T}"/test.c -o "${T}"/test
|
|
561 |
if "${T}"/test | grep -q "Hello Gentoo! Your magic number is: 42" ; then
|
|
562 |
:;
|
|
563 |
else
|
|
564 |
die "Test with '${opt} ${opt2}' failed! Aborting to avoid broken binutils!"
|
|
565 |
fi
|
|
566 |
done
|
|
567 |
done
|
|
568 |
|
|
569 |
popd >/dev/null
|
|
570 |
}
|
|
571 |
|
|
572 |
pkg_preinst() {
|
|
573 |
[[ -n ${ROOT} ]] && return 0
|
|
574 |
[[ -d ${ED}${BINPATH} ]] || return 0
|
|
575 |
[[ -n ${BOOTSTRAP_RAP} ]] || return 0
|
|
576 |
is_cross && return 0
|
|
577 |
binutils_sanity_check
|
|
578 |
}
|
|
579 |
|
505 |
580 |
pkg_postinst() {
|
506 |
581 |
# Make sure this ${CTARGET} has a binutils version selected
|
507 |
582 |
[[ -e ${EROOT}/etc/env.d/binutils/config-${CTARGET} ]] && return 0
|