Diff glibc-2.19-r2 with a glibc-2.31-r7

/usr/portage/sys-libs/glibc/glibc-2.31-r7.ebuild 2023-10-09 14:52:35.544368503 +0300
1 1
# Copyright 1999-2023 Gentoo Authors
2 2
# Distributed under the terms of the GNU General Public License v2
3 3

  
4
EAPI=6
4
EAPI=7
5 5

  
6
PYTHON_COMPAT=( python3_{9..11} )
6 7
TMPFILES_OPTIONAL=1
7 8

  
8
inherit prefix toolchain-funcs flag-o-matic gnuconfig \
9
inherit python-any-r1 prefix toolchain-funcs flag-o-matic gnuconfig \
9 10
	multilib systemd multiprocessing tmpfiles
10 11

  
11 12
DESCRIPTION="GNU libc C library"
......
15 16

  
16 17
EMULTILIB_PKG="true"
17 18

  
19
# Gentoo patchset (ignored for live ebuilds)
20
PATCH_VER=9
21
PATCH_DEV=dilfridge
22

  
18 23
if [[ ${PV} == 9999* ]]; then
19
	EGIT_REPO_URI="https://sourceware.org/git/glibc.git"
20 24
	inherit git-r3
21 25
else
22
	KEYWORDS="~amd64"
26
	KEYWORDS="~alpha amd64 arm arm64 ~hppa ~ia64 ~m68k ~mips ppc ppc64 ~riscv ~s390 ~sparc x86"
23 27
	SRC_URI="mirror://gnu/glibc/${P}.tar.xz"
28
	SRC_URI+=" https://dev.gentoo.org/~${PATCH_DEV}/distfiles/${P}-patches-${PATCH_VER}.tar.xz"
24 29
fi
25 30

  
26 31
RELEASE_VER=${PV}
27 32

  
28
GCC_BOOTSTRAP_VER="4.7.3-r1"
33
GCC_BOOTSTRAP_VER=20180511
29 34

  
30
# Gentoo patchset
31
PATCH_VER=9
35
LOCALE_GEN_VER=2.00
32 36

  
33
SRC_URI+=" https://dev.gentoo.org/~dilfridge/distfiles/${P}-patches-${PATCH_VER}.tar.bz2"
34
SRC_URI+=" multilib? ( https://dev.gentoo.org/~dilfridge/distfiles/gcc-${GCC_BOOTSTRAP_VER}-multilib-bootstrap.tar.bz2 )"
37
SRC_URI+=" https://gitweb.gentoo.org/proj/locale-gen.git/snapshot/locale-gen-${LOCALE_GEN_VER}.tar.gz"
38
SRC_URI+=" multilib? ( https://dev.gentoo.org/~dilfridge/distfiles/gcc-multilib-bootstrap-${GCC_BOOTSTRAP_VER}.tar.xz )"
35 39

  
36
IUSE="audit caps compile-locales debug doc gd headers-only multilib nscd profile selinux suid systemtap vanilla"
40
IUSE="audit caps cet compile-locales +crypt custom-cflags doc gd headers-only +multiarch multilib nscd profile selinux +ssp +static-libs static-pie suid systemtap test vanilla"
37 41

  
38 42
# Minimum kernel version that glibc requires
39
# hppa requires 2.6.20
40
MIN_KERN_VER="2.6.16"
43
MIN_KERN_VER="3.2.0"
41 44

  
42 45
# Here's how the cross-compile logic breaks down ...
43 46
#  CTARGET - machine that will target the binaries
......
79 82
#   Thus our main goal here is to prevent 'libpthread.so.0' from
80 83
#   losing it's '.symtab' entries.
81 84
# As Gentoo's strip does not allow us to pass less aggressive stripping
82
# options and does not check the machine target we disable stripping
83
# entirely.
84
RESTRICT=strip
85
# options and does not check the machine target we strip selectively.
85 86

  
86 87
# We need a new-enough binutils/gcc to match upstream baseline.
87
# Also we need to make sure our binutils/gcc supports TLS.
88
# Also we need to make sure our binutils/gcc supports TLS,
89
# and that gcc already contains the hardened patches.
90
# Lastly, let's avoid some openssh nastiness, bug 708224, as
91
# convenience to our users.
92
BDEPEND="
93
	${PYTHON_DEPS}
94
	>=app-misc/pax-utils-0.1.10
95
	sys-devel/bison
96
	doc? ( sys-apps/texinfo )
97
"
88 98
COMMON_DEPEND="
99
	gd? ( media-libs/gd:2= )
