Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
View | Details | Raw Unified | Return to bug 920753
Collapse All | Expand All

(-)a/sys-libs/glibc/glibc-2.37-r8.ebuild (+4 lines)
Lines 1-1680 Link Here
1
# Copyright 1999-2023 Gentoo Authors
1
# Copyright 1999-2023 Gentoo Authors
2
# Distributed under the terms of the GNU General Public License v2
2
# Distributed under the terms of the GNU General Public License v2
3
3
4
EAPI=8
4
EAPI=8
5
5
6
# Bumping notes: https://wiki.gentoo.org/wiki/Project:Toolchain/sys-libs/glibc
6
# Bumping notes: https://wiki.gentoo.org/wiki/Project:Toolchain/sys-libs/glibc
7
# Please read & adapt the page as necessary if obsolete.
7
# Please read & adapt the page as necessary if obsolete.
8
8
9
PYTHON_COMPAT=( python3_{9..11} )
9
PYTHON_COMPAT=( python3_{9..11} )
10
TMPFILES_OPTIONAL=1
10
TMPFILES_OPTIONAL=1
11
11
12
inherit python-any-r1 prefix preserve-libs toolchain-funcs flag-o-matic gnuconfig \
12
inherit python-any-r1 prefix preserve-libs toolchain-funcs flag-o-matic gnuconfig \
13
	multilib systemd multiprocessing tmpfiles
13
	multilib systemd multiprocessing tmpfiles
14
14
15
DESCRIPTION="GNU libc C library"
15
DESCRIPTION="GNU libc C library"
16
HOMEPAGE="https://www.gnu.org/software/libc/"
16
HOMEPAGE="https://www.gnu.org/software/libc/"
17
LICENSE="LGPL-2.1+ BSD HPND ISC inner-net rc PCRE"
17
LICENSE="LGPL-2.1+ BSD HPND ISC inner-net rc PCRE"
18
SLOT="2.2"
18
SLOT="2.2"
19
19
20
EMULTILIB_PKG="true"
20
EMULTILIB_PKG="true"
21
21
22
# Gentoo patchset (ignored for live ebuilds)
22
# Gentoo patchset (ignored for live ebuilds)
23
PATCH_VER=11
23
PATCH_VER=11
24
PATCH_DEV=dilfridge
24
PATCH_DEV=dilfridge
25
25
26
# gcc mulitilib bootstrap files version
26
# gcc mulitilib bootstrap files version
27
GCC_BOOTSTRAP_VER=20201208
27
GCC_BOOTSTRAP_VER=20201208
28
28
29
# systemd integration version
29
# systemd integration version
30
GLIBC_SYSTEMD_VER=20210729
30
GLIBC_SYSTEMD_VER=20210729
31
31
32
# Minimum kernel version that glibc requires
32
# Minimum kernel version that glibc requires
33
MIN_KERN_VER="3.2.0"
33
MIN_KERN_VER="3.2.0"
34
34
35
# Minimum pax-utils version needed (which contains any new syscall changes for
35
# Minimum pax-utils version needed (which contains any new syscall changes for
36
# its seccomp filter!). Please double check this!
36
# its seccomp filter!). Please double check this!
37
MIN_PAX_UTILS_VER="1.3.3"
37
MIN_PAX_UTILS_VER="1.3.3"
38
38
39
if [[ ${PV} == 9999* ]]; then
39
if [[ ${PV} == 9999* ]]; then
40
	inherit git-r3
40
	inherit git-r3
41
else
41
else
42
	KEYWORDS="~alpha ~amd64 ~arm ~arm64 ~hppa ~ia64 ~loong ~m68k ~mips ~ppc ~ppc64 ~riscv ~s390 ~sparc ~x86"
42
	KEYWORDS="~alpha ~amd64 ~arm ~arm64 ~hppa ~ia64 ~loong ~m68k ~mips ~ppc ~ppc64 ~riscv ~s390 ~sparc ~x86"
43
	SRC_URI="mirror://gnu/glibc/${P}.tar.xz"
43
	SRC_URI="mirror://gnu/glibc/${P}.tar.xz"
44
	SRC_URI+=" https://dev.gentoo.org/~${PATCH_DEV}/distfiles/${P}-patches-${PATCH_VER}.tar.xz"
44
	SRC_URI+=" https://dev.gentoo.org/~${PATCH_DEV}/distfiles/${P}-patches-${PATCH_VER}.tar.xz"
45
fi
45
fi
46
46
47
SRC_URI+=" multilib-bootstrap? ( https://dev.gentoo.org/~dilfridge/distfiles/gcc-multilib-bootstrap-${GCC_BOOTSTRAP_VER}.tar.xz )"
47
SRC_URI+=" multilib-bootstrap? ( https://dev.gentoo.org/~dilfridge/distfiles/gcc-multilib-bootstrap-${GCC_BOOTSTRAP_VER}.tar.xz )"
48
SRC_URI+=" systemd? ( https://gitweb.gentoo.org/proj/toolchain/glibc-systemd.git/snapshot/glibc-systemd-${GLIBC_SYSTEMD_VER}.tar.gz )"
48
SRC_URI+=" systemd? ( https://gitweb.gentoo.org/proj/toolchain/glibc-systemd.git/snapshot/glibc-systemd-${GLIBC_SYSTEMD_VER}.tar.gz )"
49
49
50
IUSE="audit caps cet compile-locales +crypt custom-cflags doc gd hash-sysv-compat headers-only +multiarch multilib multilib-bootstrap nscd perl profile selinux +ssp stack-realign +static-libs suid systemd systemtap test vanilla"
50
IUSE="audit caps cet compile-locales +crypt custom-cflags doc gd hash-sysv-compat headers-only +multiarch multilib multilib-bootstrap nscd perl profile selinux +ssp stack-realign +static-libs suid systemd systemtap test vanilla"
51
51
52
# Here's how the cross-compile logic breaks down ...
52
# Here's how the cross-compile logic breaks down ...
53
#  CTARGET - machine that will target the binaries
53
#  CTARGET - machine that will target the binaries
54
#  CHOST   - machine that will host the binaries
54
#  CHOST   - machine that will host the binaries
55
#  CBUILD  - machine that will build the binaries
55
#  CBUILD  - machine that will build the binaries
56
# If CTARGET != CHOST, it means you want a libc for cross-compiling.
56
# If CTARGET != CHOST, it means you want a libc for cross-compiling.
57
# If CHOST != CBUILD, it means you want to cross-compile the libc.
57
# If CHOST != CBUILD, it means you want to cross-compile the libc.
58
#  CBUILD = CHOST = CTARGET    - native build/install
58
#  CBUILD = CHOST = CTARGET    - native build/install
59
#  CBUILD != (CHOST = CTARGET) - cross-compile a native build
59
#  CBUILD != (CHOST = CTARGET) - cross-compile a native build
60
#  (CBUILD = CHOST) != CTARGET - libc for cross-compiler
60
#  (CBUILD = CHOST) != CTARGET - libc for cross-compiler
61
#  CBUILD != CHOST != CTARGET  - cross-compile a libc for a cross-compiler
61
#  CBUILD != CHOST != CTARGET  - cross-compile a libc for a cross-compiler
62
# For install paths:
62
# For install paths:
63
#  CHOST = CTARGET  - install into /
63
#  CHOST = CTARGET  - install into /
64
#  CHOST != CTARGET - install into /usr/CTARGET/
64
#  CHOST != CTARGET - install into /usr/CTARGET/
65
#
65
#
66
export CBUILD=${CBUILD:-${CHOST}}
66
export CBUILD=${CBUILD:-${CHOST}}
67
export CTARGET=${CTARGET:-${CHOST}}
67
export CTARGET=${CTARGET:-${CHOST}}
68
if [[ ${CTARGET} == ${CHOST} ]] ; then
68
if [[ ${CTARGET} == ${CHOST} ]] ; then
69
	if [[ ${CATEGORY} == cross-* ]] ; then
69
	if [[ ${CATEGORY} == cross-* ]] ; then
70
		export CTARGET=${CATEGORY#cross-}
70
		export CTARGET=${CATEGORY#cross-}
71
	fi
71
	fi
72
fi
72
fi
73
73
74
# Note [Disable automatic stripping]
74
# Note [Disable automatic stripping]
75
# Disabling automatic stripping for a few reasons:
75
# Disabling automatic stripping for a few reasons:
76
# - portage's attempt to strip breaks non-native binaries at least on
76
# - portage's attempt to strip breaks non-native binaries at least on
77
#   arm: bug #697428
77
#   arm: bug #697428
78
# - portage's attempt to strip libpthread.so.0 breaks gdb thread
78
# - portage's attempt to strip libpthread.so.0 breaks gdb thread
79
#   enumeration: bug #697910. This is quite subtle:
79
#   enumeration: bug #697910. This is quite subtle:
80
#   * gdb uses glibc's libthread_db-1.0.so to enumerate threads.
80
#   * gdb uses glibc's libthread_db-1.0.so to enumerate threads.
81
#   * libthread_db-1.0.so needs access to libpthread.so.0 local symbols
81
#   * libthread_db-1.0.so needs access to libpthread.so.0 local symbols
82
#     via 'ps_pglobal_lookup' symbol defined in gdb.
82
#     via 'ps_pglobal_lookup' symbol defined in gdb.
83
#   * 'ps_pglobal_lookup' uses '.symtab' section table to resolve all
83
#   * 'ps_pglobal_lookup' uses '.symtab' section table to resolve all
84
#     known symbols in 'libpthread.so.0'. Specifically 'nptl_version'
84
#     known symbols in 'libpthread.so.0'. Specifically 'nptl_version'
85
#     (unexported) is used to sanity check compatibility before enabling
85
#     (unexported) is used to sanity check compatibility before enabling
86
#     debugging.
86
#     debugging.
87
#     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
87
#     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
88
#   * normal 'strip' command trims '.symtab'
88
#   * normal 'strip' command trims '.symtab'
89
#   Thus our main goal here is to prevent 'libpthread.so.0' from
89
#   Thus our main goal here is to prevent 'libpthread.so.0' from
90
#   losing it's '.symtab' entries.
90
#   losing it's '.symtab' entries.
91
# - similarly, valgrind requires knowledge about symbols in ld.so:
92
#	bug #920753
91
# As Gentoo's strip does not allow us to pass less aggressive stripping
93
# As Gentoo's strip does not allow us to pass less aggressive stripping
92
# options and does not check the machine target we strip selectively.
94
# options and does not check the machine target we strip selectively.
93
95
94
# We need a new-enough binutils/gcc to match upstream baseline.
96
# We need a new-enough binutils/gcc to match upstream baseline.
95
# Also we need to make sure our binutils/gcc supports TLS,
97
# Also we need to make sure our binutils/gcc supports TLS,
96
# and that gcc already contains the hardened patches.
98
# and that gcc already contains the hardened patches.
97
# Lastly, let's avoid some openssh nastiness, bug 708224, as
99
# Lastly, let's avoid some openssh nastiness, bug 708224, as
98
# convenience to our users.
100
# convenience to our users.
99
101
100
IDEPEND="
102
IDEPEND="
101
	!compile-locales? ( sys-apps/locale-gen )
103
	!compile-locales? ( sys-apps/locale-gen )
102
"
104
"
103
BDEPEND="
105
BDEPEND="
104
	${PYTHON_DEPS}
106
	${PYTHON_DEPS}
105
	>=app-misc/pax-utils-${MIN_PAX_UTILS_VER}
107
	>=app-misc/pax-utils-${MIN_PAX_UTILS_VER}
106
	sys-devel/bison
108
	sys-devel/bison
107
	compile-locales? ( sys-apps/locale-gen )
109
	compile-locales? ( sys-apps/locale-gen )
108
	doc? (
110
	doc? (
109
		dev-lang/perl
111
		dev-lang/perl
110
		sys-apps/texinfo
112
		sys-apps/texinfo
111
	)
113
	)
112
	test? (
114
	test? (
113
		dev-lang/perl
115
		dev-lang/perl
114
		>=net-dns/libidn2-2.3.0
116
		>=net-dns/libidn2-2.3.0
115
	)
117
	)
116
"
118
"
117
COMMON_DEPEND="
119
COMMON_DEPEND="
118
	gd? ( media-libs/gd:2= )
120
	gd? ( media-libs/gd:2= )
119
	nscd? ( selinux? (
121
	nscd? ( selinux? (
120
		audit? ( sys-process/audit )
122
		audit? ( sys-process/audit )
121
		caps? ( sys-libs/libcap )
123
		caps? ( sys-libs/libcap )
122
	) )
124
	) )
123
	suid? ( caps? ( sys-libs/libcap ) )
125
	suid? ( caps? ( sys-libs/libcap ) )
124
	selinux? ( sys-libs/libselinux )
126
	selinux? ( sys-libs/libselinux )
125
	systemtap? ( dev-util/systemtap )
127
	systemtap? ( dev-util/systemtap )
126
"
128
"
127
DEPEND="${COMMON_DEPEND}
129
DEPEND="${COMMON_DEPEND}
128
"
130
"
129
RDEPEND="${COMMON_DEPEND}
131
RDEPEND="${COMMON_DEPEND}
130
	!<app-misc/pax-utils-${MIN_PAX_UTILS_VER}
132
	!<app-misc/pax-utils-${MIN_PAX_UTILS_VER}
131
	perl? ( dev-lang/perl )
133
	perl? ( dev-lang/perl )
132
"
134
"
133
135
134
RESTRICT="!test? ( test )"
136
RESTRICT="!test? ( test )"
135
137
136
if [[ ${CATEGORY} == cross-* ]] ; then
138
if [[ ${CATEGORY} == cross-* ]] ; then
137
	BDEPEND+=" !headers-only? (
139
	BDEPEND+=" !headers-only? (
138
		>=${CATEGORY}/binutils-2.27
140
		>=${CATEGORY}/binutils-2.27
139
		>=${CATEGORY}/gcc-6.2
141
		>=${CATEGORY}/gcc-6.2
140
	)"
142
	)"
141
	[[ ${CATEGORY} == *-linux* ]] && DEPEND+=" ${CATEGORY}/linux-headers"
143
	[[ ${CATEGORY} == *-linux* ]] && DEPEND+=" ${CATEGORY}/linux-headers"
142
else
144
else
143
	BDEPEND+="
145
	BDEPEND+="
144
		>=sys-devel/binutils-2.27
146
		>=sys-devel/binutils-2.27
145
		>=sys-devel/gcc-6.2
147
		>=sys-devel/gcc-6.2
146
	"
148
	"
147
	DEPEND+=" virtual/os-headers "
149
	DEPEND+=" virtual/os-headers "
148
	RDEPEND+="
150
	RDEPEND+="
149
		>=net-dns/libidn2-2.3.0
151
		>=net-dns/libidn2-2.3.0
150
		vanilla? ( !sys-libs/timezone-data )
152
		vanilla? ( !sys-libs/timezone-data )
151
	"
153
	"
152
	PDEPEND+=" !vanilla? ( sys-libs/timezone-data )"
154
	PDEPEND+=" !vanilla? ( sys-libs/timezone-data )"
153
fi
155
fi
154
156
155
# Ignore tests whitelisted below
157
# Ignore tests whitelisted below
156
GENTOO_GLIBC_XFAIL_TESTS="${GENTOO_GLIBC_XFAIL_TESTS:-yes}"
158
GENTOO_GLIBC_XFAIL_TESTS="${GENTOO_GLIBC_XFAIL_TESTS:-yes}"
157
159
158
# The following tests fail due to the Gentoo build system and are thus
160
# The following tests fail due to the Gentoo build system and are thus
159
# executed but ignored:
161
# executed but ignored:
160
XFAIL_TEST_LIST=(
162
XFAIL_TEST_LIST=(
161
	# buggy test, assumes /dev/ and /dev/null on a single filesystem
163
	# buggy test, assumes /dev/ and /dev/null on a single filesystem
162
	# 'mount --bind /dev/null /chroot/dev/null' breaks it.
164
	# 'mount --bind /dev/null /chroot/dev/null' breaks it.
163
	# https://sourceware.org/PR25909
165
	# https://sourceware.org/PR25909
164
	tst-support_descriptors
166
	tst-support_descriptors
165
167
166
	# The following tests fail only inside portage
168
	# The following tests fail only inside portage
167
	# https://bugs.gentoo.org/831267
169
	# https://bugs.gentoo.org/831267
168
	tst-system
170
	tst-system
169
	tst-strerror
171
	tst-strerror
170
	tst-strsignal
172
	tst-strsignal
171
)
173
)
172
174
173
XFAIL_NSPAWN_TEST_LIST=(
175
XFAIL_NSPAWN_TEST_LIST=(
174
	# These tests need to be adapted to handle EPERM/ENOSYS(?) properly
176
	# These tests need to be adapted to handle EPERM/ENOSYS(?) properly
175
	# upstream, as systemd-nspawn's default seccomp whitelist is too strict.
177
	# upstream, as systemd-nspawn's default seccomp whitelist is too strict.
176
	# https://sourceware.org/PR30603
178
	# https://sourceware.org/PR30603
177
	test-errno-linux
179
	test-errno-linux
178
	tst-bz21269
180
	tst-bz21269
179
	tst-mlock2
181
	tst-mlock2
180
	tst-ntp_gettime
182
	tst-ntp_gettime
181
	tst-ntp_gettime-time64
183
	tst-ntp_gettime-time64
182
	tst-ntp_gettimex
184
	tst-ntp_gettimex
183
	tst-ntp_gettimex-time64
185
	tst-ntp_gettimex-time64
184
	tst-pkey
186
	tst-pkey
185
	tst-process_mrelease
187
	tst-process_mrelease
186
	tst-adjtime
188
	tst-adjtime
187
	tst-adjtime-time64
189
	tst-adjtime-time64
188
	tst-clock2
190
	tst-clock2
189
	tst-clock2-time64
191
	tst-clock2-time64
190
192
191
	# These fail if --suppress-sync and/or low priority is set
193
	# These fail if --suppress-sync and/or low priority is set
192
	tst-sync_file_range
194
	tst-sync_file_range
193
	tst-sched1
195
	tst-sched1
194
	test-errno
196
	test-errno
195
)
197
)
196
198
197
#
199
#
198
# Small helper functions
200
# Small helper functions
199
#
201
#
200
202
201
dump_build_environment() {
203
dump_build_environment() {
202
	einfo ==== glibc build environment ========================================================
204
	einfo ==== glibc build environment ========================================================
203
	local v
205
	local v
204
	for v in ABI CBUILD CHOST CTARGET CBUILD_OPT CTARGET_OPT CC CXX CPP LD {AS,C,CPP,CXX,LD}FLAGS MAKEINFO NM AR AS STRIP RANLIB OBJCOPY STRINGS OBJDUMP READELF; do
206
	for v in ABI CBUILD CHOST CTARGET CBUILD_OPT CTARGET_OPT CC CXX CPP LD {AS,C,CPP,CXX,LD}FLAGS MAKEINFO NM AR AS STRIP RANLIB OBJCOPY STRINGS OBJDUMP READELF; do
205
		einfo " $(printf '%15s' ${v}:)   ${!v}"
207
		einfo " $(printf '%15s' ${v}:)   ${!v}"
206
	done
208
	done
207
	einfo =====================================================================================
209
	einfo =====================================================================================
208
}
210
}
209
211
210
is_crosscompile() {
212
is_crosscompile() {
211
	[[ ${CHOST} != ${CTARGET} ]]
213
	[[ ${CHOST} != ${CTARGET} ]]
212
}
214
}
213
215
214
just_headers() {
216
just_headers() {
215
	is_crosscompile && use headers-only
217
	is_crosscompile && use headers-only
216
}
218
}
217
219
218
alt_prefix() {
220
alt_prefix() {
219
	is_crosscompile && echo /usr/${CTARGET}
221
	is_crosscompile && echo /usr/${CTARGET}
220
}
222
}
221
223
222
# This prefix is applicable to CHOST when building against this
224
# This prefix is applicable to CHOST when building against this
223
# glibc. It is baked into the library at configure time.
225
# glibc. It is baked into the library at configure time.
224
host_eprefix() {
226
host_eprefix() {
225
	is_crosscompile || echo "${EPREFIX}"
227
	is_crosscompile || echo "${EPREFIX}"
226
}
228
}
227
229
228
# This prefix is applicable to CBUILD when building against this
230
# This prefix is applicable to CBUILD when building against this
229
# glibc. It determines the destination path at install time.
231
# glibc. It determines the destination path at install time.
230
build_eprefix() {
232
build_eprefix() {
231
	is_crosscompile && echo "${EPREFIX}"
233
	is_crosscompile && echo "${EPREFIX}"
232
}
234
}
233
235
234
# We need to be able to set alternative headers for compiling for non-native
236
# We need to be able to set alternative headers for compiling for non-native
235
# platform. Will also become useful for testing kernel-headers without screwing
237
# platform. Will also become useful for testing kernel-headers without screwing
236
# up the whole system.
238
# up the whole system.
237
alt_headers() {
239
alt_headers() {
238
	echo ${ALT_HEADERS:=$(alt_prefix)/usr/include}
240
	echo ${ALT_HEADERS:=$(alt_prefix)/usr/include}
239
}
241
}
240
242
241
alt_build_headers() {
243
alt_build_headers() {
242
	if [[ -z ${ALT_BUILD_HEADERS} ]] ; then
244
	if [[ -z ${ALT_BUILD_HEADERS} ]] ; then
243
		ALT_BUILD_HEADERS="$(host_eprefix)$(alt_headers)"
245
		ALT_BUILD_HEADERS="$(host_eprefix)$(alt_headers)"
244
		if tc-is-cross-compiler ; then
246
		if tc-is-cross-compiler ; then
245
			ALT_BUILD_HEADERS=${SYSROOT}$(alt_headers)
247
			ALT_BUILD_HEADERS=${SYSROOT}$(alt_headers)
246
			if [[ ! -e ${ALT_BUILD_HEADERS}/linux/version.h ]] ; then
248
			if [[ ! -e ${ALT_BUILD_HEADERS}/linux/version.h ]] ; then
247
				local header_path=$(echo '#include <linux/version.h>' | $(tc-getCPP ${CTARGET}) ${CFLAGS} 2>&1 | grep -o '[^"]*linux/version.h')
249
				local header_path=$(echo '#include <linux/version.h>' | $(tc-getCPP ${CTARGET}) ${CFLAGS} 2>&1 | grep -o '[^"]*linux/version.h')
248
				ALT_BUILD_HEADERS=${header_path%/linux/version.h}
250
				ALT_BUILD_HEADERS=${header_path%/linux/version.h}
249
			fi
251
			fi
250
		fi
252
		fi
251
	fi
253
	fi
252
	echo "${ALT_BUILD_HEADERS}"
254
	echo "${ALT_BUILD_HEADERS}"
253
}
255
}
254
256
255
alt_libdir() {
257
alt_libdir() {
256
	echo $(alt_prefix)/$(get_libdir)
258
	echo $(alt_prefix)/$(get_libdir)
257
}
259
}
258
alt_usrlibdir() {
260
alt_usrlibdir() {
259
	echo $(alt_prefix)/usr/$(get_libdir)
261
	echo $(alt_prefix)/usr/$(get_libdir)
260
}
262
}
261
263
262
builddir() {
264
builddir() {
263
	echo "${WORKDIR}/build-${ABI}-${CTARGET}-$1"
265
	echo "${WORKDIR}/build-${ABI}-${CTARGET}-$1"
264
}
266
}
265
267
266
do_compile_test() {
268
do_compile_test() {
267
	local ret save_cflags=${CFLAGS}
269
	local ret save_cflags=${CFLAGS}
268
	CFLAGS+=" $1"
270
	CFLAGS+=" $1"
269
	shift
271
	shift
270
272
271
	pushd "${T}" >/dev/null
273
	pushd "${T}" >/dev/null
272
274
273
	rm -f glibc-test*
275
	rm -f glibc-test*
274
	printf '%b' "$*" > glibc-test.c
276
	printf '%b' "$*" > glibc-test.c
275
277
276
	# We assume CC is already set up.
278
	# We assume CC is already set up.
277
	nonfatal emake glibc-test
279
	nonfatal emake glibc-test
278
	ret=$?
280
	ret=$?
279
281
280
	popd >/dev/null
282
	popd >/dev/null
281
283
282
	CFLAGS=${save_cflags}
284
	CFLAGS=${save_cflags}
283
	return ${ret}
285
	return ${ret}
284
}
286
}
285
287
286
do_run_test() {
288
do_run_test() {
287
	local ret
289
	local ret
288
290
289
	if [[ ${MERGE_TYPE} == "binary" ]] ; then
291
	if [[ ${MERGE_TYPE} == "binary" ]] ; then
290
		# ignore build failures when installing a binary package #324685
292
		# ignore build failures when installing a binary package #324685
291
		do_compile_test "" "$@" 2>/dev/null || return 0
293
		do_compile_test "" "$@" 2>/dev/null || return 0
292
	else
294
	else
293
		if ! do_compile_test "" "$@" ; then
295
		if ! do_compile_test "" "$@" ; then
294
			ewarn "Simple build failed ... assuming this is desired #324685"
296
			ewarn "Simple build failed ... assuming this is desired #324685"
295
			return 0
297
			return 0
296
		fi
298
		fi
297
	fi
299
	fi
298
300
299
	pushd "${T}" >/dev/null
301
	pushd "${T}" >/dev/null
300
302
301
	./glibc-test
303
	./glibc-test
302
	ret=$?
304
	ret=$?
303
	rm -f glibc-test*
305
	rm -f glibc-test*
304
306
305
	popd >/dev/null
307
	popd >/dev/null
306
308
307
	return ${ret}
309
	return ${ret}
308
}
310
}
309
311
310
setup_target_flags() {
312
setup_target_flags() {
311
	# This largely mucks with compiler flags.  None of which should matter
313
	# This largely mucks with compiler flags.  None of which should matter
312
	# when building up just the headers.
314
	# when building up just the headers.
313
	just_headers && return 0
315
	just_headers && return 0
314
316
315
	case $(tc-arch) in
317
	case $(tc-arch) in
316
		x86)
318
		x86)
317
			# -march needed for #185404 #199334
319
			# -march needed for #185404 #199334
318
			# TODO: When creating the first glibc cross-compile, this test will
320
			# TODO: When creating the first glibc cross-compile, this test will
319
			# always fail as it does a full link which in turn requires glibc.
321
			# always fail as it does a full link which in turn requires glibc.
320
			# Probably also applies when changing multilib profile settings (e.g.
322
			# Probably also applies when changing multilib profile settings (e.g.
321
			# enabling x86 when the profile was amd64-only previously).
323
			# enabling x86 when the profile was amd64-only previously).
322
			# We could change main to _start and pass -nostdlib here so that we
324
			# We could change main to _start and pass -nostdlib here so that we
323
			# only test the gcc code compilation.  Or we could do a compile and
325
			# only test the gcc code compilation.  Or we could do a compile and
324
			# then look for the symbol via scanelf.
326
			# then look for the symbol via scanelf.
325
			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
327
			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
326
				local t=${CTARGET_OPT:-${CTARGET}}
328
				local t=${CTARGET_OPT:-${CTARGET}}
327
				t=${t%%-*}
329
				t=${t%%-*}
328
				filter-flags '-march=*'
330
				filter-flags '-march=*'
329
				export CFLAGS="-march=${t} ${CFLAGS}"
331
				export CFLAGS="-march=${t} ${CFLAGS}"
330
				einfo "Auto adding -march=${t} to CFLAGS #185404"
332
				einfo "Auto adding -march=${t} to CFLAGS #185404"
331
			fi
333
			fi
332
			# For compatibility with older binaries at slight performance cost.
334
			# For compatibility with older binaries at slight performance cost.
333
			use stack-realign && export CFLAGS+=" -mstackrealign"
335
			use stack-realign && export CFLAGS+=" -mstackrealign"
334
		;;
336
		;;
335
		amd64)
337
		amd64)
336
			# -march needed for #185404 #199334
338
			# -march needed for #185404 #199334
337
			# TODO: See cross-compile issues listed above for x86.
339
			# TODO: See cross-compile issues listed above for x86.
338
			if [[ ${ABI} == x86 ]]; then
340
			if [[ ${ABI} == x86 ]]; then
339
				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
341
				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
340
					local t=${CTARGET_OPT:-${CTARGET}}
342
					local t=${CTARGET_OPT:-${CTARGET}}
341
					t=${t%%-*}
343
					t=${t%%-*}
342
					# Normally the target is x86_64-xxx, so turn that into the -march that
344
					# Normally the target is x86_64-xxx, so turn that into the -march that
343
					# gcc actually accepts. #528708
345
					# gcc actually accepts. #528708
344
					[[ ${t} == "x86_64" ]] && t="x86-64"
346
					[[ ${t} == "x86_64" ]] && t="x86-64"
345
					filter-flags '-march=*'
347
					filter-flags '-march=*'
346
					# ugly, ugly, ugly.  ugly.
348
					# ugly, ugly, ugly.  ugly.
347
					CFLAGS_x86=$(CFLAGS=${CFLAGS_x86} filter-flags '-march=*'; echo "${CFLAGS}")
349
					CFLAGS_x86=$(CFLAGS=${CFLAGS_x86} filter-flags '-march=*'; echo "${CFLAGS}")
348
					export CFLAGS_x86="${CFLAGS_x86} -march=${t}"
350
					export CFLAGS_x86="${CFLAGS_x86} -march=${t}"
349
					einfo "Auto adding -march=${t} to CFLAGS_x86 #185404 (ABI=${ABI})"
351
					einfo "Auto adding -march=${t} to CFLAGS_x86 #185404 (ABI=${ABI})"
350
				fi
352
				fi
351
				# For compatibility with older binaries at slight performance cost.
353
				# For compatibility with older binaries at slight performance cost.
352
				use stack-realign && export CFLAGS_x86+=" -mstackrealign"
354
				use stack-realign && export CFLAGS_x86+=" -mstackrealign"
353
355
354
				# Workaround for bug #823780.
356
				# Workaround for bug #823780.
355
				# Need to save/restore CC because earlier on, we stuff it full of CFLAGS, and tc-getCPP doesn't like that.
357
				# Need to save/restore CC because earlier on, we stuff it full of CFLAGS, and tc-getCPP doesn't like that.
356
				CC_mangled=${CC}
358
				CC_mangled=${CC}
357
				CC=${glibc__GLIBC_CC}
359
				CC=${glibc__GLIBC_CC}
358
				if tc-is-gcc && (($(gcc-major-version) == 11)) && (($(gcc-minor-version) <= 2)) && (($(gcc-micro-version) == 0)) ; then
360
				if tc-is-gcc && (($(gcc-major-version) == 11)) && (($(gcc-minor-version) <= 2)) && (($(gcc-micro-version) == 0)) ; then
359
					export CFLAGS_x86="${CFLAGS_x86} -mno-avx512f"
361
					export CFLAGS_x86="${CFLAGS_x86} -mno-avx512f"
360
					einfo "Auto adding -mno-avx512f to CFLAGS_x86 for buggy GCC version (bug #823780) (ABI=${ABI})"
362
					einfo "Auto adding -mno-avx512f to CFLAGS_x86 for buggy GCC version (bug #823780) (ABI=${ABI})"
361
				fi
363
				fi
362
				CC=${CC_mangled}
364
				CC=${CC_mangled}
363
			fi
365
			fi
364
		;;
366
		;;
365
		mips)
367
		mips)
366
			# The mips abi cannot support the GNU style hashes. #233233
368
			# The mips abi cannot support the GNU style hashes. #233233
367
			filter-ldflags -Wl,--hash-style=gnu -Wl,--hash-style=both
369
			filter-ldflags -Wl,--hash-style=gnu -Wl,--hash-style=both
368
		;;
370
		;;
369
		ppc|ppc64)
371
		ppc|ppc64)
370
			# Many arch-specific implementations do not work on ppc with
372
			# Many arch-specific implementations do not work on ppc with
371
			# cache-block not equal to 128 bytes. This breaks memset:
373
			# cache-block not equal to 128 bytes. This breaks memset:
372
			#   https://sourceware.org/PR26522
374
			#   https://sourceware.org/PR26522
373
			#   https://bugs.gentoo.org/737996
375
			#   https://bugs.gentoo.org/737996
374
			# Use default -mcpu=. For ppc it means non-multiarch setup.
376
			# Use default -mcpu=. For ppc it means non-multiarch setup.
375
			filter-flags '-mcpu=*'
377
			filter-flags '-mcpu=*'
376
		;;
378
		;;
377
		sparc)
379
		sparc)
378
			# Both sparc and sparc64 can use -fcall-used-g6.  -g7 is bad, though.
380
			# Both sparc and sparc64 can use -fcall-used-g6.  -g7 is bad, though.
379
			filter-flags "-fcall-used-g7"
381
			filter-flags "-fcall-used-g7"
380
			append-flags "-fcall-used-g6"
382
			append-flags "-fcall-used-g6"
381
383
382
			local cpu
384
			local cpu
383
			case ${CTARGET} in
385
			case ${CTARGET} in
384
			sparc64-*)
386
			sparc64-*)
385
				cpu="sparc64"
387
				cpu="sparc64"
386
				case $(get-flag mcpu) in
388
				case $(get-flag mcpu) in
387
				v9)
389
				v9)
388
					# We need to force at least v9a because the base build doesn't
390
					# We need to force at least v9a because the base build doesn't
389
					# work with just v9.
391
					# work with just v9.
390
					# https://sourceware.org/bugzilla/show_bug.cgi?id=19477
392
					# https://sourceware.org/bugzilla/show_bug.cgi?id=19477
391
					append-flags "-Wa,-xarch=v9a"
393
					append-flags "-Wa,-xarch=v9a"
392
					;;
394
					;;
393
				esac
395
				esac
394
				;;
396
				;;
395
			sparc-*)
397
			sparc-*)
396
				case $(get-flag mcpu) in
398
				case $(get-flag mcpu) in
397
				v8|supersparc|hypersparc|leon|leon3)
399
				v8|supersparc|hypersparc|leon|leon3)
398
					cpu="sparcv8"
400
					cpu="sparcv8"
399
					;;
401
					;;
400
				*)
402
				*)
401
					cpu="sparcv9"
403
					cpu="sparcv9"
402
					;;
404
					;;
403
				esac
405
				esac
404
			;;
406
			;;
405
			esac
407
			esac
406
			[[ -n ${cpu} ]] && CTARGET_OPT="${cpu}-${CTARGET#*-}"
408
			[[ -n ${cpu} ]] && CTARGET_OPT="${cpu}-${CTARGET#*-}"
407
		;;
409
		;;
408
	esac
410
	esac
