Gentoo Archives: gentoo-alt

From: Fabian Groffen <grobian@g.o>
To: gentoo-alt@l.g.o
Subject: Re: [gentoo-alt] clang-5 on macOS
Date: Tue, 26 Dec 2017 10:37:05
Message-Id: 20171226103652.GC38438@gentoo.org
In Reply to: [gentoo-alt] clang-5 on macOS by Michael Weiser
1 On 26-12-2017 00:17:55 +0100, Michael Weiser wrote:
2 > Happy Christmas!
3 >
4 > Is anyone (else) working to get clang-5 running in prefix on macOS?
5 >
6 > After upgrading to macOS 10.13, a couple of packages stopped compiling
7 > with clang 3.9.1. The errors came from system headers. It looked like
8 > Apple had again used some funky new clang feature in them which 3.9.1
9 > didn't support.
10
11 Yes, I noticed that too, see:
12 https://bugs.gentoo.org/632500
13
14 > (Disclamer: I left prefix untouched when updating. It's still running
15 > with CHOST=x86_64-apple-darwin16 and profile
16 > prefix/darwin/macos/10.12/x64.)
17 >
18 > Getting clang-5 up and running wasn't all that bad: I needed to clone
19 > the libcxx and libcxxabi ebuilds for version 5.0.1, adjust eclass
20 > cmake-utils and reintroduce some prefix provisions to clang and
21 > compiler-rt ebuilds that didn't make the move from the llvm ebuild.
22
23 Oh, I experienced failures to compile it on a 10.13 profile.
24
25 > The cmake problem is somewhat tricky to explain: A special prefix
26 > handling is supposed to force all cmake-based builds to link against the
27 > libraries in prefix. This is done by setting an rpath and forcing cmake
28 > to use that rpath whenever possible. Normally, cmake will link the
29 > binaries for the build directory with an rpath that prefers libraries in
30 > the build directory. This is disabled by setting
31 > CMAKE_BUILD_WITH_INSTALL_RPATH.
32 >
33 > For LLVM and clang builds this causes a problem: Newly compiled binaries
34 > immediately get linked with the forced rpath. But the build calls some
35 > of them while still in the build directory and before installation of
36 > their libraries (especially llvm-tblgen and clang-tblgen). So they pick
37 > up the old installed versions of the libraries via the rpath and croak
38 > on missing symbols. I guess, other packages would face the same problem,
39 > if they called dynamically linked binaries from the build directory -
40 > which is somewhat rare.
41 >
42 > Does anyone remember why CMAKE_BUILD_WITH_INSTALL_RPATH was necessary
43 > for cmake ebuilds?
44
45 I don't recall, seems like this indeed shouldn't be forced.
46
47 > Disabling this setting led to another problem: LLVM and clang have all
48 > their libs reference each other using @rpath. This is done relative to
49 > the executable they're linked into which gets an rpath of
50 > @executable_path/../lib for that purpose. This is fine as long as both
51 > LLVM and clang are built in one sitting. With the new concept of first
52 > building and installing LLVM and then building clang, the call to
53 > clang-tblgen in the build directory again croaks. But this time it is
54 > because dynamic LLVM libraries that get pulled in by the dynamic LLVM
55 > libraries it's linked against can't be found because they're not on its
56 > @rpath. So I had to force an *install* rpath of
57 > ${EPREFIX}/usr/lib/llvm/${SLOT}/lib.
58
59 I assume this is install_name_tool-ing.
60
61 > With this I got llvm, clang and their other components installed. clang
62 > defaulted to /usr/include for includes at first and compiler-rt compiled
63 > against the Xcode SDK. With some research in the 3.9.1 ebuilds that was
64 > quickly remedied.
65 >
66 > The only real fallout came from the fact that my binutils-apple had LTO
67 > and tapi support enabled. Both broke horribly which rendered ld64
68 > defunct.
69 >
70 > As long as neither USE tapi nor lto are enabled on binutils-apple, they
71 > should be fine. Symlinks to size and nm will break and will need
72 > adjustment to point to the new llvm install though.
73
74 Hmm...
75
76 > I think I got LTO support sorted in an updated binutils-apple-8.2.1
77 > ebuild. I have also taken care of LLVMs move into a slotted
78 > $EPREFIX/usr/lib/llvm which should make them more robust to future
79 > updates and moves.
80 >
81 > But tapi is a real mess which shines a spotlight on a more fundamental
82 > problem: Apple has yet to release the source of Xcode 9. So tapi-1.30
83 > won't compile with clang-5.0.1 any more. A tapi-2.0.0 open source drop
84 > on GitHub (https://github.com/ributzka/tapi) requires Apple-specific
85 > additions to LLVM (ObjCMetadata). Those from the last released Apple
86 > clang-8.0.0 are slightly incompatible to llvm-5.0.0 *and* this
87 > tapi-2.0.0. I am currently digging my way through that.
88 >
89 > In case anyone wonders: tapi is the library that supports SDK .tbd stub
90 > files. So if ld64 has no tapi support it can't use recent Apple SDKs,
91 > which for the purposes of a prefix install is no big deal, I guess. It
92 > might even serve as a flag that some package is trying to use an SDK.
93 >
94 > Any comments on my approach would be highly appreciated. Patches
95 > attached for documentation.
96
97 Seems like you got yourself pretty deep into it! clang-5 is the blocker
98 for supporting high sierra IMO. Can you now build 5 using 3.9.1?
99
100 I think the cmake patches are ok, I'll look into the ebuilds you
101 mention. I'll sync whatever I can find in this area.
102
103 Thanks,
104 Fabian
105
106
107 > --- portage/eclass/cmake-utils.eclass.orig 2017-12-25 22:56:39.589527684 +0100
108 > +++ portage/eclass/cmake-utils.eclass 2017-12-25 23:09:19.207489713 +0100
109 > @@ -588,9 +588,25 @@
110 > SET(CMAKE_PREFIX_PATH "${EPREFIX}/usr" CACHE STRING "" FORCE)
111 > SET(CMAKE_SKIP_BUILD_RPATH OFF CACHE BOOL "" FORCE)
112 > SET(CMAKE_SKIP_RPATH OFF CACHE BOOL "" FORCE)
113 > + _EOF_
114 > +
115 > + case ${PN} in
116 > + llvm|clang)
117 > + cat >> "${build_rules}" <<- _EOF_ || die
118 > + SET(CMAKE_INSTALL_RPATH "${EPREFIX}/usr/lib/llvm/${SLOT}/$(get_libdir)" CACHE STRING "" FORCE)
119 > + _EOF_
120 > + ;;
121 > +
122 > + *)
123 > + cat >> "${build_rules}" <<- _EOF_ || die
124 > SET(CMAKE_BUILD_WITH_INSTALL_RPATH TRUE CACHE BOOL "")
125 > SET(CMAKE_INSTALL_RPATH "${EPREFIX}/usr/lib;${EPREFIX}/usr/${CHOST}/lib/gcc;${EPREFIX}/usr/${CHOST}/lib;${EPREFIX}/usr/$(get_libdir);${EPREFIX}/$(get_libdir)" CACHE STRING "" FORCE)
126 > SET(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE CACHE BOOL "" FORCE)
127 > + _EOF_
128 > + ;;
129 > + esac
130 > +
131 > + cat >> "${build_rules}" <<- _EOF_ || die
132 > SET(CMAKE_INSTALL_NAME_DIR "${EPREFIX}/usr/lib" CACHE STRING "" FORCE)
133 >
134 > ENDIF (NOT APPLE)
135
136 > --- portage/sys-devel/clang/clang-5.0.1.ebuild 2017-12-20 23:24:32.000000000 +0100
137 > +++ portage/sys-devel/clang/clang-5.0.1.ebuild 2017-12-23 21:38:22.000000000 +0100
138 > @@ -110,6 +110,13 @@
139 > fi
140 > }
141 >
142 > +src_prepare() {
143 > + default
144 > +
145 > + eapply "${FILESDIR}"/${PN}-5.0.1-darwin_prefix-include-paths.patch
146 > + eprefixify lib/Frontend/InitHeaderSearch.cpp
147 > +}
148 > +
149 > multilib_src_configure() {
150 > local llvm_version=$(llvm-config --version) || die
151 > local clang_version=$(ver_cut 1-3 "${llvm_version}")
152
153 > --- a/lib/Frontend/InitHeaderSearch.cpp
154 > +++ b/lib/Frontend/InitHeaderSearch.cpp
155 > @@ -233,6 +233,7 @@
156 > case llvm::Triple::Bitrig:
157 > break;
158 > default:
159 > + AddPath("@GENTOO_PORTAGE_EPREFIX@/usr/include", System, false);
160 > // FIXME: temporary hack: hard-coded paths.
161 > AddPath("/usr/local/include", System, false);
162 > break;
163 > @@ -505,6 +506,7 @@
164 > // Add the default framework include paths on Darwin.
165 > if (HSOpts.UseStandardSystemIncludes) {
166 > if (triple.isOSDarwin()) {
167 > + AddPath("@GENTOO_PORTAGE_EPREFIX@/Frameworks", System, true);
168 > AddPath("/System/Library/Frameworks", System, true);
169 > AddPath("/Library/Frameworks", System, true);
170 > }
171
172 > --- portage/sys-libs/compiler-rt/compiler-rt-5.0.1.ebuild 2017-12-20 21:40:08.000000000 +0100
173 > +++ portage/sys-libs/compiler-rt/compiler-rt-5.0.1.ebuild 2017-12-23 21:56:33.000000000 +0100
174 > @@ -77,6 +77,13 @@
175 > -DCOMPILER_RT_BUILD_XRAY=OFF
176 > )
177 >
178 > + if use prefix && [[ "${CHOST}" == *-darwin* ]] ; then
179 > + mycmakeargs+=(
180 > + # disable use of SDK for the system itself
181 > + -DDARWIN_macosx_CACHED_SYSROOT=/
182 > + )
183 > + fi
184 > +
185 > if use test; then
186 > mycmakeargs+=(
187 > -DLIT_COMMAND="${EPREFIX}/usr/bin/lit"
188
189
190 --
191 Fabian Groffen
192 Gentoo on a different level

Attachments

File name MIME type
signature.asc application/pgp-signature

Replies

Subject Author
Re: [gentoo-alt] clang-5 on macOS Michael Weiser <michael@×××××××××××××××.net>