/[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 1591 - (show annotations) (download) (as text)
Fri Nov 2 10:58:02 2007 UTC (6 years, 10 months ago) by haubi
File MIME type: text/x-csrc
File size: 6543 byte(s)
initial import of toolchain-prefix-wrapper

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 StringList* hpuxplugin(StringList *argList, StringList *userLibpathList, StringList *sysLibpathList)
27 {
28 int argc = 0;
29 int err;
30
31 bool withDefaultRunpath = true; /* +nodefaultrpath */
32 envrunpath_t withEnvRunpath = envrunpath_no; /* +s */
33
34 StringList *newArgList = NULL;
35 StringList *tmpArgList = NULL;
36 StringList *runpathList = NULL;
37 StringList *libpathList = NULL;
38 StringList *defaultRunpathList = NULL;
39 String *newString = NULL;
40 String *argString;
41 char const *argBuffer;
42 int argBufferLength;
43
44 do { /* dummy loop */
45 err = 1;
46
47 /* keep argv[0] */
48 newArgList = StringListCreate(argList, 0, 1);
49 if (newArgList == NULL)
50 break;
51
52 tmpArgList = StringListCreate(argList, 0, 0);
53 if (tmpArgList == NULL)
54 break;
55
56 runpathList = StringListCreate(NULL, 0, 0);
57 if (runpathList == NULL)
58 break;
59
60 libpathList = StringListCreate(NULL, 0, 0);
61 if (libpathList == NULL)
62 break;
63
64 defaultRunpathList = StringListCreate(NULL, 0, 0);
65 if (defaultRunpathList == NULL)
66 break;
67
68 for(argc = 1; argc < StringListGetSize(argList); argc++) {
69 argString = StringListGetString(argList, argc);
70 argBuffer = StringGetBuffer(argString);
71 argBufferLength = StringGetLength(argString);
72
73 if (strcmp(argBuffer, "+s") == 0) {
74 if (StringListGetSize(runpathList) == 0)
75 withEnvRunpath = envrunpath_first;
76 else
77 withEnvRunpath = envrunpath_second;
78 continue;
79 } else
80 if (strcmp(argBuffer, "+nodefaultrpath") == 0) {
81 withDefaultRunpath = false;
82 continue;
83 #if defined(__ia64)
84 } else
85 if (strcmp(argBuffer, "+defaultrpath") == 0) {
86 withDefaultRunpath = true;
87 continue;
88 #endif
89 } else
90 if (strncmp(argBuffer, "+b", 2) == 0) {
91 /* collect runpath from "+b runpath1:runpathN" */
92 char const *curr, *next;
93
94 argBuffer += 2;
95 argBufferLength -= 2;
96
97 if (*argBuffer == 0 && argc < StringListGetSize(argList)) {
98 argc++;
99 argString = StringListGetString(argList, argc);
100 argBuffer = StringGetBuffer(argString);
101 argBufferLength = StringGetLength(argString);
102 }
103
104 for(curr = next = argBuffer; *next != '\0'; curr = next+1) {
105 for(next = curr; *next != '\0' && *next != ':'; next++);
106
107 if (next - curr <= 1) {
108 /* skip empty path */
109 continue;
110 }
111
112 if (StringListContains(sysLibpathList, curr, next - curr)) {
113 /* sys runpath will be added later */
114 continue;
115 }
116
117 if (StringListContains(runpathList, curr, next - curr)) {
118 /* already recorded user runpath */
119 continue;
120 }
121
122 /* record this path into libpath list */
123 if (StringListAppendConcat(runpathList, curr, next - curr, NULL) < 0)
124 break;
125 }
126
127 /* end "+b" handling */
128 continue;
129 } else
130 if (strncmp(argBuffer, "-L", 2) == 0) {
131 /* collect libpath from "-L libpath" */
132
133 argBuffer += 2;
134 argBufferLength -= 2;
135
136 if (*argBuffer == 0 && argc < StringListGetSize(argList)) {
137 argc++;
138 argString = StringListGetString(argList, argc);
139 argBuffer = StringGetBuffer(argString);
140 argBufferLength = StringGetLength(argString);
141 }
142 if (StringListContains(sysLibpathList, argBuffer, argBufferLength))
143 continue;
144
145 if (StringListAppendConcat(libpathList, argBuffer, argBufferLength, NULL) < 0)
146 break;
147
148 continue;
149 } else
150 if (strncmp(argBuffer, "-R", 2) == 0) {
151 /* extension:
152 * collect additional default runpath from "-R runpath"
153 */
154
155 argBuffer += 2;
156 argBufferLength -= 2;
157
158 if (*argBuffer == 0 && argc < StringListGetSize(argList)) {
159 argc++;
160 argString = StringListGetString(argList, argc);
161 argBuffer = StringGetBuffer(argString);
162 argBufferLength = StringGetLength(argString);
163 }
164 if (StringListContains(sysLibpathList, argBuffer, argBufferLength))
165 continue;
166
167 if (StringListAppendConcat(defaultRunpathList, argBuffer, argBufferLength, NULL) < 0)
168 break;
169
170 continue;
171 }
172
173 /* keep other arguments on commandline */
174 if (StringListAppendString(tmpArgList, argString) < 0)
175 break;
176 }
177 if (argc < StringListGetSize(argList)) {
178 /* error during argument parsing */
179 break;
180 }
181
182 /* if there is no runpath (+b), use libpath as runpath
183 * if not disabled with "+nodefaultrpath"
184 */
185 if (StringListGetSize(runpathList) == 0
186 && withDefaultRunpath == true
187 && StringListAppendList(runpathList, libpathList, 0, -1) < 0
188 ) break;
189
190 /*
191 * first, put libpath list (-L) on the commandline
192 */
193 if (StringListAppendListModify(newArgList, libpathList, 0, -1, "-L", 2, NULL, 0) < 0)
194 break;
195
196 /* also put sys libpath list as libpath (-L) on commandline */
197 if (StringListAppendListModify(newArgList, sysLibpathList, 0, -1, "-L", 2, NULL, 0) < 0)
198 break;
199
200 /*
201 * second, put runpath list (-R, +b) on the commandline
202 */
203
204 /* append "+b" to commandline */
205 if (StringListAppendConcat(newArgList, "+b", 2, NULL) < 0)
206 break;
207
208 /* append default runpath list (-R) to runpath list */
209 if (StringListAppendList(runpathList, defaultRunpathList, 0, -1) < 0)
210 break;
211
212 /* append sys libpath list to runpath list */
213 if (StringListAppendList(runpathList, sysLibpathList, 0, -1) < 0)
214 break;
215
216 /* create runpath string: runpath1:runpathN */
217 newString = StringListJoin(runpathList, NULL, 0, ":", 1, NULL, 0);
218 if (newString == NULL)
219 break;
220
221 /* append runpath string to commandline */
222 if (StringListAppendString(newArgList, newString) < 0)
223 break;
224
225 /*
226 * third, put other arguments on commandline
227 */
228 if (StringListAppendList(newArgList, tmpArgList, 0, -1) < 0)
229 break;
230
231 err = 0;
232 } while(0); /* end dummy loop */
233
234 newString = StringDestroy(newString);
235 defaultRunpathList = StringListDestroy(defaultRunpathList);
236 libpathList = StringListDestroy(libpathList);
237 runpathList = StringListDestroy(runpathList);
238 tmpArgList = StringListDestroy(tmpArgList);
239
240 if (err) newArgList = StringListDestroy(newArgList);
241
242 return newArgList;
243 }
244
245 #if defined(__cplusplus)
246 }
247 #endif

Properties

Name Value
svn:executable

  ViewVC Help
Powered by ViewVC 1.1.20