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

Contents of /trunk/toolchain-prefix-wrapper/ld/aixplugin.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: 4453 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 "aixplugin.h"
10
11 #include <stdlib.h>
12 #include <string.h>
13
14 #if defined(__cplusplus)
15 extern "C" {
16 #endif
17
18 /* HPUX-ld:
19 * When there is no explicit runpath on the linker commandline (+b runpath),
20 * then all library paths (-L) are recorded as runpath
21 */
22 StringList* aixplugin(StringList *argList, StringList *userLibpathList, StringList *sysLibpathList)
23 {
24 int argc = 0;
25 int err;
26 StringList *newArgList = NULL;
27 StringList *defaultRunpathList = NULL;
28 StringList *runpathList = NULL;
29 String *argString;
30 String *newString = NULL;
31 char const *argBuffer;
32 int argBufferLength;
33
34 do { /* dummy loop */
35 err = 1;
36
37 /* keep argv[0] */
38 newArgList = StringListCreate(argList, 0, 1);
39 if (newArgList == NULL)
40 break;
41
42 defaultRunpathList = StringListCreate(NULL, 0, 0);
43 if (defaultRunpathList == NULL)
44 break;
45
46 runpathList = StringListCreate(NULL, 0, 0);
47 if (runpathList == NULL)
48 break;
49
50 /* always pass "-brtl" */
51 if (StringListAppendConcat(newArgList, "-brtl", 5, NULL) < 0)
52 break;
53
54 for(argc = 1; argc < StringListGetSize(argList); argc++) {
55 argString = StringListGetString(argList, argc);
56 argBuffer = StringGetBuffer(argString);
57 argBufferLength = StringGetLength(argString);
58
59 if (strncmp(argBuffer, "-blibpath:", 10) == 0) {
60 char const *curr, *next;
61
62 argBuffer += 10;
63
64 for(curr = next = argBuffer; *next != '\0'; curr = next+1) {
65 for(next = curr; *next != '\0' && *next != ':'; next++);
66
67 if (next - curr <= 1) {
68 /* skip empty path */
69 continue;
70 }
71
72 /* search default path list */
73 if (StringListContains(sysLibpathList, curr, next - curr))
74 continue;
75
76 /* unique out runpath */
77 if (StringListContains(runpathList, curr, next - curr))
78 continue;
79
80 /* record this path into runpath list */
81 if (StringListAppendConcat(runpathList, curr, next - curr, NULL) < 0)
82 break;
83 }
84
85 /* end "-blibpath:" handling */
86 continue;
87 } else
88 if (strncmp(argBuffer, "-R", 2) == 0) {
89 /* extension:
90 * collect additional default runpath from "-R runpath"
91 */
92
93 argBuffer += 2;
94 argBufferLength -= 2;
95
96 if (*argBuffer == 0 && argc < StringListGetSize(argList)) {
97 argc++;
98 argString = StringListGetString(argList, argc);
99 argBuffer = StringGetBuffer(argString);
100 argBufferLength = StringGetLength(argString);
101 }
102 if (StringListContains(sysLibpathList, argBuffer, argBufferLength))
103 continue;
104
105 if (StringListAppendConcat(defaultRunpathList, argBuffer, argBufferLength, NULL) < 0)
106 break;
107
108 continue;
109 }
110
111 /* keep other arguments */
112 if (StringListAppendString(newArgList, argString) < 0) break;
113 }
114 if (argc < StringListGetSize(argList)) {
115 /* error during argument parsing */
116 break;
117 }
118
119 if (StringListGetSize(runpathList) > 0 || StringListGetSize(defaultRunpathList)) {
120 /* if there is no user-runpath, all -L path's are recorded as runpath */
121
122 /* always have default runpath list in runpath */
123 if (StringListAppendList(runpathList, defaultRunpathList, 0, -1) < 0)
124 break;
125
126 /* always have sys libpath list in runpath */
127 if (StringListAppendList(runpathList, sysLibpathList, 0, -1) < 0)
128 break;
129
130 /* need to add /usr/lib:/lib to explicit runpath if any */
131 if (StringListAppendConcat(runpathList, "/usr/lib", 8, NULL) < 0)
132 break;
133 if (StringListAppendConcat(runpathList, "/lib", 4, NULL) < 0)
134 break;
135
136 /* create runpath string: "-blibpath:libpath1:libpathN" */
137 newString = StringListJoin(runpathList, "-blibpath:", 10, ":", 1, NULL, 0);
138 if (newString == NULL)
139 break;
140
141 /* append runpath string to commandline */
142 if (StringListAppendString(newArgList, newString) < 0)
143 break;
144 }
145
146 /* append sys libpath's with "-L" */
147 if (StringListAppendListModify(newArgList, sysLibpathList, 0, -1, "-L", 2, NULL, 0) < 0)
148 break;
149
150 err = 0;
151 } while(0); /* end dummy loop */
152
153 if (newString != NULL) newString = StringDestroy(newString);
154 if (runpathList != NULL) runpathList = StringListDestroy(runpathList);
155 if (defaultRunpathList != NULL) defaultRunpathList = StringListDestroy(defaultRunpathList);
156
157 if (err && newArgList != NULL) newArgList = StringListDestroy(newArgList);
158
159 return newArgList;
160 }
161
162 #if defined(__cplusplus)
163 }
164 #endif

Properties

Name Value
svn:executable

  ViewVC Help
Powered by ViewVC 1.1.20