Diff binutils-apple-8.2.1-r2 with a binutils-apple-8.2.1-r103

/usr/portage/sys-devel/binutils-apple/binutils-apple-8.2.1-r103.ebuild 2023-10-09 14:52:35.476368501 +0300
1
# Copyright 1999-2022 Gentoo Authors
1
# Copyright 2020-2022 Gentoo Authors
2 2
# Distributed under the terms of the GNU General Public License v2
3 3

  
4
EAPI="7"
4
EAPI=7
5 5

  
6
inherit flag-o-matic llvm prefix
6
CMAKE_MAKEFILE_GENERATOR=emake  # keep dependencies down
7 7

  
8
# versions:
9
# XCode-11.3.1                 ld64-530        cctools-949.0.1
10
# XCode-11.2.1                 ld64-520        cctools-949.0.1
11
# XCode-11.0                   ld64-512.4      cctools-949.0.1
12
# XCode-8.2.1                  ld64-274.2      cctools-895         <== binutils-apple-8.2.1-r1  (2019)
13

  
14
# macOS-10.15.6                dyld-750.6                          Causes build failures with Xcode-11 tools
15
# macOS-10.14.4-10.14.6        dyld-655.1.1                        Causes build failures with Xcode-11 tools
16
# macOS-10.13.6                dyld-551.4
17
# macOS-10.12.1-10.12.3        dyld-421.2                          <== binutils-apple-8.2.1-r1,8.1
18

  
19
LD64=ld64-274.2
20
CCTOOLS_VERSION=895
21
CCTOOLS=cctools-${CCTOOLS_VERSION}
22
DYLD=dyld-421.2
23

  
24
DESCRIPTION="Darwin assembler as(1) and static linker ld(1), Xcode Tools ${PV}"
25
HOMEPAGE="http://www.opensource.apple.com/"
26
SRC_URI="http://www.opensource.apple.com/tarballs/ld64/${LD64}.tar.gz
27
	http://www.opensource.apple.com/tarballs/cctools/${CCTOOLS}.tar.gz
28
	http://www.opensource.apple.com/tarballs/dyld/${DYLD}.tar.gz
29
	https://dev.gentoo.org/~grobian/distfiles/${PN}-patches-4.3-r1.tar.bz2
30
	https://dev.gentoo.org/~grobian/distfiles/${PN}-patches-5.1-r2.tar.bz2
31
	https://dev.gentoo.org/~grobian/distfiles/${PN}-patches-7.3-r2.tar.bz2
32
	https://dev.gentoo.org/~grobian/distfiles/${PN}-patches-8.2-r1.tar.bz2"
8
inherit cmake
33 9

  
34
LICENSE="APSL-2"
35
KEYWORDS="~x64-macos"
36
IUSE="lto classic test"
37
RESTRICT="!test? ( test )"
38

  
39
# ld64 can now only be compiled using llvm and libc++ since it massively uses
40
# C++11 language features. *But additionally* the as driver now defaults to
41
# calling clang as the assembler on many platforms. This can be disabled using
42
# -Wa,-Q but since it's default we make llvm a static runtime dependency.
43
RDEPEND="sys-devel/binutils-config
44
	lto? ( app-arch/xar )
45
	sys-devel/llvm:*
46
	sys-libs/libcxx"
47
DEPEND="${RDEPEND}
48
	test? ( >=dev-lang/perl-5.8.8 )"
