| 3 |
3 |
|
| 4 |
4 |
EAPI=8
|
| 5 |
5 |
|
| 6 |
|
inherit bash-completion-r1 llvm.org
|
|
6 |
inherit bash-completion-r1 elisp-common llvm.org multilib
|
| 7 |
7 |
|
| 8 |
8 |
DESCRIPTION="Common files shared between multiple slots of clang"
|
| 9 |
9 |
HOMEPAGE="https://llvm.org/"
|
| 10 |
10 |
|
| 11 |
11 |
LICENSE="Apache-2.0-with-LLVM-exceptions UoI-NCSA"
|
| 12 |
12 |
SLOT="0"
|
| 13 |
|
KEYWORDS="amd64 arm arm64 ppc ppc64 ~riscv ~sparc x86 ~x64-macos"
|
|
13 |
KEYWORDS="amd64 arm arm64 ~loong ~mips ppc ppc64 ~riscv ~sparc x86 ~arm64-macos ~x64-macos"
|
| 14 |
14 |
IUSE="
|
| 15 |
|
default-compiler-rt default-libcxx default-lld llvm-libunwind
|
| 16 |
|
hardened
|
|
15 |
default-compiler-rt default-libcxx default-lld
|
|
16 |
bootstrap-prefix cet emacs hardened llvm-libunwind
|
| 17 |
17 |
"
|
| 18 |
18 |
|
| 19 |
19 |
PDEPEND="
|
| 20 |
20 |
default-compiler-rt? (
|
| 21 |
|
llvm-runtimes/clang-runtime:${PV}[compiler-rt]
|
|
21 |
llvm-runtimes/clang-runtime:${LLVM_MAJOR}[compiler-rt]
|
| 22 |
22 |
llvm-libunwind? ( llvm-runtimes/libunwind[static-libs] )
|
| 23 |
23 |
!llvm-libunwind? ( sys-libs/libunwind[static-libs] )
|
| 24 |
24 |
)
|
| ... | ... | |
| 28 |
28 |
default-lld? ( >=llvm-core/lld-${PV} )
|
| 29 |
29 |
!default-lld? ( sys-devel/binutils )
|
| 30 |
30 |
"
|
|
31 |
# enforce flags on clang-runtime as well to aid transition
|
|
32 |
PDEPEND+="
|
|
33 |
llvm-runtimes/clang-runtime[default-compiler-rt(-)?,default-libcxx(-)?,default-lld(-)?,llvm-libunwind(-)?]
|
|
34 |
emacs? ( >=app-editors/emacs-26.3:* )
|
|
35 |
"
|
| 31 |
36 |
IDEPEND="
|
| 32 |
37 |
!default-compiler-rt? ( sys-devel/gcc-config )
|
| 33 |
38 |
!default-libcxx? ( sys-devel/gcc-config )
|
| 34 |
39 |
"
|
|
40 |
BDEPEND="
|
|
41 |
emacs? ( >=app-editors/emacs-26.3:* )
|
|
42 |
"
|
| 35 |
43 |
|
| 36 |
|
LLVM_COMPONENTS=( clang/utils )
|
|
44 |
LLVM_COMPONENTS=( clang/utils clang/tools/clang-format )
|
| 37 |
45 |
llvm.org_set_globals
|
| 38 |
46 |
|
|
47 |
SITEFILE="50clang-gentoo.el"
|
|
48 |
|
| 39 |
49 |
pkg_pretend() {
|
| 40 |
50 |
[[ ${CLANG_IGNORE_DEFAULT_RUNTIMES} ]] && return
|
| 41 |
51 |
|
| ... | ... | |
| 62 |
72 |
fi
|
| 63 |
73 |
}
|
| 64 |
74 |
|
|
75 |
_doclang_cfg() {
|
|
76 |
local triple="${1}"
|
|
77 |
|
|
78 |
local tool
|
|
79 |
for tool in ${triple}-clang{,++}; do
|
|
80 |
newins - "${tool}.cfg" <<-EOF
|
|
81 |
# This configuration file is used by ${tool} driver.
|
|
82 |
@gentoo-common.cfg
|
|
83 |
@gentoo-common-ld.cfg
|
|
84 |
EOF
|
|
85 |
if [[ ${triple} == x86_64* ]]; then
|
|
86 |
cat >> "${ED}/etc/clang/${tool}.cfg" <<-EOF || die
|
|
87 |
@gentoo-cet.cfg
|
|
88 |
EOF
|
|
89 |
fi
|
|
90 |
done
|
|
91 |
|
|
92 |
if use kernel_Darwin; then
|
|
93 |
cat >> "${ED}/etc/clang/${triple}-clang++.cfg" <<-EOF || die
|
|
94 |
-lc++abi
|
|
95 |
EOF
|
|
96 |
fi
|
|
97 |
|
|
98 |
newins - "${triple}-clang-cpp.cfg" <<-EOF
|
|
99 |
# This configuration file is used by the ${triple}-clang-cpp driver.
|
|
100 |
@gentoo-common.cfg
|
|
101 |
EOF
|
|
102 |
if [[ ${triple} == x86_64* ]]; then
|
|
103 |
cat >> "${ED}/etc/clang/${triple}-clang-cpp.cfg" <<-EOF || die
|
|
104 |
@gentoo-cet.cfg
|
|
105 |
EOF
|
|
106 |
fi
|
|
107 |
|
|
108 |
# Install symlinks for triples with other vendor strings since some
|
|
109 |
# programs insist on mangling the triple.
|
|
110 |
local vendor
|
|
111 |
for vendor in gentoo pc unknown; do
|
|
112 |
local vendor_triple="${triple%%-*}-${vendor}-${triple#*-*-}"
|
|
113 |
for tool in clang{,++,-cpp}; do
|
|
114 |
if [[ ! -f "${ED}/etc/clang/${vendor_triple}-${tool}.cfg" ]]; then
|
|
115 |
dosym "${triple}-${tool}.cfg" "/etc/clang/${vendor_triple}-${tool}.cfg"
|
|
116 |
fi
|
|
117 |
done
|
|
118 |
done
|
|
119 |
}
|
|
120 |
|
|
121 |
doclang_cfg() {
|
|
122 |
local triple="${1}"
|
|
123 |
|
|
124 |
_doclang_cfg ${triple}
|
|
125 |
|
|
126 |
# LLVM may have different arch names in some cases. For example in x86
|
|
127 |
# profiles the triple uses i686, but llvm will prefer i386 if invoked
|
|
128 |
# with "clang" on x86 or "clang -m32" on x86_64. The gentoo triple will
|
|
129 |
# be used if invoked through ${CHOST}-clang{,++,-cpp} though.
|
|
130 |
#
|
|
131 |
# To make sure the correct triples are installed,
|
|
132 |
# see Triple::getArchTypeName() in llvm/lib/TargetParser/Triple.cpp
|
|
133 |
# and compare with CHOST values in profiles.
|
|
134 |
|
|
135 |
local abi=${triple%%-*}
|
|
136 |
case ${abi} in
|
|
137 |
armv4l|armv4t|armv5tel|armv6j|armv7a)
|
|
138 |
_doclang_cfg ${triple/${abi}/arm}
|
|
139 |
;;
|
|
140 |
i686)
|
|
141 |
_doclang_cfg ${triple/${abi}/i386}
|
|
142 |
;;
|
|
143 |
sparc)
|
|
144 |
_doclang_cfg ${triple/${abi}/sparcel}
|
|
145 |
;;
|
|
146 |
sparc64)
|
|
147 |
_doclang_cfg ${triple/${abi}/sparcv9}
|
|
148 |
;;
|
|
149 |
esac
|
|
150 |
}
|
|
151 |
|
|
152 |
src_compile() {
|
|
153 |
default
|
|
154 |
use emacs && elisp-compile ../tools/clang-format/clang-format.el
|
|
155 |
}
|
|
156 |
|
| 65 |
157 |
src_install() {
|
| 66 |
158 |
newbashcomp bash-autocomplete.sh clang
|
| 67 |
159 |
|
| ... | ... | |
| 90 |
182 |
-include "${EPREFIX}/usr/include/gentoo/maybe-stddefs.h"
|
| 91 |
183 |
EOF
|
| 92 |
184 |
|
|
185 |
# clang-cpp does not like link args being passed to it when directly
|
|
186 |
# invoked, so use a separate configuration file.
|
|
187 |
newins - gentoo-common-ld.cfg <<-EOF
|
|
188 |
# This file contains flags common to clang and clang++
|
|
189 |
@gentoo-hardened-ld.cfg
|
|
190 |
EOF
|
|
191 |
|
| 93 |
192 |
# Baseline hardening (bug #851111)
|
| 94 |
|
# (-fstack-clash-protection is omitted because of a possible Clang bug,
|
| 95 |
|
# see bug #892537 and bug #865339.)
|
| 96 |
193 |
newins - gentoo-hardened.cfg <<-EOF
|
| 97 |
194 |
# Some of these options are added unconditionally, regardless of
|
| 98 |
195 |
# USE=hardened, for parity with sys-devel/gcc.
|
|
196 |
-Xarch_host -fstack-clash-protection
|
| 99 |
197 |
-Xarch_host -fstack-protector-strong
|
| 100 |
198 |
-fPIE
|
| 101 |
199 |
-include "${EPREFIX}/usr/include/gentoo/fortify.h"
|
| 102 |
200 |
EOF
|
| 103 |
201 |
|
|
202 |
newins - gentoo-cet.cfg <<-EOF
|
|
203 |
-Xarch_host -fcf-protection=$(usex cet full none)
|
|
204 |
EOF
|
|
205 |
|
|
206 |
if use kernel_Darwin; then
|
|
207 |
newins - gentoo-hardened-ld.cfg <<-EOF
|
|
208 |
# There was -Wl,-z,relro here, but it's not supported on Mac
|
|
209 |
# TODO: investigate whether -bind_at_load or -read_only_stubs will do the job
|
|
210 |
EOF
|
|
211 |
else
|
|
212 |
newins - gentoo-hardened-ld.cfg <<-EOF
|
|
213 |
# Some of these options are added unconditionally, regardless of
|
|
214 |
# USE=hardened, for parity with sys-devel/gcc.
|
|
215 |
-Wl,-z,relro
|
|
216 |
-Wl,-z,now
|
|
217 |
EOF
|
|
218 |
fi
|
|
219 |
|
| 104 |
220 |
dodir /usr/include/gentoo
|
| 105 |
221 |
|
| 106 |
222 |
cat >> "${ED}/usr/include/gentoo/maybe-stddefs.h" <<-EOF || die
|
| ... | ... | |
| 126 |
242 |
# define __GENTOO_HAS_FEATURE(x) 0
|
| 127 |
243 |
# endif
|
| 128 |
244 |
#
|
| 129 |
|
# if defined(__OPTIMIZE__) && __OPTIMIZE__ > 0
|
| 130 |
|
# if !defined(__SANITIZE_ADDRESS__) && !__GENTOO_HAS_FEATURE(address_sanitizer) && !__GENTOO_HAS_FEATURE(memory_sanitizer)
|
| 131 |
|
# define _FORTIFY_SOURCE ${fortify_level}
|
| 132 |
|
# endif
|
|
245 |
# if !defined(__OPTIMIZE__) || __OPTIMIZE__ == 0
|
|
246 |
# elif !defined(__STDC_HOSTED__) || __STDC_HOSTED__ != 1
|
|
247 |
# elif defined(__SANITIZE_ADDRESS__)
|
|
248 |
# elif __GENTOO_HAS_FEATURE(address_sanitizer)
|
|
249 |
# elif __GENTOO_HAS_FEATURE(hwaddress_sanitizer)
|
|
250 |
# elif __GENTOO_HAS_FEATURE(memory_sanitizer)
|
|
251 |
# elif __GENTOO_HAS_FEATURE(numerical_stability_sanitizer)
|
|
252 |
# elif __GENTOO_HAS_FEATURE(realtime_sanitizer)
|
|
253 |
# elif __GENTOO_HAS_FEATURE(thread_sanitizer)
|
|
254 |
# else
|
|
255 |
# define _FORTIFY_SOURCE ${fortify_level}
|
| 133 |
256 |
# endif
|
|
257 |
#
|
| 134 |
258 |
# undef __GENTOO_HAS_FEATURE
|
| 135 |
259 |
#endif
|
| 136 |
260 |
EOF
|
| 137 |
261 |
|
|
262 |
# TODO: Maybe -D_LIBCPP_HARDENING_MODE=_LIBCPP_HARDENING_MODE_FAST for
|
|
263 |
# non-hardened?
|
| 138 |
264 |
if use hardened ; then
|
| 139 |
265 |
cat >> "${ED}/etc/clang/gentoo-hardened.cfg" <<-EOF || die
|
| 140 |
266 |
# Options below are conditional on USE=hardened.
|
| 141 |
|
-D_GLIBCXX_ASSERTIONS
|
|
267 |
-Xarch_host -D_GLIBCXX_ASSERTIONS
|
| 142 |
268 |
|
| 143 |
269 |
# Analogue to GLIBCXX_ASSERTIONS
|
| 144 |
270 |
# https://libcxx.llvm.org/UsingLibcxx.html#assertions-mode
|
| 145 |
|
-D_LIBCPP_ENABLE_ASSERTIONS=1
|
|
271 |
# https://libcxx.llvm.org/Hardening.html#using-hardened-mode
|
|
272 |
-Xarch_host -D_LIBCPP_HARDENING_MODE=_LIBCPP_HARDENING_MODE_EXTENSIVE
|
| 146 |
273 |
EOF
|
| 147 |
|
fi
|
| 148 |
274 |
|
| 149 |
|
local tool
|
| 150 |
|
for tool in clang{,++,-cpp}; do
|
| 151 |
|
newins - "${tool}.cfg" <<-EOF
|
| 152 |
|
# This configuration file is used by ${tool} driver.
|
| 153 |
|
@gentoo-common.cfg
|
|
275 |
cat >> "${ED}/etc/clang/gentoo-hardened-ld.cfg" <<-EOF || die
|
|
276 |
# Options below are conditional on USE=hardened.
|
| 154 |
277 |
EOF
|
|
278 |
fi
|
|
279 |
|
|
280 |
# We only install config files for supported ABIs because unprefixed tools
|
|
281 |
# might be used for crosscompilation where e.g. PIE may not be supported.
|
|
282 |
# See bug #912237 and bug #901247. Just ${CHOST} won't do due to bug #912685.
|
|
283 |
local abi
|
|
284 |
for abi in $(get_all_abis); do
|
|
285 |
local abi_chost=$(get_abi_CHOST "${abi}")
|
|
286 |
doclang_cfg "${abi_chost}"
|
| 155 |
287 |
done
|
|
288 |
|
|
289 |
if use kernel_Darwin; then
|
|
290 |
cat >> "${ED}/etc/clang/gentoo-common.cfg" <<-EOF || die
|
|
291 |
# Gentoo Prefix on Darwin
|
|
292 |
-Wl,-search_paths_first
|
|
293 |
EOF
|
|
294 |
if use bootstrap-prefix ; then
|
|
295 |
# bootstrap-prefix is only set during stage2 of bootstrapping
|
|
296 |
# Prefix, where EPREFIX is set to EPREFIX/tmp.
|
|
297 |
# Here we need to point it at the future lib dir of the stage3's
|
|
298 |
# EPREFIX.
|
|
299 |
cat >> "${ED}/etc/clang/gentoo-common.cfg" <<-EOF || die
|
|
300 |
-Wl,-rpath,${EPREFIX}/../usr/lib
|
|
301 |
-Wl,-L,${EPREFIX}/../usr/lib
|
|
302 |
-isystem ${EPREFIX}/../usr/include
|
|
303 |
EOF
|
|
304 |
fi
|
|
305 |
# Using -Wl,-L instead of -L to trick compiler driver to put it
|
|
306 |
# after -isysroot's internal -L
|
|
307 |
cat >> "${ED}/etc/clang/gentoo-common.cfg" <<-EOF || die
|
|
308 |
-Wl,-rpath,${EPREFIX}/usr/lib
|
|
309 |
-Wl,-L,${EPREFIX}/usr/lib
|
|
310 |
-isystem ${EPREFIX}/usr/include
|
|
311 |
-isysroot ${EPREFIX}/MacOSX.sdk
|
|
312 |
EOF
|
|
313 |
fi
|
|
314 |
|
|
315 |
if use emacs ; then
|
|
316 |
elisp-install clang ../tools/clang-format/clang-format.{el,elc}
|
|
317 |
elisp-make-site-file "${SITEFILE}" clang
|
|
318 |
fi
|
| 156 |
319 |
}
|
| 157 |
320 |
|
| 158 |
321 |
pkg_preinst() {
|
| ... | ... | |
| 166 |
329 |
fi
|
| 167 |
330 |
fi
|
| 168 |
331 |
}
|
|
332 |
|
|
333 |
pkg_postinst() {
|
|
334 |
use emacs && elisp-site-regen
|
|
335 |
}
|
|
336 |
|
|
337 |
pkg_postrm() {
|
|
338 |
use emacs && elisp-site-regen
|
|
339 |
}
|