/[gentoo-alt]/trunk/toolchain-prefix-wrapper/ld/hpuxplugin.c
Gentoo

Contents of /trunk/toolchain-prefix-wrapper/ld/hpuxplugin.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1631 - (show annotations) (download) (as text)
Fri May 9 09:17:44 2008 UTC (6 years, 4 months ago) by haubi
File MIME type: text/x-csrc
File size: 6252 byte(s)
no need to parse -L args in plugin any more.
don't forget to add '+s' on proper place if initially given.
1 /*
2 * Copyright 2007 Gentoo Foundation
3 * Distributed under the terms of the GNU General Public License v2
4 * Author: Michael Haubenwallner <haubi@gentoo.org>
5 */
6
7 #include <config.h>
8
9 #include "hpuxplugin.h"
10
11 #include <stdlib.h>
12 #include <string.h>
13
14 #if defined(__cplusplus)
15 extern "C" {
16 #else
17 typedef enum { false = 0, true = 1 } bool;
18 #endif
19
20 typedef enum { envrunpath_no = 0, envrunpath_first = 1, envrunpath_second = 2 } envrunpath_t;
21
22 /* HPUX-ld:
23 * When there is no explicit runpath on the linker commandline (+b runpath),
24 * then all library paths (-L) are recorded as runpath
25 */
26 int hpuxplugin(LdPluginData *data)
27 {
28 int argc = 0;
29 int err;
30
31 bool withDefaultRunpath = true; /* +nodefaultrpath */
32 envrunpath_t withEnvRunpath = envrunpath_no; /* +s */
33
34 StringList *tmpArgList = NULL;
35 StringList *runpathList = NULL;
36 StringList *defaultRunpathList = NULL;
37 String *newString = NULL;
38 String const *argString;
39 char const *argBuffer;
40 int argBufferLength;
41
42 do { /* dummy loop */
43 err = -1;
44
45 tmpArgList = StringListCreate(NULL, 0, 0);
46 if (tmpArgList == NULL)
47 break;
48
49 runpathList = StringListCreate(NULL, 0, 0);
50 if (runpathList == NULL)
51 break;
52
53 defaultRunpathList = StringListCreate(NULL, 0, 0);
54 if (defaultRunpathList == NULL)
55 break;
56
57 for(argc = 1; argc < StringListGetSize(data->in->argList); argc++) {
58 argString = StringListGetString(data->in->argList, argc);
59 argBuffer = StringGetBuffer(argString);
60 argBufferLength = StringGetLength(argString);
61
62 if (strcmp(argBuffer, "+s") == 0) {
63 if (StringListGetSize(runpathList) == 0)
64 withEnvRunpath = envrunpath_first;
65 else
66 withEnvRunpath = envrunpath_second;
67 continue;
68 } else
69 if (strcmp(argBuffer, "+nodefaultrpath") == 0) {
70 withDefaultRunpath = false;
71 continue;
72 #if defined(__ia64)
73 } else
74 if (strcmp(argBuffer, "+defaultrpath") == 0) {
75 withDefaultRunpath = true;
76 continue;
77 #endif
78 } else
79 if (strncmp(argBuffer, "+b", 2) == 0) {
80 /* collect runpath from "+b runpath1:runpathN" */
81 char const *curr, *next;
82
83 argBuffer += 2;
84 argBufferLength -= 2;
85
86 if (*argBuffer == 0 && argc < StringListGetSize(data->in->argList)) {
87 argc++;
88 argString = StringListGetString(data->in->argList, argc);
89 argBuffer = StringGetBuffer(argString);
90 argBufferLength = StringGetLength(argString);
91 }
92
93 for(curr = next = argBuffer; *next != '\0'; curr = next+1) {
94 for(next = curr; *next != '\0' && *next != ':'; next++);
95
96 if (next - curr <= 1) {
97 /* skip empty path */
98 continue;
99 }
100
101 if (StringListContains(data->in->sysLibpath, curr, next - curr)) {
102 /* sys runpath will be added later */
103 continue;
104 }
105
106 if (StringListContains(runpathList, curr, next - curr)) {
107 /* already recorded user runpath */
108 continue;
109 }
110
111 /* record this path into libpath list */
112 if (StringListAppendConcat(runpathList, curr, next - curr, NULL) < 0)
113 break;
114 }
115
116 /* end "+b" handling */
117 continue;
118 } else
119 if (strncmp(argBuffer, "-L", 2) == 0) {
120 /* drop -L arguments from commandline,
121 * we need to pass them before any libs.
122 * The path list already is collected in userLibpath.
123 */
124 continue;
125 } else
126 if (strncmp(argBuffer, "-R", 2) == 0) {
127 /* extension:
128 * collect additional default runpath from "-R runpath"
129 */
130
131 argBuffer += 2;
132 argBufferLength -= 2;
133
134 if (*argBuffer == 0 && argc < StringListGetSize(data->in->argList)) {
135 argc++;
136 argString = StringListGetString(data->in->argList, argc);
137 argBuffer = StringGetBuffer(argString);
138 argBufferLength = StringGetLength(argString);
139 }
140 if (StringListContains(data->in->sysLibpath, argBuffer, argBufferLength))
141 continue;
142
143 if (StringListAppendConcat(defaultRunpathList, argBuffer, argBufferLength, NULL) < 0)
144 break;
145
146 continue;
147 }
148
149 /* keep other arguments on commandline */
150 if (StringListAppendString(tmpArgList, argString) < 0)
151 break;
152 }
153 if (argc < StringListGetSize(data->in->argList)) {
154 /* error during argument parsing */
155 break;
156 }
157
158 /*
159 * first, put libpath list (-L) on the commandline
160 */
161 if (StringListAppendListModify(data->out->argList, data->in->userLibpath, 0, -1, "-L", 2, NULL, 0) < 0)
162 break;
163
164 /* also put sys libpath list as libpath (-L) on commandline */
165 if (StringListAppendListModify(data->out->argList, data->in->sysLibpath, 0, -1, "-L", 2, NULL, 0) < 0)
166 break;
167
168 /* do we need to use env-runpath first? */
169 if (withEnvRunpath == envrunpath_first
170 && StringListAppendConcat(data->out->argList, "+s", 2, NULL) < 0
171 ) break;
172
173 /*
174 * now put runpath list (from -R, +b) on the commandline
175 */
176
177 /* append "+b" to commandline */
178 if (StringListAppendConcat(data->out->argList, "+b", 2, NULL) < 0)
179 break;
180
181 /* if there is no runpath (+b), use libpath as runpath
182 * if not disabled with "+nodefaultrpath"
183 */
184 if (StringListGetSize(runpathList) == 0
185 && withDefaultRunpath == true
186 && StringListAppendList(runpathList, data->in->userLibpath, 0, -1) < 0
187 ) break;
188
189 /* append default runpath list (-R) to runpath list */
190 if (StringListAppendList(runpathList, defaultRunpathList, 0, -1) < 0)
191 break;
192
193 /* append sys libpath list to runpath list */
194 if (StringListAppendList(runpathList, data->in->sysRunpath, 0, -1) < 0)
195 break;
196
197 /* create runpath string: runpath1:runpathN */
198 newString = StringListJoin(runpathList, NULL, 0, ":", 1, NULL, 0);
199 if (newString == NULL)
200 break;
201
202 /* append runpath string to commandline */
203 if (StringListAppendString(data->out->argList, newString) < 0)
204 break;
205
206 /* do we need to use env-runpath second? */
207 if (withEnvRunpath == envrunpath_second
208 && StringListAppendConcat(data->out->argList, "+s", 2, NULL) < 0
209 ) break;
210
211 /*
212 * third, put other arguments on commandline
213 */
214 if (StringListAppendList(data->out->argList, tmpArgList, 0, -1) < 0)
215 break;
216
217 err = 0;
218 } while(0); /* end dummy loop */
219
220 newString = StringDestroy(newString);
221 defaultRunpathList = StringListDestroy(defaultRunpathList);
222 runpathList = StringListDestroy(runpathList);
223 tmpArgList = StringListDestroy(tmpArgList);
224
225 return err;
226 }
227
228 #if defined(__cplusplus)
229 }
230 #endif

Properties

Name Value
svn:executable

  ViewVC Help
Powered by ViewVC 1.1.20