89 100
	nscd? ( selinux? (
90 101
		audit? ( sys-process/audit )
91 102
		caps? ( sys-libs/libcap )
......
93 104
	suid? ( caps? ( sys-libs/libcap ) )
94 105
	selinux? ( sys-libs/libselinux )
95 106
	systemtap? ( dev-util/systemtap )
107
	!<net-misc/openssh-8.1_p1-r2
96 108
"
97 109
DEPEND="${COMMON_DEPEND}
98
	>=app-misc/pax-utils-0.1.10
99
	doc? ( sys-apps/texinfo )
110
	test? ( >=net-dns/libidn2-2.3.0 )
100 111
"
101 112
RDEPEND="${COMMON_DEPEND}
102 113
	sys-apps/gentoo-functions
103 114
"
104 115

  
116
RESTRICT="!test? ( test )"
117

  
105 118
if [[ ${CATEGORY} == cross-* ]] ; then
106
	DEPEND+=" !headers-only? (
119
	BDEPEND+=" !headers-only? (
107 120
		>=${CATEGORY}/binutils-2.24
108
		>=${CATEGORY}/gcc-4.9
121
		>=${CATEGORY}/gcc-6
109 122
	)"
110 123
	[[ ${CATEGORY} == *-linux* ]] && DEPEND+=" ${CATEGORY}/linux-headers"
111 124
else
112
	DEPEND+="
125
	BDEPEND+="
113 126
		>=sys-devel/binutils-2.24
114
		>=sys-devel/gcc-4.9
115
		virtual/os-headers
127
		>=sys-devel/gcc-6
128
	"
129
	DEPEND+=" virtual/os-headers "
130
	RDEPEND+="
131
		>=net-dns/libidn2-2.3.0
132
		vanilla? ( !sys-libs/timezone-data )
116 133
	"
117
	RDEPEND+=" vanilla? ( !sys-libs/timezone-data )"
118 134
	PDEPEND+=" !vanilla? ( sys-libs/timezone-data )"
119 135
fi
120 136

  
137
# Ignore tests whitelisted below
138
GENTOO_GLIBC_XFAIL_TESTS="${GENTOO_GLIBC_XFAIL_TESTS:-yes}"
139

  
140
# The following tests fail due to the Gentoo build system and are thus
141
# executed but ignored:
142
XFAIL_TEST_LIST=(
143
	# 9) Failures of unknown origin
144
	tst-latepthread
145

  
146
	# buggy test, assumes /dev/ and /dev/null on a single filesystem
147
	# 'mount --bind /dev/null /chroot/dev/null' breaks it.
148
	# https://sourceware.org/PR25909
149
	tst-support_descriptors
150

  
151
	# Flaky test, known to fail occasionally:
152
	# https://sourceware.org/PR19329
153
	# https://bugs.gentoo.org/719674#c12
154
	tst-stack4
155
)
156

  
121 157
#
122 158
# Small helper functions
123 159
#
......
134 170
	is_crosscompile && echo /usr/${CTARGET}
135 171
}
136 172

  
173
# This prefix is applicable to CHOST when building against this
174
# glibc. It is baked into the library at configure time.
175
host_eprefix() {
176
	is_crosscompile || echo "${EPREFIX}"
177
}
178

  
179
# This prefix is applicable to CBUILD when building against this
180
# glibc. It determines the destination path at install time.
181
build_eprefix() {
182
	is_crosscompile && echo "${EPREFIX}"
183
}
184

  
137 185
# We need to be able to set alternative headers for compiling for non-native
138 186
# platform. Will also become useful for testing kernel-headers without screwing
139 187
# up the whole system.
......
143 191

  
144 192
alt_build_headers() {
145 193
	if [[ -z ${ALT_BUILD_HEADERS} ]] ; then
146
		ALT_BUILD_HEADERS="${EPREFIX}$(alt_headers)"
194
		ALT_BUILD_HEADERS="$(host_eprefix)$(alt_headers)"
147 195
		if tc-is-cross-compiler ; then
148 196
			ALT_BUILD_HEADERS=${SYSROOT}$(alt_headers)
149 197
			if [[ ! -e ${ALT_BUILD_HEADERS}/linux/version.h ]] ; then
......
176 224
	rm -f glibc-test*
177 225
	printf '%b' "$*" > glibc-test.c
178 226

  
179
	nonfatal emake -s glibc-test
227
	# Most of the time CC is already set, but not in early sanity checks.
228
	nonfatal emake glibc-test CC="${CC-$(tc-getCC ${CTARGET})}"
180 229
	ret=$?
181 230

  
182 231
	popd >/dev/null
......
224 273
			# We could change main to _start and pass -nostdlib here so that we
225 274
			# only test the gcc code compilation.  Or we could do a compile and
226 275
			# then look for the symbol via scanelf.
227
			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' 2>/dev/null ; then
276
			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
228 277
				local t=${CTARGET_OPT:-${CTARGET}}
229 278
				t=${t%%-*}
230 279
				filter-flags '-march=*'
......
234 283
		;;
235 284
		amd64)
236 285
			# -march needed for #185404 #199334
237
			# Note: This test only matters when the x86 ABI is enabled, so we could
238
			# optimize a bit and elide it.
239 286
			# TODO: See cross-compile issues listed above for x86.
240
			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' 2>/dev/null ; then
287
			[[ ${ABI} == x86 ]] &&
288
			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
241 289
				local t=${CTARGET_OPT:-${CTARGET}}
242 290
				t=${t%%-*}
243 291
				# Normally the target is x86_64-xxx, so turn that into the -march that
......
247 295
				# ugly, ugly, ugly.  ugly.
248 296
				CFLAGS_x86=$(CFLAGS=${CFLAGS_x86} filter-flags '-march=*'; echo "${CFLAGS}")
249 297
				export CFLAGS_x86="${CFLAGS_x86} -march=${t}"
250
				einfo "Auto adding -march=${t} to CFLAGS_x86 #185404"
298
				einfo "Auto adding -march=${t} to CFLAGS_x86 #185404 (ABI=${ABI})"
251 299
			fi
252 300
		;;
253 301
		mips)
254 302
			# The mips abi cannot support the GNU style hashes. #233233
255 303
			filter-ldflags -Wl,--hash-style=gnu -Wl,--hash-style=both
256 304
		;;
305
		ppc|ppc64)
306
			# Many arch-specific implementations do not work on ppc with
307
			# cache-block not equal to 128 bytes. This breaks memset:
308
			#   https://sourceware.org/PR26522
309
			#   https://bugs.gentoo.org/737996
310
			# Use default -mcpu=. For ppc it means non-multiarch setup.
311
			filter-flags '-mcpu=*'
312
		;;
257 313
		sparc)
258 314
			# Both sparc and sparc64 can use -fcall-used-g6.  -g7 is bad, though.
259 315
			filter-flags "-fcall-used-g7"
260 316
			append-flags "-fcall-used-g6"
261 317

  
262
			# If the CHOST is the basic one (e.g. not sparcv9-xxx already),
263
			# try to pick a better one so glibc can use cpu-specific .S files.
264
			# We key off the CFLAGS to get a good value.  Also need to handle
265
			# version skew.
266
			# We can't force users to set their CHOST to their exact machine
267
			# as many of these are not recognized by config.sub/gcc and such :(.
268
			# Note: If the mcpu values don't scale, we might try probing CPP defines.
269
			# Note: Should we factor in -Wa,-AvXXX flags too ?  Or -mvis/etc... ?
270

  
271 318
			local cpu
272 319
			case ${CTARGET} in
273 320
			sparc64-*)
321
				cpu="sparc64"
274 322
				case $(get-flag mcpu) in
275
				niagara[234])
276
					cpu="sparc64v2"
277
					;;
278
				niagara)
279
					cpu="sparc64v"
280
					;;
281
				ultrasparc3)
282
					cpu="sparc64b"
283
					;;
284
				*)
323
				v9)
