Diff binutils-apple-3.2.6-r1 with a binutils-apple-8.2.1-r2

/usr/portage/sys-devel/binutils-apple/binutils-apple-8.2.1-r2.ebuild 2023-10-09 14:52:35.476368501 +0300
3 3

  
4 4
EAPI="7"
5 5

  
6
inherit flag-o-matic toolchain-funcs
6
inherit flag-o-matic llvm prefix
7 7

  
8
RESTRICT="test" # the test suite will test what's installed.
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
9 23

  
10
LD64=ld64-97.17
11
CCTOOLS=cctools-795
12
LIBUNWIND=libunwind-30
13
DYLD=dyld-132.13
14

  
15
DESCRIPTION="Darwin assembler as(1) and static linker ld(1), Xcode Tools 3.2.6"
24
DESCRIPTION="Darwin assembler as(1) and static linker ld(1), Xcode Tools ${PV}"
16 25
HOMEPAGE="http://www.opensource.apple.com/"
17
SRC_URI="https://opensource.apple.com/tarballs/ld64/${LD64}.tar.gz
18
	https://opensource.apple.com/tarballs/cctools/${CCTOOLS}.tar.gz
19
	http://www.opensource.apple.com/tarballs/libunwind/${LIBUNWIND}.tar.gz
26
SRC_URI="http://www.opensource.apple.com/tarballs/ld64/${LD64}.tar.gz
27
	http://www.opensource.apple.com/tarballs/cctools/${CCTOOLS}.tar.gz
20 28
	http://www.opensource.apple.com/tarballs/dyld/${DYLD}.tar.gz
21
	https://dev.gentoo.org/~grobian/distfiles/${PN}-patches-3.2.6-r0.tar.bz2"
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"
22 33

  
23 34
LICENSE="APSL-2"
24
KEYWORDS="~ppc-macos ~x64-macos"
25
IUSE="test"
26

  
27
RDEPEND="sys-devel/binutils-config"
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"
28 47
DEPEND="${RDEPEND}
29 48
	test? ( >=dev-lang/perl-5.8.8 )"
