1 # Copyright 1999-2020 Gentoo Authors
2 # Distributed under the terms of the GNU General Public License v2
6 PYTHON_COMPAT=( python3_{6,7,8} )
8 inherit python-any-r1 prefix eutils toolchain-funcs flag-o-matic gnuconfig \
9 multilib systemd multiprocessing
11 DESCRIPTION="GNU libc C library"
12 HOMEPAGE="https://www.gnu.org/software/libc/"
13 LICENSE="LGPL-2.1+ BSD HPND ISC inner-net rc PCRE"
18 if [[ ${PV} == 9999* ]]; then
19 EGIT_REPO_URI="https://sourceware.org/git/glibc.git"
22 KEYWORDS="~alpha ~amd64 ~arm ~arm64 ~hppa ~ia64 ~m68k ~mips ~ppc ~ppc64 ~riscv ~s390 ~sparc ~x86"
23 SRC_URI="mirror://gnu/glibc/${P}.tar.xz"
28 GCC_BOOTSTRAP_VER=20180511
34 SRC_URI+=" https://dev.gentoo.org/~${PATCH_DEV}/distfiles/${P}-patches-${PATCH_VER}.tar.xz"
35 SRC_URI+=" multilib? ( https://dev.gentoo.org/~dilfridge/distfiles/gcc-multilib-bootstrap-${GCC_BOOTSTRAP_VER}.tar.xz )"
37 IUSE="audit caps cet compile-locales +crypt custom-cflags doc gd headers-only +multiarch multilib nscd profile selinux +ssp +static-libs suid systemtap test vanilla"
39 # Minimum kernel version that glibc requires
42 # Here's how the cross-compile logic breaks down ...
43 # CTARGET - machine that will target the binaries
44 # CHOST - machine that will host the binaries
45 # CBUILD - machine that will build the binaries
46 # If CTARGET != CHOST, it means you want a libc for cross-compiling.
47 # If CHOST != CBUILD, it means you want to cross-compile the libc.
48 # CBUILD = CHOST = CTARGET - native build/install
49 # CBUILD != (CHOST = CTARGET) - cross-compile a native build
50 # (CBUILD = CHOST) != CTARGET - libc for cross-compiler
51 # CBUILD != CHOST != CTARGET - cross-compile a libc for a cross-compiler
53 # CHOST = CTARGET - install into /
54 # CHOST != CTARGET - install into /usr/CTARGET/
56 export CBUILD=${CBUILD:-${CHOST}}
57 export CTARGET=${CTARGET:-${CHOST}}
58 if [[ ${CTARGET} == ${CHOST} ]] ; then
59 if [[ ${CATEGORY} == cross-* ]] ; then
60 export CTARGET=${CATEGORY#cross-}
64 # Note [Disable automatic stripping]
65 # Disabling automatic stripping for a few reasons:
66 # - portage's attempt to strip breaks non-native binaries at least on
68 # - portage's attempt to strip libpthread.so.0 breaks gdb thread
69 # enumeration: bug #697910. This is quite subtle:
70 # * gdb uses glibc's libthread_db-1.0.so to enumerate threads.
71 # * libthread_db-1.0.so needs access to libpthread.so.0 local symbols
72 # via 'ps_pglobal_lookup' symbol defined in gdb.
73 # * 'ps_pglobal_lookup' uses '.symtab' section table to resolve all
74 # known symbols in 'libpthread.so.0'. Specifically 'nptl_version'
75 # (unexported) is used to sanity check compatibility before enabling
77 # 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
78 # * normal 'strip' command trims '.symtab'
79 # Thus our main goal here is to prevent 'libpthread.so.0' from
80 # losing it's '.symtab' entries.
81 # As Gentoo's strip does not allow us to pass less aggressive stripping
82 # options and does not check the machine target we strip selectively.
84 # We need a new-enough binutils/gcc to match upstream baseline.
85 # Also we need to make sure our binutils/gcc supports TLS,
86 # and that gcc already contains the hardened patches.
89 >=app-misc/pax-utils-0.1.10
92 doc? ( sys-apps/texinfo )
95 gd? ( media-libs/gd:2= )
97 audit? ( sys-process/audit )
98 caps? ( sys-libs/libcap )
100 suid? ( caps? ( sys-libs/libcap ) )
101 selinux? ( sys-libs/libselinux )
102 systemtap? ( dev-util/systemtap )
104 DEPEND="${COMMON_DEPEND}
105 test? ( >=net-dns/libidn2-2.3.0 )
107 RDEPEND="${COMMON_DEPEND}
108 sys-apps/gentoo-functions
111 RESTRICT="!test? ( test )"
113 if [[ ${CATEGORY} == cross-* ]] ; then
114 BDEPEND+=" !headers-only? (
115 >=${CATEGORY}/binutils-2.24
118 [[ ${CATEGORY} == *-linux* ]] && DEPEND+=" ${CATEGORY}/linux-headers"
121 >=sys-devel/binutils-2.24
124 DEPEND+=" virtual/os-headers "
126 >=net-dns/libidn2-2.3.0
127 vanilla? ( !sys-libs/timezone-data )
129 PDEPEND+=" !vanilla? ( sys-libs/timezone-data )"
132 # Ignore tests whitelisted below
133 GENTOO_GLIBC_XFAIL_TESTS="${GENTOO_GLIBC_XFAIL_TESTS:-yes}"
135 # The following tests fail due to the Gentoo build system and are thus
136 # executed but ignored:
139 tst-ldconfig-bad-aux-cache
144 tst-nss-files-hosts-long
146 # 2) Namespaces and cgroup
148 # 9) Failures of unknown origin
153 # Small helper functions
157 [[ ${CHOST} != ${CTARGET} ]]
161 is_crosscompile && use headers-only
165 is_crosscompile && echo /usr/${CTARGET}
168 # This prefix is applicable to CHOST when building against this
169 # glibc. It is baked into the library at configure time.
171 is_crosscompile || echo "${EPREFIX}"
174 # This prefix is applicable to CBUILD when building against this
175 # glibc. It determines the destination path at install time.
177 is_crosscompile && echo "${EPREFIX}"
180 # We need to be able to set alternative headers for compiling for non-native
181 # platform. Will also become useful for testing kernel-headers without screwing
182 # up the whole system.
184 echo ${ALT_HEADERS:=$(alt_prefix)/usr/include}
187 alt_build_headers() {
188 if [[ -z ${ALT_BUILD_HEADERS} ]] ; then
189 ALT_BUILD_HEADERS="$(host_eprefix)$(alt_headers)"
190 if tc-is-cross-compiler ; then
191 ALT_BUILD_HEADERS=${SYSROOT}$(alt_headers)
192 if [[ ! -e ${ALT_BUILD_HEADERS}/linux/version.h ]] ; then
193 local header_path=$(echo '#include <linux/version.h>' | $(tc-getCPP ${CTARGET}) ${CFLAGS} 2>&1 | grep -o '[^"]*linux/version.h')
194 ALT_BUILD_HEADERS=${header_path%/linux/version.h}
198 echo "${ALT_BUILD_HEADERS}"
202 echo $(alt_prefix)/$(get_libdir)
205 echo $(alt_prefix)/usr/$(get_libdir)
209 echo "${WORKDIR}/build-${ABI}-${CTARGET}-$1"
213 local ret save_cflags=${CFLAGS}
217 pushd "${T}" >/dev/null
220 printf '%b' "$*" > glibc-test.c
222 nonfatal emake glibc-test
227 CFLAGS=${save_cflags}
234 if [[ ${MERGE_TYPE} == "binary" ]] ; then
235 # ignore build failures when installing a binary package #324685
236 do_compile_test "" "$@" 2>/dev/null || return 0
238 if ! do_compile_test "" "$@" ; then
239 ewarn "Simple build failed ... assuming this is desired #324685"
244 pushd "${T}" >/dev/null
255 setup_target_flags() {
256 # This largely mucks with compiler flags. None of which should matter
257 # when building up just the headers.
258 just_headers && return 0
262 # -march needed for #185404 #199334
263 # TODO: When creating the first glibc cross-compile, this test will
264 # always fail as it does a full link which in turn requires glibc.
265 # Probably also applies when changing multilib profile settings (e.g.
266 # enabling x86 when the profile was amd64-only previously).
267 # We could change main to _start and pass -nostdlib here so that we
268 # only test the gcc code compilation. Or we could do a compile and
269 # then look for the symbol via scanelf.
270 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
271 local t=${CTARGET_OPT:-${CTARGET}}
273 filter-flags '-march=*'
274 export CFLAGS="-march=${t} ${CFLAGS}"
275 einfo "Auto adding -march=${t} to CFLAGS #185404"
279 # -march needed for #185404 #199334
280 # TODO: See cross-compile issues listed above for x86.
281 [[ ${ABI} == x86 ]] &&
282 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
283 local t=${CTARGET_OPT:-${CTARGET}}
285 # Normally the target is x86_64-xxx, so turn that into the -march that
286 # gcc actually accepts. #528708
287 [[ ${t} == "x86_64" ]] && t="x86-64"
288 filter-flags '-march=*'
289 # ugly, ugly, ugly. ugly.
290 CFLAGS_x86=$(CFLAGS=${CFLAGS_x86} filter-flags '-march=*'; echo "${CFLAGS}")
291 export CFLAGS_x86="${CFLAGS_x86} -march=${t}"
292 einfo "Auto adding -march=${t} to CFLAGS_x86 #185404 (ABI=${ABI})"
296 # The mips abi cannot support the GNU style hashes. #233233
297 filter-ldflags -Wl,--hash-style=gnu -Wl,--hash-style=both
300 # Both sparc and sparc64 can use -fcall-used-g6. -g7 is bad, though.
301 filter-flags "-fcall-used-g7"
302 append-flags "-fcall-used-g6"
308 case $(get-flag mcpu) in
310 # We need to force at least v9a because the base build doesn't
312 # https://sourceware.org/bugzilla/show_bug.cgi?id=19477
313 append-flags "-Wa,-xarch=v9a"
318 case $(get-flag mcpu) in
319 v8|supersparc|hypersparc|leon|leon3)
328 [[ -n ${cpu} ]] && CTARGET_OPT="${cpu}-${CTARGET#*-}"
334 # Make sure host make.conf doesn't pollute us
335 if is_crosscompile || tc-is-cross-compiler ; then
336 CHOST=${CTARGET} strip-unsupported-flags
339 # Store our CFLAGS because it's changed depending on which CTARGET
340 # we are building when pulling glibc on a multilib profile
341 CFLAGS_BASE=${CFLAGS_BASE-${CFLAGS}}
342 CFLAGS=${CFLAGS_BASE}
343 CXXFLAGS_BASE=${CXXFLAGS_BASE-${CXXFLAGS}}
344 CXXFLAGS=${CXXFLAGS_BASE}
345 ASFLAGS_BASE=${ASFLAGS_BASE-${ASFLAGS}}
346 ASFLAGS=${ASFLAGS_BASE}
348 # Allow users to explicitly avoid flag sanitization via
350 if ! use custom-cflags; then
351 # Over-zealous CFLAGS can often cause problems. What may work for one
352 # person may not work for another. To avoid a large influx of bugs
353 # relating to failed builds, we strip most CFLAGS out to ensure as few
354 # problems as possible.
356 # Lock glibc at -O2; we want to be conservative here.
360 strip-unsupported-flags
361 filter-flags -m32 -m64 '-mabi=*'
363 # glibc aborts if rpath is set by LDFLAGS
364 filter-ldflags '-Wl,-rpath=*'
367 filter-flags -frecord-gcc-switches
369 unset CBUILD_OPT CTARGET_OPT
370 if use multilib ; then
371 CTARGET_OPT=$(get_abi_CTARGET)
372 [[ -z ${CTARGET_OPT} ]] && CTARGET_OPT=$(get_abi_CHOST)
377 if [[ -n ${CTARGET_OPT} && ${CBUILD} == ${CHOST} ]] && ! is_crosscompile; then
378 CBUILD_OPT=${CTARGET_OPT}
381 # glibc's headers disallow -O0 and fail at build time:
382 # include/libc-symbols.h:75:3: #error "glibc cannot be compiled without optimization"
383 replace-flags -O0 -O1
385 filter-flags '-fstack-protector*'
389 # Archs that can use TLS (Thread Local Storage)
392 # requires i486 or better #106556
393 [[ ${CTARGET} == i[4567]86* ]] && return 0
403 # For some reason --with-tls --with__thread is causing segfaults on sparc32.
404 [[ ${PROFILE_ARCH} == "sparc" ]] && return 1
406 [[ -n ${WANT__THREAD} ]] && return ${WANT__THREAD}
408 # only test gcc -- can't test linking yet
409 tc-has-tls -c ${CTARGET}
412 return ${WANT__THREAD}
416 # Allow user to disable runtime arch detection in multilib.
417 use multiarch || return 1
418 # Make sure binutils is new enough to support indirect functions,
419 # #336792. This funky sed supports gold and bfd linkers.
421 bver=$($(tc-getLD ${CTARGET}) -v | sed -n -r '1{s:[^0-9]*::;s:^([0-9.]*).*:\1:;p}')
422 case $(tc-arch ${CTARGET}) in
423 amd64|x86) nver="2.20" ;;
426 ppc|ppc64) nver="2.20" ;;
427 # ifunc support was added in 2.23, but glibc also needs
428 # machinemode which is in 2.24.
430 sparc) nver="2.21" ;;
433 ver_test ${bver} -ge ${nver}
436 # Setup toolchain variables that had historically been defined in the
437 # profiles for these archs.
441 unset LD_ASSUME_KERNEL
443 if is_crosscompile || tc-is-cross-compiler ; then
444 multilib_env ${CTARGET_OPT:-${CTARGET}}
446 if ! use multilib ; then
447 MULTILIB_ABIS=${DEFAULT_ABI}
449 MULTILIB_ABIS=${MULTILIB_ABIS:-${DEFAULT_ABI}}
452 # If the user has CFLAGS_<CTARGET> in their make.conf, use that,
453 # and fall back on CFLAGS.
454 local VAR=CFLAGS_${CTARGET//[-.]/_}
455 CFLAGS=${!VAR-${CFLAGS}}
456 einfo " $(printf '%15s' 'Manual CFLAGS:') ${CFLAGS}"
461 export ABI=${ABI:-${DEFAULT_ABI:-default}}
463 if just_headers ; then
464 # Avoid mixing host's CC and target's CFLAGS_${ABI}:
465 # At this bootstrap stage we have only binutils for
466 # target but not compiler yet.
467 einfo "Skip CC ABI injection. We can't use (cross-)compiler yet."
470 local VAR=CFLAGS_${ABI}
471 # We need to export CFLAGS with abi information in them because glibc's
472 # configure script checks CFLAGS for some targets (like mips). Keep
473 # around the original clean value to avoid appending multiple ABIs on
475 : ${__GLIBC_CC:=$(tc-getCC ${CTARGET_OPT:-${CTARGET}})}
476 export __GLIBC_CC CC="${__GLIBC_CC} ${!VAR}"
477 einfo " $(printf '%15s' 'Manual CC:') ${CC}"
485 if use multilib ; then
486 abilist=$(get_install_abis)
488 abilist=${DEFAULT_ABI}
491 for ABI in ${abilist:-default} ; do
493 einfo "Running $1 for ABI ${ABI}"
501 local b="Gentoo ${PVR}"
502 [[ -n ${PATCH_VER} ]] && ! use vanilla && b+=" p${PATCH_VER}"
507 # Make sure devpts is mounted correctly for use w/out setuid pt_chown.
509 # If merely building the binary package, then there's nothing to verify.
510 [[ ${MERGE_TYPE} == "buildonly" ]] && return
512 # Only sanity check when installing the native glibc.
513 [[ -n ${ROOT} ]] && return
515 # If they're opting in to the old suid code, then no need to check.
518 if awk '$3 == "devpts" && $4 ~ /[, ]gid=5[, ]/ { exit 1 }' /proc/mounts ; then
519 eerror "In order to use glibc with USE=-suid, you must make sure that"
520 eerror "you have devpts mounted at /dev/pts with the gid=5 option."
521 eerror "Openrc should do this for you, so you should check /etc/fstab"
522 eerror "and make sure you do not have any invalid settings there."
523 die "mount & fix your /dev/pts settings"
527 # The following Kernel version handling functions are mostly copied from portage
528 # source. It's better not to use linux-info.eclass here since a) it adds too
529 # much magic, see bug 326693 for some of the arguments, and b) some of the
530 # functions are just not provided.
538 [[ -z $1 ]] && return 1
544 [[ -z $1 ]] && return 1
551 [[ -z $1 ]] && return 1
554 echo "${KV%%[^[:digit:]]*}"
558 [[ -z $1 ]] && return 1
559 local KV_MAJOR=$(g_KV_major "$1")
560 local KV_MINOR=$(g_KV_minor "$1")
561 local KV_MICRO=$(g_KV_micro "$1")
562 local KV_int=$(( KV_MAJOR * 65536 + KV_MINOR * 256 + KV_MICRO ))
564 # We make version 2.2.0 the minimum version we will handle as
565 # a sanity check ... if its less, we fail ...
566 if [[ ${KV_int} -ge 131584 ]] ; then
574 local version=$1 major minor micro
575 major=$((version / 65536))
576 minor=$(((version % 65536) / 256))
577 micro=$((version % 256))
578 echo ${major}.${minor}.${micro}
582 [[ $(g_KV_to_int $1) -ge $(g_KV_to_int $2) ]]
586 get_kheader_version() {
587 printf '#include <linux/version.h>\nLINUX_VERSION_CODE\n' | \
588 $(tc-getCPP ${CTARGET}) -I "$(build_eprefix)$(alt_build_headers)" - | \
592 # We collect all sanity checks here. Consistency is not guranteed between
593 # pkg_ and src_ phases, so we call this function both in pkg_pretend and in
596 # Make sure devpts is mounted correctly for use w/out setuid pt_chown
599 # Prevent native builds from downgrading
600 if [[ ${MERGE_TYPE} != "buildonly" ]] && \
601 [[ -z ${ROOT} ]] && \
602 [[ ${CBUILD} == ${CHOST} ]] && \
603 [[ ${CHOST} == ${CTARGET} ]] ; then
605 # The high rev # is to allow people to downgrade between -r#
606 # versions. We want to block 2.20->2.19, but 2.20-r3->2.20-r2
607 # should be fine. Hopefully we never actually use a r# this
609 if has_version ">${CATEGORY}/${P}-r10000" ; then
610 eerror "Sanity check to keep you from breaking your system:"
611 eerror " Downgrading glibc is not supported and a sure way to destruction."
612 [[ ${I_ALLOW_TO_BREAK_MY_SYSTEM} = yes ]] || die "Aborting to save your system."
615 if ! do_run_test '#include <unistd.h>\n#include <sys/syscall.h>\nint main(){return syscall(1000)!=-1;}\n' ; then
616 eerror "Your old kernel is broken. You need to update it to a newer"
617 eerror "version as syscall(<bignum>) will break. See bug 279260."
618 die "Old and broken kernel."
622 # Users have had a chance to phase themselves, time to give em the boot
623 if [[ -e ${EROOT}/etc/locale.gen ]] && [[ -e ${EROOT}/etc/locales.build ]] ; then
624 eerror "You still haven't deleted ${EROOT}/etc/locales.build."
625 eerror "Do so now after making sure ${EROOT}/etc/locale.gen is kosher."
626 die "Lazy upgrader detected"
629 if [[ ${CTARGET} == i386-* ]] ; then
630 eerror "i386 CHOSTs are no longer supported."
631 eerror "Chances are you don't actually want/need i386."
632 eerror "Please read https://www.gentoo.org/doc/en/change-chost.xml"
633 die "Please fix your CHOST"
636 if [[ -e /proc/xen ]] && [[ $(tc-arch) == "x86" ]] && ! is-flag -mno-tls-direct-seg-refs ; then
637 ewarn "You are using Xen but don't have -mno-tls-direct-seg-refs in your CFLAGS."
638 ewarn "This will result in a 50% performance penalty when running with a 32bit"
639 ewarn "hypervisor, which is probably not what you want."
642 # Check for sanity of /etc/nsswitch.conf
643 if [[ -e ${EROOT}/etc/nsswitch.conf ]] ; then
645 for entry in passwd group shadow; do
646 if ! egrep -q "^[ \t]*${entry}:.*files" "${EROOT}"/etc/nsswitch.conf; then
647 eerror "Your ${EROOT}/etc/nsswitch.conf is out of date."
648 eerror "Please make sure you have 'files' entries for"
649 eerror "'passwd:', 'group:' and 'shadow:' databases."
650 eerror "For more details see:"
651 eerror " https://wiki.gentoo.org/wiki/Project:Toolchain/nsswitch.conf_in_glibc-2.26"
652 die "nsswitch.conf has no 'files' provider in '${entry}'."
657 # ABI-specific checks follow here. Hey, we have a lot more specific conditions that
659 if ! is_crosscompile ; then
660 if use amd64 && use multilib && [[ ${MERGE_TYPE} != "binary" ]] ; then
661 ebegin "Checking that IA32 emulation is enabled in the running kernel"
662 echo 'int main(){return 0;}' > "${T}/check-ia32-emulation.c"
664 if "${CC-${CHOST}-gcc}" ${CFLAGS_x86} "${T}/check-ia32-emulation.c" -o "${T}/check-ia32-emulation.elf32"; then
665 "${T}/check-ia32-emulation.elf32"
668 # Don't fail here to allow single->multi ABI switch
669 # or recover from breakage like bug #646424
670 ewarn "Failed to compile the ABI test. Broken host glibc?"
673 rm -f "${T}/check-ia32-emulation.elf32"
675 [[ $STAT -eq 0 ]] || die "CONFIG_IA32_EMULATION must be enabled in the kernel to compile a multilib glibc."
680 # When we actually have to compile something...
681 if ! just_headers ; then
682 ebegin "Checking gcc for __thread support"
683 if ! eend $(want__thread ; echo $?) ; then
685 eerror "Could not find a gcc that supports the __thread directive!"
686 eerror "Please update your binutils/gcc and try again."
687 die "No __thread support in gcc!"
690 if [[ ${CTARGET} == *-linux* ]] ; then
691 local run_kv build_kv want_kv
693 run_kv=$(g_get_running_KV)
694 build_kv=$(g_int_to_KV $(get_kheader_version))
695 want_kv=${MIN_KERN_VER}
697 if ! is_crosscompile && ! tc-is-cross-compiler ; then
698 # Building fails on an non-supporting kernel
699 ebegin "Checking running kernel version (${run_kv} >= ${want_kv})"
700 if ! eend_KV ${run_kv} ${want_kv} ; then
702 eerror "You need a kernel of at least ${want_kv}!"
703 die "Kernel version too low!"
707 ebegin "Checking linux-headers version (${build_kv} >= ${want_kv})"
708 if ! eend_KV ${build_kv} ${want_kv} ; then
710 eerror "You need linux-headers of at least ${want_kv}!"
711 die "linux-headers version too low!"
725 einfo "Checking general environment sanity."
731 [[ -z ${BOOTSTRAP_RAP} ]] && python-any-r1_pkg_setup
737 # Consistency is not guaranteed between pkg_ and src_ ...
740 use multilib && unpack gcc-multilib-bootstrap-${GCC_BOOTSTRAP_VER}.tar.xz
744 if [[ -n ${EGIT_REPO_URI} ]] ; then
750 cd "${WORKDIR}" || die
751 unpack glibc-${RELEASE_VER}-patches-${PATCH_VER}.tar.xz
755 if ! use vanilla ; then
756 elog "Applying Gentoo Glibc Patchset ${RELEASE_VER}-${PATCH_VER}"
757 eapply "${WORKDIR}"/patches
766 find . -name configure -exec touch {} +
768 eprefixify extra/locale/locale-gen
770 # Fix permissions on some of the scripts.
771 chmod u+x "${S}"/scripts/*.sh
776 glibc_do_configure() {
777 # Glibc does not work with gold (for various reasons) #269274.
780 # CXX isnt handled by the multilib system, so if we dont unset here
781 # we accumulate crap across abis
784 einfo "Configuring glibc for nptl"
787 export MAKEINFO=makeinfo
789 export MAKEINFO=/dev/null
793 for v in ABI CBUILD CHOST CTARGET CBUILD_OPT CTARGET_OPT CC CXX LD {AS,C,CPP,CXX,LD}FLAGS MAKEINFO ; do
794 einfo " $(printf '%15s' ${v}:) ${!v}"
797 # CFLAGS can contain ABI-specific flags like -mfpu=neon, see bug #657760
798 # To build .S (assembly) files with the same ABI-specific flags
799 # upstream currently recommends adding CFLAGS to CC/CXX:
800 # https://sourceware.org/PR23273
801 # Note: Passing CFLAGS via CPPFLAGS overrides glibc's arch-specific CFLAGS
802 # and breaks multiarch support. See 659030#c3 for an example.
803 # The glibc configure script doesn't properly use LDFLAGS all the time.
804 export CC="$(tc-getCC ${CTARGET}) ${CFLAGS} ${LDFLAGS}"
805 einfo " $(printf '%15s' 'Manual CC:') ${CC}"
807 # Some of the tests are written in C++, so we need to force our multlib abis in, bug 623548
808 export CXX="$(tc-getCXX ${CTARGET}) $(get_abi_CFLAGS) ${CFLAGS}"
810 if is_crosscompile; then
811 # Assume worst-case bootstrap: glibc is buil first time
812 # when ${CTARGET}-g++ is not available yet. We avoid
813 # building auxiliary programs that require C++: bug #683074
814 # It should not affect final result.
815 export libc_cv_cxx_link_ok=no
816 # The line above has the same effect. We set CXX explicitly
817 # to make build logs less confusing.
820 einfo " $(printf '%15s' 'Manual CXX:') ${CXX}"
828 # setjmp() is not compatible with stack protection:
829 # https://sourceware.org/PR24202
830 myconf+=( --enable-stack-protector=no )
833 # Currently gcc on powerpc32 generates invalid code for
834 # __builtin_return_address(0) calls. Normally programs
835 # don't do that but malloc hooks in glibc do:
836 # https://gcc.gnu.org/PR81996
837 # https://bugs.gentoo.org/629054
838 myconf+=( --enable-stack-protector=no )
841 # Use '=strong' instead of '=all' to protect only functions
842 # worth protecting from stack smashes.
843 # '=all' is also known to have a problem in IFUNC resolution
844 # tests: https://sourceware.org/PR25680, bug #712356.
845 myconf+=( --enable-stack-protector=$(usex ssp strong no) )
848 myconf+=( --enable-stackguard-randomization )
850 # Keep a whitelist of targets supporing IFUNC. glibc's ./configure
851 # is not robust enough to detect proper support:
852 # https://bugs.gentoo.org/641216
853 # https://sourceware.org/PR22634#c0
854 case $(tc-arch ${CTARGET}) in
855 # Keep whitelist of targets where autodetection mostly works.
856 amd64|x86|sparc|ppc|ppc64|arm|arm64|s390) ;;
857 # Blacklist everywhere else
858 *) myconf+=( libc_cv_ld_gnu_indirect_function=no ) ;;
861 # Enable Intel Control-flow Enforcement Technology on amd64 if requested
863 x86_64-*) myconf+=( $(use_enable cet) ) ;;
867 [[ $(tc-is-softfloat) == "yes" ]] && myconf+=( --without-fp )
869 myconf+=( --enable-kernel=${MIN_KERN_VER} )
871 # Since SELinux support is only required for nscd, only enable it if:
873 # 2. only for the primary ABI on multilib systems
874 # 3. Not a crosscompile
875 if ! is_crosscompile && use selinux ; then
876 if use multilib ; then
877 if is_final_abi ; then
878 myconf+=( --with-selinux )
880 myconf+=( --without-selinux )
883 myconf+=( --with-selinux )
886 myconf+=( --without-selinux )
889 # Force a few tests where we always know the answer but
890 # configure is incapable of finding it.
891 if is_crosscompile ; then
893 libc_cv_c_cleanup=yes \
894 libc_cv_forced_unwind=yes
901 --build=${CBUILD_OPT:-${CBUILD}}
902 --host=${CTARGET_OPT:-${CTARGET}}
903 $(use_enable profile)
905 --with-headers=$(build_eprefix)$(alt_build_headers)
906 --prefix="$(host_eprefix)/usr"
907 --sysconfdir="$(host_eprefix)/etc"
908 --localstatedir="$(host_eprefix)/var"
909 --libdir='$(prefix)'/$(get_libdir)
910 --mandir='$(prefix)'/share/man
911 --infodir='$(prefix)'/share/info
912 --libexecdir='$(libdir)'/misc/glibc
913 --with-bugurl=https://bugs.gentoo.org/
914 --with-pkgversion="$(glibc_banner)"
916 $(use_multiarch || echo --disable-multi-arch)
917 $(use_enable systemtap)
922 # We rely on sys-libs/timezone-data for timezone tools normally.
923 myconf+=( $(use_enable vanilla timezone-tools) )
925 # These libs don't have configure flags.
926 ac_cv_lib_audit_audit_log_user_avc_message=$(usex audit || echo no)
927 ac_cv_lib_cap_cap_init=$(usex caps || echo no)
929 # There is no configure option for this and we need to export it
930 # since the glibc build will re-run configure on itself
931 export libc_cv_rootsbindir="$(host_eprefix)/sbin"
932 export libc_cv_slibdir="$(host_eprefix)/$(get_libdir)"
934 # We take care of patching our binutils to use both hash styles,
935 # and many people like to force gnu hash style only, so disable
936 # this overriding check. #347761
937 export libc_cv_hashstyle=no
939 local builddir=$(builddir nptl)
940 mkdir -p "${builddir}"
942 set -- "${S}"/configure "${myconf[@]}"
944 "$@" || die "failed to configure glibc"
946 # ia64 static cross-compilers are a pita in so much that they
947 # can't produce static ELFs (as the libgcc.a is broken). so
948 # disable building of the programs for those targets if it
950 # XXX: We could turn this into a compiler test, but ia64 is
951 # the only one that matters, so this should be fine for now.
952 if is_crosscompile && [[ ${CTARGET} == ia64* ]] ; then
953 sed -i '1i+link-static = touch $@' config.make
956 # If we're trying to migrate between ABI sets, we need
957 # to lie and use a local copy of gcc. Like if the system
958 # is built with MULTILIB_ABIS="amd64 x86" but we want to
959 # add x32 to it, gcc/glibc don't yet support x32.
961 if [[ -n ${GCC_BOOTSTRAP_VER} ]] && use multilib ; then
962 echo 'main(){}' > "${T}"/test.c
963 if ! $(tc-getCC ${CTARGET}) ${CFLAGS} ${LDFLAGS} "${T}"/test.c -Wl,-emain -lgcc 2>/dev/null ; then
964 sed -i -e '/^CC = /s:$: -B$(objdir)/../'"gcc-multilib-bootstrap-${GCC_BOOTSTRAP_VER}/${ABI}:" config.make || die
969 glibc_headers_configure() {
972 local builddir=$(builddir "headers")
973 mkdir -p "${builddir}"
976 # if we don't have a compiler yet, we can't really test it now ...
977 # hopefully they don't affect header generation, so let's hope for
980 ac_cv_header_cpuid_h=yes
981 libc_cv_{386,390,alpha,arm,hppa,ia64,mips,{powerpc,sparc}{,32,64},sh,x86_64}_tls=yes
982 libc_cv_asm_cfi_directives=yes
983 libc_cv_broken_visibility_attribute=no
984 libc_cv_c_cleanup=yes
985 libc_cv_compiler_powerpc64le_binary128_ok=yes
986 libc_cv_forced_unwind=yes
987 libc_cv_gcc___thread=yes
988 libc_cv_mlong_double_128=yes
989 libc_cv_mlong_double_128ibm=yes
990 libc_cv_ppc_machine=yes
991 libc_cv_ppc_rel16=yes
992 libc_cv_predef_fortify_source=no
993 libc_cv_target_power8_ok=yes
994 libc_cv_visibility_attribute=yes
995 libc_cv_z_combreloc=yes
996 libc_cv_z_execstack=yes
997 libc_cv_z_initfirst=yes
998 libc_cv_z_nodelete=yes
999 libc_cv_z_nodlopen=yes
1001 libc_mips_abi=${ABI}
1002 libc_mips_float=$([[ $(tc-is-softfloat) == "yes" ]] && echo soft || echo hard)
1003 # These libs don't have configure flags.
1004 ac_cv_lib_audit_audit_log_user_avc_message=no
1005 ac_cv_lib_cap_cap_init=no
1008 einfo "Forcing cached settings:"
1009 for v in "${vars[@]}" ; do
1014 local headers_only_arch_CPPFLAGS=()
1016 # Blow away some random CC settings that screw things up. #550192
1017 if [[ -d ${S}/sysdeps/mips ]]; then
1018 pushd "${S}"/sysdeps/mips >/dev/null
1019 sed -i -e '/^CC +=/s:=.*:= -D_MIPS_SZPTR=32:' mips32/Makefile mips64/n32/Makefile || die
1020 sed -i -e '/^CC +=/s:=.*:= -D_MIPS_SZPTR=64:' mips64/n64/Makefile || die
1022 # Force the mips ABI to the default. This is OK because the set of
1023 # installed headers in this phase is the same between the 3 ABIs.
1024 # If this ever changes, this hack will break, but that's unlikely
1025 # as glibc discourages that behavior.
1026 # https://crbug.com/647033
1027 sed -i -e 's:abiflag=.*:abiflag=_ABIO32:' preconfigure || die
1034 # RISC-V interrogates the compiler to determine which target to
1035 # build. If building the headers then we don't strictly need a
1036 # RISC-V compiler, so the built-in definitions that are provided
1037 # along with all RISC-V compiler might not exist. This causes
1038 # glibc's RISC-V preconfigure script to blow up. Since we're just
1039 # building the headers any value will actually work here, so just
1040 # pick the standard one (rv64g/lp64d) to make the build scripts
1041 # happy for now -- the headers are all the same anyway so it
1043 headers_only_arch_CPPFLAGS+=(
1046 -D__riscv_float_abi_double=1
1053 --disable-sanity-checks
1054 --enable-hacker-mode
1058 --build=${CBUILD_OPT:-${CBUILD}}
1059 --host=${CTARGET_OPT:-${CTARGET}}
1060 --with-headers=$(build_eprefix)$(alt_build_headers)
1061 --prefix="$(host_eprefix)/usr"
1065 # Nothing is compiled here which would affect the headers for the target.
1066 # So forcing CC/CFLAGS is sane.
1067 local headers_only_CC=$(tc-getBUILD_CC)
1068 local headers_only_CFLAGS="-O1 -pipe"
1069 local headers_only_CPPFLAGS="-U_FORTIFY_SOURCE ${headers_only_arch_CPPFLAGS[*]}"
1070 local headers_only_LDFLAGS=""
1071 set -- "${S}"/configure "${myconf[@]}"
1073 "CC=${headers_only_CC}" \
1074 "CFLAGS=${headers_only_CFLAGS}" \
1075 "CPPFLAGS=${headers_only_CPPFLAGS}" \
1076 "LDFLAGS=${headers_only_LDFLAGS}" \
1078 CC=${headers_only_CC} \
1079 CFLAGS=${headers_only_CFLAGS} \
1080 CPPFLAGS=${headers_only_CPPFLAGS} \
1082 "$@" || die "failed to configure glibc"
1085 do_src_configure() {
1086 if just_headers ; then
1087 glibc_headers_configure
1089 glibc_do_configure nptl
1094 foreach_abi do_src_configure
1098 emake -C "$(builddir nptl)"
1102 if just_headers ; then
1106 foreach_abi do_src_compile
1110 cd "$(builddir nptl)"
1112 local myxfailparams=""
1113 if [[ "${GENTOO_GLIBC_XFAIL_TESTS}" == "yes" ]] ; then
1114 for myt in ${XFAIL_TEST_LIST[@]} ; do
1115 myxfailparams+="test-xfail-${myt}=yes "
1119 emake ${myxfailparams} check
1132 if just_headers ; then
1136 # Give tests more time to complete.
1137 export TIMEOUTFACTOR=5
1139 foreach_abi do_src_test || die "tests failed"
1143 # if the host locales.gen contains no entries, we'll install everything
1147 if [[ "${root}" == "--inplace-glibc" ]] ; then
1148 inplace="--inplace-glibc"
1152 local locale_list="${root}/etc/locale.gen"
1154 pushd "${ED}"/$(get_libdir) >/dev/null
1156 if [[ -z $(locale-gen --list --config "${locale_list}") ]] ; then
1157 [[ -z ${inplace} ]] && ewarn "Generating all locales; edit /etc/locale.gen to save time/space"
1158 locale_list="${root}/usr/share/i18n/SUPPORTED"
1161 locale-gen ${inplace} --jobs $(makeopts_jobs) --config "${locale_list}" \
1167 glibc_do_src_install() {
1168 local builddir=$(builddir nptl)
1171 emake install_root="${D}/$(build_eprefix)$(alt_prefix)" install
1173 # This version (2.26) provides some compatibility libraries for the NIS/NIS+ support
1174 # which come without headers etc. Only needed for binary packages since the
1175 # external net-libs/libnsl has increased soversion. Keep only versioned libraries.
1176 find "${D}" -name "libnsl.a" -delete
1177 find "${D}" -name "libnsl.so" -delete
1179 # Normally upstream_pv is ${PV}. Live ebuilds are exception, there we need
1180 # to infer upstream version:
1181 # '#define VERSION "2.26.90"' -> '2.26.90'
1182 local upstream_pv=$(sed -n -r 's/#define VERSION "(.*)"/\1/p' "${S}"/version.h)
1184 # Avoid stripping binaries not targeted by ${CHOST}. Or else
1185 # ${CHOST}-strip would break binaries build for ${CTARGET}.
1186 is_crosscompile && dostrip -x /
1187 # gdb thread introspection relies on local libpthreas symbols. stripping breaks it
1188 # See Note [Disable automatic stripping]
1189 dostrip -x $(alt_libdir)/libpthread-${upstream_pv}.so
1191 if [[ -e ${ED}/$(alt_usrlibdir)/libm-${upstream_pv}.a ]] ; then
1192 # Move versioned .a file out of libdir to evade portage QA checks
1193 # instead of using gen_usr_ldscript(). We fix ldscript as:
1194 # "GROUP ( /usr/lib64/libm-<pv>.a ..." -> "GROUP ( /usr/lib64/glibc-<pv>/libm-<pv>.a ..."
1195 sed -i "s@\(libm-${upstream_pv}.a\)@${P}/\1@" "${ED}"/$(alt_usrlibdir)/libm.a || die
1196 dodir $(alt_usrlibdir)/${P}
1197 mv "${ED}"/$(alt_usrlibdir)/libm-${upstream_pv}.a "${ED}"/$(alt_usrlibdir)/${P}/libm-${upstream_pv}.a || die
1200 # We'll take care of the cache ourselves
1201 rm -f "${ED}"/etc/ld.so.cache
1203 # Everything past this point just needs to be done once ...
1204 is_final_abi || return 0
1206 # Make sure the non-native interp can be found on multilib systems even
1207 # if the main library set isn't installed into the right place. Maybe
1208 # we should query the active gcc for info instead of hardcoding it ?
1209 local i ldso_abi ldso_name
1210 local ldso_abi_list=(
1212 amd64 /lib64/ld-linux-x86-64.so.2
1213 x32 /libx32/ld-linux-x32.so.2
1214 x86 /lib/ld-linux.so.2
1221 ppc64 /lib64/ld64.so.1
1223 lp64d /lib/ld-linux-riscv64-lp64d.so.1
1224 lp64 /lib/ld-linux-riscv64-lp64.so.1
1227 s390x /lib/ld64.so.1
1229 sparc32 /lib/ld-linux.so.2
1230 sparc64 /lib64/ld-linux.so.2
1232 case $(tc-endian) in
1236 arm64 /lib/ld-linux-aarch64.so.1
1242 arm64 /lib/ld-linux-aarch64_be.so.1
1246 if [[ ${SYMLINK_LIB} == "yes" ]] && [[ ! -e ${ED}/$(alt_prefix)/lib ]] ; then
1247 dosym $(get_abi_LIBDIR ${DEFAULT_ABI}) $(alt_prefix)/lib
1249 for (( i = 0; i < ${#ldso_abi_list[@]}; i += 2 )) ; do
1250 ldso_abi=${ldso_abi_list[i]}
1251 has ${ldso_abi} $(get_install_abis) || continue
1253 ldso_name="$(alt_prefix)${ldso_abi_list[i+1]}"
1254 if [[ ! -L ${ED}/${ldso_name} && ! -e ${ED}/${ldso_name} ]] ; then
1255 dosym ../$(get_abi_LIBDIR ${ldso_abi})/${ldso_name##*/} ${ldso_name}
1259 # With devpts under Linux mounted properly, we do not need the pt_chown
1260 # binary to be setuid. This is because the default owners/perms will be
1261 # exactly what we want.
1262 if ! use suid ; then
1263 find "${ED}" -name pt_chown -exec chmod -s {} +
1266 #################################################################
1267 # EVERYTHING AFTER THIS POINT IS FOR NATIVE GLIBC INSTALLS ONLY #
1268 # Make sure we install some symlink hacks so that when we build
1269 # a 2nd stage cross-compiler, gcc finds the target system
1270 # headers correctly. See gcc/doc/gccinstall.info
1271 if is_crosscompile ; then
1272 # We need to make sure that /lib and /usr/lib always exists.
1273 # gcc likes to use relative paths to get to its multilibs like
1274 # /usr/lib/../lib64/. So while we don't install any files into
1275 # /usr/lib/, we do need it to exist.
1276 keepdir $(alt_prefix)/lib
1277 keepdir $(alt_prefix)/usr/lib
1279 dosym usr/include $(alt_prefix)/sys-include
1283 # Files for Debian-style locale updating
1284 dodir /usr/share/i18n
1287 -e "/SUPPORTED-LOCALES=/d" \
1288 -e "s: \\\\::g" -e "s:/: :g" \
1289 "${S}"/localedata/SUPPORTED > "${ED}"/usr/share/i18n/SUPPORTED \
1290 || die "generating /usr/share/i18n/SUPPORTED failed"
1291 cd "${WORKDIR}"/extra/locale
1297 # Make sure all the ABI's can find the locales and so we only
1298 # have to generate one set
1300 keepdir /usr/$(get_libdir)/locale
1301 for a in $(get_install_abis) ; do
1302 if [[ ! -e ${ED}/usr/$(get_abi_LIBDIR ${a})/locale ]] ; then
1303 dosym ../$(get_libdir)/locale /usr/$(get_abi_LIBDIR ${a})/locale
1307 # HACK: If we're building for riscv, we need to additionally make sure that
1308 # we can find the locale archive afterwards
1311 if [[ ! -e ${ED}/usr/lib/locale ]] ; then
1312 dosym ../$(get_libdir)/locale /usr/lib/locale
1320 # Install misc network config files
1322 doins nscd/nscd.conf posix/gai.conf nss/nsswitch.conf
1323 doins "${WORKDIR}"/extra/etc/*.conf
1326 doinitd "$(prefixify_ro "${WORKDIR}"/extra/etc/nscd)"
1329 -e "s:@PIDFILE@:$(strings "${ED}"/usr/sbin/nscd | grep nscd.pid):"
1332 sed -i "${nscd_args[@]}" "${ED}"/etc/init.d/nscd
1334 systemd_dounit nscd/nscd.service
1335 systemd_newtmpfilesd nscd/nscd.tmpfiles nscd.conf
1337 # Do this since extra/etc/*.conf above might have nscd.conf.
1338 rm -f "${ED}"/etc/nscd.conf
1341 echo 'LDPATH="include ld.so.conf.d/*.conf"' > "${T}"/00glibc
1342 doenvd "${T}"/00glibc
1344 for d in BUGS ChangeLog CONFORMANCE FAQ NEWS NOTES PROJECTS README* ; do
1345 [[ -s ${d} ]] && dodoc ${d}
1347 dodoc -r ChangeLog.old
1349 # Prevent overwriting of the /etc/localtime symlink. We'll handle the
1350 # creation of the "factory" symlink in pkg_postinst().
1351 rm -f "${ED}"/etc/localtime
1353 # Generate all locales if this is a native build as locale generation
1354 if use compile-locales && ! is_crosscompile ; then
1355 run_locale_gen --inplace-glibc "${ED}/"
1356 sed -e 's:COMPILED_LOCALES="":COMPILED_LOCALES="1":' -i "${ED}"/usr/sbin/locale-gen || die
1360 glibc_headers_install() {
1361 local builddir=$(builddir "headers")
1363 emake install_root="${D}/$(build_eprefix)$(alt_prefix)" install-headers
1365 insinto $(alt_headers)/gnu
1366 doins "${S}"/include/gnu/stubs.h
1368 # Make sure we install the sys-include symlink so that when
1369 # we build a 2nd stage cross-compiler, gcc finds the target
1370 # system headers correctly. See gcc/doc/gccinstall.info
1371 dosym usr/include $(alt_prefix)/sys-include
1375 if just_headers ; then
1377 glibc_headers_install
1381 foreach_abi glibc_do_src_install
1383 if ! use static-libs ; then
1384 elog "Not installing static glibc libraries"
1385 find "${ED}" -name "*.a" -and -not -name "*_nonshared.a" -delete
1389 # Simple test to make sure our new glibc isn't completely broken.
1390 # Make sure we don't test with statically built binaries since
1391 # they will fail. Also, skip if this glibc is a cross compiler.
1393 # If coreutils is built with USE=multicall, some of these files
1394 # will just be wrapper scripts, not actual ELFs we can test.
1395 glibc_sanity_check() {
1398 # We enter ${ED} so to avoid trouble if the path contains
1399 # special characters; for instance if the path contains the
1400 # colon character (:), then the linker will try to split it
1401 # and look for the libraries in an unexpected place. This can
1402 # lead to unsafe code execution if the generated prefix is
1403 # within a world-writable directory.
1404 # (e.g. /var/tmp/portage:${HOSTNAME})
1405 pushd "${ED}"/$(get_libdir) >/dev/null
1408 for x in cal date env free ls true uname uptime ; do
1410 [[ -z ${x} || ${x} != ${EPREFIX}/* ]] && continue
1411 striptest=$(LC_ALL="C" file -L ${x} 2>/dev/null) || continue
1412 case ${striptest} in
1413 *"statically linked"*) continue;;
1414 *"ASCII text"*) continue;;
1416 # We need to clear the locale settings as the upgrade might want
1417 # incompatible locale data. This test is not for verifying that.
1419 ./ld-*.so --library-path . ${x} > /dev/null \
1420 || die "simple run test (${x}) failed"
1427 # nothing to do if just installing headers
1428 just_headers && return
1430 # prepare /etc/ld.so.conf.d/ for files
1431 mkdir -p "${EROOT}"/etc/ld.so.conf.d
1433 # Default /etc/hosts.conf:multi to on for systems with small dbs.
1434 if [[ $(wc -l < "${EROOT}"/etc/hosts) -lt 1000 ]] ; then
1435 sed -i '/^multi off/s:off:on:' "${ED}"/etc/host.conf
1436 einfo "Defaulting /etc/host.conf:multi to on"
1439 [[ -n ${ROOT} ]] && return 0
1440 [[ -d ${ED}/$(get_libdir) ]] || return 0
1441 [[ -z ${BOOTSTRAP_RAP} ]] && glibc_sanity_check
1445 # nothing to do if just installing headers
1446 just_headers && return
1448 if ! tc-is-cross-compiler && [[ -x ${EROOT}/usr/sbin/iconvconfig ]] ; then
1449 # Generate fastloading iconv module configuration file.
1450 "${EROOT}"/usr/sbin/iconvconfig --prefix="${ROOT}/"
1453 if ! is_crosscompile && [[ -z ${ROOT} ]] ; then
1454 use compile-locales || run_locale_gen "${EROOT}/"
1457 # Check for sanity of /etc/nsswitch.conf, take 2
1458 if [[ -e ${EROOT}/etc/nsswitch.conf ]] && ! has_version sys-auth/libnss-nis ; then
1460 for entry in passwd group shadow; do
1461 if egrep -q "^[ \t]*${entry}:.*nis" "${EROOT}"/etc/nsswitch.conf; then
1463 ewarn "Your ${EROOT}/etc/nsswitch.conf uses NIS. Support for that has been"
1464 ewarn "removed from glibc and is now provided by the package"
1465 ewarn " sys-auth/libnss-nis"
1466 ewarn "Install it now to keep your NIS setup working."