Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 537342 - >=sys-devel/llvm-3.4.2: uses host compiler and SDKs to compile runtime, uses system libstdc++ headers and library and fails to compile on < 10.5
Summary: >=sys-devel/llvm-3.4.2: uses host compiler and SDKs to compile runtime, uses ...
Status: RESOLVED OBSOLETE
Alias: None
Product: Gentoo/Alt
Classification: Unclassified
Component: Prefix Support (show other bugs)
Hardware: All OS X
: Normal normal (vote)
Assignee: Gentoo Prefix
URL: https://trac.macports.org/ticket/43353
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2015-01-22 12:26 UTC by Michael Weiser
Modified: 2016-11-13 19:50 UTC (History)
0 users

See Also:
Package list:
Runtime testing required: ---


Attachments
patch to the ebuilds of 3.4.2 and 3.5.[01] that fixes all three problems on darwin (for me) (llvm-darwin-fixes.patch,8.21 KB, patch)
2015-01-22 12:26 UTC, Michael Weiser
Details | Diff
collection of darwin prefix support patches (llvm-darwin-ebuilds.tar.gz,7.26 KB, patch)
2015-02-02 23:34 UTC, Michael Weiser
Details | Diff
updated collection of darwin prefix support patches (llvm-darwin-ebuilds-2.tar.gz,7.96 KB, application/x-gzip)
2015-02-04 04:24 UTC, Michael Weiser
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Michael Weiser 2015-01-22 12:26:13 UTC
When installing llvm 3.4.2 and 3.5.0 on OS X 10.8/9 in a 32bit prefix, I got reproducible hangs when it started to compile compiler-rt. While investigating, I found that compiler-rt runs the compiler and other tools via xcrun. This makes it pick up the system's compiler and SDKs instead of the one that was just compiled by the ebuild. This doesn't seem a good idea to me on principle. Also, disabling use of the system's compiler also made my hangs disappear. I suspect that it has something to do with calling the system's 64bit xcrun and clang from a 32bit prefix - but that's for a different bug report, if it continues to crop up.

Disabling use of the system SDKs indirectly also disables compilation of the runtime for iphonesimulator.

Also, compilation fails on 10.5 as discussed in this MacPorts ticket: https://trac.macports.org/ticket/43353.

Finally, the old-linker patch has not made it from 3.4.2's ebuild into 3.5.[01]. But it isn't necessary any more if >= sys-devel/binutils-5.1 from the following bug is in use: https://bugs.gentoo.org/show_bug.cgi?id=473068.

