1 |
Author: haubi |
2 |
Date: 2009-07-01 20:14:40 +0000 (Wed, 01 Jul 2009) |
3 |
New Revision: 1652 |
4 |
|
5 |
Modified: |
6 |
trunk/toolchain-prefix-wrapper/ld/hpuxplugin.c |
7 |
Log: |
8 |
Added hppa-hpux support, hopefully without breaking ia64-hpux. |
9 |
Basically knows about all ia64/ia64w/hppa/hppa64, but untested. |
10 |
|
11 |
|
12 |
Modified: trunk/toolchain-prefix-wrapper/ld/hpuxplugin.c |
13 |
=================================================================== |
14 |
--- trunk/toolchain-prefix-wrapper/ld/hpuxplugin.c 2009-04-12 19:16:44 UTC (rev 1651) |
15 |
+++ trunk/toolchain-prefix-wrapper/ld/hpuxplugin.c 2009-07-01 20:14:40 UTC (rev 1652) |
16 |
@@ -17,23 +17,33 @@ |
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 |
+typedef enum { EnvRpath_No = 0, EnvRpath_First = 1, EnvRpath_Second = 2 } EnvRpathFlag; |
22 |
+typedef enum { UseRpath_Concat = 0, UseRpath_First = 1, UseRpath_Last = 2 } UseRpathFlag; |
23 |
+typedef enum { LinkMode_ELF = 0, LinkMode_SOM = 1, LinkMode_Compat = 2 } LinkModeType; |
24 |
|
25 |
/* HPUX-ld: |
26 |
- * When there is no explicit runpath on the linker commandline (+b runpath), |
27 |
- * then all library paths (-L) are recorded as runpath |
28 |
+ * ELF: When there is no explicit runpath on the linker commandline (+b runpath), |
29 |
+ * then all library paths (-L) are recorded as runpath |
30 |
+ * SOM: Runpath used to be stored on explicit flag (+b runpath) only. |
31 |
+ * When there is "+b :", then library paths (-L) are recorded as runpath. |
32 |
+ * We assume "+b :" is set at least, to get our paths searched always. |
33 |
*/ |
34 |
int hpuxplugin(LdPluginData *data) |
35 |
{ |
36 |
int argc = 0; |
37 |
int err; |
38 |
+ bool isIA64; |
39 |
+ bool is64bit; |
40 |
|
41 |
- bool withDefaultRunpath = true; /* +nodefaultrpath */ |
42 |
- envrunpath_t withEnvRunpath = envrunpath_no; /* +s */ |
43 |
+ /* ELF settings */ |
44 |
+ bool needLibpathAsRunpath = true; |
45 |
+ UseRpathFlag useRpathFlag = UseRpath_Last; |
46 |
|
47 |
+ EnvRpathFlag envRpathFlag = EnvRpath_No; /* +s */ |
48 |
StringList *tmpArgList = NULL; |
49 |
StringList *runpathList = NULL; |
50 |
StringList *defaultRunpathList = NULL; |
51 |
+ StringList *sysRunpathList = NULL; |
52 |
String *newString = NULL; |
53 |
String const *argString; |
54 |
char const *argBuffer; |
55 |
@@ -54,27 +64,69 @@ |
56 |
if (defaultRunpathList == NULL) |
57 |
break; |
58 |
|
59 |
+ sysRunpathList = StringListCreate(NULL, 0, 0); |
60 |
+ if (sysRunpathList == NULL) |
61 |
+ break; |
62 |
+ |
63 |
+ if (strncmp(StringGetBuffer(data->in->host.triplet), "ia64", strlen("ia64")) == 0) { |
64 |
+ isIA64 = true; |
65 |
+ is64bit = false; |
66 |
+ if (StringGetBuffer(data->in->host.triplet)[strlen("ia64")] == 'w') { |
67 |
+ /* ia64w: ELF, 64bit */ |
68 |
+ is64bit = true; |
69 |
+ } |
70 |
+ } else |
71 |
+ if (strncmp(StringGetBuffer(data->in->host.triplet), "hppa64", strlen("hppa64")) == 0) { |
72 |
+ /* hppa64: ELF, 64bit */ |
73 |
+ isIA64 = false; |
74 |
+ is64bit = true; |
75 |
+ } else { |
76 |
+ /* hppa: SOM, 32bit */ |
77 |
+ isIA64 = false; |
78 |
+ is64bit = false; |
79 |
+ } |
80 |
+ |
81 |
+ if (!isIA64 || is64bit) { |
82 |
+ /* hppa64 only */ |
83 |
+ for(argc = 1; argc < StringListGetSize(data->in->argList); argc++) { |
84 |
+ argString = StringListGetString(data->in->argList, argc); |
85 |
+ argBuffer = StringGetBuffer(argString); |
86 |
+ if (strcmp(argBuffer, "+concatrpath") == 0) { |
87 |
+ useRpathFlag = UseRpath_Concat; |
88 |
+ } else |
89 |
+ if (strcmp(argBuffer, "+noconcatrpath") == 0) { |
90 |
+ useRpathFlag = UseRpath_Last; |
91 |
+ } |
92 |
+ } |
93 |
+ } |
94 |
+ |
95 |
+ if (!isIA64 && !is64bit) { |
96 |
+ /* hppa only */ |
97 |
+ useRpathFlag = UseRpath_First; |
98 |
+ } |
99 |
+ |
100 |
for(argc = 1; argc < StringListGetSize(data->in->argList); argc++) { |
101 |
argString = StringListGetString(data->in->argList, argc); |
102 |
argBuffer = StringGetBuffer(argString); |
103 |
argBufferLength = StringGetLength(argString); |
104 |
|
105 |
if (strcmp(argBuffer, "+s") == 0) { |
106 |
- if (StringListGetSize(runpathList) == 0) |
107 |
- withEnvRunpath = envrunpath_first; |
108 |
+ if (StringListGetSize(runpathList) + StringListGetSize(sysRunpathList)) |
109 |
+ envRpathFlag = EnvRpath_Second; |
110 |
else |
111 |
- withEnvRunpath = envrunpath_second; |
112 |
+ envRpathFlag = EnvRpath_First; |
113 |
continue; |
114 |
} else |
115 |
if (strcmp(argBuffer, "+nodefaultrpath") == 0) { |
116 |
- withDefaultRunpath = false; |
117 |
+ needLibpathAsRunpath = false; |
118 |
continue; |
119 |
-#if defined(__ia64) |
120 |
} else |
121 |
if (strcmp(argBuffer, "+defaultrpath") == 0) { |
122 |
- withDefaultRunpath = true; |
123 |
- continue; |
124 |
-#endif |
125 |
+ /* SOM: Unrecognized argument */ |
126 |
+ if (isIA64 || is64bit) { |
127 |
+ needLibpathAsRunpath = true; |
128 |
+ continue; |
129 |
+ } |
130 |
} else |
131 |
if (strncmp(argBuffer, "+b", 2) == 0) { |
132 |
/* collect runpath from "+b runpath1:runpathN" */ |
133 |
@@ -90,6 +142,47 @@ |
134 |
argBufferLength = StringGetLength(argString); |
135 |
} |
136 |
|
137 |
+ if (useRpathFlag != UseRpath_Concat) { |
138 |
+ if (StringListGetSize(runpathList) + StringListGetSize(sysRunpathList)) { |
139 |
+ if (useRpathFlag == UseRpath_First) { |
140 |
+ continue; |
141 |
+ } |
142 |
+ StringListClear(runpathList); |
143 |
+ StringListClear(sysRunpathList); |
144 |
+ } |
145 |
+ |
146 |
+ if (argBufferLength == 1 && argBuffer[0] == ':') { |
147 |
+ /* "+b:" collects all "-L" paths and LPATH envvar */ |
148 |
+ needLibpathAsRunpath = true; |
149 |
+ /* TODO: getenv("LPATH") */ |
150 |
+ if (isIA64 && is64bit) { |
151 |
+ /* ia64w */ |
152 |
+ if (StringListAppendConcat(sysRunpathList, |
153 |
+ "/usr/lib/hpux64", strlen("/usr/lib/hpux64"), |
154 |
+ NULL) < 0) |
155 |
+ break; |
156 |
+ } else |
157 |
+ if (isIA64 && !is64bit) { |
158 |
+ /* ia64 */ |
159 |
+ if (StringListAppendConcat(sysRunpathList, |
160 |
+ "/usr/lib/hpux32", strlen("/usr/lib/hpux32"), |
161 |
+ NULL) < 0) |
162 |
+ break; |
163 |
+ } else |
164 |
+ if (is64bit) { |
165 |
+ /* hppa64 */ |
166 |
+ if (StringListAppendConcat(sysRunpathList, |
167 |
+ "/usr/lib/pa20_64", strlen("/usr/lib/pa20_64"), |
168 |
+ "/usr/ccs/lib/pa20_64", strlen("/usr/ccs/lib/pa20_64"), |
169 |
+ NULL) < 0) |
170 |
+ break; |
171 |
+ } else { |
172 |
+ /* hppa */ |
173 |
+ } |
174 |
+ continue; |
175 |
+ } |
176 |
+ } |
177 |
+ |
178 |
for(curr = next = argBuffer; *next != '\0'; curr = next+1) { |
179 |
for(next = curr; *next != '\0' && *next != ':'; next++); |
180 |
|
181 |
@@ -166,7 +259,7 @@ |
182 |
break; |
183 |
|
184 |
/* do we need to use env-runpath first? */ |
185 |
- if (withEnvRunpath == envrunpath_first |
186 |
+ if (envRpathFlag == EnvRpath_First |
187 |
&& StringListAppendConcat(data->out->argList, "+s", 2, NULL) < 0 |
188 |
) break; |
189 |
|
190 |
@@ -182,7 +275,7 @@ |
191 |
* if not disabled with "+nodefaultrpath" |
192 |
*/ |
193 |
if (StringListGetSize(runpathList) == 0 |
194 |
- && withDefaultRunpath == true |
195 |
+ && needLibpathAsRunpath == true |
196 |
&& StringListAppendList(runpathList, data->in->userLibpath, 0, -1) < 0 |
197 |
) break; |
198 |
|
199 |
@@ -194,6 +287,10 @@ |
200 |
if (StringListAppendList(runpathList, data->in->sysRunpath, 0, -1) < 0) |
201 |
break; |
202 |
|
203 |
+ /* append local sys libpath list to runpath list */ |
204 |
+ if (StringListAppendList(runpathList, sysRunpathList, 0, -1) < 0) |
205 |
+ break; |
206 |
+ |
207 |
/* create runpath string: runpath1:runpathN */ |
208 |
newString = StringListJoin(runpathList, NULL, 0, ":", 1, NULL, 0); |
209 |
if (newString == NULL) |
210 |
@@ -204,7 +301,7 @@ |
211 |
break; |
212 |
|
213 |
/* do we need to use env-runpath second? */ |
214 |
- if (withEnvRunpath == envrunpath_second |
215 |
+ if (envRpathFlag == EnvRpath_Second |
216 |
&& StringListAppendConcat(data->out->argList, "+s", 2, NULL) < 0 |
217 |
) break; |
218 |
|
219 |
@@ -218,6 +315,7 @@ |
220 |
} while(0); /* end dummy loop */ |
221 |
|
222 |
newString = StringDestroy(newString); |
223 |
+ sysRunpathList = StringListDestroy(sysRunpathList); |
224 |
defaultRunpathList = StringListDestroy(defaultRunpathList); |
225 |
runpathList = StringListDestroy(runpathList); |
226 |
tmpArgList = StringListDestroy(tmpArgList); |