3 |
3 |
|
4 |
4 |
EAPI=8
|
5 |
5 |
|
6 |
|
inherit bash-completion-r1 llvm.org
|
|
6 |
inherit bash-completion-r1 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 ~loong ppc ppc64 ~riscv sparc x86 ~amd64-linux ~ppc-macos ~x64-macos"
|
|
13 |
KEYWORDS="~amd64 ~arm ~arm64 ~loong ~ppc ~ppc64 ~riscv ~sparc ~x86 ~amd64-linux ~ppc-macos ~x64-macos"
|
14 |
14 |
IUSE="
|
15 |
15 |
default-compiler-rt default-libcxx default-lld llvm-libunwind
|
16 |
16 |
hardened stricter
|
... | ... | |
63 |
63 |
fi
|
64 |
64 |
}
|
65 |
65 |
|
|
66 |
doclang_cfg() {
|
|
67 |
local triple="${1}"
|
|
68 |
|
|
69 |
local tool
|
|
70 |
for tool in ${triple}-clang{,++}; do
|
|
71 |
newins - "${tool}.cfg" <<-EOF
|
|
72 |
# This configuration file is used by ${tool} driver.
|
|
73 |
@gentoo-common.cfg
|
|
74 |
@gentoo-common-ld.cfg
|
|
75 |
EOF
|
|
76 |
done
|
|
77 |
|
|
78 |
newins - "${triple}-clang-cpp.cfg" <<-EOF
|
|
79 |
# This configuration file is used by the ${triple}-clang-cpp driver.
|
|
80 |
@gentoo-common.cfg
|
|
81 |
EOF
|
|
82 |
|
|
83 |
# Install symlinks for triples with other vendor strings since some
|
|
84 |
# programs insist on mangling the triple.
|
|
85 |
local vendor
|
|
86 |
for vendor in gentoo pc unknown; do
|
|
87 |
local vendor_triple="${triple%%-*}-${vendor}-${triple#*-*-}"
|
|
88 |
for tool in clang{,++,-cpp}; do
|
|
89 |
if [[ ! -f "${ED}/etc/clang/${vendor_triple}-${tool}.cfg" ]]; then
|
|
90 |
dosym "${triple}-${tool}.cfg" "/etc/clang/${vendor_triple}-${tool}.cfg"
|
|
91 |
fi
|
|
92 |
done
|
|
93 |
done
|
|
94 |
}
|
|
95 |
|
66 |
96 |
src_install() {
|
67 |
97 |
newbashcomp bash-autocomplete.sh clang
|
68 |
98 |
|
... | ... | |
91 |
121 |
-include "${EPREFIX}/usr/include/gentoo/maybe-stddefs.h"
|
92 |
122 |
EOF
|
93 |
123 |
|
|
124 |
# clang-cpp does not like link args being passed to it when directly
|
|
125 |
# invoked, so use a separate configuration file.
|
|
126 |
newins - gentoo-common-ld.cfg <<-EOF
|
|
127 |
# This file contains flags common to clang and clang++
|
|
128 |
@gentoo-hardened-ld.cfg
|
|
129 |
EOF
|
|
130 |
|
94 |
131 |
# Baseline hardening (bug #851111)
|
95 |
132 |
newins - gentoo-hardened.cfg <<-EOF
|
96 |
133 |
# Some of these options are added unconditionally, regardless of
|
... | ... | |
101 |
138 |
-include "${EPREFIX}/usr/include/gentoo/fortify.h"
|
102 |
139 |
EOF
|
103 |
140 |
|
|
141 |
newins - gentoo-hardened-ld.cfg <<-EOF
|
|
142 |
# Some of these options are added unconditionally, regardless of
|
|
143 |
# USE=hardened, for parity with sys-devel/gcc.
|
|
144 |
-Wl,-z,relro
|
|
145 |
EOF
|
|
146 |
|
104 |
147 |
dodir /usr/include/gentoo
|
105 |
148 |
|
106 |
149 |
cat >> "${ED}/usr/include/gentoo/maybe-stddefs.h" <<-EOF || die
|
... | ... | |
126 |
169 |
# define __GENTOO_HAS_FEATURE(x) 0
|
127 |
170 |
# endif
|
128 |
171 |
#
|
129 |
|
# if defined(__OPTIMIZE__) && __OPTIMIZE__ > 0
|
|
172 |
# if defined(__STDC_HOSTED__) && __STDC_HOSTED__ == 1
|
|
173 |
# define __GENTOO_NOT_FREESTANDING 1
|
|
174 |
# else
|
|
175 |
# define __GENTOO_NOT_FREESTANDING 0
|
|
176 |
# endif
|
|
177 |
#
|
|
178 |
# if defined(__OPTIMIZE__) && __OPTIMIZE__ > 0 && __GENTOO_NOT_FREESTANDING > 0
|
130 |
179 |
# if !defined(__SANITIZE_ADDRESS__) && !__GENTOO_HAS_FEATURE(address_sanitizer) && !__GENTOO_HAS_FEATURE(memory_sanitizer)
|
131 |
180 |
# define _FORTIFY_SOURCE ${fortify_level}
|
132 |
181 |
# endif
|
133 |
182 |
# endif
|
134 |
183 |
# undef __GENTOO_HAS_FEATURE
|
|
184 |
# undef __GENTOO_NOT_FREESTANDING
|
135 |
185 |
#endif
|
136 |
186 |
EOF
|
137 |
187 |
|
... | ... | |
142 |
192 |
|
143 |
193 |
# Analogue to GLIBCXX_ASSERTIONS
|
144 |
194 |
# https://libcxx.llvm.org/UsingLibcxx.html#assertions-mode
|
|
195 |
# https://libcxx.llvm.org/Hardening.html#using-hardened-mode
|
145 |
196 |
-D_LIBCPP_ENABLE_ASSERTIONS=1
|
146 |
197 |
EOF
|
|
198 |
|
|
199 |
cat >> "${ED}/etc/clang/gentoo-hardened-ld.cfg" <<-EOF || die
|
|
200 |
# Options below are conditional on USE=hardened.
|
|
201 |
-Wl,-z,now
|
|
202 |
EOF
|
147 |
203 |
fi
|
148 |
204 |
|
149 |
205 |
if use stricter; then
|
... | ... | |
168 |
224 |
EOF
|
169 |
225 |
fi
|
170 |
226 |
|
171 |
|
local tool
|
172 |
|
for tool in clang{,++,-cpp}; do
|
173 |
|
newins - "${tool}.cfg" <<-EOF
|
174 |
|
# This configuration file is used by ${tool} driver.
|
175 |
|
@gentoo-common.cfg
|
176 |
|
EOF
|
|
227 |
# We only install config files for supported ABIs because unprefixed tools
|
|
228 |
# might be used for crosscompilation where e.g. PIE may not be supported.
|
|
229 |
# See bug #912237 and bug #901247.
|
|
230 |
doclang_cfg "${CHOST}"
|
|
231 |
|
|
232 |
# Just ${CHOST} won't do due to bug #912685.
|
|
233 |
local abi
|
|
234 |
for abi in $(get_all_abis); do
|
|
235 |
local abi_chost=$(get_abi_CHOST "${abi}")
|
|
236 |
doclang_cfg "${abi_chost}"
|
177 |
237 |
done
|
178 |
238 |
}
|
179 |
239 |
|