Reproducible: Always
Comment 1 Michael Weiser 2015-01-22 12:26:55 UTC
Created attachment 394604 [details, diff]
patch to the ebuilds of 3.4.2  and 3.5.[01] that fixes all three problems on darwin (for me)
Comment 2 Michael Weiser 2015-01-31 15:41:59 UTC
binutils-apple-5.1 and -6.1 are in the tree now. So they can "legally" be required by the ebuilds.
Comment 3 Fabian Groffen gentoo-dev 2015-01-31 16:11:08 UTC
so, can we close this bug, or do you want to update the requirement to 6.1?
Comment 4 Michael Weiser 2015-01-31 19:05:53 UTC
5.1 should be fine. It's tested and supports everything clang needs.
Comment 5 Fabian Groffen gentoo-dev 2015-01-31 19:19:15 UTC
(In reply to Michael Weiser from comment #4)
> 5.1 should be fine. It's tested and supports everything clang needs.

ok, then I'll drop the darwin-old-linker patch at the same time
Comment 6 Michael Weiser 2015-01-31 19:53:04 UTC
Then don't forget to update the dependency in 3.4.2 as well. I didn't because the old-linker-patch was in there and working.
Comment 7 Fabian Groffen gentoo-dev 2015-01-31 20:15:32 UTC
I've done all of them :)

I'm just a bit lost on the remaining changes to be done here.  I want the independency, but i wonder about the asan patch, why can't that one be unconditional?

Side note, I see in the no-asan patch a remark that 10.6 has a bug in its ranlib, and therefore it strips arm targets.  This is of course non-sense in Prefix.  I guess a review is necessary to rid it from more of those "assumptions".  (If you want all targets to be enabled, that is.)
Comment 8 Michael Weiser 2015-01-31 21:17:25 UTC
(In reply to Fabian Groffen from comment #7)
> I'm just a bit lost on the remaining changes to be done here.  I want the
> independency, but i wonder about the asan patch, why can't that one be
> unconditional?

The asan patch disables building of that part of the runtime. No idea what it does but the MacPorts bug report says it shouldn't be built on < 10.6 because it can't work there. But everywhere else it should be built and does work. So the block

+	if [[ "${CHOST##*-darwin}" -le 9 ]] ; then
+		# https://trac.macports.org/ticket/43353
+		epatch "${FILESDIR}"/${PN}-3.4.2-leopard-no-asan.patch
 	fi

disables it only on < 10.5.

The rest of the patch is for disabling use of the host tools:

 		sed -i -e "/^CFLAGS /s@-Werror@-I${EPREFIX}/usr/include@" \
+			-e "s@override CC@CC@" \

keeps the CC variable from being overridden with a clang found via xc-run. And

+	if [[ ${CHOST} == *darwin* ]] ; then
+		# Keep compiler-rt from using the system's compiler and SDKs.
+		# This also disables the iphonesimulator target.
+		MAKEARGS+=(
+			DSYMUTIL=dsymutil
+			LIPO=lipo
+			STRIP=strip
+			RANLIB=ranlib
+			AR=ar
+			IOSSIM_SDK_PATH=
+			ACTIVE_SDK_PATH=
+		)
+	fi

forces the paths to the SDKs to be undefined so they aren't used and the tools not to be searched using xc-run either but the search path instead.

> Side note, I see in the no-asan patch a remark that 10.6 has a bug in its
> ranlib, and therefore it strips arm targets.  This is of course non-sense in
> Prefix.  I guess a review is necessary to rid it from more of those
> "assumptions".  (If you want all targets to be enabled, that is.)

Here's the whole text:

# Darwin 10.6 has a bug in cctools that makes it unable to use ranlib on our ARM
# object files. If we are on that platform, strip out all ARM archs. We still
# build the libraries themselves so that Clang can find them where it expects
# them, even though they might not have an expected slice.
ifneq ($(shell test -x /usr/bin/sw_vers && sw_vers -productVersion | grep 10.6),)
UniversalArchs.ios := $(filter-out armv7, $(UniversalArchs.ios))
UniversalArchs.cc_kext := $(filter-out armv7, $(UniversalArchs.cc_kext))
UniversalArchs.cc_kext_ios5 := $(filter-out armv7, $(UniversalArchs.cc_kext_ios5))
UniversalArchs.profile_ios := $(filter-out armv7, $(UniversalArchs.profile_ios))
endif

I agree. And looking at that osversion-conditional I think our no-asan patch could be a lot nicer and would not need to be conditional in the ebuild.

I'll get back to you with an updated ebuild. In the meantime you could add the non-host-tools bits if you wanted. :)
Comment 9 Michael Weiser 2015-02-02 23:34:28 UTC
Created attachment 395424 [details, diff]
collection of darwin prefix support patches

The attached patch files and patch to the ebuilds

- fix compilation issues on OS X 10.4 (macros not defined and dyld not understanding @rpath library references)
- disable compilation of asan and ubsan runtime libraries on OS X older than 10.6 using nice make conditional logic
- enable running ar on some arm runtime libraries because prefix's ar is current enough to do so even on OS X < 10.7
- disable the default search paths for the systems libstdc++ headers on Darwin
- disable use of the system's compiler and tools to compile runtime libraries. SDKs are still enabled at the moment, so iphonesimulator libraries are built. I'm looking into disabling only the OS X SDK but leaving IOS/arm enabled. BTW: Turns out, clang doesn't do any gcc-like bootstrap. It just compiles itself and its libraries using any host compiler. Now at least the prefix's compiler should be used consistently.
- extend the Gentoo runtime GCC detection patch to add a GCC installation detector to the Darwin clang driver to detect the prefix's GCC installation based on gcc-config files in $EPREFIX/etc/env.d/gcc. Based on that the libstdc++ include and linker paths are set up the same way gcc-apple does and clang does on Linux. With this detector in place all other kinds of special cases can be tackled.

I am somewhat uncertain on the actual linker paths to add because there are two directories carrying libstdc++:

${EPREFIX}/usr/<triple>/lib/gcc
- has libstdc++.6.dylib but no libstdc++.dylib
- is not owned by any package!? where does it come from?
- is already forced onto the linker path by the prefix ld wrapper
- would need putting -lstdc++.6 onto the linker command line by cland

${EPREFIX}/usr/lib/gcc/<triple>/<version>
- has libstdc++.dylib
- is similarly used for finding libstdc++ by gcc-4.9 on Gentoo Linux

I wonder if there is some historic or cross-compile-support reason for using either one or the other. I've opted for the latter for now but left commented-out code in the patch outlining the other option.
Comment 11 Michael Weiser 2015-02-04 04:24:46 UTC
Created attachment 395494 [details]
updated collection of darwin prefix support patches
Comment 12 Michael Weiser 2016-11-13 19:50:11 UTC
Overtaken by reality: works well enough for bootstrapping into a clang environment with libc++.