1 |
Author: haubi |
2 |
Date: 2008-02-04 21:42:40 +0000 (Mon, 04 Feb 2008) |
3 |
New Revision: 1602 |
4 |
|
5 |
Added: |
6 |
trunk/toolchain-prefix-wrapper/ld/binutils-config.h |
7 |
Modified: |
8 |
trunk/toolchain-prefix-wrapper/binutils-config.in |
9 |
trunk/toolchain-prefix-wrapper/ld/Makefile.am |
10 |
trunk/toolchain-prefix-wrapper/ld/ldplugin.h |
11 |
trunk/toolchain-prefix-wrapper/ld/ldwrapper.c |
12 |
Log: |
13 |
during binutils-config for native ld, ld-wrapper is configured using env-vars |
14 |
to use the new binutils without etc/env.d/ configfile, because this is |
15 |
invalid in case that version might have just been unmerged. |
16 |
|
17 |
|
18 |
Modified: trunk/toolchain-prefix-wrapper/binutils-config.in |
19 |
=================================================================== |
20 |
--- trunk/toolchain-prefix-wrapper/binutils-config.in 2008-02-04 17:56:28 UTC (rev 1601) |
21 |
+++ trunk/toolchain-prefix-wrapper/binutils-config.in 2008-02-04 21:42:40 UTC (rev 1602) |
22 |
@@ -125,53 +125,40 @@ |
23 |
# the target in the cp that follows |
24 |
local oldumask=$(umask) |
25 |
umask 077 |
26 |
- local ctargetfile="${TMPDIR:-${BPREFIX}/tmp}"/ctarget-$$.c |
27 |
- rm -f "${ctargetfile}" |
28 |
+ local ctargetstem="${TMPDIR:-${BPREFIX}/tmp}"/binutils-config-ctarget-$$ |
29 |
+ local plugins= |
30 |
+ if [[ ${TARGET} != ${HOST} ]]; then |
31 |
+ # cross linker |
32 |
+ plugins="${plugins}${plugins:+,}gnu" |
33 |
+ # allow debugging any plugin |
34 |
+ [[ -z ${LDPLUGINS} ]] || plugins=${LDPLUGINS} |
35 |
+ else |
36 |
+ case ${TARGET} in |
37 |
+ *-darwin*) plugins="${plugins}${plugins:+,}darwin" ;; |
38 |
+ *-aix*) plugins="${plugins}${plugins:+,}aix" ;; |
39 |
+ *-hpux*) plugins="${plugins}${plugins:+,}hpux" ;; |
40 |
+ *-linux* | *-solaris*) plugins="${plugins}${plugins:+,}gnu" ;; |
41 |
+ *) eerror "unknown platform ${CTARGET}" |
42 |
+ exit 1 |
43 |
+ ;; |
44 |
+ esac |
45 |
+ fi |
46 |
+ rm -f "${ctargetstem}".* |
47 |
( |
48 |
- plugins= |
49 |
- echo "#include <ldplugin.h>" |
50 |
- echo "char const *CTARGET=\"${TARGET}\";" |
51 |
- if [[ ${TARGET} != ${HOST} ]]; then |
52 |
- # cross linker |
53 |
- plugins="${plugins} gnu" |
54 |
- # allow debugging any plugin |
55 |
- [[ -z ${LDPLUGINS} ]] || plugins=${LDPLUGINS} |
56 |
- else |
57 |
- local ldversion=$("${EROOT}${BINPATH}/${x}" --version 2>/dev/null) |
58 |
- if [[ $? -eq 0 && ${ldversion} == *GNU* ]]; then |
59 |
- plugins="${plugins} gnu" |
60 |
- else |
61 |
- case ${TARGET} in |
62 |
- *-darwin*) plugins="${plugins} darwin" ;; |
63 |
- *-aix*) plugins="${plugins} aix" ;; |
64 |
- *-hpux*) plugins="${plugins} hpux" ;; |
65 |
- *-linux* | *-solaris*) plugins="${plugins} gnu" ;; |
66 |
- *) eerror "unknown platform ${CTARGET}" |
67 |
- exit 1 |
68 |
- ;; |
69 |
- esac |
70 |
- fi |
71 |
- fi |
72 |
- for plugin in ${plugins}; do |
73 |
- echo "#include <${plugin}plugin.h>" |
74 |
- done |
75 |
- echo "LdPluginFct const* LDPLUGINS() {" |
76 |
- echo " static const LdPluginFct plugins[] = {" |
77 |
- for plugin in ${plugins}; do |
78 |
- echo " ${plugin}plugin," |
79 |
- done |
80 |
- echo " 0 };" |
81 |
- echo " return plugins; };" |
82 |
- echo -n "int DEBUG(void) { return " |
83 |
- [[ ${DEBUG} == yes ]] && echo "1; }" || echo "0; }" |
84 |
- ) > "${ctargetfile}" || return 1 |
85 |
+ echo "#include <binutils-config.h>" |
86 |
+ echo "char const *CTARGET(void) { return \"${TARGET}\"; }" |
87 |
+ echo "char const* LDPLUGINS() { return \"${plugins}\"; }" |
88 |
+ [[ ${DEBUG} == yes ]] \ |
89 |
+ && echo "int DEBUG(void) { return 1; }" \ |
90 |
+ || echo "int DEBUG(void) { return 0; }" |
91 |
+ ) > "${ctargetstem}".c || return 1 |
92 |
umask ${oldumask} || return 1 |
93 |
+ set_BUILD |
94 |
local cc=$(type -p "${CC}") |
95 |
- [[ -z ${cc} ]] && set_BUILD |
96 |
- [[ -z ${cc} ]] && [[ ${HOST} == ${BUILD} ]] && cc=$(type -p "${BUILD_CC}") |
97 |
[[ -z ${cc} ]] && cc=$(type -p "${HOST}-gcc") |
98 |
[[ -z ${cc} ]] && cc=$(type -p "${HOST}-cc") |
99 |
- if [[ -z ${cc} && ${HOST} == ${BUILD} ]]; then |
100 |
+ if [[ ${HOST} == ${BUILD} ]]; then |
101 |
+ [[ -z ${cc} ]] && cc=$(type -p "${BUILD_CC}") |
102 |
[[ -z ${cc} ]] && cc=$(type -p gcc) |
103 |
[[ -z ${cc} ]] && cc=$(type -p cc) |
104 |
fi |
105 |
@@ -179,15 +166,19 @@ |
106 |
echo -n "Cannot find compiler for ${HOST} (try setting CC)" |
107 |
return 1 |
108 |
fi |
109 |
- rm -f "${EROOT}${BINPATH_LINKS}/${x}.new" > /dev/null || return 1 |
110 |
- if [[ -z ${ROOT%/} && ${TARGET} == ${HOST} ]]; then |
111 |
- # allow current ld-wrapper find the new ld, |
112 |
- # since the old one may be unmerged already. |
113 |
- export PATH="${EPREFIX}/${BINPATH}:${PATH}" |
114 |
+ |
115 |
+ if [[ -z ${ROOT%/} && ${TARGET} == ${HOST} && ${EPREFIX} == ${BPREFIX} ]]; then |
116 |
+ # builtin ld-wrapper config may be out-of-date, |
117 |
+ # so configure it by environment. |
118 |
+ export BINUTILS_CONFIG_LD="${EPREFIX}/${BINPATH}/${x}" |
119 |
+ export BINUTILS_CONFIG_LDTARGET="${HOST}" |
120 |
+ export BINUTILS_CONFIG_LDPLUGINS="${plugins}" |
121 |
fi |
122 |
- "${cc}" -o "${EROOT}${BINPATH_LINKS}/${x}.new" "${ctargetfile}" \ |
123 |
- "-I${wrapper}" "${wrapper}/libbinutils-config.a" ${CFLAGS} || return 1 |
124 |
- [[ ${DEBUG} == yes ]] || rm -f "${ctargetfile}" || return 1 |
125 |
+ rm -f "${EROOT}${BINPATH_LINKS}/${x}.new" > /dev/null || return 1 |
126 |
+ "${cc}" ${CFLAGS} -o "${EROOT}${BINPATH_LINKS}/${x}.new" \ |
127 |
+ "${ctargetstem}".c "-I${wrapper}" \ |
128 |
+ "${wrapper}/libbinutils-config.a" || return 1 |
129 |
+ [[ ${DEBUG} == yes ]] || rm -f "${ctargetstem}".* || return 1 |
130 |
mv -f "${EROOT}${BINPATH_LINKS}/${x}"{.new,} || return 1 |
131 |
touch -r "${EROOT}/${BINPATH}/${x}" "${EROOT}${BINPATH_LINKS}/${x}" || return 1 |
132 |
;; |
133 |
|
134 |
Modified: trunk/toolchain-prefix-wrapper/ld/Makefile.am |
135 |
=================================================================== |
136 |
--- trunk/toolchain-prefix-wrapper/ld/Makefile.am 2008-02-04 17:56:28 UTC (rev 1601) |
137 |
+++ trunk/toolchain-prefix-wrapper/ld/Makefile.am 2008-02-04 21:42:40 UTC (rev 1602) |
138 |
@@ -7,6 +7,7 @@ |
139 |
libmisc_LIBRARIES = libbinutils-config.a |
140 |
libbinutils_config_a_SOURCES = ldwrapper.c |
141 |
|
142 |
+libbinutils_config_a_SOURCES += ldplugin.h binutils-config.h |
143 |
libbinutils_config_a_SOURCES += darwinplugin.c darwinplugin.h |
144 |
libbinutils_config_a_SOURCES += aixplugin.c aixplugin.h |
145 |
libbinutils_config_a_SOURCES += hpuxplugin.c hpuxplugin.h |
146 |
@@ -16,13 +17,7 @@ |
147 |
libbinutils_config_a_SOURCES += $(top_srcdir)/utils/textfile.c |
148 |
libbinutils_config_a_SOURCES += $(top_srcdir)/utils/textfile.h |
149 |
|
150 |
-libmisc_HEADERS = ldplugin.h |
151 |
-libmisc_HEADERS += darwinplugin.h |
152 |
-libmisc_HEADERS += aixplugin.h |
153 |
-libmisc_HEADERS += hpuxplugin.h |
154 |
-libmisc_HEADERS += gnuplugin.h |
155 |
-libmisc_HEADERS += $(top_srcdir)/utils/stringutil.h |
156 |
-libmisc_HEADERS += $(top_srcdir)/utils/textfile.h |
157 |
+libmisc_HEADERS = binutils-config.h |
158 |
|
159 |
libbinutils_config_a_CPPFLAGS = -I$(top_srcdir)/utils |
160 |
|
161 |
|
162 |
Copied: trunk/toolchain-prefix-wrapper/ld/binutils-config.h (from rev 1598, trunk/toolchain-prefix-wrapper/ld/ldplugin.h) |
163 |
=================================================================== |
164 |
--- trunk/toolchain-prefix-wrapper/ld/binutils-config.h (rev 0) |
165 |
+++ trunk/toolchain-prefix-wrapper/ld/binutils-config.h 2008-02-04 21:42:40 UTC (rev 1602) |
166 |
@@ -0,0 +1,15 @@ |
167 |
+/* |
168 |
+ * Copyright 2008 Gentoo Foundation |
169 |
+ * Distributed under the terms of the GNU General Public License v2 |
170 |
+ * Authors: Michael Haubenwallner <haubi@g.o> |
171 |
+ */ |
172 |
+ |
173 |
+#ifndef _BINUTILS_CONFIG_H_ |
174 |
+#define _BINUTILS_CONFIG_H_ |
175 |
+ |
176 |
+/* return comma separated list of plugin names to be called */ |
177 |
+extern char const* CTARGET(void); |
178 |
+extern char const* LDPLUGINS(void); |
179 |
+extern int DEBUG(void); |
180 |
+ |
181 |
+#endif /* _BINUTILS_CONFIG_H_ */ |
182 |
|
183 |
Modified: trunk/toolchain-prefix-wrapper/ld/ldplugin.h |
184 |
=================================================================== |
185 |
--- trunk/toolchain-prefix-wrapper/ld/ldplugin.h 2008-02-04 17:56:28 UTC (rev 1601) |
186 |
+++ trunk/toolchain-prefix-wrapper/ld/ldplugin.h 2008-02-04 21:42:40 UTC (rev 1602) |
187 |
@@ -31,8 +31,4 @@ |
188 |
LdPluginOut* out; |
189 |
}; |
190 |
|
191 |
-extern LdPluginFct const* LDPLUGINS(); |
192 |
- |
193 |
-extern int DEBUG(void); |
194 |
- |
195 |
#endif /* _LDPLUGIN_H_ */ |
196 |
|
197 |
Modified: trunk/toolchain-prefix-wrapper/ld/ldwrapper.c |
198 |
=================================================================== |
199 |
--- trunk/toolchain-prefix-wrapper/ld/ldwrapper.c 2008-02-04 17:56:28 UTC (rev 1601) |
200 |
+++ trunk/toolchain-prefix-wrapper/ld/ldwrapper.c 2008-02-04 21:42:40 UTC (rev 1602) |
201 |
@@ -12,7 +12,12 @@ |
202 |
#include <stringutil.h> |
203 |
#include <textfile.h> |
204 |
|
205 |
+#include "binutils-config.h" |
206 |
#include "ldplugin.h" |
207 |
+#include "aixplugin.h" |
208 |
+#include "gnuplugin.h" |
209 |
+#include "hpuxplugin.h" |
210 |
+#include "darwinplugin.h" |
211 |
|
212 |
#define _REENTRANT |
213 |
#if !defined(_GNU_SOURCE) |
214 |
@@ -38,8 +43,6 @@ |
215 |
|
216 |
#define dprintf DEBUG() && fprintf |
217 |
|
218 |
-extern const char* CTARGET; |
219 |
- |
220 |
typedef struct _GccConfig { |
221 |
String* version; |
222 |
StringList* ldpath; |
223 |
@@ -442,6 +445,20 @@ |
224 |
FILE *inpipe = NULL; |
225 |
String* binpath_command; |
226 |
char str[MAXPATHLEN + 1]; |
227 |
+ char const* env = getenv("BINUTILS_CONFIG_LD"); |
228 |
+ |
229 |
+ if (env != NULL && *env != '\0') { |
230 |
+ /* as we do linking during binutils-config, |
231 |
+ * we need some working ld-wrapper for gcc, |
232 |
+ * but the old one may be configured for the now unmerged ld. |
233 |
+ */ |
234 |
+ data->bin = StringCreateConcat(env, -1, NULL); |
235 |
+ if (data->bin == NULL) { |
236 |
+ wrapper_exit("%s wrapper: %s\n", |
237 |
+ StringGetBuffer(data->name), strerror(errno)); |
238 |
+ } |
239 |
+ return; |
240 |
+ } |
241 |
|
242 |
setup_ctarget_binutilsbin(data); |
243 |
|
244 |
@@ -732,7 +749,7 @@ |
245 |
{ NULL, -1 }, |
246 |
}; |
247 |
struct libdir const * l = libdirs; |
248 |
- if (!data->isCrossTriplet && StringGetLength(data->root) == 0) { |
249 |
+ if (data->isCrossTriplet || StringGetLength(data->root) == 0) { |
250 |
return; |
251 |
} |
252 |
while(l->path != NULL) { |
253 |
@@ -745,41 +762,87 @@ |
254 |
} |
255 |
} |
256 |
|
257 |
-static void callPlugins(LdWrapperData* data, LdPluginFct const* plugins) |
258 |
+static void callPlugin(LdWrapperData* data, LdPluginFct plugins) |
259 |
{ |
260 |
LdPluginData pluginData = {0}; |
261 |
LdPluginOut pluginOut = {0}; |
262 |
|
263 |
- if (plugins == NULL) { |
264 |
- return; |
265 |
+ pluginData.in = &data->pluginIn; |
266 |
+ pluginData.out = &pluginOut; |
267 |
+ pluginData.plugin = *plugins; |
268 |
+ |
269 |
+ /* keep argv[0] */ |
270 |
+ pluginData.out->argList = StringListCreate(pluginData.in->argList, 0, 1); |
271 |
+ if (pluginData.out->argList == NULL) { |
272 |
+ wrapper_exit("%s wrapper: %s\n", |
273 |
+ StringGetBuffer(data->name), strerror(errno)); |
274 |
} |
275 |
|
276 |
- while(*plugins != NULL) { |
277 |
- pluginData.in = &data->pluginIn; |
278 |
- pluginData.out = &pluginOut; |
279 |
- pluginData.plugin = *plugins; |
280 |
- |
281 |
- /* keep argv[0] */ |
282 |
- pluginData.out->argList = StringListCreate(pluginData.in->argList, 0, 1); |
283 |
- if (pluginData.out->argList == NULL) { |
284 |
- wrapper_exit("%s wrapper: %s\n", |
285 |
+ if ((*plugins)(&pluginData) < 0) { |
286 |
+ if (pluginData.out->diagnostics == NULL) { |
287 |
+ wrapper_exit("%s wrapper: %s: %s\n", |
288 |
+ StringGetBuffer(data->name), pluginData.out->diagnostics, strerror(errno)); |
289 |
+ } else { |
290 |
+ wrapper_exit("%s wrapper could not run plugin: %s\n", |
291 |
StringGetBuffer(data->name), strerror(errno)); |
292 |
} |
293 |
+ } |
294 |
+ if (pluginOut.argList != NULL) { |
295 |
+ StringListDestroy(data->pluginIn.argList); |
296 |
+ data->pluginIn.argList = pluginOut.argList; |
297 |
+ } |
298 |
+} |
299 |
|
300 |
- if ((*plugins)(&pluginData) < 0) { |
301 |
- if (pluginData.out->diagnostics == NULL) { |
302 |
- wrapper_exit("%s wrapper: %s: %s\n", |
303 |
- StringGetBuffer(data->name), pluginData.out->diagnostics, strerror(errno)); |
304 |
- } else { |
305 |
- wrapper_exit("%s wrapper could not run plugin: %s\n", |
306 |
- StringGetBuffer(data->name), strerror(errno)); |
307 |
- } |
308 |
+typedef struct _KnownPlugin { |
309 |
+ int namelen; |
310 |
+ char const *name; |
311 |
+ LdPluginFct plugin; |
312 |
+} KnownPlugin; |
313 |
+ |
314 |
+static int compareKnownPluginName(void const *v1, void const *v2) |
315 |
+{ |
316 |
+ KnownPlugin const* p1 = (KnownPlugin const*)v1; |
317 |
+ KnownPlugin const* p2 = (KnownPlugin const*)v2; |
318 |
+ int rv; |
319 |
+ rv = p1->namelen - p2->namelen; |
320 |
+ if (rv) return rv; |
321 |
+ return strncmp(p1->name, p2->name, p1->namelen); |
322 |
+} |
323 |
+ |
324 |
+/* call the plugins from comma-separated list of plugin-names */ |
325 |
+static void callPlugins(LdWrapperData* data, char const* plugins) |
326 |
+{ |
327 |
+ char const *end; |
328 |
+ static KnownPlugin const knownPlugins[] = { |
329 |
+ /* keep sorted on namelen,name */ |
330 |
+ { 3, "aix", aixplugin }, |
331 |
+ { 3, "gnu", gnuplugin }, |
332 |
+ { 4, "hpux", hpuxplugin }, |
333 |
+ { 6, "darwin", darwinplugin }, |
334 |
+ }; |
335 |
+ KnownPlugin search; |
336 |
+ KnownPlugin *found; |
337 |
+ |
338 |
+ if (plugins == NULL) { |
339 |
+ return; |
340 |
+ } |
341 |
+ |
342 |
+ while(plugins != NULL && *plugins != '\0') { |
343 |
+ end = strchr(plugins, ','); |
344 |
+ if (end == NULL) { |
345 |
+ end = plugins + strlen(plugins); |
346 |
} |
347 |
- if (pluginOut.argList != NULL) { |
348 |
- StringListDestroy(data->pluginIn.argList); |
349 |
- data->pluginIn.argList = pluginOut.argList; |
350 |
+ search.name = plugins; |
351 |
+ search.namelen = end - plugins; |
352 |
+ found = bsearch(&search, knownPlugins, |
353 |
+ sizeof(knownPlugins) / sizeof(knownPlugins[0]), |
354 |
+ sizeof(knownPlugins[0]), |
355 |
+ compareKnownPluginName); |
356 |
+ if (found != NULL) { |
357 |
+ callPlugin(data, found->plugin); |
358 |
} |
359 |
- plugins++; |
360 |
+ while (*end == ',') end++; |
361 |
+ plugins = end; |
362 |
} |
363 |
|
364 |
return; |
365 |
@@ -794,7 +857,6 @@ |
366 |
char **newargv = argv; |
367 |
char const *found; |
368 |
char const *tmp; |
369 |
- LdPluginFct builtinPlugins[] = { filterSysLibpath, NULL }; |
370 |
|
371 |
memset(&data, 0, sizeof(data)); |
372 |
|
373 |
@@ -881,12 +943,25 @@ |
374 |
StringGetBuffer(data.name), strerror(errno)); |
375 |
} |
376 |
|
377 |
- data.target.triplet = StringCreateConcat(CTARGET, -1, NULL); |
378 |
+ found = getenv("BINUTILS_CONFIG_LDTARGET"); |
379 |
+ if (found == NULL) { |
380 |
+ found = CTARGET(); |
381 |
+ } |
382 |
+ data.target.triplet = StringCreateConcat(found, -1, NULL); |
383 |
if (data.target.triplet == NULL) { |
384 |
wrapper_exit("%s wrapper: %s\n", |
385 |
StringGetBuffer(data.name), strerror(errno)); |
386 |
} |
387 |
|
388 |
+ dprintf(stderr, "%s wrapper: chost '%s'\n", |
389 |
+ StringGetBuffer(data.name), StringGetBuffer(data.host.triplet)); |
390 |
+ dprintf(stderr, "%s wrapper: ctarget '%s'\n", |
391 |
+ StringGetBuffer(data.name), StringGetBuffer(data.target.triplet)); |
392 |
+ dprintf(stderr, "%s wrapper: host eprefix '%s'\n", |
393 |
+ StringGetBuffer(data.name), StringGetBuffer(data.host.eprefix)); |
394 |
+ dprintf(stderr, "%s wrapper: target eprefix '%s'\n", |
395 |
+ StringGetBuffer(data.name), StringGetBuffer(data.target.eprefix)); |
396 |
+ |
397 |
data.isCrossTriplet = StringIsEqualString(data.host.triplet, data.target.triplet) ? 0 : 1; |
398 |
|
399 |
find_wrapper_binutils(&data); |
400 |
@@ -965,10 +1040,14 @@ |
401 |
add_host_system_libdirs(&data); |
402 |
|
403 |
/* filter out sys libpath's passed with "-L" */ |
404 |
- callPlugins(&data, builtinPlugins); |
405 |
+ callPlugin(&data, filterSysLibpath); |
406 |
|
407 |
+ found = getenv("BINUTILS_CONFIG_LDPLUGINS"); |
408 |
+ if (found == NULL) { |
409 |
+ found = LDPLUGINS(); |
410 |
+ } |
411 |
/* call the target specific plugin */ |
412 |
- callPlugins(&data, LDPLUGINS()); |
413 |
+ callPlugins(&data, found); |
414 |
|
415 |
newargv = StringListToArgv(data.pluginIn.argList); |
416 |
if (newargv == NULL) { |
417 |
|
418 |
-- |
419 |
gentoo-commits@l.g.o mailing list |