30 49

  
31
SLOT="3"
50
SLOT="8"
32 51

  
33 52
S=${WORKDIR}
34 53

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

  
37
eprepare_ld64() {
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() {
38 63
	cd "${S}"/${LD64}/src
39
	cp "${WORKDIR}"/Makefile Makefile || die
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
40 79

  
41 80
	# provide missing headers from libunwind and dyld
42 81
	mkdir -p include/{mach,mach-o/arm} || die
43 82
	# never present because it's private
44 83
	cp ../../${DYLD}/include/mach-o/dyld_priv.h include/mach-o || die
45
	# missing on <= 10.5
46
	cp ../../${LIBUNWIND}/include/libunwind.h include/ || die
47
	ln -s ../../../${LIBUNWIND}/src include/libunwind || die
48
	cp ../../${LIBUNWIND}/include/mach-o/compact_unwind_encoding.h include/mach-o || die
49
	# missing on <= 10.4
50
	cp ../../${DYLD}/include/mach-o/dyld_images.h include/mach-o || die
51
	cp ../../${CCTOOLS}/include/mach-o/loader.h include/mach-o || die
52 84
	# use copies from cctools because they're otherwise hidden in some SDK
53 85
	cp ../../${CCTOOLS}/include/mach-o/arm/reloc.h include/mach-o/arm || die
54 86
	# provide all required CPU_TYPEs on all platforms
55 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
56 91

  
57 92
	local VER_STR="\"@(#)PROGRAM:ld  PROJECT:${LD64} (Gentoo ${PN}-${PVR})\\n\""
58
	sed -i \
59
		-e '/^#define LTO_SUPPORT 1/s:1:0:' \
60
		other/ObjectDump.cpp || die
61
	echo '#undef LTO_SUPPORT' > include/configure.h
62
	echo '' > linker_opts
63 93
	echo "char ldVersionString[] = ${VER_STR};" > version.cpp
64 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

  
65 128
	# clean up test suite
66 129
	cd "${S}"/${LD64}/unit-tests/test-cases
67 130
	local c
......
86 149
	# TODO no idea what goes wrong here
87 150
	((++c)); rm -rf dwarf-debug-notes;
88 151

  
89
	elog "Deleted $c tests that were bound to fail"
90
}
91

  
92
src_prepare() {
93
	eprepare_ld64
94

  
95
	cd "${S}"/${CCTOOLS}
96
	eapply -p1 "${WORKDIR}"/${PN}-3.2.6-as-dir.patch
97
	eapply -p1 "${WORKDIR}"/${PN}-3.1.1-libtool-ranlib.patch
98
	eapply -p1 "${WORKDIR}"/${PN}-3.1.1-nmedit.patch
99
	eapply -p1 "${WORKDIR}"/${PN}-3.1.1-no-headers.patch
100
	eapply -p1 "${WORKDIR}"/${PN}-3.1.1-no-oss-dir.patch
101

  
102
	# drop as targets which are not suported by anything
103
	sed -i \
104
		-e '/^all:/,/^$/s/\(a68\|a88\|a860\|ahppa\|asparc\)_build//g' \
105
		-e '/^macos_install:/s/common_install//' \
106
		-e '/^xcommon_install:/,/^$/{' \
107
			-e '/\(m68k\|a68\|sparc\)/d' \
108
		-e '}' \
109
		as/Makefile || die
110

  
111
	cd "${S}"/${LD64}
112
	eapply -p1 "${WORKDIR}"/${PN}-3.1.1-testsuite.patch
113
	eapply -p1 "${WORKDIR}"/${PN}-3.2.6-lto.patch
152
	einfo "Deleted $c tests that were bound to fail"
114 153

  
115 154
	cd "${S}"
116 155
	ebegin "cleaning Makefiles from unwanted CFLAGS"
117 156
	find . -name "Makefile" -print0 | xargs -0 sed \
118 157
		-i \
119 158
		-e 's/ -g / /g' \
159
		-e 's/^G =.*$/G =/' \
120 160
		-e 's/^OFLAG =.*$/OFLAG =/' \
121 161
		-e 's/install -c -s/install/g'
122 162
	eend $?
123

  
124
	# -pg is used and the two are incompatible
125
	filter-flags -fomit-frame-pointer
126

  
127
	eapply_user
128 163
}
129 164

  
130 165
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

  
131 182
	export CTARGET=${CTARGET:-${CHOST}}
132 183
	if [[ ${CTARGET} == ${CHOST} ]] ; then
133 184
		if [[ ${CATEGORY} == cross-* ]] ; then
......
136 187
	fi
137 188

  
138 189
	LIBPATH=/usr/$(get_libdir)/binutils/${CTARGET}/${PV}
139
	INCPATH=${LIBPATH}/include
140 190
	DATAPATH=/usr/share/binutils-data/${CTARGET}/${PV}
141 191
	if is_cross ; then
142 192
		BINPATH=/usr/${CHOST}/${CTARGET}/binutils-bin/${PV}
......
144 194
		BINPATH=/usr/${CTARGET}/binutils-bin/${PV}
145 195
	fi
146 196

  
147
	if tc-is-gcc && [[ $(gcc-fullversion) != 4.2.1 ]] ; then
148
		# force gcc-apple
149
		CC=${CTARGET}-gcc-4.2.1
150
		CXX=${CTARGET}-g++-4.2.1
151
	fi
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
152 204
}
153 205

  
154 206
compile_ld64() {
207
	einfo "building ${LD64}"
155 208
	cd "${S}"/${LD64}/src
156
	# 'struct linkedit_data_command' is defined in mach-o/loader.h on leopard,
157
	# but not on tiger.
158
	[[ ${CHOST} == *-apple-darwin8 ]] && \
159
		append-flags -isystem "${S}"/${CCTOOLS}/include/
160
	local myincs="-Iinclude -Iabstraction -Ild"
161
	emake CFLAGS="${CFLAGS} ${myincs}" CXXFLAGS="${CXXFLAGS} ${myincs}"
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
162 215

  
163 216
	use test && emake build_test
164 217
}
165 218

  
166 219
compile_cctools() {
220
	einfo "building ${CCTOOLS}"
167 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.
168 226
	emake \
169
		LTO= \
170
		TRIE= \
227
		LIB_PRUNETRIE="-L../../${LD64}/src -lprunetrie" \
171 228
		EFITOOLS= \
229
		LTO="${CCTOOLS_LTO_CFLAGS} ${CCTOOLS_LLVM_CFLAGS}" \
172 230
		COMMON_SUBDIRS='libstuff ar misc otool' \
173 231
		SUBDIRS_32= \
174
		RC_CFLAGS="${CFLAGS}" OFLAG="${CFLAGS}"
232
		LEGACY= \
233
		RC_ProjectSourceVersion=${CCTOOLS_VERSION} \
234
		RC_CFLAGS="${CFLAGS}" \
235
		OFLAG="${CCTOOLS_OFLAG}" \
236
		DSYMUTIL=": disabled: dsymutil"
175 237

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

  
182 247
src_compile() {
183
	tc-export CC CXX
184 248
	compile_ld64
185 249
	compile_cctools
186 250
}
187 251

  
188 252
install_ld64() {
189 253
	exeinto ${BINPATH}
190
	doexe "${S}"/${LD64}/src/{ld64,rebase}
254
	doexe "${S}"/${LD64}/src/{ld64,rebase,dyldinfo,unwinddump,ObjectDump}
191 255
	dosym ld64 ${BINPATH}/ld
192 256
	insinto ${DATAPATH}/man/man1
193 257
	doins "${S}"/${LD64}/doc/man/man1/{ld,ld64,rebase}.1
......
199 263
		EFITOOLS= \
200 264
		COMMON_SUBDIRS='ar misc otool' \
201 265
		SUBDIRS_32= \
202
		RC_CFLAGS="${CFLAGS}" OFLAG="${CFLAGS}" \
203 266
		DSTROOT="\"${D}\"" \
204 267
		BINDIR="\"${EPREFIX}\"${BINPATH}" \
205 268
		LOCBINDIR="\"${EPREFIX}\"${BINPATH}" \
......
214 277
		LIBDIR="\"${EPREFIX}\"${LIBPATH}" \
215 278
		LOCLIBDIR="\"${EPREFIX}\"${LIBPATH}"
216 279

  
217
	cd "${ED}"${BINPATH}
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
303

  
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}"
315
	done
316

  
317
	cd "${ED}"/${BINPATH}
218 318
	insinto ${DATAPATH}/man/man1
219 319
	local skips manpage
220 320
	# ar brings an up-to-date manpage with it
......
235 335
}
236 336

  
237 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

  
238 343
	einfo "Running unit tests"
239 344
	cd "${S}"/${LD64}/unit-tests/test-cases
240
	# need host arch, since GNU arch doesn't do what Apple's does
241
	tc-export CC CXX
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
242 350
	perl ../bin/make-recursive.pl \
243
		ARCH="$(/usr/bin/arch)" \
244
		RELEASEDIR="${S}"/${LD64}/src \
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 \
245 357
		| perl ../bin/result-filter.pl
246 358
}
247 359

  
Thank you!