1 |
commit: e5996958687948b4693324073f5114f19fd38b0e |
2 |
Author: Jonathan Davies <jpds <AT> protonmail <DOT> com> |
3 |
AuthorDate: Mon Nov 22 13:38:31 2021 +0000 |
4 |
Commit: Sam James <sam <AT> gentoo <DOT> org> |
5 |
CommitDate: Mon Nov 22 13:58:14 2021 +0000 |
6 |
URL: https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=e5996958 |
7 |
|
8 |
sys-libs/musl: fix ldconfig on SELinux |
9 |
|
10 |
Replaced mv in ldconfig with cp/rm dance so that the correct |
11 |
SELinux label is applied to the resulting file and the system doesn't |
12 |
brick itself instantly. |
13 |
|
14 |
Bug: https://bugs.gentoo.org/663990 |
15 |
Closes: https://bugs.gentoo.org/696818 |
16 |
Signed-off-by: Jonathan Davies <jpds <AT> protonmail.com> |
17 |
Closes: https://github.com/gentoo/gentoo/pull/23037 |
18 |
Signed-off-by: Sam James <sam <AT> gentoo.org> |
19 |
|
20 |
sys-libs/musl/files/ldconfig.in-r2 | 157 ++++++++++++++++++++++++++++++++++ |
21 |
sys-libs/musl/musl-1.2.2-r7.ebuild | 167 +++++++++++++++++++++++++++++++++++++ |
22 |
2 files changed, 324 insertions(+) |
23 |
|
24 |
diff --git a/sys-libs/musl/files/ldconfig.in-r2 b/sys-libs/musl/files/ldconfig.in-r2 |
25 |
new file mode 100644 |
26 |
index 000000000000..72a2f58bc744 |
27 |
--- /dev/null |
28 |
+++ b/sys-libs/musl/files/ldconfig.in-r2 |
29 |
@@ -0,0 +1,157 @@ |
30 |
+#!/bin/bash -e |
31 |
+# Copyright 1999-2021 Gentoo Authors |
32 |
+# Distributed under the terms of the GNU General Public License v2 |
33 |
+ |
34 |
+ROOT="/" |
35 |
+LDSO_CONF="/etc/ld.so.conf" |
36 |
+ |
37 |
+VERBOSE=0 |
38 |
+ |
39 |
+UPDATE_LINKS=1 |
40 |
+ |
41 |
+get_options() { |
42 |
+ while getopts "vnNXf:C:r:p" opt "$@"; do |
43 |
+ case $opt in |
44 |
+ v) |
45 |
+ echo "ldconfig for musl in Gentoo" |
46 |
+ VERBOSE=1 |
47 |
+ ;; |
48 |
+ r) |
49 |
+ ROOT=${OPTARG} |
50 |
+ LDSO_CONF=${ROOT}${LDSO_CONF} |
51 |
+ LDSO_CONF_DIR=$(dirname ${LDSO_CONF}) |
52 |
+ ;; |
53 |
+ f) |
54 |
+ LDSO_CONF=${OPTARG} |
55 |
+ ;; |
56 |
+ X) |
57 |
+ UPDATE_LINKS=0 |
58 |
+ ;; |
59 |
+ \?) |
60 |
+ echo "Invalid option: -${opt}" >&2 |
61 |
+ exit 1 |
62 |
+ ;; |
63 |
+ n|N|C|p) |
64 |
+ echo "Unimplemented option: -${opt}" >&2 |
65 |
+ exit 1 |
66 |
+ ;; |
67 |
+ esac |
68 |
+ done |
69 |
+ |
70 |
+ if [[ ${UPDATE_LINKS} == 1 ]]; then |
71 |
+ echo "Updating links is not implemented." |
72 |
+ fi |
73 |
+} |
74 |
+ |
75 |
+ |
76 |
+repeated() { |
77 |
+ local l=${1} |
78 |
+ local drs="${@:2}" |
79 |
+ for m in ${drs}; do |
80 |
+ [[ ${m} == ${l} ]] && return 0 |
81 |
+ done |
82 |
+ return 1 |
83 |
+} |
84 |
+ |
85 |
+expand() { |
86 |
+ # We are assuming the ld.so.conf's 'include' is not recursive |
87 |
+ local f line l |
88 |
+ local glob="${LDSO_CONF_DIR}/${1}" |
89 |
+ local drs="${@:2} " |
90 |
+ |
91 |
+ for f in ${glob}; do |
92 |
+ [[ ! -f ${f} ]] && continue |
93 |
+ while read line; do |
94 |
+ line=${line%%#*} |
95 |
+ line=${line//:/ } |
96 |
+ line=${line//,/ } |
97 |
+ for l in ${line}; do |
98 |
+ # We must add this whether or not the directory exists |
99 |
+ repeated ${l} ${drs} && continue |
100 |
+ drs+=" ${l} " |
101 |
+ done |
102 |
+ done < ${f} |
103 |
+ done |
104 |
+ |
105 |
+ echo ${drs} |
106 |
+} |
107 |
+ |
108 |
+read_ldso_conf() { |
109 |
+ local drs=" " |
110 |
+ |
111 |
+ while read line; do |
112 |
+ # Sanitize the line - see ldconfig(8) for delimiters |
113 |
+ # Note: bash read turns tabs into spaces and read already |
114 |
+ # delimits on newlines with the default $IFS |
115 |
+ line=${line%%#*} # Remove comments |
116 |
+ line=${line//:/ } # Change colon delimiter to space |
117 |
+ line=${line//,/ } # Change comma delimiter to space |
118 |
+ |
119 |
+ next=0 |
120 |
+ for l in ${line}; do |
121 |
+ if [[ ${next} == 1 ]]; then |
122 |
+ next=0 |
123 |
+ drs=$(expand ${l} ${drs}) |
124 |
+ elif [[ ${l} == "include" ]]; then |
125 |
+ next=1 |
126 |
+ else |
127 |
+ # glibc's ldconfig silently skips non directories |
128 |
+ if [[ -d ${l} ]]; then |
129 |
+ repeated ${l} ${drs} && continue |
130 |
+ drs+=" ${l} " |
131 |
+ fi |
132 |
+ fi |
133 |
+ done |
134 |
+ done < ${1} |
135 |
+ |
136 |
+ echo ${drs} |
137 |
+} |
138 |
+ |
139 |
+sanitize() { |
140 |
+ local drs=$@ |
141 |
+ |
142 |
+ repeated "/lib" ${drs} || drs="/lib ${drs}" |
143 |
+ repeated "/usr/lib" ${drs} || drs="/usr/lib ${drs}" |
144 |
+ |
145 |
+ echo ${drs} |
146 |
+} |
147 |
+ |
148 |
+changed() { |
149 |
+ [[ -f ${ETC_LDSO_PATH} ]] || return 0 |
150 |
+ local current=$(<${ETC_LDSO_PATH}) |
151 |
+ current=${current//$'\n'/ } |
152 |
+ [[ ${current} != ${drs} ]] || return 1 |
153 |
+} |
154 |
+ |
155 |
+get_options "$@" |
156 |
+ |
157 |
+if [[ ! -e ${LDSO_CONF} ]]; then |
158 |
+ echo "${LDSO_CONF} not found" >&2 |
159 |
+ exit 1 |
160 |
+fi |
161 |
+ |
162 |
+LDSO_CONF_DIR=$(dirname ${LDSO_CONF}) |
163 |
+ |
164 |
+drs=$(read_ldso_conf "${LDSO_CONF}") |
165 |
+drs=$(sanitize ${drs}) |
166 |
+ |
167 |
+ARCH=@@ARCH@@ |
168 |
+LDSO_PATH="${ROOT}/lib/ld-musl-${ARCH}.so.1" |
169 |
+if [[ ! -e ${LDSO_PATH} ]]; then |
170 |
+ echo "${LDSO_PATH} not found" >&2 |
171 |
+ exit 1 |
172 |
+fi |
173 |
+ |
174 |
+LDSO_ARCH=$(basename ${LDSO_PATH}) |
175 |
+LDSO_NAME=${LDSO_ARCH%.so.1} |
176 |
+ETC_LDSO_PATH="${ROOT}/etc/${LDSO_NAME}.path" |
177 |
+ |
178 |
+changed || exit 0 |
179 |
+X=$(mktemp -p /tmp ${LDSO_NAME}.XXXXXX) |
180 |
+for d in ${drs}; do |
181 |
+ echo ${d} >> ${X} |
182 |
+done |
183 |
+chmod 644 ${X} |
184 |
+# busybox doesn't support mz -Z |
185 |
+cp ${X} ${ETC_LDSO_PATH} |
186 |
+rm ${X} |
187 |
|
188 |
diff --git a/sys-libs/musl/musl-1.2.2-r7.ebuild b/sys-libs/musl/musl-1.2.2-r7.ebuild |
189 |
new file mode 100644 |
190 |
index 000000000000..dac76c213424 |
191 |
--- /dev/null |
192 |
+++ b/sys-libs/musl/musl-1.2.2-r7.ebuild |
193 |
@@ -0,0 +1,167 @@ |
194 |
+# Copyright 1999-2021 Gentoo Authors |
195 |
+# Distributed under the terms of the GNU General Public License v2 |
196 |
+ |
197 |
+EAPI=7 |
198 |
+ |
199 |
+inherit eapi8-dosym flag-o-matic toolchain-funcs |
200 |
+if [[ ${PV} == "9999" ]] ; then |
201 |
+ EGIT_REPO_URI="git://git.musl-libc.org/musl" |
202 |
+ inherit git-r3 |
203 |
+else |
204 |
+ SRC_URI="http://www.musl-libc.org/releases/${P}.tar.gz" |
205 |
+ KEYWORDS="-* ~amd64 ~arm ~arm64 ~mips ~ppc ~ppc64 ~x86" |
206 |
+fi |
207 |
+GETENT_COMMIT="93a08815f8598db442d8b766b463d0150ed8e2ab" |
208 |
+GETENT_FILE="musl-getent-${GETENT_COMMIT}.c" |
209 |
+SRC_URI+=" |
210 |
+ https://dev.gentoo.org/~blueness/musl-misc/getconf.c |
211 |
+ https://gitlab.alpinelinux.org/alpine/aports/-/raw/${GETENT_COMMIT}/main/musl/getent.c -> ${GETENT_FILE} |
212 |
+ https://dev.gentoo.org/~blueness/musl-misc/iconv.c |
213 |
+" |
214 |
+ |
215 |
+export CBUILD=${CBUILD:-${CHOST}} |
216 |
+export CTARGET=${CTARGET:-${CHOST}} |
217 |
+if [[ ${CTARGET} == ${CHOST} ]] ; then |
218 |
+ if [[ ${CATEGORY} == cross-* ]] ; then |
219 |
+ export CTARGET=${CATEGORY#cross-} |
220 |
+ fi |
221 |
+fi |
222 |
+ |
223 |
+DESCRIPTION="Light, fast and simple C library focused on standards-conformance and safety" |
224 |
+HOMEPAGE="https://musl.libc.org" |
225 |
+LICENSE="MIT LGPL-2 GPL-2" |
226 |
+SLOT="0" |
227 |
+IUSE="headers-only" |
228 |
+ |
229 |
+QA_SONAME="/usr/lib/libc.so" |
230 |
+QA_DT_NEEDED="/usr/lib/libc.so" |
231 |
+ |
232 |
+is_crosscompile() { |
233 |
+ [[ ${CHOST} != ${CTARGET} ]] |
234 |
+} |
235 |
+ |
236 |
+just_headers() { |
237 |
+ use headers-only && is_crosscompile |
238 |
+} |
239 |
+ |
240 |
+pkg_setup() { |
241 |
+ if [ ${CTARGET} == ${CHOST} ] ; then |
242 |
+ case ${CHOST} in |
243 |
+ *-musl*) ;; |
244 |
+ *) die "Use sys-devel/crossdev to build a musl toolchain" ;; |
245 |
+ esac |
246 |
+ fi |
247 |
+ |
248 |
+ # fix for #667126, copied from glibc ebuild |
249 |
+ # make sure host make.conf doesn't pollute us |
250 |
+ if is_crosscompile || tc-is-cross-compiler ; then |
251 |
+ CHOST=${CTARGET} strip-unsupported-flags |
252 |
+ fi |
253 |
+} |
254 |
+ |
255 |
+src_unpack() { |
256 |
+ if [[ ${PV} == 9999 ]]; then |
257 |
+ git-r3_src_unpack |
258 |
+ else |
259 |
+ unpack "${P}.tar.gz" |
260 |
+ fi |
261 |
+ mkdir misc || die |
262 |
+ cp "${DISTDIR}"/getconf.c misc/getconf.c || die |
263 |
+ cp "${DISTDIR}/${GETENT_FILE}" misc/getent.c || die |
264 |
+ cp "${DISTDIR}"/iconv.c misc/iconv.c || die |
265 |
+} |
266 |
+ |
267 |
+src_prepare() { |
268 |
+ default |
269 |
+ |
270 |
+ # Expand gethostid instead of being just a stub |
271 |
+ eapply "${FILESDIR}/${PN}-1.2.2-gethostid.patch" |
272 |
+} |
273 |
+ |
274 |
+src_configure() { |
275 |
+ tc-getCC ${CTARGET} |
276 |
+ just_headers && export CC=true |
277 |
+ |
278 |
+ local sysroot |
279 |
+ is_crosscompile && sysroot="${EPREFIX}"/usr/${CTARGET} |
280 |
+ ./configure \ |
281 |
+ --target=${CTARGET} \ |
282 |
+ --prefix=${sysroot}/usr \ |
283 |
+ --syslibdir=${sysroot}/lib \ |
284 |
+ --disable-gcc-wrapper || die |
285 |
+} |
286 |
+ |
287 |
+src_compile() { |
288 |
+ emake obj/include/bits/alltypes.h |
289 |
+ just_headers && return 0 |
290 |
+ |
291 |
+ emake |
292 |
+ if [[ ${CATEGORY} != cross-* ]] ; then |
293 |
+ emake -C "${T}" getconf getent iconv \ |
294 |
+ CC="$(tc-getCC)" \ |
295 |
+ CFLAGS="${CFLAGS}" \ |
296 |
+ CPPFLAGS="${CPPFLAGS}" \ |
297 |
+ LDFLAGS="${LDFLAGS}" \ |
298 |
+ VPATH="${WORKDIR}/misc" |
299 |
+ fi |
300 |
+ |
301 |
+ $(tc-getCC) ${CFLAGS} -c -o libssp_nonshared.o "${FILESDIR}"/stack_chk_fail_local.c || die |
302 |
+ $(tc-getAR) -rcs libssp_nonshared.a libssp_nonshared.o || die |
303 |
+} |
304 |
+ |
305 |
+src_install() { |
306 |
+ local target="install" |
307 |
+ just_headers && target="install-headers" |
308 |
+ emake DESTDIR="${D}" ${target} |
309 |
+ just_headers && return 0 |
310 |
+ |
311 |
+ # musl provides ldd via a sym link to its ld.so |
312 |
+ local sysroot |
313 |
+ is_crosscompile && sysroot=/usr/${CTARGET} |
314 |
+ local ldso=$(basename "${D}"${sysroot}/lib/ld-musl-*) |
315 |
+ dosym ${sysroot}/lib/${ldso} ${sysroot}/usr/bin/ldd |
316 |
+ |
317 |
+ if [[ ${CATEGORY} != cross-* ]] ; then |
318 |
+ # Fish out of config: |
319 |
+ # ARCH = ... |
320 |
+ # SUBARCH = ... |
321 |
+ # and print $(ARCH)$(SUBARCH). |
322 |
+ local arch=$(awk '{ k[$1] = $3 } END { printf("%s%s", k["ARCH"], k["SUBARCH"]); }' config.mak) |
323 |
+ |
324 |
+ if [[ ! -e "${ED}"/lib/ld-musl-${arch}.so.1 ]] ; then |
325 |
+ # During cross (using crossdev), when emerging sys-libs/musl, |
326 |
+ # if /usr/lib/libc.so.1 doesn't exist on the system, installation |
327 |
+ # would fail. |
328 |
+ # |
329 |
+ # The musl build system seems to create a symlink: |
330 |
+ # ${D}/lib/ld-musl-${arch}.so.1 -> /usr/lib/libc.so.1 (absolute) |
331 |
+ # During cross, there's no guarantee that the host is using musl |
332 |
+ # so that file may not exist. Use a relative symlink within ${D} |
333 |
+ # instead. |
334 |
+ dosym8 -r /usr/lib/libc.so /lib/ld-musl-${arch}.so.1 |
335 |
+ |
336 |
+ # If it's still a dead symlnk, OK, we really do need to abort. |
337 |
+ [[ -e "${ED}"/lib/ld-musl-${arch}.so.1 ]] || die |
338 |
+ fi |
339 |
+ |
340 |
+ cp "${FILESDIR}"/ldconfig.in-r2 "${T}"/ldconfig.in || die |
341 |
+ sed -e "s|@@ARCH@@|${arch}|" "${T}"/ldconfig.in > "${T}"/ldconfig || die |
342 |
+ into / |
343 |
+ dosbin "${T}"/ldconfig |
344 |
+ into /usr |
345 |
+ dobin "${T}"/getconf |
346 |
+ dobin "${T}"/getent |
347 |
+ dobin "${T}"/iconv |
348 |
+ echo 'LDPATH="include ld.so.conf.d/*.conf"' > "${T}"/00musl || die |
349 |
+ doenvd "${T}"/00musl |
350 |
+ dolib.a libssp_nonshared.a |
351 |
+ fi |
352 |
+} |
353 |
+ |
354 |
+pkg_postinst() { |
355 |
+ is_crosscompile && return 0 |
356 |
+ |
357 |
+ [ "${ROOT}" != "/" ] && return 0 |
358 |
+ |
359 |
+ ldconfig || die |
360 |
+} |