1 |
This intentionally redefines the same function to ease migration. Once |
2 |
all ebuilds have been converted, the definition in toolchain-funcs can |
3 |
be removed. |
4 |
|
5 |
Signed-off-by: Mike Gilbert <floppym@g.o> |
6 |
--- |
7 |
eclass/usr-ldscript.eclass | 156 +++++++++++++++++++++++++++++++++++++ |
8 |
1 file changed, 156 insertions(+) |
9 |
create mode 100644 eclass/usr-ldscript.eclass |
10 |
|
11 |
diff --git a/eclass/usr-ldscript.eclass b/eclass/usr-ldscript.eclass |
12 |
new file mode 100644 |
13 |
index 000000000000..c1abbb49f4ba |
14 |
--- /dev/null |
15 |
+++ b/eclass/usr-ldscript.eclass |
16 |
@@ -0,0 +1,156 @@ |
17 |
+# Copyright 2019 Gentoo Authors |
18 |
+# Distributed under the terms of the GNU General Public License v2 |
19 |
+ |
20 |
+# @ECLASS: usr-ldscript.eclass |
21 |
+# @MAINTAINER: |
22 |
+# Toolchain Ninjas <toolchain@g.o> |
23 |
+# @AUTHOR: |
24 |
+# Mike Gilbert <floppym@g.o> |
25 |
+# @BLURB: Defines the gen_usr_ldscript function. |
26 |
+ |
27 |
+if [[ -z ${_USR_LDSCRIPT_ECLASS} ]]; then |
28 |
+_USR_LDSCRIPT_ECLASS=1 |
29 |
+ |
30 |
+inherit multilib toolchain-funcs |
31 |
+ |
32 |
+# @FUNCTION: gen_usr_ldscript |
33 |
+# @USAGE: [-a] <list of libs to create linker scripts for> |
34 |
+# @DESCRIPTION: |
35 |
+# This function generate linker scripts in /usr/lib for dynamic |
36 |
+# libs in /lib. This is to fix linking problems when you have |
37 |
+# the .so in /lib, and the .a in /usr/lib. What happens is that |
38 |
+# in some cases when linking dynamic, the .a in /usr/lib is used |
39 |
+# instead of the .so in /lib due to gcc/libtool tweaking ld's |
40 |
+# library search path. This causes many builds to fail. |
41 |
+# See bug #4411 for more info. |
42 |
+# |
43 |
+# Note that you should in general use the unversioned name of |
44 |
+# the library (libfoo.so), as ldconfig should usually update it |
45 |
+# correctly to point to the latest version of the library present. |
46 |
+gen_usr_ldscript() { |
47 |
+ local lib libdir=$(get_libdir) output_format="" auto=false suffix=$(get_libname) |
48 |
+ [[ -z ${ED+set} ]] && local ED=${D%/}${EPREFIX}/ |
49 |
+ |
50 |
+ tc-is-static-only && return |
51 |
+ |
52 |
+ # We only care about stuffing / for the native ABI. #479448 |
53 |
+ if [[ $(type -t multilib_is_native_abi) == "function" ]] ; then |
54 |
+ multilib_is_native_abi || return 0 |
55 |
+ fi |
56 |
+ |
57 |
+ # Eventually we'd like to get rid of this func completely #417451 |
58 |
+ case ${CTARGET:-${CHOST}} in |
59 |
+ *-darwin*) ;; |
60 |
+ *-android*) return 0 ;; |
61 |
+ *linux*|*-freebsd*|*-openbsd*|*-netbsd*) |
62 |
+ use prefix && return 0 ;; |
63 |
+ *) return 0 ;; |
64 |
+ esac |
65 |
+ |
66 |
+ # Just make sure it exists |
67 |
+ dodir /usr/${libdir} |
68 |
+ |
69 |
+ if [[ $1 == "-a" ]] ; then |
70 |
+ auto=true |
71 |
+ shift |
72 |
+ dodir /${libdir} |
73 |
+ fi |
74 |
+ |
75 |
+ # OUTPUT_FORMAT gives hints to the linker as to what binary format |
76 |
+ # is referenced ... makes multilib saner |
77 |
+ local flags=( ${CFLAGS} ${LDFLAGS} -Wl,--verbose ) |
78 |
+ if $(tc-getLD) --version | grep -q 'GNU gold' ; then |
79 |
+ # If they're using gold, manually invoke the old bfd. #487696 |
80 |
+ local d="${T}/bfd-linker" |
81 |
+ mkdir -p "${d}" |
82 |
+ ln -sf $(which ${CHOST}-ld.bfd) "${d}"/ld |
83 |
+ flags+=( -B"${d}" ) |
84 |
+ fi |
85 |
+ output_format=$($(tc-getCC) "${flags[@]}" 2>&1 | sed -n 's/^OUTPUT_FORMAT("\([^"]*\)",.*/\1/p') |
86 |
+ [[ -n ${output_format} ]] && output_format="OUTPUT_FORMAT ( ${output_format} )" |
87 |
+ |
88 |
+ for lib in "$@" ; do |
89 |
+ local tlib |
90 |
+ if ${auto} ; then |
91 |
+ lib="lib${lib}${suffix}" |
92 |
+ else |
93 |
+ # Ensure /lib/${lib} exists to avoid dangling scripts/symlinks. |
94 |
+ # This especially is for AIX where $(get_libname) can return ".a", |
95 |
+ # so /lib/${lib} might be moved to /usr/lib/${lib} (by accident). |
96 |
+ [[ -r ${ED}/${libdir}/${lib} ]] || continue |
97 |
+ #TODO: better die here? |
98 |
+ fi |
99 |
+ |
100 |
+ case ${CTARGET:-${CHOST}} in |
101 |
+ *-darwin*) |
102 |
+ if ${auto} ; then |
103 |
+ tlib=$(scanmacho -qF'%S#F' "${ED}"/usr/${libdir}/${lib}) |
104 |
+ else |
105 |
+ tlib=$(scanmacho -qF'%S#F' "${ED}"/${libdir}/${lib}) |
106 |
+ fi |
107 |
+ [[ -z ${tlib} ]] && die "unable to read install_name from ${lib}" |
108 |
+ tlib=${tlib##*/} |
109 |
+ |
110 |
+ if ${auto} ; then |
111 |
+ mv "${ED}"/usr/${libdir}/${lib%${suffix}}.*${suffix#.} "${ED}"/${libdir}/ || die |
112 |
+ # some install_names are funky: they encode a version |
113 |
+ if [[ ${tlib} != ${lib%${suffix}}.*${suffix#.} ]] ; then |
114 |
+ mv "${ED}"/usr/${libdir}/${tlib%${suffix}}.*${suffix#.} "${ED}"/${libdir}/ || die |
115 |
+ fi |
116 |
+ rm -f "${ED}"/${libdir}/${lib} |
117 |
+ fi |
118 |
+ |
119 |
+ # Mach-O files have an id, which is like a soname, it tells how |
120 |
+ # another object linking against this lib should reference it. |
121 |
+ # Since we moved the lib from usr/lib into lib this reference is |
122 |
+ # wrong. Hence, we update it here. We don't configure with |
123 |
+ # libdir=/lib because that messes up libtool files. |
124 |
+ # Make sure we don't lose the specific version, so just modify the |
125 |
+ # existing install_name |
126 |
+ if [[ ! -w "${ED}/${libdir}/${tlib}" ]] ; then |
127 |
+ chmod u+w "${ED}${libdir}/${tlib}" # needed to write to it |
128 |
+ local nowrite=yes |
129 |
+ fi |
130 |
+ install_name_tool \ |
131 |
+ -id "${EPREFIX}"/${libdir}/${tlib} \ |
132 |
+ "${ED}"/${libdir}/${tlib} || die "install_name_tool failed" |
133 |
+ [[ -n ${nowrite} ]] && chmod u-w "${ED}${libdir}/${tlib}" |
134 |
+ # Now as we don't use GNU binutils and our linker doesn't |
135 |
+ # understand linker scripts, just create a symlink. |
136 |
+ pushd "${ED}/usr/${libdir}" > /dev/null |
137 |
+ ln -snf "../../${libdir}/${tlib}" "${lib}" |
138 |
+ popd > /dev/null |
139 |
+ ;; |
140 |
+ *) |
141 |
+ if ${auto} ; then |
142 |
+ tlib=$(scanelf -qF'%S#F' "${ED}"/usr/${libdir}/${lib}) |
143 |
+ [[ -z ${tlib} ]] && die "unable to read SONAME from ${lib}" |
144 |
+ mv "${ED}"/usr/${libdir}/${lib}* "${ED}"/${libdir}/ || die |
145 |
+ # some SONAMEs are funky: they encode a version before the .so |
146 |
+ if [[ ${tlib} != ${lib}* ]] ; then |
147 |
+ mv "${ED}"/usr/${libdir}/${tlib}* "${ED}"/${libdir}/ || die |
148 |
+ fi |
149 |
+ rm -f "${ED}"/${libdir}/${lib} |
150 |
+ else |
151 |
+ tlib=${lib} |
152 |
+ fi |
153 |
+ cat > "${ED}/usr/${libdir}/${lib}" <<-END_LDSCRIPT |
154 |
+ /* GNU ld script |
155 |
+ Since Gentoo has critical dynamic libraries in /lib, and the static versions |
156 |
+ in /usr/lib, we need to have a "fake" dynamic lib in /usr/lib, otherwise we |
157 |
+ run into linking problems. This "fake" dynamic lib is a linker script that |
158 |
+ redirects the linker to the real lib. And yes, this works in the cross- |
159 |
+ compiling scenario as the sysroot-ed linker will prepend the real path. |
160 |
+ |
161 |
+ See bug https://bugs.gentoo.org/4411 for more info. |
162 |
+ */ |
163 |
+ ${output_format} |
164 |
+ GROUP ( ${EPREFIX}/${libdir}/${tlib} ) |
165 |
+ END_LDSCRIPT |
166 |
+ ;; |
167 |
+ esac |
168 |
+ fperms a+x "/usr/${libdir}/${lib}" || die "could not change perms on ${lib}" |
169 |
+ done |
170 |
+} |
171 |
+ |
172 |
+fi # _USR_LDSCRIPT_ECLASS |
173 |
-- |
174 |
2.22.0 |