Gentoo Archives: gentoo-dev

From: Mike Frysinger <vapier@g.o>
To: gentoo-dev@l.g.o
Subject: [gentoo-dev] [PATCH 01/21] sep-usr.eclass: new eclass to hold gen_usr_ldscript and related logic #417451
Date: Wed, 30 Mar 2016 23:59:45
Message-Id: 1459382320-20672-2-git-send-email-vapier@gentoo.org
In Reply to: [gentoo-dev] [PATCH 00/21] gen_usr_ldscript: migrate away from a sep-/usr by default by Mike Frysinger
1 This is mostly a copy of the func as it exists in the toolchain-funcs
2 eclass, but with some of the initial logic shifted to USE=sep-usr.
3 Once all ebuilds have switched over to this eclass, we can drop it
4 from the toolchain-funcs eclass. In the meantime, make sure this is
5 inherited last.
6 ---
7 eclass/sep-usr.eclass | 152 ++++++++++++++++++++++++++++++++++++++++++++++++++
8 profiles/use.desc | 1 +
9 2 files changed, 153 insertions(+)
10 create mode 100644 eclass/sep-usr.eclass
11
12 diff --git a/eclass/sep-usr.eclass b/eclass/sep-usr.eclass
13 new file mode 100644
14 index 0000000..c6791e1
15 --- /dev/null
16 +++ b/eclass/sep-usr.eclass
17 @@ -0,0 +1,152 @@
18 +# Copyright 1999-2016 Gentoo Foundation
19 +# Distributed under the terms of the GNU General Public License v2
20 +
21 +# @ECLASS: sep-usr.eclass
22 +# @MAINTAINER:
23 +# Toolchain Ninjas <toolchain@g.o>
24 +# @BLURB: functions to support a split /usr partition
25 +# @DESCRIPTION:
26 +# Some core packages might install extra files into / instead of /usr when
27 +# the expectation is that /usr is a separate mount point. This eclass holds
28 +# various functions to simplify that process for ebuild writers.
29 +
30 +if [[ -z ${_SEP_USR_ECLASS} ]]; then
31 +_SEP_USR_ECLASS=1
32 +
33 +inherit multilib
34 +
35 +IUSE="sep-usr"
36 +
37 +# @FUNCTION: gen_usr_ldscript
38 +# @USAGE: [-a] <list of libs to create linker scripts for>
39 +# @DESCRIPTION:
40 +# This function generate linker scripts in /usr/lib for dynamic
41 +# libs in /lib. This is to fix linking problems when you have
42 +# the .so in /lib, and the .a in /usr/lib. What happens is that
43 +# in some cases when linking dynamic, the .a in /usr/lib is used
44 +# instead of the .so in /lib due to gcc/libtool tweaking ld's
45 +# library search path. This causes many builds to fail.
46 +# See bug #4411 for more info.
47 +#
48 +# Note that you should in general use the unversioned name of
49 +# the library (libfoo.so), as ldconfig should usually update it
50 +# correctly to point to the latest version of the library present.
51 +gen_usr_ldscript() {
52 + local lib libdir=$(get_libdir) output_format="" auto=false suffix=$(get_libname)
53 + [[ -z ${ED+set} ]] && local ED=${D%/}${EPREFIX}/
54 +
55 + # This code only matters when it's been enabled. #417451
56 + use sep-usr || return 0
57 +
58 + # We only care about stuffing / for the native ABI. #479448
59 + if [[ $(type -t multilib_is_native_abi) == "function" ]] ; then
60 + multilib_is_native_abi || return 0
61 + fi
62 +
63 + # Just make sure it exists
64 + dodir /usr/${libdir}
65 +
66 + if [[ $1 == "-a" ]] ; then
67 + auto=true
68 + shift
69 + dodir /${libdir}
70 + fi
71 +
72 + # OUTPUT_FORMAT gives hints to the linker as to what binary format
73 + # is referenced ... makes multilib saner
74 + local flags=( ${CFLAGS} ${LDFLAGS} -Wl,--verbose )
75 + if $(tc-getLD) --version | grep -q 'GNU gold' ; then
76 + # If they're using gold, manually invoke the old bfd. #487696
77 + local d="${T}/bfd-linker"
78 + mkdir -p "${d}"
79 + ln -sf $(which ${CHOST}-ld.bfd) "${d}"/ld
80 + flags+=( -B"${d}" )
81 + fi
82 + output_format=$($(tc-getCC) "${flags[@]}" 2>&1 | sed -n 's/^OUTPUT_FORMAT("\([^"]*\)",.*/\1/p')
83 + [[ -n ${output_format} ]] && output_format="OUTPUT_FORMAT ( ${output_format} )"
84 +
85 + for lib in "$@" ; do
86 + local tlib
87 + if ${auto} ; then
88 + lib="lib${lib}${suffix}"
89 + else
90 + # Ensure /lib/${lib} exists to avoid dangling scripts/symlinks.
91 + # This especially is for AIX where $(get_libname) can return ".a",
92 + # so /lib/${lib} might be moved to /usr/lib/${lib} (by accident).
93 + [[ -r ${ED}/${libdir}/${lib} ]] || continue
94 + #TODO: better die here?
95 + fi
96 +
97 + case ${CTARGET:-${CHOST}} in
98 + *-darwin*)
99 + if ${auto} ; then
100 + tlib=$(scanmacho -qF'%S#F' "${ED}"/usr/${libdir}/${lib})
101 + else
102 + tlib=$(scanmacho -qF'%S#F' "${ED}"/${libdir}/${lib})
103 + fi
104 + [[ -z ${tlib} ]] && die "unable to read install_name from ${lib}"
105 + tlib=${tlib##*/}
106 +
107 + if ${auto} ; then
108 + mv "${ED}"/usr/${libdir}/${lib%${suffix}}.*${suffix#.} "${ED}"/${libdir}/ || die
109 + # some install_names are funky: they encode a version
110 + if [[ ${tlib} != ${lib%${suffix}}.*${suffix#.} ]] ; then
111 + mv "${ED}"/usr/${libdir}/${tlib%${suffix}}.*${suffix#.} "${ED}"/${libdir}/ || die
112 + fi
113 + rm -f "${ED}"/${libdir}/${lib}
114 + fi
115 +
116 + # Mach-O files have an id, which is like a soname, it tells how
117 + # another object linking against this lib should reference it.
118 + # Since we moved the lib from usr/lib into lib this reference is
119 + # wrong. Hence, we update it here. We don't configure with
120 + # libdir=/lib because that messes up libtool files.
121 + # Make sure we don't lose the specific version, so just modify the
122 + # existing install_name
123 + if [[ ! -w "${ED}/${libdir}/${tlib}" ]] ; then
124 + chmod u+w "${ED}${libdir}/${tlib}" # needed to write to it
125 + local nowrite=yes
126 + fi
127 + install_name_tool \
128 + -id "${EPREFIX}"/${libdir}/${tlib} \
129 + "${ED}"/${libdir}/${tlib} || die "install_name_tool failed"
130 + [[ -n ${nowrite} ]] && chmod u-w "${ED}${libdir}/${tlib}"
131 + # Now as we don't use GNU binutils and our linker doesn't
132 + # understand linker scripts, just create a symlink.
133 + pushd "${ED}/usr/${libdir}" > /dev/null
134 + ln -snf "../../${libdir}/${tlib}" "${lib}"
135 + popd > /dev/null
136 + ;;
137 + *)
138 + if ${auto} ; then
139 + tlib=$(scanelf -qF'%S#F' "${ED}"/usr/${libdir}/${lib})
140 + [[ -z ${tlib} ]] && die "unable to read SONAME from ${lib}"
141 + mv "${ED}"/usr/${libdir}/${lib}* "${ED}"/${libdir}/ || die
142 + # some SONAMEs are funky: they encode a version before the .so
143 + if [[ ${tlib} != ${lib}* ]] ; then
144 + mv "${ED}"/usr/${libdir}/${tlib}* "${ED}"/${libdir}/ || die
145 + fi
146 + rm -f "${ED}"/${libdir}/${lib}
147 + else
148 + tlib=${lib}
149 + fi
150 + cat > "${ED}/usr/${libdir}/${lib}" <<-END_LDSCRIPT
151 + /* GNU ld script
152 + Since Gentoo has critical dynamic libraries in /lib, and the static versions
153 + in /usr/lib, we need to have a "fake" dynamic lib in /usr/lib, otherwise we
154 + run into linking problems. This "fake" dynamic lib is a linker script that
155 + redirects the linker to the real lib. And yes, this works in the cross-
156 + compiling scenario as the sysroot-ed linker will prepend the real path.
157 +
158 + See bug https://bugs.gentoo.org/4411 for more info.
159 + */
160 + ${output_format}
161 + GROUP ( ${EPREFIX}/${libdir}/${tlib} )
162 + END_LDSCRIPT
163 + ;;
164 + esac
165 + fperms a+x "/usr/${libdir}/${lib}" || die "could not change perms on ${lib}"
166 + done
167 +}
168 +
169 +fi
170 diff --git a/profiles/use.desc b/profiles/use.desc
171 index 6acf19f..6297fee 100644
172 --- a/profiles/use.desc
173 +++ b/profiles/use.desc
174 @@ -299,6 +299,7 @@ seamonkey - Add support for the Seamonkey web-browser
175 seccomp - Enable seccomp (secure computing mode) to perform system call filtering at runtime to increase security of programs
176 selinux - !!internal use only!! Security Enhanced Linux support, this must be set by the selinux profile or breakage will occur
177 semantic-desktop - Cross-KDE support for semantic search and information retrieval
178 +sep-usr - Install some critical files into / instead of /usr (for when /usr is a separate mount point)
179 session - Add persistent session support
180 sharedmem - Add support for shared memory use
181 shorten - Add support for the shorten audio compressor
182 --
183 2.7.4