409
}
411
}
410
412
411
setup_flags() {
413
setup_flags() {
412
	# Make sure host make.conf doesn't pollute us
414
	# Make sure host make.conf doesn't pollute us
413
	if is_crosscompile || tc-is-cross-compiler ; then
415
	if is_crosscompile || tc-is-cross-compiler ; then
414
		CHOST=${CTARGET} strip-unsupported-flags
416
		CHOST=${CTARGET} strip-unsupported-flags
415
	fi
417
	fi
416
418
417
	# Store our CFLAGS because it's changed depending on which CTARGET
419
	# Store our CFLAGS because it's changed depending on which CTARGET
418
	# we are building when pulling glibc on a multilib profile
420
	# we are building when pulling glibc on a multilib profile
419
	CFLAGS_BASE=${CFLAGS_BASE-${CFLAGS}}
421
	CFLAGS_BASE=${CFLAGS_BASE-${CFLAGS}}
420
	CFLAGS=${CFLAGS_BASE}
422
	CFLAGS=${CFLAGS_BASE}
421
	CXXFLAGS_BASE=${CXXFLAGS_BASE-${CXXFLAGS}}
423
	CXXFLAGS_BASE=${CXXFLAGS_BASE-${CXXFLAGS}}
422
	CXXFLAGS=${CXXFLAGS_BASE}
424
	CXXFLAGS=${CXXFLAGS_BASE}
423
	ASFLAGS_BASE=${ASFLAGS_BASE-${ASFLAGS}}
425
	ASFLAGS_BASE=${ASFLAGS_BASE-${ASFLAGS}}
424
	ASFLAGS=${ASFLAGS_BASE}
426
	ASFLAGS=${ASFLAGS_BASE}
425
427
426
	# Allow users to explicitly avoid flag sanitization via
428
	# Allow users to explicitly avoid flag sanitization via
427
	# USE=custom-cflags.
429
	# USE=custom-cflags.
428
	if ! use custom-cflags; then
430
	if ! use custom-cflags; then
429
		# Over-zealous CFLAGS can often cause problems.  What may work for one
431
		# Over-zealous CFLAGS can often cause problems.  What may work for one
430
		# person may not work for another.  To avoid a large influx of bugs
432
		# person may not work for another.  To avoid a large influx of bugs
431
		# relating to failed builds, we strip most CFLAGS out to ensure as few
433
		# relating to failed builds, we strip most CFLAGS out to ensure as few
432
		# problems as possible.
434
		# problems as possible.
433
		strip-flags
435
		strip-flags
434
		# Lock glibc at -O2; we want to be conservative here.
436
		# Lock glibc at -O2; we want to be conservative here.
435
		filter-flags '-O?'
437
		filter-flags '-O?'
436
		append-flags -O2
438
		append-flags -O2
437
	fi
439
	fi
438
440
439
	strip-unsupported-flags
441
	strip-unsupported-flags
440
	filter-lto
442
	filter-lto
441
	filter-flags -m32 -m64 '-mabi=*'
443
	filter-flags -m32 -m64 '-mabi=*'
442
444
443
	# glibc aborts if rpath is set by LDFLAGS
445
	# glibc aborts if rpath is set by LDFLAGS
444
	filter-ldflags '-Wl,-rpath=*'
446
	filter-ldflags '-Wl,-rpath=*'
445
447
446
	# ld can't use -r & --relax at the same time, bug #788901
448
	# ld can't use -r & --relax at the same time, bug #788901
447
	# https://sourceware.org/PR27837
449
	# https://sourceware.org/PR27837
448
	filter-ldflags '-Wl,--relax'
450
	filter-ldflags '-Wl,--relax'
449
451
450
	# some weird software relies on sysv hashes in glibc, bug 863863, bug 864100
452
	# some weird software relies on sysv hashes in glibc, bug 863863, bug 864100
451
	# we have to do that here already so mips can filter it out again :P
453
	# we have to do that here already so mips can filter it out again :P
452
	if use hash-sysv-compat ; then
454
	if use hash-sysv-compat ; then
453
		append-ldflags '-Wl,--hash-style=both'
455
		append-ldflags '-Wl,--hash-style=both'
454
	fi
456
	fi
455
457
456
	# #492892
458
	# #492892
457
	filter-flags -frecord-gcc-switches
459
	filter-flags -frecord-gcc-switches
458
460
459
	# #898098
461
	# #898098
460
	filter-flags -fno-builtin
462
	filter-flags -fno-builtin
461
463
462
	# #829583
464
	# #829583
463
	filter-lfs-flags
465
	filter-lfs-flags
464
466
465
	unset CBUILD_OPT CTARGET_OPT
467
	unset CBUILD_OPT CTARGET_OPT
466
	if use multilib ; then
468
	if use multilib ; then
467
		CTARGET_OPT=$(get_abi_CTARGET)
469
		CTARGET_OPT=$(get_abi_CTARGET)
468
		[[ -z ${CTARGET_OPT} ]] && CTARGET_OPT=$(get_abi_CHOST)
470
		[[ -z ${CTARGET_OPT} ]] && CTARGET_OPT=$(get_abi_CHOST)
469
	fi
471
	fi
470
472
471
	setup_target_flags
473
	setup_target_flags
472
474
473
	if [[ -n ${CTARGET_OPT} && ${CBUILD} == ${CHOST} ]] && ! is_crosscompile; then
475
	if [[ -n ${CTARGET_OPT} && ${CBUILD} == ${CHOST} ]] && ! is_crosscompile; then
474
		CBUILD_OPT=${CTARGET_OPT}
476
		CBUILD_OPT=${CTARGET_OPT}
475
	fi
477
	fi
476
478
477
	# glibc's headers disallow -O0 and fail at build time:
479
	# glibc's headers disallow -O0 and fail at build time:
478
	#  include/libc-symbols.h:75:3: #error "glibc cannot be compiled without optimization"
480
	#  include/libc-symbols.h:75:3: #error "glibc cannot be compiled without optimization"
479
	# https://sourceware.org/glibc/wiki/FAQ#Why_do_I_get:.60.23error_.22glibc_cannot_be_compiled_without_optimization.22.27.2C_when_trying_to_compile_GNU_libc_with_GNU_CC.3F
481
	# https://sourceware.org/glibc/wiki/FAQ#Why_do_I_get:.60.23error_.22glibc_cannot_be_compiled_without_optimization.22.27.2C_when_trying_to_compile_GNU_libc_with_GNU_CC.3F
480
	replace-flags -O0 -O1
482
	replace-flags -O0 -O1
481
483
482
	# glibc handles this internally already where it's appropriate;
484
	# glibc handles this internally already where it's appropriate;
483
	# can't always have SSP when we're the ones setting it up, etc
485
	# can't always have SSP when we're the ones setting it up, etc
484
	filter-flags '-fstack-protector*'
486
	filter-flags '-fstack-protector*'
485
487
486
	# Similar issues as with SSP. Can't inject yourself that early.
488
	# Similar issues as with SSP. Can't inject yourself that early.
487
	filter-flags '-fsanitize=*'
489
	filter-flags '-fsanitize=*'
488
490
489
	# See end of bug #830454; we handle this via USE=cet
491
	# See end of bug #830454; we handle this via USE=cet
490
	filter-flags '-fcf-protection=*'
492
	filter-flags '-fcf-protection=*'
491
493
492
	# When bootstrapping, we may have a situation where
494
	# When bootstrapping, we may have a situation where
493
	# CET-enabled gcc from seed is used to build CET-disabled
495
	# CET-enabled gcc from seed is used to build CET-disabled
494
	# glibc. As such, gcc implicitly enables CET if no
496
	# glibc. As such, gcc implicitly enables CET if no
495
	# -fcf-protection flag is passed. For a typical package it
497
	# -fcf-protection flag is passed. For a typical package it
496
	# should not be a problem, but for glibc it matters as it is
498
	# should not be a problem, but for glibc it matters as it is
497
	# dealing with CET in ld.so. So if CET is supposed to be
499
	# dealing with CET in ld.so. So if CET is supposed to be
498
	# disabled for glibc, be explicit about it.
500
	# disabled for glibc, be explicit about it.
499
	if (use amd64 || use x86) && ! use cet; then
501
	if (use amd64 || use x86) && ! use cet; then
500
		append-flags '-fcf-protection=none'
502
		append-flags '-fcf-protection=none'
501
	fi
503
	fi
502
}
504
}
503
505
504
use_multiarch() {
506
use_multiarch() {
505
	# Allow user to disable runtime arch detection in multilib.
507
	# Allow user to disable runtime arch detection in multilib.
506
	use multiarch || return 1
508
	use multiarch || return 1
507
	# Make sure binutils is new enough to support indirect functions,
509
	# Make sure binutils is new enough to support indirect functions,
508
	# #336792. This funky sed supports gold and bfd linkers.
510
	# #336792. This funky sed supports gold and bfd linkers.
509
	local bver nver
511
	local bver nver
510
	bver=$($(tc-getLD ${CTARGET}) -v | sed -n -r '1{s:[^0-9]*::;s:^([0-9.]*).*:\1:;p}')
512
	bver=$($(tc-getLD ${CTARGET}) -v | sed -n -r '1{s:[^0-9]*::;s:^([0-9.]*).*:\1:;p}')
511
	case $(tc-arch ${CTARGET}) in
513
	case $(tc-arch ${CTARGET}) in
512
	amd64|x86) nver="2.20" ;;
514
	amd64|x86) nver="2.20" ;;
513
	arm)       nver="2.22" ;;
515
	arm)       nver="2.22" ;;
514
	hppa)      nver="2.23" ;;
516
	hppa)      nver="2.23" ;;
515
	ppc|ppc64) nver="2.20" ;;
517
	ppc|ppc64) nver="2.20" ;;
516
	# ifunc support was added in 2.23, but glibc also needs
518
	# ifunc support was added in 2.23, but glibc also needs
517
	# machinemode which is in 2.24.
519
	# machinemode which is in 2.24.
518
	s390)      nver="2.24" ;;
520
	s390)      nver="2.24" ;;
519
	sparc)     nver="2.21" ;;
521
	sparc)     nver="2.21" ;;
520
	*)         return 1 ;;
522
	*)         return 1 ;;
521
	esac
523
	esac
522
	ver_test ${bver} -ge ${nver}
524
	ver_test ${bver} -ge ${nver}