10
DESCRIPTION="Darwin Xtools matching Xcode Tools ${PN}"
11
HOMEPAGE="https://github.com/iains/darwin-xtools"
12
SRC_URI="https://github.com/grobian/darwin-xtools/archive/gentoo-${PVR}.tar.gz -> darwin-xtools-${PVR}.tar.gz"
49 13

  
14
LICENSE="APSL-2"
50 15
SLOT="8"
16
KEYWORDS="~arm64-macos ~ppc-macos ~x64-macos"
51 17

  
52
S=${WORKDIR}
53

  
54
is_cross() { [[ ${CHOST} != ${CTARGET} ]] ; }
55

  
56
llvm_pkg_setup() {
57
	# eclass version will die if no LLVM can be found which will break prefix
58
	# bootstrap
59
	:
60
}
61

  
62
src_prepare() {
63
	cd "${S}"/${LD64}/src
64
	cp "${S}"/ld64-136-compile_stubs.h ld/compile_stubs.h
65
	cp "${S}"/ld64-274.2-Makefile Makefile
66

  
67
	eapply -p2 "${S}"/ld64-274.1-nolto.patch
68
	eapply -p2 "${S}"/ld64-236.3-crashreporter.patch
69
	eapply -p2 "${S}"/ld64-264.3.102-bitcode-case.patch
70
	eapply -p2 "${S}"/ld64-274.1-unknown-fixup.patch
71
	eapply -p2 "${S}"/ld64-274.1-notapi.patch
72
	eapply -p2 "${S}"/ld64-274.2-cfi-info-type.patch
73

  
74
	# workound llvm-3.9.{0,1} issue
75
	# https://bugs.gentoo.org/show_bug.cgi?id=603580
76
	# https://groups.google.com/forum/#!topic/llvm-dev/JY6nuKE__sU
77
	# http://lists.llvm.org/pipermail/cfe-commits/Week-of-Mon-20160829/169553.html
78
	sed -i -e '/COMPILE_TIME_ASSERT/d' ld/parsers/libunwind/*.hpp || die
79

  
80
	# provide missing headers from libunwind and dyld
81
	mkdir -p include/{mach,mach-o/arm} || die
82
	# never present because it's private
83
	cp ../../${DYLD}/include/mach-o/dyld_priv.h include/mach-o || die
84
	# use copies from cctools because they're otherwise hidden in some SDK
85
	cp ../../${CCTOOLS}/include/mach-o/arm/reloc.h include/mach-o/arm || die
86
	# provide all required CPU_TYPEs on all platforms
87
	cp ../../${CCTOOLS}/include/mach/machine.h include/mach/machine.h
88
	# add alias for newer identifiers, because ld64 uses both but cctools
89
	# header only defines the older
90
	eapply -p2 "${S}"/ld64-236.3-missing-cputypes.patch
91

  
92
	local VER_STR="\"@(#)PROGRAM:ld  PROJECT:${LD64} (Gentoo ${PN}-${PVR})\\n\""
93
	echo "char ldVersionString[] = ${VER_STR};" > version.cpp
94

  
95
	eapply -p0 "${S}"/ld64-123.2-debug-backtrace.patch
96

  
97
	cd "${S}"/${CCTOOLS}
98
	eapply -p1 "${S}"/${PN}-4.5-as.patch
99
	eapply -p1 "${S}"/${PN}-5.1-as-dir.patch
100
	eapply -p2 "${S}"/${PN}-5.1-ranlib.patch
101
	eapply -p1 "${S}"/${PN}-3.1.1-libtool-ranlib.patch
102
	eapply -p1 "${S}"/${PN}-3.1.1-no-headers.patch
103
	eapply -p0 "${S}"/${PN}-4.0-no-oss-dir.patch
104
	eapply -p1 "${S}"/cctools-839-intel-retf.patch
105
	eapply -p2 "${S}"/${PN}-5.1-extraneous-includes.patch
106
	eapply -p1 "${S}"/${PN}-5.1-strnlen.patch
107
	eapply -p1 "${S}"/${PN}-7.3-make-j.patch
108
	eapply -p1 "${S}"/${PN}-7.3-no-developertools-dir.patch
109
	eapply -p1 "${S}"/${PN}-8.2.1-llvm-prefix-3.patch
110
	eapply -p1 "${S}"/${PN}-8.2.1-llvm-shim.patch
111
	eprefixify libstuff/execute.c
112
	cp ../${LD64}/src/other/prune_trie.h include/mach-o/ || die
113

  
114
	# do not build profileable libstuff to save compile time
115
	sed -i -e "/^all:/s, profile , ," libstuff/Makefile
116

  
117
	# cctools version is provided to make via RC_ProjectSourceVersion which
118
	# generates and compiles it as apple_version[] into libstuff. From
119
	# there it's picked up by the individual tools. Since
120
	# RC_ProjectSourceVersion is also used as library version, we can't
121
	# just append our local version info. So we hack the libstuff Makefile
122
	# to include our Gentoo version.
123
	sed -i -e "/cctools-.*(RC_ProjectSourceVersion).*OFILE_DIR/s,Version),Version) (Gentoo ${PN}-${PVR})," \
124
		libstuff/Makefile
125

  
126
	eapply_user
127

  
128
	# clean up test suite
129
	cd "${S}"/${LD64}/unit-tests/test-cases
130
	local c
131

  
132
	# we don't have llvm
133
	((++c)); rm -rf llvm-integration;
134

  
135
	# we don't have dtrace
136
	((++c)); rm -rf dtrace-static-probes-coalescing;
137
	((++c)); rm -rf dtrace-static-probes;
138

  
139
	# a file is missing
140
	((++c)); rm -rf eh-coalescing-r
141

  
142
	# we don't do universal binaries
143
	((++c)); rm -rf blank-stubs;
144

  
145
	# looks like a problem with apple's result-filter.pl
146
	((++c)); rm -rf implicit-common3;
147
	((++c)); rm -rf order_file-ans;
18
# xtools uses c++11 features, not available in gcc-apple, hence gcc/clang dep
19
DEPEND="sys-devel/binutils-config
20
	|| ( sys-devel/gcc:* sys-devel/clang:* )
21
	app-arch/xar
22
	dev-libs/libyaml"
23
RDEPEND="${DEPEND}"
24
BDEPEND=""
148 25

  
149
	# TODO no idea what goes wrong here
150
	((++c)); rm -rf dwarf-debug-notes;
151

  
152
	einfo "Deleted $c tests that were bound to fail"
153

  
154
	cd "${S}"
155
	ebegin "cleaning Makefiles from unwanted CFLAGS"
156
	find . -name "Makefile" -print0 | xargs -0 sed \
157
		-i \
158
		-e 's/ -g / /g' \
159
		-e 's/^G =.*$/G =/' \
160
		-e 's/^OFLAG =.*$/OFLAG =/' \
161
		-e 's/install -c -s/install/g'
162
	eend $?
163
}
26
S="${WORKDIR}/darwin-xtools-gentoo-${PVR}"
164 27

  
165 28
src_configure() {
166
	ENABLE_LTO=0
167
	if use lto ; then
168
		ENABLE_LTO=1
169

  
170
		LLVM_INCDIR=$(get_llvm_prefix)/include
171
		LLVM_LIBDIR=$(get_llvm_prefix)/lib
172

  
173
		[ -n "${LLVM_INCDIR}" -a -n "${LLVM_LIBDIR}" ] || \
174
			die "LLVM not found - LTO support can not be enabled"
175

  
176
		# LTO and LLVM support currently both depend only on libLTO being
177
		# present. So we can enable both.
178
		CCTOOLS_LTO_CFLAGS="-DLTO_SUPPORT -I${LLVM_INCDIR}"
179
		CCTOOLS_LLVM_CFLAGS="-DLLVM_SUPPORT -I${LLVM_INCDIR}"
180
	fi
181

  
182
	export CTARGET=${CTARGET:-${CHOST}}
29
	CTARGET=${CTARGET:-${CHOST}}
183 30
	if [[ ${CTARGET} == ${CHOST} ]] ; then
184 31
		if [[ ${CATEGORY} == cross-* ]] ; then
185 32
			export CTARGET=${CATEGORY#cross-}
186 33
		fi
187 34
	fi
188 35

  
189
	LIBPATH=/usr/$(get_libdir)/binutils/${CTARGET}/${PV}
190
	DATAPATH=/usr/share/binutils-data/${CTARGET}/${PV}
191
	if is_cross ; then
192
		BINPATH=/usr/${CHOST}/${CTARGET}/binutils-bin/${PV}
36
	LIBPATH=/usr/$(get_libdir)/binutils/${CTARGET}/xtools-${PV}
37
	DATAPATH=/usr/share/binutils-data/${CTARGET}/xtools-${PV}
38
	if [[ ${CHOST} != ${CTARGET} ]] ; then
39
		BINPATH=/usr/${CHOST}/${CTARGET}/binutils-bin/xtools-${PV}
193 40
	else
194
		BINPATH=/usr/${CTARGET}/binutils-bin/${PV}
41
		BINPATH=/usr/${CTARGET}/binutils-bin/xtools-${PV}
195 42
	fi
196 43

  
197
	# CPPFLAGS only affects ld64, cctools don't use 'em (which currently is
198
	# what we want)
199
	append-cppflags -DNDEBUG
200

  
201
	# Create configure.h for ld64 with SUPPORT_ARCH_<arch> defines in it.
202
	DERIVED_FILE_DIR=${LD64}/src \
203
		${LD64}/src/create_configure
204
}
205

  
206
compile_ld64() {
207
	einfo "building ${LD64}"
208
	cd "${S}"/${LD64}/src
209
	emake \
210
		LTO=${ENABLE_LTO} \
211
		LTO_INCDIR=${LLVM_INCDIR} \
212
		LTO_LIBDIR=${LLVM_LIBDIR} \
213
		TAPI=0 \
214
		TAPI_LIBDIR="${EPREFIX}"/usr/lib
44
	is-host-64bit() {
45
		case ${CTARGET} in
46
			x86_64-*|powerpc64-*|arm64-*)   echo YES   ;;
47
			*)                              echo NO    ;;
48
		esac
49
	}
50

  
51
	local mycmakeargs=(
52
		-DCMAKE_OSX_DEPLOYMENT_TARGET=${MACOSX_DEPLOYMENT_TARGET}
53
		-DPACKAGE_VERSION="Gentoo ${PN}-${PVR}"
54
		-DCMAKE_INSTALL_PREFIX="${EPREFIX}${BINPATH%/*}" # cmake insists on /bin
55
		-DCCTOOLS_LD_CLASSIC=NO  # fails to link, and is useless anyway
56
		-DXTOOLS_AS_USE_CLANG=YES  # default to host as for unsupported targets
57
		-DXTOOLS_AS_CLANG_USE_HOST=YES  # search for arch/as-host iso clang
58
		-DXTOOLS_AS_SUBDIR="${EPREFIX}${LIBPATH}/"
59
		-DXTOOLS_LTO_SUPPORT=NO
60
		-DXTOOLS_HAS_LIBPRUNETRIE=YES
61
		-DXTOOLS_TAPI_SUPPORT=ON
62
		-DXTOOLS_USE_TAPILITE=ON
63
		-DXTOOLS_HOST_IS_64B=$(is-host-64bit)
64
		-DXTOOLS_BUGURL="https://bugs.gentoo.org/"
65
	)
215 66

  
216
	use test && emake build_test
67
	cmake_src_configure
217 68
}
218 69

  
219
compile_cctools() {
220
	einfo "building ${CCTOOLS}"
221
	cd "${S}"/${CCTOOLS}
222
	# Suppress running dsymutil because it will warn about missing debug
223
	# info which is expected when compiling without -g as we normally do.
224
	# This might need some more thought if anyone ever wanted to build us
225
	# for debugging with Apple's tools.
226
	emake \
227
		LIB_PRUNETRIE="-L../../${LD64}/src -lprunetrie" \
228
		EFITOOLS= \
229
		LTO="${CCTOOLS_LTO_CFLAGS} ${CCTOOLS_LLVM_CFLAGS}" \
230
		COMMON_SUBDIRS='libstuff ar misc otool' \
231
		SUBDIRS_32= \
232
		LEGACY= \
233
		RC_ProjectSourceVersion=${CCTOOLS_VERSION} \
234
		RC_CFLAGS="${CFLAGS}" \
235
		OFLAG="${CCTOOLS_OFLAG}" \
236
		DSYMUTIL=": disabled: dsymutil"
237

  
238
	cd "${S}"/${CCTOOLS}/as
239
	emake \
240
		BUILD_OBSOLETE_ARCH= \
241
		RC_ProjectSourceVersion=${CCTOOLS_VERSION} \
242
		RC_CFLAGS="-DASLIBEXECDIR=\"\\\"${EPREFIX}${LIBPATH}/\\\"\" ${CFLAGS}" \
243
		OFLAG="${CCTOOLS_OFLAG}" \
244
		DSYMUTIL=": disabled: dsymutil"
245
}
246

  
247
src_compile() {
248
	compile_ld64
249
	compile_cctools
250
}
251

  
252
install_ld64() {
253
	exeinto ${BINPATH}
254
	doexe "${S}"/${LD64}/src/{ld64,rebase,dyldinfo,unwinddump,ObjectDump}
255
	dosym ld64 ${BINPATH}/ld
256
	insinto ${DATAPATH}/man/man1
257
	doins "${S}"/${LD64}/doc/man/man1/{ld,ld64,rebase}.1
258
}
259

  
260
install_cctools() {
261
	cd "${S}"/${CCTOOLS}
262
	emake install_all_but_headers \
263
		EFITOOLS= \
264
		COMMON_SUBDIRS='ar misc otool' \
265
		SUBDIRS_32= \
266
		DSTROOT="\"${D}\"" \
267
		BINDIR="\"${EPREFIX}\"${BINPATH}" \
268
		LOCBINDIR="\"${EPREFIX}\"${BINPATH}" \
269
		USRBINDIR="\"${EPREFIX}\"${BINPATH}" \
270
		LOCLIBDIR="\"${EPREFIX}\"${LIBPATH}" \
271
		MANDIR="\"${EPREFIX}\"${DATAPATH}/man/"
272
	cd "${S}"/${CCTOOLS}/as
273
	emake install \
274
		BUILD_OBSOLETE_ARCH= \
275
		DSTROOT="\"${D}\"" \
276
		USRBINDIR="\"${EPREFIX}\"${BINPATH}" \
277
		LIBDIR="\"${EPREFIX}\"${LIBPATH}" \
278
		LOCLIBDIR="\"${EPREFIX}\"${LIBPATH}"
279

  
280
	# upstream is starting to replace classic binutils with llvm-integrated
281
	# ones. In Xcode, nm and size are now symlinks to llvm-{nm,size} while the
282
	# classic version is preserved as {nm,size}-classic. When asked to do so
283
	# by use classic we statically link to the classic version.
284
	#   binutils-bin/<version>/<tool>
285
	#     -> binutils-bin/<version>/<tool>-classic
286
	#
287
	# Otherwise we try to find and use the llvm version of the tool. Since our
288
	# binutils do not live in the same directory as the llvm installation and
289
	# llvm tends to move around, we use a shim that tries to find the llvm
290
	# version of the tool in prefix. It will fall back to the classic tool if
291
	# it fails.
292
	#  binutils-bin/<version>/<tool>
293
	#    -> binutils-bin/<version>/llvm-<tool>
294
	#    -> $EPREFIX/usr/lib/llvm/<major/bin/llvm-<tool>
295
	#    -> $EPREFIX/usr/bin/llvm-<tool>
296
	#    -> binutils-bin/<version>/<tool>-classic
297
	budir="${D}"/${EPREFIX}/${BINPATH}
298
	for tool in nm size ; do
299
		use classic && \
300
			ln -sfn ${tool}-classic "${budir}/${tool}" || \
301
			ln -sfn llvm-shim "${budir}/${tool}"
302
	done
70
src_install() {
71
	cmake_src_install
303 72

  
304
	# Also, otool is now based on llvm-objdump. But a small wrapper installed
305
	# as llvm-otool remains, providing command line compatibility.
306
	use classic && \
307
		ln -sfn otool-classic "${budir}/otool" || \
308
		ln -sfn llvm-otool "${budir}/otool"
309

  
310
	# And finally, although our cctools don't actually contain dsymutil and
311
	# objdump, we provide access to the llvm versions of them via the shim to
312
	# be in line with Xcode.
313
	for tool in objdump dsymutil ; do
314
		ln -sfn llvm-shim "${budir}/${tool}"
73
	# cmake insists on installing in /bin, so move bins to the place we
74
	# want them
75
	mv "${ED}${BINPATH%/*}/bin" "${ED}${BINPATH}" || die
76

  
77
	# move as impls into LIBPATH, such that binutils-config doesn't
78
	# create links for this
79
	dodir "${LIBPATH}"
80
	local as
81
	for as in "${ED}${BINPATH}"/*/as ; do
82
		as=${as%/as}
83
		mv "${as}" "${ED}${LIBPATH}"/ || die
315 84
	done
316 85

  
317
	cd "${ED}"/${BINPATH}
318
	insinto ${DATAPATH}/man/man1
319
	local skips manpage
320
	# ar brings an up-to-date manpage with it
321
	skips=( ar )
322
	for bin in *; do
323
		for skip in ${skips[@]}; do
324
			if [[ ${bin} == ${skip} ]]; then
325
				continue 2;
326
			fi
327
		done
328
		manpage=${S}/${CCTOOLS}/man/${bin}.1
329
		if [[ -f "${manpage}" ]]; then
330
			doins "${manpage}"
331
		fi
86
	# provide as-host wrappers, used on "unsupported" platforms: x86,
87
	# x64, arm, arm64, the main reason here is missing support for
88
	# instructions, e.g. the as works fine, until newer instruction sets
89
	# are used like SSE4.1, AVX, etc.
90
	local arch
91
	for arch in i386 x86_64 arm arm64 ; do
92
		mkdir -p "${ED}${LIBPATH}"/${arch}
93
		as="${ED}${LIBPATH}"/${arch}/as-host
94
		rm -f "${as}"
95
		cat <<-EOF > "${as}"
96
			#!/usr/bin/env bash
97
			exec /usr/bin/as "\$@"
98
		EOF
99
		chmod 755 "${as}"
332 100
	done
333
	insinto ${DATAPATH}/man/man5
334
	doins "${S}"/${CCTOOLS}/man/*.5
335
}
336

  
337
src_test() {
338
	if ! [[ -x "${EPREFIX}"/usr/bin/clang ]] ; then
339
		einfo "Test suite only works properly with clang - please install"
340
		return
341
	fi
342 101

  
343
	einfo "Running unit tests"
344
	cd "${S}"/${LD64}/unit-tests/test-cases
345
	# provide the new ld as a symlink to clang so that -ccc-install-dir
346
	# will pick it up
347
	ln -sfn ../../src/ld64 ld
348
	# use our arch command because the System's will report i386 even for an
349
	# x86_64 prefix
350
	perl ../bin/make-recursive.pl \
351
		BUILT_PRODUCTS_DIR="${S}"/${LD64}/src \
352
		ARCH="$(arch)" \
353
		LD="${S}"/${LD64}/src/ld64 \
354
		CC="${CC} -ccc-install-dir $PWD" \
355
		CXX="${CXX} -ccc-install-dir $PWD" \
356
		OTOOL="${S}"/${CCTOOLS}/otool/otool.NEW \
357
		| perl ../bin/result-filter.pl
358
}
359

  
360
src_install() {
361
	install_ld64
362
	install_cctools
102
	doman ld64/doc/man/man*/* cctools/man/*.[135]
103
	dodir "${DATAPATH}"
104
	mv "${ED}"/usr/share/man "${ED}/${DATAPATH}/" || die
363 105

  
364 106
	cd "${S}"
365 107
	insinto /etc/env.d/binutils
366 108
	cat <<-EOF > env.d
367 109
		TARGET="${CHOST}"
368
		VER="${PV}"
110
		VER="xtools-${PV}"
369 111
		FAKE_TARGETS="${CHOST}"
370 112
	EOF
371
	newins env.d ${CHOST}-${PV}
113
	newins env.d ${CHOST}-xtools-${PV}
372 114
}
373 115

  
374 116
pkg_postinst() {
375
	binutils-config ${CHOST}-${PV}
117
	binutils-config ${CHOST}-xtools-${PV}
376 118
}
Thank you!