285 324
					# We need to force at least v9a because the base build doesn't
286 325
					# work with just v9.
287 326
					# https://sourceware.org/bugzilla/show_bug.cgi?id=19477
288
					[[ -z ${cpu} ]] && append-flags "-Wa,-xarch=v9a"
327
					append-flags "-Wa,-xarch=v9a"
289 328
					;;
290 329
				esac
291 330
				;;
292 331
			sparc-*)
293 332
				case $(get-flag mcpu) in
294
				niagara[234])
295
					cpu="sparcv9v2"
296
					;;
297
				niagara)
298
					cpu="sparcv9v"
299
					;;
300
				ultrasparc3)
301
					cpu="sparcv9b"
302
					;;
303
				v9|ultrasparc)
304
					cpu="sparcv9"
305
					;;
306 333
				v8|supersparc|hypersparc|leon|leon3)
307 334
					cpu="sparcv8"
308 335
					;;
336
				*)
337
					cpu="sparcv9"
338
					;;
309 339
				esac
310 340
			;;
311 341
			esac
......
329 359
	ASFLAGS_BASE=${ASFLAGS_BASE-${ASFLAGS}}
330 360
	ASFLAGS=${ASFLAGS_BASE}
331 361

  
332
	# Over-zealous CFLAGS can often cause problems.  What may work for one
333
	# person may not work for another.  To avoid a large influx of bugs
334
	# relating to failed builds, we strip most CFLAGS out to ensure as few
335
	# problems as possible.
336
	strip-flags
362
	# Allow users to explicitly avoid flag sanitization via
363
	# USE=custom-cflags.
364
	if ! use custom-cflags; then
365
		# Over-zealous CFLAGS can often cause problems.  What may work for one
366
		# person may not work for another.  To avoid a large influx of bugs
367
		# relating to failed builds, we strip most CFLAGS out to ensure as few
368
		# problems as possible.
369
		strip-flags
370
		# Lock glibc at -O2; we want to be conservative here.
371
		filter-flags '-O?'
372
		append-flags -O2
373
	fi
337 374
	strip-unsupported-flags
338 375
	filter-lto
339 376
	filter-flags -m32 -m64 '-mabi=*'
......
356 393
		CBUILD_OPT=${CTARGET_OPT}
357 394
	fi
358 395

  
359
	# Lock glibc at -O2; we want to be conservative here.
360
	# -fno-strict-aliasing is to work around #155906.
361
	filter-flags '-O?'
362
	append-flags -O2 -fno-strict-aliasing
396
	# glibc's headers disallow -O0 and fail at build time:
397
	#  include/libc-symbols.h:75:3: #error "glibc cannot be compiled without optimization"
398
	replace-flags -O0 -O1
363 399

  
364 400
	filter-flags '-fstack-protector*'
365
	append-flags '-fno-stack-protector'
366 401
}
367 402

  
368 403
want_tls() {
......
392 427
	return ${WANT__THREAD}
393 428
}
394 429

  
430
use_multiarch() {
431
	# Allow user to disable runtime arch detection in multilib.
432
	use multiarch || return 1
433
	# Make sure binutils is new enough to support indirect functions,
434
	# #336792. This funky sed supports gold and bfd linkers.
435
	local bver nver
436
	bver=$($(tc-getLD ${CTARGET}) -v | sed -n -r '1{s:[^0-9]*::;s:^([0-9.]*).*:\1:;p}')
437
	case $(tc-arch ${CTARGET}) in
438
	amd64|x86) nver="2.20" ;;
439
	arm)       nver="2.22" ;;
440
	hppa)      nver="2.23" ;;
441
	ppc|ppc64) nver="2.20" ;;
442
	# ifunc support was added in 2.23, but glibc also needs
443
	# machinemode which is in 2.24.
444
	s390)      nver="2.24" ;;
445
	sparc)     nver="2.21" ;;
446
	*)         return 1 ;;
447
	esac
448
	ver_test ${bver} -ge ${nver}