523
}
525
}
524
526
525
# Setup toolchain variables that had historically been defined in the
527
# Setup toolchain variables that had historically been defined in the
526
# profiles for these archs.
528
# profiles for these archs.
527
setup_env() {
529
setup_env() {
528
	# silly users
530
	# silly users
529
	unset LD_RUN_PATH
531
	unset LD_RUN_PATH
530
	unset LD_ASSUME_KERNEL
532
	unset LD_ASSUME_KERNEL
531
533
532
	if is_crosscompile || tc-is-cross-compiler ; then
534
	if is_crosscompile || tc-is-cross-compiler ; then
533
		multilib_env ${CTARGET_OPT:-${CTARGET}}
535
		multilib_env ${CTARGET_OPT:-${CTARGET}}
534
536
535
		if ! use multilib ; then
537
		if ! use multilib ; then
536
			MULTILIB_ABIS=${DEFAULT_ABI}
538
			MULTILIB_ABIS=${DEFAULT_ABI}
537
		else
539
		else
538
			MULTILIB_ABIS=${MULTILIB_ABIS:-${DEFAULT_ABI}}
540
			MULTILIB_ABIS=${MULTILIB_ABIS:-${DEFAULT_ABI}}
539
		fi
541
		fi
540
542
541
		# If the user has CFLAGS_<CTARGET> in their make.conf, use that,
543
		# If the user has CFLAGS_<CTARGET> in their make.conf, use that,
542
		# and fall back on CFLAGS.
544
		# and fall back on CFLAGS.
543
		local VAR=CFLAGS_${CTARGET//[-.]/_}
545
		local VAR=CFLAGS_${CTARGET//[-.]/_}
544
		CFLAGS=${!VAR-${CFLAGS}}
546
		CFLAGS=${!VAR-${CFLAGS}}
545
		einfo " $(printf '%15s' 'Manual CFLAGS:')   ${CFLAGS}"
547
		einfo " $(printf '%15s' 'Manual CFLAGS:')   ${CFLAGS}"
546
	fi
548
	fi
547
549
548
	setup_flags
550
	setup_flags
549
551
550
	export ABI=${ABI:-${DEFAULT_ABI:-default}}
552
	export ABI=${ABI:-${DEFAULT_ABI:-default}}
551
553
552
	if just_headers ; then
554
	if just_headers ; then
553
		# Avoid mixing host's CC and target's CFLAGS_${ABI}:
555
		# Avoid mixing host's CC and target's CFLAGS_${ABI}:
554
		# At this bootstrap stage we have only binutils for
556
		# At this bootstrap stage we have only binutils for
555
		# target but not compiler yet.
557
		# target but not compiler yet.
556
		einfo "Skip CC ABI injection. We can't use (cross-)compiler yet."
558
		einfo "Skip CC ABI injection. We can't use (cross-)compiler yet."
557
		return 0
559
		return 0
558
	fi
560
	fi
559
561
560
	# Glibc does not work with gold (for various reasons) #269274.
562
	# Glibc does not work with gold (for various reasons) #269274.
561
	tc-ld-disable-gold
563
	tc-ld-disable-gold
562
564
563
	if use doc ; then
565
	if use doc ; then
564
		export MAKEINFO=makeinfo
566
		export MAKEINFO=makeinfo
565
	else
567
	else
566
		export MAKEINFO=/dev/null
568
		export MAKEINFO=/dev/null
567
	fi
569
	fi
568
570
569
	# Reset CC and CXX to the value at start of emerge
571
	# Reset CC and CXX to the value at start of emerge
570
	export CC=${glibc__ORIG_CC:-${CC:-$(tc-getCC ${CTARGET})}}
572
	export CC=${glibc__ORIG_CC:-${CC:-$(tc-getCC ${CTARGET})}}
571
	export CXX=${glibc__ORIG_CXX:-${CXX:-$(tc-getCXX ${CTARGET})}}
573
	export CXX=${glibc__ORIG_CXX:-${CXX:-$(tc-getCXX ${CTARGET})}}
572
574
573
	# and make sure glibc__ORIG_CC and glibc__ORIG_CXX is defined now.
575
	# and make sure glibc__ORIG_CC and glibc__ORIG_CXX is defined now.
574
	export glibc__ORIG_CC=${CC}
576
	export glibc__ORIG_CC=${CC}
575
	export glibc__ORIG_CXX=${CXX}
577
	export glibc__ORIG_CXX=${CXX}
576
578
577
	if tc-is-clang && ! use custom-cflags && ! is_crosscompile ; then
579
	if tc-is-clang && ! use custom-cflags && ! is_crosscompile ; then
578
		export glibc__force_gcc=yes
580
		export glibc__force_gcc=yes
579
		# once this is toggled on, it needs to stay on, since with CPP manipulated
581
		# once this is toggled on, it needs to stay on, since with CPP manipulated
580
		# tc-is-clang does not work correctly anymore...
582
		# tc-is-clang does not work correctly anymore...
581
	fi
583
	fi
582
584
583
	if [[ ${glibc__force_gcc} == "yes" ]] ; then
585
	if [[ ${glibc__force_gcc} == "yes" ]] ; then
584
		# If we are running in an otherwise clang/llvm environment, we need to
586
		# If we are running in an otherwise clang/llvm environment, we need to
585
		# recover the proper gcc and binutils settings here, at least until glibc
587
		# recover the proper gcc and binutils settings here, at least until glibc
586
		# is finally building with clang. So let's override everything that is
588
		# is finally building with clang. So let's override everything that is
587
		# set in the clang profiles.
589
		# set in the clang profiles.
588
		# Want to shoot yourself into the foot? Set USE=custom-cflags, that's always
590
		# Want to shoot yourself into the foot? Set USE=custom-cflags, that's always
589
		# a good start into that direction.
591
		# a good start into that direction.
590
		# Also, if you're crosscompiling, let's assume you know what you are doing.
592
		# Also, if you're crosscompiling, let's assume you know what you are doing.
591
		# Hopefully.
593
		# Hopefully.
592
		# Last, we need the settings of the *build* environment, not of the
594
		# Last, we need the settings of the *build* environment, not of the
593
		# target environment...
595
		# target environment...
594
596
595
		local current_binutils_path=$(env ROOT="${BROOT}" binutils-config -B)
597
		local current_binutils_path=$(env ROOT="${BROOT}" binutils-config -B)
596
		local current_gcc_path=$(env ROOT="${BROOT}" gcc-config -B)
598
		local current_gcc_path=$(env ROOT="${BROOT}" gcc-config -B)
597
		einfo "Overriding clang configuration, since it won't work here"
599
		einfo "Overriding clang configuration, since it won't work here"
598
600
599
		export CC="${current_gcc_path}/gcc"
601
		export CC="${current_gcc_path}/gcc"
600
		export CPP="${current_gcc_path}/cpp"
602
		export CPP="${current_gcc_path}/cpp"
601
		export CXX="${current_gcc_path}/g++"
603
		export CXX="${current_gcc_path}/g++"
602
		export LD="${current_binutils_path}/ld.bfd"
604
		export LD="${current_binutils_path}/ld.bfd"
603
		export AR="${current_binutils_path}/ar"
605
		export AR="${current_binutils_path}/ar"
604
		export AS="${current_binutils_path}/as"
606
		export AS="${current_binutils_path}/as"
605
		export NM="${current_binutils_path}/nm"
607
		export NM="${current_binutils_path}/nm"
606
		export STRIP="${current_binutils_path}/strip"
608
		export STRIP="${current_binutils_path}/strip"
607
		export RANLIB="${current_binutils_path}/ranlib"
609
		export RANLIB="${current_binutils_path}/ranlib"
608
		export OBJCOPY="${current_binutils_path}/objcopy"
610
		export OBJCOPY="${current_binutils_path}/objcopy"
609
		export STRINGS="${current_binutils_path}/strings"
611
		export STRINGS="${current_binutils_path}/strings"
610
		export OBJDUMP="${current_binutils_path}/objdump"
612
		export OBJDUMP="${current_binutils_path}/objdump"
611
		export READELF="${current_binutils_path}/readelf"
613
		export READELF="${current_binutils_path}/readelf"
612
		export ADDR2LINE="${current_binutils_path}/addr2line"
614
		export ADDR2LINE="${current_binutils_path}/addr2line"
613
615
614
		# do we need to also do flags munging here? yes! at least...
616
		# do we need to also do flags munging here? yes! at least...
615
		filter-flags '-fuse-ld=*'
617
		filter-flags '-fuse-ld=*'
616
		filter-flags '-D_FORTIFY_SOURCE=*'
618
		filter-flags '-D_FORTIFY_SOURCE=*'
617
619
618
	else
620
	else
619
621
620
		# this is the "normal" case
622
		# this is the "normal" case
621
623
622
		export CC="$(tc-getCC ${CTARGET})"
624
		export CC="$(tc-getCC ${CTARGET})"
623
		export CXX="$(tc-getCXX ${CTARGET})"
625
		export CXX="$(tc-getCXX ${CTARGET})"
624
626
625
		# Always use tuple-prefixed toolchain. For non-native ABI glibc's configure
627
		# Always use tuple-prefixed toolchain. For non-native ABI glibc's configure
626
		# can't detect them automatically due to ${CHOST} mismatch and fallbacks
628
		# can't detect them automatically due to ${CHOST} mismatch and fallbacks
627
		# to unprefixed tools. Similar to multilib.eclass:multilib_toolchain_setup().
629
		# to unprefixed tools. Similar to multilib.eclass:multilib_toolchain_setup().
628
		export NM="$(tc-getNM ${CTARGET})"
630
		export NM="$(tc-getNM ${CTARGET})"
629
		export READELF="$(tc-getREADELF ${CTARGET})"
631
		export READELF="$(tc-getREADELF ${CTARGET})"
630
632
631
	fi
633
	fi
632
634
633
	# We need to export CFLAGS with abi information in them because glibc's
635
	# We need to export CFLAGS with abi information in them because glibc's
634
	# configure script checks CFLAGS for some targets (like mips).  Keep
636
	# configure script checks CFLAGS for some targets (like mips).  Keep
635
	# around the original clean value to avoid appending multiple ABIs on
637
	# around the original clean value to avoid appending multiple ABIs on
636
	# top of each other. (Why does the comment talk about CFLAGS if the code
638
	# top of each other. (Why does the comment talk about CFLAGS if the code
637
	# acts on CC?)
639
	# acts on CC?)
638
	export glibc__GLIBC_CC=${CC}
640
	export glibc__GLIBC_CC=${CC}
639
	export glibc__GLIBC_CXX=${CXX}
641
	export glibc__GLIBC_CXX=${CXX}
640
642
641
	export glibc__abi_CFLAGS="$(get_abi_CFLAGS)"
643
	export glibc__abi_CFLAGS="$(get_abi_CFLAGS)"
642
644
643
	# CFLAGS can contain ABI-specific flags like -mfpu=neon, see bug #657760
645
	# CFLAGS can contain ABI-specific flags like -mfpu=neon, see bug #657760
644
	# To build .S (assembly) files with the same ABI-specific flags
646
	# To build .S (assembly) files with the same ABI-specific flags
645
	# upstream currently recommends adding CFLAGS to CC/CXX:
647
	# upstream currently recommends adding CFLAGS to CC/CXX:
646
	#    https://sourceware.org/PR23273
648
	#    https://sourceware.org/PR23273
647
	# Note: Passing CFLAGS via CPPFLAGS overrides glibc's arch-specific CFLAGS
649
	# Note: Passing CFLAGS via CPPFLAGS overrides glibc's arch-specific CFLAGS
648
	# and breaks multiarch support. See 659030#c3 for an example.
650
	# and breaks multiarch support. See 659030#c3 for an example.
649
	# The glibc configure script doesn't properly use LDFLAGS all the time.
651
	# The glibc configure script doesn't properly use LDFLAGS all the time.
650
	export CC="${glibc__GLIBC_CC} ${glibc__abi_CFLAGS} ${CFLAGS} ${LDFLAGS}"
652
	export CC="${glibc__GLIBC_CC} ${glibc__abi_CFLAGS} ${CFLAGS} ${LDFLAGS}"
651
653
652
	# Some of the tests are written in C++, so we need to force our multlib abis in, bug 623548
654
	# Some of the tests are written in C++, so we need to force our multlib abis in, bug 623548
653
	export CXX="${glibc__GLIBC_CXX} ${glibc__abi_CFLAGS} ${CFLAGS}"
655
	export CXX="${glibc__GLIBC_CXX} ${glibc__abi_CFLAGS} ${CFLAGS}"
654
656
655
	if is_crosscompile; then
657
	if is_crosscompile; then
656
		# Assume worst-case bootstrap: glibc is buil first time
658
		# Assume worst-case bootstrap: glibc is buil first time
657
		# when ${CTARGET}-g++ is not available yet. We avoid
659
		# when ${CTARGET}-g++ is not available yet. We avoid
658
		# building auxiliary programs that require C++: bug #683074
660
		# building auxiliary programs that require C++: bug #683074
659
		# It should not affect final result.
661
		# It should not affect final result.
660
		export libc_cv_cxx_link_ok=no
662
		export libc_cv_cxx_link_ok=no
661
		# The line above has the same effect. We set CXX explicitly
663
		# The line above has the same effect. We set CXX explicitly
662
		# to make build logs less confusing.
664
		# to make build logs less confusing.
663
		export CXX=
665
		export CXX=
664
	fi
666
	fi
665
}
667
}
666
668
667
foreach_abi() {
669
foreach_abi() {
668
	setup_env
670
	setup_env
669
671
670
	local ret=0
672
	local ret=0
671
	local abilist=""
673
	local abilist=""
672
	if use multilib ; then
674
	if use multilib ; then
673
		abilist=$(get_install_abis)
675
		abilist=$(get_install_abis)
674
	else
676
	else
675
		abilist=${DEFAULT_ABI}
677
		abilist=${DEFAULT_ABI}
676
	fi
678
	fi
677
	local -x ABI
679
	local -x ABI
678
	for ABI in ${abilist:-default} ; do
680
	for ABI in ${abilist:-default} ; do
679
		setup_env
681
		setup_env
680
		einfo "Running $1 for ABI ${ABI}"
682
		einfo "Running $1 for ABI ${ABI}"
681
		$1
683
		$1
682
		: $(( ret |= $? ))
684
		: $(( ret |= $? ))
683
	done
685
	done
684
	return ${ret}
686
	return ${ret}
685
}
687
}
686
688
687
glibc_banner() {
689
glibc_banner() {
688
	local b="Gentoo ${PVR}"
690
	local b="Gentoo ${PVR}"
689
	[[ -n ${PATCH_VER} ]] && ! use vanilla && b+=" (patchset ${PATCH_VER})"
691
	[[ -n ${PATCH_VER} ]] && ! use vanilla && b+=" (patchset ${PATCH_VER})"
690
	echo "${b}"
692
	echo "${b}"
691
}
693
}
692
694
693
# The following Kernel version handling functions are mostly copied from portage
695
# The following Kernel version handling functions are mostly copied from portage
694
# source. It's better not to use linux-info.eclass here since a) it adds too
696
# source. It's better not to use linux-info.eclass here since a) it adds too
695
# much magic, see bug 326693 for some of the arguments, and b) some of the
697
# much magic, see bug 326693 for some of the arguments, and b) some of the
696
# functions are just not provided.
698
# functions are just not provided.
697
699
698
g_get_running_KV() {
700
g_get_running_KV() {
699
	uname -r
701
	uname -r
700
	return $?
702
	return $?
701
}
703
}
702
704
703
g_KV_major() {
705
g_KV_major() {
704
	[[ -z $1 ]] && return 1
706
	[[ -z $1 ]] && return 1
705
	local KV=$@
707
	local KV=$@
706
	echo "${KV%%.*}"
708
	echo "${KV%%.*}"
707
}
709
}
708
710
709
g_KV_minor() {
711
g_KV_minor() {
710
	[[ -z $1 ]] && return 1
712
	[[ -z $1 ]] && return 1
711
	local KV=$@
713
	local KV=$@
712
	KV=${KV#*.}
714
	KV=${KV#*.}
713
	echo "${KV%%.*}"
715
	echo "${KV%%.*}"
714
}
716
}
715
717
716
g_KV_micro() {
718
g_KV_micro() {
717
	[[ -z $1 ]] && return 1
719
	[[ -z $1 ]] && return 1
718
	local KV=$@
720
	local KV=$@
719
	KV=${KV#*.*.}
721
	KV=${KV#*.*.}
720
	echo "${KV%%[^[:digit:]]*}"
722
	echo "${KV%%[^[:digit:]]*}"
721
}
723
}
722
724
723
g_KV_to_int() {
725
g_KV_to_int() {
724
	[[ -z $1 ]] && return 1
726
	[[ -z $1 ]] && return 1
725
	local KV_MAJOR=$(g_KV_major "$1")
727
	local KV_MAJOR=$(g_KV_major "$1")
726
	local KV_MINOR=$(g_KV_minor "$1")
728
	local KV_MINOR=$(g_KV_minor "$1")
727
	local KV_MICRO=$(g_KV_micro "$1")
729
	local KV_MICRO=$(g_KV_micro "$1")
728
	local KV_int=$(( KV_MAJOR * 65536 + KV_MINOR * 256 + KV_MICRO ))
730
	local KV_int=$(( KV_MAJOR * 65536 + KV_MINOR * 256 + KV_MICRO ))
729
731
730
	# We make version 2.2.0 the minimum version we will handle as
732
	# We make version 2.2.0 the minimum version we will handle as
731
	# a sanity check ... if its less, we fail ...
733
	# a sanity check ... if its less, we fail ...
732
	if [[ ${KV_int} -ge 131584 ]] ; then
734
	if [[ ${KV_int} -ge 131584 ]] ; then
733
		echo "${KV_int}"
735
		echo "${KV_int}"
734
		return 0
736
		return 0
735
	fi
737
	fi
736
	return 1
738
	return 1
737
}
739
}
738
740
739
g_int_to_KV() {
741
g_int_to_KV() {
740
	local version=$1 major minor micro
742
	local version=$1 major minor micro
741
	major=$((version / 65536))
743
	major=$((version / 65536))
742
	minor=$(((version % 65536) / 256))
744
	minor=$(((version % 65536) / 256))
743
	micro=$((version % 256))
745
	micro=$((version % 256))
744
	echo ${major}.${minor}.${micro}
746
	echo ${major}.${minor}.${micro}
745
}
747
}
746
748
747
eend_KV() {
749
eend_KV() {
748
	[[ $(g_KV_to_int $1) -ge $(g_KV_to_int $2) ]]
750
	[[ $(g_KV_to_int $1) -ge $(g_KV_to_int $2) ]]
749
	eend $?
751
	eend $?
750
}
752
}
751
753
752
get_kheader_version() {
754
get_kheader_version() {
753
	printf '#include <linux/version.h>\nLINUX_VERSION_CODE\n' | \
755
	printf '#include <linux/version.h>\nLINUX_VERSION_CODE\n' | \
754
	$(tc-getCPP ${CTARGET}) -I "$(build_eprefix)$(alt_build_headers)" - | \
756
	$(tc-getCPP ${CTARGET}) -I "$(build_eprefix)$(alt_build_headers)" - | \
755
	tail -n 1
757
	tail -n 1
756
}
758
}
757
759
758
# We collect all sanity checks here. Consistency is not guranteed between
760
# We collect all sanity checks here. Consistency is not guranteed between
759
# pkg_ and src_ phases, so we call this function both in pkg_pretend and in
761
# pkg_ and src_ phases, so we call this function both in pkg_pretend and in
760
# src_unpack.
762
# src_unpack.
761
sanity_prechecks() {
763
sanity_prechecks() {
762
	# Prevent native builds from downgrading
764
	# Prevent native builds from downgrading
763
	if [[ ${MERGE_TYPE} != "buildonly" ]] && \
765
	if [[ ${MERGE_TYPE} != "buildonly" ]] && \
764
	   [[ -z ${ROOT} ]] && \
766
	   [[ -z ${ROOT} ]] && \
765
	   [[ ${CBUILD} == ${CHOST} ]] && \
767
	   [[ ${CBUILD} == ${CHOST} ]] && \
766
	   [[ ${CHOST} == ${CTARGET} ]] ; then
768
	   [[ ${CHOST} == ${CTARGET} ]] ; then
767
769
768
		# The high rev # is to allow people to downgrade between -r#
770
		# The high rev # is to allow people to downgrade between -r#
769
		# versions. We want to block 2.20->2.19, but 2.20-r3->2.20-r2
771
		# versions. We want to block 2.20->2.19, but 2.20-r3->2.20-r2
770
		# should be fine. Hopefully we never actually use a r# this
772
		# should be fine. Hopefully we never actually use a r# this
771
		# high.
773
		# high.
772
		if has_version ">${CATEGORY}/${P}-r10000" ; then
774
		if has_version ">${CATEGORY}/${P}-r10000" ; then
773
			eerror "Sanity check to keep you from breaking your system:"
775
			eerror "Sanity check to keep you from breaking your system:"
774
			eerror " Downgrading glibc is not supported and a sure way to destruction."
776
			eerror " Downgrading glibc is not supported and a sure way to destruction."
775
			[[ ${I_ALLOW_TO_BREAK_MY_SYSTEM} = yes ]] || die "Aborting to save your system."
777
			[[ ${I_ALLOW_TO_BREAK_MY_SYSTEM} = yes ]] || die "Aborting to save your system."
776
		fi
778
		fi
777
779
778
		if ! do_run_test '#include <unistd.h>\n#include <sys/syscall.h>\nint main(){return syscall(1000)!=-1;}\n' ; then
780
		if ! do_run_test '#include <unistd.h>\n#include <sys/syscall.h>\nint main(){return syscall(1000)!=-1;}\n' ; then
779
			eerror "Your old kernel is broken. You need to update it to a newer"
781
			eerror "Your old kernel is broken. You need to update it to a newer"
780
			eerror "version as syscall(<bignum>) will break. See bug 279260."
782
			eerror "version as syscall(<bignum>) will break. See bug 279260."
781
			die "Old and broken kernel."
783
			die "Old and broken kernel."
782
		fi
784
		fi
783
	fi
785
	fi
784
786
785
	if [[ ${CTARGET} == i386-* ]] ; then
787
	if [[ ${CTARGET} == i386-* ]] ; then
786
		eerror "i386 CHOSTs are no longer supported."
788
		eerror "i386 CHOSTs are no longer supported."
787
		eerror "Chances are you don't actually want/need i386."
789
		eerror "Chances are you don't actually want/need i386."
788
		eerror "Please read https://www.gentoo.org/doc/en/change-chost.xml"
790
		eerror "Please read https://www.gentoo.org/doc/en/change-chost.xml"
789
		die "Please fix your CHOST"
791
		die "Please fix your CHOST"
790
	fi
792
	fi
791
793
792
	if [[ -e /proc/xen ]] && [[ $(tc-arch) == "x86" ]] && ! is-flag -mno-tls-direct-seg-refs ; then
794
	if [[ -e /proc/xen ]] && [[ $(tc-arch) == "x86" ]] && ! is-flag -mno-tls-direct-seg-refs ; then
793
		ewarn "You are using Xen but don't have -mno-tls-direct-seg-refs in your CFLAGS."
795
		ewarn "You are using Xen but don't have -mno-tls-direct-seg-refs in your CFLAGS."
794
		ewarn "This will result in a 50% performance penalty when running with a 32bit"
796
		ewarn "This will result in a 50% performance penalty when running with a 32bit"
795
		ewarn "hypervisor, which is probably not what you want."
797
		ewarn "hypervisor, which is probably not what you want."
796
	fi
798
	fi
797
799
798
	# ABI-specific checks follow here. Hey, we have a lot more specific conditions that
800
	# ABI-specific checks follow here. Hey, we have a lot more specific conditions that
799
	# we test for...
801
	# we test for...
800
	if ! is_crosscompile ; then
802
	if ! is_crosscompile ; then
801
		if use amd64 && use multilib && [[ ${MERGE_TYPE} != "binary" ]] ; then
803
		if use amd64 && use multilib && [[ ${MERGE_TYPE} != "binary" ]] ; then
802
			ebegin "Checking that IA32 emulation is enabled in the running kernel"
804
			ebegin "Checking that IA32 emulation is enabled in the running kernel"
803
			echo 'int main(){return 0;}' > "${T}/check-ia32-emulation.c"
805
			echo 'int main(){return 0;}' > "${T}/check-ia32-emulation.c"
804
			local STAT
806
			local STAT
805
			if ${CC-${CHOST}-gcc} ${CFLAGS_x86} "${T}/check-ia32-emulation.c" -o "${T}/check-ia32-emulation.elf32"; then
807
			if ${CC-${CHOST}-gcc} ${CFLAGS_x86} "${T}/check-ia32-emulation.c" -o "${T}/check-ia32-emulation.elf32"; then
806
				"${T}/check-ia32-emulation.elf32"
808
				"${T}/check-ia32-emulation.elf32"
807
				STAT=$?
809
				STAT=$?
808
			else
810
			else
809
				# Don't fail here to allow single->multi ABI switch
811
				# Don't fail here to allow single->multi ABI switch
810
				# or recover from breakage like bug #646424
812
				# or recover from breakage like bug #646424
811
				ewarn "Failed to compile the ABI test. Broken host glibc?"
813
				ewarn "Failed to compile the ABI test. Broken host glibc?"
812
				STAT=0
814
				STAT=0
813
			fi
815
			fi
814
			rm -f "${T}/check-ia32-emulation.elf32"
816
			rm -f "${T}/check-ia32-emulation.elf32"
815
			eend $STAT
817
			eend $STAT
816
			[[ $STAT -eq 0 ]] || die "CONFIG_IA32_EMULATION must be enabled in the kernel to compile a multilib glibc."
818
			[[ $STAT -eq 0 ]] || die "CONFIG_IA32_EMULATION must be enabled in the kernel to compile a multilib glibc."
817
		fi
819
		fi
818
820
819
	fi
821
	fi
820
822
821
	# When we actually have to compile something...
823
	# When we actually have to compile something...
822
	if ! just_headers && [[ ${MERGE_TYPE} != "binary" ]] ; then
824
	if ! just_headers && [[ ${MERGE_TYPE} != "binary" ]] ; then
823
		if [[ -d "${ESYSROOT}"/usr/lib/include ]] ; then
825
		if [[ -d "${ESYSROOT}"/usr/lib/include ]] ; then
824
			# bug #833620, bug #643302
826
			# bug #833620, bug #643302
825
			eerror "Found ${ESYSROOT}/usr/lib/include directory!"
827
			eerror "Found ${ESYSROOT}/usr/lib/include directory!"
826
			eerror "This is known to break glibc's build."
828
			eerror "This is known to break glibc's build."
827
			eerror "Please backup its contents then remove the directory."
829
			eerror "Please backup its contents then remove the directory."
828
			die "Found directory (${ESYSROOT}/usr/lib/include) which will break build (bug #833620)!"
830
			die "Found directory (${ESYSROOT}/usr/lib/include) which will break build (bug #833620)!"
829
		fi
831
		fi
830
832
831
		if [[ ${CTARGET} == *-linux* ]] ; then
833
		if [[ ${CTARGET} == *-linux* ]] ; then
832
			local run_kv build_kv want_kv
834
			local run_kv build_kv want_kv
833
835
834
			run_kv=$(g_get_running_KV)
836
			run_kv=$(g_get_running_KV)
835
			build_kv=$(g_int_to_KV $(get_kheader_version))
837
			build_kv=$(g_int_to_KV $(get_kheader_version))
836
			want_kv=${MIN_KERN_VER}
838
			want_kv=${MIN_KERN_VER}
837
839
838
			if ! is_crosscompile && ! tc-is-cross-compiler ; then
840
			if ! is_crosscompile && ! tc-is-cross-compiler ; then
839
				# Building fails on an non-supporting kernel
841
				# Building fails on an non-supporting kernel
840
				ebegin "Checking running kernel version (${run_kv} >= ${want_kv})"
842
				ebegin "Checking running kernel version (${run_kv} >= ${want_kv})"
841
				if ! eend_KV ${run_kv} ${want_kv} ; then
843
				if ! eend_KV ${run_kv} ${want_kv} ; then
842
					echo
844
					echo
843
					eerror "You need a kernel of at least ${want_kv}!"
845
					eerror "You need a kernel of at least ${want_kv}!"
844
					die "Kernel version too low!"
846
					die "Kernel version too low!"
845
				fi
847
				fi
846
			fi
848
			fi
847
849
848
			# Do not run this check for pkg_pretend, just pkg_setup and friends (if we ever get used there).
850
			# Do not run this check for pkg_pretend, just pkg_setup and friends (if we ever get used there).
849
			# It's plausible (seen it in the wild) that Portage will (correctly) schedule a linux-headers
851
			# It's plausible (seen it in the wild) that Portage will (correctly) schedule a linux-headers
850
			# upgrade before glibc, but because pkg_pretend gets run before any packages are merged at all (not
852
			# upgrade before glibc, but because pkg_pretend gets run before any packages are merged at all (not
851
			# just glibc), the whole emerge gets aborted without a good reason. We probably don't
853
			# just glibc), the whole emerge gets aborted without a good reason. We probably don't
852
			# need to run this check at all given we have a dependency on the right headers,
854
			# need to run this check at all given we have a dependency on the right headers,
853
			# but let's leave it as-is for now.
855
			# but let's leave it as-is for now.
854
			if [[ ${EBUILD_PHASE_FUNC} != pkg_pretend ]] ; then
856
			if [[ ${EBUILD_PHASE_FUNC} != pkg_pretend ]] ; then
855
				ebegin "Checking linux-headers version (${build_kv} >= ${want_kv})"
857
				ebegin "Checking linux-headers version (${build_kv} >= ${want_kv})"
856
				if ! eend_KV ${build_kv} ${want_kv} ; then
858
				if ! eend_KV ${build_kv} ${want_kv} ; then
857
					echo
859
					echo
858
					eerror "You need linux-headers of at least ${want_kv}!"
860
					eerror "You need linux-headers of at least ${want_kv}!"
859
					die "linux-headers version too low!"
861
					die "linux-headers version too low!"
860
				fi
862
				fi
861
			fi
863
			fi
862
		fi
864
		fi
863
	fi
865
	fi
864
}
866
}
865
867
866
upgrade_warning() {
868
upgrade_warning() {
867
	is_crosscompile && return
869
	is_crosscompile && return
868
870
869
	if [[ ${MERGE_TYPE} != buildonly && -n ${REPLACING_VERSIONS} && -z ${ROOT} ]]; then
871
	if [[ ${MERGE_TYPE} != buildonly && -n ${REPLACING_VERSIONS} && -z ${ROOT} ]]; then
870
		local oldv newv=$(ver_cut 1-2 ${PV})
872
		local oldv newv=$(ver_cut 1-2 ${PV})
871
		for oldv in ${REPLACING_VERSIONS}; do
873
		for oldv in ${REPLACING_VERSIONS}; do
872
			if ver_test ${oldv} -lt ${newv}; then
874
			if ver_test ${oldv} -lt ${newv}; then
873
				ewarn "After upgrading glibc, please restart all running processes."
875
				ewarn "After upgrading glibc, please restart all running processes."
874
				ewarn "Be sure to include init (telinit u) or systemd (systemctl daemon-reexec)."
876
				ewarn "Be sure to include init (telinit u) or systemd (systemctl daemon-reexec)."
875
				ewarn "Alternatively, reboot your system."
877
				ewarn "Alternatively, reboot your system."
876
				ewarn "(See bug #660556, bug #741116, bug #823756, etc)"
878
				ewarn "(See bug #660556, bug #741116, bug #823756, etc)"
877
				break
879
				break
878
			fi
880
			fi
879
		done
881
		done
880
	fi
882
	fi
881
}
883
}
882
884
883
#
885
#
884
# the phases
886
# the phases
885
#
887
#
886
888
887
# pkg_pretend
889
# pkg_pretend
888
890
889
pkg_pretend() {
891
pkg_pretend() {
890
	upgrade_warning
892
	upgrade_warning
891
}
893
}
892
894
893
# pkg_setup
895
# pkg_setup
894
896
895
pkg_setup() {
897
pkg_setup() {
896
	# see bug 682570
898
	# see bug 682570
897
	[[ -z ${BOOTSTRAP_RAP} ]] && python-any-r1_pkg_setup
899
	[[ -z ${BOOTSTRAP_RAP} ]] && python-any-r1_pkg_setup
898
}
900
}
899
901
900
# src_unpack
902
# src_unpack
901
903
902
src_unpack() {
904
src_unpack() {
903
	setup_env
905
	setup_env
904
906
905
	einfo "Checking general environment sanity."
907
	einfo "Checking general environment sanity."
906
	sanity_prechecks
908
	sanity_prechecks
907
909
908
	use multilib-bootstrap && unpack gcc-multilib-bootstrap-${GCC_BOOTSTRAP_VER}.tar.xz
910
	use multilib-bootstrap && unpack gcc-multilib-bootstrap-${GCC_BOOTSTRAP_VER}.tar.xz
909
911
910
	if [[ ${PV} == 9999* ]] ; then
912
	if [[ ${PV} == 9999* ]] ; then
911
		EGIT_REPO_URI="https://anongit.gentoo.org/git/proj/toolchain/glibc-patches.git"
913
		EGIT_REPO_URI="https://anongit.gentoo.org/git/proj/toolchain/glibc-patches.git"
912
		EGIT_CHECKOUT_DIR=${WORKDIR}/patches-git
914
		EGIT_CHECKOUT_DIR=${WORKDIR}/patches-git
913
		git-r3_src_unpack
915
		git-r3_src_unpack
914
		mv patches-git/9999 patches || die
916
		mv patches-git/9999 patches || die
915
917
916
		EGIT_REPO_URI="https://sourceware.org/git/glibc.git"
918
		EGIT_REPO_URI="https://sourceware.org/git/glibc.git"
917
		EGIT_CHECKOUT_DIR=${S}
919
		EGIT_CHECKOUT_DIR=${S}
918
		git-r3_src_unpack
920
		git-r3_src_unpack
919
	else
921
	else
920
		unpack ${P}.tar.xz
922
		unpack ${P}.tar.xz
921
923
922
		cd "${WORKDIR}" || die
924
		cd "${WORKDIR}" || die
923
		unpack glibc-${PV}-patches-${PATCH_VER}.tar.xz
925
		unpack glibc-${PV}-patches-${PATCH_VER}.tar.xz
924
	fi
926
	fi
925
927
926
	cd "${WORKDIR}" || die
928
	cd "${WORKDIR}" || die
927
	use systemd && unpack glibc-systemd-${GLIBC_SYSTEMD_VER}.tar.gz
929
	use systemd && unpack glibc-systemd-${GLIBC_SYSTEMD_VER}.tar.gz
928
}
930
}
929
931
930
# src_prepare
932
# src_prepare
931
933
932
src_prepare() {
934
src_prepare() {
933
	local patchsetname
935
	local patchsetname
934
	if ! use vanilla ; then
936
	if ! use vanilla ; then
935
		if [[ ${PV} == 9999* ]] ; then
937
		if [[ ${PV} == 9999* ]] ; then
936
			patchsetname="from git master"
938
			patchsetname="from git master"
937
		else
939
		else
938
			patchsetname="${PV}-${PATCH_VER}"
940
			patchsetname="${PV}-${PATCH_VER}"
939
		fi
941
		fi
940
		einfo "Applying Gentoo Glibc patchset ${patchsetname}"
942
		einfo "Applying Gentoo Glibc patchset ${patchsetname}"
941
		eapply "${WORKDIR}"/patches
943
		eapply "${WORKDIR}"/patches
942
		einfo "Done."
944
		einfo "Done."
943
	fi
945
	fi
944
946
945
	default
947
	default
946
948
947
	gnuconfig_update
949
	gnuconfig_update
948
950
949
	cd "${WORKDIR}" || die
951
	cd "${WORKDIR}" || die
950
	find . -name configure -exec touch {} +
952
	find . -name configure -exec touch {} +
951
953
952
	# Fix permissions on some of the scripts.
954
	# Fix permissions on some of the scripts.
953
	chmod u+x "${S}"/scripts/*.sh
955
	chmod u+x "${S}"/scripts/*.sh
954
956
955
	cd "${S}" || die
957
	cd "${S}" || die
956
}
958
}
957
959
958
# src_configure
960
# src_configure
959
961
960
glibc_do_configure() {
962
glibc_do_configure() {
961
	dump_build_environment
963
	dump_build_environment
962
964
963
	local myconf=()
965
	local myconf=()
964
966
965
	# Use '=strong' instead of '=all' to protect only functions
967
	# Use '=strong' instead of '=all' to protect only functions
966
	# worth protecting from stack smashes.
968
	# worth protecting from stack smashes.
967
	myconf+=( --enable-stack-protector=$(usex ssp strong no) )
969
	myconf+=( --enable-stack-protector=$(usex ssp strong no) )
968
970
969
	# Keep a whitelist of targets supporing IFUNC. glibc's ./configure
971
	# Keep a whitelist of targets supporing IFUNC. glibc's ./configure
970
	# is not robust enough to detect proper support:
972
	# is not robust enough to detect proper support:
971
	#    https://bugs.gentoo.org/641216
973
	#    https://bugs.gentoo.org/641216
972
	#    https://sourceware.org/PR22634#c0
974
	#    https://sourceware.org/PR22634#c0
973
	case $(tc-arch ${CTARGET}) in
975
	case $(tc-arch ${CTARGET}) in
974
		# Keep whitelist of targets where autodetection mostly works.
976
		# Keep whitelist of targets where autodetection mostly works.
975
		amd64|x86|sparc|ppc|ppc64|arm|arm64|s390|riscv|loong) ;;
977
		amd64|x86|sparc|ppc|ppc64|arm|arm64|s390|riscv|loong) ;;
976
		# Blacklist everywhere else
978
		# Blacklist everywhere else
977
		*) myconf+=( libc_cv_ld_gnu_indirect_function=no ) ;;
979
		*) myconf+=( libc_cv_ld_gnu_indirect_function=no ) ;;
978
	esac
980
	esac
979
981
980
	# Enable Intel Control-flow Enforcement Technology on amd64 if requested
982
	# Enable Intel Control-flow Enforcement Technology on amd64 if requested
981
	case ${CTARGET} in
983
	case ${CTARGET} in
982
		x86_64-*) myconf+=( $(use_enable cet) ) ;;
984
		x86_64-*) myconf+=( $(use_enable cet) ) ;;
983
		*) ;;
985
		*) ;;
984
	esac
986
	esac
985
987
986
	[[ $(tc-is-softfloat) == "yes" ]] && myconf+=( --without-fp )
988
	[[ $(tc-is-softfloat) == "yes" ]] && myconf+=( --without-fp )
987
989
988
	myconf+=( --enable-kernel=${MIN_KERN_VER} )
990
	myconf+=( --enable-kernel=${MIN_KERN_VER} )
989
991
990
	# Since SELinux support is only required for nscd, only enable it if:
992
	# Since SELinux support is only required for nscd, only enable it if:
991
	# 1. USE selinux
993
	# 1. USE selinux
992
	# 2. only for the primary ABI on multilib systems
994
	# 2. only for the primary ABI on multilib systems
993
	# 3. Not a crosscompile
995
	# 3. Not a crosscompile
994
	if ! is_crosscompile && use selinux ; then
996
	if ! is_crosscompile && use selinux ; then
995
		if use multilib ; then
997
		if use multilib ; then
996
			if is_final_abi ; then
998
			if is_final_abi ; then
997
				myconf+=( --with-selinux )
999
				myconf+=( --with-selinux )
998
			else
1000
			else
999
				myconf+=( --without-selinux )
1001
				myconf+=( --without-selinux )
1000
			fi
1002
			fi
1001
		else
1003
		else
1002
			myconf+=( --with-selinux )
1004
			myconf+=( --with-selinux )
1003
		fi
1005
		fi
1004
	else
1006
	else
1005
		myconf+=( --without-selinux )
1007
		myconf+=( --without-selinux )
1006
	fi
1008
	fi
1007
1009
1008
	# Force a few tests where we always know the answer but
1010
	# Force a few tests where we always know the answer but
1009
	# configure is incapable of finding it.
1011
	# configure is incapable of finding it.
1010
	if is_crosscompile ; then
1012
	if is_crosscompile ; then
1011
		export \
1013
		export \
1012
			libc_cv_c_cleanup=yes \
1014
			libc_cv_c_cleanup=yes \
1013
			libc_cv_forced_unwind=yes
1015
			libc_cv_forced_unwind=yes
1014
	fi
1016
	fi
1015
1017
1016
	myconf+=(
1018
	myconf+=(
1017
		--disable-werror
1019
		--disable-werror
1018
		--enable-bind-now
1020
		--enable-bind-now
1019
		--build=${CBUILD_OPT:-${CBUILD}}
1021
		--build=${CBUILD_OPT:-${CBUILD}}
1020
		--host=${CTARGET_OPT:-${CTARGET}}
1022
		--host=${CTARGET_OPT:-${CTARGET}}
1021
		$(use_enable profile)
1023
		$(use_enable profile)
1022
		$(use_with gd)
1024
		$(use_with gd)
1023
		--with-headers=$(build_eprefix)$(alt_build_headers)
1025
		--with-headers=$(build_eprefix)$(alt_build_headers)
1024
		--prefix="$(host_eprefix)/usr"
1026
		--prefix="$(host_eprefix)/usr"
1025
		--sysconfdir="$(host_eprefix)/etc"
1027
		--sysconfdir="$(host_eprefix)/etc"
1026
		--localstatedir="$(host_eprefix)/var"
1028
		--localstatedir="$(host_eprefix)/var"
1027
		--libdir='$(prefix)'/$(get_libdir)
1029
		--libdir='$(prefix)'/$(get_libdir)
1028
		--mandir='$(prefix)'/share/man
1030
		--mandir='$(prefix)'/share/man
1029
		--infodir='$(prefix)'/share/info
1031
		--infodir='$(prefix)'/share/info
1030
		--libexecdir='$(libdir)'/misc/glibc
1032
		--libexecdir='$(libdir)'/misc/glibc
1031
		--with-bugurl=https://bugs.gentoo.org/
1033
		--with-bugurl=https://bugs.gentoo.org/
1032
		--with-pkgversion="$(glibc_banner)"
1034
		--with-pkgversion="$(glibc_banner)"
1033
		$(use_enable crypt)
1035
		$(use_enable crypt)
1034
		$(use_multiarch || echo --disable-multi-arch)
1036
		$(use_multiarch || echo --disable-multi-arch)
1035
		$(use_enable systemtap)
1037
		$(use_enable systemtap)
1036
		$(use_enable nscd)
1038
		$(use_enable nscd)
1037
1039
1038
		# /usr/bin/mtrace has a Perl shebang. Gentoo Prefix QA checks fail if
1040
		# /usr/bin/mtrace has a Perl shebang. Gentoo Prefix QA checks fail if
1039
		# Perl hasn't been installed inside the prefix yet and configure picks
1041
		# Perl hasn't been installed inside the prefix yet and configure picks
1040
		# up a Perl from outside the prefix instead. configure will fail to
1042
		# up a Perl from outside the prefix instead. configure will fail to
1041
		# execute Perl during configure if we're cross-compiling a prefix, but
1043
		# execute Perl during configure if we're cross-compiling a prefix, but
1042
		# it will just disable mtrace in that case.
1044
		# it will just disable mtrace in that case.
1043
		# Note: mtrace is needed by the test suite.
1045
		# Note: mtrace is needed by the test suite.
1044
		ac_cv_path_PERL="$(usex perl "${EPREFIX}"/usr/bin/perl $(usex test "${EPREFIX}"/usr/bin/perl $(usex doc "${EPREFIX}"/usr/bin/perl no)))"
1046
		ac_cv_path_PERL="$(usex perl "${EPREFIX}"/usr/bin/perl $(usex test "${EPREFIX}"/usr/bin/perl $(usex doc "${EPREFIX}"/usr/bin/perl no)))"
1045
1047
1046
		# locale data is arch-independent
1048
		# locale data is arch-independent
1047
		# https://bugs.gentoo.org/753740
1049
		# https://bugs.gentoo.org/753740
1048
		libc_cv_complocaledir='${exec_prefix}/lib/locale'
1050
		libc_cv_complocaledir='${exec_prefix}/lib/locale'
1049
1051
1050
		# -march= option tricks build system to infer too
1052
		# -march= option tricks build system to infer too
1051
		# high ISA level: https://sourceware.org/PR27318
1053
		# high ISA level: https://sourceware.org/PR27318
1052
		libc_cv_include_x86_isa_level=no
1054
		libc_cv_include_x86_isa_level=no
1053
1055
1054
		# Explicit override of https://sourceware.org/PR27991
1056
		# Explicit override of https://sourceware.org/PR27991
1055
		# exposes a bug in glibc's configure:
1057
		# exposes a bug in glibc's configure:
1056
		# https://sourceware.org/PR27991
1058
		# https://sourceware.org/PR27991
1057
		libc_cv_have_x86_lahf_sahf=no
1059
		libc_cv_have_x86_lahf_sahf=no
1058
		libc_cv_have_x86_movbe=no
1060
		libc_cv_have_x86_movbe=no
1059
1061
1060
		${EXTRA_ECONF}
1062
		${EXTRA_ECONF}
1061
	)
1063
	)
1062
1064
1063
	# We rely on sys-libs/timezone-data for timezone tools normally.
1065
	# We rely on sys-libs/timezone-data for timezone tools normally.
1064
	myconf+=( $(use_enable vanilla timezone-tools) )
1066
	myconf+=( $(use_enable vanilla timezone-tools) )
1065
1067
1066
	# These libs don't have configure flags.
1068
	# These libs don't have configure flags.
1067
	ac_cv_lib_audit_audit_log_user_avc_message=$(usex audit || echo no)
1069
	ac_cv_lib_audit_audit_log_user_avc_message=$(usex audit || echo no)
1068
	ac_cv_lib_cap_cap_init=$(usex caps || echo no)
1070
	ac_cv_lib_cap_cap_init=$(usex caps || echo no)
1069
1071
1070
	# There is no configure option for this and we need to export it
1072
	# There is no configure option for this and we need to export it
1071
	# since the glibc build will re-run configure on itself
1073
	# since the glibc build will re-run configure on itself
1072
	export libc_cv_rootsbindir="$(host_eprefix)/sbin"
1074
	export libc_cv_rootsbindir="$(host_eprefix)/sbin"
1073
	export libc_cv_slibdir="$(host_eprefix)/$(get_libdir)"
1075
	export libc_cv_slibdir="$(host_eprefix)/$(get_libdir)"
1074
1076
1075
	local builddir=$(builddir nptl)
1077
	local builddir=$(builddir nptl)
1076
	mkdir -p "${builddir}"
1078
	mkdir -p "${builddir}"
1077
	cd "${builddir}"
1079
	cd "${builddir}"
1078
	set -- "${S}"/configure "${myconf[@]}"
1080
	set -- "${S}"/configure "${myconf[@]}"
1079
	echo "$@"
1081
	echo "$@"
1080
	"$@" || die "failed to configure glibc"
1082
	"$@" || die "failed to configure glibc"
1081
1083
1082
	# ia64 static cross-compilers are a pita in so much that they
1084
	# ia64 static cross-compilers are a pita in so much that they
1083
	# can't produce static ELFs (as the libgcc.a is broken).  so
1085
	# can't produce static ELFs (as the libgcc.a is broken).  so
1084
	# disable building of the programs for those targets if it
1086
	# disable building of the programs for those targets if it
1085
	# doesn't work.
1087
	# doesn't work.
1086
	# XXX: We could turn this into a compiler test, but ia64 is
1088
	# XXX: We could turn this into a compiler test, but ia64 is
1087
	# the only one that matters, so this should be fine for now.
1089
	# the only one that matters, so this should be fine for now.
1088
	if is_crosscompile && [[ ${CTARGET} == ia64* ]] ; then
1090
	if is_crosscompile && [[ ${CTARGET} == ia64* ]] ; then
1089
		sed -i '1i+link-static = touch $@' config.make
1091
		sed -i '1i+link-static = touch $@' config.make
1090
	fi
1092
	fi
1091
1093
1092
	# If we're trying to migrate between ABI sets, we need
1094
	# If we're trying to migrate between ABI sets, we need
1093
	# to lie and use a local copy of gcc.  Like if the system
1095
	# to lie and use a local copy of gcc.  Like if the system
1094
	# is built with MULTILIB_ABIS="amd64 x86" but we want to
1096
	# is built with MULTILIB_ABIS="amd64 x86" but we want to
1095
	# add x32 to it, gcc/glibc don't yet support x32.
1097
	# add x32 to it, gcc/glibc don't yet support x32.
1096
	#
1098
	#
1097
	if [[ -n ${GCC_BOOTSTRAP_VER} ]] && use multilib-bootstrap ; then
1099
	if [[ -n ${GCC_BOOTSTRAP_VER} ]] && use multilib-bootstrap ; then
1098
		echo 'main(){}' > "${T}"/test.c
1100
		echo 'main(){}' > "${T}"/test.c
1099
		if ! $(tc-getCC ${CTARGET}) ${CFLAGS} ${LDFLAGS} "${T}"/test.c -Wl,-emain -lgcc 2>/dev/null ; then
1101
		if ! $(tc-getCC ${CTARGET}) ${CFLAGS} ${LDFLAGS} "${T}"/test.c -Wl,-emain -lgcc 2>/dev/null ; then
1100
			sed -i -e '/^CC = /s:$: -B$(objdir)/../'"gcc-multilib-bootstrap-${GCC_BOOTSTRAP_VER}/${ABI}:" config.make || die
1102
			sed -i -e '/^CC = /s:$: -B$(objdir)/../'"gcc-multilib-bootstrap-${GCC_BOOTSTRAP_VER}/${ABI}:" config.make || die
1101
		fi
1103
		fi
1102
	fi
1104
	fi
1103
}
1105
}
1104
1106
1105
glibc_headers_configure() {
1107
glibc_headers_configure() {
1106
	export ABI=default
1108
	export ABI=default
1107
1109
1108
	local builddir=$(builddir "headers")
1110
	local builddir=$(builddir "headers")
1109
	mkdir -p "${builddir}"
1111
	mkdir -p "${builddir}"
1110
	cd "${builddir}"
1112
	cd "${builddir}"
1111
1113
1112
	# if we don't have a compiler yet, we can't really test it now ...
1114
	# if we don't have a compiler yet, we can't really test it now ...
1113
	# hopefully they don't affect header generation, so let's hope for
1115
	# hopefully they don't affect header generation, so let's hope for
1114
	# the best here ...
1116
	# the best here ...
1115
	local v vars=(
1117
	local v vars=(
1116
		ac_cv_header_cpuid_h=yes
1118
		ac_cv_header_cpuid_h=yes
1117
		libc_cv_{386,390,alpha,arm,hppa,ia64,mips,{powerpc,sparc}{,32,64},sh,x86_64}_tls=yes
1119
		libc_cv_{386,390,alpha,arm,hppa,ia64,mips,{powerpc,sparc}{,32,64},sh,x86_64}_tls=yes
1118
		libc_cv_asm_cfi_directives=yes
1120
		libc_cv_asm_cfi_directives=yes
1119
		libc_cv_broken_visibility_attribute=no
1121
		libc_cv_broken_visibility_attribute=no
1120
		libc_cv_c_cleanup=yes
1122
		libc_cv_c_cleanup=yes
1121
		libc_cv_compiler_powerpc64le_binary128_ok=yes
1123
		libc_cv_compiler_powerpc64le_binary128_ok=yes
1122
		libc_cv_forced_unwind=yes
1124
		libc_cv_forced_unwind=yes
1123
		libc_cv_gcc___thread=yes
1125
		libc_cv_gcc___thread=yes
1124
		libc_cv_mlong_double_128=yes
1126
		libc_cv_mlong_double_128=yes
1125
		libc_cv_mlong_double_128ibm=yes
1127
		libc_cv_mlong_double_128ibm=yes
1126
		libc_cv_ppc_machine=yes
1128
		libc_cv_ppc_machine=yes
1127
		libc_cv_ppc_rel16=yes
1129
		libc_cv_ppc_rel16=yes
1128
		libc_cv_predef_fortify_source=no
1130
		libc_cv_predef_fortify_source=no
1129
		libc_cv_target_power8_ok=yes
1131
		libc_cv_target_power8_ok=yes
1130
		libc_cv_visibility_attribute=yes
1132
		libc_cv_visibility_attribute=yes
1131
		libc_cv_z_combreloc=yes
1133
		libc_cv_z_combreloc=yes
1132
		libc_cv_z_execstack=yes
1134
		libc_cv_z_execstack=yes
1133
		libc_cv_z_initfirst=yes
1135
		libc_cv_z_initfirst=yes
1134
		libc_cv_z_nodelete=yes
1136
		libc_cv_z_nodelete=yes
1135
		libc_cv_z_nodlopen=yes
1137
		libc_cv_z_nodlopen=yes
1136
		libc_cv_z_relro=yes
1138
		libc_cv_z_relro=yes
1137
		libc_mips_abi=${ABI}
1139
		libc_mips_abi=${ABI}
1138
		libc_mips_float=$([[ $(tc-is-softfloat) == "yes" ]] && echo soft || echo hard)
1140
		libc_mips_float=$([[ $(tc-is-softfloat) == "yes" ]] && echo soft || echo hard)
1139
		# These libs don't have configure flags.
1141
		# These libs don't have configure flags.
1140
		ac_cv_lib_audit_audit_log_user_avc_message=no
1142
		ac_cv_lib_audit_audit_log_user_avc_message=no
1141
		ac_cv_lib_cap_cap_init=no
1143
		ac_cv_lib_cap_cap_init=no
1142
	)
1144
	)
1143
1145
1144
	einfo "Forcing cached settings:"
1146
	einfo "Forcing cached settings:"
1145
	for v in "${vars[@]}" ; do
1147
	for v in "${vars[@]}" ; do
1146
		einfo " ${v}"
1148
		einfo " ${v}"
1147
		export ${v}
1149
		export ${v}
1148
	done
1150
	done
1149
1151
1150
	local headers_only_arch_CPPFLAGS=()
1152
	local headers_only_arch_CPPFLAGS=()
1151
1153
1152
	# Blow away some random CC settings that screw things up. #550192
1154
	# Blow away some random CC settings that screw things up. #550192
1153
	if [[ -d ${S}/sysdeps/mips ]]; then
1155
	if [[ -d ${S}/sysdeps/mips ]]; then
1154
		pushd "${S}"/sysdeps/mips >/dev/null
1156
		pushd "${S}"/sysdeps/mips >/dev/null
1155
		sed -i -e '/^CC +=/s:=.*:= -D_MIPS_SZPTR=32:' mips32/Makefile mips64/n32/Makefile || die
1157
		sed -i -e '/^CC +=/s:=.*:= -D_MIPS_SZPTR=32:' mips32/Makefile mips64/n32/Makefile || die
1156
		sed -i -e '/^CC +=/s:=.*:= -D_MIPS_SZPTR=64:' mips64/n64/Makefile || die
1158
		sed -i -e '/^CC +=/s:=.*:= -D_MIPS_SZPTR=64:' mips64/n64/Makefile || die
1157
1159
1158
		# Force the mips ABI to the default.  This is OK because the set of
1160
		# Force the mips ABI to the default.  This is OK because the set of
1159
		# installed headers in this phase is the same between the 3 ABIs.
1161
		# installed headers in this phase is the same between the 3 ABIs.
1160
		# If this ever changes, this hack will break, but that's unlikely
1162
		# If this ever changes, this hack will break, but that's unlikely
1161
		# as glibc discourages that behavior.
1163
		# as glibc discourages that behavior.
1162
		# https://crbug.com/647033
1164
		# https://crbug.com/647033
1163
		sed -i -e 's:abiflag=.*:abiflag=_ABIO32:' preconfigure || die
1165
		sed -i -e 's:abiflag=.*:abiflag=_ABIO32:' preconfigure || die
1164
1166
1165
		popd >/dev/null
1167
		popd >/dev/null
1166
	fi
1168
	fi
1167
1169
1168
	case ${CTARGET} in
1170
	case ${CTARGET} in
1169
	riscv*)
1171
	riscv*)
1170
		# RISC-V interrogates the compiler to determine which target to
1172
		# RISC-V interrogates the compiler to determine which target to
1171
		# build.  If building the headers then we don't strictly need a
1173
		# build.  If building the headers then we don't strictly need a
1172
		# RISC-V compiler, so the built-in definitions that are provided
1174
		# RISC-V compiler, so the built-in definitions that are provided
1173
		# along with all RISC-V compiler might not exist.  This causes
1175
		# along with all RISC-V compiler might not exist.  This causes
1174
		# glibc's RISC-V preconfigure script to blow up.  Since we're just
1176
		# glibc's RISC-V preconfigure script to blow up.  Since we're just
1175
		# building the headers any value will actually work here, so just
1177
		# building the headers any value will actually work here, so just
1176
		# pick the standard one (rv64g/lp64d) to make the build scripts
1178
		# pick the standard one (rv64g/lp64d) to make the build scripts
1177
		# happy for now -- the headers are all the same anyway so it
1179
		# happy for now -- the headers are all the same anyway so it
1178
		# doesn't matter.
1180
		# doesn't matter.
1179
		headers_only_arch_CPPFLAGS+=(
1181
		headers_only_arch_CPPFLAGS+=(
1180
			-D__riscv_xlen=64
1182
			-D__riscv_xlen=64
1181
			-D__riscv_flen=64
1183
			-D__riscv_flen=64
1182
			-D__riscv_float_abi_double=1
1184
			-D__riscv_float_abi_double=1
1183
			-D__riscv_atomic=1
1185
			-D__riscv_atomic=1
1184
		) ;;
1186
		) ;;
1185
	esac
1187
	esac
1186
1188
1187
	local myconf=()
1189
	local myconf=()
1188
	myconf+=(
1190
	myconf+=(
1189
		--disable-sanity-checks
1191
		--disable-sanity-checks
1190
		--enable-hacker-mode
1192
		--enable-hacker-mode
1191
		--disable-werror
1193
		--disable-werror
1192
		--enable-bind-now
1194
		--enable-bind-now
1193
		--build=${CBUILD_OPT:-${CBUILD}}
1195
		--build=${CBUILD_OPT:-${CBUILD}}
1194
		--host=${CTARGET_OPT:-${CTARGET}}
1196
		--host=${CTARGET_OPT:-${CTARGET}}
1195
		--with-headers=$(build_eprefix)$(alt_build_headers)
1197
		--with-headers=$(build_eprefix)$(alt_build_headers)
1196
		--prefix="$(host_eprefix)/usr"
1198
		--prefix="$(host_eprefix)/usr"
1197
		$(use_enable crypt)
1199
		$(use_enable crypt)
1198
		${EXTRA_ECONF}
1200
		${EXTRA_ECONF}
1199
	)
1201
	)
1200
1202
1201
	# Nothing is compiled here which would affect the headers for the target.
1203
	# Nothing is compiled here which would affect the headers for the target.
1202
	# So forcing CC/CFLAGS is sane.
1204
	# So forcing CC/CFLAGS is sane.
1203
	local headers_only_CC=$(tc-getBUILD_CC)
1205
	local headers_only_CC=$(tc-getBUILD_CC)
1204
	local headers_only_CFLAGS="-O1 -pipe"
1206
	local headers_only_CFLAGS="-O1 -pipe"
1205
	local headers_only_CPPFLAGS="-U_FORTIFY_SOURCE ${headers_only_arch_CPPFLAGS[*]}"
1207
	local headers_only_CPPFLAGS="-U_FORTIFY_SOURCE ${headers_only_arch_CPPFLAGS[*]}"
1206
	local headers_only_LDFLAGS=""
1208
	local headers_only_LDFLAGS=""
1207
	set -- "${S}"/configure "${myconf[@]}"
1209
	set -- "${S}"/configure "${myconf[@]}"
1208
	echo \
1210
	echo \
1209
		"CC=${headers_only_CC}" \
1211
		"CC=${headers_only_CC}" \
1210
		"CFLAGS=${headers_only_CFLAGS}" \
1212
		"CFLAGS=${headers_only_CFLAGS}" \
1211
		"CPPFLAGS=${headers_only_CPPFLAGS}" \
1213
		"CPPFLAGS=${headers_only_CPPFLAGS}" \
1212
		"LDFLAGS=${headers_only_LDFLAGS}" \
1214
		"LDFLAGS=${headers_only_LDFLAGS}" \
1213
		"$@"
1215
		"$@"
1214
	CC=${headers_only_CC} \
1216
	CC=${headers_only_CC} \
1215
	CFLAGS=${headers_only_CFLAGS} \
1217
	CFLAGS=${headers_only_CFLAGS} \
1216
	CPPFLAGS=${headers_only_CPPFLAGS} \
1218
	CPPFLAGS=${headers_only_CPPFLAGS} \
1217
	LDFLAGS="" \
1219
	LDFLAGS="" \
1218
	"$@" || die "failed to configure glibc"
1220
	"$@" || die "failed to configure glibc"
1219
}
1221
}
1220
1222
1221
do_src_configure() {
1223
do_src_configure() {
1222
	if just_headers ; then
1224
	if just_headers ; then
1223
		glibc_headers_configure
1225
		glibc_headers_configure
1224
	else
1226
	else
1225
		glibc_do_configure nptl
1227
		glibc_do_configure nptl
1226
	fi
1228
	fi
1227
}
1229
}
1228
1230
1229
src_configure() {
1231
src_configure() {
1230
	foreach_abi do_src_configure
1232
	foreach_abi do_src_configure
1231
}
1233
}
1232
1234
1233
# src_compile
1235
# src_compile
1234
1236
1235
do_src_compile() {
1237
do_src_compile() {
1236
	emake -C "$(builddir nptl)"
1238
	emake -C "$(builddir nptl)"
1237
}
1239
}
1238
1240
1239
src_compile() {
1241
src_compile() {
1240
	if just_headers ; then
1242
	if just_headers ; then
1241
		return
1243
		return
1242
	fi
1244
	fi
1243
1245
1244
	foreach_abi do_src_compile
1246
	foreach_abi do_src_compile
1245
}
1247
}
1246
1248
1247
# src_test
1249
# src_test
1248
1250
1249
glibc_src_test() {
1251
glibc_src_test() {
1250
	cd "$(builddir nptl)"
1252
	cd "$(builddir nptl)"
1251
1253
1252
	local myxfailparams=""
1254
	local myxfailparams=""
1253
	if [[ "${GENTOO_GLIBC_XFAIL_TESTS}" == "yes" ]] ; then
1255
	if [[ "${GENTOO_GLIBC_XFAIL_TESTS}" == "yes" ]] ; then
1254
		local virt=$(systemd-detect-virt 2>/dev/null)
1256
		local virt=$(systemd-detect-virt 2>/dev/null)
1255
		if [[ ${virt} == systemd-nspawn ]] ; then
1257
		if [[ ${virt} == systemd-nspawn ]] ; then
1256
			ewarn "Skipping extra tests because in systemd-nspawn container"
1258
			ewarn "Skipping extra tests because in systemd-nspawn container"
1257
			XFAIL_TEST_LIST+=( "${XFAIL_NSPAWN_TEST_LIST[@]}" )
1259
			XFAIL_TEST_LIST+=( "${XFAIL_NSPAWN_TEST_LIST[@]}" )
1258
		fi
1260
		fi
1259
1261
1260
		for myt in ${XFAIL_TEST_LIST[@]} ; do
1262
		for myt in ${XFAIL_TEST_LIST[@]} ; do
1261
			myxfailparams+="test-xfail-${myt}=yes "
1263
			myxfailparams+="test-xfail-${myt}=yes "
1262
		done
1264
		done
1263
	fi
1265
	fi
1264
1266
1265
	# sandbox does not understand unshare() and prevents
1267
	# sandbox does not understand unshare() and prevents
1266
	# writes to /proc/, which makes many tests fail
1268
	# writes to /proc/, which makes many tests fail
1267
1269
1268
	# we give the tests a bit more time to avoid spurious
1270
	# we give the tests a bit more time to avoid spurious
1269
	# bug reports on slow arches
1271
	# bug reports on slow arches
1270
1272
1271
	SANDBOX_ON=0 LD_PRELOAD= TIMEOUTFACTOR=16 emake ${myxfailparams} check
1273
	SANDBOX_ON=0 LD_PRELOAD= TIMEOUTFACTOR=16 emake ${myxfailparams} check
1272
}
1274
}
1273
1275
1274
src_test() {
1276
src_test() {
1275
	if just_headers ; then
1277
	if just_headers ; then
1276
		return
1278
		return
1277
	fi
1279
	fi
1278
1280
1279
	foreach_abi glibc_src_test || die "tests failed"
1281
	foreach_abi glibc_src_test || die "tests failed"
1280
}
1282
}
1281
1283
1282
# src_install
1284
# src_install
1283
1285
1284
run_locale_gen() {
1286
run_locale_gen() {
1285
	# if the host locales.gen contains no entries, we'll install everything
1287
	# if the host locales.gen contains no entries, we'll install everything
1286
	local root="$1"
1288
	local root="$1"
1287
	local inplace=""
1289
	local inplace=""
1288
1290
1289
	if [[ "${root}" == "--inplace-glibc" ]] ; then
1291
	if [[ "${root}" == "--inplace-glibc" ]] ; then
1290
		inplace="--inplace-glibc"
1292
		inplace="--inplace-glibc"
1291
		root="$2"
1293
		root="$2"
1292
	fi
1294
	fi
1293
1295
1294
	local locale_list="${root%/}/etc/locale.gen"
1296
	local locale_list="${root%/}/etc/locale.gen"
1295
1297
1296
	pushd "${ED}"/$(get_libdir) >/dev/null
1298
	pushd "${ED}"/$(get_libdir) >/dev/null
1297
1299
1298
	if [[ -z $(locale-gen --list --config "${locale_list}") ]] ; then
1300
	if [[ -z $(locale-gen --list --config "${locale_list}") ]] ; then
1299
		[[ -z ${inplace} ]] && ewarn "Generating all locales; edit /etc/locale.gen to save time/space"
1301
		[[ -z ${inplace} ]] && ewarn "Generating all locales; edit /etc/locale.gen to save time/space"
1300
		locale_list="${root%/}/usr/share/i18n/SUPPORTED"
1302
		locale_list="${root%/}/usr/share/i18n/SUPPORTED"
1301
	fi
1303
	fi
1302
1304
1303
	# bug 736794: we need to be careful with the parallelization... the number of
1305
	# bug 736794: we need to be careful with the parallelization... the number of
1304
	# processors saved in the environment of a binary package may differ strongly
1306
	# processors saved in the environment of a binary package may differ strongly
1305
	# from the number of processes available during postinst
1307
	# from the number of processes available during postinst
1306
	local mygenjobs="$(makeopts_jobs)"
1308
	local mygenjobs="$(makeopts_jobs)"
1307
	if [[ "${EMERGE_FROM}" == "binary" ]] ; then
1309
	if [[ "${EMERGE_FROM}" == "binary" ]] ; then
1308
		mygenjobs="$(nproc)"
1310
		mygenjobs="$(nproc)"
1309
	fi
1311
	fi
1310
1312
1311
	set -- locale-gen ${inplace} --jobs "${mygenjobs}" --config "${locale_list}" \
1313
	set -- locale-gen ${inplace} --jobs "${mygenjobs}" --config "${locale_list}" \
1312
		--destdir "${root}"
1314
		--destdir "${root}"
1313
	echo "$@"
1315
	echo "$@"
1314
	"$@"
1316
	"$@"
1315
1317
1316
	popd >/dev/null
1318
	popd >/dev/null
1317
}
1319
}
1318
1320
1319
glibc_do_src_install() {
1321
glibc_do_src_install() {
1320
	local builddir=$(builddir nptl)
1322
	local builddir=$(builddir nptl)
1321
	cd "${builddir}"
1323
	cd "${builddir}"
1322
1324
1323
	emake install_root="${D}/$(build_eprefix)$(alt_prefix)" install
1325
	emake install_root="${D}/$(build_eprefix)$(alt_prefix)" install
1324
1326
1325
	# This version (2.26) provides some compatibility libraries for the NIS/NIS+ support
1327
	# This version (2.26) provides some compatibility libraries for the NIS/NIS+ support
1326
	# which come without headers etc. Only needed for binary packages since the
1328
	# which come without headers etc. Only needed for binary packages since the
1327
	# external net-libs/libnsl has increased soversion. Keep only versioned libraries.
1329
	# external net-libs/libnsl has increased soversion. Keep only versioned libraries.
1328
	find "${D}" -name "libnsl.a" -delete
1330
	find "${D}" -name "libnsl.a" -delete
1329
	find "${D}" -name "libnsl.so" -delete
1331
	find "${D}" -name "libnsl.so" -delete
1330
1332
1331
	# Normally upstream_pv is ${PV}. Live ebuilds are exception, there we need
1333
	# Normally upstream_pv is ${PV}. Live ebuilds are exception, there we need
1332
	# to infer upstream version:
1334
	# to infer upstream version:
1333
	# '#define VERSION "2.26.90"' -> '2.26.90'
1335
	# '#define VERSION "2.26.90"' -> '2.26.90'
1334
	local upstream_pv=$(sed -n -r 's/#define VERSION "(.*)"/\1/p' "${S}"/version.h)
1336
	local upstream_pv=$(sed -n -r 's/#define VERSION "(.*)"/\1/p' "${S}"/version.h)
1335
1337
1336
	# Avoid stripping binaries not targeted by ${CHOST}. Or else
1338
	# Avoid stripping binaries not targeted by ${CHOST}. Or else
1337
	# ${CHOST}-strip would break binaries build for ${CTARGET}.
1339
	# ${CHOST}-strip would break binaries build for ${CTARGET}.
1338
	is_crosscompile && dostrip -x /
1340
	is_crosscompile && dostrip -x /
1339
1341
1340
	# gdb thread introspection relies on local libpthreads symbols. stripping breaks it
1342
	# gdb thread introspection relies on local libpthreads symbols. stripping breaks it
1341
	# See Note [Disable automatic stripping]
1343
	# See Note [Disable automatic stripping]
1342
	dostrip -x $(alt_libdir)/libpthread-${upstream_pv}.so
1344
	dostrip -x $(alt_libdir)/libpthread-${upstream_pv}.so
1345
	# valgrind requires knowledge about ld.so symbols.
1346
	dostrip -x $(alt_libdir)/ld-*.so*
1343
1347
1344
	if [[ -e ${ED}/$(alt_usrlibdir)/libm-${upstream_pv}.a ]] ; then
1348
	if [[ -e ${ED}/$(alt_usrlibdir)/libm-${upstream_pv}.a ]] ; then
1345
		# Move versioned .a file out of libdir to evade portage QA checks
1349
		# Move versioned .a file out of libdir to evade portage QA checks
1346
		# instead of using gen_usr_ldscript(). We fix ldscript as:
1350
		# instead of using gen_usr_ldscript(). We fix ldscript as:
1347
		# "GROUP ( /usr/lib64/libm-<pv>.a ..." -> "GROUP ( /usr/lib64/glibc-<pv>/libm-<pv>.a ..."
1351
		# "GROUP ( /usr/lib64/libm-<pv>.a ..." -> "GROUP ( /usr/lib64/glibc-<pv>/libm-<pv>.a ..."
1348
		sed -i "s@\(libm-${upstream_pv}.a\)@${P}/\1@" "${ED}"/$(alt_usrlibdir)/libm.a || die
1352
		sed -i "s@\(libm-${upstream_pv}.a\)@${P}/\1@" "${ED}"/$(alt_usrlibdir)/libm.a || die
1349
		dodir $(alt_usrlibdir)/${P}
1353
		dodir $(alt_usrlibdir)/${P}
1350
		mv "${ED}"/$(alt_usrlibdir)/libm-${upstream_pv}.a "${ED}"/$(alt_usrlibdir)/${P}/libm-${upstream_pv}.a || die
1354
		mv "${ED}"/$(alt_usrlibdir)/libm-${upstream_pv}.a "${ED}"/$(alt_usrlibdir)/${P}/libm-${upstream_pv}.a || die
1351
	fi
1355
	fi
1352
1356
1353
	# We configure toolchains for standalone prefix systems with a sysroot,
1357
	# We configure toolchains for standalone prefix systems with a sysroot,
1354
	# which is prepended to paths in ld scripts, so strip the prefix from these.
1358
	# which is prepended to paths in ld scripts, so strip the prefix from these.
1355
	# Before: GROUP ( /foo/lib64/libc.so.6 /foo/usr/lib64/libc_nonshared.a  AS_NEEDED ( /foo/lib64/ld-linux-x86-64.so.2 ) )
1359
	# Before: GROUP ( /foo/lib64/libc.so.6 /foo/usr/lib64/libc_nonshared.a  AS_NEEDED ( /foo/lib64/ld-linux-x86-64.so.2 ) )
1356
	# After: GROUP ( /lib64/libc.so.6 /usr/lib64/libc_nonshared.a  AS_NEEDED ( /lib64/ld-linux-x86-64.so.2 ) )
1360
	# After: GROUP ( /lib64/libc.so.6 /usr/lib64/libc_nonshared.a  AS_NEEDED ( /lib64/ld-linux-x86-64.so.2 ) )
1357
	if [[ -n $(host_eprefix) ]] ; then
1361
	if [[ -n $(host_eprefix) ]] ; then
1358
		local file
1362
		local file
1359
		grep -lZIF "ld script" "${ED}/$(alt_usrlibdir)"/lib*.{a,so} 2>/dev/null | while read -rd '' file ; do
1363
		grep -lZIF "ld script" "${ED}/$(alt_usrlibdir)"/lib*.{a,so} 2>/dev/null | while read -rd '' file ; do
1360
			sed -i "s|$(host_eprefix)/|/|g" "${file}" || die
1364
			sed -i "s|$(host_eprefix)/|/|g" "${file}" || die
1361
		done
1365
		done
1362
	fi
1366
	fi
1363
1367
1364
	# We'll take care of the cache ourselves
1368
	# We'll take care of the cache ourselves
1365
	rm -f "${ED}"/etc/ld.so.cache
1369
	rm -f "${ED}"/etc/ld.so.cache
1366
1370
1367
	# Everything past this point just needs to be done once ...
1371
	# Everything past this point just needs to be done once ...
1368
	is_final_abi || return 0
1372
	is_final_abi || return 0
1369
1373
1370
	# Make sure the non-native interp can be found on multilib systems even
1374
	# Make sure the non-native interp can be found on multilib systems even
1371
	# if the main library set isn't installed into the right place.  Maybe
1375
	# if the main library set isn't installed into the right place.  Maybe
1372
	# we should query the active gcc for info instead of hardcoding it ?
1376
	# we should query the active gcc for info instead of hardcoding it ?
1373
	local i ldso_abi ldso_name
1377
	local i ldso_abi ldso_name
1374
	local ldso_abi_list=(
1378
	local ldso_abi_list=(
1375
		# x86
1379
		# x86
1376
		amd64   /lib64/ld-linux-x86-64.so.2
1380
		amd64   /lib64/ld-linux-x86-64.so.2
1377
		x32     /libx32/ld-linux-x32.so.2
1381
		x32     /libx32/ld-linux-x32.so.2
1378
		x86     /lib/ld-linux.so.2
1382
		x86     /lib/ld-linux.so.2
1379
		# mips
1383
		# mips
1380
		o32     /lib/ld.so.1
1384
		o32     /lib/ld.so.1
1381
		n32     /lib32/ld.so.1
1385
		n32     /lib32/ld.so.1
1382
		n64     /lib64/ld.so.1
1386
		n64     /lib64/ld.so.1
1383
		# powerpc
1387
		# powerpc
1384
		ppc     /lib/ld.so.1
1388
		ppc     /lib/ld.so.1
1385
		# riscv
1389
		# riscv
1386
		ilp32d  /lib/ld-linux-riscv32-ilp32d.so.1
1390
		ilp32d  /lib/ld-linux-riscv32-ilp32d.so.1
1387
		ilp32   /lib/ld-linux-riscv32-ilp32.so.1
1391
		ilp32   /lib/ld-linux-riscv32-ilp32.so.1
1388
		lp64d   /lib/ld-linux-riscv64-lp64d.so.1
1392
		lp64d   /lib/ld-linux-riscv64-lp64d.so.1
1389
		lp64    /lib/ld-linux-riscv64-lp64.so.1
1393
		lp64    /lib/ld-linux-riscv64-lp64.so.1
1390
		# s390
1394
		# s390
1391
		s390    /lib/ld.so.1
1395
		s390    /lib/ld.so.1
1392
		s390x   /lib/ld64.so.1
1396
		s390x   /lib/ld64.so.1
1393
		# sparc
1397
		# sparc
1394
		sparc32 /lib/ld-linux.so.2
1398
		sparc32 /lib/ld-linux.so.2
1395
		sparc64 /lib64/ld-linux.so.2
1399
		sparc64 /lib64/ld-linux.so.2
1396
	)
1400
	)
1397
	case $(tc-endian) in
1401
	case $(tc-endian) in
1398
	little)
1402
	little)
1399
		ldso_abi_list+=(
1403
		ldso_abi_list+=(
1400
			# arm
1404
			# arm
1401
			arm64   /lib/ld-linux-aarch64.so.1
1405
			arm64   /lib/ld-linux-aarch64.so.1
1402
			# ELFv2 (glibc does not support ELFv1 on LE)
1406
			# ELFv2 (glibc does not support ELFv1 on LE)
1403
			ppc64   /lib64/ld64.so.2
1407
			ppc64   /lib64/ld64.so.2
1404
		)
1408
		)
1405
		;;
1409
		;;
1406
	big)
1410
	big)
1407
		ldso_abi_list+=(
1411
		ldso_abi_list+=(
1408
			# arm
1412
			# arm
1409
			arm64   /lib/ld-linux-aarch64_be.so.1
1413
			arm64   /lib/ld-linux-aarch64_be.so.1
1410
			# ELFv1 (glibc does not support ELFv2 on BE)
1414
			# ELFv1 (glibc does not support ELFv2 on BE)
1411
			ppc64   /lib64/ld64.so.1
1415
			ppc64   /lib64/ld64.so.1
1412
		)
1416
		)
1413
		;;
1417
		;;
1414
	esac
1418
	esac
1415
	if [[ ${SYMLINK_LIB} == "yes" ]] && [[ ! -e ${ED}/$(alt_prefix)/lib ]] ; then
1419
	if [[ ${SYMLINK_LIB} == "yes" ]] && [[ ! -e ${ED}/$(alt_prefix)/lib ]] ; then
1416
		dosym $(get_abi_LIBDIR ${DEFAULT_ABI}) $(alt_prefix)/lib
1420
		dosym $(get_abi_LIBDIR ${DEFAULT_ABI}) $(alt_prefix)/lib
1417
	fi
1421
	fi
1418
	for (( i = 0; i < ${#ldso_abi_list[@]}; i += 2 )) ; do
1422
	for (( i = 0; i < ${#ldso_abi_list[@]}; i += 2 )) ; do
1419
		ldso_abi=${ldso_abi_list[i]}
1423
		ldso_abi=${ldso_abi_list[i]}
1420
		has ${ldso_abi} $(get_install_abis) || continue
1424
		has ${ldso_abi} $(get_install_abis) || continue
1421
1425
1422
		ldso_name="$(alt_prefix)${ldso_abi_list[i+1]}"
1426
		ldso_name="$(alt_prefix)${ldso_abi_list[i+1]}"
1423
		if [[ ! -L ${ED}/${ldso_name} && ! -e ${ED}/${ldso_name} ]] ; then
1427
		if [[ ! -L ${ED}/${ldso_name} && ! -e ${ED}/${ldso_name} ]] ; then
1424
			dosym ../$(get_abi_LIBDIR ${ldso_abi})/${ldso_name##*/} ${ldso_name}
1428
			dosym ../$(get_abi_LIBDIR ${ldso_abi})/${ldso_name##*/} ${ldso_name}
1425
		fi
1429
		fi
1426
	done
1430
	done
1427
1431
1428
	# In the LSB 5.0 definition, someone had the excellent idea to "standardize"
1432
	# In the LSB 5.0 definition, someone had the excellent idea to "standardize"
1429
	# the runtime loader name, see also https://xkcd.com/927/
1433
	# the runtime loader name, see also https://xkcd.com/927/
1430
	# Normally, in Gentoo one should never come across executables that require this.
1434
	# Normally, in Gentoo one should never come across executables that require this.
1431
	# However, binary commercial packages are known to adhere to weird practices.
1435
	# However, binary commercial packages are known to adhere to weird practices.
1432
	# https://refspecs.linuxfoundation.org/LSB_5.0.0/LSB-Core-AMD64/LSB-Core-AMD64.html#BASELIB
1436
	# https://refspecs.linuxfoundation.org/LSB_5.0.0/LSB-Core-AMD64/LSB-Core-AMD64.html#BASELIB
1433
	local lsb_ldso_name native_ldso_name lsb_ldso_abi
1437
	local lsb_ldso_name native_ldso_name lsb_ldso_abi
1434
	local lsb_ldso_abi_list=(
1438
	local lsb_ldso_abi_list=(
1435
		# x86
1439
		# x86
1436
		amd64	ld-linux-x86-64.so.2	ld-lsb-x86-64.so.3
1440
		amd64	ld-linux-x86-64.so.2	ld-lsb-x86-64.so.3
1437
	)
1441
	)
1438
	for (( i = 0; i < ${#lsb_ldso_abi_list[@]}; i += 3 )) ; do
1442
	for (( i = 0; i < ${#lsb_ldso_abi_list[@]}; i += 3 )) ; do
1439
		lsb_ldso_abi=${lsb_ldso_abi_list[i]}
1443
		lsb_ldso_abi=${lsb_ldso_abi_list[i]}
1440
		native_ldso_name=${lsb_ldso_abi_list[i+1]}
1444
		native_ldso_name=${lsb_ldso_abi_list[i+1]}
1441
		lsb_ldso_name=${lsb_ldso_abi_list[i+2]}
1445
		lsb_ldso_name=${lsb_ldso_abi_list[i+2]}
1442
		has ${lsb_ldso_abi} $(get_install_abis) || continue
1446
		has ${lsb_ldso_abi} $(get_install_abis) || continue
1443
1447
1444
		if [[ ! -L ${ED}/$(get_abi_LIBDIR ${lsb_ldso_abi})/${lsb_ldso_name} && ! -e ${ED}/$(get_abi_LIBDIR ${lsb_ldso_abi})/${lsb_ldso_name} ]] ; then
1448
		if [[ ! -L ${ED}/$(get_abi_LIBDIR ${lsb_ldso_abi})/${lsb_ldso_name} && ! -e ${ED}/$(get_abi_LIBDIR ${lsb_ldso_abi})/${lsb_ldso_name} ]] ; then
1445
			dosym ${native_ldso_name} "$(alt_prefix)/$(get_abi_LIBDIR ${lsb_ldso_abi})/${lsb_ldso_name}"
1449
			dosym ${native_ldso_name} "$(alt_prefix)/$(get_abi_LIBDIR ${lsb_ldso_abi})/${lsb_ldso_name}"
1446
		fi
1450
		fi
1447
	done
1451
	done
1448
1452
1449
	# With devpts under Linux mounted properly, we do not need the pt_chown
1453
	# With devpts under Linux mounted properly, we do not need the pt_chown
1450
	# binary to be setuid.  This is because the default owners/perms will be
1454
	# binary to be setuid.  This is because the default owners/perms will be
1451
	# exactly what we want.
1455
	# exactly what we want.
1452
	if ! use suid ; then
1456
	if ! use suid ; then
1453
		find "${ED}" -name pt_chown -exec chmod -s {} +
1457
		find "${ED}" -name pt_chown -exec chmod -s {} +
1454
	fi
1458
	fi
1455
1459
1456
	#################################################################
1460
	#################################################################
1457
	# EVERYTHING AFTER THIS POINT IS FOR NATIVE GLIBC INSTALLS ONLY #
1461
	# EVERYTHING AFTER THIS POINT IS FOR NATIVE GLIBC INSTALLS ONLY #
1458
	#################################################################
1462
	#################################################################
1459
1463
1460
	# Make sure we install some symlink hacks so that when we build
1464
	# Make sure we install some symlink hacks so that when we build
1461
	# a 2nd stage cross-compiler, gcc finds the target system
1465
	# a 2nd stage cross-compiler, gcc finds the target system
1462
	# headers correctly.  See gcc/doc/gccinstall.info
1466
	# headers correctly.  See gcc/doc/gccinstall.info
1463
	if is_crosscompile ; then
1467
	if is_crosscompile ; then
1464
		# We need to make sure that /lib and /usr/lib always exists.
1468
		# We need to make sure that /lib and /usr/lib always exists.
1465
		# gcc likes to use relative paths to get to its multilibs like
1469
		# gcc likes to use relative paths to get to its multilibs like
1466
		# /usr/lib/../lib64/.  So while we don't install any files into
1470
		# /usr/lib/../lib64/.  So while we don't install any files into
1467
		# /usr/lib/, we do need it to exist.
1471
		# /usr/lib/, we do need it to exist.
1468
		keepdir $(alt_prefix)/lib
1472
		keepdir $(alt_prefix)/lib
1469
		keepdir $(alt_prefix)/usr/lib
1473
		keepdir $(alt_prefix)/usr/lib
1470
1474
1471
		dosym usr/include $(alt_prefix)/sys-include
1475
		dosym usr/include $(alt_prefix)/sys-include
1472
		return 0
1476
		return 0
1473
	fi
1477
	fi
1474
1478
1475
	# Files for Debian-style locale updating
1479
	# Files for Debian-style locale updating
1476
	dodir /usr/share/i18n
1480
	dodir /usr/share/i18n
1477
	sed \
1481
	sed \
1478
		-e "/^#/d" \
1482
		-e "/^#/d" \
1479
		-e "/SUPPORTED-LOCALES=/d" \
1483
		-e "/SUPPORTED-LOCALES=/d" \
1480
		-e "s: \\\\::g" -e "s:/: :g" \
1484
		-e "s: \\\\::g" -e "s:/: :g" \
1481
		"${S}"/localedata/SUPPORTED > "${ED}"/usr/share/i18n/SUPPORTED \
1485
		"${S}"/localedata/SUPPORTED > "${ED}"/usr/share/i18n/SUPPORTED \
1482
		|| die "generating /usr/share/i18n/SUPPORTED failed"
1486
		|| die "generating /usr/share/i18n/SUPPORTED failed"
1483
1487
1484
	cd "${S}" || die
1488
	cd "${S}" || die
1485
1489
1486
	# Install misc network config files
1490
	# Install misc network config files
1487
	insinto /etc
1491
	insinto /etc
1488
	doins posix/gai.conf
1492
	doins posix/gai.conf
1489
1493
1490
	if use systemd ; then
1494
	if use systemd ; then
1491
		doins "${WORKDIR}/glibc-systemd-${GLIBC_SYSTEMD_VER}/gentoo-config/nsswitch.conf"
1495
		doins "${WORKDIR}/glibc-systemd-${GLIBC_SYSTEMD_VER}/gentoo-config/nsswitch.conf"
1492
	else
1496
	else
1493
		doins nss/nsswitch.conf
1497
		doins nss/nsswitch.conf
1494
	fi
1498
	fi
1495
1499
1496
	# Gentoo-specific
1500
	# Gentoo-specific
1497
	newins "${FILESDIR}"/host.conf-1 host.conf
1501
	newins "${FILESDIR}"/host.conf-1 host.conf
1498
1502
1499
	if use nscd ; then
1503
	if use nscd ; then
1500
		doins nscd/nscd.conf
1504
		doins nscd/nscd.conf
1501
1505
1502
		newinitd "$(prefixify_ro "${FILESDIR}"/nscd-1)" nscd
1506
		newinitd "$(prefixify_ro "${FILESDIR}"/nscd-1)" nscd
1503
1507
1504
		local nscd_args=(
1508
		local nscd_args=(
1505
			-e "s:@PIDFILE@:$(strings "${ED}"/usr/sbin/nscd | grep nscd.pid):"
1509
			-e "s:@PIDFILE@:$(strings "${ED}"/usr/sbin/nscd | grep nscd.pid):"
1506
		)
1510
		)
1507
1511
1508
		sed -i "${nscd_args[@]}" "${ED}"/etc/init.d/nscd
1512
		sed -i "${nscd_args[@]}" "${ED}"/etc/init.d/nscd
1509
1513
1510
		use systemd && systemd_dounit nscd/nscd.service
1514
		use systemd && systemd_dounit nscd/nscd.service
1511
		newtmpfiles nscd/nscd.tmpfiles nscd.conf
1515
		newtmpfiles nscd/nscd.tmpfiles nscd.conf
1512
	fi
1516
	fi
1513
1517
1514
	echo 'LDPATH="include ld.so.conf.d/*.conf"' > "${T}"/00glibc
1518
	echo 'LDPATH="include ld.so.conf.d/*.conf"' > "${T}"/00glibc
1515
	doenvd "${T}"/00glibc
1519
	doenvd "${T}"/00glibc
1516
1520
1517
	for d in BUGS ChangeLog CONFORMANCE FAQ NEWS NOTES PROJECTS README* ; do
1521
	for d in BUGS ChangeLog CONFORMANCE FAQ NEWS NOTES PROJECTS README* ; do
1518
		[[ -s ${d} ]] && dodoc ${d}
1522
		[[ -s ${d} ]] && dodoc ${d}
1519
	done
1523
	done
1520
	dodoc -r ChangeLog.old
1524
	dodoc -r ChangeLog.old
1521
1525
1522
	# Prevent overwriting of the /etc/localtime symlink.  We'll handle the
1526
	# Prevent overwriting of the /etc/localtime symlink.  We'll handle the
1523
	# creation of the "factory" symlink in pkg_postinst().
1527
	# creation of the "factory" symlink in pkg_postinst().
1524
	rm -f "${ED}"/etc/localtime
1528
	rm -f "${ED}"/etc/localtime
1525
1529
1526
	# Generate all locales if this is a native build as locale generation
1530
	# Generate all locales if this is a native build as locale generation
1527
	if use compile-locales && ! is_crosscompile ; then
1531
	if use compile-locales && ! is_crosscompile ; then
1528
		run_locale_gen --inplace-glibc "${ED}/"
1532
		run_locale_gen --inplace-glibc "${ED}/"
1529
	fi
1533
	fi
1530
}
1534
}
1531
1535
1532
glibc_headers_install() {
1536
glibc_headers_install() {
1533
	local builddir=$(builddir "headers")
1537
	local builddir=$(builddir "headers")
1534
	cd "${builddir}"
1538
	cd "${builddir}"
1535
	emake install_root="${D}/$(build_eprefix)$(alt_prefix)" install-headers
1539
	emake install_root="${D}/$(build_eprefix)$(alt_prefix)" install-headers
1536
1540
1537
	insinto $(alt_headers)/gnu
1541
	insinto $(alt_headers)/gnu
1538
	doins "${S}"/include/gnu/stubs.h
1542
	doins "${S}"/include/gnu/stubs.h
1539
1543
1540
	# Make sure we install the sys-include symlink so that when
1544
	# Make sure we install the sys-include symlink so that when
1541
	# we build a 2nd stage cross-compiler, gcc finds the target
1545
	# we build a 2nd stage cross-compiler, gcc finds the target
1542
	# system headers correctly.  See gcc/doc/gccinstall.info
1546
	# system headers correctly.  See gcc/doc/gccinstall.info
1543
	dosym usr/include $(alt_prefix)/sys-include
1547
	dosym usr/include $(alt_prefix)/sys-include
1544
}
1548
}
1545
1549
1546
src_install() {
1550
src_install() {
1547
	if just_headers ; then
1551
	if just_headers ; then
1548
		export ABI=default
1552
		export ABI=default
1549
		glibc_headers_install
1553
		glibc_headers_install
1550
		return
1554
		return
1551
	fi
1555
	fi
1552
1556
1553
	foreach_abi glibc_do_src_install
1557
	foreach_abi glibc_do_src_install
1554
1558
1555
	if ! use static-libs ; then
1559
	if ! use static-libs ; then
1556
		einfo "Not installing static glibc libraries"
1560
		einfo "Not installing static glibc libraries"
1557
		find "${ED}" -name "*.a" -and -not -name "*_nonshared.a" -delete
1561
		find "${ED}" -name "*.a" -and -not -name "*_nonshared.a" -delete
1558
	fi
1562
	fi
1559
}
1563
}
1560
1564
1561
# Simple test to make sure our new glibc isn't completely broken.
1565
# Simple test to make sure our new glibc isn't completely broken.
1562
# Make sure we don't test with statically built binaries since
1566
# Make sure we don't test with statically built binaries since
1563
# they will fail.  Also, skip if this glibc is a cross compiler.
1567
# they will fail.  Also, skip if this glibc is a cross compiler.
1564
#
1568
#
1565
# If coreutils is built with USE=multicall, some of these files
1569
# If coreutils is built with USE=multicall, some of these files
1566
# will just be wrapper scripts, not actual ELFs we can test.
1570
# will just be wrapper scripts, not actual ELFs we can test.
1567
glibc_sanity_check() {
1571
glibc_sanity_check() {
1568
	cd / #228809
1572
	cd / #228809
1569
1573
1570
	# We enter ${ED} so to avoid trouble if the path contains
1574
	# We enter ${ED} so to avoid trouble if the path contains
1571
	# special characters; for instance if the path contains the
1575
	# special characters; for instance if the path contains the
1572
	# colon character (:), then the linker will try to split it
1576
	# colon character (:), then the linker will try to split it
1573
	# and look for the libraries in an unexpected place. This can
1577
	# and look for the libraries in an unexpected place. This can
1574
	# lead to unsafe code execution if the generated prefix is
1578
	# lead to unsafe code execution if the generated prefix is
1575
	# within a world-writable directory.
1579
	# within a world-writable directory.
1576
	# (e.g. /var/tmp/portage:${HOSTNAME})
1580
	# (e.g. /var/tmp/portage:${HOSTNAME})
1577
	pushd "${ED}"/$(get_libdir) >/dev/null
1581
	pushd "${ED}"/$(get_libdir) >/dev/null
1578
1582
1579
	# first let's find the actual dynamic linker here
1583
	# first let's find the actual dynamic linker here
1580
	# symlinks may point to the wrong abi
1584
	# symlinks may point to the wrong abi
1581
	local newldso=$(find . -maxdepth 1 -name 'ld*so.?' -type f -print -quit)
1585
	local newldso=$(find . -maxdepth 1 -name 'ld*so.?' -type f -print -quit)
1582
1586
1583
	einfo Last-minute run tests with ${newldso} in /$(get_libdir) ...
1587
	einfo Last-minute run tests with ${newldso} in /$(get_libdir) ...
1584
1588
1585
	local x striptest
1589
	local x striptest
1586
	for x in cal date env free ls true uname uptime ; do
1590
	for x in cal date env free ls true uname uptime ; do
1587
		x=$(type -p ${x})
1591
		x=$(type -p ${x})
1588
		[[ -z ${x} || ${x} != ${EPREFIX}/* ]] && continue
1592
		[[ -z ${x} || ${x} != ${EPREFIX}/* ]] && continue
1589
		striptest=$(LC_ALL="C" file -L ${x} 2>/dev/null) || continue
1593
		striptest=$(LC_ALL="C" file -L ${x} 2>/dev/null) || continue
1590
		case ${striptest} in
1594
		case ${striptest} in
1591
		*"statically linked"*) continue;;
1595
		*"statically linked"*) continue;;
1592
		*"ASCII text"*) continue;;
1596
		*"ASCII text"*) continue;;
1593
		esac
1597
		esac
1594
		# We need to clear the locale settings as the upgrade might want
1598
		# We need to clear the locale settings as the upgrade might want
1595
		# incompatible locale data.  This test is not for verifying that.
1599
		# incompatible locale data.  This test is not for verifying that.
1596
		LC_ALL=C \
1600
		LC_ALL=C \
1597
		${newldso} --library-path . ${x} > /dev/null \
1601
		${newldso} --library-path . ${x} > /dev/null \
1598
			|| die "simple run test (${x}) failed"
1602
			|| die "simple run test (${x}) failed"
1599
	done
1603
	done
1600
1604
1601
	popd >/dev/null
1605
	popd >/dev/null
1602
}
1606
}
1603
1607
1604
pkg_preinst() {
1608
pkg_preinst() {
1605
	# nothing to do if just installing headers
1609
	# nothing to do if just installing headers
1606
	just_headers && return
1610
	just_headers && return
1607
1611
1608
	einfo "Checking general environment sanity."
1612
	einfo "Checking general environment sanity."
1609
	sanity_prechecks
1613
	sanity_prechecks
1610
1614
1611
	# prepare /etc/ld.so.conf.d/ for files
1615
	# prepare /etc/ld.so.conf.d/ for files
1612
	mkdir -p "${EROOT}"/etc/ld.so.conf.d
1616
	mkdir -p "${EROOT}"/etc/ld.so.conf.d
1613
1617
1614
	# Default /etc/hosts.conf:multi to on for systems with small dbs.
1618
	# Default /etc/hosts.conf:multi to on for systems with small dbs.
1615
	if [[ $(wc -l < "${EROOT}"/etc/hosts) -lt 1000 ]] ; then
1619
	if [[ $(wc -l < "${EROOT}"/etc/hosts) -lt 1000 ]] ; then
1616
		sed -i '/^multi off/s:off:on:' "${ED}"/etc/host.conf
1620
		sed -i '/^multi off/s:off:on:' "${ED}"/etc/host.conf
1617
		einfo "Defaulting /etc/host.conf:multi to on"
1621
		einfo "Defaulting /etc/host.conf:multi to on"
1618
	fi
1622
	fi
1619
1623
1620
	[[ -n ${ROOT} ]] && return 0
1624
	[[ -n ${ROOT} ]] && return 0
1621
	[[ -d ${ED}/$(get_libdir) ]] || return 0
1625
	[[ -d ${ED}/$(get_libdir) ]] || return 0
1622
	[[ -z ${BOOTSTRAP_RAP} ]] && glibc_sanity_check
1626
	[[ -z ${BOOTSTRAP_RAP} ]] && glibc_sanity_check
1623
1627
1624
	if [[ -L ${EROOT}/usr/lib/locale ]]; then
1628
	if [[ -L ${EROOT}/usr/lib/locale ]]; then
1625
		# Help portage migrate this to a directory
1629
		# Help portage migrate this to a directory
1626
		# https://bugs.gentoo.org/753740
1630
		# https://bugs.gentoo.org/753740
1627
		rm "${EROOT}"/usr/lib/locale || die
1631
		rm "${EROOT}"/usr/lib/locale || die
1628
	fi
1632
	fi
1629
1633
1630
	# Keep around libcrypt so that Perl doesn't break when merging libxcrypt
1634
	# Keep around libcrypt so that Perl doesn't break when merging libxcrypt
1631
	# (libxcrypt is the new provider for now of libcrypt.so.{1,2}).
1635
	# (libxcrypt is the new provider for now of libcrypt.so.{1,2}).
1632
	# bug #802207
1636
	# bug #802207
1633
	if ! use crypt && has_version "${CATEGORY}/${PN}[crypt]" && ! has preserve-libs ${FEATURES}; then
1637
	if ! use crypt && has_version "${CATEGORY}/${PN}[crypt]" && ! has preserve-libs ${FEATURES}; then
1634
		PRESERVED_OLD_LIBCRYPT=1
1638
		PRESERVED_OLD_LIBCRYPT=1
1635
		cp -p "${EROOT}/$(get_libdir)/libcrypt$(get_libname 1)" "${T}/libcrypt$(get_libname 1)" || die
1639
		cp -p "${EROOT}/$(get_libdir)/libcrypt$(get_libname 1)" "${T}/libcrypt$(get_libname 1)" || die
1636
	else
1640
	else
1637
		PRESERVED_OLD_LIBCRYPT=0
1641
		PRESERVED_OLD_LIBCRYPT=0
1638
	fi
1642
	fi
1639
}
1643
}
1640
1644
1641
pkg_postinst() {
1645
pkg_postinst() {
1642
	# nothing to do if just installing headers
1646
	# nothing to do if just installing headers
1643
	just_headers && return
1647
	just_headers && return
1644
1648
1645
	if ! tc-is-cross-compiler && [[ -x ${EROOT}/usr/sbin/iconvconfig ]] ; then
1649
	if ! tc-is-cross-compiler && [[ -x ${EROOT}/usr/sbin/iconvconfig ]] ; then
1646
		# Generate fastloading iconv module configuration file.
1650
		# Generate fastloading iconv module configuration file.
1647
		"${EROOT}"/usr/sbin/iconvconfig --prefix="${ROOT}/"
1651
		"${EROOT}"/usr/sbin/iconvconfig --prefix="${ROOT}/"
1648
	fi
1652
	fi
1649
1653
1650
	if ! is_crosscompile && [[ -z ${ROOT} ]] ; then
1654
	if ! is_crosscompile && [[ -z ${ROOT} ]] ; then
1651
		use compile-locales || run_locale_gen "${EROOT}/"
1655
		use compile-locales || run_locale_gen "${EROOT}/"
1652
	fi
1656
	fi
1653
1657
1654
	upgrade_warning
1658
	upgrade_warning
1655
1659
1656
	# Check for sanity of /etc/nsswitch.conf, take 2
1660
	# Check for sanity of /etc/nsswitch.conf, take 2
1657
	if [[ -e ${EROOT}/etc/nsswitch.conf ]] && ! has_version sys-auth/libnss-nis ; then
1661
	if [[ -e ${EROOT}/etc/nsswitch.conf ]] && ! has_version sys-auth/libnss-nis ; then
1658
		local entry
1662
		local entry
1659
		for entry in passwd group shadow; do
1663
		for entry in passwd group shadow; do
1660
			if grep -E -q "^[ \t]*${entry}:.*nis" "${EROOT}"/etc/nsswitch.conf; then
1664
			if grep -E -q "^[ \t]*${entry}:.*nis" "${EROOT}"/etc/nsswitch.conf; then
1661
				ewarn ""
1665
				ewarn ""
1662
				ewarn "Your ${EROOT}/etc/nsswitch.conf uses NIS. Support for that has been"
1666
				ewarn "Your ${EROOT}/etc/nsswitch.conf uses NIS. Support for that has been"
1663
				ewarn "removed from glibc and is now provided by the package"
1667
				ewarn "removed from glibc and is now provided by the package"
1664
				ewarn "  sys-auth/libnss-nis"
1668
				ewarn "  sys-auth/libnss-nis"
1665
				ewarn "Install it now to keep your NIS setup working."
1669
				ewarn "Install it now to keep your NIS setup working."
1666
				ewarn ""
1670
				ewarn ""
1667
			fi
1671
			fi
1668
		done
1672
		done
1669
	fi
1673
	fi
1670
1674
1671
	if [[ ${PRESERVED_OLD_LIBCRYPT} -eq 1 ]] ; then
1675
	if [[ ${PRESERVED_OLD_LIBCRYPT} -eq 1 ]] ; then
1672
		cp -p "${T}/libcrypt$(get_libname 1)" "${EROOT}/$(get_libdir)/libcrypt$(get_libname 1)" || die
1676
		cp -p "${T}/libcrypt$(get_libname 1)" "${EROOT}/$(get_libdir)/libcrypt$(get_libname 1)" || die
1673
		preserve_old_lib_notify /$(get_libdir)/libcrypt$(get_libname 1)
1677
		preserve_old_lib_notify /$(get_libdir)/libcrypt$(get_libname 1)
1674
1678
1675
		elog "Please ignore a possible later error message about a file collision involving"
1679
		elog "Please ignore a possible later error message about a file collision involving"
1676
		elog "${EROOT}/$(get_libdir)/libcrypt$(get_libname 1). We need to preserve this file for the moment to keep"
1680
		elog "${EROOT}/$(get_libdir)/libcrypt$(get_libname 1). We need to preserve this file for the moment to keep"
1677
		elog "the upgrade working, but it also needs to be overwritten when"
1681
		elog "the upgrade working, but it also needs to be overwritten when"
1678
		elog "sys-libs/libxcrypt is installed. See bug 802210 for more details."
1682
		elog "sys-libs/libxcrypt is installed. See bug 802210 for more details."
1679
	fi
1683
	fi
1680
}
1684
}
(-)a/sys-libs/glibc/glibc-2.38-r8.ebuild (-1 / +4 lines)
Lines 1-1714 Link Here
1
# Copyright 1999-2023 Gentoo Authors
1
# Copyright 1999-2023 Gentoo Authors
2
# Distributed under the terms of the GNU General Public License v2
2
# Distributed under the terms of the GNU General Public License v2
3
3
4
EAPI=8
4
EAPI=8
5
5
6
# Bumping notes: https://wiki.gentoo.org/wiki/Project:Toolchain/sys-libs/glibc
6
# Bumping notes: https://wiki.gentoo.org/wiki/Project:Toolchain/sys-libs/glibc
7
# Please read & adapt the page as necessary if obsolete.
7
# Please read & adapt the page as necessary if obsolete.
8
8
9
PYTHON_COMPAT=( python3_{9..12} )
9
PYTHON_COMPAT=( python3_{9..12} )
10
TMPFILES_OPTIONAL=1
10
TMPFILES_OPTIONAL=1
11
11
12
inherit python-any-r1 prefix preserve-libs toolchain-funcs flag-o-matic gnuconfig \
12
inherit python-any-r1 prefix preserve-libs toolchain-funcs flag-o-matic gnuconfig \
13
	multilib systemd multiprocessing tmpfiles
13
	multilib systemd multiprocessing tmpfiles
14
14
15
DESCRIPTION="GNU libc C library"
15
DESCRIPTION="GNU libc C library"
16
HOMEPAGE="https://www.gnu.org/software/libc/"
16
HOMEPAGE="https://www.gnu.org/software/libc/"
17
LICENSE="LGPL-2.1+ BSD HPND ISC inner-net rc PCRE"
17
LICENSE="LGPL-2.1+ BSD HPND ISC inner-net rc PCRE"
18
SLOT="2.2"
18
SLOT="2.2"
19
19
20
EMULTILIB_PKG="true"
20
EMULTILIB_PKG="true"
21
21
22
# Gentoo patchset (ignored for live ebuilds)
22
# Gentoo patchset (ignored for live ebuilds)
23
PATCH_VER=9
23
PATCH_VER=9
24
PATCH_DEV=dilfridge
24
PATCH_DEV=dilfridge
25
25
26
# gcc mulitilib bootstrap files version
26
# gcc mulitilib bootstrap files version
27
GCC_BOOTSTRAP_VER=20201208
27
GCC_BOOTSTRAP_VER=20201208
28
28
29
# systemd integration version
29
# systemd integration version
30
GLIBC_SYSTEMD_VER=20210729
30
GLIBC_SYSTEMD_VER=20210729
31
31
32
# Minimum kernel version that glibc requires
32
# Minimum kernel version that glibc requires
33
MIN_KERN_VER="3.2.0"
33
MIN_KERN_VER="3.2.0"
34
34
35
# Minimum pax-utils version needed (which contains any new syscall changes for
35
# Minimum pax-utils version needed (which contains any new syscall changes for
36
# its seccomp filter!). Please double check this!
36
# its seccomp filter!). Please double check this!
37
MIN_PAX_UTILS_VER="1.3.3"
37
MIN_PAX_UTILS_VER="1.3.3"
38
38
39
if [[ ${PV} == 9999* ]]; then
39
if [[ ${PV} == 9999* ]]; then
40
	inherit git-r3
40
	inherit git-r3
41
else
41
else
42
	# KEYWORDS="~alpha ~amd64 ~arm ~arm64 ~hppa ~ia64 ~loong ~m68k ~mips ~ppc ~ppc64 ~riscv ~s390 ~sparc ~x86"
42
	# KEYWORDS="~alpha ~amd64 ~arm ~arm64 ~hppa ~ia64 ~loong ~m68k ~mips ~ppc ~ppc64 ~riscv ~s390 ~sparc ~x86"
43
	SRC_URI="mirror://gnu/glibc/${P}.tar.xz"
43
	SRC_URI="mirror://gnu/glibc/${P}.tar.xz"
44
	SRC_URI+=" https://dev.gentoo.org/~${PATCH_DEV}/distfiles/${P}-patches-${PATCH_VER}.tar.xz"
44
	SRC_URI+=" https://dev.gentoo.org/~${PATCH_DEV}/distfiles/${P}-patches-${PATCH_VER}.tar.xz"
45
fi
45
fi
46
46
47
SRC_URI+=" multilib-bootstrap? ( https://dev.gentoo.org/~dilfridge/distfiles/gcc-multilib-bootstrap-${GCC_BOOTSTRAP_VER}.tar.xz )"
47
SRC_URI+=" multilib-bootstrap? ( https://dev.gentoo.org/~dilfridge/distfiles/gcc-multilib-bootstrap-${GCC_BOOTSTRAP_VER}.tar.xz )"
48
SRC_URI+=" systemd? ( https://gitweb.gentoo.org/proj/toolchain/glibc-systemd.git/snapshot/glibc-systemd-${GLIBC_SYSTEMD_VER}.tar.gz )"
48
SRC_URI+=" systemd? ( https://gitweb.gentoo.org/proj/toolchain/glibc-systemd.git/snapshot/glibc-systemd-${GLIBC_SYSTEMD_VER}.tar.gz )"
49
49
50
IUSE="audit caps cet compile-locales +crypt custom-cflags doc gd hash-sysv-compat headers-only +multiarch multilib multilib-bootstrap nscd perl profile selinux +ssp stack-realign +static-libs suid systemd systemtap test vanilla"
50
IUSE="audit caps cet compile-locales +crypt custom-cflags doc gd hash-sysv-compat headers-only +multiarch multilib multilib-bootstrap nscd perl profile selinux +ssp stack-realign +static-libs suid systemd systemtap test vanilla"
51
51
52
# Here's how the cross-compile logic breaks down ...
52
# Here's how the cross-compile logic breaks down ...
53
#  CTARGET - machine that will target the binaries
53
#  CTARGET - machine that will target the binaries
54
#  CHOST   - machine that will host the binaries
54
#  CHOST   - machine that will host the binaries
55
#  CBUILD  - machine that will build the binaries
55
#  CBUILD  - machine that will build the binaries
56
# If CTARGET != CHOST, it means you want a libc for cross-compiling.
56
# If CTARGET != CHOST, it means you want a libc for cross-compiling.
57
# If CHOST != CBUILD, it means you want to cross-compile the libc.
57
# If CHOST != CBUILD, it means you want to cross-compile the libc.
58
#  CBUILD = CHOST = CTARGET    - native build/install
58
#  CBUILD = CHOST = CTARGET    - native build/install
59
#  CBUILD != (CHOST = CTARGET) - cross-compile a native build
59
#  CBUILD != (CHOST = CTARGET) - cross-compile a native build
60
#  (CBUILD = CHOST) != CTARGET - libc for cross-compiler
60
#  (CBUILD = CHOST) != CTARGET - libc for cross-compiler
61
#  CBUILD != CHOST != CTARGET  - cross-compile a libc for a cross-compiler
61
#  CBUILD != CHOST != CTARGET  - cross-compile a libc for a cross-compiler
62
# For install paths:
62
# For install paths:
63
#  CHOST = CTARGET  - install into /
63
#  CHOST = CTARGET  - install into /
64
#  CHOST != CTARGET - install into /usr/CTARGET/
64
#  CHOST != CTARGET - install into /usr/CTARGET/
65
#
65
#
66
export CBUILD=${CBUILD:-${CHOST}}
66
export CBUILD=${CBUILD:-${CHOST}}
67
export CTARGET=${CTARGET:-${CHOST}}
67
export CTARGET=${CTARGET:-${CHOST}}
68
if [[ ${CTARGET} == ${CHOST} ]] ; then
68
if [[ ${CTARGET} == ${CHOST} ]] ; then
69
	if [[ ${CATEGORY} == cross-* ]] ; then
69
	if [[ ${CATEGORY} == cross-* ]] ; then
70
		export CTARGET=${CATEGORY#cross-}
70
		export CTARGET=${CATEGORY#cross-}
71
	fi
71
	fi
72
fi
72
fi
73
73
74
# Note [Disable automatic stripping]
74
# Note [Disable automatic stripping]
75
# Disabling automatic stripping for a few reasons:
75
# Disabling automatic stripping for a few reasons:
76
# - portage's attempt to strip breaks non-native binaries at least on
76
# - portage's attempt to strip breaks non-native binaries at least on
77
#   arm: bug #697428
77
#   arm: bug #697428
78
# - portage's attempt to strip libpthread.so.0 breaks gdb thread
78
# - portage's attempt to strip libpthread.so.0 breaks gdb thread
79
#   enumeration: bug #697910. This is quite subtle:
79
#   enumeration: bug #697910. This is quite subtle:
80
#   * gdb uses glibc's libthread_db-1.0.so to enumerate threads.
80
#   * gdb uses glibc's libthread_db-1.0.so to enumerate threads.
81
#   * libthread_db-1.0.so needs access to libpthread.so.0 local symbols
81
#   * libthread_db-1.0.so needs access to libpthread.so.0 local symbols
82
#     via 'ps_pglobal_lookup' symbol defined in gdb.
82
#     via 'ps_pglobal_lookup' symbol defined in gdb.
83
#   * 'ps_pglobal_lookup' uses '.symtab' section table to resolve all
83
#   * 'ps_pglobal_lookup' uses '.symtab' section table to resolve all
84
#     known symbols in 'libpthread.so.0'. Specifically 'nptl_version'
84
#     known symbols in 'libpthread.so.0'. Specifically 'nptl_version'
85
#     (unexported) is used to sanity check compatibility before enabling
85
#     (unexported) is used to sanity check compatibility before enabling
86
#     debugging.
86
#     debugging.
87
#     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
87
#     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
88
#   * normal 'strip' command trims '.symtab'
88
#   * normal 'strip' command trims '.symtab'
89
#   Thus our main goal here is to prevent 'libpthread.so.0' from
89
#   Thus our main goal here is to prevent 'libpthread.so.0' from
90
#   losing it's '.symtab' entries.
90
#   losing it's '.symtab' entries.
91
# - similarly, valgrind requires knowledge about symbols in ld.so:
92
#	bug #920753
91
# As Gentoo's strip does not allow us to pass less aggressive stripping
93
# As Gentoo's strip does not allow us to pass less aggressive stripping
92
# options and does not check the machine target we strip selectively.
94
# options and does not check the machine target we strip selectively.
93
95
94
# We need a new-enough binutils/gcc to match upstream baseline.
96
# We need a new-enough binutils/gcc to match upstream baseline.
95
# Also we need to make sure our binutils/gcc supports TLS,
97
# Also we need to make sure our binutils/gcc supports TLS,
96
# and that gcc already contains the hardened patches.
98
# and that gcc already contains the hardened patches.
97
# Lastly, let's avoid some openssh nastiness, bug 708224, as
99
# Lastly, let's avoid some openssh nastiness, bug 708224, as
98
# convenience to our users.
100
# convenience to our users.
99
101
100
IDEPEND="
102
IDEPEND="
101
	!compile-locales? ( sys-apps/locale-gen )
103
	!compile-locales? ( sys-apps/locale-gen )
102
"
104
"
103
BDEPEND="
105
BDEPEND="
104
	${PYTHON_DEPS}
106
	${PYTHON_DEPS}
105
	>=app-misc/pax-utils-${MIN_PAX_UTILS_VER}
107
	>=app-misc/pax-utils-${MIN_PAX_UTILS_VER}
106
	sys-devel/bison
108
	sys-devel/bison
107
	compile-locales? ( sys-apps/locale-gen )
109
	compile-locales? ( sys-apps/locale-gen )
108
	doc? (
110
	doc? (
109
		dev-lang/perl
111
		dev-lang/perl
110
		sys-apps/texinfo
112
		sys-apps/texinfo
111
	)
113
	)
112
	test? (
114
	test? (
113
		dev-lang/perl
115
		dev-lang/perl
114
		>=net-dns/libidn2-2.3.0
116
		>=net-dns/libidn2-2.3.0
115
	)
117
	)
116
"
118
"
117
COMMON_DEPEND="
119
COMMON_DEPEND="
118
	gd? ( media-libs/gd:2= )
120
	gd? ( media-libs/gd:2= )
119
	nscd? ( selinux? (
121
	nscd? ( selinux? (
120
		audit? ( sys-process/audit )
122
		audit? ( sys-process/audit )
121
		caps? ( sys-libs/libcap )
123
		caps? ( sys-libs/libcap )
122
	) )
124
	) )
123
	suid? ( caps? ( sys-libs/libcap ) )
125
	suid? ( caps? ( sys-libs/libcap ) )
124
	selinux? ( sys-libs/libselinux )
126
	selinux? ( sys-libs/libselinux )
125
	systemtap? ( dev-util/systemtap )
127
	systemtap? ( dev-util/systemtap )
126
"
128
"
127
DEPEND="${COMMON_DEPEND}
129
DEPEND="${COMMON_DEPEND}
128
"
130
"
129
RDEPEND="${COMMON_DEPEND}
131
RDEPEND="${COMMON_DEPEND}
130
	!<app-misc/pax-utils-${MIN_PAX_UTILS_VER}
132
	!<app-misc/pax-utils-${MIN_PAX_UTILS_VER}
131
	perl? ( dev-lang/perl )
133
	perl? ( dev-lang/perl )
132
"
134
"
133
135
134
RESTRICT="!test? ( test )"
136
RESTRICT="!test? ( test )"
135
137
136
if [[ ${CATEGORY} == cross-* ]] ; then
138
if [[ ${CATEGORY} == cross-* ]] ; then
137
	BDEPEND+=" !headers-only? (
139
	BDEPEND+=" !headers-only? (
138
		>=${CATEGORY}/binutils-2.27
140
		>=${CATEGORY}/binutils-2.27
139
		>=${CATEGORY}/gcc-6.2
141
		>=${CATEGORY}/gcc-6.2
140
	)"
142
	)"
141
	[[ ${CATEGORY} == *-linux* ]] && DEPEND+=" ${CATEGORY}/linux-headers"
143
	[[ ${CATEGORY} == *-linux* ]] && DEPEND+=" ${CATEGORY}/linux-headers"
142
else
144
else
143
	BDEPEND+="
145
	BDEPEND+="
144
		>=sys-devel/binutils-2.27
146
		>=sys-devel/binutils-2.27
145
		>=sys-devel/gcc-6.2
147
		>=sys-devel/gcc-6.2
146
	"
148
	"
147
	DEPEND+=" virtual/os-headers "
149
	DEPEND+=" virtual/os-headers "
148
	RDEPEND+="
150
	RDEPEND+="
149
		>=net-dns/libidn2-2.3.0
151
		>=net-dns/libidn2-2.3.0
150
		vanilla? ( !sys-libs/timezone-data )
152
		vanilla? ( !sys-libs/timezone-data )
151
	"
153
	"
152
	PDEPEND+=" !vanilla? ( sys-libs/timezone-data )"
154
	PDEPEND+=" !vanilla? ( sys-libs/timezone-data )"
153
fi
155
fi
154
156
155
# Ignore tests whitelisted below
157
# Ignore tests whitelisted below
156
GENTOO_GLIBC_XFAIL_TESTS="${GENTOO_GLIBC_XFAIL_TESTS:-yes}"
158
GENTOO_GLIBC_XFAIL_TESTS="${GENTOO_GLIBC_XFAIL_TESTS:-yes}"
157
159
158
# The following tests fail due to the Gentoo build system and are thus
160
# The following tests fail due to the Gentoo build system and are thus
159
# executed but ignored:
161
# executed but ignored:
160
XFAIL_TEST_LIST=(
162
XFAIL_TEST_LIST=(
161
	# buggy test, assumes /dev/ and /dev/null on a single filesystem
163
	# buggy test, assumes /dev/ and /dev/null on a single filesystem
162
	# 'mount --bind /dev/null /chroot/dev/null' breaks it.
164
	# 'mount --bind /dev/null /chroot/dev/null' breaks it.
163
	# https://sourceware.org/PR25909
165
	# https://sourceware.org/PR25909
164
	tst-support_descriptors
166
	tst-support_descriptors
165
167
166
	# The following tests fail only inside portage
168
	# The following tests fail only inside portage
167
	# https://bugs.gentoo.org/831267
169
	# https://bugs.gentoo.org/831267
168
	tst-system
170
	tst-system
169
	tst-strerror
171
	tst-strerror
170
	tst-strsignal
172
	tst-strsignal
171
	# Fails with certain PORTAGE_NICENESS/PORTAGE_SCHEDULING_POLICY
173
	# Fails with certain PORTAGE_NICENESS/PORTAGE_SCHEDULING_POLICY
172
	tst-sched1
174
	tst-sched1
173
)
175
)
174
176
175
XFAIL_NSPAWN_TEST_LIST=(
177
XFAIL_NSPAWN_TEST_LIST=(
176
	# These tests need to be adapted to handle EPERM/ENOSYS(?) properly
178
	# These tests need to be adapted to handle EPERM/ENOSYS(?) properly
177
	# upstream, as systemd-nspawn's default seccomp whitelist is too strict.
179
	# upstream, as systemd-nspawn's default seccomp whitelist is too strict.
178
	# https://sourceware.org/PR30603
180
	# https://sourceware.org/PR30603
179
	test-errno-linux
181
	test-errno-linux
180
	tst-bz21269
182
	tst-bz21269
181
	tst-mlock2
183
	tst-mlock2
182
	tst-ntp_gettime
184
	tst-ntp_gettime
183
	tst-ntp_gettime-time64
185
	tst-ntp_gettime-time64
184
	tst-ntp_gettimex
186
	tst-ntp_gettimex
185
	tst-ntp_gettimex-time64
187
	tst-ntp_gettimex-time64
186
	tst-pkey
188
	tst-pkey
187
	tst-process_mrelease
189
	tst-process_mrelease
188
	tst-adjtime
190
	tst-adjtime
189
	tst-adjtime-time64
191
	tst-adjtime-time64
190
	tst-clock2
192
	tst-clock2
191
	tst-clock2-time64
193
	tst-clock2-time64
192
194
193
	# These fail if --suppress-sync and/or low priority is set
195
	# These fail if --suppress-sync and/or low priority is set
194
	tst-sync_file_range
196
	tst-sync_file_range
195
	test-errno
197
	test-errno
196
)
198
)
197
199
198
#
200
#
199
# Small helper functions
201
# Small helper functions
200
#
202
#
201
203
202
dump_build_environment() {
204
dump_build_environment() {
203
	einfo ==== glibc build environment ========================================================
205
	einfo ==== glibc build environment ========================================================
204
	local v
206
	local v
205
	for v in ABI CBUILD CHOST CTARGET CBUILD_OPT CTARGET_OPT CC CXX CPP LD {AS,C,CPP,CXX,LD}FLAGS MAKEINFO NM AR AS STRIP RANLIB OBJCOPY STRINGS OBJDUMP READELF; do
207
	for v in ABI CBUILD CHOST CTARGET CBUILD_OPT CTARGET_OPT CC CXX CPP LD {AS,C,CPP,CXX,LD}FLAGS MAKEINFO NM AR AS STRIP RANLIB OBJCOPY STRINGS OBJDUMP READELF; do
206
		einfo " $(printf '%15s' ${v}:)   ${!v}"
208
		einfo " $(printf '%15s' ${v}:)   ${!v}"
207
	done
209
	done
208
	einfo =====================================================================================
210
	einfo =====================================================================================
209
}
211
}
210
212
211
is_crosscompile() {
213
is_crosscompile() {
212
	[[ ${CHOST} != ${CTARGET} ]]
214
	[[ ${CHOST} != ${CTARGET} ]]
213
}
215
}
214
216
215
just_headers() {
217
just_headers() {
216
	is_crosscompile && use headers-only
218
	is_crosscompile && use headers-only
217
}
219
}
218
220
219
alt_prefix() {
221
alt_prefix() {
220
	is_crosscompile && echo /usr/${CTARGET}
222
	is_crosscompile && echo /usr/${CTARGET}
221
}
223
}
222
224
223
# This prefix is applicable to CHOST when building against this
225
# This prefix is applicable to CHOST when building against this
224
# glibc. It is baked into the library at configure time.
226
# glibc. It is baked into the library at configure time.
225
host_eprefix() {
227
host_eprefix() {
226
	is_crosscompile || echo "${EPREFIX}"
228
	is_crosscompile || echo "${EPREFIX}"
227
}
229
}
228
230
229
# This prefix is applicable to CBUILD when building against this
231
# This prefix is applicable to CBUILD when building against this
230
# glibc. It determines the destination path at install time.
232
# glibc. It determines the destination path at install time.
231
build_eprefix() {
233
build_eprefix() {
232
	is_crosscompile && echo "${EPREFIX}"
234
	is_crosscompile && echo "${EPREFIX}"
233
}
235
}
234
236
235
# We need to be able to set alternative headers for compiling for non-native
237
# We need to be able to set alternative headers for compiling for non-native
236
# platform. Will also become useful for testing kernel-headers without screwing
238
# platform. Will also become useful for testing kernel-headers without screwing
237
# up the whole system.
239
# up the whole system.
238
alt_headers() {
240
alt_headers() {
239
	echo ${ALT_HEADERS:=$(alt_prefix)/usr/include}
241
	echo ${ALT_HEADERS:=$(alt_prefix)/usr/include}
240
}
242
}
241
243
242
alt_build_headers() {
244
alt_build_headers() {
243
	if [[ -z ${ALT_BUILD_HEADERS} ]] ; then
245
	if [[ -z ${ALT_BUILD_HEADERS} ]] ; then
244
		ALT_BUILD_HEADERS="$(host_eprefix)$(alt_headers)"
246
		ALT_BUILD_HEADERS="$(host_eprefix)$(alt_headers)"
245
		if tc-is-cross-compiler ; then
247
		if tc-is-cross-compiler ; then
246
			ALT_BUILD_HEADERS=${SYSROOT}$(alt_headers)
248
			ALT_BUILD_HEADERS=${SYSROOT}$(alt_headers)
247
			if [[ ! -e ${ALT_BUILD_HEADERS}/linux/version.h ]] ; then
249
			if [[ ! -e ${ALT_BUILD_HEADERS}/linux/version.h ]] ; then
248
				local header_path=$(echo '#include <linux/version.h>' | $(tc-getCPP ${CTARGET}) ${CFLAGS} 2>&1 | grep -o '[^"]*linux/version.h')
250
				local header_path=$(echo '#include <linux/version.h>' | $(tc-getCPP ${CTARGET}) ${CFLAGS} 2>&1 | grep -o '[^"]*linux/version.h')
249
				ALT_BUILD_HEADERS=${header_path%/linux/version.h}
251
				ALT_BUILD_HEADERS=${header_path%/linux/version.h}
250
			fi
252
			fi
251
		fi
253
		fi
252
	fi
254
	fi
253
	echo "${ALT_BUILD_HEADERS}"
255
	echo "${ALT_BUILD_HEADERS}"
254
}
256
}
255
257
256
alt_libdir() {
258
alt_libdir() {
257
	echo $(alt_prefix)/$(get_libdir)
259
	echo $(alt_prefix)/$(get_libdir)
258
}
260
}
259
alt_usrlibdir() {
261
alt_usrlibdir() {
260
	echo $(alt_prefix)/usr/$(get_libdir)
262
	echo $(alt_prefix)/usr/$(get_libdir)
261
}
263
}
262
264
263
builddir() {
265
builddir() {
264
	echo "${WORKDIR}/build-${ABI}-${CTARGET}-$1"
266
	echo "${WORKDIR}/build-${ABI}-${CTARGET}-$1"
265
}
267
}
266
268
267
do_compile_test() {
269
do_compile_test() {
268
	local ret save_cflags=${CFLAGS}
270
	local ret save_cflags=${CFLAGS}
269
	CFLAGS+=" $1"
271
	CFLAGS+=" $1"
270
	shift
272
	shift
271
273
272
	pushd "${T}" >/dev/null
274
	pushd "${T}" >/dev/null
273
275
274
	rm -f glibc-test*
276
	rm -f glibc-test*
275
	printf '%b' "$*" > glibc-test.c
277
	printf '%b' "$*" > glibc-test.c
276
278
277
	# We assume CC is already set up.
279
	# We assume CC is already set up.
278
	nonfatal emake glibc-test
280
	nonfatal emake glibc-test
279
	ret=$?
281
	ret=$?
280
282
281
	popd >/dev/null
283
	popd >/dev/null
282
284
283
	CFLAGS=${save_cflags}
285
	CFLAGS=${save_cflags}
284
	return ${ret}
286
	return ${ret}
285
}
287
}
286
288
287
do_run_test() {
289
do_run_test() {
288
	local ret
290
	local ret
289
291
290
	if [[ ${MERGE_TYPE} == "binary" ]] ; then
292
	if [[ ${MERGE_TYPE} == "binary" ]] ; then
291
		# ignore build failures when installing a binary package #324685
293
		# ignore build failures when installing a binary package #324685
292
		do_compile_test "" "$@" 2>/dev/null || return 0
294
		do_compile_test "" "$@" 2>/dev/null || return 0
293
	else
295
	else
294
		if ! do_compile_test "" "$@" ; then
296
		if ! do_compile_test "" "$@" ; then
295
			ewarn "Simple build failed ... assuming this is desired #324685"
297
			ewarn "Simple build failed ... assuming this is desired #324685"
296
			return 0
298
			return 0
297
		fi
299
		fi
298
	fi
300
	fi
299
301
300
	pushd "${T}" >/dev/null
302
	pushd "${T}" >/dev/null
301
303
302
	./glibc-test
304
	./glibc-test
303
	ret=$?
305
	ret=$?
304
	rm -f glibc-test*
306
	rm -f glibc-test*
305
307
306
	popd >/dev/null
308
	popd >/dev/null
307
309
308
	return ${ret}
310
	return ${ret}
309
}
311
}
310
312
311
setup_target_flags() {
313
setup_target_flags() {
312
	# This largely mucks with compiler flags.  None of which should matter
314
	# This largely mucks with compiler flags.  None of which should matter
313
	# when building up just the headers.
315
	# when building up just the headers.
314
	just_headers && return 0
316
	just_headers && return 0
315
317
316
	case $(tc-arch) in
318
	case $(tc-arch) in
317
		x86)
319
		x86)
318
			# -march needed for #185404 #199334
320
			# -march needed for #185404 #199334
319
			# TODO: When creating the first glibc cross-compile, this test will
321
			# TODO: When creating the first glibc cross-compile, this test will
320
			# always fail as it does a full link which in turn requires glibc.
322
			# always fail as it does a full link which in turn requires glibc.
321
			# Probably also applies when changing multilib profile settings (e.g.
323
			# Probably also applies when changing multilib profile settings (e.g.
322
			# enabling x86 when the profile was amd64-only previously).
324
			# enabling x86 when the profile was amd64-only previously).
323
			# We could change main to _start and pass -nostdlib here so that we
325
			# We could change main to _start and pass -nostdlib here so that we
324
			# only test the gcc code compilation.  Or we could do a compile and
326
			# only test the gcc code compilation.  Or we could do a compile and
325
			# then look for the symbol via scanelf.
327
			# then look for the symbol via scanelf.
326
			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
328
			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
327
				local t=${CTARGET_OPT:-${CTARGET}}
329
				local t=${CTARGET_OPT:-${CTARGET}}
328
				t=${t%%-*}
330
				t=${t%%-*}
329
				filter-flags '-march=*'
331
				filter-flags '-march=*'
330
				export CFLAGS="-march=${t} ${CFLAGS}"
332
				export CFLAGS="-march=${t} ${CFLAGS}"
331
				einfo "Auto adding -march=${t} to CFLAGS #185404"
333
				einfo "Auto adding -march=${t} to CFLAGS #185404"
332
			fi
334
			fi
333
			# For compatibility with older binaries at slight performance cost.
335
			# For compatibility with older binaries at slight performance cost.
334
			use stack-realign && export CFLAGS+=" -mstackrealign"
336
			use stack-realign && export CFLAGS+=" -mstackrealign"
335
		;;
337
		;;
336
		amd64)
338
		amd64)
337
			# -march needed for #185404 #199334
339
			# -march needed for #185404 #199334
338
			# TODO: See cross-compile issues listed above for x86.
340
			# TODO: See cross-compile issues listed above for x86.
339
			if [[ ${ABI} == x86 ]]; then
341
			if [[ ${ABI} == x86 ]]; then
340
				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
342
				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
341
					local t=${CTARGET_OPT:-${CTARGET}}
343
					local t=${CTARGET_OPT:-${CTARGET}}
342
					t=${t%%-*}
344
					t=${t%%-*}
343
					# Normally the target is x86_64-xxx, so turn that into the -march that
345
					# Normally the target is x86_64-xxx, so turn that into the -march that
344
					# gcc actually accepts. #528708
346
					# gcc actually accepts. #528708
345
					[[ ${t} == "x86_64" ]] && t="x86-64"
347
					[[ ${t} == "x86_64" ]] && t="x86-64"
346
					filter-flags '-march=*'
348
					filter-flags '-march=*'
347
					# ugly, ugly, ugly.  ugly.
349
					# ugly, ugly, ugly.  ugly.
348
					CFLAGS_x86=$(CFLAGS=${CFLAGS_x86} filter-flags '-march=*'; echo "${CFLAGS}")
350
					CFLAGS_x86=$(CFLAGS=${CFLAGS_x86} filter-flags '-march=*'; echo "${CFLAGS}")
349
					export CFLAGS_x86="${CFLAGS_x86} -march=${t}"
351
					export CFLAGS_x86="${CFLAGS_x86} -march=${t}"
350
					einfo "Auto adding -march=${t} to CFLAGS_x86 #185404 (ABI=${ABI})"
352
					einfo "Auto adding -march=${t} to CFLAGS_x86 #185404 (ABI=${ABI})"
351
				fi
353
				fi
352
				# For compatibility with older binaries at slight performance cost.
354
				# For compatibility with older binaries at slight performance cost.
353
				use stack-realign && export CFLAGS_x86+=" -mstackrealign"
355
				use stack-realign && export CFLAGS_x86+=" -mstackrealign"
354
356
355
				# Workaround for bug #823780.
357
				# Workaround for bug #823780.
356
				# Need to save/restore CC because earlier on, we stuff it full of CFLAGS, and tc-getCPP doesn't like that.
358
				# Need to save/restore CC because earlier on, we stuff it full of CFLAGS, and tc-getCPP doesn't like that.
357
				CC_mangled=${CC}
359
				CC_mangled=${CC}
358
				CC=${glibc__GLIBC_CC}
360
				CC=${glibc__GLIBC_CC}
359
				if tc-is-gcc && (($(gcc-major-version) == 11)) && (($(gcc-minor-version) <= 2)) && (($(gcc-micro-version) == 0)) ; then
361
				if tc-is-gcc && (($(gcc-major-version) == 11)) && (($(gcc-minor-version) <= 2)) && (($(gcc-micro-version) == 0)) ; then
360
					export CFLAGS_x86="${CFLAGS_x86} -mno-avx512f"
362
					export CFLAGS_x86="${CFLAGS_x86} -mno-avx512f"
361
					einfo "Auto adding -mno-avx512f to CFLAGS_x86 for buggy GCC version (bug #823780) (ABI=${ABI})"
363
					einfo "Auto adding -mno-avx512f to CFLAGS_x86 for buggy GCC version (bug #823780) (ABI=${ABI})"
362
				fi
364
				fi
363
				CC=${CC_mangled}
365
				CC=${CC_mangled}
364
			fi
366
			fi
365
		;;
367
		;;
366
		mips)
368
		mips)
367
			# The mips abi cannot support the GNU style hashes. #233233
369
			# The mips abi cannot support the GNU style hashes. #233233
368
			filter-ldflags -Wl,--hash-style=gnu -Wl,--hash-style=both
370
			filter-ldflags -Wl,--hash-style=gnu -Wl,--hash-style=both
369
		;;
371
		;;
370
		ppc|ppc64)
372
		ppc|ppc64)
371
			# Many arch-specific implementations do not work on ppc with
373
			# Many arch-specific implementations do not work on ppc with
372
			# cache-block not equal to 128 bytes. This breaks memset:
374
			# cache-block not equal to 128 bytes. This breaks memset:
373
			#   https://sourceware.org/PR26522
375
			#   https://sourceware.org/PR26522
374
			#   https://bugs.gentoo.org/737996
376
			#   https://bugs.gentoo.org/737996
375
			# Use default -mcpu=. For ppc it means non-multiarch setup.
377
			# Use default -mcpu=. For ppc it means non-multiarch setup.
376
			filter-flags '-mcpu=*'
378
			filter-flags '-mcpu=*'
377
		;;
379
		;;
378
		sparc)
380
		sparc)
379
			# Both sparc and sparc64 can use -fcall-used-g6.  -g7 is bad, though.
381
			# Both sparc and sparc64 can use -fcall-used-g6.  -g7 is bad, though.
380
			filter-flags "-fcall-used-g7"
382
			filter-flags "-fcall-used-g7"
381
			append-flags "-fcall-used-g6"
383
			append-flags "-fcall-used-g6"
382
384
383
			local cpu
385
			local cpu
384
			case ${CTARGET} in
386
			case ${CTARGET} in
385
			sparc64-*)
387
			sparc64-*)
386
				cpu="sparc64"
388
				cpu="sparc64"
387
				case $(get-flag mcpu) in
389
				case $(get-flag mcpu) in
388
				v9)
390
				v9)
389
					# We need to force at least v9a because the base build doesn't
391
					# We need to force at least v9a because the base build doesn't
390
					# work with just v9.
392
					# work with just v9.
391
					# https://sourceware.org/bugzilla/show_bug.cgi?id=19477
393
					# https://sourceware.org/bugzilla/show_bug.cgi?id=19477
392
					append-flags "-Wa,-xarch=v9a"
394
					append-flags "-Wa,-xarch=v9a"
393
					;;
395
					;;
394
				esac
396
				esac
395
				;;
397
				;;
396
			sparc-*)
398
			sparc-*)
397
				case $(get-flag mcpu) in
399
				case $(get-flag mcpu) in
398
				v8|supersparc|hypersparc|leon|leon3)
400
				v8|supersparc|hypersparc|leon|leon3)
399
					cpu="sparcv8"
401
					cpu="sparcv8"
400
					;;
402
					;;
401
				*)
403
				*)
402
					cpu="sparcv9"
404
					cpu="sparcv9"
403
					;;
405
					;;
404
				esac
406
				esac
405
			;;
407
			;;
406
			esac
408
			esac
407
			[[ -n ${cpu} ]] && CTARGET_OPT="${cpu}-${CTARGET#*-}"
409
			[[ -n ${cpu} ]] && CTARGET_OPT="${cpu}-${CTARGET#*-}"
408
		;;
410
		;;
409
	esac
411
	esac
410
}
412
}
411
413
412
setup_flags() {
414
setup_flags() {
413
	# Make sure host make.conf doesn't pollute us
415
	# Make sure host make.conf doesn't pollute us
414
	if is_crosscompile || tc-is-cross-compiler ; then
416
	if is_crosscompile || tc-is-cross-compiler ; then
415
		CHOST=${CTARGET} strip-unsupported-flags
417
		CHOST=${CTARGET} strip-unsupported-flags
416
	fi
418
	fi
417
419
418
	# Store our CFLAGS because it's changed depending on which CTARGET
420
	# Store our CFLAGS because it's changed depending on which CTARGET
419
	# we are building when pulling glibc on a multilib profile
421
	# we are building when pulling glibc on a multilib profile
420
	CFLAGS_BASE=${CFLAGS_BASE-${CFLAGS}}
422
	CFLAGS_BASE=${CFLAGS_BASE-${CFLAGS}}
421
	CFLAGS=${CFLAGS_BASE}
423
	CFLAGS=${CFLAGS_BASE}
422
	CXXFLAGS_BASE=${CXXFLAGS_BASE-${CXXFLAGS}}
424
	CXXFLAGS_BASE=${CXXFLAGS_BASE-${CXXFLAGS}}
423
	CXXFLAGS=${CXXFLAGS_BASE}
425
	CXXFLAGS=${CXXFLAGS_BASE}
424
	ASFLAGS_BASE=${ASFLAGS_BASE-${ASFLAGS}}
426
	ASFLAGS_BASE=${ASFLAGS_BASE-${ASFLAGS}}
425
	ASFLAGS=${ASFLAGS_BASE}
427
	ASFLAGS=${ASFLAGS_BASE}
426
428
427
	# Allow users to explicitly avoid flag sanitization via
429
	# Allow users to explicitly avoid flag sanitization via
428
	# USE=custom-cflags.
430
	# USE=custom-cflags.
429
	if ! use custom-cflags; then
431
	if ! use custom-cflags; then
430
		# Over-zealous CFLAGS can often cause problems.  What may work for one
432
		# Over-zealous CFLAGS can often cause problems.  What may work for one
431
		# person may not work for another.  To avoid a large influx of bugs
433
		# person may not work for another.  To avoid a large influx of bugs
432
		# relating to failed builds, we strip most CFLAGS out to ensure as few
434
		# relating to failed builds, we strip most CFLAGS out to ensure as few
433
		# problems as possible.
435
		# problems as possible.
434
		strip-flags
436
		strip-flags
435
		# Lock glibc at -O2; we want to be conservative here.
437
		# Lock glibc at -O2; we want to be conservative here.
436
		filter-flags '-O?'
438
		filter-flags '-O?'
437
		append-flags -O2
439
		append-flags -O2
438
	fi
440
	fi
439
441
440
	strip-unsupported-flags
442
	strip-unsupported-flags
441
	filter-lto
443
	filter-lto
442
	filter-flags -m32 -m64 '-mabi=*'
444
	filter-flags -m32 -m64 '-mabi=*'
443
445
444
	# glibc aborts if rpath is set by LDFLAGS
446
	# glibc aborts if rpath is set by LDFLAGS
445
	filter-ldflags '-Wl,-rpath=*'
447
	filter-ldflags '-Wl,-rpath=*'
446
448
447
	# ld can't use -r & --relax at the same time, bug #788901
449
	# ld can't use -r & --relax at the same time, bug #788901
448
	# https://sourceware.org/PR27837
450
	# https://sourceware.org/PR27837
449
	filter-ldflags '-Wl,--relax'
451
	filter-ldflags '-Wl,--relax'
450
452
451
	# Flag added for cross-prefix, but causes ldconfig to segfault. Not needed
453
	# Flag added for cross-prefix, but causes ldconfig to segfault. Not needed
452
	# anyway because glibc already handles this by itself.
454
	# anyway because glibc already handles this by itself.
453
	filter-ldflags '-Wl,--dynamic-linker=*'
455
	filter-ldflags '-Wl,--dynamic-linker=*'
454
456
455
	# some weird software relies on sysv hashes in glibc, bug 863863, bug 864100
457
	# some weird software relies on sysv hashes in glibc, bug 863863, bug 864100
456
	# we have to do that here already so mips can filter it out again :P
458
	# we have to do that here already so mips can filter it out again :P
457
	if use hash-sysv-compat ; then
459
	if use hash-sysv-compat ; then
458
		append-ldflags '-Wl,--hash-style=both'
460
		append-ldflags '-Wl,--hash-style=both'
459
	fi
461
	fi
460
462
461
	# #492892
463
	# #492892
462
	filter-flags -frecord-gcc-switches
464
	filter-flags -frecord-gcc-switches
463
465
464
	# #898098
466
	# #898098
465
	filter-flags -fno-builtin
467
	filter-flags -fno-builtin
466
468
467
	# #829583
469
	# #829583
468
	filter-lfs-flags
470
	filter-lfs-flags
469
471
470
	unset CBUILD_OPT CTARGET_OPT
472
	unset CBUILD_OPT CTARGET_OPT
471
	if use multilib ; then
473
	if use multilib ; then
472
		CTARGET_OPT=$(get_abi_CTARGET)
474
		CTARGET_OPT=$(get_abi_CTARGET)
473
		[[ -z ${CTARGET_OPT} ]] && CTARGET_OPT=$(get_abi_CHOST)
475
		[[ -z ${CTARGET_OPT} ]] && CTARGET_OPT=$(get_abi_CHOST)
474
	fi
476
	fi
475
477
476
	setup_target_flags
478
	setup_target_flags
477
479
478
	if [[ -n ${CTARGET_OPT} && ${CBUILD} == ${CHOST} ]] && ! is_crosscompile; then
480
	if [[ -n ${CTARGET_OPT} && ${CBUILD} == ${CHOST} ]] && ! is_crosscompile; then
479
		CBUILD_OPT=${CTARGET_OPT}
481
		CBUILD_OPT=${CTARGET_OPT}
480
	fi
482
	fi
481
483
482
	# glibc's headers disallow -O0 and fail at build time:
484
	# glibc's headers disallow -O0 and fail at build time:
483
	#  include/libc-symbols.h:75:3: #error "glibc cannot be compiled without optimization"
485
	#  include/libc-symbols.h:75:3: #error "glibc cannot be compiled without optimization"
484
	# https://sourceware.org/glibc/wiki/FAQ#Why_do_I_get:.60.23error_.22glibc_cannot_be_compiled_without_optimization.22.27.2C_when_trying_to_compile_GNU_libc_with_GNU_CC.3F
486
	# https://sourceware.org/glibc/wiki/FAQ#Why_do_I_get:.60.23error_.22glibc_cannot_be_compiled_without_optimization.22.27.2C_when_trying_to_compile_GNU_libc_with_GNU_CC.3F
485
	replace-flags -O0 -O1
487
	replace-flags -O0 -O1
486
488
487
	# glibc handles this internally already where it's appropriate;
489
	# glibc handles this internally already where it's appropriate;
488
	# can't always have SSP when we're the ones setting it up, etc
490
	# can't always have SSP when we're the ones setting it up, etc
489
	filter-flags '-fstack-protector*'
491
	filter-flags '-fstack-protector*'
490
492
491
	# Similar issues as with SSP. Can't inject yourself that early.
493
	# Similar issues as with SSP. Can't inject yourself that early.
492
	filter-flags '-fsanitize=*'
494
	filter-flags '-fsanitize=*'
493
495
494
	# See end of bug #830454; we handle this via USE=cet
496
	# See end of bug #830454; we handle this via USE=cet
495
	filter-flags '-fcf-protection=*'
497
	filter-flags '-fcf-protection=*'
496
498
497
	# When bootstrapping, we may have a situation where
499
	# When bootstrapping, we may have a situation where
498
	# CET-enabled gcc from seed is used to build CET-disabled
500
	# CET-enabled gcc from seed is used to build CET-disabled
499
	# glibc. As such, gcc implicitly enables CET if no
501
	# glibc. As such, gcc implicitly enables CET if no
500
	# -fcf-protection flag is passed. For a typical package it
502
	# -fcf-protection flag is passed. For a typical package it
501
	# should not be a problem, but for glibc it matters as it is
503
	# should not be a problem, but for glibc it matters as it is
502
	# dealing with CET in ld.so. So if CET is supposed to be
504
	# dealing with CET in ld.so. So if CET is supposed to be
503
	# disabled for glibc, be explicit about it.
505
	# disabled for glibc, be explicit about it.
504
	if (use amd64 || use x86) && ! use cet; then
506
	if (use amd64 || use x86) && ! use cet; then
505
		append-flags '-fcf-protection=none'
507
		append-flags '-fcf-protection=none'
506
	fi
508
	fi
507
}
509
}
508
510
509
use_multiarch() {
511
use_multiarch() {
510
	# Allow user to disable runtime arch detection in multilib.
512
	# Allow user to disable runtime arch detection in multilib.
511
	use multiarch || return 1
513
	use multiarch || return 1
512
	# Make sure binutils is new enough to support indirect functions,
514
	# Make sure binutils is new enough to support indirect functions,
513
	# #336792. This funky sed supports gold and bfd linkers.
515
	# #336792. This funky sed supports gold and bfd linkers.
514
	local bver nver
516
	local bver nver
515
	bver=$($(tc-getLD ${CTARGET}) -v | sed -n -r '1{s:[^0-9]*::;s:^([0-9.]*).*:\1:;p}')
517
	bver=$($(tc-getLD ${CTARGET}) -v | sed -n -r '1{s:[^0-9]*::;s:^([0-9.]*).*:\1:;p}')
516
	case $(tc-arch ${CTARGET}) in
518
	case $(tc-arch ${CTARGET}) in
517
	amd64|x86) nver="2.20" ;;
519
	amd64|x86) nver="2.20" ;;
518
	arm)       nver="2.22" ;;
520
	arm)       nver="2.22" ;;
519
	hppa)      nver="2.23" ;;
521
	hppa)      nver="2.23" ;;
520
	ppc|ppc64) nver="2.20" ;;
522
	ppc|ppc64) nver="2.20" ;;
521
	# ifunc support was added in 2.23, but glibc also needs
523
	# ifunc support was added in 2.23, but glibc also needs
522
	# machinemode which is in 2.24.
524
	# machinemode which is in 2.24.
523
	s390)      nver="2.24" ;;
525
	s390)      nver="2.24" ;;
524
	sparc)     nver="2.21" ;;
526
	sparc)     nver="2.21" ;;
525
	*)         return 1 ;;
527
	*)         return 1 ;;
526
	esac
528
	esac
527
	ver_test ${bver} -ge ${nver}
529
	ver_test ${bver} -ge ${nver}
528
}
530
}
529
531
530
# Setup toolchain variables that had historically been defined in the
532
# Setup toolchain variables that had historically been defined in the
531
# profiles for these archs.
533
# profiles for these archs.
532
setup_env() {
534
setup_env() {
533
	# silly users
535
	# silly users
534
	unset LD_RUN_PATH
536
	unset LD_RUN_PATH
535
	unset LD_ASSUME_KERNEL
537
	unset LD_ASSUME_KERNEL
536
538
537
	if is_crosscompile || tc-is-cross-compiler ; then
539
	if is_crosscompile || tc-is-cross-compiler ; then
538
		multilib_env ${CTARGET_OPT:-${CTARGET}}
540
		multilib_env ${CTARGET_OPT:-${CTARGET}}
539
541
540
		if ! use multilib ; then
542
		if ! use multilib ; then
541
			MULTILIB_ABIS=${DEFAULT_ABI}
543
			MULTILIB_ABIS=${DEFAULT_ABI}
542
		else
544
		else
543
			MULTILIB_ABIS=${MULTILIB_ABIS:-${DEFAULT_ABI}}
545
			MULTILIB_ABIS=${MULTILIB_ABIS:-${DEFAULT_ABI}}
544
		fi
546
		fi
545
547
546
		# If the user has CFLAGS_<CTARGET> in their make.conf, use that,
548
		# If the user has CFLAGS_<CTARGET> in their make.conf, use that,
547
		# and fall back on CFLAGS.
549
		# and fall back on CFLAGS.
548
		local VAR=CFLAGS_${CTARGET//[-.]/_}
550
		local VAR=CFLAGS_${CTARGET//[-.]/_}
549
		CFLAGS=${!VAR-${CFLAGS}}
551
		CFLAGS=${!VAR-${CFLAGS}}
550
		einfo " $(printf '%15s' 'Manual CFLAGS:')   ${CFLAGS}"
552
		einfo " $(printf '%15s' 'Manual CFLAGS:')   ${CFLAGS}"
551
	fi
553
	fi
552
554
553
	setup_flags
555
	setup_flags
554
556
555
	export ABI=${ABI:-${DEFAULT_ABI:-default}}
557
	export ABI=${ABI:-${DEFAULT_ABI:-default}}
556
558
557
	if just_headers ; then
559
	if just_headers ; then
558
		# Avoid mixing host's CC and target's CFLAGS_${ABI}:
560
		# Avoid mixing host's CC and target's CFLAGS_${ABI}:
559
		# At this bootstrap stage we have only binutils for
561
		# At this bootstrap stage we have only binutils for
560
		# target but not compiler yet.
562
		# target but not compiler yet.
561
		einfo "Skip CC ABI injection. We can't use (cross-)compiler yet."
563
		einfo "Skip CC ABI injection. We can't use (cross-)compiler yet."
562
		return 0
564
		return 0
563
	fi
565
	fi
564
566
565
	# Glibc does not work with gold (for various reasons) #269274.
567
	# Glibc does not work with gold (for various reasons) #269274.
566
	tc-ld-disable-gold
568
	tc-ld-disable-gold
567
569
568
	if use doc ; then
570
	if use doc ; then
569
		export MAKEINFO=makeinfo
571
		export MAKEINFO=makeinfo
570
	else
572
	else
571
		export MAKEINFO=/dev/null
573
		export MAKEINFO=/dev/null
572
	fi
574
	fi
573
575
574
	# Reset CC and CXX to the value at start of emerge
576
	# Reset CC and CXX to the value at start of emerge
575
	export CC=${glibc__ORIG_CC:-${CC:-$(tc-getCC ${CTARGET})}}
577
	export CC=${glibc__ORIG_CC:-${CC:-$(tc-getCC ${CTARGET})}}
576
	export CXX=${glibc__ORIG_CXX:-${CXX:-$(tc-getCXX ${CTARGET})}}
578
	export CXX=${glibc__ORIG_CXX:-${CXX:-$(tc-getCXX ${CTARGET})}}
577
579
578
	# and make sure glibc__ORIG_CC and glibc__ORIG_CXX is defined now.
580
	# and make sure glibc__ORIG_CC and glibc__ORIG_CXX is defined now.
579
	export glibc__ORIG_CC=${CC}
581
	export glibc__ORIG_CC=${CC}
580
	export glibc__ORIG_CXX=${CXX}
582
	export glibc__ORIG_CXX=${CXX}
581
583
582
	if tc-is-clang && ! use custom-cflags && ! is_crosscompile ; then
584
	if tc-is-clang && ! use custom-cflags && ! is_crosscompile ; then
583
		export glibc__force_gcc=yes
585
		export glibc__force_gcc=yes
584
		# once this is toggled on, it needs to stay on, since with CPP manipulated
586
		# once this is toggled on, it needs to stay on, since with CPP manipulated
585
		# tc-is-clang does not work correctly anymore...
587
		# tc-is-clang does not work correctly anymore...
586
	fi
588
	fi
587
589
588
	if [[ ${glibc__force_gcc} == "yes" ]] ; then
590
	if [[ ${glibc__force_gcc} == "yes" ]] ; then
589
		# If we are running in an otherwise clang/llvm environment, we need to
591
		# If we are running in an otherwise clang/llvm environment, we need to
590
		# recover the proper gcc and binutils settings here, at least until glibc
592
		# recover the proper gcc and binutils settings here, at least until glibc
591
		# is finally building with clang. So let's override everything that is
593
		# is finally building with clang. So let's override everything that is
592
		# set in the clang profiles.
594
		# set in the clang profiles.
593
		# Want to shoot yourself into the foot? Set USE=custom-cflags, that's always
595
		# Want to shoot yourself into the foot? Set USE=custom-cflags, that's always
594
		# a good start into that direction.
596
		# a good start into that direction.
595
		# Also, if you're crosscompiling, let's assume you know what you are doing.
597
		# Also, if you're crosscompiling, let's assume you know what you are doing.
596
		# Hopefully.
598
		# Hopefully.
597
		# Last, we need the settings of the *build* environment, not of the
599
		# Last, we need the settings of the *build* environment, not of the
598
		# target environment...
600
		# target environment...
599
601
600
		local current_binutils_path=$(env ROOT="${BROOT}" binutils-config -B)
602
		local current_binutils_path=$(env ROOT="${BROOT}" binutils-config -B)
601
		local current_gcc_path=$(env ROOT="${BROOT}" gcc-config -B)
603
		local current_gcc_path=$(env ROOT="${BROOT}" gcc-config -B)
602
		einfo "Overriding clang configuration, since it won't work here"
604
		einfo "Overriding clang configuration, since it won't work here"
603
605
604
		export CC="${current_gcc_path}/gcc"
606
		export CC="${current_gcc_path}/gcc"
605
		export CPP="${current_gcc_path}/cpp"
607
		export CPP="${current_gcc_path}/cpp"
606
		export CXX="${current_gcc_path}/g++"
608
		export CXX="${current_gcc_path}/g++"
607
		export LD="${current_binutils_path}/ld.bfd"
609
		export LD="${current_binutils_path}/ld.bfd"
608
		export AR="${current_binutils_path}/ar"
610
		export AR="${current_binutils_path}/ar"
609
		export AS="${current_binutils_path}/as"
611
		export AS="${current_binutils_path}/as"
610
		export NM="${current_binutils_path}/nm"
612
		export NM="${current_binutils_path}/nm"
611
		export STRIP="${current_binutils_path}/strip"
613
		export STRIP="${current_binutils_path}/strip"
612
		export RANLIB="${current_binutils_path}/ranlib"
614
		export RANLIB="${current_binutils_path}/ranlib"
613
		export OBJCOPY="${current_binutils_path}/objcopy"
615
		export OBJCOPY="${current_binutils_path}/objcopy"
614
		export STRINGS="${current_binutils_path}/strings"
616
		export STRINGS="${current_binutils_path}/strings"
615
		export OBJDUMP="${current_binutils_path}/objdump"
617
		export OBJDUMP="${current_binutils_path}/objdump"
616
		export READELF="${current_binutils_path}/readelf"
618
		export READELF="${current_binutils_path}/readelf"
617
		export ADDR2LINE="${current_binutils_path}/addr2line"
619
		export ADDR2LINE="${current_binutils_path}/addr2line"
618
620
619
		# do we need to also do flags munging here? yes! at least...
621
		# do we need to also do flags munging here? yes! at least...
620
		filter-flags '-fuse-ld=*'
622
		filter-flags '-fuse-ld=*'
621
		filter-flags '-D_FORTIFY_SOURCE=*'
623
		filter-flags '-D_FORTIFY_SOURCE=*'
622
624
623
	else
625
	else
624
626
625
		# this is the "normal" case
627
		# this is the "normal" case
626
628
627
		export CC="$(tc-getCC ${CTARGET})"
629
		export CC="$(tc-getCC ${CTARGET})"
628
		export CXX="$(tc-getCXX ${CTARGET})"
630
		export CXX="$(tc-getCXX ${CTARGET})"
629
631
630
		# Always use tuple-prefixed toolchain. For non-native ABI glibc's configure
632
		# Always use tuple-prefixed toolchain. For non-native ABI glibc's configure
631
		# can't detect them automatically due to ${CHOST} mismatch and fallbacks
633
		# can't detect them automatically due to ${CHOST} mismatch and fallbacks
632
		# to unprefixed tools. Similar to multilib.eclass:multilib_toolchain_setup().
634
		# to unprefixed tools. Similar to multilib.eclass:multilib_toolchain_setup().
633
		export NM="$(tc-getNM ${CTARGET})"
635
		export NM="$(tc-getNM ${CTARGET})"
634
		export READELF="$(tc-getREADELF ${CTARGET})"
636
		export READELF="$(tc-getREADELF ${CTARGET})"
635
637
636
	fi
638
	fi
637
639
638
	# We need to export CFLAGS with abi information in them because glibc's
640
	# We need to export CFLAGS with abi information in them because glibc's
639
	# configure script checks CFLAGS for some targets (like mips).  Keep
641
	# configure script checks CFLAGS for some targets (like mips).  Keep
640
	# around the original clean value to avoid appending multiple ABIs on
642
	# around the original clean value to avoid appending multiple ABIs on
641
	# top of each other. (Why does the comment talk about CFLAGS if the code
643
	# top of each other. (Why does the comment talk about CFLAGS if the code
642
	# acts on CC?)
644
	# acts on CC?)
643
	export glibc__GLIBC_CC=${CC}
645
	export glibc__GLIBC_CC=${CC}
644
	export glibc__GLIBC_CXX=${CXX}
646
	export glibc__GLIBC_CXX=${CXX}
645
647
646
	export glibc__abi_CFLAGS="$(get_abi_CFLAGS)"
648
	export glibc__abi_CFLAGS="$(get_abi_CFLAGS)"
647
649
648
	# CFLAGS can contain ABI-specific flags like -mfpu=neon, see bug #657760
650
	# CFLAGS can contain ABI-specific flags like -mfpu=neon, see bug #657760
649
	# To build .S (assembly) files with the same ABI-specific flags
651
	# To build .S (assembly) files with the same ABI-specific flags
650
	# upstream currently recommends adding CFLAGS to CC/CXX:
652
	# upstream currently recommends adding CFLAGS to CC/CXX:
651
	#    https://sourceware.org/PR23273
653
	#    https://sourceware.org/PR23273
652
	# Note: Passing CFLAGS via CPPFLAGS overrides glibc's arch-specific CFLAGS
654
	# Note: Passing CFLAGS via CPPFLAGS overrides glibc's arch-specific CFLAGS
653
	# and breaks multiarch support. See 659030#c3 for an example.
655
	# and breaks multiarch support. See 659030#c3 for an example.
654
	# The glibc configure script doesn't properly use LDFLAGS all the time.
656
	# The glibc configure script doesn't properly use LDFLAGS all the time.
655
	export CC="${glibc__GLIBC_CC} ${glibc__abi_CFLAGS} ${CFLAGS} ${LDFLAGS}"
657
	export CC="${glibc__GLIBC_CC} ${glibc__abi_CFLAGS} ${CFLAGS} ${LDFLAGS}"
656
658
657
	# Some of the tests are written in C++, so we need to force our multlib abis in, bug 623548
659
	# Some of the tests are written in C++, so we need to force our multlib abis in, bug 623548
658
	export CXX="${glibc__GLIBC_CXX} ${glibc__abi_CFLAGS} ${CFLAGS}"
660
	export CXX="${glibc__GLIBC_CXX} ${glibc__abi_CFLAGS} ${CFLAGS}"
659
661
660
	if is_crosscompile; then
662
	if is_crosscompile; then
661
		# Assume worst-case bootstrap: glibc is built for the first time
663
		# Assume worst-case bootstrap: glibc is built for the first time
662
		# with ${CTARGET}-g++ not available yet. We avoid
664
		# with ${CTARGET}-g++ not available yet. We avoid
663
		# building auxiliary programs that require C++: bug #683074
665
		# building auxiliary programs that require C++: bug #683074
664
		# It should not affect final result.
666
		# It should not affect final result.
665
		export libc_cv_cxx_link_ok=no
667
		export libc_cv_cxx_link_ok=no
666
		# The line above has the same effect. We set CXX explicitly
668
		# The line above has the same effect. We set CXX explicitly
667
		# to make build logs less confusing.
669
		# to make build logs less confusing.
668
		export CXX=
670
		export CXX=
669
	fi
671
	fi
670
}
672
}
671
673
672
foreach_abi() {
674
foreach_abi() {
673
	setup_env
675
	setup_env
674
676
675
	local ret=0
677
	local ret=0
676
	local abilist=""
678
	local abilist=""
677
	if use multilib ; then
679
	if use multilib ; then
678
		abilist=$(get_install_abis)
680
		abilist=$(get_install_abis)
679
	else
681
	else
680
		abilist=${DEFAULT_ABI}
682
		abilist=${DEFAULT_ABI}
681
	fi
683
	fi
682
	local -x ABI
684
	local -x ABI
683
	for ABI in ${abilist:-default} ; do
685
	for ABI in ${abilist:-default} ; do
684
		setup_env
686
		setup_env
685
		einfo "Running $1 for ABI ${ABI}"
687
		einfo "Running $1 for ABI ${ABI}"
686
		$1
688
		$1
687
		: $(( ret |= $? ))
689
		: $(( ret |= $? ))
688
	done
690
	done
689
	return ${ret}
691
	return ${ret}
690
}
692
}
691
693
692
glibc_banner() {
694
glibc_banner() {
693
	local b="Gentoo ${PVR}"
695
	local b="Gentoo ${PVR}"
694
	[[ -n ${PATCH_VER} ]] && ! use vanilla && b+=" (patchset ${PATCH_VER})"
696
	[[ -n ${PATCH_VER} ]] && ! use vanilla && b+=" (patchset ${PATCH_VER})"
695
	echo "${b}"
697
	echo "${b}"
696
}
698
}
697
699
698
# The following Kernel version handling functions are mostly copied from portage
700
# The following Kernel version handling functions are mostly copied from portage
699
# source. It's better not to use linux-info.eclass here since a) it adds too
701
# source. It's better not to use linux-info.eclass here since a) it adds too
700
# much magic, see bug 326693 for some of the arguments, and b) some of the
702
# much magic, see bug 326693 for some of the arguments, and b) some of the
701
# functions are just not provided.
703
# functions are just not provided.
702
704
703
g_get_running_KV() {
705
g_get_running_KV() {
704
	uname -r
706
	uname -r
705
	return $?
707
	return $?
706
}
708
}
707
709
708
g_KV_major() {
710
g_KV_major() {
709
	[[ -z $1 ]] && return 1
711
	[[ -z $1 ]] && return 1
710
	local KV=$@
712
	local KV=$@
711
	echo "${KV%%.*}"
713
	echo "${KV%%.*}"
712
}
714
}
713
715
714
g_KV_minor() {
716
g_KV_minor() {
715
	[[ -z $1 ]] && return 1
717
	[[ -z $1 ]] && return 1
716
	local KV=$@
718
	local KV=$@
717
	KV=${KV#*.}
719
	KV=${KV#*.}
718
	echo "${KV%%.*}"
720
	echo "${KV%%.*}"
719
}
721
}
720
722
721
g_KV_micro() {
723
g_KV_micro() {
722
	[[ -z $1 ]] && return 1
724
	[[ -z $1 ]] && return 1
723
	local KV=$@
725
	local KV=$@
724
	KV=${KV#*.*.}
726
	KV=${KV#*.*.}
725
	echo "${KV%%[^[:digit:]]*}"
727
	echo "${KV%%[^[:digit:]]*}"
726
}
728
}
727
729
728
g_KV_to_int() {
730
g_KV_to_int() {
729
	[[ -z $1 ]] && return 1
731
	[[ -z $1 ]] && return 1
730
	local KV_MAJOR=$(g_KV_major "$1")
732
	local KV_MAJOR=$(g_KV_major "$1")
731
	local KV_MINOR=$(g_KV_minor "$1")
733
	local KV_MINOR=$(g_KV_minor "$1")
732
	local KV_MICRO=$(g_KV_micro "$1")
734
	local KV_MICRO=$(g_KV_micro "$1")
733
	local KV_int=$(( KV_MAJOR * 65536 + KV_MINOR * 256 + KV_MICRO ))
735
	local KV_int=$(( KV_MAJOR * 65536 + KV_MINOR * 256 + KV_MICRO ))
734
736
735
	# We make version 2.2.0 the minimum version we will handle as
737
	# We make version 2.2.0 the minimum version we will handle as
736
	# a sanity check ... if its less, we fail ...
738
	# a sanity check ... if its less, we fail ...
737
	if [[ ${KV_int} -ge 131584 ]] ; then
739
	if [[ ${KV_int} -ge 131584 ]] ; then
738
		echo "${KV_int}"
740
		echo "${KV_int}"
739
		return 0
741
		return 0
740
	fi
742
	fi
741
	return 1
743
	return 1
742
}
744
}
743
745
744
g_int_to_KV() {
746
g_int_to_KV() {
745
	local version=$1 major minor micro
747
	local version=$1 major minor micro
746
	major=$((version / 65536))
748
	major=$((version / 65536))
747
	minor=$(((version % 65536) / 256))
749
	minor=$(((version % 65536) / 256))
748
	micro=$((version % 256))
750
	micro=$((version % 256))
749
	echo ${major}.${minor}.${micro}
751
	echo ${major}.${minor}.${micro}
750
}
752
}
751
753
752
eend_KV() {
754
eend_KV() {
753
	[[ $(g_KV_to_int $1) -ge $(g_KV_to_int $2) ]]
755
	[[ $(g_KV_to_int $1) -ge $(g_KV_to_int $2) ]]
754
	eend $?
756
	eend $?
755
}
757
}
756
758
757
get_kheader_version() {
759
get_kheader_version() {
758
	printf '#include <linux/version.h>\nLINUX_VERSION_CODE\n' | \
760
	printf '#include <linux/version.h>\nLINUX_VERSION_CODE\n' | \
759
	$(tc-getCPP ${CTARGET}) -I "$(build_eprefix)$(alt_build_headers)" - | \
761
	$(tc-getCPP ${CTARGET}) -I "$(build_eprefix)$(alt_build_headers)" - | \
760
	tail -n 1
762
	tail -n 1
761
}
763
}
762
764
763
# We collect all sanity checks here. Consistency is not guranteed between
765
# We collect all sanity checks here. Consistency is not guranteed between
764
# pkg_ and src_ phases, so we call this function both in pkg_pretend and in
766
# pkg_ and src_ phases, so we call this function both in pkg_pretend and in
765
# src_unpack.
767
# src_unpack.
766
sanity_prechecks() {
768
sanity_prechecks() {
767
	# Prevent native builds from downgrading
769
	# Prevent native builds from downgrading
768
	if [[ ${MERGE_TYPE} != "buildonly" ]] && \
770
	if [[ ${MERGE_TYPE} != "buildonly" ]] && \
769
	   [[ -z ${ROOT} ]] && \
771
	   [[ -z ${ROOT} ]] && \
770
	   [[ ${CBUILD} == ${CHOST} ]] && \
772
	   [[ ${CBUILD} == ${CHOST} ]] && \
771
	   [[ ${CHOST} == ${CTARGET} ]] ; then
773
	   [[ ${CHOST} == ${CTARGET} ]] ; then
772
774
773
		# The high rev # is to allow people to downgrade between -r#
775
		# The high rev # is to allow people to downgrade between -r#
774
		# versions. We want to block 2.20->2.19, but 2.20-r3->2.20-r2
776
		# versions. We want to block 2.20->2.19, but 2.20-r3->2.20-r2
775
		# should be fine. Hopefully we never actually use a r# this
777
		# should be fine. Hopefully we never actually use a r# this
776
		# high.
778
		# high.
777
		if has_version ">${CATEGORY}/${P}-r10000" ; then
779
		if has_version ">${CATEGORY}/${P}-r10000" ; then
778
			eerror "Sanity check to keep you from breaking your system:"
780
			eerror "Sanity check to keep you from breaking your system:"
779
			eerror " Downgrading glibc is not supported and a sure way to destruction."
781
			eerror " Downgrading glibc is not supported and a sure way to destruction."
780
			[[ ${I_ALLOW_TO_BREAK_MY_SYSTEM} = yes ]] || die "Aborting to save your system."
782
			[[ ${I_ALLOW_TO_BREAK_MY_SYSTEM} = yes ]] || die "Aborting to save your system."
781
		fi
783
		fi
782
784
783
		if ! do_run_test '#include <unistd.h>\n#include <sys/syscall.h>\nint main(){return syscall(1000)!=-1;}\n' ; then
785
		if ! do_run_test '#include <unistd.h>\n#include <sys/syscall.h>\nint main(){return syscall(1000)!=-1;}\n' ; then
784
			eerror "Your old kernel is broken. You need to update it to a newer"
786
			eerror "Your old kernel is broken. You need to update it to a newer"
785
			eerror "version as syscall(<bignum>) will break. See bug 279260."
787
			eerror "version as syscall(<bignum>) will break. See bug 279260."
786
			die "Old and broken kernel."
788
			die "Old and broken kernel."
787
		fi
789
		fi
788
	fi
790
	fi
789
791
790
	if [[ ${CTARGET} == i386-* ]] ; then
792
	if [[ ${CTARGET} == i386-* ]] ; then
791
		eerror "i386 CHOSTs are no longer supported."
793
		eerror "i386 CHOSTs are no longer supported."
792
		eerror "Chances are you don't actually want/need i386."
794
		eerror "Chances are you don't actually want/need i386."
793
		eerror "Please read https://www.gentoo.org/doc/en/change-chost.xml"
795
		eerror "Please read https://www.gentoo.org/doc/en/change-chost.xml"
794
		die "Please fix your CHOST"
796
		die "Please fix your CHOST"
795
	fi
797
	fi
796
798
797
	if [[ -e /proc/xen ]] && [[ $(tc-arch) == "x86" ]] && ! is-flag -mno-tls-direct-seg-refs ; then
799
	if [[ -e /proc/xen ]] && [[ $(tc-arch) == "x86" ]] && ! is-flag -mno-tls-direct-seg-refs ; then
798
		ewarn "You are using Xen but don't have -mno-tls-direct-seg-refs in your CFLAGS."
800
		ewarn "You are using Xen but don't have -mno-tls-direct-seg-refs in your CFLAGS."
799
		ewarn "This will result in a 50% performance penalty when running with a 32bit"
801
		ewarn "This will result in a 50% performance penalty when running with a 32bit"
800
		ewarn "hypervisor, which is probably not what you want."
802
		ewarn "hypervisor, which is probably not what you want."
801
	fi
803
	fi
802
804
803
	# ABI-specific checks follow here. Hey, we have a lot more specific conditions that
805
	# ABI-specific checks follow here. Hey, we have a lot more specific conditions that
804
	# we test for...
806
	# we test for...
805
	if ! is_crosscompile ; then
807
	if ! is_crosscompile ; then
806
		if use amd64 && use multilib && [[ ${MERGE_TYPE} != "binary" ]] ; then
808
		if use amd64 && use multilib && [[ ${MERGE_TYPE} != "binary" ]] ; then
807
			ebegin "Checking that IA32 emulation is enabled in the running kernel"
809
			ebegin "Checking that IA32 emulation is enabled in the running kernel"
808
			echo 'int main(){return 0;}' > "${T}/check-ia32-emulation.c"
810
			echo 'int main(){return 0;}' > "${T}/check-ia32-emulation.c"
809
			local STAT
811
			local STAT
810
			if ${CC-${CHOST}-gcc} ${CFLAGS_x86} "${T}/check-ia32-emulation.c" -o "${T}/check-ia32-emulation.elf32"; then
812
			if ${CC-${CHOST}-gcc} ${CFLAGS_x86} "${T}/check-ia32-emulation.c" -o "${T}/check-ia32-emulation.elf32"; then
811
				"${T}/check-ia32-emulation.elf32"
813
				"${T}/check-ia32-emulation.elf32"
812
				STAT=$?
814
				STAT=$?
813
			else
815
			else
814
				# Don't fail here to allow single->multi ABI switch
816
				# Don't fail here to allow single->multi ABI switch
815
				# or recover from breakage like bug #646424
817
				# or recover from breakage like bug #646424
816
				ewarn "Failed to compile the ABI test. Broken host glibc?"
818
				ewarn "Failed to compile the ABI test. Broken host glibc?"
817
				STAT=0
819
				STAT=0
818
			fi
820
			fi
819
			rm -f "${T}/check-ia32-emulation.elf32"
821
			rm -f "${T}/check-ia32-emulation.elf32"
820
			eend $STAT
822
			eend $STAT
821
			[[ $STAT -eq 0 ]] || die "CONFIG_IA32_EMULATION must be enabled in the kernel to compile a multilib glibc."
823
			[[ $STAT -eq 0 ]] || die "CONFIG_IA32_EMULATION must be enabled in the kernel to compile a multilib glibc."
822
		fi
824
		fi
823
825
824
	fi
826
	fi
825
827
826
	# When we actually have to compile something...
828
	# When we actually have to compile something...
827
	if ! just_headers && [[ ${MERGE_TYPE} != "binary" ]] ; then
829
	if ! just_headers && [[ ${MERGE_TYPE} != "binary" ]] ; then
828
		if [[ -d "${ESYSROOT}"/usr/lib/include ]] ; then
830
		if [[ -d "${ESYSROOT}"/usr/lib/include ]] ; then
829
			# bug #833620, bug #643302
831
			# bug #833620, bug #643302
830
			eerror "Found ${ESYSROOT}/usr/lib/include directory!"
832
			eerror "Found ${ESYSROOT}/usr/lib/include directory!"
831
			eerror "This is known to break glibc's build."
833
			eerror "This is known to break glibc's build."
832
			eerror "Please backup its contents then remove the directory."
834
			eerror "Please backup its contents then remove the directory."
833
			die "Found directory (${ESYSROOT}/usr/lib/include) which will break build (bug #833620)!"
835
			die "Found directory (${ESYSROOT}/usr/lib/include) which will break build (bug #833620)!"
834
		fi
836
		fi
835
837
836
		if [[ ${CTARGET} == *-linux* ]] ; then
838
		if [[ ${CTARGET} == *-linux* ]] ; then
837
			local run_kv build_kv want_kv
839
			local run_kv build_kv want_kv
838
840
839
			run_kv=$(g_get_running_KV)
841
			run_kv=$(g_get_running_KV)
840
			build_kv=$(g_int_to_KV $(get_kheader_version))
842
			build_kv=$(g_int_to_KV $(get_kheader_version))
841
			want_kv=${MIN_KERN_VER}
843
			want_kv=${MIN_KERN_VER}
842
844
843
			if ! is_crosscompile && ! tc-is-cross-compiler ; then
845
			if ! is_crosscompile && ! tc-is-cross-compiler ; then
844
				# Building fails on an non-supporting kernel
846
				# Building fails on an non-supporting kernel
845
				ebegin "Checking running kernel version (${run_kv} >= ${want_kv})"
847
				ebegin "Checking running kernel version (${run_kv} >= ${want_kv})"
846
				if ! eend_KV ${run_kv} ${want_kv} ; then
848
				if ! eend_KV ${run_kv} ${want_kv} ; then
847
					echo
849
					echo
848
					eerror "You need a kernel of at least ${want_kv}!"
850
					eerror "You need a kernel of at least ${want_kv}!"
849
					die "Kernel version too low!"
851
					die "Kernel version too low!"
850
				fi
852
				fi
851
			fi
853
			fi
852
854
853
			# Do not run this check for pkg_pretend, just pkg_setup and friends (if we ever get used there).
855
			# Do not run this check for pkg_pretend, just pkg_setup and friends (if we ever get used there).
854
			# It's plausible (seen it in the wild) that Portage will (correctly) schedule a linux-headers
856
			# It's plausible (seen it in the wild) that Portage will (correctly) schedule a linux-headers
855
			# upgrade before glibc, but because pkg_pretend gets run before any packages are merged at all (not
857
			# upgrade before glibc, but because pkg_pretend gets run before any packages are merged at all (not
856
			# just glibc), the whole emerge gets aborted without a good reason. We probably don't
858
			# just glibc), the whole emerge gets aborted without a good reason. We probably don't
857
			# need to run this check at all given we have a dependency on the right headers,
859
			# need to run this check at all given we have a dependency on the right headers,
858
			# but let's leave it as-is for now.
860
			# but let's leave it as-is for now.
859
			if [[ ${EBUILD_PHASE_FUNC} != pkg_pretend ]] ; then
861
			if [[ ${EBUILD_PHASE_FUNC} != pkg_pretend ]] ; then
860
				ebegin "Checking linux-headers version (${build_kv} >= ${want_kv})"
862
				ebegin "Checking linux-headers version (${build_kv} >= ${want_kv})"
861
				if ! eend_KV ${build_kv} ${want_kv} ; then
863
				if ! eend_KV ${build_kv} ${want_kv} ; then
862
					echo
864
					echo
863
					eerror "You need linux-headers of at least ${want_kv}!"
865
					eerror "You need linux-headers of at least ${want_kv}!"
864
					die "linux-headers version too low!"
866
					die "linux-headers version too low!"
865
				fi
867
				fi
866
			fi
868
			fi
867
		fi
869
		fi
868
	fi
870
	fi
869
}
871
}
870
872
871
upgrade_warning() {
873
upgrade_warning() {
872
	is_crosscompile && return
874
	is_crosscompile && return
873
875
874
	if [[ ${MERGE_TYPE} != buildonly && -n ${REPLACING_VERSIONS} && -z ${ROOT} ]]; then
876
	if [[ ${MERGE_TYPE} != buildonly && -n ${REPLACING_VERSIONS} && -z ${ROOT} ]]; then
875
		local oldv newv=$(ver_cut 1-2 ${PV})
877
		local oldv newv=$(ver_cut 1-2 ${PV})
876
		for oldv in ${REPLACING_VERSIONS}; do
878
		for oldv in ${REPLACING_VERSIONS}; do
877
			if ver_test ${oldv} -lt ${newv}; then
879
			if ver_test ${oldv} -lt ${newv}; then
878
				ewarn "After upgrading glibc, please restart all running processes."
880
				ewarn "After upgrading glibc, please restart all running processes."
879
				ewarn "Be sure to include init (telinit u) or systemd (systemctl daemon-reexec)."
881
				ewarn "Be sure to include init (telinit u) or systemd (systemctl daemon-reexec)."
880
				ewarn "Alternatively, reboot your system."
882
				ewarn "Alternatively, reboot your system."
881
				ewarn "(See bug #660556, bug #741116, bug #823756, etc)"
883
				ewarn "(See bug #660556, bug #741116, bug #823756, etc)"
882
				break
884
				break
883
			fi
885
			fi
884
		done
886
		done
885
	fi
887
	fi
886
}
888
}
887
889
888
#
890
#
889
# the phases
891
# the phases
890
#
892
#
891
893
892
# pkg_pretend
894
# pkg_pretend
893
895
894
pkg_pretend() {
896
pkg_pretend() {
895
	upgrade_warning
897
	upgrade_warning
896
}
898
}
897
899
898
# pkg_setup
900
# pkg_setup
899
901
900
pkg_setup() {
902
pkg_setup() {
901
	# see bug 682570
903
	# see bug 682570
902
	[[ -z ${BOOTSTRAP_RAP} ]] && python-any-r1_pkg_setup
904
	[[ -z ${BOOTSTRAP_RAP} ]] && python-any-r1_pkg_setup
903
}
905
}
904
906
905
# src_unpack
907
# src_unpack
906
908
907
src_unpack() {
909
src_unpack() {
908
	setup_env
910
	setup_env
909
911
910
	einfo "Checking general environment sanity."
912
	einfo "Checking general environment sanity."
911
	sanity_prechecks
913
	sanity_prechecks
912
914
913
	use multilib-bootstrap && unpack gcc-multilib-bootstrap-${GCC_BOOTSTRAP_VER}.tar.xz
915
	use multilib-bootstrap && unpack gcc-multilib-bootstrap-${GCC_BOOTSTRAP_VER}.tar.xz
914
916
915
	if [[ ${PV} == 9999* ]] ; then
917
	if [[ ${PV} == 9999* ]] ; then
916
		EGIT_REPO_URI="https://anongit.gentoo.org/git/proj/toolchain/glibc-patches.git"
918
		EGIT_REPO_URI="https://anongit.gentoo.org/git/proj/toolchain/glibc-patches.git"
917
		EGIT_CHECKOUT_DIR=${WORKDIR}/patches-git
919
		EGIT_CHECKOUT_DIR=${WORKDIR}/patches-git
918
		git-r3_src_unpack
920
		git-r3_src_unpack
919
		mv patches-git/9999 patches || die
921
		mv patches-git/9999 patches || die
920
922
921
		EGIT_REPO_URI="https://sourceware.org/git/glibc.git"
923
		EGIT_REPO_URI="https://sourceware.org/git/glibc.git"
922
		EGIT_CHECKOUT_DIR=${S}
924
		EGIT_CHECKOUT_DIR=${S}
923
		git-r3_src_unpack
925
		git-r3_src_unpack
924
	else
926
	else
925
		unpack ${P}.tar.xz
927
		unpack ${P}.tar.xz
926
928
927
		cd "${WORKDIR}" || die
929
		cd "${WORKDIR}" || die
928
		unpack glibc-${PV}-patches-${PATCH_VER}.tar.xz
930
		unpack glibc-${PV}-patches-${PATCH_VER}.tar.xz
929
	fi
931
	fi
930
932
931
	cd "${WORKDIR}" || die
933
	cd "${WORKDIR}" || die
932
	use systemd && unpack glibc-systemd-${GLIBC_SYSTEMD_VER}.tar.gz
934
	use systemd && unpack glibc-systemd-${GLIBC_SYSTEMD_VER}.tar.gz
933
}
935
}
934
936
935
# src_prepare
937
# src_prepare
936
938
937
src_prepare() {
939
src_prepare() {
938
	local patchsetname
940
	local patchsetname
939
	if ! use vanilla ; then
941
	if ! use vanilla ; then
940
		if [[ ${PV} == 9999* ]] ; then
942
		if [[ ${PV} == 9999* ]] ; then
941
			patchsetname="from git master"
943
			patchsetname="from git master"
942
		else
944
		else
943
			patchsetname="${PV}-${PATCH_VER}"
945
			patchsetname="${PV}-${PATCH_VER}"
944
		fi
946
		fi
945
		einfo "Applying Gentoo Glibc patchset ${patchsetname}"
947
		einfo "Applying Gentoo Glibc patchset ${patchsetname}"
946
		eapply "${WORKDIR}"/patches
948
		eapply "${WORKDIR}"/patches
947
		einfo "Done."
949
		einfo "Done."
948
	fi
950
	fi
949
951
950
	default
952
	default
951
953
952
	gnuconfig_update
954
	gnuconfig_update
953
955
954
	cd "${WORKDIR}" || die
956
	cd "${WORKDIR}" || die
955
	find . -name configure -exec touch {} +
957
	find . -name configure -exec touch {} +
956
958
957
	# Fix permissions on some of the scripts.
959
	# Fix permissions on some of the scripts.
958
	chmod u+x "${S}"/scripts/*.sh
960
	chmod u+x "${S}"/scripts/*.sh
959
961
960
	cd "${S}" || die
962
	cd "${S}" || die
961
}
963
}
962
964
963
# src_configure
965
# src_configure
964
966
965
glibc_do_configure() {
967
glibc_do_configure() {
966
	dump_build_environment
968
	dump_build_environment
967
969
968
	local myconf=()
970
	local myconf=()
969
971
970
	# Use '=strong' instead of '=all' to protect only functions
972
	# Use '=strong' instead of '=all' to protect only functions
971
	# worth protecting from stack smashes.
973
	# worth protecting from stack smashes.
972
	myconf+=( --enable-stack-protector=$(usex ssp strong no) )
974
	myconf+=( --enable-stack-protector=$(usex ssp strong no) )
973
975
974
	# Keep a whitelist of targets supporing IFUNC. glibc's ./configure
976
	# Keep a whitelist of targets supporing IFUNC. glibc's ./configure
975
	# is not robust enough to detect proper support:
977
	# is not robust enough to detect proper support:
976
	#    https://bugs.gentoo.org/641216
978
	#    https://bugs.gentoo.org/641216
977
	#    https://sourceware.org/PR22634#c0
979
	#    https://sourceware.org/PR22634#c0
978
	case $(tc-arch ${CTARGET}) in
980
	case $(tc-arch ${CTARGET}) in
979
		# Keep whitelist of targets where autodetection mostly works.
981
		# Keep whitelist of targets where autodetection mostly works.
980
		amd64|x86|sparc|ppc|ppc64|arm|arm64|s390|riscv|loong) ;;
982
		amd64|x86|sparc|ppc|ppc64|arm|arm64|s390|riscv|loong) ;;
981
		# Blacklist everywhere else
983
		# Blacklist everywhere else
982
		*) myconf+=( libc_cv_ld_gnu_indirect_function=no ) ;;
984
		*) myconf+=( libc_cv_ld_gnu_indirect_function=no ) ;;
983
	esac
985
	esac
984
986
985
	# Enable Intel Control-flow Enforcement Technology on amd64 if requested
987
	# Enable Intel Control-flow Enforcement Technology on amd64 if requested
986
	case ${CTARGET} in
988
	case ${CTARGET} in
987
		x86_64-*) myconf+=( $(use_enable cet) ) ;;
989
		x86_64-*) myconf+=( $(use_enable cet) ) ;;
988
		*) ;;
990
		*) ;;
989
	esac
991
	esac
990
992
991
	[[ $(tc-is-softfloat) == "yes" ]] && myconf+=( --without-fp )
993
	[[ $(tc-is-softfloat) == "yes" ]] && myconf+=( --without-fp )
992
994
993
	myconf+=( --enable-kernel=${MIN_KERN_VER} )
995
	myconf+=( --enable-kernel=${MIN_KERN_VER} )
994
996
995
	# Since SELinux support is only required for nscd, only enable it if:
997
	# Since SELinux support is only required for nscd, only enable it if:
996
	# 1. USE selinux
998
	# 1. USE selinux
997
	# 2. only for the primary ABI on multilib systems
999
	# 2. only for the primary ABI on multilib systems
998
	# 3. Not a crosscompile
1000
	# 3. Not a crosscompile
999
	if ! is_crosscompile && use selinux ; then
1001
	if ! is_crosscompile && use selinux ; then
1000
		if use multilib ; then
1002
		if use multilib ; then
1001
			if is_final_abi ; then
1003
			if is_final_abi ; then
1002
				myconf+=( --with-selinux )
1004
				myconf+=( --with-selinux )
1003
			else
1005
			else
1004
				myconf+=( --without-selinux )
1006
				myconf+=( --without-selinux )
1005
			fi
1007
			fi
1006
		else
1008
		else
1007
			myconf+=( --with-selinux )
1009
			myconf+=( --with-selinux )
1008
		fi
1010
		fi
1009
	else
1011
	else
1010
		myconf+=( --without-selinux )
1012
		myconf+=( --without-selinux )
1011
	fi
1013
	fi
1012
1014
1013
	# Force a few tests where we always know the answer but
1015
	# Force a few tests where we always know the answer but
1014
	# configure is incapable of finding it.
1016
	# configure is incapable of finding it.
1015
	if is_crosscompile ; then
1017
	if is_crosscompile ; then
1016
		export \
1018
		export \
1017
			libc_cv_c_cleanup=yes \
1019
			libc_cv_c_cleanup=yes \
1018
			libc_cv_forced_unwind=yes
1020
			libc_cv_forced_unwind=yes
1019
	fi
1021
	fi
1020
1022
1021
	myconf+=(
1023
	myconf+=(
1022
		--disable-werror
1024
		--disable-werror
1023
		--enable-bind-now
1025
		--enable-bind-now
1024
		--enable-fortify-source
1026
		--enable-fortify-source
1025
		--build=${CBUILD_OPT:-${CBUILD}}
1027
		--build=${CBUILD_OPT:-${CBUILD}}
1026
		--host=${CTARGET_OPT:-${CTARGET}}
1028
		--host=${CTARGET_OPT:-${CTARGET}}
1027
		$(use_enable profile)
1029
		$(use_enable profile)
1028
		$(use_with gd)
1030
		$(use_with gd)
1029
		--with-headers=$(build_eprefix)$(alt_build_headers)
1031
		--with-headers=$(build_eprefix)$(alt_build_headers)
1030
		--prefix="$(host_eprefix)/usr"
1032
		--prefix="$(host_eprefix)/usr"
1031
		--sysconfdir="$(host_eprefix)/etc"
1033
		--sysconfdir="$(host_eprefix)/etc"
1032
		--localstatedir="$(host_eprefix)/var"
1034
		--localstatedir="$(host_eprefix)/var"
1033
		--libdir='$(prefix)'/$(get_libdir)
1035
		--libdir='$(prefix)'/$(get_libdir)
1034
		--mandir='$(prefix)'/share/man
1036
		--mandir='$(prefix)'/share/man
1035
		--infodir='$(prefix)'/share/info
1037
		--infodir='$(prefix)'/share/info
1036
		--libexecdir='$(libdir)'/misc/glibc
1038
		--libexecdir='$(libdir)'/misc/glibc
1037
		--with-bugurl=https://bugs.gentoo.org/
1039
		--with-bugurl=https://bugs.gentoo.org/
1038
		--with-pkgversion="$(glibc_banner)"
1040
		--with-pkgversion="$(glibc_banner)"
1039
		$(use_enable crypt)
1041
		$(use_enable crypt)
1040
		$(use_multiarch || echo --disable-multi-arch)
1042
		$(use_multiarch || echo --disable-multi-arch)
1041
		$(use_enable systemtap)
1043
		$(use_enable systemtap)
1042
		$(use_enable nscd)
1044
		$(use_enable nscd)
1043
1045
1044
		# /usr/bin/mtrace has a Perl shebang. Gentoo Prefix QA checks fail if
1046
		# /usr/bin/mtrace has a Perl shebang. Gentoo Prefix QA checks fail if
1045
		# Perl hasn't been installed inside the prefix yet and configure picks
1047
		# Perl hasn't been installed inside the prefix yet and configure picks
1046
		# up a Perl from outside the prefix instead. configure will fail to
1048
		# up a Perl from outside the prefix instead. configure will fail to
1047
		# execute Perl during configure if we're cross-compiling a prefix, but
1049
		# execute Perl during configure if we're cross-compiling a prefix, but
1048
		# it will just disable mtrace in that case.
1050
		# it will just disable mtrace in that case.
1049
		# Note: mtrace is needed by the test suite.
1051
		# Note: mtrace is needed by the test suite.
1050
		ac_cv_path_PERL="$(usex perl "${EPREFIX}"/usr/bin/perl $(usex test "${EPREFIX}"/usr/bin/perl $(usex doc "${EPREFIX}"/usr/bin/perl no)))"
1052
		ac_cv_path_PERL="$(usex perl "${EPREFIX}"/usr/bin/perl $(usex test "${EPREFIX}"/usr/bin/perl $(usex doc "${EPREFIX}"/usr/bin/perl no)))"
1051
1053
1052
		# locale data is arch-independent
1054
		# locale data is arch-independent
1053
		# https://bugs.gentoo.org/753740
1055
		# https://bugs.gentoo.org/753740
1054
		libc_cv_complocaledir='${exec_prefix}/lib/locale'
1056
		libc_cv_complocaledir='${exec_prefix}/lib/locale'
1055
1057
1056
		# On aarch64 there is no way to override -mcpu=native, and if
1058
		# On aarch64 there is no way to override -mcpu=native, and if
1057
		# the current cpu does not support SVE configure fails.
1059
		# the current cpu does not support SVE configure fails.
1058
		# Let's boldly assume our toolchain can always build SVE instructions.
1060
		# Let's boldly assume our toolchain can always build SVE instructions.
1059
		libc_cv_aarch64_sve_asm=yes
1061
		libc_cv_aarch64_sve_asm=yes
1060
1062
1061
		${EXTRA_ECONF}
1063
		${EXTRA_ECONF}
1062
	)
1064
	)
1063
1065
1064
	# We rely on sys-libs/timezone-data for timezone tools normally.
1066
	# We rely on sys-libs/timezone-data for timezone tools normally.
1065
	myconf+=( $(use_enable vanilla timezone-tools) )
1067
	myconf+=( $(use_enable vanilla timezone-tools) )
1066
1068
1067
	# These libs don't have configure flags.
1069
	# These libs don't have configure flags.
1068
	ac_cv_lib_audit_audit_log_user_avc_message=$(usex audit || echo no)
1070
	ac_cv_lib_audit_audit_log_user_avc_message=$(usex audit || echo no)
1069
	ac_cv_lib_cap_cap_init=$(usex caps || echo no)
1071
	ac_cv_lib_cap_cap_init=$(usex caps || echo no)
1070
1072
1071
	# There is no configure option for this and we need to export it
1073
	# There is no configure option for this and we need to export it
1072
	# since the glibc build will re-run configure on itself
1074
	# since the glibc build will re-run configure on itself
1073
	export libc_cv_rootsbindir="$(host_eprefix)/sbin"
1075
	export libc_cv_rootsbindir="$(host_eprefix)/sbin"
1074
	export libc_cv_slibdir="$(host_eprefix)/$(get_libdir)"
1076
	export libc_cv_slibdir="$(host_eprefix)/$(get_libdir)"
1075
1077
1076
	local builddir=$(builddir nptl)
1078
	local builddir=$(builddir nptl)
1077
	mkdir -p "${builddir}"
1079
	mkdir -p "${builddir}"
1078
	cd "${builddir}"
1080
	cd "${builddir}"
1079
	set -- "${S}"/configure "${myconf[@]}"
1081
	set -- "${S}"/configure "${myconf[@]}"
1080
	echo "$@"
1082
	echo "$@"
1081
	"$@" || die "failed to configure glibc"
1083
	"$@" || die "failed to configure glibc"
1082
1084
1083
	# ia64 static cross-compilers are a pita in so much that they
1085
	# ia64 static cross-compilers are a pita in so much that they
1084
	# can't produce static ELFs (as the libgcc.a is broken).  so
1086
	# can't produce static ELFs (as the libgcc.a is broken).  so
1085
	# disable building of the programs for those targets if it
1087
	# disable building of the programs for those targets if it
1086
	# doesn't work.
1088
	# doesn't work.
1087
	# XXX: We could turn this into a compiler test, but ia64 is
1089
	# XXX: We could turn this into a compiler test, but ia64 is
1088
	# the only one that matters, so this should be fine for now.
1090
	# the only one that matters, so this should be fine for now.
1089
	if is_crosscompile && [[ ${CTARGET} == ia64* ]] ; then
1091
	if is_crosscompile && [[ ${CTARGET} == ia64* ]] ; then
1090
		sed -i '1i+link-static = touch $@' config.make
1092
		sed -i '1i+link-static = touch $@' config.make
1091
	fi
1093
	fi
1092
1094
1093
	# If we're trying to migrate between ABI sets, we need
1095
	# If we're trying to migrate between ABI sets, we need
1094
	# to lie and use a local copy of gcc.  Like if the system
1096
	# to lie and use a local copy of gcc.  Like if the system
1095
	# is built with MULTILIB_ABIS="amd64 x86" but we want to
1097
	# is built with MULTILIB_ABIS="amd64 x86" but we want to
1096
	# add x32 to it, gcc/glibc don't yet support x32.
1098
	# add x32 to it, gcc/glibc don't yet support x32.
1097
	#
1099
	#
1098
	if [[ -n ${GCC_BOOTSTRAP_VER} ]] && use multilib-bootstrap ; then
1100
	if [[ -n ${GCC_BOOTSTRAP_VER} ]] && use multilib-bootstrap ; then
1099
		echo 'int main(void){}' > "${T}"/test.c || die
1101
		echo 'int main(void){}' > "${T}"/test.c || die
1100
		if ! $(tc-getCC ${CTARGET}) ${CFLAGS} ${LDFLAGS} "${T}"/test.c -Wl,-emain -lgcc 2>/dev/null ; then
1102
		if ! $(tc-getCC ${CTARGET}) ${CFLAGS} ${LDFLAGS} "${T}"/test.c -Wl,-emain -lgcc 2>/dev/null ; then
1101
			sed -i -e '/^CC = /s:$: -B$(objdir)/../'"gcc-multilib-bootstrap-${GCC_BOOTSTRAP_VER}/${ABI}:" config.make || die
1103
			sed -i -e '/^CC = /s:$: -B$(objdir)/../'"gcc-multilib-bootstrap-${GCC_BOOTSTRAP_VER}/${ABI}:" config.make || die
1102
		fi
1104
		fi
1103
	fi
1105
	fi
1104
}
1106
}
1105
1107
1106
glibc_headers_configure() {
1108
glibc_headers_configure() {
1107
	export ABI=default
1109
	export ABI=default
1108
1110
1109
	local builddir=$(builddir "headers")
1111
	local builddir=$(builddir "headers")
1110
	mkdir -p "${builddir}"
1112
	mkdir -p "${builddir}"
1111
	cd "${builddir}"
1113
	cd "${builddir}"
1112
1114
1113
	# if we don't have a compiler yet, we can't really test it now ...
1115
	# if we don't have a compiler yet, we can't really test it now ...
1114
	# hopefully they don't affect header generation, so let's hope for
1116
	# hopefully they don't affect header generation, so let's hope for
1115
	# the best here ...
1117
	# the best here ...
1116
	local v vars=(
1118
	local v vars=(
1117
		ac_cv_header_cpuid_h=yes
1119
		ac_cv_header_cpuid_h=yes
1118
		libc_cv_{386,390,alpha,arm,hppa,ia64,mips,{powerpc,sparc}{,32,64},sh,x86_64}_tls=yes
1120
		libc_cv_{386,390,alpha,arm,hppa,ia64,mips,{powerpc,sparc}{,32,64},sh,x86_64}_tls=yes
1119
		libc_cv_asm_cfi_directives=yes
1121
		libc_cv_asm_cfi_directives=yes
1120
		libc_cv_broken_visibility_attribute=no
1122
		libc_cv_broken_visibility_attribute=no
1121
		libc_cv_c_cleanup=yes
1123
		libc_cv_c_cleanup=yes
1122
		libc_cv_compiler_powerpc64le_binary128_ok=yes
1124
		libc_cv_compiler_powerpc64le_binary128_ok=yes
1123
		libc_cv_forced_unwind=yes
1125
		libc_cv_forced_unwind=yes
1124
		libc_cv_gcc___thread=yes
1126
		libc_cv_gcc___thread=yes
1125
		libc_cv_mlong_double_128=yes
1127
		libc_cv_mlong_double_128=yes
1126
		libc_cv_mlong_double_128ibm=yes
1128
		libc_cv_mlong_double_128ibm=yes
1127
		libc_cv_ppc_machine=yes
1129
		libc_cv_ppc_machine=yes
1128
		libc_cv_ppc_rel16=yes
1130
		libc_cv_ppc_rel16=yes
1129
		libc_cv_predef_fortify_source=no
1131
		libc_cv_predef_fortify_source=no
1130
		libc_cv_target_power8_ok=yes
1132
		libc_cv_target_power8_ok=yes
1131
		libc_cv_visibility_attribute=yes
1133
		libc_cv_visibility_attribute=yes
1132
		libc_cv_z_combreloc=yes
1134
		libc_cv_z_combreloc=yes
1133
		libc_cv_z_execstack=yes
1135
		libc_cv_z_execstack=yes
1134
		libc_cv_z_initfirst=yes
1136
		libc_cv_z_initfirst=yes
1135
		libc_cv_z_nodelete=yes
1137
		libc_cv_z_nodelete=yes
1136
		libc_cv_z_nodlopen=yes
1138
		libc_cv_z_nodlopen=yes
1137
		libc_cv_z_relro=yes
1139
		libc_cv_z_relro=yes
1138
		libc_mips_abi=${ABI}
1140
		libc_mips_abi=${ABI}
1139
		libc_mips_float=$([[ $(tc-is-softfloat) == "yes" ]] && echo soft || echo hard)
1141
		libc_mips_float=$([[ $(tc-is-softfloat) == "yes" ]] && echo soft || echo hard)
1140
		# These libs don't have configure flags.
1142
		# These libs don't have configure flags.
1141
		ac_cv_lib_audit_audit_log_user_avc_message=no
1143
		ac_cv_lib_audit_audit_log_user_avc_message=no
1142
		ac_cv_lib_cap_cap_init=no
1144
		ac_cv_lib_cap_cap_init=no
1143
	)
1145
	)
1144
1146
1145
	einfo "Forcing cached settings:"
1147
	einfo "Forcing cached settings:"
1146
	for v in "${vars[@]}" ; do
1148
	for v in "${vars[@]}" ; do
1147
		einfo " ${v}"
1149
		einfo " ${v}"
1148
		export ${v}
1150
		export ${v}
1149
	done
1151
	done
1150
1152
1151
	local headers_only_arch_CPPFLAGS=()
1153
	local headers_only_arch_CPPFLAGS=()
1152
1154
1153
	# Blow away some random CC settings that screw things up. #550192
1155
	# Blow away some random CC settings that screw things up. #550192
1154
	if [[ -d ${S}/sysdeps/mips ]]; then
1156
	if [[ -d ${S}/sysdeps/mips ]]; then
1155
		pushd "${S}"/sysdeps/mips >/dev/null
1157
		pushd "${S}"/sysdeps/mips >/dev/null
1156
		sed -i -e '/^CC +=/s:=.*:= -D_MIPS_SZPTR=32:' mips32/Makefile mips64/n32/Makefile || die
1158
		sed -i -e '/^CC +=/s:=.*:= -D_MIPS_SZPTR=32:' mips32/Makefile mips64/n32/Makefile || die
1157
		sed -i -e '/^CC +=/s:=.*:= -D_MIPS_SZPTR=64:' mips64/n64/Makefile || die
1159
		sed -i -e '/^CC +=/s:=.*:= -D_MIPS_SZPTR=64:' mips64/n64/Makefile || die
1158
1160
1159
		# Force the mips ABI to the default.  This is OK because the set of
1161
		# Force the mips ABI to the default.  This is OK because the set of
1160
		# installed headers in this phase is the same between the 3 ABIs.
1162
		# installed headers in this phase is the same between the 3 ABIs.
1161
		# If this ever changes, this hack will break, but that's unlikely
1163
		# If this ever changes, this hack will break, but that's unlikely
1162
		# as glibc discourages that behavior.
1164
		# as glibc discourages that behavior.
1163
		# https://crbug.com/647033
1165
		# https://crbug.com/647033
1164
		sed -i -e 's:abiflag=.*:abiflag=_ABIO32:' preconfigure || die
1166
		sed -i -e 's:abiflag=.*:abiflag=_ABIO32:' preconfigure || die
1165
1167
1166
		popd >/dev/null
1168
		popd >/dev/null
1167
	fi
1169
	fi
1168
1170
1169
	local myconf=()
1171
	local myconf=()
1170
1172
1171
	case ${CTARGET} in
1173
	case ${CTARGET} in
1172
	aarch64*)
1174
	aarch64*)
1173
		# The configure checks fail during cross-build, so disable here
1175
		# The configure checks fail during cross-build, so disable here
1174
		# for headers-only
1176
		# for headers-only
1175
		myconf+=(
1177
		myconf+=(
1176
			--disable-mathvec
1178
			--disable-mathvec
1177
		) ;;
1179
		) ;;
1178
	riscv*)
1180
	riscv*)
1179
		# RISC-V interrogates the compiler to determine which target to
1181
		# RISC-V interrogates the compiler to determine which target to
1180
		# build.  If building the headers then we don't strictly need a
1182
		# build.  If building the headers then we don't strictly need a
1181
		# RISC-V compiler, so the built-in definitions that are provided
1183
		# RISC-V compiler, so the built-in definitions that are provided
1182
		# along with all RISC-V compiler might not exist.  This causes
1184
		# along with all RISC-V compiler might not exist.  This causes
1183
		# glibc's RISC-V preconfigure script to blow up.  Since we're just
1185
		# glibc's RISC-V preconfigure script to blow up.  Since we're just
1184
		# building the headers any value will actually work here, so just
1186
		# building the headers any value will actually work here, so just
1185
		# pick the standard one (rv64g/lp64d) to make the build scripts
1187
		# pick the standard one (rv64g/lp64d) to make the build scripts
1186
		# happy for now -- the headers are all the same anyway so it
1188
		# happy for now -- the headers are all the same anyway so it
1187
		# doesn't matter.
1189
		# doesn't matter.
1188
		headers_only_arch_CPPFLAGS+=(
1190
		headers_only_arch_CPPFLAGS+=(
1189
			-D__riscv_xlen=64
1191
			-D__riscv_xlen=64
1190
			-D__riscv_flen=64
1192
			-D__riscv_flen=64
1191
			-D__riscv_float_abi_double=1
1193
			-D__riscv_float_abi_double=1
1192
			-D__riscv_atomic=1
1194
			-D__riscv_atomic=1
1193
		) ;;
1195
		) ;;
1194
	esac
1196
	esac
1195
1197
1196
	myconf+=(
1198
	myconf+=(
1197
		--disable-sanity-checks
1199
		--disable-sanity-checks
1198
		--enable-hacker-mode
1200
		--enable-hacker-mode
1199
		--disable-werror
1201
		--disable-werror
1200
		--enable-bind-now
1202
		--enable-bind-now
1201
		--build=${CBUILD_OPT:-${CBUILD}}
1203
		--build=${CBUILD_OPT:-${CBUILD}}
1202
		--host=${CTARGET_OPT:-${CTARGET}}
1204
		--host=${CTARGET_OPT:-${CTARGET}}
1203
		--with-headers=$(build_eprefix)$(alt_build_headers)
1205
		--with-headers=$(build_eprefix)$(alt_build_headers)
1204
		--prefix="$(host_eprefix)/usr"
1206
		--prefix="$(host_eprefix)/usr"
1205
		$(use_enable crypt)
1207
		$(use_enable crypt)
1206
		${EXTRA_ECONF}
1208
		${EXTRA_ECONF}
1207
	)
1209
	)
1208
1210
1209
	# Nothing is compiled here which would affect the headers for the target.
1211
	# Nothing is compiled here which would affect the headers for the target.
1210
	# So forcing CC/CFLAGS is sane.
1212
	# So forcing CC/CFLAGS is sane.
1211
	local headers_only_CC=$(tc-getBUILD_CC)
1213
	local headers_only_CC=$(tc-getBUILD_CC)
1212
	local headers_only_CFLAGS="-O1 -pipe"
1214
	local headers_only_CFLAGS="-O1 -pipe"
1213
	local headers_only_CPPFLAGS="-U_FORTIFY_SOURCE ${headers_only_arch_CPPFLAGS[*]}"
1215
	local headers_only_CPPFLAGS="-U_FORTIFY_SOURCE ${headers_only_arch_CPPFLAGS[*]}"
1214
	local headers_only_LDFLAGS=""
1216
	local headers_only_LDFLAGS=""
1215
	set -- "${S}"/configure "${myconf[@]}"
1217
	set -- "${S}"/configure "${myconf[@]}"
1216
	echo \
1218
	echo \
1217
		"CC=${headers_only_CC}" \
1219
		"CC=${headers_only_CC}" \
1218
		"CFLAGS=${headers_only_CFLAGS}" \
1220
		"CFLAGS=${headers_only_CFLAGS}" \
1219
		"CPPFLAGS=${headers_only_CPPFLAGS}" \
1221
		"CPPFLAGS=${headers_only_CPPFLAGS}" \
1220
		"LDFLAGS=${headers_only_LDFLAGS}" \
1222
		"LDFLAGS=${headers_only_LDFLAGS}" \
1221
		"$@"
1223
		"$@"
1222
	CC=${headers_only_CC} \
1224
	CC=${headers_only_CC} \
1223
	CFLAGS=${headers_only_CFLAGS} \
1225
	CFLAGS=${headers_only_CFLAGS} \
1224
	CPPFLAGS=${headers_only_CPPFLAGS} \
1226
	CPPFLAGS=${headers_only_CPPFLAGS} \
1225
	LDFLAGS="" \
1227
	LDFLAGS="" \
1226
	"$@" || die "failed to configure glibc"
1228
	"$@" || die "failed to configure glibc"
1227
}
1229
}
1228
1230
1229
do_src_configure() {
1231
do_src_configure() {
1230
	if just_headers ; then
1232
	if just_headers ; then
1231
		glibc_headers_configure
1233
		glibc_headers_configure
1232
	else
1234
	else
1233
		glibc_do_configure nptl
1235
		glibc_do_configure nptl
1234
	fi
1236
	fi
1235
}
1237
}
1236
1238
1237
src_configure() {
1239
src_configure() {
1238
	foreach_abi do_src_configure
1240
	foreach_abi do_src_configure
1239
}
1241
}
1240
1242
1241
# src_compile
1243
# src_compile
1242
1244
1243
do_src_compile() {
1245
do_src_compile() {
1244
	emake -C "$(builddir nptl)"
1246
	emake -C "$(builddir nptl)"
1245
}
1247
}
1246
1248
1247
src_compile() {
1249
src_compile() {
1248
	if just_headers ; then
1250
	if just_headers ; then
1249
		return
1251
		return
1250
	fi
1252
	fi
1251
1253
1252
	foreach_abi do_src_compile
1254
	foreach_abi do_src_compile
1253
}
1255
}
1254
1256
1255
# src_test
1257
# src_test
1256
1258
1257
glibc_src_test() {
1259
glibc_src_test() {
1258
	cd "$(builddir nptl)"
1260
	cd "$(builddir nptl)"
1259
1261
1260
	local myxfailparams=""
1262
	local myxfailparams=""
1261
	if [[ "${GENTOO_GLIBC_XFAIL_TESTS}" == "yes" ]] ; then
1263
	if [[ "${GENTOO_GLIBC_XFAIL_TESTS}" == "yes" ]] ; then
1262
		local virt=$(systemd-detect-virt 2>/dev/null)
1264
		local virt=$(systemd-detect-virt 2>/dev/null)
1263
		if [[ ${virt} == systemd-nspawn ]] ; then
1265
		if [[ ${virt} == systemd-nspawn ]] ; then
1264
			ewarn "Skipping extra tests because in systemd-nspawn container"
1266
			ewarn "Skipping extra tests because in systemd-nspawn container"
1265
			XFAIL_TEST_LIST+=( "${XFAIL_NSPAWN_TEST_LIST[@]}" )
1267
			XFAIL_TEST_LIST+=( "${XFAIL_NSPAWN_TEST_LIST[@]}" )
1266
		fi
1268
		fi
1267
1269
1268
		for myt in ${XFAIL_TEST_LIST[@]} ; do
1270
		for myt in ${XFAIL_TEST_LIST[@]} ; do
1269
			myxfailparams+="test-xfail-${myt}=yes "
1271
			myxfailparams+="test-xfail-${myt}=yes "
1270
		done
1272
		done
1271
	fi
1273
	fi
1272
1274
1273
	# sandbox does not understand unshare() and prevents
1275
	# sandbox does not understand unshare() and prevents
1274
	# writes to /proc/, which makes many tests fail
1276
	# writes to /proc/, which makes many tests fail
1275
1277
1276
	# we give the tests a bit more time to avoid spurious
1278
	# we give the tests a bit more time to avoid spurious
1277
	# bug reports on slow arches
1279
	# bug reports on slow arches
1278
1280
1279
	SANDBOX_ON=0 LD_PRELOAD= TIMEOUTFACTOR=32 emake ${myxfailparams} check
1281
	SANDBOX_ON=0 LD_PRELOAD= TIMEOUTFACTOR=32 emake ${myxfailparams} check
1280
}
1282
}
1281
1283
1282
src_test() {
1284
src_test() {
1283
	if just_headers ; then
1285
	if just_headers ; then
1284
		return
1286
		return
1285
	fi
1287
	fi
1286
1288
1287
	foreach_abi glibc_src_test || die "tests failed"
1289
	foreach_abi glibc_src_test || die "tests failed"
1288
}
1290
}
1289
1291
1290
# src_install
1292
# src_install
1291
1293
1292
run_locale_gen() {
1294
run_locale_gen() {
1293
	# if the host locales.gen contains no entries, we'll install everything
1295
	# if the host locales.gen contains no entries, we'll install everything
1294
	local root="$1"
1296
	local root="$1"
1295
	local inplace=""
1297
	local inplace=""
1296
1298
1297
	if [[ "${root}" == "--inplace-glibc" ]] ; then
1299
	if [[ "${root}" == "--inplace-glibc" ]] ; then
1298
		inplace="--inplace-glibc"
1300
		inplace="--inplace-glibc"
1299
		root="$2"
1301
		root="$2"
1300
	fi
1302
	fi
1301
1303
1302
	local locale_list="${root%/}/etc/locale.gen"
1304
	local locale_list="${root%/}/etc/locale.gen"
1303
1305
1304
	pushd "${ED}"/$(get_libdir) >/dev/null
1306
	pushd "${ED}"/$(get_libdir) >/dev/null
1305
1307
1306
	if [[ -z $(locale-gen --list --config "${locale_list}") ]] ; then
1308
	if [[ -z $(locale-gen --list --config "${locale_list}") ]] ; then
1307
		[[ -z ${inplace} ]] && ewarn "Generating all locales; edit /etc/locale.gen to save time/space"
1309
		[[ -z ${inplace} ]] && ewarn "Generating all locales; edit /etc/locale.gen to save time/space"
1308
		locale_list="${root%/}/usr/share/i18n/SUPPORTED"
1310
		locale_list="${root%/}/usr/share/i18n/SUPPORTED"
1309
	fi
1311
	fi
1310
1312
1311
	# bug 736794: we need to be careful with the parallelization... the number of
1313
	# bug 736794: we need to be careful with the parallelization... the number of
1312
	# processors saved in the environment of a binary package may differ strongly
1314
	# processors saved in the environment of a binary package may differ strongly
1313
	# from the number of processes available during postinst
1315
	# from the number of processes available during postinst
1314
	local mygenjobs="$(makeopts_jobs)"
1316
	local mygenjobs="$(makeopts_jobs)"
1315
	if [[ "${EMERGE_FROM}" == "binary" ]] ; then
1317
	if [[ "${EMERGE_FROM}" == "binary" ]] ; then
1316
		mygenjobs="$(nproc)"
1318
		mygenjobs="$(nproc)"
1317
	fi
1319
	fi
1318
1320
1319
	set -- locale-gen ${inplace} --jobs "${mygenjobs}" --config "${locale_list}" \
1321
	set -- locale-gen ${inplace} --jobs "${mygenjobs}" --config "${locale_list}" \
1320
		--destdir "${root}"
1322
		--destdir "${root}"
1321
	echo "$@"
1323
	echo "$@"
1322
	"$@"
1324
	"$@"
1323
1325
1324
	popd >/dev/null
1326
	popd >/dev/null
1325
}
1327
}
1326
1328
1327
glibc_do_src_install() {
1329
glibc_do_src_install() {
1328
	local builddir=$(builddir nptl)
1330
	local builddir=$(builddir nptl)
1329
	cd "${builddir}"
1331
	cd "${builddir}"
1330
1332
1331
	emake install_root="${D}/$(build_eprefix)$(alt_prefix)" install
1333
	emake install_root="${D}/$(build_eprefix)$(alt_prefix)" install
1332
1334
1333
	# This version (2.26) provides some compatibility libraries for the NIS/NIS+ support
1335
	# This version (2.26) provides some compatibility libraries for the NIS/NIS+ support
1334
	# which come without headers etc. Only needed for binary packages since the
1336
	# which come without headers etc. Only needed for binary packages since the
1335
	# external net-libs/libnsl has increased soversion. Keep only versioned libraries.
1337
	# external net-libs/libnsl has increased soversion. Keep only versioned libraries.
1336
	find "${D}" -name "libnsl.a" -delete
1338
	find "${D}" -name "libnsl.a" -delete
1337
	find "${D}" -name "libnsl.so" -delete
1339
	find "${D}" -name "libnsl.so" -delete
1338
1340
1339
	# Normally upstream_pv is ${PV}. Live ebuilds are exception, there we need
1341
	# Normally upstream_pv is ${PV}. Live ebuilds are exception, there we need
1340
	# to infer upstream version:
1342
	# to infer upstream version:
1341
	# '#define VERSION "2.26.90"' -> '2.26.90'
1343
	# '#define VERSION "2.26.90"' -> '2.26.90'
1342
	local upstream_pv=$(sed -n -r 's/#define VERSION "(.*)"/\1/p' "${S}"/version.h)
1344
	local upstream_pv=$(sed -n -r 's/#define VERSION "(.*)"/\1/p' "${S}"/version.h)
1343
1345
1344
	# Avoid stripping binaries not targeted by ${CHOST}. Or else
1346
	# Avoid stripping binaries not targeted by ${CHOST}. Or else
1345
	# ${CHOST}-strip would break binaries build for ${CTARGET}.
1347
	# ${CHOST}-strip would break binaries build for ${CTARGET}.
1346
	is_crosscompile && dostrip -x /
1348
	is_crosscompile && dostrip -x /
1347
1349
1348
	# gdb thread introspection relies on local libpthreads symbols. stripping breaks it
1350
	# gdb thread introspection relies on local libpthreads symbols. stripping breaks it
1349
	# See Note [Disable automatic stripping]
1351
	# See Note [Disable automatic stripping]
1350
	dostrip -x $(alt_libdir)/libpthread-${upstream_pv}.so
1352
	dostrip -x $(alt_libdir)/libpthread-${upstream_pv}.so
1353
	# valgrind requires knowledge about ld.so symbols.
1354
	dostrip -x $(alt_libdir)/ld-*.so*
1351
1355
1352
	if [[ -e ${ED}/$(alt_usrlibdir)/libm-${upstream_pv}.a ]] ; then
1356
	if [[ -e ${ED}/$(alt_usrlibdir)/libm-${upstream_pv}.a ]] ; then
1353
		# Move versioned .a file out of libdir to evade portage QA checks
1357
		# Move versioned .a file out of libdir to evade portage QA checks
1354
		# instead of using gen_usr_ldscript(). We fix ldscript as:
1358
		# instead of using gen_usr_ldscript(). We fix ldscript as:
1355
		# "GROUP ( /usr/lib64/libm-<pv>.a ..." -> "GROUP ( /usr/lib64/glibc-<pv>/libm-<pv>.a ..."
1359
		# "GROUP ( /usr/lib64/libm-<pv>.a ..." -> "GROUP ( /usr/lib64/glibc-<pv>/libm-<pv>.a ..."
1356
		sed -i "s@\(libm-${upstream_pv}.a\)@${P}/\1@" "${ED}"/$(alt_usrlibdir)/libm.a || die
1360
		sed -i "s@\(libm-${upstream_pv}.a\)@${P}/\1@" "${ED}"/$(alt_usrlibdir)/libm.a || die
1357
		dodir $(alt_usrlibdir)/${P}
1361
		dodir $(alt_usrlibdir)/${P}
1358
		mv "${ED}"/$(alt_usrlibdir)/libm-${upstream_pv}.a "${ED}"/$(alt_usrlibdir)/${P}/libm-${upstream_pv}.a || die
1362
		mv "${ED}"/$(alt_usrlibdir)/libm-${upstream_pv}.a "${ED}"/$(alt_usrlibdir)/${P}/libm-${upstream_pv}.a || die
1359
	fi
1363
	fi
1360
1364
1361
	# We configure toolchains for standalone prefix systems with a sysroot,
1365
	# We configure toolchains for standalone prefix systems with a sysroot,
1362
	# which is prepended to paths in ld scripts, so strip the prefix from these.
1366
	# which is prepended to paths in ld scripts, so strip the prefix from these.
1363
	# Before: GROUP ( /foo/lib64/libc.so.6 /foo/usr/lib64/libc_nonshared.a  AS_NEEDED ( /foo/lib64/ld-linux-x86-64.so.2 ) )
1367
	# Before: GROUP ( /foo/lib64/libc.so.6 /foo/usr/lib64/libc_nonshared.a  AS_NEEDED ( /foo/lib64/ld-linux-x86-64.so.2 ) )
1364
	# After: GROUP ( /lib64/libc.so.6 /usr/lib64/libc_nonshared.a  AS_NEEDED ( /lib64/ld-linux-x86-64.so.2 ) )
1368
	# After: GROUP ( /lib64/libc.so.6 /usr/lib64/libc_nonshared.a  AS_NEEDED ( /lib64/ld-linux-x86-64.so.2 ) )
1365
	if [[ -n $(host_eprefix) ]] ; then
1369
	if [[ -n $(host_eprefix) ]] ; then
1366
		local file
1370
		local file
1367
		grep -lZIF "ld script" "${ED}/$(alt_usrlibdir)"/lib*.{a,so} 2>/dev/null | while read -rd '' file ; do
1371
		grep -lZIF "ld script" "${ED}/$(alt_usrlibdir)"/lib*.{a,so} 2>/dev/null | while read -rd '' file ; do
1368
			sed -i "s|$(host_eprefix)/|/|g" "${file}" || die
1372
			sed -i "s|$(host_eprefix)/|/|g" "${file}" || die
1369
		done
1373
		done
1370
	fi
1374
	fi
1371
1375
1372
	# We'll take care of the cache ourselves
1376
	# We'll take care of the cache ourselves
1373
	rm -f "${ED}"/etc/ld.so.cache
1377
	rm -f "${ED}"/etc/ld.so.cache
1374
1378
1375
	# Everything past this point just needs to be done once ...
1379
	# Everything past this point just needs to be done once ...
1376
	is_final_abi || return 0
1380
	is_final_abi || return 0
1377
1381
1378
	# Make sure the non-native interp can be found on multilib systems even
1382
	# Make sure the non-native interp can be found on multilib systems even
1379
	# if the main library set isn't installed into the right place.  Maybe
1383
	# if the main library set isn't installed into the right place.  Maybe
1380
	# we should query the active gcc for info instead of hardcoding it ?
1384
	# we should query the active gcc for info instead of hardcoding it ?
1381
	local i ldso_abi ldso_name
1385
	local i ldso_abi ldso_name
1382
	local ldso_abi_list=(
1386
	local ldso_abi_list=(
1383
		# x86
1387
		# x86
1384
		amd64   /lib64/ld-linux-x86-64.so.2
1388
		amd64   /lib64/ld-linux-x86-64.so.2
1385
		x32     /libx32/ld-linux-x32.so.2
1389
		x32     /libx32/ld-linux-x32.so.2
1386
		x86     /lib/ld-linux.so.2
1390
		x86     /lib/ld-linux.so.2
1387
		# mips
1391
		# mips
1388
		o32     /lib/ld.so.1
1392
		o32     /lib/ld.so.1
1389
		n32     /lib32/ld.so.1
1393
		n32     /lib32/ld.so.1
1390
		n64     /lib64/ld.so.1
1394
		n64     /lib64/ld.so.1
1391
		# powerpc
1395
		# powerpc
1392
		ppc     /lib/ld.so.1
1396
		ppc     /lib/ld.so.1
1393
		# riscv
1397
		# riscv
1394
		ilp32d  /lib/ld-linux-riscv32-ilp32d.so.1
1398
		ilp32d  /lib/ld-linux-riscv32-ilp32d.so.1
1395
		ilp32   /lib/ld-linux-riscv32-ilp32.so.1
1399
		ilp32   /lib/ld-linux-riscv32-ilp32.so.1
1396
		lp64d   /lib/ld-linux-riscv64-lp64d.so.1
1400
		lp64d   /lib/ld-linux-riscv64-lp64d.so.1
1397
		lp64    /lib/ld-linux-riscv64-lp64.so.1
1401
		lp64    /lib/ld-linux-riscv64-lp64.so.1
1398
		# s390
1402
		# s390
1399
		s390    /lib/ld.so.1
1403
		s390    /lib/ld.so.1
1400
		s390x   /lib/ld64.so.1
1404
		s390x   /lib/ld64.so.1
1401
		# sparc
1405
		# sparc
1402
		sparc32 /lib/ld-linux.so.2
1406
		sparc32 /lib/ld-linux.so.2
1403
		sparc64 /lib64/ld-linux.so.2
1407
		sparc64 /lib64/ld-linux.so.2
1404
	)
1408
	)
1405
	case $(tc-endian) in
1409
	case $(tc-endian) in
1406
	little)
1410
	little)
1407
		ldso_abi_list+=(
1411
		ldso_abi_list+=(
1408
			# arm
1412
			# arm
1409
			arm64   /lib/ld-linux-aarch64.so.1
1413
			arm64   /lib/ld-linux-aarch64.so.1
1410
			# ELFv2 (glibc does not support ELFv1 on LE)
1414
			# ELFv2 (glibc does not support ELFv1 on LE)
1411
			ppc64   /lib64/ld64.so.2
1415
			ppc64   /lib64/ld64.so.2
1412
		)
1416
		)
1413
		;;
1417
		;;
1414
	big)
1418
	big)
1415
		ldso_abi_list+=(
1419
		ldso_abi_list+=(
1416
			# arm
1420
			# arm
1417
			arm64   /lib/ld-linux-aarch64_be.so.1
1421
			arm64   /lib/ld-linux-aarch64_be.so.1
1418
			# ELFv1 (glibc does not support ELFv2 on BE)
1422
			# ELFv1 (glibc does not support ELFv2 on BE)
1419
			ppc64   /lib64/ld64.so.1
1423
			ppc64   /lib64/ld64.so.1
1420
		)
1424
		)
1421
		;;
1425
		;;
1422
	esac
1426
	esac
1423
	if [[ ${SYMLINK_LIB} == "yes" ]] && [[ ! -e ${ED}/$(alt_prefix)/lib ]] ; then
1427
	if [[ ${SYMLINK_LIB} == "yes" ]] && [[ ! -e ${ED}/$(alt_prefix)/lib ]] ; then
1424
		dosym $(get_abi_LIBDIR ${DEFAULT_ABI}) $(alt_prefix)/lib
1428
		dosym $(get_abi_LIBDIR ${DEFAULT_ABI}) $(alt_prefix)/lib
1425
	fi
1429
	fi
1426
	for (( i = 0; i < ${#ldso_abi_list[@]}; i += 2 )) ; do
1430
	for (( i = 0; i < ${#ldso_abi_list[@]}; i += 2 )) ; do
1427
		ldso_abi=${ldso_abi_list[i]}
1431
		ldso_abi=${ldso_abi_list[i]}
1428
		has ${ldso_abi} $(get_install_abis) || continue
1432
		has ${ldso_abi} $(get_install_abis) || continue
1429
1433
1430
		ldso_name="$(alt_prefix)${ldso_abi_list[i+1]}"
1434
		ldso_name="$(alt_prefix)${ldso_abi_list[i+1]}"
1431
		if [[ ! -L ${ED}/${ldso_name} && ! -e ${ED}/${ldso_name} ]] ; then
1435
		if [[ ! -L ${ED}/${ldso_name} && ! -e ${ED}/${ldso_name} ]] ; then
1432
			dosym ../$(get_abi_LIBDIR ${ldso_abi})/${ldso_name##*/} ${ldso_name}
1436
			dosym ../$(get_abi_LIBDIR ${ldso_abi})/${ldso_name##*/} ${ldso_name}
1433
		fi
1437
		fi
1434
	done
1438
	done
1435
1439
1436
	# In the LSB 5.0 definition, someone had the excellent idea to "standardize"
1440
	# In the LSB 5.0 definition, someone had the excellent idea to "standardize"
1437
	# the runtime loader name, see also https://xkcd.com/927/
1441
	# the runtime loader name, see also https://xkcd.com/927/
1438
	# Normally, in Gentoo one should never come across executables that require this.
1442
	# Normally, in Gentoo one should never come across executables that require this.
1439
	# However, binary commercial packages are known to adhere to weird practices.
1443
	# However, binary commercial packages are known to adhere to weird practices.
1440
	# https://refspecs.linuxfoundation.org/LSB_5.0.0/LSB-Core-AMD64/LSB-Core-AMD64.html#BASELIB
1444
	# https://refspecs.linuxfoundation.org/LSB_5.0.0/LSB-Core-AMD64/LSB-Core-AMD64.html#BASELIB
1441
	local lsb_ldso_name native_ldso_name lsb_ldso_abi
1445
	local lsb_ldso_name native_ldso_name lsb_ldso_abi
1442
	local lsb_ldso_abi_list=(
1446
	local lsb_ldso_abi_list=(
1443
		# x86
1447
		# x86
1444
		amd64	ld-linux-x86-64.so.2	ld-lsb-x86-64.so.3
1448
		amd64	ld-linux-x86-64.so.2	ld-lsb-x86-64.so.3
1445
	)
1449
	)
1446
	for (( i = 0; i < ${#lsb_ldso_abi_list[@]}; i += 3 )) ; do
1450
	for (( i = 0; i < ${#lsb_ldso_abi_list[@]}; i += 3 )) ; do
1447
		lsb_ldso_abi=${lsb_ldso_abi_list[i]}
1451
		lsb_ldso_abi=${lsb_ldso_abi_list[i]}
1448
		native_ldso_name=${lsb_ldso_abi_list[i+1]}
1452
		native_ldso_name=${lsb_ldso_abi_list[i+1]}
1449
		lsb_ldso_name=${lsb_ldso_abi_list[i+2]}
1453
		lsb_ldso_name=${lsb_ldso_abi_list[i+2]}
1450
		has ${lsb_ldso_abi} $(get_install_abis) || continue
1454
		has ${lsb_ldso_abi} $(get_install_abis) || continue
1451
1455
1452
		if [[ ! -L ${ED}/$(get_abi_LIBDIR ${lsb_ldso_abi})/${lsb_ldso_name} && ! -e ${ED}/$(get_abi_LIBDIR ${lsb_ldso_abi})/${lsb_ldso_name} ]] ; then
1456
		if [[ ! -L ${ED}/$(get_abi_LIBDIR ${lsb_ldso_abi})/${lsb_ldso_name} && ! -e ${ED}/$(get_abi_LIBDIR ${lsb_ldso_abi})/${lsb_ldso_name} ]] ; then
1453
			dosym ${native_ldso_name} "$(alt_prefix)/$(get_abi_LIBDIR ${lsb_ldso_abi})/${lsb_ldso_name}"
1457
			dosym ${native_ldso_name} "$(alt_prefix)/$(get_abi_LIBDIR ${lsb_ldso_abi})/${lsb_ldso_name}"
1454
		fi
1458
		fi
1455
	done
1459
	done
1456
1460
1457
	# With devpts under Linux mounted properly, we do not need the pt_chown
1461
	# With devpts under Linux mounted properly, we do not need the pt_chown
1458
	# binary to be setuid.  This is because the default owners/perms will be
1462
	# binary to be setuid.  This is because the default owners/perms will be
1459
	# exactly what we want.
1463
	# exactly what we want.
1460
	if ! use suid ; then
1464
	if ! use suid ; then
1461
		find "${ED}" -name pt_chown -exec chmod -s {} +
1465
		find "${ED}" -name pt_chown -exec chmod -s {} +
1462
	fi
1466
	fi
1463
1467
1464
	#################################################################
1468
	#################################################################
1465
	# EVERYTHING AFTER THIS POINT IS FOR NATIVE GLIBC INSTALLS ONLY #
1469
	# EVERYTHING AFTER THIS POINT IS FOR NATIVE GLIBC INSTALLS ONLY #
1466
	#################################################################
1470
	#################################################################
1467
1471
1468
	# Make sure we install some symlink hacks so that when we build
1472
	# Make sure we install some symlink hacks so that when we build
1469
	# a 2nd stage cross-compiler, gcc finds the target system
1473
	# a 2nd stage cross-compiler, gcc finds the target system
1470
	# headers correctly.  See gcc/doc/gccinstall.info
1474
	# headers correctly.  See gcc/doc/gccinstall.info
1471
	if is_crosscompile ; then
1475
	if is_crosscompile ; then
1472
		# We need to make sure that /lib and /usr/lib always exists.
1476
		# We need to make sure that /lib and /usr/lib always exists.
1473
		# gcc likes to use relative paths to get to its multilibs like
1477
		# gcc likes to use relative paths to get to its multilibs like
1474
		# /usr/lib/../lib64/.  So while we don't install any files into
1478
		# /usr/lib/../lib64/.  So while we don't install any files into
1475
		# /usr/lib/, we do need it to exist.
1479
		# /usr/lib/, we do need it to exist.
1476
		keepdir $(alt_prefix)/lib
1480
		keepdir $(alt_prefix)/lib
1477
		keepdir $(alt_prefix)/usr/lib
1481
		keepdir $(alt_prefix)/usr/lib
1478
1482
1479
		dosym usr/include $(alt_prefix)/sys-include
1483
		dosym usr/include $(alt_prefix)/sys-include
1480
		return 0
1484
		return 0
1481
	fi
1485
	fi
1482
1486
1483
	# Files for Debian-style locale updating
1487
	# Files for Debian-style locale updating
1484
	dodir /usr/share/i18n
1488
	dodir /usr/share/i18n
1485
	sed \
1489
	sed \
1486
		-e "/^#/d" \
1490
		-e "/^#/d" \
1487
		-e "/SUPPORTED-LOCALES=/d" \
1491
		-e "/SUPPORTED-LOCALES=/d" \
1488
		-e "s: \\\\::g" -e "s:/: :g" \
1492
		-e "s: \\\\::g" -e "s:/: :g" \
1489
		"${S}"/localedata/SUPPORTED > "${ED}"/usr/share/i18n/SUPPORTED \
1493
		"${S}"/localedata/SUPPORTED > "${ED}"/usr/share/i18n/SUPPORTED \
1490
		|| die "generating /usr/share/i18n/SUPPORTED failed"
1494
		|| die "generating /usr/share/i18n/SUPPORTED failed"
1491
1495
1492
	cd "${S}" || die
1496
	cd "${S}" || die
1493
1497
1494
	# Install misc network config files
1498
	# Install misc network config files
1495
	insinto /etc
1499
	insinto /etc
1496
	doins posix/gai.conf
1500
	doins posix/gai.conf
1497
1501
1498
	if use systemd ; then
1502
	if use systemd ; then
1499
		doins "${WORKDIR}/glibc-systemd-${GLIBC_SYSTEMD_VER}/gentoo-config/nsswitch.conf"
1503
		doins "${WORKDIR}/glibc-systemd-${GLIBC_SYSTEMD_VER}/gentoo-config/nsswitch.conf"
1500
	else
1504
	else
1501
		doins nss/nsswitch.conf
1505
		doins nss/nsswitch.conf
1502
	fi
1506
	fi
1503
1507
1504
	# Gentoo-specific
1508
	# Gentoo-specific
1505
	newins "${FILESDIR}"/host.conf-1 host.conf
1509
	newins "${FILESDIR}"/host.conf-1 host.conf
1506
1510
1507
	if use nscd ; then
1511
	if use nscd ; then
1508
		doins nscd/nscd.conf
1512
		doins nscd/nscd.conf
1509
1513
1510
		newinitd "$(prefixify_ro "${FILESDIR}"/nscd-1)" nscd
1514
		newinitd "$(prefixify_ro "${FILESDIR}"/nscd-1)" nscd
1511
1515
1512
		local nscd_args=(
1516
		local nscd_args=(
1513
			-e "s:@PIDFILE@:$(strings "${ED}"/usr/sbin/nscd | grep nscd.pid):"
1517
			-e "s:@PIDFILE@:$(strings "${ED}"/usr/sbin/nscd | grep nscd.pid):"
1514
		)
1518
		)
1515
1519
1516
		sed -i "${nscd_args[@]}" "${ED}"/etc/init.d/nscd
1520
		sed -i "${nscd_args[@]}" "${ED}"/etc/init.d/nscd
1517
1521
1518
		use systemd && systemd_dounit nscd/nscd.service
1522
		use systemd && systemd_dounit nscd/nscd.service
1519
		newtmpfiles nscd/nscd.tmpfiles nscd.conf
1523
		newtmpfiles nscd/nscd.tmpfiles nscd.conf
1520
	fi
1524
	fi
1521
1525
1522
	echo 'LDPATH="include ld.so.conf.d/*.conf"' > "${T}"/00glibc
1526
	echo 'LDPATH="include ld.so.conf.d/*.conf"' > "${T}"/00glibc
1523
	doenvd "${T}"/00glibc
1527
	doenvd "${T}"/00glibc
1524
1528
1525
	for d in BUGS ChangeLog CONFORMANCE FAQ NEWS NOTES PROJECTS README* ; do
1529
	for d in BUGS ChangeLog CONFORMANCE FAQ NEWS NOTES PROJECTS README* ; do
1526
		[[ -s ${d} ]] && dodoc ${d}
1530
		[[ -s ${d} ]] && dodoc ${d}
1527
	done
1531
	done
1528
	dodoc -r ChangeLog.old
1532
	dodoc -r ChangeLog.old
1529
1533
1530
	# Prevent overwriting of the /etc/localtime symlink.  We'll handle the
1534
	# Prevent overwriting of the /etc/localtime symlink.  We'll handle the
1531
	# creation of the "factory" symlink in pkg_postinst().
1535
	# creation of the "factory" symlink in pkg_postinst().
1532
	rm -f "${ED}"/etc/localtime
1536
	rm -f "${ED}"/etc/localtime
1533
1537
1534
	# Generate all locales if this is a native build as locale generation
1538
	# Generate all locales if this is a native build as locale generation
1535
	if use compile-locales && ! is_crosscompile ; then
1539
	if use compile-locales && ! is_crosscompile ; then
1536
		run_locale_gen --inplace-glibc "${ED}/"
1540
		run_locale_gen --inplace-glibc "${ED}/"
1537
	fi
1541
	fi
1538
}
1542
}
1539
1543
1540
glibc_headers_install() {
1544
glibc_headers_install() {
1541
	local builddir=$(builddir "headers")
1545
	local builddir=$(builddir "headers")
1542
	cd "${builddir}"
1546
	cd "${builddir}"
1543
	emake install_root="${D}/$(build_eprefix)$(alt_prefix)" install-headers
1547
	emake install_root="${D}/$(build_eprefix)$(alt_prefix)" install-headers
1544
1548
1545
	insinto $(alt_headers)/gnu
1549
	insinto $(alt_headers)/gnu
1546
	doins "${S}"/include/gnu/stubs.h
1550
	doins "${S}"/include/gnu/stubs.h
1547
1551
1548
	# Make sure we install the sys-include symlink so that when
1552
	# Make sure we install the sys-include symlink so that when
1549
	# we build a 2nd stage cross-compiler, gcc finds the target
1553
	# we build a 2nd stage cross-compiler, gcc finds the target
1550
	# system headers correctly.  See gcc/doc/gccinstall.info
1554
	# system headers correctly.  See gcc/doc/gccinstall.info
1551
	dosym usr/include $(alt_prefix)/sys-include
1555
	dosym usr/include $(alt_prefix)/sys-include
1552
}
1556
}
1553
1557
1554
src_install() {
1558
src_install() {
1555
	if just_headers ; then
1559
	if just_headers ; then
1556
		export ABI=default
1560
		export ABI=default
1557
		glibc_headers_install
1561
		glibc_headers_install
1558
		return
1562
		return
1559
	fi
1563
	fi
1560
1564
1561
	foreach_abi glibc_do_src_install
1565
	foreach_abi glibc_do_src_install
1562
1566
1563
	if ! use static-libs ; then
1567
	if ! use static-libs ; then
1564
		einfo "Not installing static glibc libraries"
1568
		einfo "Not installing static glibc libraries"
1565
		find "${ED}" -name "*.a" -and -not -name "*_nonshared.a" -delete
1569
		find "${ED}" -name "*.a" -and -not -name "*_nonshared.a" -delete
1566
	fi
1570
	fi
1567
}
1571
}
1568
1572
1569
# Simple test to make sure our new glibc isn't completely broken.
1573
# Simple test to make sure our new glibc isn't completely broken.
1570
# Make sure we don't test with statically built binaries since
1574
# Make sure we don't test with statically built binaries since
1571
# they will fail.  Also, skip if this glibc is a cross compiler.
1575
# they will fail.  Also, skip if this glibc is a cross compiler.
1572
#
1576
#
1573
# If coreutils is built with USE=multicall, some of these files
1577
# If coreutils is built with USE=multicall, some of these files
1574
# will just be wrapper scripts, not actual ELFs we can test.
1578
# will just be wrapper scripts, not actual ELFs we can test.
1575
glibc_sanity_check() {
1579
glibc_sanity_check() {
1576
	cd / #228809
1580
	cd / #228809
1577
1581
1578
	# We enter ${ED} so to avoid trouble if the path contains
1582
	# We enter ${ED} so to avoid trouble if the path contains
1579
	# special characters; for instance if the path contains the
1583
	# special characters; for instance if the path contains the
1580
	# colon character (:), then the linker will try to split it
1584
	# colon character (:), then the linker will try to split it
1581
	# and look for the libraries in an unexpected place. This can
1585
	# and look for the libraries in an unexpected place. This can
1582
	# lead to unsafe code execution if the generated prefix is
1586
	# lead to unsafe code execution if the generated prefix is
1583
	# within a world-writable directory.
1587
	# within a world-writable directory.
1584
	# (e.g. /var/tmp/portage:${HOSTNAME})
1588
	# (e.g. /var/tmp/portage:${HOSTNAME})
1585
	pushd "${ED}"/$(get_libdir) >/dev/null
1589
	pushd "${ED}"/$(get_libdir) >/dev/null
1586
1590
1587
	# first let's find the actual dynamic linker here
1591
	# first let's find the actual dynamic linker here
1588
	# symlinks may point to the wrong abi
1592
	# symlinks may point to the wrong abi
1589
	local newldso=$(find . -maxdepth 1 -name 'ld*so.?' -type f -print -quit)
1593
	local newldso=$(find . -maxdepth 1 -name 'ld*so.?' -type f -print -quit)
1590
1594
1591
	einfo Last-minute run tests with ${newldso} in /$(get_libdir) ...
1595
	einfo Last-minute run tests with ${newldso} in /$(get_libdir) ...
1592
1596
1593
	local x striptest
1597
	local x striptest
1594
	for x in cal date env free ls true uname uptime ; do
1598
	for x in cal date env free ls true uname uptime ; do
1595
		x=$(type -p ${x})
1599
		x=$(type -p ${x})
1596
		[[ -z ${x} || ${x} != ${EPREFIX}/* ]] && continue
1600
		[[ -z ${x} || ${x} != ${EPREFIX}/* ]] && continue
1597
		striptest=$(LC_ALL="C" file -L ${x} 2>/dev/null) || continue
1601
		striptest=$(LC_ALL="C" file -L ${x} 2>/dev/null) || continue
1598
		case ${striptest} in
1602
		case ${striptest} in
1599
		*"statically linked"*) continue;;
1603
		*"statically linked"*) continue;;
1600
		*"ASCII text"*) continue;;
1604
		*"ASCII text"*) continue;;
1601
		esac
1605
		esac
1602
		# We need to clear the locale settings as the upgrade might want
1606
		# We need to clear the locale settings as the upgrade might want
1603
		# incompatible locale data.  This test is not for verifying that.
1607
		# incompatible locale data.  This test is not for verifying that.
1604
		LC_ALL=C \
1608
		LC_ALL=C \
1605
		${newldso} --library-path . ${x} > /dev/null \
1609
		${newldso} --library-path . ${x} > /dev/null \
1606
			|| die "simple run test (${x}) failed"
1610
			|| die "simple run test (${x}) failed"
1607
	done
1611
	done
1608
1612
1609
	popd >/dev/null
1613
	popd >/dev/null
1610
}
1614
}
1611
1615
1612
pkg_preinst() {
1616
pkg_preinst() {
1613
	# nothing to do if just installing headers
1617
	# nothing to do if just installing headers
1614
	just_headers && return
1618
	just_headers && return
1615
1619
1616
	einfo "Checking general environment sanity."
1620
	einfo "Checking general environment sanity."
1617
	sanity_prechecks
1621
	sanity_prechecks
1618
1622
1619
	# prepare /etc/ld.so.conf.d/ for files
1623
	# prepare /etc/ld.so.conf.d/ for files
1620
	mkdir -p "${EROOT}"/etc/ld.so.conf.d
1624
	mkdir -p "${EROOT}"/etc/ld.so.conf.d
1621
1625
1622
	# Default /etc/hosts.conf:multi to on for systems with small dbs.
1626
	# Default /etc/hosts.conf:multi to on for systems with small dbs.
1623
	if [[ $(wc -l < "${EROOT}"/etc/hosts) -lt 1000 ]] ; then
1627
	if [[ $(wc -l < "${EROOT}"/etc/hosts) -lt 1000 ]] ; then
1624
		sed -i '/^multi off/s:off:on:' "${ED}"/etc/host.conf
1628
		sed -i '/^multi off/s:off:on:' "${ED}"/etc/host.conf
1625
		einfo "Defaulting /etc/host.conf:multi to on"
1629
		einfo "Defaulting /etc/host.conf:multi to on"
1626
	fi
1630
	fi
1627
1631
1628
	[[ -n ${ROOT} ]] && return 0
1632
	[[ -n ${ROOT} ]] && return 0
1629
	[[ -d ${ED}/$(get_libdir) ]] || return 0
1633
	[[ -d ${ED}/$(get_libdir) ]] || return 0
1630
	[[ -z ${BOOTSTRAP_RAP} ]] && glibc_sanity_check
1634
	[[ -z ${BOOTSTRAP_RAP} ]] && glibc_sanity_check
1631
1635
1632
	if [[ -L ${EROOT}/usr/lib/locale ]]; then
1636
	if [[ -L ${EROOT}/usr/lib/locale ]]; then
1633
		# Help portage migrate this to a directory
1637
		# Help portage migrate this to a directory
1634
		# https://bugs.gentoo.org/753740
1638
		# https://bugs.gentoo.org/753740
1635
		rm "${EROOT}"/usr/lib/locale || die
1639
		rm "${EROOT}"/usr/lib/locale || die
1636
	fi
1640
	fi
1637
1641
1638
	# Keep around libcrypt so that Perl doesn't break when merging libxcrypt
1642
	# Keep around libcrypt so that Perl doesn't break when merging libxcrypt
1639
	# (libxcrypt is the new provider for now of libcrypt.so.{1,2}).
1643
	# (libxcrypt is the new provider for now of libcrypt.so.{1,2}).
1640
	# bug #802207
1644
	# bug #802207
1641
	if ! use crypt && has_version "${CATEGORY}/${PN}[crypt]" && ! has preserve-libs ${FEATURES}; then
1645
	if ! use crypt && has_version "${CATEGORY}/${PN}[crypt]" && ! has preserve-libs ${FEATURES}; then
1642
		PRESERVED_OLD_LIBCRYPT=1
1646
		PRESERVED_OLD_LIBCRYPT=1
1643
		cp -p "${EROOT}/$(get_libdir)/libcrypt$(get_libname 1)" "${T}/libcrypt$(get_libname 1)" || die
1647
		cp -p "${EROOT}/$(get_libdir)/libcrypt$(get_libname 1)" "${T}/libcrypt$(get_libname 1)" || die
1644
	else
1648
	else
1645
		PRESERVED_OLD_LIBCRYPT=0
1649
		PRESERVED_OLD_LIBCRYPT=0
1646
	fi
1650
	fi
1647
}
1651
}
1648
1652
1649
glibc_refresh_ldconfig() {
1653
glibc_refresh_ldconfig() {
1650
	if [[ ${MERGE_TYPE} == buildonly ]]; then
1654
	if [[ ${MERGE_TYPE} == buildonly ]]; then
1651
		return
1655
		return
1652
	fi
1656
	fi
1653
1657
1654
	# Version check could be added to avoid unnecessary work, but ldconfig
1658
	# Version check could be added to avoid unnecessary work, but ldconfig
1655
	# should finish quickly enough to not matter.
1659
	# should finish quickly enough to not matter.
1656
	ebegin "Refreshing ld.so.cache"
1660
	ebegin "Refreshing ld.so.cache"
1657
	ldconfig -i
1661
	ldconfig -i
1658
	if ! eend $?; then
1662
	if ! eend $?; then
1659
		ewarn "Failed to refresh the ld.so.cache for you. Some programs may be broken"
1663
		ewarn "Failed to refresh the ld.so.cache for you. Some programs may be broken"
1660
		ewarn "before you manually do so (ldconfig -i)."
1664
		ewarn "before you manually do so (ldconfig -i)."
1661
	fi
1665
	fi
1662
}
1666
}
1663
1667
1664
pkg_postinst() {
1668
pkg_postinst() {
1665
	# nothing to do if just installing headers
1669
	# nothing to do if just installing headers
1666
	just_headers && return
1670
	just_headers && return
1667
1671
1668
	if ! tc-is-cross-compiler && [[ -x ${EROOT}/usr/sbin/iconvconfig ]] ; then
1672
	if ! tc-is-cross-compiler && [[ -x ${EROOT}/usr/sbin/iconvconfig ]] ; then
1669
		# Generate fastloading iconv module configuration file.
1673
		# Generate fastloading iconv module configuration file.
1670
		"${EROOT}"/usr/sbin/iconvconfig --prefix="${ROOT}/"
1674
		"${EROOT}"/usr/sbin/iconvconfig --prefix="${ROOT}/"
1671
	fi
1675
	fi
1672
1676
1673
	if ! is_crosscompile && [[ -z ${ROOT} ]] ; then
1677
	if ! is_crosscompile && [[ -z ${ROOT} ]] ; then
1674
		# glibc-2.38+ on loong has ldconfig support added, but the ELF e_flags
1678
		# glibc-2.38+ on loong has ldconfig support added, but the ELF e_flags
1675
		# handling has changed as well, which means stale ldconfig auxiliary
1679
		# handling has changed as well, which means stale ldconfig auxiliary
1676
		# cache entries and failure to lookup libgcc_s / libstdc++ (breaking
1680
		# cache entries and failure to lookup libgcc_s / libstdc++ (breaking
1677
		# every C++ application) / libgomp etc., among other breakages.
1681
		# every C++ application) / libgomp etc., among other breakages.
1678
		#
1682
		#
1679
		# To fix this, simply refresh the ld.so.cache without using the
1683
		# To fix this, simply refresh the ld.so.cache without using the
1680
		# auxiliary cache if we're natively installing on loong. This should
1684
		# auxiliary cache if we're natively installing on loong. This should
1681
		# be done relatively soon because we want to minimize the breakage
1685
		# be done relatively soon because we want to minimize the breakage
1682
		# window for the affected programs.
1686
		# window for the affected programs.
1683
		use loong && glibc_refresh_ldconfig
1687
		use loong && glibc_refresh_ldconfig
1684
1688
1685
		use compile-locales || run_locale_gen "${EROOT}/"
1689
		use compile-locales || run_locale_gen "${EROOT}/"
1686
	fi
1690
	fi
1687
1691
1688
	upgrade_warning
1692
	upgrade_warning
1689
1693
1690
	# Check for sanity of /etc/nsswitch.conf, take 2
1694
	# Check for sanity of /etc/nsswitch.conf, take 2
1691
	if [[ -e ${EROOT}/etc/nsswitch.conf ]] && ! has_version sys-auth/libnss-nis ; then
1695
	if [[ -e ${EROOT}/etc/nsswitch.conf ]] && ! has_version sys-auth/libnss-nis ; then
1692
		local entry
1696
		local entry
1693
		for entry in passwd group shadow; do
1697
		for entry in passwd group shadow; do
1694
			if grep -E -q "^[ \t]*${entry}:.*nis" "${EROOT}"/etc/nsswitch.conf; then
1698
			if grep -E -q "^[ \t]*${entry}:.*nis" "${EROOT}"/etc/nsswitch.conf; then
1695
				ewarn ""
1699
				ewarn ""
1696
				ewarn "Your ${EROOT}/etc/nsswitch.conf uses NIS. Support for that has been"
1700
				ewarn "Your ${EROOT}/etc/nsswitch.conf uses NIS. Support for that has been"
1697
				ewarn "removed from glibc and is now provided by the package"
1701
				ewarn "removed from glibc and is now provided by the package"
1698
				ewarn "  sys-auth/libnss-nis"
1702
				ewarn "  sys-auth/libnss-nis"
1699
				ewarn "Install it now to keep your NIS setup working."
1703
				ewarn "Install it now to keep your NIS setup working."
1700
				ewarn ""
1704
				ewarn ""
1701
			fi
1705
			fi
1702
		done
1706
		done
1703
	fi
1707
	fi
1704
1708
1705
	if [[ ${PRESERVED_OLD_LIBCRYPT} -eq 1 ]] ; then
1709
	if [[ ${PRESERVED_OLD_LIBCRYPT} -eq 1 ]] ; then
1706
		cp -p "${T}/libcrypt$(get_libname 1)" "${EROOT}/$(get_libdir)/libcrypt$(get_libname 1)" || die
1710
		cp -p "${T}/libcrypt$(get_libname 1)" "${EROOT}/$(get_libdir)/libcrypt$(get_libname 1)" || die
1707
		preserve_old_lib_notify /$(get_libdir)/libcrypt$(get_libname 1)
1711
		preserve_old_lib_notify /$(get_libdir)/libcrypt$(get_libname 1)
1708
1712
1709
		elog "Please ignore a possible later error message about a file collision involving"
1713
		elog "Please ignore a possible later error message about a file collision involving"
1710
		elog "${EROOT}/$(get_libdir)/libcrypt$(get_libname 1). We need to preserve this file for the moment to keep"
1714
		elog "${EROOT}/$(get_libdir)/libcrypt$(get_libname 1). We need to preserve this file for the moment to keep"
1711
		elog "the upgrade working, but it also needs to be overwritten when"
1715
		elog "the upgrade working, but it also needs to be overwritten when"
1712
		elog "sys-libs/libxcrypt is installed. See bug 802210 for more details."
1716
		elog "sys-libs/libxcrypt is installed. See bug 802210 for more details."
1713
	fi
1717
	fi
1714
}
1718
}
1715
- 

Return to bug 920753