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 ~sh ~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
93 doc? ( sys-apps/texinfo )
96 gd? ( media-libs/gd:2= )
98 audit? ( sys-process/audit )
99 caps? ( sys-libs/libcap )
101 suid? ( caps? ( sys-libs/libcap ) )
102 selinux? ( sys-libs/libselinux )
103 systemtap? ( dev-util/systemtap )
105 DEPEND="${COMMON_DEPEND}
106 test? ( >=net-dns/libidn2-2.0.5 )
108 RDEPEND="${COMMON_DEPEND}
109 sys-apps/gentoo-functions
112 RESTRICT="!test? ( test )"
114 if [[ ${CATEGORY} == cross-* ]] ; then
115 BDEPEND+=" !headers-only? (
116 >=${CATEGORY}/binutils-2.24
119 [[ ${CATEGORY} == *-linux* ]] && DEPEND+=" ${CATEGORY}/linux-headers"
122 >=sys-devel/binutils-2.24
125 DEPEND+=" virtual/os-headers "
127 >=net-dns/libidn2-2.0.5
128 vanilla? ( !sys-libs/timezone-data )
130 PDEPEND+=" !vanilla? ( sys-libs/timezone-data )"
134 # Small helper functions
138 [[ ${CHOST} != ${CTARGET} ]]
142 is_crosscompile && use headers-only
146 is_crosscompile && echo /usr/${CTARGET}
149 # This prefix is applicable to CHOST when building against this
150 # glibc. It is baked into the library at configure time.
152 is_crosscompile || echo "${EPREFIX}"
155 # This prefix is applicable to CBUILD when building against this
156 # glibc. It determines the destination path at install time.
158 is_crosscompile && echo "${EPREFIX}"
161 # We need to be able to set alternative headers for compiling for non-native
162 # platform. Will also become useful for testing kernel-headers without screwing
163 # up the whole system.
165 echo ${ALT_HEADERS:=$(alt_prefix)/usr/include}
168 alt_build_headers() {
169 if [[ -z ${ALT_BUILD_HEADERS} ]] ; then
170 ALT_BUILD_HEADERS="$(host_eprefix)$(alt_headers)"
171 if tc-is-cross-compiler ; then
172 ALT_BUILD_HEADERS=${SYSROOT}$(alt_headers)
173 if [[ ! -e ${ALT_BUILD_HEADERS}/linux/version.h ]] ; then
174 local header_path=$(echo '#include <linux/version.h>' | $(tc-getCPP ${CTARGET}) ${CFLAGS} 2>&1 | grep -o '[^"]*linux/version.h')
175 ALT_BUILD_HEADERS=${header_path%/linux/version.h}
179 echo "${ALT_BUILD_HEADERS}"
183 echo $(alt_prefix)/$(get_libdir)
186 echo $(alt_prefix)/usr/$(get_libdir)
190 echo "${WORKDIR}/build-${ABI}-${CTARGET}-$1"
194 local ret save_cflags=${CFLAGS}
198 pushd "${T}" >/dev/null
201 printf '%b' "$*" > glibc-test.c
203 nonfatal emake glibc-test
208 CFLAGS=${save_cflags}
215 if [[ ${MERGE_TYPE} == "binary" ]] ; then
216 # ignore build failures when installing a binary package #324685
217 do_compile_test "" "$@" 2>/dev/null || return 0
219 if ! do_compile_test "" "$@" ; then
220 ewarn "Simple build failed ... assuming this is desired #324685"
225 pushd "${T}" >/dev/null
236 setup_target_flags() {
237 # This largely mucks with compiler flags. None of which should matter
238 # when building up just the headers.
239 just_headers && return 0
243 # -march needed for #185404 #199334
244 # TODO: When creating the first glibc cross-compile, this test will
245 # always fail as it does a full link which in turn requires glibc.
246 # Probably also applies when changing multilib profile settings (e.g.
247 # enabling x86 when the profile was amd64-only previously).
248 # We could change main to _start and pass -nostdlib here so that we
249 # only test the gcc code compilation. Or we could do a compile and
250 # then look for the symbol via scanelf.
251 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
252 local t=${CTARGET_OPT:-${CTARGET}}
254 filter-flags '-march=*'
255 export CFLAGS="-march=${t} ${CFLAGS}"
256 einfo "Auto adding -march=${t} to CFLAGS #185404"
260 # -march needed for #185404 #199334
261 # TODO: See cross-compile issues listed above for x86.
262 [[ ${ABI} == x86 ]] &&
263 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
264 local t=${CTARGET_OPT:-${CTARGET}}
266 # Normally the target is x86_64-xxx, so turn that into the -march that
267 # gcc actually accepts. #528708
268 [[ ${t} == "x86_64" ]] && t="x86-64"
269 filter-flags '-march=*'
270 # ugly, ugly, ugly. ugly.
271 CFLAGS_x86=$(CFLAGS=${CFLAGS_x86} filter-flags '-march=*'; echo "${CFLAGS}")
272 export CFLAGS_x86="${CFLAGS_x86} -march=${t}"
273 einfo "Auto adding -march=${t} to CFLAGS_x86 #185404 (ABI=${ABI})"
277 # The mips abi cannot support the GNU style hashes. #233233
278 filter-ldflags -Wl,--hash-style=gnu -Wl,--hash-style=both
281 # Both sparc and sparc64 can use -fcall-used-g6. -g7 is bad, though.
282 filter-flags "-fcall-used-g7"
283 append-flags "-fcall-used-g6"
285 # If the CHOST is the basic one (e.g. not sparcv9-xxx already),
286 # try to pick a better one so glibc can use cpu-specific .S files.
287 # We key off the CFLAGS to get a good value. Also need to handle
289 # We can't force users to set their CHOST to their exact machine
290 # as many of these are not recognized by config.sub/gcc and such :(.
291 # Note: If the mcpu values don't scale, we might try probing CPP defines.
292 # Note: Should we factor in -Wa,-AvXXX flags too ? Or -mvis/etc... ?
297 case $(get-flag mcpu) in
299 if ver_test -ge 2.8 ; then
301 elif ver_test -ge 2.4 ; then
303 elif ver_test -ge 2.2.3 ; then
308 if ver_test -ge 2.4 ; then
310 elif ver_test -ge 2.2.3 ; then
318 # We need to force at least v9a because the base build doesn't
320 # https://sourceware.org/bugzilla/show_bug.cgi?id=19477
321 [[ -z ${cpu} ]] && append-flags "-Wa,-xarch=v9a"
326 case $(get-flag mcpu) in
328 if ver_test -ge 2.8 ; then
330 elif ver_test -ge 2.4 ; then
332 elif ver_test -ge 2.2.3 ; then
339 if ver_test -ge 2.4 ; then
341 elif ver_test -ge 2.2.3 ; then
353 v8|supersparc|hypersparc|leon|leon3)
359 [[ -n ${cpu} ]] && CTARGET_OPT="${cpu}-${CTARGET#*-}"
365 # Make sure host make.conf doesn't pollute us
366 if is_crosscompile || tc-is-cross-compiler ; then
367 CHOST=${CTARGET} strip-unsupported-flags
370 # Store our CFLAGS because it's changed depending on which CTARGET
371 # we are building when pulling glibc on a multilib profile
372 CFLAGS_BASE=${CFLAGS_BASE-${CFLAGS}}
373 CFLAGS=${CFLAGS_BASE}
374 CXXFLAGS_BASE=${CXXFLAGS_BASE-${CXXFLAGS}}
375 CXXFLAGS=${CXXFLAGS_BASE}
376 ASFLAGS_BASE=${ASFLAGS_BASE-${ASFLAGS}}
377 ASFLAGS=${ASFLAGS_BASE}
379 # Allow users to explicitly avoid flag sanitization via
381 if ! use custom-cflags; then
382 # Over-zealous CFLAGS can often cause problems. What may work for one
383 # person may not work for another. To avoid a large influx of bugs
384 # relating to failed builds, we strip most CFLAGS out to ensure as few
385 # problems as possible.
387 # Lock glibc at -O2; we want to be conservative here.
391 strip-unsupported-flags
392 filter-flags -m32 -m64 '-mabi=*'
394 # glibc aborts if rpath is set by LDFLAGS
395 filter-ldflags '-Wl,-rpath=*'
398 filter-flags -frecord-gcc-switches
400 unset CBUILD_OPT CTARGET_OPT
401 if use multilib ; then
402 CTARGET_OPT=$(get_abi_CTARGET)
403 [[ -z ${CTARGET_OPT} ]] && CTARGET_OPT=$(get_abi_CHOST)
408 if [[ -n ${CTARGET_OPT} && ${CBUILD} == ${CHOST} ]] && ! is_crosscompile; then
409 CBUILD_OPT=${CTARGET_OPT}
412 # glibc's headers disallow -O0 and fail at build time:
413 # include/libc-symbols.h:75:3: #error "glibc cannot be compiled without optimization"
414 replace-flags -O0 -O1
416 filter-flags '-fstack-protector*'
420 # Archs that can use TLS (Thread Local Storage)
423 # requires i486 or better #106556
424 [[ ${CTARGET} == i[4567]86* ]] && return 0
434 # For some reason --with-tls --with__thread is causing segfaults on sparc32.
435 [[ ${PROFILE_ARCH} == "sparc" ]] && return 1
437 [[ -n ${WANT__THREAD} ]] && return ${WANT__THREAD}
439 # only test gcc -- can't test linking yet
440 tc-has-tls -c ${CTARGET}
443 return ${WANT__THREAD}
447 # Allow user to disable runtime arch detection in multilib.
448 use multiarch || return 1
449 # Make sure binutils is new enough to support indirect functions,
450 # #336792. This funky sed supports gold and bfd linkers.
452 bver=$($(tc-getLD ${CTARGET}) -v | sed -n -r '1{s:[^0-9]*::;s:^([0-9.]*).*:\1:;p}')
453 case $(tc-arch ${CTARGET}) in
454 amd64|x86) nver="2.20" ;;
457 ppc|ppc64) nver="2.20" ;;
458 # ifunc support was added in 2.23, but glibc also needs
459 # machinemode which is in 2.24.
461 sparc) nver="2.21" ;;
464 ver_test ${bver} -ge ${nver}
467 # Setup toolchain variables that had historically been defined in the
468 # profiles for these archs.
472 unset LD_ASSUME_KERNEL
474 if is_crosscompile || tc-is-cross-compiler ; then
475 multilib_env ${CTARGET_OPT:-${CTARGET}}
477 if ! use multilib ; then
478 MULTILIB_ABIS=${DEFAULT_ABI}
480 MULTILIB_ABIS=${MULTILIB_ABIS:-${DEFAULT_ABI}}
483 # If the user has CFLAGS_<CTARGET> in their make.conf, use that,
484 # and fall back on CFLAGS.
485 local VAR=CFLAGS_${CTARGET//[-.]/_}
486 CFLAGS=${!VAR-${CFLAGS}}
487 einfo " $(printf '%15s' 'Manual CFLAGS:') ${CFLAGS}"
492 export ABI=${ABI:-${DEFAULT_ABI:-default}}
494 if just_headers ; then
495 # Avoid mixing host's CC and target's CFLAGS_${ABI}:
496 # At this bootstrap stage we have only binutils for
497 # target but not compiler yet.
498 einfo "Skip CC ABI injection. We can't use (cross-)compiler yet."
501 local VAR=CFLAGS_${ABI}
502 # We need to export CFLAGS with abi information in them because glibc's
503 # configure script checks CFLAGS for some targets (like mips). Keep
504 # around the original clean value to avoid appending multiple ABIs on
506 : ${__GLIBC_CC:=$(tc-getCC ${CTARGET_OPT:-${CTARGET}})}
507 export __GLIBC_CC CC="${__GLIBC_CC} ${!VAR}"
508 einfo " $(printf '%15s' 'Manual CC:') ${CC}"
516 if use multilib ; then
517 abilist=$(get_install_abis)
519 abilist=${DEFAULT_ABI}
522 for ABI in ${abilist:-default} ; do
524 einfo "Running $1 for ABI ${ABI}"
532 local b="Gentoo ${PVR}"
533 [[ -n ${PATCH_VER} ]] && ! use vanilla && b+=" p${PATCH_VER}"
538 # Make sure devpts is mounted correctly for use w/out setuid pt_chown.
540 # If merely building the binary package, then there's nothing to verify.
541 [[ ${MERGE_TYPE} == "buildonly" ]] && return
543 # Only sanity check when installing the native glibc.
544 [[ -n ${ROOT} ]] && return
546 # If they're opting in to the old suid code, then no need to check.
549 if awk '$3 == "devpts" && $4 ~ /[, ]gid=5[, ]/ { exit 1 }' /proc/mounts ; then
550 eerror "In order to use glibc with USE=-suid, you must make sure that"
551 eerror "you have devpts mounted at /dev/pts with the gid=5 option."
552 eerror "Openrc should do this for you, so you should check /etc/fstab"
553 eerror "and make sure you do not have any invalid settings there."
554 die "mount & fix your /dev/pts settings"
558 # The following Kernel version handling functions are mostly copied from portage
559 # source. It's better not to use linux-info.eclass here since a) it adds too
560 # much magic, see bug 326693 for some of the arguments, and b) some of the
561 # functions are just not provided.
569 [[ -z $1 ]] && return 1
575 [[ -z $1 ]] && return 1
582 [[ -z $1 ]] && return 1
585 echo "${KV%%[^[:digit:]]*}"
589 [[ -z $1 ]] && return 1
590 local KV_MAJOR=$(g_KV_major "$1")
591 local KV_MINOR=$(g_KV_minor "$1")
592 local KV_MICRO=$(g_KV_micro "$1")
593 local KV_int=$(( KV_MAJOR * 65536 + KV_MINOR * 256 + KV_MICRO ))
595 # We make version 2.2.0 the minimum version we will handle as
596 # a sanity check ... if its less, we fail ...
597 if [[ ${KV_int} -ge 131584 ]] ; then
605 local version=$1 major minor micro
606 major=$((version / 65536))
607 minor=$(((version % 65536) / 256))
608 micro=$((version % 256))
609 echo ${major}.${minor}.${micro}
613 [[ $(g_KV_to_int $1) -ge $(g_KV_to_int $2) ]]
617 get_kheader_version() {
618 printf '#include <linux/version.h>\nLINUX_VERSION_CODE\n' | \
619 $(tc-getCPP ${CTARGET}) -I "$(build_eprefix)$(alt_build_headers)" - | \
623 # We collect all sanity checks here. Consistency is not guranteed between
624 # pkg_ and src_ phases, so we call this function both in pkg_pretend and in
627 # Make sure devpts is mounted correctly for use w/out setuid pt_chown
630 # Prevent native builds from downgrading
631 if [[ ${MERGE_TYPE} != "buildonly" ]] && \
632 [[ -z ${ROOT} ]] && \
633 [[ ${CBUILD} == ${CHOST} ]] && \
634 [[ ${CHOST} == ${CTARGET} ]] ; then
636 # The high rev # is to allow people to downgrade between -r#
637 # versions. We want to block 2.20->2.19, but 2.20-r3->2.20-r2
638 # should be fine. Hopefully we never actually use a r# this
640 if has_version ">${CATEGORY}/${P}-r10000" ; then
641 eerror "Sanity check to keep you from breaking your system:"
642 eerror " Downgrading glibc is not supported and a sure way to destruction."
643 [[ ${I_ALLOW_TO_BREAK_MY_SYSTEM} = yes ]] || die "Aborting to save your system."
646 if ! do_run_test '#include <unistd.h>\n#include <sys/syscall.h>\nint main(){return syscall(1000)!=-1;}\n' ; then
647 eerror "Your old kernel is broken. You need to update it to a newer"
648 eerror "version as syscall(<bignum>) will break. See bug 279260."
649 die "Old and broken kernel."
653 # Users have had a chance to phase themselves, time to give em the boot
654 if [[ -e ${EROOT}/etc/locale.gen ]] && [[ -e ${EROOT}/etc/locales.build ]] ; then
655 eerror "You still haven't deleted ${EROOT}/etc/locales.build."
656 eerror "Do so now after making sure ${EROOT}/etc/locale.gen is kosher."
657 die "Lazy upgrader detected"
660 if [[ ${CTARGET} == i386-* ]] ; then
661 eerror "i386 CHOSTs are no longer supported."
662 eerror "Chances are you don't actually want/need i386."
663 eerror "Please read https://www.gentoo.org/doc/en/change-chost.xml"
664 die "Please fix your CHOST"
667 if [[ -e /proc/xen ]] && [[ $(tc-arch) == "x86" ]] && ! is-flag -mno-tls-direct-seg-refs ; then
668 ewarn "You are using Xen but don't have -mno-tls-direct-seg-refs in your CFLAGS."
669 ewarn "This will result in a 50% performance penalty when running with a 32bit"
670 ewarn "hypervisor, which is probably not what you want."
673 # Check for sanity of /etc/nsswitch.conf
674 if [[ -e ${EROOT}/etc/nsswitch.conf ]] ; then
676 for entry in passwd group shadow; do
677 if ! egrep -q "^[ \t]*${entry}:.*files" "${EROOT}"/etc/nsswitch.conf; then
678 eerror "Your ${EROOT}/etc/nsswitch.conf is out of date."
679 eerror "Please make sure you have 'files' entries for"
680 eerror "'passwd:', 'group:' and 'shadow:' databases."
681 eerror "For more details see:"
682 eerror " https://wiki.gentoo.org/wiki/Project:Toolchain/nsswitch.conf_in_glibc-2.26"
683 die "nsswitch.conf has no 'files' provider in '${entry}'."
688 # ABI-specific checks follow here. Hey, we have a lot more specific conditions that
690 if ! is_crosscompile ; then
691 if use amd64 && use multilib && [[ ${MERGE_TYPE} != "binary" ]] ; then
692 ebegin "Checking that IA32 emulation is enabled in the running kernel"
693 echo 'int main(){return 0;}' > "${T}/check-ia32-emulation.c"
695 if "${CC-${CHOST}-gcc}" ${CFLAGS_x86} "${T}/check-ia32-emulation.c" -o "${T}/check-ia32-emulation.elf32"; then
696 "${T}/check-ia32-emulation.elf32"
699 # Don't fail here to allow single->multi ABI switch
700 # or recover from breakage like bug #646424
701 ewarn "Failed to compile the ABI test. Broken host glibc?"
704 rm -f "${T}/check-ia32-emulation.elf32"
706 [[ $STAT -eq 0 ]] || die "CONFIG_IA32_EMULATION must be enabled in the kernel to compile a multilib glibc."
711 # When we actually have to compile something...
712 if ! just_headers ; then
713 ebegin "Checking gcc for __thread support"
714 if ! eend $(want__thread ; echo $?) ; then
716 eerror "Could not find a gcc that supports the __thread directive!"
717 eerror "Please update your binutils/gcc and try again."
718 die "No __thread support in gcc!"
721 if [[ ${CTARGET} == *-linux* ]] ; then
722 local run_kv build_kv want_kv
724 run_kv=$(g_get_running_KV)
725 build_kv=$(g_int_to_KV $(get_kheader_version))
726 want_kv=${MIN_KERN_VER}
728 if ! is_crosscompile && ! tc-is-cross-compiler ; then
729 # Building fails on an non-supporting kernel
730 ebegin "Checking running kernel version (${run_kv} >= ${want_kv})"
731 if ! eend_KV ${run_kv} ${want_kv} ; then
733 eerror "You need a kernel of at least ${want_kv}!"
734 die "Kernel version too low!"
738 ebegin "Checking linux-headers version (${build_kv} >= ${want_kv})"
739 if ! eend_KV ${build_kv} ${want_kv} ; then
741 eerror "You need linux-headers of at least ${want_kv}!"
742 die "linux-headers version too low!"
756 einfo "Checking general environment sanity."
762 [[ -z ${BOOTSTRAP_RAP} ]] && python-any-r1_pkg_setup
768 # Consistency is not guaranteed between pkg_ and src_ ...
771 use multilib && unpack gcc-multilib-bootstrap-${GCC_BOOTSTRAP_VER}.tar.xz
775 if [[ -n ${EGIT_REPO_URI} ]] ; then
781 cd "${WORKDIR}" || die
782 unpack glibc-${RELEASE_VER}-patches-${PATCH_VER}.tar.xz
786 if ! use vanilla ; then
787 elog "Applying Gentoo Glibc Patchset ${RELEASE_VER}-${PATCH_VER}"
788 eapply "${WORKDIR}"/patches
797 find . -name configure -exec touch {} +
799 eprefixify extra/locale/locale-gen
801 # Fix permissions on some of the scripts.
802 chmod u+x "${S}"/scripts/*.sh
807 glibc_do_configure() {
808 # Glibc does not work with gold (for various reasons) #269274.
811 # CXX isnt handled by the multilib system, so if we dont unset here
812 # we accumulate crap across abis
815 einfo "Configuring glibc for nptl"
818 export MAKEINFO=makeinfo
820 export MAKEINFO=/dev/null
824 for v in ABI CBUILD CHOST CTARGET CBUILD_OPT CTARGET_OPT CC CXX LD {AS,C,CPP,CXX,LD}FLAGS MAKEINFO ; do
825 einfo " $(printf '%15s' ${v}:) ${!v}"
828 # CFLAGS can contain ABI-specific flags like -mfpu=neon, see bug #657760
829 # To build .S (assembly) files with the same ABI-specific flags
830 # upstream currently recommends adding CFLAGS to CC/CXX:
831 # https://sourceware.org/PR23273
832 # Note: Passing CFLAGS via CPPFLAGS overrides glibc's arch-specific CFLAGS
833 # and breaks multiarch support. See 659030#c3 for an example.
834 # The glibc configure script doesn't properly use LDFLAGS all the time.
835 export CC="$(tc-getCC ${CTARGET}) ${CFLAGS} ${LDFLAGS}"
836 einfo " $(printf '%15s' 'Manual CC:') ${CC}"
838 # Some of the tests are written in C++, so we need to force our multlib abis in, bug 623548
839 export CXX="$(tc-getCXX ${CTARGET}) $(get_abi_CFLAGS) ${CFLAGS}"
841 if is_crosscompile; then
842 # Assume worst-case bootstrap: glibc is buil first time
843 # when ${CTARGET}-g++ is not available yet. We avoid
844 # building auxiliary programs that require C++: bug #683074
845 # It should not affect final result.
846 export libc_cv_cxx_link_ok=no
847 # The line above has the same effect. We set CXX explicitly
848 # to make build logs less confusing.
851 einfo " $(printf '%15s' 'Manual CXX:') ${CXX}"
859 # setjmp() is not compatible with stack protection:
860 # https://sourceware.org/PR24202
861 myconf+=( --enable-stack-protector=no )
864 # Currently gcc on powerpc32 generates invalid code for
865 # __builtin_return_address(0) calls. Normally programs
866 # don't do that but malloc hooks in glibc do:
867 # https://gcc.gnu.org/PR81996
868 # https://bugs.gentoo.org/629054
869 myconf+=( --enable-stack-protector=no )
872 myconf+=( --enable-stack-protector=$(usex ssp all no) )
875 myconf+=( --enable-stackguard-randomization )
877 # Keep a whitelist of targets supporing IFUNC. glibc's ./configure
878 # is not robust enough to detect proper support:
879 # https://bugs.gentoo.org/641216
880 # https://sourceware.org/PR22634#c0
881 case $(tc-arch ${CTARGET}) in
882 # Keep whitelist of targets where autodetection mostly works.
883 amd64|x86|sparc|ppc|ppc64|arm|arm64|s390) ;;
884 # Blacklist everywhere else
885 *) myconf+=( libc_cv_ld_gnu_indirect_function=no ) ;;
888 # Enable Intel Control-flow Enforcement Technology on amd64 if requested
890 x86_64-*) myconf+=( $(use_enable cet) ) ;;
894 [[ $(tc-is-softfloat) == "yes" ]] && myconf+=( --without-fp )
896 myconf+=( --enable-kernel=${MIN_KERN_VER} )
898 # Since SELinux support is only required for nscd, only enable it if:
900 # 2. only for the primary ABI on multilib systems
901 # 3. Not a crosscompile
902 if ! is_crosscompile && use selinux ; then
903 if use multilib ; then
904 if is_final_abi ; then
905 myconf+=( --with-selinux )
907 myconf+=( --without-selinux )
910 myconf+=( --with-selinux )
913 myconf+=( --without-selinux )
916 # Force a few tests where we always know the answer but
917 # configure is incapable of finding it.
918 if is_crosscompile ; then
920 libc_cv_c_cleanup=yes \
921 libc_cv_forced_unwind=yes
928 --build=${CBUILD_OPT:-${CBUILD}}
929 --host=${CTARGET_OPT:-${CTARGET}}
930 $(use_enable profile)
932 --with-headers=$(build_eprefix)$(alt_build_headers)
933 --prefix="$(host_eprefix)/usr"
934 --sysconfdir="$(host_eprefix)/etc"
935 --localstatedir="$(host_eprefix)/var"
936 --libdir='$(prefix)'/$(get_libdir)
937 --mandir='$(prefix)'/share/man
938 --infodir='$(prefix)'/share/info
939 --libexecdir='$(libdir)'/misc/glibc
940 --with-bugurl=https://bugs.gentoo.org/
941 --with-pkgversion="$(glibc_banner)"
943 $(use_multiarch || echo --disable-multi-arch)
944 $(use_enable systemtap)
949 # We rely on sys-libs/timezone-data for timezone tools normally.
950 myconf+=( $(use_enable vanilla timezone-tools) )
952 # These libs don't have configure flags.
953 ac_cv_lib_audit_audit_log_user_avc_message=$(usex audit || echo no)
954 ac_cv_lib_cap_cap_init=$(usex caps || echo no)
956 # There is no configure option for this and we need to export it
957 # since the glibc build will re-run configure on itself
958 export libc_cv_rootsbindir="$(host_eprefix)/sbin"
959 export libc_cv_slibdir="$(host_eprefix)/$(get_libdir)"
961 # We take care of patching our binutils to use both hash styles,
962 # and many people like to force gnu hash style only, so disable
963 # this overriding check. #347761
964 export libc_cv_hashstyle=no
966 local builddir=$(builddir nptl)
967 mkdir -p "${builddir}"
969 set -- "${S}"/configure "${myconf[@]}"
971 "$@" || die "failed to configure glibc"
973 # ia64 static cross-compilers are a pita in so much that they
974 # can't produce static ELFs (as the libgcc.a is broken). so
975 # disable building of the programs for those targets if it
977 # XXX: We could turn this into a compiler test, but ia64 is
978 # the only one that matters, so this should be fine for now.
979 if is_crosscompile && [[ ${CTARGET} == ia64* ]] ; then
980 sed -i '1i+link-static = touch $@' config.make
983 # If we're trying to migrate between ABI sets, we need
984 # to lie and use a local copy of gcc. Like if the system
985 # is built with MULTILIB_ABIS="amd64 x86" but we want to
986 # add x32 to it, gcc/glibc don't yet support x32.
988 if [[ -n ${GCC_BOOTSTRAP_VER} ]] && use multilib ; then
989 echo 'main(){}' > "${T}"/test.c
990 if ! $(tc-getCC ${CTARGET}) ${CFLAGS} ${LDFLAGS} "${T}"/test.c -Wl,-emain -lgcc 2>/dev/null ; then
991 sed -i -e '/^CC = /s:$: -B$(objdir)/../'"gcc-multilib-bootstrap-${GCC_BOOTSTRAP_VER}/${ABI}:" config.make || die
996 glibc_headers_configure() {
999 local builddir=$(builddir "headers")
1000 mkdir -p "${builddir}"
1003 # if we don't have a compiler yet, we can't really test it now ...
1004 # hopefully they don't affect header generation, so let's hope for
1007 ac_cv_header_cpuid_h=yes
1008 libc_cv_{386,390,alpha,arm,hppa,ia64,mips,{powerpc,sparc}{,32,64},sh,x86_64}_tls=yes
1009 libc_cv_asm_cfi_directives=yes
1010 libc_cv_broken_visibility_attribute=no
1011 libc_cv_c_cleanup=yes
1012 libc_cv_compiler_powerpc64le_binary128_ok=yes
1013 libc_cv_forced_unwind=yes
1014 libc_cv_gcc___thread=yes
1015 libc_cv_mlong_double_128=yes
1016 libc_cv_mlong_double_128ibm=yes
1017 libc_cv_ppc_machine=yes
1018 libc_cv_ppc_rel16=yes
1019 libc_cv_predef_fortify_source=no
1020 libc_cv_target_power8_ok=yes
1021 libc_cv_visibility_attribute=yes
1022 libc_cv_z_combreloc=yes
1023 libc_cv_z_execstack=yes
1024 libc_cv_z_initfirst=yes
1025 libc_cv_z_nodelete=yes
1026 libc_cv_z_nodlopen=yes
1028 libc_mips_abi=${ABI}
1029 libc_mips_float=$([[ $(tc-is-softfloat) == "yes" ]] && echo soft || echo hard)
1030 # These libs don't have configure flags.
1031 ac_cv_lib_audit_audit_log_user_avc_message=no
1032 ac_cv_lib_cap_cap_init=no
1035 einfo "Forcing cached settings:"
1036 for v in "${vars[@]}" ; do
1041 local headers_only_arch_CPPFLAGS=()
1043 # Blow away some random CC settings that screw things up. #550192
1044 if [[ -d ${S}/sysdeps/mips ]]; then
1045 pushd "${S}"/sysdeps/mips >/dev/null
1046 sed -i -e '/^CC +=/s:=.*:= -D_MIPS_SZPTR=32:' mips32/Makefile mips64/n32/Makefile || die
1047 sed -i -e '/^CC +=/s:=.*:= -D_MIPS_SZPTR=64:' mips64/n64/Makefile || die
1049 # Force the mips ABI to the default. This is OK because the set of
1050 # installed headers in this phase is the same between the 3 ABIs.
1051 # If this ever changes, this hack will break, but that's unlikely
1052 # as glibc discourages that behavior.
1053 # https://crbug.com/647033
1054 sed -i -e 's:abiflag=.*:abiflag=_ABIO32:' preconfigure || die
1061 # RISC-V interrogates the compiler to determine which target to
1062 # build. If building the headers then we don't strictly need a
1063 # RISC-V compiler, so the built-in definitions that are provided
1064 # along with all RISC-V compiler might not exist. This causes
1065 # glibc's RISC-V preconfigure script to blow up. Since we're just
1066 # building the headers any value will actually work here, so just
1067 # pick the standard one (rv64g/lp64d) to make the build scripts
1068 # happy for now -- the headers are all the same anyway so it
1070 headers_only_arch_CPPFLAGS+=(
1073 -D__riscv_float_abi_double=1
1080 --disable-sanity-checks
1081 --enable-hacker-mode
1085 --build=${CBUILD_OPT:-${CBUILD}}
1086 --host=${CTARGET_OPT:-${CTARGET}}
1087 --with-headers=$(build_eprefix)$(alt_build_headers)
1088 --prefix="$(host_eprefix)/usr"
1092 # Nothing is compiled here which would affect the headers for the target.
1093 # So forcing CC/CFLAGS is sane.
1094 local headers_only_CC=$(tc-getBUILD_CC)
1095 local headers_only_CFLAGS="-O1 -pipe"
1096 local headers_only_CPPFLAGS="-U_FORTIFY_SOURCE ${headers_only_arch_CPPFLAGS[*]}"
1097 local headers_only_LDFLAGS=""
1098 set -- "${S}"/configure "${myconf[@]}"
1100 "CC=${headers_only_CC}" \
1101 "CFLAGS=${headers_only_CFLAGS}" \
1102 "CPPFLAGS=${headers_only_CPPFLAGS}" \
1103 "LDFLAGS=${headers_only_LDFLAGS}" \
1105 CC=${headers_only_CC} \
1106 CFLAGS=${headers_only_CFLAGS} \
1107 CPPFLAGS=${headers_only_CPPFLAGS} \
1109 "$@" || die "failed to configure glibc"
1112 do_src_configure() {
1113 if just_headers ; then
1114 glibc_headers_configure
1116 glibc_do_configure nptl
1121 foreach_abi do_src_configure
1125 emake -C "$(builddir nptl)"
1129 if just_headers ; then
1133 foreach_abi do_src_compile
1137 cd "$(builddir nptl)"
1151 if just_headers ; then
1155 # Give tests more time to complete.
1156 export TIMEOUTFACTOR=5
1158 foreach_abi do_src_test || die "tests failed"
1162 # if the host locales.gen contains no entries, we'll install everything
1166 if [[ "${root}" == "--inplace-glibc" ]] ; then
1167 inplace="--inplace-glibc"
1171 local locale_list="${root}/etc/locale.gen"
1173 pushd "${ED}"/$(get_libdir) >/dev/null
1175 if [[ -z $(locale-gen --list --config "${locale_list}") ]] ; then
1176 [[ -z ${inplace} ]] && ewarn "Generating all locales; edit /etc/locale.gen to save time/space"
1177 locale_list="${root}/usr/share/i18n/SUPPORTED"
1180 locale-gen ${inplace} --jobs $(makeopts_jobs) --config "${locale_list}" \
1186 glibc_do_src_install() {
1187 local builddir=$(builddir nptl)
1190 emake install_root="${D}/$(build_eprefix)$(alt_prefix)" install
1192 # This version (2.26) provides some compatibility libraries for the NIS/NIS+ support
1193 # which come without headers etc. Only needed for binary packages since the
1194 # external net-libs/libnsl has increased soversion. Keep only versioned libraries.
1195 find "${D}" -name "libnsl.a" -delete
1196 find "${D}" -name "libnsl.so" -delete
1198 # Normally upstream_pv is ${PV}. Live ebuilds are exception, there we need
1199 # to infer upstream version:
1200 # '#define VERSION "2.26.90"' -> '2.26.90'
1201 local upstream_pv=$(sed -n -r 's/#define VERSION "(.*)"/\1/p' "${S}"/version.h)
1203 # Avoid stripping binaries not targeted by ${CHOST}. Or else
1204 # ${CHOST}-strip would break binaries build for ${CTARGET}.
1205 is_crosscompile && dostrip -x /
1206 # gdb thread introspection relies on local libpthreas symbols. stripping breaks it
1207 # See Note [Disable automatic stripping]
1208 dostrip -x $(alt_libdir)/libpthread-${upstream_pv}.so
1210 if [[ -e ${ED}/$(alt_usrlibdir)/libm-${upstream_pv}.a ]] ; then
1211 # Move versioned .a file out of libdir to evade portage QA checks
1212 # instead of using gen_usr_ldscript(). We fix ldscript as:
1213 # "GROUP ( /usr/lib64/libm-<pv>.a ..." -> "GROUP ( /usr/lib64/glibc-<pv>/libm-<pv>.a ..."
1214 sed -i "s@\(libm-${upstream_pv}.a\)@${P}/\1@" "${ED}"/$(alt_usrlibdir)/libm.a || die
1215 dodir $(alt_usrlibdir)/${P}
1216 mv "${ED}"/$(alt_usrlibdir)/libm-${upstream_pv}.a "${ED}"/$(alt_usrlibdir)/${P}/libm-${upstream_pv}.a || die
1219 # We'll take care of the cache ourselves
1220 rm -f "${ED}"/etc/ld.so.cache
1222 # Everything past this point just needs to be done once ...
1223 is_final_abi || return 0
1225 # Make sure the non-native interp can be found on multilib systems even
1226 # if the main library set isn't installed into the right place. Maybe
1227 # we should query the active gcc for info instead of hardcoding it ?
1228 local i ldso_abi ldso_name
1229 local ldso_abi_list=(
1231 amd64 /lib64/ld-linux-x86-64.so.2
1232 x32 /libx32/ld-linux-x32.so.2
1233 x86 /lib/ld-linux.so.2
1240 ppc64 /lib64/ld64.so.1
1242 lp64d /lib/ld-linux-riscv64-lp64d.so.1
1243 lp64 /lib/ld-linux-riscv64-lp64.so.1
1246 s390x /lib/ld64.so.1
1248 sparc32 /lib/ld-linux.so.2
1249 sparc64 /lib64/ld-linux.so.2
1251 case $(tc-endian) in
1255 arm64 /lib/ld-linux-aarch64.so.1
1261 arm64 /lib/ld-linux-aarch64_be.so.1
1265 if [[ ${SYMLINK_LIB} == "yes" ]] && [[ ! -e ${ED}/$(alt_prefix)/lib ]] ; then
1266 dosym $(get_abi_LIBDIR ${DEFAULT_ABI}) $(alt_prefix)/lib
1268 for (( i = 0; i < ${#ldso_abi_list[@]}; i += 2 )) ; do
1269 ldso_abi=${ldso_abi_list[i]}
1270 has ${ldso_abi} $(get_install_abis) || continue
1272 ldso_name="$(alt_prefix)${ldso_abi_list[i+1]}"
1273 if [[ ! -L ${ED}/${ldso_name} && ! -e ${ED}/${ldso_name} ]] ; then
1274 dosym ../$(get_abi_LIBDIR ${ldso_abi})/${ldso_name##*/} ${ldso_name}
1278 # With devpts under Linux mounted properly, we do not need the pt_chown
1279 # binary to be setuid. This is because the default owners/perms will be
1280 # exactly what we want.
1281 if ! use suid ; then
1282 find "${ED}" -name pt_chown -exec chmod -s {} +
1285 #################################################################
1286 # EVERYTHING AFTER THIS POINT IS FOR NATIVE GLIBC INSTALLS ONLY #
1287 # Make sure we install some symlink hacks so that when we build
1288 # a 2nd stage cross-compiler, gcc finds the target system
1289 # headers correctly. See gcc/doc/gccinstall.info
1290 if is_crosscompile ; then
1291 # We need to make sure that /lib and /usr/lib always exists.
1292 # gcc likes to use relative paths to get to its multilibs like
1293 # /usr/lib/../lib64/. So while we don't install any files into
1294 # /usr/lib/, we do need it to exist.
1295 keepdir $(alt_prefix)/lib
1296 keepdir $(alt_prefix)/usr/lib
1298 dosym usr/include $(alt_prefix)/sys-include
1302 # Files for Debian-style locale updating
1303 dodir /usr/share/i18n
1306 -e "/SUPPORTED-LOCALES=/d" \
1307 -e "s: \\\\::g" -e "s:/: :g" \
1308 "${S}"/localedata/SUPPORTED > "${ED}"/usr/share/i18n/SUPPORTED \
1309 || die "generating /usr/share/i18n/SUPPORTED failed"
1310 cd "${WORKDIR}"/extra/locale
1316 # Make sure all the ABI's can find the locales and so we only
1317 # have to generate one set
1319 keepdir /usr/$(get_libdir)/locale
1320 for a in $(get_install_abis) ; do
1321 if [[ ! -e ${ED}/usr/$(get_abi_LIBDIR ${a})/locale ]] ; then
1322 dosym ../$(get_libdir)/locale /usr/$(get_abi_LIBDIR ${a})/locale
1326 # HACK: If we're building for riscv, we need to additionally make sure that
1327 # we can find the locale archive afterwards
1330 if [[ ! -e ${ED}/usr/lib/locale ]] ; then
1331 dosym ../$(get_libdir)/locale /usr/lib/locale
1339 # Install misc network config files
1341 doins nscd/nscd.conf posix/gai.conf nss/nsswitch.conf
1342 doins "${WORKDIR}"/extra/etc/*.conf
1345 doinitd "$(prefixify_ro "${WORKDIR}"/extra/etc/nscd)"
1348 -e "s:@PIDFILE@:$(strings "${ED}"/usr/sbin/nscd | grep nscd.pid):"
1351 sed -i "${nscd_args[@]}" "${ED}"/etc/init.d/nscd
1353 systemd_dounit nscd/nscd.service
1354 systemd_newtmpfilesd nscd/nscd.tmpfiles nscd.conf
1356 # Do this since extra/etc/*.conf above might have nscd.conf.
1357 rm -f "${ED}"/etc/nscd.conf
1360 echo 'LDPATH="include ld.so.conf.d/*.conf"' > "${T}"/00glibc
1361 doenvd "${T}"/00glibc
1363 for d in BUGS ChangeLog CONFORMANCE FAQ NEWS NOTES PROJECTS README* ; do
1364 [[ -s ${d} ]] && dodoc ${d}
1366 dodoc -r ChangeLog.old
1368 # Prevent overwriting of the /etc/localtime symlink. We'll handle the
1369 # creation of the "factory" symlink in pkg_postinst().
1370 rm -f "${ED}"/etc/localtime
1372 # Generate all locales if this is a native build as locale generation
1373 if use compile-locales && ! is_crosscompile ; then
1374 run_locale_gen --inplace-glibc "${ED}/"
1375 sed -e 's:COMPILED_LOCALES="":COMPILED_LOCALES="1":' -i "${ED}"/usr/sbin/locale-gen || die
1379 glibc_headers_install() {
1380 local builddir=$(builddir "headers")
1382 emake install_root="${D}/$(build_eprefix)$(alt_prefix)" install-headers
1384 insinto $(alt_headers)/gnu
1385 doins "${S}"/include/gnu/stubs.h
1387 # Make sure we install the sys-include symlink so that when
1388 # we build a 2nd stage cross-compiler, gcc finds the target
1389 # system headers correctly. See gcc/doc/gccinstall.info
1390 dosym usr/include $(alt_prefix)/sys-include
1394 if just_headers ; then
1396 glibc_headers_install
1400 foreach_abi glibc_do_src_install
1402 if ! use static-libs ; then
1403 elog "Not installing static glibc libraries"
1404 find "${ED}" -name "*.a" -and -not -name "*_nonshared.a" -delete
1408 # Simple test to make sure our new glibc isn't completely broken.
1409 # Make sure we don't test with statically built binaries since
1410 # they will fail. Also, skip if this glibc is a cross compiler.
1412 # If coreutils is built with USE=multicall, some of these files
1413 # will just be wrapper scripts, not actual ELFs we can test.
1414 glibc_sanity_check() {
1417 # We enter ${ED} so to avoid trouble if the path contains
1418 # special characters; for instance if the path contains the
1419 # colon character (:), then the linker will try to split it
1420 # and look for the libraries in an unexpected place. This can
1421 # lead to unsafe code execution if the generated prefix is
1422 # within a world-writable directory.
1423 # (e.g. /var/tmp/portage:${HOSTNAME})
1424 pushd "${ED}"/$(get_libdir) >/dev/null
1427 for x in cal date env free ls true uname uptime ; do
1429 [[ -z ${x} || ${x} != ${EPREFIX}/* ]] && continue
1430 striptest=$(LC_ALL="C" file -L ${x} 2>/dev/null) || continue
1431 case ${striptest} in
1432 *"statically linked"*) continue;;
1433 *"ASCII text"*) continue;;
1435 # We need to clear the locale settings as the upgrade might want
1436 # incompatible locale data. This test is not for verifying that.
1438 ./ld-*.so --library-path . ${x} > /dev/null \
1439 || die "simple run test (${x}) failed"
1446 # nothing to do if just installing headers
1447 just_headers && return
1449 # prepare /etc/ld.so.conf.d/ for files
1450 mkdir -p "${EROOT}"/etc/ld.so.conf.d
1452 # Default /etc/hosts.conf:multi to on for systems with small dbs.
1453 if [[ $(wc -l < "${EROOT}"/etc/hosts) -lt 1000 ]] ; then
1454 sed -i '/^multi off/s:off:on:' "${ED}"/etc/host.conf
1455 einfo "Defaulting /etc/host.conf:multi to on"
1458 [[ -n ${ROOT} ]] && return 0
1459 [[ -d ${ED}/$(get_libdir) ]] || return 0
1460 [[ -z ${BOOTSTRAP_RAP} ]] && glibc_sanity_check
1464 # nothing to do if just installing headers
1465 just_headers && return
1467 if ! tc-is-cross-compiler && [[ -x ${EROOT}/usr/sbin/iconvconfig ]] ; then
1468 # Generate fastloading iconv module configuration file.
1469 "${EROOT}"/usr/sbin/iconvconfig --prefix="${ROOT}/"
1472 if ! is_crosscompile && [[ -z ${ROOT} ]] ; then
1473 use compile-locales || run_locale_gen "${EROOT}/"
1476 # Check for sanity of /etc/nsswitch.conf, take 2
1477 if [[ -e ${EROOT}/etc/nsswitch.conf ]] && ! has_version sys-auth/libnss-nis ; then
1479 for entry in passwd group shadow; do
1480 if egrep -q "^[ \t]*${entry}:.*nis" "${EROOT}"/etc/nsswitch.conf; then
1482 ewarn "Your ${EROOT}/etc/nsswitch.conf uses NIS. Support for that has been"
1483 ewarn "removed from glibc and is now provided by the package"
1484 ewarn " sys-auth/libnss-nis"
1485 ewarn "Install it now to keep your NIS setup working."