449
}
450

  
395 451
# Setup toolchain variables that had historically been defined in the
396 452
# profiles for these archs.
397 453
setup_env() {
......
412 468
		# and fall back on CFLAGS.
413 469
		local VAR=CFLAGS_${CTARGET//[-.]/_}
414 470
		CFLAGS=${!VAR-${CFLAGS}}
471
		einfo " $(printf '%15s' 'Manual CFLAGS:')   ${CFLAGS}"
415 472
	fi
416 473

  
417 474
	setup_flags
418 475

  
419 476
	export ABI=${ABI:-${DEFAULT_ABI:-default}}
420 477

  
478
	if just_headers ; then
479
		# Avoid mixing host's CC and target's CFLAGS_${ABI}:
480
		# At this bootstrap stage we have only binutils for
481
		# target but not compiler yet.
482
		einfo "Skip CC ABI injection. We can't use (cross-)compiler yet."
483
		return 0
484
	fi
421 485
	local VAR=CFLAGS_${ABI}
422 486
	# We need to export CFLAGS with abi information in them because glibc's
423 487
	# configure script checks CFLAGS for some targets (like mips).  Keep
424 488
	# around the original clean value to avoid appending multiple ABIs on
425 489
	# top of each other.
426
	: ${__GLIBC_CC:=$(tc-getCC ${CTARGET_OPT:-${CTARGET}})}
490
	: ${__GLIBC_CC:=$(tc-getCC ${CTARGET})}
427 491
	export __GLIBC_CC CC="${__GLIBC_CC} ${!VAR}"
492
	einfo " $(printf '%15s' 'Manual CC:')   ${CC}"
428 493
}
429 494

  
430 495
foreach_abi() {
......
453 518
	echo "${b}"
454 519
}
455 520

  
456
check_devpts() {
457
	# Make sure devpts is mounted correctly for use w/out setuid pt_chown.
458

  
459
	# If merely building the binary package, then there's nothing to verify.
460
	[[ ${MERGE_TYPE} == "buildonly" ]] && return
461

  
462
	# Only sanity check when installing the native glibc.
463
	[[ ${ROOT} != "/" ]] && return
464

  
465
	# If they're opting in to the old suid code, then no need to check.
466
	use suid && return
467

  
468
	if awk '$3 == "devpts" && $4 ~ /[, ]gid=5[, ]/ { exit 1 }' /proc/mounts ; then
469
		eerror "In order to use glibc with USE=-suid, you must make sure that"
470
		eerror "you have devpts mounted at /dev/pts with the gid=5 option."
471
		eerror "Openrc should do this for you, so you should check /etc/fstab"
472
		eerror "and make sure you do not have any invalid settings there."
473
		die "mount & fix your /dev/pts settings"
474
	fi
475
}
476

  
477 521
# The following Kernel version handling functions are mostly copied from portage
478 522
# source. It's better not to use linux-info.eclass here since a) it adds too
479 523
# much magic, see bug 326693 for some of the arguments, and b) some of the
......
535 579

  
536 580
get_kheader_version() {
537 581
	printf '#include <linux/version.h>\nLINUX_VERSION_CODE\n' | \
538
	$(tc-getCPP ${CTARGET}) -I "${EPREFIX}/$(alt_build_headers)" - | \
582
	$(tc-getCPP ${CTARGET}) -I "$(build_eprefix)$(alt_build_headers)" - | \
539 583
	tail -n 1
540 584
}
541 585

  
......
543 587
# pkg_ and src_ phases, so we call this function both in pkg_pretend and in
544 588
# src_unpack.
545 589
sanity_prechecks() {
546
	# Make sure devpts is mounted correctly for use w/out setuid pt_chown
547
	check_devpts
548

  
549 590
	# Prevent native builds from downgrading
550 591
	if [[ ${MERGE_TYPE} != "buildonly" ]] && \
551
	   [[ ${ROOT} == "/" ]] && \
592
	   [[ -z ${ROOT} ]] && \
552 593
	   [[ ${CBUILD} == ${CHOST} ]] && \
553 594
	   [[ ${CHOST} == ${CTARGET} ]] ; then
554 595

  
......
629 670

  
630 671
	# When we actually have to compile something...
631 672
	if ! just_headers ; then
632
		local run_kv build_kv want_kv
633

  
634
		run_kv=$(g_get_running_KV)
635
		build_kv=$(g_int_to_KV $(get_kheader_version))
636
		want_kv=${MIN_KERN_VER}
637

  
638 673
		ebegin "Checking gcc for __thread support"
639 674
		if ! eend $(want__thread ; echo $?) ; then
640 675
			echo
......
643 678
			die "No __thread support in gcc!"
644 679
		fi
645 680

  
646
		if ! is_crosscompile && ! tc-is-cross-compiler ; then
647
			# Building fails on an non-supporting kernel
648
			ebegin "Checking running kernel version (${run_kv} >= ${want_kv})"
649
			if ! eend_KV ${run_kv} ${want_kv} ; then
650
				echo
651
				eerror "You need a kernel of at least ${want_kv}!"
652
				die "Kernel version too low!"
681
		if [[ ${CTARGET} == *-linux* ]] ; then
682
			local run_kv build_kv want_kv
683

  
684
			run_kv=$(g_get_running_KV)
685
			build_kv=$(g_int_to_KV $(get_kheader_version))
686
			want_kv=${MIN_KERN_VER}
687

  
688
			if ! is_crosscompile && ! tc-is-cross-compiler ; then
689
				# Building fails on an non-supporting kernel
690
				ebegin "Checking running kernel version (${run_kv} >= ${want_kv})"
691
				if ! eend_KV ${run_kv} ${want_kv} ; then
692
					echo
693
					eerror "You need a kernel of at least ${want_kv}!"
694
					die "Kernel version too low!"
695
				fi
653 696
			fi
654
		fi
655 697

  
656
		ebegin "Checking linux-headers version (${build_kv} >= ${want_kv})"
657
		if ! eend_KV ${build_kv} ${want_kv} ; then
658
			echo
659
			eerror "You need linux-headers of at least ${want_kv}!"
660
			die "linux-headers version too low!"
698
			ebegin "Checking linux-headers version (${build_kv} >= ${want_kv})"
699
			if ! eend_KV ${build_kv} ${want_kv} ; then
700
				echo
701
				eerror "You need linux-headers of at least ${want_kv}!"
702
				die "linux-headers version too low!"
703
			fi
661 704
		fi
662 705
	fi
663 706
}
......
674 717
	sanity_prechecks
675 718
}
676 719

  
720
pkg_setup() {
721
	# see bug 682570
722
	[[ -z ${BOOTSTRAP_RAP} ]] && python-any-r1_pkg_setup
723
}
724

  
677 725
# src_unpack
678 726

  
679 727
src_unpack() {
680 728
	# Consistency is not guaranteed between pkg_ and src_ ...
681 729
	sanity_prechecks
682 730

  
683
	use multilib && unpack gcc-${GCC_BOOTSTRAP_VER}-multilib-bootstrap.tar.bz2
731
	use multilib && unpack gcc-multilib-bootstrap-${GCC_BOOTSTRAP_VER}.tar.xz
684 732

  
685 733
	setup_env
686 734

  
687
	if [[ -n ${EGIT_REPO_URI} ]] ; then
735
	if [[ ${PV} == 9999* ]] ; then
736
		EGIT_REPO_URI="https://anongit.gentoo.org/git/proj/toolchain/glibc-patches.git"
737
		EGIT_CHECKOUT_DIR=${WORKDIR}/patches-git
738
		git-r3_src_unpack
739
		mv patches-git/9999 patches || die
740

  
741
		EGIT_REPO_URI="https://sourceware.org/git/glibc.git"
742
		EGIT_CHECKOUT_DIR=${S}
688 743
		git-r3_src_unpack
689 744
	else
690 745
		unpack ${P}.tar.xz
691
	fi
692 746

  
693
	cd "${S}" || die
694
	touch locale/C-translit.h || die #185476 #218003
747
		cd "${WORKDIR}" || die
748
		unpack glibc-${RELEASE_VER}-patches-${PATCH_VER}.tar.xz
749
	fi
695 750

  
696 751
	cd "${WORKDIR}" || die
697
	unpack glibc-${RELEASE_VER}-patches-${PATCH_VER}.tar.bz2
752
	unpack locale-gen-${LOCALE_GEN_VER}.tar.gz
698 753
}
699 754

  
700 755
src_prepare() {
756
	local patchsetname
701 757
	if ! use vanilla ; then
702
		elog "Applying Gentoo Glibc Patchset ${RELEASE_VER}-${PATCH_VER}"
758
		if [[ ${PV} == 9999* ]] ; then
759
			patchsetname="from git master"
760
		else
761
			patchsetname="${RELEASE_VER}-${PATCH_VER}"
762
		fi
763
		elog "Applying Gentoo Glibc Patchset ${patchsetname}"
703 764
		eapply "${WORKDIR}"/patches
704 765
		einfo "Done."
705 766
	fi
706 767

  
707
	if just_headers ; then
708
		if [[ -e ports/sysdeps/mips/preconfigure ]] ; then
709
			# mips peeps like to screw with us.  if building headers,
710
			# we don't have a real compiler, so we can't let them
711
			# insert -mabi on us.
712
			sed -i '/CPPFLAGS=.*-mabi/s|.*|:|' ports/sysdeps/mips/preconfigure || die
713
			find ports/sysdeps/mips/ -name Makefile -exec sed -i '/^CC.*-mabi=/s:-mabi=.*:-D_MIPS_SZPTR=32:' {} +
714
		fi
715
	fi
716

  
717 768
	default
718 769

  
719 770
	gnuconfig_update
720 771

  
721
	eapply "${FILESDIR}"/2.19/glibc-2.19-kernel-2.6.16-compat.patch
722
	eapply "${FILESDIR}"/2.19/glibc-2.19-kernel-2.6.16-hide-pipe2.patch
723
	eapply "${FILESDIR}"/2.19/glibc-2.19-gcc-10.patch
724

  
725 772
	cd "${WORKDIR}"
726 773
	find . -name configure -exec touch {} +
727 774

  
775
	# move the external locale-gen to its old place
776
	mkdir extra || die
777
	mv locale-gen-${LOCALE_GEN_VER} extra/locale || die
778

  
728 779
	eprefixify extra/locale/locale-gen
729 780

  
730 781
	# Fix permissions on some of the scripts.
731 782
	chmod u+x "${S}"/scripts/*.sh
783

  
784
	cd "${S}"
732 785
}
733 786

  
734 787
glibc_do_configure() {
......
748 801
	fi
749 802

  
750 803
	local v
751
	for v in ABI CBUILD CHOST CTARGET CBUILD_OPT CTARGET_OPT CC CXX LD {AS,C,CPP,CXX,LD}FLAGS MAKEINFO ; do
804
	for v in ABI CBUILD CHOST CTARGET CBUILD_OPT CTARGET_OPT CC CXX LD {AS,C,CPP,CXX,LD}FLAGS MAKEINFO NM READELF; do
752 805
		einfo " $(printf '%15s' ${v}:)   ${!v}"
753 806
	done
754 807

  
808
	# CFLAGS can contain ABI-specific flags like -mfpu=neon, see bug #657760
809
	# To build .S (assembly) files with the same ABI-specific flags
810
	# upstream currently recommends adding CFLAGS to CC/CXX:
811
	#    https://sourceware.org/PR23273
812
	# Note: Passing CFLAGS via CPPFLAGS overrides glibc's arch-specific CFLAGS
813
	# and breaks multiarch support. See 659030#c3 for an example.
755 814
	# The glibc configure script doesn't properly use LDFLAGS all the time.
756
	export CC="$(tc-getCC ${CTARGET}) ${LDFLAGS}"
815
	export CC="$(tc-getCC ${CTARGET}) ${CFLAGS} ${LDFLAGS}"
757 816
	einfo " $(printf '%15s' 'Manual CC:')   ${CC}"
758 817

  
759 818
	# Some of the tests are written in C++, so we need to force our multlib abis in, bug 623548
760
	export CXX="$(tc-getCXX ${CTARGET}) $(get_abi_CFLAGS)"
819
	export CXX="$(tc-getCXX ${CTARGET}) $(get_abi_CFLAGS) ${CFLAGS}"
820

  
821
	if is_crosscompile; then
822
		# Assume worst-case bootstrap: glibc is buil first time
823
		# when ${CTARGET}-g++ is not available yet. We avoid
824
		# building auxiliary programs that require C++: bug #683074
825
		# It should not affect final result.
826
		export libc_cv_cxx_link_ok=no
827
		# The line above has the same effect. We set CXX explicitly
828
		# to make build logs less confusing.
829
		export CXX=
830
	fi
761 831
	einfo " $(printf '%15s' 'Manual CXX:')   ${CXX}"
762 832

  
833
	# Always use tuple-prefixed toolchain. For non-native ABI glibc's configure
834
	# can't detect them automatically due to ${CHOST} mismatch and fallbacks
835
	# to unprefixed tools. Similar to multilib.eclass:multilib_toolchain_setup().
836
	export NM="$(tc-getNM ${CTARGET})"
837
	export READELF="$(tc-getREADELF ${CTARGET})"
838
	einfo " $(printf '%15s' 'Manual NM:')   ${NM}"
839
	einfo " $(printf '%15s' 'Manual READELF:')   ${READELF}"
840

  
763 841
	echo
764 842

  
765 843
	local myconf=()
766 844

  
767 845
	case ${CTARGET} in
846
		m68k*)
847
			# setjmp() is not compatible with stack protection:
848
			# https://sourceware.org/PR24202
849
			myconf+=( --enable-stack-protector=no )
850
			;;
768 851
		powerpc-*)
769 852
			# Currently gcc on powerpc32 generates invalid code for
770 853
			# __builtin_return_address(0) calls. Normally programs
......
774 857
			myconf+=( --enable-stack-protector=no )
775 858
			;;
776 859
		*)
777
			myconf+=( --enable-stack-protector=all )
860
			# Use '=strong' instead of '=all' to protect only functions
861
			# worth protecting from stack smashes.
862
			# '=all' is also known to have a problem in IFUNC resolution
863
			# tests: https://sourceware.org/PR25680, bug #712356.
864
			myconf+=( --enable-stack-protector=$(usex ssp strong no) )
778 865
			;;
779 866
	esac
780 867
	myconf+=( --enable-stackguard-randomization )
......
790 877
		*) myconf+=( libc_cv_ld_gnu_indirect_function=no ) ;;
791 878
	esac
792 879

  
880
	# Enable Intel Control-flow Enforcement Technology on amd64 if requested
881
	case ${CTARGET} in
882
		x86_64-*) myconf+=( $(use_enable cet) ) ;;
883
		*) ;;
884
	esac
885

  
793 886
	[[ $(tc-is-softfloat) == "yes" ]] && myconf+=( --without-fp )
794 887

  
795 888
	myconf+=( --enable-kernel=${MIN_KERN_VER} )
......
828 921
		--host=${CTARGET_OPT:-${CTARGET}}
829 922
		$(use_enable profile)
830 923
		$(use_with gd)
831
		--with-headers=$(alt_build_headers)
832
		--prefix="${EPREFIX}/usr"
833
		--sysconfdir="${EPREFIX}/etc"
834
		--localstatedir="${EPREFIX}/var"
924
		--with-headers=$(build_eprefix)$(alt_build_headers)
925
		--prefix="$(host_eprefix)/usr"
926
		--sysconfdir="$(host_eprefix)/etc"
927
		--localstatedir="$(host_eprefix)/var"
835 928
		--libdir='$(prefix)'/$(get_libdir)
836 929
		--mandir='$(prefix)'/share/man
837 930
		--infodir='$(prefix)'/share/info
838 931
		--libexecdir='$(libdir)'/misc/glibc
839 932
		--with-bugurl=https://bugs.gentoo.org/
840 933
		--with-pkgversion="$(glibc_banner)"
934
		$(use_enable crypt)
935
		$(use_multiarch || echo --disable-multi-arch)
936
		$(use_enable static-pie)
841 937
		$(use_enable systemtap)
842 938
		$(use_enable nscd)
843 939
		${EXTRA_ECONF}
......
852 948

  
853 949
	# There is no configure option for this and we need to export it
854 950
	# since the glibc build will re-run configure on itself
855
	export libc_cv_rootsbindir="${EPREFIX}/sbin"
856
	export libc_cv_slibdir="${EPREFIX}/$(get_libdir)"
951
	export libc_cv_rootsbindir="$(host_eprefix)/sbin"
952
	export libc_cv_slibdir="$(host_eprefix)/$(get_libdir)"
857 953

  
858 954
	# We take care of patching our binutils to use both hash styles,
859 955
	# and many people like to force gnu hash style only, so disable
......
885 981
	if [[ -n ${GCC_BOOTSTRAP_VER} ]] && use multilib ; then
886 982
		echo 'main(){}' > "${T}"/test.c
887 983
		if ! $(tc-getCC ${CTARGET}) ${CFLAGS} ${LDFLAGS} "${T}"/test.c -Wl,-emain -lgcc 2>/dev/null ; then
888
			sed -i -e '/^CC = /s:$: -B$(objdir)/../'"gcc-${GCC_BOOTSTRAP_VER}/${ABI}:" config.make || die
984
			sed -i -e '/^CC = /s:$: -B$(objdir)/../'"gcc-multilib-bootstrap-${GCC_BOOTSTRAP_VER}/${ABI}:" config.make || die
889 985
		fi
890 986
	fi
891 987
}
......
906 1002
		libc_cv_asm_cfi_directives=yes
907 1003
		libc_cv_broken_visibility_attribute=no
908 1004
		libc_cv_c_cleanup=yes
1005
		libc_cv_compiler_powerpc64le_binary128_ok=yes
909 1006
		libc_cv_forced_unwind=yes
910 1007
		libc_cv_gcc___thread=yes
911 1008
		libc_cv_mlong_double_128=yes
......
913 1010
		libc_cv_ppc_machine=yes
914 1011
		libc_cv_ppc_rel16=yes
915 1012
		libc_cv_predef_fortify_source=no
1013
		libc_cv_target_power8_ok=yes
916 1014
		libc_cv_visibility_attribute=yes
917 1015
		libc_cv_z_combreloc=yes
918 1016
		libc_cv_z_execstack=yes
......
933 1031
		export ${v}
934 1032
	done
935 1033

  
1034
	local headers_only_arch_CPPFLAGS=()
1035

  
936 1036
	# Blow away some random CC settings that screw things up. #550192
937 1037
	if [[ -d ${S}/sysdeps/mips ]]; then
938 1038
		pushd "${S}"/sysdeps/mips >/dev/null
......
949 1049
		popd >/dev/null
950 1050
	fi
951 1051

  
1052
	case ${CTARGET} in
1053
	riscv*)
1054
		# RISC-V interrogates the compiler to determine which target to
1055
		# build.  If building the headers then we don't strictly need a
1056
		# RISC-V compiler, so the built-in definitions that are provided
1057
		# along with all RISC-V compiler might not exist.  This causes
1058
		# glibc's RISC-V preconfigure script to blow up.  Since we're just
1059
		# building the headers any value will actually work here, so just
1060
		# pick the standard one (rv64g/lp64d) to make the build scripts
1061
		# happy for now -- the headers are all the same anyway so it
1062
		# doesn't matter.
1063
		headers_only_arch_CPPFLAGS+=(
1064
			-D__riscv_xlen=64
1065
			-D__riscv_flen=64
1066
			-D__riscv_float_abi_double=1
1067
			-D__riscv_atomic=1
1068
		) ;;
1069
	esac
1070

  
952 1071
	local myconf=()
953 1072
	myconf+=(
954 1073
		--disable-sanity-checks
......
958 1077
		--enable-bind-now
959 1078
		--build=${CBUILD_OPT:-${CBUILD}}
960 1079
		--host=${CTARGET_OPT:-${CTARGET}}
961
		--with-headers=$(alt_build_headers)
962
		--prefix="${EPREFIX}/usr"
1080
		--with-headers=$(build_eprefix)$(alt_build_headers)
1081
		--prefix="$(host_eprefix)/usr"
963 1082
		${EXTRA_ECONF}
964 1083
	)
965 1084

  
966 1085
	# Nothing is compiled here which would affect the headers for the target.
967 1086
	# So forcing CC/CFLAGS is sane.
1087
	local headers_only_CC=$(tc-getBUILD_CC)
1088
	local headers_only_CFLAGS="-O1 -pipe"
1089
	local headers_only_CPPFLAGS="-U_FORTIFY_SOURCE ${headers_only_arch_CPPFLAGS[*]}"
1090
	local headers_only_LDFLAGS=""
968 1091
	set -- "${S}"/configure "${myconf[@]}"
969
	echo "$@"
970
	CC="$(tc-getBUILD_CC)" \
971
	CFLAGS="-O1 -pipe" \
972
	CPPFLAGS="-U_FORTIFY_SOURCE" \
1092
	echo \
1093
		"CC=${headers_only_CC}" \
1094
		"CFLAGS=${headers_only_CFLAGS}" \
1095
		"CPPFLAGS=${headers_only_CPPFLAGS}" \
1096
		"LDFLAGS=${headers_only_LDFLAGS}" \
1097
		"$@"
1098
	CC=${headers_only_CC} \
1099
	CFLAGS=${headers_only_CFLAGS} \
1100
	CPPFLAGS=${headers_only_CPPFLAGS} \
973 1101
	LDFLAGS="" \
974 1102
	"$@" || die "failed to configure glibc"
975 1103
}
......
1000 1128

  
1001 1129
glibc_src_test() {
1002 1130
	cd "$(builddir nptl)"
1003
	emake check
1131

  
1132
	local myxfailparams=""
1133
	if [[ "${GENTOO_GLIBC_XFAIL_TESTS}" == "yes" ]] ; then
1134
		for myt in ${XFAIL_TEST_LIST[@]} ; do
1135
			myxfailparams+="test-xfail-${myt}=yes "
1136
		done
1137
	fi
1138

  
1139
	# sandbox does not understand unshare() and prevents
1140
	# writes to /proc/, which makes many tests fail
1141

  
1142
	SANDBOX_ON=0 LD_PRELOAD= emake ${myxfailparams} check
1004 1143
}
1005 1144

  
1006 1145
do_src_test() {
......
1013 1152
}
1014 1153

  
1015 1154
src_test() {
1155
	if just_headers ; then
1156
		return
1157
	fi
1158

  
1016 1159
	# Give tests more time to complete.
1017 1160
	export TIMEOUTFACTOR=5
1018 1161

  
......
1022 1165
run_locale_gen() {
1023 1166
	# if the host locales.gen contains no entries, we'll install everything
1024 1167
	local root="$1"
1168
	local inplace=""
1169

  
1170
	if [[ "${root}" == "--inplace-glibc" ]] ; then
1171
		inplace="--inplace-glibc"
1172
		root="$2"
1173
	fi
1174

  
1025 1175
	local locale_list="${root}/etc/locale.gen"
1176

  
1177
	pushd "${ED}"/$(get_libdir) >/dev/null
1178

  
1026 1179
	if [[ -z $(locale-gen --list --config "${locale_list}") ]] ; then
1027
		ewarn "Generating all locales; edit /etc/locale.gen to save time/space"
1180
		[[ -z ${inplace} ]] && ewarn "Generating all locales; edit /etc/locale.gen to save time/space"
1028 1181
		locale_list="${root}/usr/share/i18n/SUPPORTED"
1029 1182
	fi
1030 1183

  
1031
	locale-gen --jobs $(makeopts_jobs) --config "${locale_list}" \
1184
	set -- locale-gen ${inplace} --jobs $(makeopts_jobs) --config "${locale_list}" \
1032 1185
		--destdir "${root}"
1186
	echo "$@"
1187
	"$@"
1188

  
1189
	popd >/dev/null
1033 1190
}
1034 1191

  
1035 1192
glibc_do_src_install() {
1036 1193
	local builddir=$(builddir nptl)
1037 1194
	cd "${builddir}"
1038 1195

  
1039
	emake install_root="${D}$(alt_prefix)" install
1196
	emake install_root="${D}/$(build_eprefix)$(alt_prefix)" install
1040 1197

  
1041 1198
	# This version (2.26) provides some compatibility libraries for the NIS/NIS+ support
1042 1199
	# which come without headers etc. Only needed for binary packages since the
......
1049 1206
	# '#define VERSION "2.26.90"' -> '2.26.90'
1050 1207
	local upstream_pv=$(sed -n -r 's/#define VERSION "(.*)"/\1/p' "${S}"/version.h)
1051 1208

  
1052
	if [[ -e ${ED}$(alt_usrlibdir)/libm-${upstream_pv}.a ]] ; then
1209
	# Avoid stripping binaries not targeted by ${CHOST}. Or else
1210
	# ${CHOST}-strip would break binaries build for ${CTARGET}.
1211
	is_crosscompile && dostrip -x /
1212
	# gdb thread introspection relies on local libpthreas symbols. stripping breaks it
1213
	# See Note [Disable automatic stripping]
1214
	dostrip -x $(alt_libdir)/libpthread-${upstream_pv}.so
1215

  
1216
	if [[ -e ${ED}/$(alt_usrlibdir)/libm-${upstream_pv}.a ]] ; then
1053 1217
		# Move versioned .a file out of libdir to evade portage QA checks
1054 1218
		# instead of using gen_usr_ldscript(). We fix ldscript as:
1055 1219
		# "GROUP ( /usr/lib64/libm-<pv>.a ..." -> "GROUP ( /usr/lib64/glibc-<pv>/libm-<pv>.a ..."
1056
		sed -i "s@\(libm-${upstream_pv}.a\)@${P}/\1@" "${ED}"$(alt_usrlibdir)/libm.a || die
1220
		sed -i "s@\(libm-${upstream_pv}.a\)@${P}/\1@" "${ED}"/$(alt_usrlibdir)/libm.a || die
1057 1221
		dodir $(alt_usrlibdir)/${P}
1058
		mv "${ED}"$(alt_usrlibdir)/libm-${upstream_pv}.a "${ED}"$(alt_usrlibdir)/${P}/libm-${upstream_pv}.a || die
1222
		mv "${ED}"/$(alt_usrlibdir)/libm-${upstream_pv}.a "${ED}"/$(alt_usrlibdir)/${P}/libm-${upstream_pv}.a || die
1059 1223
	fi
1060 1224

  
1061 1225
	# We'll take care of the cache ourselves
......
1079 1243
		n64     /lib64/ld.so.1
1080 1244
		# powerpc
1081 1245
		ppc     /lib/ld.so.1
1246
		# riscv
1247
		lp64d   /lib/ld-linux-riscv64-lp64d.so.1
1248
		lp64    /lib/ld-linux-riscv64-lp64.so.1
1082 1249
		# s390
1083 1250
		s390    /lib/ld.so.1
1084 1251
		s390x   /lib/ld64.so.1
......
1134 1301
		# gcc likes to use relative paths to get to its multilibs like
1135 1302
		# /usr/lib/../lib64/.  So while we don't install any files into
1136 1303
		# /usr/lib/, we do need it to exist.
1137
		cd "${ED}"$(alt_libdir)/..
1138
		[[ -e lib ]] || mkdir lib
1139
		cd "${ED}"$(alt_usrlibdir)/..
1140
		[[ -e lib ]] || mkdir lib
1304
		keepdir $(alt_prefix)/lib
1305
		keepdir $(alt_prefix)/usr/lib
1141 1306

  
1142 1307
		dosym usr/include $(alt_prefix)/sys-include
1143 1308
		return 0
......
1167 1332
		fi
1168 1333
	done
1169 1334

  
1335
	# HACK: If we're building for riscv, we need to additionally make sure that
1336
	# we can find the locale archive afterwards
1337
	case ${CTARGET} in
1338
		riscv*)
1339
			if [[ ! -e ${ED}/usr/lib/locale ]] ; then
1340
				dosym ../$(get_libdir)/locale /usr/lib/locale
1341
			fi
1342
			;;
1343
		*) ;;
1344
	esac
1345

  
1170 1346
	cd "${S}"
1171 1347

  
1172 1348
	# Install misc network config files
1173 1349
	insinto /etc
1174
	doins nscd/nscd.conf posix/gai.conf nss/nsswitch.conf
1175
	doins "${WORKDIR}"/extra/etc/*.conf
1350
	doins posix/gai.conf nss/nsswitch.conf
1351

  
1352
	# Gentoo-specific
1353
	newins "${FILESDIR}"/host.conf-1 host.conf
1176 1354

  
1177 1355
	if use nscd ; then
1178
		doinitd "$(prefixify_ro "${WORKDIR}"/extra/etc/nscd)"
1356
		doins nscd/nscd.conf
1357

  
1358
		newinitd "$(prefixify_ro "${FILESDIR}"/nscd-1)" nscd
1179 1359

  
1180 1360
		local nscd_args=(
1181 1361
			-e "s:@PIDFILE@:$(strings "${ED}"/usr/sbin/nscd | grep nscd.pid):"
......
1185 1365

  
1186 1366
		systemd_dounit nscd/nscd.service
1187 1367
		newtmpfiles nscd/nscd.tmpfiles nscd.conf
1188
	else
1189
		# Do this since extra/etc/*.conf above might have nscd.conf.
1190
		rm -f "${ED}"/etc/nscd.conf
1191 1368
	fi
1192 1369

  
1193 1370
	echo 'LDPATH="include ld.so.conf.d/*.conf"' > "${T}"/00glibc
......
1196 1373
	for d in BUGS ChangeLog CONFORMANCE FAQ NEWS NOTES PROJECTS README* ; do
1197 1374
		[[ -s ${d} ]] && dodoc ${d}
1198 1375
	done
1376
	dodoc -r ChangeLog.old
1199 1377

  
1200 1378
	# Prevent overwriting of the /etc/localtime symlink.  We'll handle the
1201 1379
	# creation of the "factory" symlink in pkg_postinst().
......
1203 1381

  
1204 1382
	# Generate all locales if this is a native build as locale generation
1205 1383
	if use compile-locales && ! is_crosscompile ; then
1206
		run_locale_gen "${ED}"
1384
		run_locale_gen --inplace-glibc "${ED}/"
1385
		sed -e 's:COMPILED_LOCALES="":COMPILED_LOCALES="1":' -i "${ED}"/usr/sbin/locale-gen || die
1207 1386
	fi
1208 1387
}
1209 1388

  
1210 1389
glibc_headers_install() {
1211 1390
	local builddir=$(builddir "headers")
1212 1391
	cd "${builddir}"
1213
	emake install_root="${D}$(alt_prefix)" install-headers
1392
	emake install_root="${D}/$(build_eprefix)$(alt_prefix)" install-headers
1214 1393

  
1215 1394
	insinto $(alt_headers)/gnu
1216 1395
	doins "${S}"/include/gnu/stubs.h
......
1229 1408
	fi
1230 1409

  
1231 1410
	foreach_abi glibc_do_src_install
1411

  
1412
	if ! use static-libs ; then
1413
		elog "Not installing static glibc libraries"
1414
		find "${ED}" -name "*.a" -and -not -name "*_nonshared.a" -delete
1415
	fi
1232 1416
}
1233 1417

  
1234 1418
# Simple test to make sure our new glibc isn't completely broken.
......
1281 1465
		einfo "Defaulting /etc/host.conf:multi to on"
1282 1466
	fi
1283 1467

  
1284
	[[ ${ROOT} != "/" ]] && return 0
1468
	[[ -n ${ROOT} ]] && return 0
1285 1469
	[[ -d ${ED}/$(get_libdir) ]] || return 0
1286 1470
	[[ -z ${BOOTSTRAP_RAP} ]] && glibc_sanity_check
1287 1471
}
......
1292 1476

  
1293 1477
	if ! tc-is-cross-compiler && [[ -x ${EROOT}/usr/sbin/iconvconfig ]] ; then
1294 1478
		# Generate fastloading iconv module configuration file.
1295
		"${EROOT}"/usr/sbin/iconvconfig --prefix="${ROOT}"
1479
		"${EROOT}"/usr/sbin/iconvconfig --prefix="${ROOT}/"
1296 1480
	fi
1297 1481

  
1298
	if ! is_crosscompile && [[ ${ROOT} == "/" ]] ; then
1299
		use compile-locales || run_locale_gen "${EROOT}"
1482
	if ! is_crosscompile && [[ -z ${ROOT} ]] ; then
1483
		use compile-locales || run_locale_gen "${EROOT}/"
1300 1484
	fi
1301 1485

  
1302 1486
	# Check for sanity of /etc/nsswitch.conf, take 2
Thank you!