remove ia64 keywords
[gentoo-zh.git] / app-emulation / liblol-glibc / liblol-glibc-0.1.5_pre6.ebuild
blobacdaa146dab9ec03cbc85989e7838e0ea0484219
1 # Copyright 1999-2024 Gentoo Authors
2 # Distributed under the terms of the GNU General Public License v2
4 EAPI=8
6 # Bumping notes: https://wiki.gentoo.org/wiki/Project:Toolchain/sys-libs/glibc
7 # Please read & adapt the page as necessary if obsolete.
9 PYTHON_COMPAT=( python3_{10..12} )
10 TMPFILES_OPTIONAL=1
12 inherit python-any-r1 toolchain-funcs flag-o-matic gnuconfig multilib tmpfiles
14 DESCRIPTION="GNU libc C library, for liblol"
15 HOMEPAGE="https://www.gnu.org/software/libc/ https://liblol.aosc.io"
16 LICENSE="LGPL-2.1+ BSD HPND ISC inner-net rc PCRE"
17 SLOT="2.2"
19 EMULTILIB_PKG="true"
21 # Gentoo patchset (ignored for live ebuilds)
22 PATCH_VER=2
23 PATCH_DEV=dilfridge
25 # liblol additions
26 GLIBC_PV=2.39
27 GLIBC_PVR=2.39-r2
28 LOLPREFIX=/opt/lol
30 LOL_LIBS=(
31 math/libm.so.6
32 resolv/libresolv.so.2
33 malloc/libc_malloc_debug.so.0
34 nptl_db/libthread_db.so.1
35 locale/libBrokenLocale.so.1
37 LOL_MERGED_LIBS=(
38 resolv/libanl.so.1
39 dlfcn/libdl.so.2
40 rt/librt.so.1
41 login/libutil.so.1
42 nis/libnsl.so.1
45 # gcc mulitilib bootstrap files version
46 GCC_BOOTSTRAP_VER=20201208
48 # systemd integration version
49 GLIBC_SYSTEMD_VER=20210729
51 # Minimum kernel version that glibc requires
52 MIN_KERN_VER="3.2.0"
54 # Minimum pax-utils version needed (which contains any new syscall changes for
55 # its seccomp filter!). Please double check this!
56 MIN_PAX_UTILS_VER="1.3.3"
58 # Minimum systemd version needed (which contains any new syscall changes for
59 # its seccomp filter!). Please double check this!
60 MIN_SYSTEMD_VER="254.9-r1"
62 if [[ ${PV} == 9999* ]]; then
63 inherit git-r3
64 else
65 #KEYWORDS="~alpha ~amd64 ~arm ~arm64 ~hppa -ia64 ~loong ~m68k ~mips ~ppc ~ppc64 ~riscv ~s390 ~sparc ~x86"
66 KEYWORDS="-* ~loong"
67 SRC_URI="mirror://gnu/glibc/glibc-${GLIBC_PV}.tar.xz"
68 SRC_URI+=" https://dev.gentoo.org/~${PATCH_DEV}/distfiles/glibc-${GLIBC_PV}-patches-${PATCH_VER}.tar.xz"
69 SRC_URI+=" https://github.com/AOSC-Dev/liblol/archive/refs/tags/v${PV}.tar.gz -> liblol-${PV}.tar.gz"
72 SRC_URI+=" multilib-bootstrap? ( https://dev.gentoo.org/~dilfridge/distfiles/gcc-multilib-bootstrap-${GCC_BOOTSTRAP_VER}.tar.xz )"
73 SRC_URI+=" systemd? ( https://gitweb.gentoo.org/proj/toolchain/glibc-systemd.git/snapshot/glibc-systemd-${GLIBC_SYSTEMD_VER}.tar.gz )"
75 S="${WORKDIR}/glibc-${GLIBC_PV}"
77 IUSE="audit caps cet compile-locales custom-cflags doc gd hash-sysv-compat headers-only +multiarch multilib multilib-bootstrap nscd perl profile selinux split-usr +ssp stack-realign +static-libs suid systemd systemtap test vanilla"
79 # Here's how the cross-compile logic breaks down ...
80 # CTARGET - machine that will target the binaries
81 # CHOST - machine that will host the binaries
82 # CBUILD - machine that will build the binaries
83 # If CTARGET != CHOST, it means you want a libc for cross-compiling.
84 # If CHOST != CBUILD, it means you want to cross-compile the libc.
85 # CBUILD = CHOST = CTARGET - native build/install
86 # CBUILD != (CHOST = CTARGET) - cross-compile a native build
87 # (CBUILD = CHOST) != CTARGET - libc for cross-compiler
88 # CBUILD != CHOST != CTARGET - cross-compile a libc for a cross-compiler
89 # For install paths:
90 # CHOST = CTARGET - install into /
91 # CHOST != CTARGET - install into /usr/CTARGET/
93 export CBUILD=${CBUILD:-${CHOST}}
94 export CTARGET=${CTARGET:-${CHOST}}
95 if [[ ${CTARGET} == ${CHOST} ]] ; then
96 if [[ ${CATEGORY} == cross-* ]] ; then
97 export CTARGET=${CATEGORY#cross-}
101 # Note [Disable automatic stripping]
102 # Disabling automatic stripping for a few reasons:
103 # - portage's attempt to strip breaks non-native binaries at least on
104 # arm: bug #697428
105 # - portage's attempt to strip libpthread.so.0 breaks gdb thread
106 # enumeration: bug #697910. This is quite subtle:
107 # * gdb uses glibc's libthread_db-1.0.so to enumerate threads.
108 # * libthread_db-1.0.so needs access to libpthread.so.0 local symbols
109 # via 'ps_pglobal_lookup' symbol defined in gdb.
110 # * 'ps_pglobal_lookup' uses '.symtab' section table to resolve all
111 # known symbols in 'libpthread.so.0'. Specifically 'nptl_version'
112 # (unexported) is used to sanity check compatibility before enabling
113 # debugging.
114 # Also see https://sourceware.org/gdb/wiki/FAQ#GDB_does_not_see_any_threads_besides_the_one_in_which_crash_occurred.3B_or_SIGTRAP_kills_my_program_when_I_set_a_breakpoint
115 # * normal 'strip' command trims '.symtab'
116 # Thus our main goal here is to prevent 'libpthread.so.0' from
117 # losing it's '.symtab' entries.
118 # - similarly, valgrind requires knowledge about symbols in ld.so:
119 # bug #920753
120 # As Gentoo's strip does not allow us to pass less aggressive stripping
121 # options and does not check the machine target we strip selectively.
123 # We need a new-enough binutils/gcc to match upstream baseline.
124 # Also we need to make sure our binutils/gcc supports TLS,
125 # and that gcc already contains the hardened patches.
126 # Lastly, let's avoid some openssh nastiness, bug 708224, as
127 # convenience to our users.
129 IDEPEND="
130 !compile-locales? ( sys-apps/locale-gen )
132 BDEPEND="
133 ${PYTHON_DEPS}
134 >=app-misc/pax-utils-${MIN_PAX_UTILS_VER}
135 >=dev-util/patchelf-liblol-0.1.4
136 sys-devel/bison
137 compile-locales? ( sys-apps/locale-gen )
138 doc? (
139 dev-lang/perl
140 sys-apps/texinfo
142 test? (
143 dev-lang/perl
144 >=net-dns/libidn2-2.3.0
147 COMMON_DEPEND="
148 gd? ( media-libs/gd:2= )
149 nscd? ( selinux? (
150 audit? ( sys-process/audit )
151 caps? ( sys-libs/libcap )
153 suid? ( caps? ( sys-libs/libcap ) )
154 selinux? ( sys-libs/libselinux )
155 systemtap? ( dev-debug/systemtap )
157 DEPEND="${COMMON_DEPEND}
159 RDEPEND="${COMMON_DEPEND}
160 !<app-emulation/liblol-0.1.0
161 !<app-misc/pax-utils-${MIN_PAX_UTILS_VER}
162 !<sys-apps/systemd-${MIN_SYSTEMD_VER}
163 perl? ( dev-lang/perl )
166 RESTRICT="!test? ( test )"
168 if [[ ${CATEGORY} == cross-* ]] ; then
169 BDEPEND+=" !headers-only? (
170 >=${CATEGORY}/binutils-2.27
171 >=${CATEGORY}/gcc-6.2
173 [[ ${CATEGORY} == *-linux* ]] && DEPEND+=" ${CATEGORY}/linux-headers"
174 else
175 BDEPEND+="
176 >=sys-devel/binutils-2.27
177 >=sys-devel/gcc-6.2
179 DEPEND+=" virtual/os-headers "
180 RDEPEND+="
181 >=net-dns/libidn2-2.3.0
182 vanilla? ( !sys-libs/timezone-data )
184 PDEPEND+=" !vanilla? ( sys-libs/timezone-data )"
187 # Ignore tests whitelisted below
188 GENTOO_GLIBC_XFAIL_TESTS="${GENTOO_GLIBC_XFAIL_TESTS:-yes}"
190 # The following tests fail due to the Gentoo build system and are thus
191 # executed but ignored:
192 XFAIL_TEST_LIST=(
193 # buggy test, assumes /dev/ and /dev/null on a single filesystem
194 # 'mount --bind /dev/null /chroot/dev/null' breaks it.
195 # https://sourceware.org/PR25909
196 tst-support_descriptors
198 # The following tests fail only inside portage
199 # https://bugs.gentoo.org/831267
200 tst-system
201 tst-strerror
202 tst-strsignal
204 # Fails with certain PORTAGE_NICENESS/PORTAGE_SCHEDULING_POLICY
205 tst-sched1
207 # Fails regularly, unreliable
208 tst-valgrind-smoke
211 XFAIL_NSPAWN_TEST_LIST=(
212 # These tests need to be adapted to handle EPERM/ENOSYS(?) properly
213 # upstream, as systemd-nspawn's default seccomp whitelist is too strict.
214 # https://sourceware.org/PR30603
215 test-errno-linux
216 tst-bz21269
217 tst-mlock2
218 tst-ntp_gettime
219 tst-ntp_gettime-time64
220 tst-ntp_gettimex
221 tst-ntp_gettimex-time64
222 tst-pkey
223 tst-process_mrelease
224 tst-adjtime
225 tst-adjtime-time64
226 tst-clock2
227 tst-clock2-time64
229 # These fail if --suppress-sync and/or low priority is set
230 tst-sync_file_range
231 test-errno
235 # Small helper functions
238 dump_build_environment() {
239 einfo ==== glibc build environment ========================================================
240 local v
241 for v in ABI CBUILD CHOST CTARGET CBUILD_OPT CTARGET_OPT CC CXX CPP LD {AS,C,CPP,CXX,LD}FLAGS MAKEINFO NM AR AS STRIP RANLIB OBJCOPY STRINGS OBJDUMP READELF; do
242 einfo " $(printf '%15s' ${v}:) ${!v}"
243 done
244 einfo =====================================================================================
247 is_crosscompile() {
248 [[ ${CHOST} != ${CTARGET} ]]
251 just_headers() {
252 is_crosscompile && use headers-only
255 alt_prefix() {
256 is_crosscompile && echo /usr/${CTARGET}
259 # This prefix is applicable to CHOST when building against this
260 # glibc. It is baked into the library at configure time.
261 host_eprefix() {
262 is_crosscompile || echo "${EPREFIX}"
265 eprefix_lol() {
266 echo "${EPREFIX}${LOLPREFIX}"
269 # This prefix is applicable to CBUILD when building against this
270 # glibc. It determines the destination path at install time.
271 build_eprefix() {
272 is_crosscompile && echo "${EPREFIX}"
275 # We need to be able to set alternative headers for compiling for non-native
276 # platform. Will also become useful for testing kernel-headers without screwing
277 # up the whole system.
278 alt_headers() {
279 echo ${ALT_HEADERS:=$(alt_prefix)/usr/include}
282 alt_build_headers() {
283 if [[ -z ${ALT_BUILD_HEADERS} ]] ; then
284 ALT_BUILD_HEADERS="$(host_eprefix)$(alt_headers)"
285 if tc-is-cross-compiler ; then
286 ALT_BUILD_HEADERS=${SYSROOT}$(alt_headers)
287 if [[ ! -e ${ALT_BUILD_HEADERS}/linux/version.h ]] ; then
288 local header_path=$(echo '#include <linux/version.h>' | $(tc-getCPP ${CTARGET}) ${CFLAGS} 2>&1 | grep -o '[^"]*linux/version.h')
289 ALT_BUILD_HEADERS=${header_path%/linux/version.h}
293 echo "${ALT_BUILD_HEADERS}"
296 alt_libdir() {
297 echo $(alt_prefix)${LOLPREFIX}/$(get_libdir)
299 alt_usrlibdir() {
300 echo $(alt_prefix)${LOLPREFIX}/usr/$(get_libdir)
303 builddir() {
304 echo "${WORKDIR}/build-${ABI}-${CTARGET}-$1"
307 do_compile_test() {
308 local ret save_cflags=${CFLAGS}
309 CFLAGS+=" $1"
310 shift
312 pushd "${T}" >/dev/null
314 rm -f glibc-test*
315 printf '%b' "$*" > glibc-test.c
317 # We assume CC is already set up.
318 nonfatal emake glibc-test
319 ret=$?
321 popd >/dev/null
323 CFLAGS=${save_cflags}
324 return ${ret}
327 do_run_test() {
328 local ret
330 if [[ ${MERGE_TYPE} == "binary" ]] ; then
331 # ignore build failures when installing a binary package #324685
332 do_compile_test "" "$@" 2>/dev/null || return 0
333 else
334 if ! do_compile_test "" "$@" ; then
335 ewarn "Simple build failed ... assuming this is desired #324685"
336 return 0
340 pushd "${T}" >/dev/null
342 ./glibc-test
343 ret=$?
344 rm -f glibc-test*
346 popd >/dev/null
348 return ${ret}
351 setup_target_flags() {
352 # This largely mucks with compiler flags. None of which should matter
353 # when building up just the headers.
354 just_headers && return 0
356 case $(tc-arch) in
357 x86)
358 # -march needed for #185404 #199334
359 # TODO: When creating the first glibc cross-compile, this test will
360 # always fail as it does a full link which in turn requires glibc.
361 # Probably also applies when changing multilib profile settings (e.g.
362 # enabling x86 when the profile was amd64-only previously).
363 # We could change main to _start and pass -nostdlib here so that we
364 # only test the gcc code compilation. Or we could do a compile and
365 # then look for the symbol via scanelf.
366 if ! do_compile_test "" 'void f(int i, void *p) {if (__sync_fetch_and_add(&i, 1)) f(i, p);}\nint main(){return 0;}\n'; then
367 local t=${CTARGET_OPT:-${CTARGET}}
368 t=${t%%-*}
369 filter-flags '-march=*'
370 export CFLAGS="-march=${t} ${CFLAGS}"
371 einfo "Auto adding -march=${t} to CFLAGS #185404"
373 # For compatibility with older binaries at slight performance cost.
374 use stack-realign && export CFLAGS+=" -mstackrealign"
376 amd64)
377 # -march needed for #185404 #199334
378 # TODO: See cross-compile issues listed above for x86.
379 if [[ ${ABI} == x86 ]]; then
380 if ! do_compile_test "${CFLAGS_x86}" 'void f(int i, void *p) {if (__sync_fetch_and_add(&i, 1)) f(i, p);}\nint main(){return 0;}\n'; then
381 local t=${CTARGET_OPT:-${CTARGET}}
382 t=${t%%-*}
383 # Normally the target is x86_64-xxx, so turn that into the -march that
384 # gcc actually accepts. #528708
385 [[ ${t} == "x86_64" ]] && t="x86-64"
386 filter-flags '-march=*'
387 # ugly, ugly, ugly. ugly.
388 CFLAGS_x86=$(CFLAGS=${CFLAGS_x86} filter-flags '-march=*'; echo "${CFLAGS}")
389 export CFLAGS_x86="${CFLAGS_x86} -march=${t}"
390 einfo "Auto adding -march=${t} to CFLAGS_x86 #185404 (ABI=${ABI})"
392 # For compatibility with older binaries at slight performance cost.
393 use stack-realign && export CFLAGS_x86+=" -mstackrealign"
395 # Workaround for bug #823780.
396 # Need to save/restore CC because earlier on, we stuff it full of CFLAGS, and tc-getCPP doesn't like that.
397 CC_mangled=${CC}
398 CC=${glibc__GLIBC_CC}
399 if tc-is-gcc && (($(gcc-major-version) == 11)) && (($(gcc-minor-version) <= 2)) && (($(gcc-micro-version) == 0)) ; then
400 export CFLAGS_x86="${CFLAGS_x86} -mno-avx512f"
401 einfo "Auto adding -mno-avx512f to CFLAGS_x86 for buggy GCC version (bug #823780) (ABI=${ABI})"
403 CC=${CC_mangled}
406 mips)
407 # The mips abi cannot support the GNU style hashes. #233233
408 filter-ldflags -Wl,--hash-style=gnu -Wl,--hash-style=both
410 ppc|ppc64)
411 # Many arch-specific implementations do not work on ppc with
412 # cache-block not equal to 128 bytes. This breaks memset:
413 # https://sourceware.org/PR26522
414 # https://bugs.gentoo.org/737996
415 # Use default -mcpu=. For ppc it means non-multiarch setup.
416 filter-flags '-mcpu=*'
418 sparc)
419 # Both sparc and sparc64 can use -fcall-used-g6. -g7 is bad, though.
420 filter-flags "-fcall-used-g7"
421 append-flags "-fcall-used-g6"
423 local cpu
424 case ${CTARGET} in
425 sparc64-*)
426 cpu="sparc64"
427 case $(get-flag mcpu) in
429 # We need to force at least v9a because the base build doesn't
430 # work with just v9.
431 # https://sourceware.org/bugzilla/show_bug.cgi?id=19477
432 append-flags "-Wa,-xarch=v9a"
434 esac
436 sparc-*)
437 case $(get-flag mcpu) in
438 v8|supersparc|hypersparc|leon|leon3)
439 cpu="sparcv8"
442 cpu="sparcv9"
444 esac
446 esac
447 [[ -n ${cpu} ]] && CTARGET_OPT="${cpu}-${CTARGET#*-}"
449 esac
452 setup_flags() {
453 # Make sure host make.conf doesn't pollute us
454 if is_crosscompile || tc-is-cross-compiler ; then
455 CHOST=${CTARGET} strip-unsupported-flags
458 # Store our CFLAGS because it's changed depending on which CTARGET
459 # we are building when pulling glibc on a multilib profile
460 CFLAGS_BASE=${CFLAGS_BASE-${CFLAGS}}
461 CFLAGS=${CFLAGS_BASE}
462 CXXFLAGS_BASE=${CXXFLAGS_BASE-${CXXFLAGS}}
463 CXXFLAGS=${CXXFLAGS_BASE}
464 ASFLAGS_BASE=${ASFLAGS_BASE-${ASFLAGS}}
465 ASFLAGS=${ASFLAGS_BASE}
467 # Allow users to explicitly avoid flag sanitization via
468 # USE=custom-cflags.
469 if ! use custom-cflags; then
470 # Over-zealous CFLAGS can often cause problems. What may work for one
471 # person may not work for another. To avoid a large influx of bugs
472 # relating to failed builds, we strip most CFLAGS out to ensure as few
473 # problems as possible.
474 strip-flags
475 # Lock glibc at -O2; we want to be conservative here.
476 filter-flags '-O?'
477 append-flags -O2
480 strip-unsupported-flags
481 filter-lto
482 filter-flags -m32 -m64 '-mabi=*'
484 # glibc aborts if rpath is set by LDFLAGS
485 filter-ldflags '-Wl,-rpath=*'
487 # ld can't use -r & --relax at the same time, bug #788901
488 # https://sourceware.org/PR27837
489 filter-ldflags '-Wl,--relax'
491 # Flag added for cross-prefix, but causes ldconfig to segfault. Not needed
492 # anyway because glibc already handles this by itself.
493 filter-ldflags '-Wl,--dynamic-linker=*'
495 # some weird software relies on sysv hashes in glibc, bug 863863, bug 864100
496 # we have to do that here already so mips can filter it out again :P
497 if use hash-sysv-compat ; then
498 append-ldflags '-Wl,--hash-style=both'
501 # #492892
502 filter-flags -frecord-gcc-switches
504 # #898098
505 filter-flags -fno-builtin
507 # #829583
508 filter-lfs-flags
510 unset CBUILD_OPT CTARGET_OPT
511 if use multilib ; then
512 CTARGET_OPT=$(get_abi_CTARGET)
513 [[ -z ${CTARGET_OPT} ]] && CTARGET_OPT=$(get_abi_CHOST)
516 setup_target_flags
518 if [[ -n ${CTARGET_OPT} && ${CBUILD} == ${CHOST} ]] && ! is_crosscompile; then
519 CBUILD_OPT=${CTARGET_OPT}
522 # glibc's headers disallow -O0 and fail at build time:
523 # include/libc-symbols.h:75:3: #error "glibc cannot be compiled without optimization"
524 # https://sourceware.org/glibc/wiki/FAQ#Why_do_I_get:.60.23error_.22glibc_cannot_be_compiled_without_optimization.22.27.2C_when_trying_to_compile_GNU_libc_with_GNU_CC.3F
525 replace-flags -O0 -O1
527 # glibc handles this internally already where it's appropriate;
528 # can't always have SSP when we're the ones setting it up, etc
529 filter-flags '-fstack-protector*'
531 # Similar issues as with SSP. Can't inject yourself that early.
532 filter-flags '-fsanitize=*'
534 # See end of bug #830454; we handle this via USE=cet
535 filter-flags '-fcf-protection=*'
537 # When bootstrapping, we may have a situation where
538 # CET-enabled gcc from seed is used to build CET-disabled
539 # glibc. As such, gcc implicitly enables CET if no
540 # -fcf-protection flag is passed. For a typical package it
541 # should not be a problem, but for glibc it matters as it is
542 # dealing with CET in ld.so. So if CET is supposed to be
543 # disabled for glibc, be explicit about it.
544 if ! use cet; then
545 if use amd64 || use x86; then
546 append-flags '-fcf-protection=none'
547 elif use arm64; then
548 append-flags '-mbranch-protection=none'
553 use_multiarch() {
554 # Allow user to disable runtime arch detection in multilib.
555 use multiarch || return 1
556 # Make sure binutils is new enough to support indirect functions,
557 # #336792. This funky sed supports gold and bfd linkers.
558 local bver nver
559 bver=$($(tc-getLD ${CTARGET}) -v | sed -n -r '1{s:[^0-9]*::;s:^([0-9.]*).*:\1:;p}')
560 case $(tc-arch ${CTARGET}) in
561 amd64|x86) nver="2.20" ;;
562 arm) nver="2.22" ;;
563 hppa) nver="2.23" ;;
564 ppc|ppc64) nver="2.20" ;;
565 # ifunc support was added in 2.23, but glibc also needs
566 # machinemode which is in 2.24.
567 s390) nver="2.24" ;;
568 sparc) nver="2.21" ;;
569 *) return 1 ;;
570 esac
571 ver_test ${bver} -ge ${nver}
574 # Setup toolchain variables that had historically been defined in the
575 # profiles for these archs.
576 setup_env() {
577 # silly users
578 unset LD_RUN_PATH
579 unset LD_ASSUME_KERNEL
581 if is_crosscompile || tc-is-cross-compiler ; then
582 multilib_env ${CTARGET_OPT:-${CTARGET}}
584 if ! use multilib ; then
585 MULTILIB_ABIS=${DEFAULT_ABI}
586 else
587 MULTILIB_ABIS=${MULTILIB_ABIS:-${DEFAULT_ABI}}
590 # If the user has CFLAGS_<CTARGET> in their make.conf, use that,
591 # and fall back on CFLAGS.
592 local VAR=CFLAGS_${CTARGET//[-.]/_}
593 CFLAGS=${!VAR-${CFLAGS}}
594 einfo " $(printf '%15s' 'Manual CFLAGS:') ${CFLAGS}"
597 setup_flags
599 export ABI=${ABI:-${DEFAULT_ABI:-default}}
601 if just_headers ; then
602 # Avoid mixing host's CC and target's CFLAGS_${ABI}:
603 # At this bootstrap stage we have only binutils for
604 # target but not compiler yet.
605 einfo "Skip CC ABI injection. We can't use (cross-)compiler yet."
606 return 0
609 # Glibc does not work with gold (for various reasons) #269274.
610 tc-ld-disable-gold
612 if use doc ; then
613 export MAKEINFO=makeinfo
614 else
615 export MAKEINFO=/dev/null
618 # Reset CC and CXX to the value at start of emerge
619 export CC=${glibc__ORIG_CC:-${CC:-$(tc-getCC ${CTARGET})}}
620 export CXX=${glibc__ORIG_CXX:-${CXX:-$(tc-getCXX ${CTARGET})}}
622 # and make sure glibc__ORIG_CC and glibc__ORIG_CXX is defined now.
623 export glibc__ORIG_CC=${CC}
624 export glibc__ORIG_CXX=${CXX}
626 if tc-is-clang && ! use custom-cflags && ! is_crosscompile ; then
627 export glibc__force_gcc=yes
628 # once this is toggled on, it needs to stay on, since with CPP manipulated
629 # tc-is-clang does not work correctly anymore...
632 if [[ ${glibc__force_gcc} == "yes" ]] ; then
633 # If we are running in an otherwise clang/llvm environment, we need to
634 # recover the proper gcc and binutils settings here, at least until glibc
635 # is finally building with clang. So let's override everything that is
636 # set in the clang profiles.
637 # Want to shoot yourself into the foot? Set USE=custom-cflags, that's always
638 # a good start into that direction.
639 # Also, if you're crosscompiling, let's assume you know what you are doing.
640 # Hopefully.
641 # Last, we need the settings of the *build* environment, not of the
642 # target environment...
644 local current_binutils_path=$(env ROOT="${BROOT}" binutils-config -B)
645 local current_gcc_path=$(env ROOT="${BROOT}" gcc-config -B)
646 einfo "Overriding clang configuration, since it won't work here"
648 export CC="${current_gcc_path}/gcc"
649 export CPP="${current_gcc_path}/cpp"
650 export CXX="${current_gcc_path}/g++"
651 export LD="${current_binutils_path}/ld.bfd"
652 export AR="${current_binutils_path}/ar"
653 export AS="${current_binutils_path}/as"
654 export NM="${current_binutils_path}/nm"
655 export STRIP="${current_binutils_path}/strip"
656 export RANLIB="${current_binutils_path}/ranlib"
657 export OBJCOPY="${current_binutils_path}/objcopy"
658 export STRINGS="${current_binutils_path}/strings"
659 export OBJDUMP="${current_binutils_path}/objdump"
660 export READELF="${current_binutils_path}/readelf"
661 export ADDR2LINE="${current_binutils_path}/addr2line"
663 # do we need to also do flags munging here? yes! at least...
664 filter-flags '-fuse-ld=*'
665 filter-flags '-D_FORTIFY_SOURCE=*'
667 else
669 # this is the "normal" case
671 export CC="$(tc-getCC ${CTARGET})"
672 export CXX="$(tc-getCXX ${CTARGET})"
674 # Always use tuple-prefixed toolchain. For non-native ABI glibc's configure
675 # can't detect them automatically due to ${CHOST} mismatch and fallbacks
676 # to unprefixed tools. Similar to multilib.eclass:multilib_toolchain_setup().
677 export NM="$(tc-getNM ${CTARGET})"
678 export READELF="$(tc-getREADELF ${CTARGET})"
682 # We need to export CFLAGS with abi information in them because glibc's
683 # configure script checks CFLAGS for some targets (like mips). Keep
684 # around the original clean value to avoid appending multiple ABIs on
685 # top of each other. (Why does the comment talk about CFLAGS if the code
686 # acts on CC?)
687 export glibc__GLIBC_CC=${CC}
688 export glibc__GLIBC_CXX=${CXX}
690 export glibc__abi_CFLAGS="$(get_abi_CFLAGS)"
692 # CFLAGS can contain ABI-specific flags like -mfpu=neon, see bug #657760
693 # To build .S (assembly) files with the same ABI-specific flags
694 # upstream currently recommends adding CFLAGS to CC/CXX:
695 # https://sourceware.org/PR23273
696 # Note: Passing CFLAGS via CPPFLAGS overrides glibc's arch-specific CFLAGS
697 # and breaks multiarch support. See 659030#c3 for an example.
698 # The glibc configure script doesn't properly use LDFLAGS all the time.
699 export CC="${glibc__GLIBC_CC} ${glibc__abi_CFLAGS} ${CFLAGS} ${LDFLAGS}"
701 # Some of the tests are written in C++, so we need to force our multlib abis in, bug 623548
702 export CXX="${glibc__GLIBC_CXX} ${glibc__abi_CFLAGS} ${CFLAGS}"
704 if is_crosscompile; then
705 # Assume worst-case bootstrap: glibc is built for the first time
706 # with ${CTARGET}-g++ not available yet. We avoid
707 # building auxiliary programs that require C++: bug #683074
708 # It should not affect final result.
709 export libc_cv_cxx_link_ok=no
710 # The line above has the same effect. We set CXX explicitly
711 # to make build logs less confusing.
712 export CXX=
716 foreach_abi() {
717 setup_env
719 local ret=0
720 local abilist=""
721 if use multilib ; then
722 abilist=$(get_install_abis)
723 else
724 abilist=${DEFAULT_ABI}
726 local -x ABI
727 for ABI in ${abilist:-default} ; do
728 setup_env
729 einfo "Running $1 for ABI ${ABI}"
731 : $(( ret |= $? ))
732 done
733 return ${ret}
736 glibc_banner() {
737 local b="Gentoo ${GLIBC_PVR}"
738 [[ -n ${PATCH_VER} ]] && ! use vanilla && b+=" (patchset ${PATCH_VER})"
739 echo "${b}, LibLoL ${PVR}"
742 # The following Kernel version handling functions are mostly copied from portage
743 # source. It's better not to use linux-info.eclass here since a) it adds too
744 # much magic, see bug 326693 for some of the arguments, and b) some of the
745 # functions are just not provided.
747 g_get_running_KV() {
748 uname -r
749 return $?
752 g_KV_major() {
753 [[ -z $1 ]] && return 1
754 local KV=$@
755 echo "${KV%%.*}"
758 g_KV_minor() {
759 [[ -z $1 ]] && return 1
760 local KV=$@
761 KV=${KV#*.}
762 echo "${KV%%.*}"
765 g_KV_micro() {
766 [[ -z $1 ]] && return 1
767 local KV=$@
768 KV=${KV#*.*.}
769 echo "${KV%%[^[:digit:]]*}"
772 g_KV_to_int() {
773 [[ -z $1 ]] && return 1
774 local KV_MAJOR=$(g_KV_major "$1")
775 local KV_MINOR=$(g_KV_minor "$1")
776 local KV_MICRO=$(g_KV_micro "$1")
777 local KV_int=$(( KV_MAJOR * 65536 + KV_MINOR * 256 + KV_MICRO ))
779 # We make version 2.2.0 the minimum version we will handle as
780 # a sanity check ... if its less, we fail ...
781 if [[ ${KV_int} -ge 131584 ]] ; then
782 echo "${KV_int}"
783 return 0
785 return 1
788 g_int_to_KV() {
789 local version=$1 major minor micro
790 major=$((version / 65536))
791 minor=$(((version % 65536) / 256))
792 micro=$((version % 256))
793 echo ${major}.${minor}.${micro}
796 eend_KV() {
797 [[ $(g_KV_to_int $1) -ge $(g_KV_to_int $2) ]]
798 eend $?
801 get_kheader_version() {
802 printf '#include <linux/version.h>\nLINUX_VERSION_CODE\n' | \
803 $(tc-getCPP ${CTARGET}) -I "$(build_eprefix)$(alt_build_headers)" - | \
804 tail -n 1
807 # We collect all sanity checks here. Consistency is not guranteed between
808 # pkg_ and src_ phases, so we call this function both in pkg_pretend and in
809 # src_unpack.
810 sanity_prechecks() {
811 # Prevent native builds from downgrading
812 if [[ ${MERGE_TYPE} != "buildonly" ]] && \
813 [[ -z ${ROOT} ]] && \
814 [[ ${CBUILD} == ${CHOST} ]] && \
815 [[ ${CHOST} == ${CTARGET} ]] ; then
817 # The high rev # is to allow people to downgrade between -r#
818 # versions. We want to block 2.20->2.19, but 2.20-r3->2.20-r2
819 # should be fine. Hopefully we never actually use a r# this
820 # high.
821 if has_version ">${CATEGORY}/${P}-r10000" ; then
822 eerror "Sanity check to keep you from breaking your system:"
823 eerror " Downgrading glibc is not supported and a sure way to destruction."
824 [[ ${I_ALLOW_TO_BREAK_MY_SYSTEM} = yes ]] || die "Aborting to save your system."
827 if ! do_run_test '#include <unistd.h>\n#include <sys/syscall.h>\nint main(){return syscall(1000)!=-1;}\n' ; then
828 eerror "Your old kernel is broken. You need to update it to a newer"
829 eerror "version as syscall(<bignum>) will break. See bug 279260."
830 die "Old and broken kernel."
834 if [[ ${CTARGET} == i386-* ]] ; then
835 eerror "i386 CHOSTs are no longer supported."
836 eerror "Chances are you don't actually want/need i386."
837 eerror "Please read https://www.gentoo.org/doc/en/change-chost.xml"
838 die "Please fix your CHOST"
841 if [[ -e /proc/xen ]] && [[ $(tc-arch) == "x86" ]] && ! is-flag -mno-tls-direct-seg-refs ; then
842 ewarn "You are using Xen but don't have -mno-tls-direct-seg-refs in your CFLAGS."
843 ewarn "This will result in a 50% performance penalty when running with a 32bit"
844 ewarn "hypervisor, which is probably not what you want."
847 # ABI-specific checks follow here. Hey, we have a lot more specific conditions that
848 # we test for...
849 if ! is_crosscompile ; then
850 if use amd64 && use multilib && [[ ${MERGE_TYPE} != "binary" ]] ; then
851 ebegin "Checking that IA32 emulation is enabled in the running kernel"
852 echo 'int main(){return 0;}' > "${T}/check-ia32-emulation.c"
853 local STAT
854 if ${CC-${CHOST}-gcc} ${CFLAGS_x86} "${T}/check-ia32-emulation.c" -o "${T}/check-ia32-emulation.elf32"; then
855 "${T}/check-ia32-emulation.elf32"
856 STAT=$?
857 else
858 # Don't fail here to allow single->multi ABI switch
859 # or recover from breakage like bug #646424
860 ewarn "Failed to compile the ABI test. Broken host glibc?"
861 STAT=0
863 rm -f "${T}/check-ia32-emulation.elf32"
864 eend $STAT
865 [[ $STAT -eq 0 ]] || die "CONFIG_IA32_EMULATION must be enabled in the kernel to compile a multilib glibc."
870 # When we actually have to compile something...
871 if ! just_headers && [[ ${MERGE_TYPE} != "binary" ]] ; then
872 if [[ -d "${ESYSROOT}"/usr/lib/include ]] ; then
873 # bug #833620, bug #643302
874 eerror "Found ${ESYSROOT}/usr/lib/include directory!"
875 eerror "This is known to break glibc's build."
876 eerror "Please backup its contents then remove the directory."
877 die "Found directory (${ESYSROOT}/usr/lib/include) which will break build (bug #833620)!"
880 if [[ ${CTARGET} == *-linux* ]] ; then
881 local run_kv build_kv want_kv
883 run_kv=$(g_get_running_KV)
884 build_kv=$(g_int_to_KV $(get_kheader_version))
885 want_kv=${MIN_KERN_VER}
887 if ! is_crosscompile && ! tc-is-cross-compiler ; then
888 # Building fails on an non-supporting kernel
889 ebegin "Checking running kernel version (${run_kv} >= ${want_kv})"
890 if ! eend_KV ${run_kv} ${want_kv} ; then
891 echo
892 eerror "You need a kernel of at least ${want_kv}!"
893 die "Kernel version too low!"
897 # Do not run this check for pkg_pretend, just pkg_setup and friends (if we ever get used there).
898 # It's plausible (seen it in the wild) that Portage will (correctly) schedule a linux-headers
899 # upgrade before glibc, but because pkg_pretend gets run before any packages are merged at all (not
900 # just glibc), the whole emerge gets aborted without a good reason. We probably don't
901 # need to run this check at all given we have a dependency on the right headers,
902 # but let's leave it as-is for now.
903 if [[ ${EBUILD_PHASE_FUNC} != pkg_pretend ]] ; then
904 ebegin "Checking linux-headers version (${build_kv} >= ${want_kv})"
905 if ! eend_KV ${build_kv} ${want_kv} ; then
906 echo
907 eerror "You need linux-headers of at least ${want_kv}!"
908 die "linux-headers version too low!"
915 upgrade_warning() {
916 # unneeded for liblol
917 return
921 # the phases
924 # pkg_pretend
926 pkg_pretend() {
927 upgrade_warning
930 # pkg_setup
932 pkg_setup() {
933 # see bug 682570
934 [[ -z ${BOOTSTRAP_RAP} ]] && python-any-r1_pkg_setup
937 # src_unpack
939 src_unpack() {
940 setup_env
942 einfo "Checking general environment sanity."
943 sanity_prechecks
945 use multilib-bootstrap && unpack gcc-multilib-bootstrap-${GCC_BOOTSTRAP_VER}.tar.xz
947 if [[ ${PV} == 9999* ]] ; then
948 EGIT_REPO_URI="https://anongit.gentoo.org/git/proj/toolchain/glibc-patches.git"
949 EGIT_CHECKOUT_DIR=${WORKDIR}/patches-git
950 git-r3_src_unpack
951 mv patches-git/9999 patches || die
953 EGIT_REPO_URI="https://sourceware.org/git/glibc.git"
954 EGIT_CHECKOUT_DIR=${S}
955 git-r3_src_unpack
956 else
957 unpack glibc-${GLIBC_PV}.tar.xz
959 cd "${WORKDIR}" || die
960 unpack glibc-${GLIBC_PV}-patches-${PATCH_VER}.tar.xz
962 unpack "liblol-${PV}.tar.gz"
965 cd "${WORKDIR}" || die
966 use systemd && unpack glibc-systemd-${GLIBC_SYSTEMD_VER}.tar.gz
969 # src_prepare
971 src_prepare() {
972 local patchsetname
973 if ! use vanilla ; then
974 if [[ ${PV} == 9999* ]] ; then
975 patchsetname="from git master"
976 else
977 patchsetname="${GLIBC_PV}-${PATCH_VER}"
979 einfo "Applying Gentoo Glibc patchset ${patchsetname}"
980 eapply "${WORKDIR}"/patches
981 einfo "Done."
984 einfo "Applying libLoL patchset"
985 eapply "${WORKDIR}/liblol-${PV}/autobuild/patches/glibc"
986 einfo "Done."
988 default
990 gnuconfig_update
992 cd "${WORKDIR}" || die
993 find . -name configure -exec touch {} +
995 # Fix permissions on some of the scripts.
996 chmod u+x "${S}"/scripts/*.sh
998 cd "${S}" || die
1001 # src_configure
1003 glibc_do_configure() {
1004 dump_build_environment
1006 local myconf=()
1008 # Use '=strong' instead of '=all' to protect only functions
1009 # worth protecting from stack smashes.
1010 myconf+=( --enable-stack-protector=$(usex ssp strong no) )
1012 # Keep a whitelist of targets supporing IFUNC. glibc's ./configure
1013 # is not robust enough to detect proper support:
1014 # https://bugs.gentoo.org/641216
1015 # https://sourceware.org/PR22634#c0
1016 case $(tc-arch ${CTARGET}) in
1017 # Keep whitelist of targets where autodetection mostly works.
1018 amd64|x86|sparc|ppc|ppc64|arm|arm64|s390|riscv|loong) ;;
1019 # Blacklist everywhere else
1020 *) myconf+=( libc_cv_ld_gnu_indirect_function=no ) ;;
1021 esac
1023 case ${ABI}-${CTARGET} in
1024 amd64-x86_64-*|x32-x86_64-*-*-gnux32) myconf+=( $(use_enable cet) ) ;;
1025 *) ;;
1026 esac
1028 [[ $(tc-is-softfloat) == "yes" ]] && myconf+=( --without-fp )
1030 myconf+=( --enable-kernel=${MIN_KERN_VER} )
1032 # Since SELinux support is only required for nscd, only enable it if:
1033 # 1. USE selinux
1034 # 2. only for the primary ABI on multilib systems
1035 # 3. Not a crosscompile
1036 if ! is_crosscompile && use selinux ; then
1037 if use multilib ; then
1038 if is_final_abi ; then
1039 myconf+=( --with-selinux )
1040 else
1041 myconf+=( --without-selinux )
1043 else
1044 myconf+=( --with-selinux )
1046 else
1047 myconf+=( --without-selinux )
1050 # Force a few tests where we always know the answer but
1051 # configure is incapable of finding it.
1052 if is_crosscompile ; then
1053 export \
1054 libc_cv_c_cleanup=yes \
1055 libc_cv_forced_unwind=yes
1058 myconf+=(
1059 --disable-werror
1060 --enable-bind-now
1061 --enable-fortify-source
1062 --enable-obsolete-rpc # liblol passes this, not sure if essential
1063 --build=${CBUILD_OPT:-${CBUILD}}
1064 --host=${CTARGET_OPT:-${CTARGET}}
1065 $(use_enable profile)
1066 $(use_with gd)
1067 --with-headers=$(build_eprefix)$(alt_build_headers)
1068 --prefix="$(host_eprefix)/usr"
1069 --sysconfdir="$(eprefix_lol)/etc"
1070 --localstatedir="$(eprefix_lol)/var"
1071 --libdir='$(prefix)'/$(get_libdir)
1072 --mandir='$(prefix)'/share/man
1073 --infodir='$(prefix)'/share/info
1074 --libexecdir='$(libdir)'/misc/glibc
1075 --with-bugurl=https://github.com/AOSC-Dev/liblol/issues
1076 --with-pkgversion="$(glibc_banner)"
1077 $(use_multiarch || echo --disable-multi-arch)
1078 $(use_enable systemtap)
1079 $(use_enable nscd)
1081 # /usr/bin/mtrace has a Perl shebang. Gentoo Prefix QA checks fail if
1082 # Perl hasn't been installed inside the prefix yet and configure picks
1083 # up a Perl from outside the prefix instead. configure will fail to
1084 # execute Perl during configure if we're cross-compiling a prefix, but
1085 # it will just disable mtrace in that case.
1086 # Note: mtrace is needed by the test suite.
1087 ac_cv_path_PERL="$(usex perl "${EPREFIX}"/usr/bin/perl $(usex test "${EPREFIX}"/usr/bin/perl $(usex doc "${EPREFIX}"/usr/bin/perl no)))"
1089 # locale data is arch-independent
1090 # https://bugs.gentoo.org/753740
1091 libc_cv_complocaledir='${exec_prefix}/lib/locale'
1093 # On aarch64 there is no way to override -mcpu=native, and if
1094 # the current cpu does not support SVE configure fails.
1095 # Let's boldly assume our toolchain can always build SVE instructions.
1096 libc_cv_aarch64_sve_asm=yes
1098 ${EXTRA_ECONF}
1101 # We rely on sys-libs/timezone-data for timezone tools normally.
1102 myconf+=( $(use_enable vanilla timezone-tools) )
1104 # These libs don't have configure flags.
1105 ac_cv_lib_audit_audit_log_user_avc_message=$(usex audit || echo no)
1106 ac_cv_lib_cap_cap_init=$(usex caps || echo no)
1108 # There is no configure option for this and we need to export it
1109 # since the glibc build will re-run configure on itself
1110 export libc_cv_rootsbindir="$(host_eprefix)/sbin"
1111 export libc_cv_slibdir="$(host_eprefix)/$(get_libdir)"
1113 local builddir=$(builddir nptl)
1114 mkdir -p "${builddir}"
1115 cd "${builddir}"
1117 # set some variables not accessible with configure arguments
1118 cat > configparms <<EOF
1119 user-defined-trusted-dirs-pre = $(eprefix_lol)/local/$(get_libdir)/preload $(eprefix_lol)/$(get_libdir)/preload
1120 user-defined-trusted-dirs = $(eprefix_lol)/local/$(get_libdir) $(eprefix_lol)/$(get_libdir)
1123 set -- "${S}"/configure "${myconf[@]}"
1124 echo "$@"
1125 "$@" || die "failed to configure glibc"
1127 # If we're trying to migrate between ABI sets, we need
1128 # to lie and use a local copy of gcc. Like if the system
1129 # is built with MULTILIB_ABIS="amd64 x86" but we want to
1130 # add x32 to it, gcc/glibc don't yet support x32.
1132 if [[ -n ${GCC_BOOTSTRAP_VER} ]] && use multilib-bootstrap ; then
1133 echo 'int main(void){}' > "${T}"/test.c || die
1134 if ! $(tc-getCC ${CTARGET}) ${CFLAGS} ${LDFLAGS} "${T}"/test.c -Wl,-emain -lgcc 2>/dev/null ; then
1135 sed -i -e '/^CC = /s:$: -B$(objdir)/../'"gcc-multilib-bootstrap-${GCC_BOOTSTRAP_VER}/${ABI}:" config.make || die
1140 glibc_headers_configure() {
1141 export ABI=default
1143 local builddir=$(builddir "headers")
1144 mkdir -p "${builddir}"
1145 cd "${builddir}"
1147 # if we don't have a compiler yet, we can't really test it now ...
1148 # hopefully they don't affect header generation, so let's hope for
1149 # the best here ...
1150 local v vars=(
1151 ac_cv_header_cpuid_h=yes
1152 libc_cv_{386,390,alpha,arm,hppa,mips,{powerpc,sparc}{,32,64},sh,x86_64}_tls=yes
1153 libc_cv_asm_cfi_directives=yes
1154 libc_cv_broken_visibility_attribute=no
1155 libc_cv_c_cleanup=yes
1156 libc_cv_compiler_powerpc64le_binary128_ok=yes
1157 libc_cv_forced_unwind=yes
1158 libc_cv_gcc___thread=yes
1159 libc_cv_mlong_double_128=yes
1160 libc_cv_mlong_double_128ibm=yes
1161 libc_cv_ppc_machine=yes
1162 libc_cv_ppc_rel16=yes
1163 libc_cv_predef_fortify_source=no
1164 libc_cv_target_power8_ok=yes
1165 libc_cv_visibility_attribute=yes
1166 libc_cv_z_combreloc=yes
1167 libc_cv_z_execstack=yes
1168 libc_cv_z_initfirst=yes
1169 libc_cv_z_nodelete=yes
1170 libc_cv_z_nodlopen=yes
1171 libc_cv_z_relro=yes
1172 libc_mips_abi=${ABI}
1173 libc_mips_float=$([[ $(tc-is-softfloat) == "yes" ]] && echo soft || echo hard)
1174 # These libs don't have configure flags.
1175 ac_cv_lib_audit_audit_log_user_avc_message=no
1176 ac_cv_lib_cap_cap_init=no
1179 einfo "Forcing cached settings:"
1180 for v in "${vars[@]}" ; do
1181 einfo " ${v}"
1182 export ${v}
1183 done
1185 local headers_only_arch_CPPFLAGS=()
1187 # Blow away some random CC settings that screw things up. #550192
1188 if [[ -d ${S}/sysdeps/mips ]]; then
1189 pushd "${S}"/sysdeps/mips >/dev/null
1190 sed -i -e '/^CC +=/s:=.*:= -D_MIPS_SZPTR=32:' mips32/Makefile mips64/n32/Makefile || die
1191 sed -i -e '/^CC +=/s:=.*:= -D_MIPS_SZPTR=64:' mips64/n64/Makefile || die
1193 # Force the mips ABI to the default. This is OK because the set of
1194 # installed headers in this phase is the same between the 3 ABIs.
1195 # If this ever changes, this hack will break, but that's unlikely
1196 # as glibc discourages that behavior.
1197 # https://crbug.com/647033
1198 sed -i -e 's:abiflag=.*:abiflag=_ABIO32:' preconfigure || die
1200 popd >/dev/null
1203 local myconf=()
1205 case ${CTARGET} in
1206 aarch64*)
1207 # The configure checks fail during cross-build, so disable here
1208 # for headers-only
1209 myconf+=(
1210 --disable-mathvec
1211 ) ;;
1212 riscv*)
1213 # RISC-V interrogates the compiler to determine which target to
1214 # build. If building the headers then we don't strictly need a
1215 # RISC-V compiler, so the built-in definitions that are provided
1216 # along with all RISC-V compiler might not exist. This causes
1217 # glibc's RISC-V preconfigure script to blow up. Since we're just
1218 # building the headers any value will actually work here, so just
1219 # pick the standard one (rv64g/lp64d) to make the build scripts
1220 # happy for now -- the headers are all the same anyway so it
1221 # doesn't matter.
1222 headers_only_arch_CPPFLAGS+=(
1223 -D__riscv_xlen=64
1224 -D__riscv_flen=64
1225 -D__riscv_float_abi_double=1
1226 -D__riscv_atomic=1
1227 ) ;;
1228 esac
1230 myconf+=(
1231 --disable-sanity-checks
1232 --enable-hacker-mode
1233 --disable-werror
1234 --enable-bind-now
1235 --build=${CBUILD_OPT:-${CBUILD}}
1236 --host=${CTARGET_OPT:-${CTARGET}}
1237 --with-headers=$(build_eprefix)$(alt_build_headers)
1238 --prefix="$(host_eprefix)/usr"
1239 ${EXTRA_ECONF}
1242 # Nothing is compiled here which would affect the headers for the target.
1243 # So forcing CC/CFLAGS is sane.
1244 local headers_only_CC=$(tc-getBUILD_CC)
1245 local headers_only_CFLAGS="-O1 -pipe"
1246 local headers_only_CPPFLAGS="-U_FORTIFY_SOURCE ${headers_only_arch_CPPFLAGS[*]}"
1247 local headers_only_LDFLAGS=""
1248 set -- "${S}"/configure "${myconf[@]}"
1249 echo \
1250 "CC=${headers_only_CC}" \
1251 "CFLAGS=${headers_only_CFLAGS}" \
1252 "CPPFLAGS=${headers_only_CPPFLAGS}" \
1253 "LDFLAGS=${headers_only_LDFLAGS}" \
1254 "$@"
1255 CC=${headers_only_CC} \
1256 CFLAGS=${headers_only_CFLAGS} \
1257 CPPFLAGS=${headers_only_CPPFLAGS} \
1258 LDFLAGS="" \
1259 "$@" || die "failed to configure glibc"
1262 do_src_configure() {
1263 if just_headers ; then
1264 glibc_headers_configure
1265 else
1266 glibc_do_configure nptl
1270 src_configure() {
1271 foreach_abi do_src_configure
1274 # src_compile
1276 remap_symvers() {
1277 local file="$1"
1278 local symvers="$2"
1280 args=(
1281 --page-size "$(( 16 * 1024 ))"
1282 --remap-symvers "$symvers"
1283 --also-remap-verneed
1284 "$file"
1287 patchelf-liblol "${args[@]}" || die
1290 lol_build() {
1291 local path="$1"
1292 local maketarget="${PWD}/$path"
1293 local dir="$(dirname -- "$path")"
1294 local lib="$(basename -- "$path")"
1295 local emakeargs
1297 einfo "Building $path"
1298 case "$lib" in
1299 libc.so*)
1300 emakeargs=( "$maketarget" )
1303 emakeargs=(
1304 -C "${S}/$dir"
1305 subdir="$dir"
1306 ..=../
1307 objdir="$PWD"
1308 "$maketarget"
1311 esac
1313 emake "${emakeargs[@]}"
1316 lol_patch() {
1317 local path="$1"
1318 local maketarget="${PWD}/$path"
1319 local lib="$(basename -- "$path")"
1320 local symvers
1321 local sv
1323 local libc_map="GLIBC_2.36=GLIBC_2.27,GLIBC_2.28"
1324 local pthread_map="GLIBC_2.27=GLIBC_2.0,GLIBC_2.2,GLIBC_2.2.1,GLIBC_2.2.2,GLIBC_2.2.3,GLIBC_2.2.4,GLIBC_2.2.6,GLIBC_2.3,GLIBC_2.3.2,GLIBC_2.3.3,GLIBC_2.3.4,GLIBC_2.4,GLIBC_2.5,GLIBC_2.6,GLIBC_2.7,GLIBC_2.8,GLIBC_2.9,GLIBC_2.10,GLIBC_2.11,GLIBC_2.12,GLIBC_2.13,GLIBC_2.14,GLIBC_2.15,GLIBC_2.16,GLIBC_2.17,GLIBC_2.18,GLIBC_2.19,GLIBC_2.20,GLIBC_2.21,GLIBC_2.22,GLIBC_2.23,GLIBC_2.24,GLIBC_2.25,GLIBC_2.26"
1326 case "$lib" in
1327 libc.so*)
1328 symvers=( "$pthread_map" "$libc_map" )
1330 libpthread.so.0)
1331 symvers=( "$pthread_map" )
1333 ld.so.1|libm.so.6|libresolv.so.2|libc_malloc_debug.so.0|libthread_db.so.1|libBrokenLocale.so.1)
1334 symvers=( "$libc_map" )
1336 esac
1338 [[ ${#symvers[@]} -eq 0 ]] && return
1340 einfo "Patching ELF symbol versions of $path"
1341 for sv in "${symvers[@]}"; do
1342 remap_symvers "$maketarget" "$sv"
1343 done
1346 do_src_compile() {
1347 local build_order_phase1=(
1348 libc.so.6
1349 linkobj/libc.so
1350 elf/ld.so.1
1352 local patch_order_phase1=(
1353 elf/ld.so.1
1354 libc.so.6
1355 linkobj/libc.so
1357 local build_order_phase2=(
1358 nptl/libpthread.so.0
1359 "${LOL_LIBS[@]}"
1360 "${LOL_MERGED_LIBS[@]}"
1362 local i
1364 cd "$(builddir nptl)" || die
1366 for i in "${build_order_phase1[@]}"; do
1367 lol_build "$i"
1368 done
1369 for i in "${patch_order_phase1[@]}"; do
1370 lol_patch "$i"
1371 done
1373 for i in "${build_order_phase2[@]}"; do
1374 lol_build "$i"
1375 done
1376 for i in "${build_order_phase2[@]}"; do
1377 lol_patch "$i"
1378 done
1380 ebegin "Generating a dummy ld-linux-loongarch-lp64d.so.1"
1381 $CC -shared \
1382 -x c /dev/null \
1383 -o ld-linux-loongarch-lp64d.so.1 \
1384 -Wl,--version-script -Wl,ld.map \
1385 -nostdlib \
1386 $CFLAGS \
1387 $LDFLAGS
1388 eend $?
1391 src_compile() {
1392 if just_headers ; then
1393 return
1396 foreach_abi do_src_compile
1399 # src_test
1401 glibc_src_test() {
1402 cd "$(builddir nptl)"
1404 die "TODO: check abiversions"
1407 src_test() {
1408 if just_headers ; then
1409 return
1412 foreach_abi glibc_src_test || die "tests failed"
1415 # src_install
1417 # locale_gen is unneeded for liblol
1419 liblol_install() {
1420 local i
1421 local files_to_install=(
1422 libc.so.6
1423 ld-linux-loongarch-lp64d.so.1
1424 elf/ld.so.1
1425 nptl/libpthread.so.0
1426 "${LOL_LIBS[@]}"
1427 "${LOL_MERGED_LIBS[@]}"
1429 local liblol_libdir="$(eprefix_lol)/$(get_libdir)/preload"
1430 local host_libdir
1432 if use split-usr; then
1433 host_libdir="${EPREFIX}/$(get_libdir)"
1434 else
1435 host_libdir="${EPREFIX}/usr/$(get_libdir)"
1438 dodir "$liblol_libdir"
1439 for i in "${files_to_install[@]}"; do
1440 # pwd is builddir
1441 # the targets are all symlinks, so doins cannot be used
1442 cp "$i" "${D}${liblol_libdir}/${i##*/}" || die
1443 done
1445 dosym -r "${liblol_libdir}/ld.so.1" "${host_libdir}/ld.so.1"
1447 keepdir "$(eprefix_lol)/local/$(get_libdir)/preload"
1450 glibc_do_src_install() {
1451 local builddir=$(builddir nptl)
1452 cd "${builddir}"
1454 liblol_install
1456 # Normally upstream_pv is ${PV}. Live ebuilds are exception, there we need
1457 # to infer upstream version:
1458 # '#define VERSION "2.26.90"' -> '2.26.90'
1459 local upstream_pv=$(sed -n -r 's/#define VERSION "(.*)"/\1/p' "${S}"/version.h)
1461 # Avoid stripping binaries not targeted by ${CHOST}. Or else
1462 # ${CHOST}-strip would break binaries build for ${CTARGET}.
1463 is_crosscompile && dostrip -x /
1465 # gdb thread introspection relies on local libpthreads symbols. stripping breaks it
1466 # See Note [Disable automatic stripping]
1467 dostrip -x $(alt_libdir)/libpthread-${upstream_pv}.so
1468 # valgrind requires knowledge about ld.so symbols.
1469 dostrip -x $(alt_libdir)/ld-*.so*
1471 # Everything past this point just needs to be done once ...
1472 is_final_abi || return 0
1474 #################################################################
1475 # EVERYTHING AFTER THIS POINT IS FOR NATIVE GLIBC INSTALLS ONLY #
1476 #################################################################
1478 # Make sure we install some symlink hacks so that when we build
1479 # a 2nd stage cross-compiler, gcc finds the target system
1480 # headers correctly. See gcc/doc/gccinstall.info
1481 if is_crosscompile ; then
1482 # We need to make sure that /lib and /usr/lib always exists.
1483 # gcc likes to use relative paths to get to its multilibs like
1484 # /usr/lib/../lib64/. So while we don't install any files into
1485 # /usr/lib/, we do need it to exist.
1486 keepdir $(alt_prefix)/lib
1487 keepdir $(alt_prefix)/usr/lib
1489 dosym usr/include $(alt_prefix)/sys-include
1490 return 0
1493 cd "${S}" || die
1495 for d in BUGS ChangeLog CONFORMANCE FAQ NEWS NOTES PROJECTS README* ; do
1496 [[ -s ${d} ]] && dodoc ${d}
1497 done
1498 dodoc -r ChangeLog.old
1501 glibc_headers_install() {
1502 local builddir=$(builddir "headers")
1503 cd "${builddir}"
1504 emake install_root="${D}/$(build_eprefix)$(alt_prefix)" install-headers
1506 insinto $(alt_headers)/gnu
1507 doins "${S}"/include/gnu/stubs.h
1509 # Make sure we install the sys-include symlink so that when
1510 # we build a 2nd stage cross-compiler, gcc finds the target
1511 # system headers correctly. See gcc/doc/gccinstall.info
1512 dosym usr/include $(alt_prefix)/sys-include
1515 src_install() {
1516 if just_headers ; then
1517 export ABI=default
1518 glibc_headers_install
1519 return
1522 foreach_abi glibc_do_src_install
1524 if ! use static-libs ; then
1525 einfo "Not installing static glibc libraries"
1526 find "${ED}" -name "*.a" -and -not -name "*_nonshared.a" -delete
1530 refresh_lib_symlinks() {
1531 local liblol_libdir="${EROOT}${LOLPREFIX}/$(get_libdir)/preload"
1532 local gcc_libs=(
1533 libatomic.so.1
1534 libgcc_s.so.1
1535 libgfortran.so.5
1536 libgomp.so.1
1537 libstdc++.so.6
1539 local gcc_lib
1540 local lol_lib
1542 if has_version sys-devel/gcc-config && has_version sys-devel/gcc; then
1543 local gcc_path="$(gcc-config --get-lib-path 2>/dev/null)"
1544 # only keep the first entry
1545 gcc_path="${gcc_path%%:*}"
1547 einfo "Symlinking GCC libs at $gcc_path to libLoL preload libdir"
1548 for i in "${gcc_libs[@]}"; do
1549 gcc_lib="${gcc_path}/$i"
1550 lol_lib="${liblol_libdir}/$i"
1552 if ! [[ -f "$gcc_lib" ]]; then
1553 continue
1556 rm -f "$lol_lib"
1557 ln -s "$gcc_lib" "$lol_lib"
1558 done
1562 pkg_postinst() {
1563 refresh_lib_symlinks
1565 elog "Because libLoL cannot hook into env-update, you need to manually"
1566 elog "refresh symlinks after e.g. GCC version changes, by running:"
1567 elog
1568 elog " emerge --config ${CATEGORY}/${PN}"
1571 pkg_config() {
1572 refresh_lib_symlinks