blob: b7c81962a0e53c5094b76c7cc8778ac46e8c293c [file] [log] [blame]
Alexandre Julliardc585a502000-09-27 23:40:43 +00001/*
2 * DLL imports support
3 *
4 * Copyright 2000 Alexandre Julliard
Eric Pouech5e32d162000-12-26 01:22:34 +00005 * 2000 Eric Pouech
Alexandre Julliard0799c1a2002-03-09 23:29:33 +00006 *
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
11 *
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Alexandre Julliardc585a502000-09-27 23:40:43 +000020 */
21
Francois Gougete5ddd262001-10-14 16:18:52 +000022#include "config.h"
Alexandre Julliard894b1882002-04-25 21:40:56 +000023#include "wine/port.h"
Francois Gougete5ddd262001-10-14 16:18:52 +000024
Alexandre Julliardd25878f2002-07-25 00:25:40 +000025#include <ctype.h>
Alexandre Julliardc585a502000-09-27 23:40:43 +000026#include <fcntl.h>
27#include <stdio.h>
Jon Griffiths4ab15582001-01-22 02:17:29 +000028#include <string.h>
Dmitry Timoshkovc63d9802002-08-17 18:28:43 +000029#ifdef HAVE_UNISTD_H
30# include <unistd.h>
31#endif
Alexandre Julliardc585a502000-09-27 23:40:43 +000032
Alexandre Julliardc585a502000-09-27 23:40:43 +000033#include "build.h"
34
Alexandre Julliardd25878f2002-07-25 00:25:40 +000035struct func
36{
Alexandre Julliardada5e652002-12-12 22:03:14 +000037 char *name; /* function name */
Alexandre Julliardd25878f2002-07-25 00:25:40 +000038 int ordinal; /* function ordinal */
Alexandre Julliard15a75252002-07-28 17:54:31 +000039 int ord_only; /* non-zero if function is imported by ordinal */
Alexandre Julliardd25878f2002-07-25 00:25:40 +000040};
41
Alexandre Julliardc585a502000-09-27 23:40:43 +000042struct import
43{
44 char *dll; /* dll name */
Eric Pouech5e32d162000-12-26 01:22:34 +000045 int delay; /* delay or not dll loading ? */
Alexandre Julliardd25878f2002-07-25 00:25:40 +000046 struct func *exports; /* functions exported from this dll */
Alexandre Julliard000c13a2000-11-09 20:31:18 +000047 int nb_exports; /* number of exported functions */
Alexandre Julliardd25878f2002-07-25 00:25:40 +000048 struct func *imports; /* functions we want to import from this dll */
Alexandre Julliardc585a502000-09-27 23:40:43 +000049 int nb_imports; /* number of imported functions */
50};
51
Alexandre Julliard000c13a2000-11-09 20:31:18 +000052static char **undef_symbols; /* list of undefined symbols */
Alexandre Julliard0a8114c2000-11-12 03:45:55 +000053static int nb_undef_symbols = -1;
54static int undef_size;
Alexandre Julliardc585a502000-09-27 23:40:43 +000055
Jon Griffiths4f12e612000-12-14 22:18:22 +000056static char **ignore_symbols; /* list of symbols to ignore */
57static int nb_ignore_symbols;
58static int ignore_size;
59
Alexandre Julliardf08b1862002-08-27 22:29:26 +000060static char *ld_tmp_file; /* ld temp file name */
Alexandre Julliard1862a672002-08-01 18:34:12 +000061
Alexandre Julliardc585a502000-09-27 23:40:43 +000062static struct import **dll_imports = NULL;
Eric Pouech5e32d162000-12-26 01:22:34 +000063static int nb_imports = 0; /* number of imported dlls (delayed or not) */
64static int nb_delayed = 0; /* number of delayed dlls */
65static int total_imports = 0; /* total number of imported functions */
66static int total_delayed = 0; /* total number of imported functions in delayed DLLs */
Alexandre Julliardc585a502000-09-27 23:40:43 +000067
Alexandre Julliard72e1c642002-12-12 02:20:47 +000068/* list of symbols that are ignored by default */
69static const char * const default_ignored_symbols[] =
70{
71 "abs",
72 "acos",
73 "asin",
74 "atan",
75 "atan2",
76 "atof",
77 "atoi",
78 "atol",
79 "bsearch",
80 "ceil",
81 "cos",
82 "cosh",
83 "div",
84 "exp",
85 "fabs",
86 "floor",
87 "fmod",
88 "frexp",
89 "labs",
90 "ldiv",
91 "log",
92 "log10",
93 "memchr",
94 "memcmp",
95 "memcpy",
96 "memmove",
97 "memset",
98 "modf",
99 "pow",
100 "qsort",
101 "sin",
102 "sinh",
Alexandre Julliard72e1c642002-12-12 02:20:47 +0000103 "sqrt",
Alexandre Julliard72e1c642002-12-12 02:20:47 +0000104 "strcat",
105 "strchr",
106 "strcmp",
107 "strcpy",
108 "strcspn",
109 "strlen",
110 "strncat",
111 "strncmp",
112 "strncpy",
113 "strpbrk",
114 "strrchr",
115 "strspn",
116 "strstr",
117 "tan",
Alexandre Julliard9ba2e892002-12-20 00:36:18 +0000118 "tanh"
Alexandre Julliard72e1c642002-12-12 02:20:47 +0000119};
120
Alexandre Julliard346ca952003-08-13 21:57:42 +0000121#ifdef __powerpc__
122# ifdef __APPLE__
123# define ppc_high(mem) "ha16(" mem ")"
124# define ppc_low(mem) "lo16(" mem ")"
125static const char * const ppc_reg[32] = { "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7",
126 "r8", "r9", "r10","r11","r12","r13","r14","r15",
127 "r16","r17","r18","r19","r20","r21","r22","r23",
128 "r24","r25","r26","r27","r28","r29","r30","r31" };
129# else /* __APPLE__ */
130# define ppc_high(mem) "(" mem ")@hi"
131# define ppc_low(mem) "(" mem ")@l"
132static const char * const ppc_reg[32] = { "0", "1", "2", "3", "4", "5", "6", "7",
133 "8", "9", "10","11","12","13","14","15",
134 "16","17","18","19","20","21","22","23",
135 "24","25","26","27","28","29","30","31" };
136# endif /* __APPLE__ */
137#endif /* __powerpc__ */
138
Alexandre Julliard000c13a2000-11-09 20:31:18 +0000139/* compare function names; helper for resolve_imports */
140static int name_cmp( const void *name, const void *entry )
141{
142 return strcmp( *(char **)name, *(char **)entry );
143}
144
Alexandre Julliardd25878f2002-07-25 00:25:40 +0000145/* compare function names; helper for resolve_imports */
146static int func_cmp( const void *func1, const void *func2 )
147{
148 return strcmp( ((struct func *)func1)->name, ((struct func *)func2)->name );
149}
150
Alexandre Julliard000c13a2000-11-09 20:31:18 +0000151/* locate a symbol in a (sorted) list */
152inline static const char *find_symbol( const char *name, char **table, int size )
153{
Patrik Stridvall35d288b2000-12-18 03:13:52 +0000154 char **res = NULL;
155
156 if (table) {
157 res = bsearch( &name, table, size, sizeof(*table), name_cmp );
158 }
159
Alexandre Julliard000c13a2000-11-09 20:31:18 +0000160 return res ? *res : NULL;
161}
162
Alexandre Julliardd25878f2002-07-25 00:25:40 +0000163/* locate an export in a (sorted) export list */
164inline static struct func *find_export( const char *name, struct func *table, int size )
165{
166 struct func func, *res = NULL;
167
Alexandre Julliardada5e652002-12-12 22:03:14 +0000168 func.name = (char *)name;
Alexandre Julliardd25878f2002-07-25 00:25:40 +0000169 func.ordinal = -1;
170 if (table) res = bsearch( &func, table, size, sizeof(*table), func_cmp );
171 return res;
172}
173
Alexandre Julliard000c13a2000-11-09 20:31:18 +0000174/* sort a symbol table */
175inline static void sort_symbols( char **table, int size )
176{
Ulrich Weigand0108d832000-12-29 05:17:33 +0000177 if (table )
178 qsort( table, size, sizeof(*table), name_cmp );
Alexandre Julliard000c13a2000-11-09 20:31:18 +0000179}
180
Alexandre Julliardada5e652002-12-12 22:03:14 +0000181/* free an import structure */
182static void free_imports( struct import *imp )
183{
184 int i;
185
186 for (i = 0; i < imp->nb_exports; i++) free( imp->exports[i].name );
187 for (i = 0; i < imp->nb_imports; i++) free( imp->imports[i].name );
188 free( imp->exports );
189 free( imp->imports );
190 free( imp->dll );
191 free( imp );
192}
193
Alexandre Julliard1862a672002-08-01 18:34:12 +0000194/* remove the temp file at exit */
195static void remove_ld_tmp_file(void)
196{
197 if (ld_tmp_file) unlink( ld_tmp_file );
198}
199
Alexandre Julliardada5e652002-12-12 22:03:14 +0000200/* check whether a given dll has already been imported */
201static int is_already_imported( const char *name )
202{
203 int i;
204
205 for (i = 0; i < nb_imports; i++)
206 {
207 if (!strcmp( dll_imports[i]->dll, name )) return 1;
208 }
209 return 0;
210}
211
Alexandre Julliard000c13a2000-11-09 20:31:18 +0000212/* open the .so library for a given dll in a specified path */
213static char *try_library_path( const char *path, const char *name )
214{
Alexandre Julliardc1bfca02002-03-20 22:19:06 +0000215 char *buffer;
Alexandre Julliard000c13a2000-11-09 20:31:18 +0000216 int fd;
217
Alexandre Julliardc1bfca02002-03-20 22:19:06 +0000218 buffer = xmalloc( strlen(path) + strlen(name) + 9 );
Alexandre Julliardada5e652002-12-12 22:03:14 +0000219 sprintf( buffer, "%s/lib%s.def", path, name );
220
Alexandre Julliard000c13a2000-11-09 20:31:18 +0000221 /* check if the file exists */
Alexandre Julliardc1bfca02002-03-20 22:19:06 +0000222 if ((fd = open( buffer, O_RDONLY )) != -1)
223 {
224 close( fd );
225 return buffer;
226 }
227 free( buffer );
228 return NULL;
Alexandre Julliard000c13a2000-11-09 20:31:18 +0000229}
230
231/* open the .so library for a given dll */
232static char *open_library( const char *name )
233{
234 char *fullname;
235 int i;
236
237 for (i = 0; i < nb_lib_paths; i++)
238 {
239 if ((fullname = try_library_path( lib_path[i], name ))) return fullname;
240 }
241 if (!(fullname = try_library_path( ".", name )))
Alexandre Julliardada5e652002-12-12 22:03:14 +0000242 fatal_error( "could not open .def file for %s\n", name );
Alexandre Julliard000c13a2000-11-09 20:31:18 +0000243 return fullname;
244}
245
Alexandre Julliardada5e652002-12-12 22:03:14 +0000246/* skip whitespace until the next token */
247static char *skip_whitespace( char *p )
248{
249 while (*p && isspace(*p)) p++;
250 if (!*p || *p == ';') p = NULL;
251 return p;
252}
253
254/* skip to the start of the next token, null terminating the current one */
255static char *next_token( char *p )
256{
257 while (*p && !isspace(*p)) p++;
258 if (*p) *p++ = 0;
259 return skip_whitespace( p );
260}
261
262/* remove the @nn suffix from stdcall names */
263static char *remove_stdcall_decoration( char *buffer )
264{
265 char *p = buffer + strlen(buffer) - 1;
266 while (p > buffer && isdigit(*p)) p--;
267 if (p > buffer && *p == '@') *p = 0;
268 return buffer;
269}
270
271/* read in the list of exported symbols of an import library */
272static int read_import_lib( const char *name, struct import *imp )
Alexandre Julliard000c13a2000-11-09 20:31:18 +0000273{
274 FILE *f;
Alexandre Julliardada5e652002-12-12 22:03:14 +0000275 char buffer[1024];
276 char *fullname;
277 int size;
Alexandre Julliard000c13a2000-11-09 20:31:18 +0000278
279 imp->exports = NULL;
280 imp->nb_exports = size = 0;
281
Alexandre Julliardada5e652002-12-12 22:03:14 +0000282 fullname = open_library( name );
283 f = open_input_file( NULL, fullname );
Alexandre Julliard000c13a2000-11-09 20:31:18 +0000284 free( fullname );
285
Alexandre Julliard000c13a2000-11-09 20:31:18 +0000286 while (fgets( buffer, sizeof(buffer), f ))
287 {
Alexandre Julliardada5e652002-12-12 22:03:14 +0000288 char *name, *flags;
Alexandre Julliard15a75252002-07-28 17:54:31 +0000289 int ordinal = 0, ord_only = 0;
Alexandre Julliardada5e652002-12-12 22:03:14 +0000290
Alexandre Julliard000c13a2000-11-09 20:31:18 +0000291 char *p = buffer + strlen(buffer) - 1;
Alexandre Julliardada5e652002-12-12 22:03:14 +0000292 if (p < buffer) goto next;
Alexandre Julliard000c13a2000-11-09 20:31:18 +0000293 if (*p == '\n') *p-- = 0;
Alexandre Julliardada5e652002-12-12 22:03:14 +0000294
295 p = buffer;
296 if (!(p = skip_whitespace(p))) goto next;
297 name = p;
298 p = next_token( name );
299
300 if (!strcmp( name, "LIBRARY" ))
Alexandre Julliard15a75252002-07-28 17:54:31 +0000301 {
Alexandre Julliard49edd192003-03-18 05:30:54 +0000302 if (!p)
303 {
304 error( "Expected name after LIBRARY\n" );
305 goto next;
306 }
Alexandre Julliardada5e652002-12-12 22:03:14 +0000307 name = p;
308 p = next_token( name );
Alexandre Julliard49edd192003-03-18 05:30:54 +0000309 if (p)
310 {
311 error( "Garbage after LIBRARY statement\n" );
312 goto next;
313 }
Alexandre Julliardada5e652002-12-12 22:03:14 +0000314 if (is_already_imported( name ))
315 {
316 close_input_file( f );
317 return 0; /* ignore this dll */
318 }
319 free( imp->dll );
320 imp->dll = xstrdup( name );
321 goto next;
Alexandre Julliard15a75252002-07-28 17:54:31 +0000322 }
Alexandre Julliardada5e652002-12-12 22:03:14 +0000323 if (!strcmp( name, "EXPORTS" )) goto next;
324
325 /* check for ordinal */
Alexandre Julliard49edd192003-03-18 05:30:54 +0000326 if (!p)
327 {
328 error( "Expected ordinal after function name\n" );
329 goto next;
330 }
Alexandre Julliardada5e652002-12-12 22:03:14 +0000331 if (*p != '@' || !isdigit(p[1]))
Alexandre Julliard49edd192003-03-18 05:30:54 +0000332 {
333 error( "Expected ordinal after function name '%s'\n", name );
334 goto next;
335 }
Alexandre Julliardada5e652002-12-12 22:03:14 +0000336 ordinal = strtol( p+1, &p, 10 );
Alexandre Julliard49edd192003-03-18 05:30:54 +0000337 if (ordinal >= MAX_ORDINALS)
338 {
339 error( "Invalid ordinal number %d\n", ordinal );
340 goto next;
341 }
Alexandre Julliardada5e652002-12-12 22:03:14 +0000342
343 /* check for optional flags */
344 while (p && (p = skip_whitespace(p)))
Alexandre Julliardd25878f2002-07-25 00:25:40 +0000345 {
Alexandre Julliardada5e652002-12-12 22:03:14 +0000346 flags = p;
347 p = next_token( flags );
348 if (!strcmp( flags, "NONAME" ))
349 {
350 ord_only = 1;
Alexandre Julliard49edd192003-03-18 05:30:54 +0000351 if (!ordinal)
352 {
353 error( "Invalid ordinal number %d\n", ordinal );
354 goto next;
355 }
Alexandre Julliardada5e652002-12-12 22:03:14 +0000356 }
357 else if (!strcmp( flags, "CONSTANT" ) || !strcmp( flags, "DATA" ))
358 {
359 /* we don't support importing non-function entry points */
360 goto next;
361 }
Alexandre Julliard152b98f2003-07-28 19:19:48 +0000362 else if (!strcmp( flags, "PRIVATE" ))
363 {
364 /* function must not be imported */
365 goto next;
366 }
Alexandre Julliard49edd192003-03-18 05:30:54 +0000367 else
368 {
369 error( "Garbage after ordinal declaration\n" );
370 goto next;
371 }
Alexandre Julliardd25878f2002-07-25 00:25:40 +0000372 }
Alexandre Julliard000c13a2000-11-09 20:31:18 +0000373
374 if (imp->nb_exports == size)
375 {
376 size += 128;
377 imp->exports = xrealloc( imp->exports, size * sizeof(*imp->exports) );
378 }
Alexandre Julliardada5e652002-12-12 22:03:14 +0000379 if ((p = strchr( name, '=' ))) *p = 0;
380 remove_stdcall_decoration( name );
381 imp->exports[imp->nb_exports].name = xstrdup( name );
Alexandre Julliardd25878f2002-07-25 00:25:40 +0000382 imp->exports[imp->nb_exports].ordinal = ordinal;
Alexandre Julliard15a75252002-07-28 17:54:31 +0000383 imp->exports[imp->nb_exports].ord_only = ord_only;
Alexandre Julliardd25878f2002-07-25 00:25:40 +0000384 imp->nb_exports++;
Alexandre Julliardada5e652002-12-12 22:03:14 +0000385 next:
386 current_line++;
Alexandre Julliard000c13a2000-11-09 20:31:18 +0000387 }
Alexandre Julliardada5e652002-12-12 22:03:14 +0000388 close_input_file( f );
Alexandre Julliardd25878f2002-07-25 00:25:40 +0000389 if (imp->nb_exports)
390 qsort( imp->exports, imp->nb_exports, sizeof(*imp->exports), func_cmp );
Alexandre Julliard49edd192003-03-18 05:30:54 +0000391 return !nb_errors;
Alexandre Julliard000c13a2000-11-09 20:31:18 +0000392}
393
Alexandre Julliardc585a502000-09-27 23:40:43 +0000394/* add a dll to the list of imports */
Eric Pouech5e32d162000-12-26 01:22:34 +0000395void add_import_dll( const char *name, int delay )
Alexandre Julliardc585a502000-09-27 23:40:43 +0000396{
Alexandre Julliard32459912002-05-09 00:05:48 +0000397 struct import *imp;
Alexandre Julliard67371bc2002-05-11 23:06:32 +0000398 char *fullname;
Alexandre Julliard32459912002-05-09 00:05:48 +0000399
Alexandre Julliard67371bc2002-05-11 23:06:32 +0000400 fullname = xmalloc( strlen(name) + 5 );
401 strcpy( fullname, name );
402 if (!strchr( fullname, '.' )) strcat( fullname, ".dll" );
403
Alexandre Julliard32459912002-05-09 00:05:48 +0000404 /* check if we already imported it */
Alexandre Julliardada5e652002-12-12 22:03:14 +0000405 if (is_already_imported( fullname ))
Alexandre Julliard67371bc2002-05-11 23:06:32 +0000406 {
Alexandre Julliardada5e652002-12-12 22:03:14 +0000407 free( fullname );
408 return;
Alexandre Julliard67371bc2002-05-11 23:06:32 +0000409 }
Alexandre Julliard32459912002-05-09 00:05:48 +0000410
411 imp = xmalloc( sizeof(*imp) );
Alexandre Julliard67371bc2002-05-11 23:06:32 +0000412 imp->dll = fullname;
Eric Pouech5e32d162000-12-26 01:22:34 +0000413 imp->delay = delay;
Alexandre Julliardc585a502000-09-27 23:40:43 +0000414 imp->imports = NULL;
415 imp->nb_imports = 0;
416
Eric Pouech5e32d162000-12-26 01:22:34 +0000417 if (delay) nb_delayed++;
Alexandre Julliard000c13a2000-11-09 20:31:18 +0000418
Alexandre Julliardada5e652002-12-12 22:03:14 +0000419 if (read_import_lib( name, imp ))
420 {
421 dll_imports = xrealloc( dll_imports, (nb_imports+1) * sizeof(*dll_imports) );
422 dll_imports[nb_imports++] = imp;
423 }
Alexandre Julliard49edd192003-03-18 05:30:54 +0000424 else
425 {
426 free_imports( imp );
427 if (nb_errors) exit(1);
428 }
Alexandre Julliardc585a502000-09-27 23:40:43 +0000429}
430
Alexandre Julliarddaecaba2003-03-16 23:59:48 +0000431/* remove an imported dll, based on its index in the dll_imports array */
432static void remove_import_dll( int index )
433{
434 struct import *imp = dll_imports[index];
435
436 memmove( &dll_imports[index], &dll_imports[index+1], sizeof(imp) * (nb_imports - index - 1) );
437 nb_imports--;
438 if (imp->delay) nb_delayed--;
439 free_imports( imp );
440}
441
Alexandre Julliard72e1c642002-12-12 02:20:47 +0000442/* initialize the list of ignored symbols */
443static void init_ignored_symbols(void)
444{
445 int i;
446
447 nb_ignore_symbols = sizeof(default_ignored_symbols)/sizeof(default_ignored_symbols[0]);
448 ignore_size = nb_ignore_symbols + 32;
449 ignore_symbols = xmalloc( ignore_size * sizeof(*ignore_symbols) );
450 for (i = 0; i < nb_ignore_symbols; i++)
451 ignore_symbols[i] = xstrdup( default_ignored_symbols[i] );
452}
453
454/* add a symbol to the ignored symbol list */
455/* if the name starts with '-' the symbol is removed instead */
Jon Griffiths4f12e612000-12-14 22:18:22 +0000456void add_ignore_symbol( const char *name )
457{
Alexandre Julliard72e1c642002-12-12 02:20:47 +0000458 int i;
459
460 if (!ignore_symbols) init_ignored_symbols(); /* first time around, fill list with defaults */
461
462 if (name[0] == '-') /* remove it */
Jon Griffiths4f12e612000-12-14 22:18:22 +0000463 {
Alexandre Julliard72e1c642002-12-12 02:20:47 +0000464 if (!name[1]) /* remove everything */
465 {
466 for (i = 0; i < nb_ignore_symbols; i++) free( ignore_symbols[i] );
467 nb_ignore_symbols = 0;
468 }
469 else
470 {
471 for (i = 0; i < nb_ignore_symbols; i++)
472 {
473 if (!strcmp( ignore_symbols[i], name+1 ))
474 {
475 free( ignore_symbols[i] );
476 memmove( &ignore_symbols[i], &ignore_symbols[i+1], nb_ignore_symbols - i - 1 );
477 nb_ignore_symbols--;
478 }
479 }
480 }
Jon Griffiths4f12e612000-12-14 22:18:22 +0000481 }
Alexandre Julliard72e1c642002-12-12 02:20:47 +0000482 else
483 {
484 if (nb_ignore_symbols == ignore_size)
485 {
486 ignore_size += 32;
487 ignore_symbols = xrealloc( ignore_symbols, ignore_size * sizeof(*ignore_symbols) );
488 }
489 ignore_symbols[nb_ignore_symbols++] = xstrdup( name );
490 }
Jon Griffiths4f12e612000-12-14 22:18:22 +0000491}
492
Alexandre Julliardc585a502000-09-27 23:40:43 +0000493/* add a function to the list of imports from a given dll */
Alexandre Julliardd25878f2002-07-25 00:25:40 +0000494static void add_import_func( struct import *imp, const struct func *func )
Alexandre Julliardc585a502000-09-27 23:40:43 +0000495{
496 imp->imports = xrealloc( imp->imports, (imp->nb_imports+1) * sizeof(*imp->imports) );
Alexandre Julliardd25878f2002-07-25 00:25:40 +0000497 imp->imports[imp->nb_imports].name = xstrdup( func->name );
498 imp->imports[imp->nb_imports].ordinal = func->ordinal;
Alexandre Julliard15a75252002-07-28 17:54:31 +0000499 imp->imports[imp->nb_imports].ord_only = func->ord_only;
Alexandre Julliardd25878f2002-07-25 00:25:40 +0000500 imp->nb_imports++;
Alexandre Julliardc585a502000-09-27 23:40:43 +0000501 total_imports++;
Eric Pouech5e32d162000-12-26 01:22:34 +0000502 if (imp->delay) total_delayed++;
Alexandre Julliardc585a502000-09-27 23:40:43 +0000503}
Alexandre Julliard000c13a2000-11-09 20:31:18 +0000504
505/* add a symbol to the undef list */
506inline static void add_undef_symbol( const char *name )
507{
508 if (nb_undef_symbols == undef_size)
509 {
510 undef_size += 128;
511 undef_symbols = xrealloc( undef_symbols, undef_size * sizeof(*undef_symbols) );
512 }
513 undef_symbols[nb_undef_symbols++] = xstrdup( name );
514}
515
Jon Griffiths4f12e612000-12-14 22:18:22 +0000516/* remove all the holes in the undefined symbol list; return the number of removed symbols */
517static int remove_symbol_holes(void)
518{
519 int i, off;
520 for (i = off = 0; i < nb_undef_symbols; i++)
521 {
522 if (!undef_symbols[i]) off++;
523 else undef_symbols[i - off] = undef_symbols[i];
524 }
525 nb_undef_symbols -= off;
526 return off;
527}
528
Alexandre Julliard5e47acb2002-05-25 21:09:15 +0000529/* add a symbol to the extra list, but only if needed */
530static int add_extra_symbol( const char **extras, int *count, const char *name )
531{
532 int i;
533
534 if (!find_symbol( name, undef_symbols, nb_undef_symbols ))
535 {
536 /* check if the symbol is being exported by this dll */
537 for (i = 0; i < nb_entry_points; i++)
538 {
539 ORDDEF *odp = EntryPoints[i];
540 if (odp->type == TYPE_STDCALL ||
541 odp->type == TYPE_CDECL ||
542 odp->type == TYPE_VARARGS ||
543 odp->type == TYPE_EXTERN)
544 {
Alexandre Julliard15a75252002-07-28 17:54:31 +0000545 if (odp->name && !strcmp( odp->name, name )) return 0;
Alexandre Julliard5e47acb2002-05-25 21:09:15 +0000546 }
547 }
548 extras[*count] = name;
549 (*count)++;
550 }
551 return 1;
552}
553
Alexandre Julliard000c13a2000-11-09 20:31:18 +0000554/* add the extra undefined symbols that will be contained in the generated spec file itself */
555static void add_extra_undef_symbols(void)
556{
Alexandre Julliardeb9a8632001-12-11 00:50:33 +0000557 const char *extras[10];
Alexandre Julliardbf90f4d2002-05-16 23:17:37 +0000558 int i, count = 0, nb_stubs = 0, nb_regs = 0;
Alexandre Julliard5e47acb2002-05-25 21:09:15 +0000559 int kernel_imports = 0, ntdll_imports = 0;
Alexandre Julliard000c13a2000-11-09 20:31:18 +0000560
561 sort_symbols( undef_symbols, nb_undef_symbols );
562
Alexandre Julliardbf90f4d2002-05-16 23:17:37 +0000563 for (i = 0; i < nb_entry_points; i++)
564 {
565 ORDDEF *odp = EntryPoints[i];
566 if (odp->type == TYPE_STUB) nb_stubs++;
567 if (odp->flags & FLAG_REGISTER) nb_regs++;
568 }
569
Alexandre Julliard000c13a2000-11-09 20:31:18 +0000570 /* add symbols that will be contained in the spec file itself */
571 switch (SpecMode)
572 {
Alexandre Julliard909eff92000-12-15 03:38:11 +0000573 case SPEC_MODE_DLL:
574 break;
Alexandre Julliard000c13a2000-11-09 20:31:18 +0000575 case SPEC_MODE_GUIEXE:
Alexandre Julliard5e47acb2002-05-25 21:09:15 +0000576 kernel_imports += add_extra_symbol( extras, &count, "GetCommandLineA" );
577 kernel_imports += add_extra_symbol( extras, &count, "GetStartupInfoA" );
578 kernel_imports += add_extra_symbol( extras, &count, "GetModuleHandleA" );
Alexandre Julliard000c13a2000-11-09 20:31:18 +0000579 /* fall through */
580 case SPEC_MODE_CUIEXE:
Alexandre Julliard5e47acb2002-05-25 21:09:15 +0000581 kernel_imports += add_extra_symbol( extras, &count, "ExitProcess" );
Alexandre Julliard909eff92000-12-15 03:38:11 +0000582 break;
583 case SPEC_MODE_GUIEXE_UNICODE:
Alexandre Julliard5e47acb2002-05-25 21:09:15 +0000584 kernel_imports += add_extra_symbol( extras, &count, "GetCommandLineA" );
585 kernel_imports += add_extra_symbol( extras, &count, "GetStartupInfoA" );
586 kernel_imports += add_extra_symbol( extras, &count, "GetModuleHandleA" );
Alexandre Julliard000c13a2000-11-09 20:31:18 +0000587 /* fall through */
Alexandre Julliard909eff92000-12-15 03:38:11 +0000588 case SPEC_MODE_CUIEXE_UNICODE:
Alexandre Julliard5e47acb2002-05-25 21:09:15 +0000589 kernel_imports += add_extra_symbol( extras, &count, "ExitProcess" );
Alexandre Julliard000c13a2000-11-09 20:31:18 +0000590 break;
591 }
Eric Pouech5e32d162000-12-26 01:22:34 +0000592 if (nb_delayed)
593 {
Alexandre Julliard5e47acb2002-05-25 21:09:15 +0000594 kernel_imports += add_extra_symbol( extras, &count, "LoadLibraryA" );
595 kernel_imports += add_extra_symbol( extras, &count, "GetProcAddress" );
Eric Pouech5e32d162000-12-26 01:22:34 +0000596 }
Alexandre Julliard5e47acb2002-05-25 21:09:15 +0000597 if (nb_regs)
598 ntdll_imports += add_extra_symbol( extras, &count, "__wine_call_from_32_regs" );
599 if (nb_delayed || nb_stubs)
600 ntdll_imports += add_extra_symbol( extras, &count, "RtlRaiseException" );
Alexandre Julliard909eff92000-12-15 03:38:11 +0000601
Alexandre Julliardbf90f4d2002-05-16 23:17:37 +0000602 /* make sure we import the dlls that contain these functions */
Alexandre Julliard5e47acb2002-05-25 21:09:15 +0000603 if (kernel_imports) add_import_dll( "kernel32", 0 );
604 if (ntdll_imports) add_import_dll( "ntdll", 0 );
Alexandre Julliardeb9a8632001-12-11 00:50:33 +0000605
Alexandre Julliard000c13a2000-11-09 20:31:18 +0000606 if (count)
607 {
608 for (i = 0; i < count; i++) add_undef_symbol( extras[i] );
609 sort_symbols( undef_symbols, nb_undef_symbols );
610 }
611}
612
Alexandre Julliarddaecaba2003-03-16 23:59:48 +0000613/* check if a given imported dll is not needed, taking forwards into account */
614static int check_unused( const struct import* imp )
Alexandre Julliard3570bfd2000-11-13 04:46:34 +0000615{
Alexandre Julliardf08b1862002-08-27 22:29:26 +0000616 int i;
Eric Pouech03350952000-12-06 03:32:26 +0000617 size_t len = strlen(imp->dll);
618 const char *p = strchr( imp->dll, '.' );
619 if (p && !strcasecmp( p, ".dll" )) len = p - imp->dll;
Alexandre Julliard3570bfd2000-11-13 04:46:34 +0000620
621 for (i = Base; i <= Limit; i++)
622 {
623 ORDDEF *odp = Ordinals[i];
Alexandre Julliard470cbf22002-12-15 01:22:40 +0000624 if (!odp || !(odp->flags & FLAG_FORWARD)) continue;
Alexandre Julliard66fed8c2000-12-15 23:04:40 +0000625 if (!strncasecmp( odp->link_name, imp->dll, len ) &&
626 odp->link_name[len] == '.')
Alexandre Julliarddaecaba2003-03-16 23:59:48 +0000627 return 0; /* found a forward, it is used */
Alexandre Julliard3570bfd2000-11-13 04:46:34 +0000628 }
Alexandre Julliarddaecaba2003-03-16 23:59:48 +0000629 return 1;
Alexandre Julliard3570bfd2000-11-13 04:46:34 +0000630}
631
Alexandre Julliard1862a672002-08-01 18:34:12 +0000632/* combine a list of object files with ld into a single object file */
633/* returns the name of the combined file */
634static const char *ldcombine_files( char **argv )
635{
636 int i, len = 0;
637 char *cmd;
638 int fd, err;
Alexandre Julliard1862a672002-08-01 18:34:12 +0000639
Alexandre Julliardf08b1862002-08-27 22:29:26 +0000640 if (output_file_name && output_file_name[0])
641 {
Alexandre Julliard2ee8b5b2003-03-20 21:07:49 +0000642 ld_tmp_file = xmalloc( strlen(output_file_name) + 10 );
Alexandre Julliardf08b1862002-08-27 22:29:26 +0000643 strcpy( ld_tmp_file, output_file_name );
Alexandre Julliard2ee8b5b2003-03-20 21:07:49 +0000644 strcat( ld_tmp_file, ".XXXXXX.o" );
Alexandre Julliardf08b1862002-08-27 22:29:26 +0000645 }
Alexandre Julliard2ee8b5b2003-03-20 21:07:49 +0000646 else ld_tmp_file = xstrdup( "/tmp/winebuild.tmp.XXXXXX.o" );
Alexandre Julliardf08b1862002-08-27 22:29:26 +0000647
Alexandre Julliard2ee8b5b2003-03-20 21:07:49 +0000648 if ((fd = mkstemps( ld_tmp_file, 2 ) == -1)) fatal_error( "could not generate a temp file\n" );
Alexandre Julliard1862a672002-08-01 18:34:12 +0000649 close( fd );
Alexandre Julliard1862a672002-08-01 18:34:12 +0000650 atexit( remove_ld_tmp_file );
651
652 for (i = 0; argv[i]; i++) len += strlen(argv[i]) + 1;
653 cmd = xmalloc( len + strlen(ld_tmp_file) + 10 );
654 sprintf( cmd, "ld -r -o %s", ld_tmp_file );
655 for (i = 0; argv[i]; i++) sprintf( cmd + strlen(cmd), " %s", argv[i] );
656 err = system( cmd );
657 if (err) fatal_error( "ld -r failed with status %d\n", err );
658 free( cmd );
659 return ld_tmp_file;
660}
661
Alexandre Julliard000c13a2000-11-09 20:31:18 +0000662/* read in the list of undefined symbols */
Alexandre Julliard1862a672002-08-01 18:34:12 +0000663void read_undef_symbols( char **argv )
Alexandre Julliard000c13a2000-11-09 20:31:18 +0000664{
665 FILE *f;
666 char buffer[1024];
667 int err;
Alexandre Julliard1862a672002-08-01 18:34:12 +0000668 const char *name;
669
670 if (!argv[0]) return;
Alexandre Julliard000c13a2000-11-09 20:31:18 +0000671
672 undef_size = nb_undef_symbols = 0;
673
Alexandre Julliard1862a672002-08-01 18:34:12 +0000674 /* if we have multiple object files, link them together */
675 if (argv[1]) name = ldcombine_files( argv );
676 else name = argv[0];
677
Alexandre Julliard000c13a2000-11-09 20:31:18 +0000678 sprintf( buffer, "nm -u %s", name );
679 if (!(f = popen( buffer, "r" )))
680 fatal_error( "Cannot execute '%s'\n", buffer );
681
682 while (fgets( buffer, sizeof(buffer), f ))
683 {
684 char *p = buffer + strlen(buffer) - 1;
685 if (p < buffer) continue;
686 if (*p == '\n') *p-- = 0;
Alexandre Julliard6d1f9b02003-04-10 18:36:40 +0000687 p = buffer;
688 while (*p == ' ') p++;
689 if (p[0] == 'U' && p[1] == ' ' && p[2]) p += 2;
Ulrich Weigand0108d832000-12-29 05:17:33 +0000690 add_undef_symbol( p );
Alexandre Julliard000c13a2000-11-09 20:31:18 +0000691 }
Alexandre Julliard28b64db2003-05-14 19:36:28 +0000692 if ((err = pclose( f ))) warning( "nm -u %s error %d\n", name, err );
Alexandre Julliard000c13a2000-11-09 20:31:18 +0000693}
694
Jon Griffiths4f12e612000-12-14 22:18:22 +0000695static void remove_ignored_symbols(void)
696{
697 int i;
698
Alexandre Julliard72e1c642002-12-12 02:20:47 +0000699 if (!ignore_symbols) init_ignored_symbols();
Jon Griffiths4f12e612000-12-14 22:18:22 +0000700 sort_symbols( ignore_symbols, nb_ignore_symbols );
701 for (i = 0; i < nb_undef_symbols; i++)
702 {
703 if (find_symbol( undef_symbols[i], ignore_symbols, nb_ignore_symbols ))
704 {
705 free( undef_symbols[i] );
706 undef_symbols[i] = NULL;
707 }
708 }
709 remove_symbol_holes();
710}
711
Alexandre Julliard000c13a2000-11-09 20:31:18 +0000712/* resolve the imports for a Win32 module */
Dmitry Timoshkov3724de92001-05-22 19:55:51 +0000713int resolve_imports( void )
Alexandre Julliard000c13a2000-11-09 20:31:18 +0000714{
Jon Griffiths4f12e612000-12-14 22:18:22 +0000715 int i, j;
Alexandre Julliard000c13a2000-11-09 20:31:18 +0000716
Alexandre Julliard0a8114c2000-11-12 03:45:55 +0000717 if (nb_undef_symbols == -1) return 0; /* no symbol file specified */
Alexandre Julliard000c13a2000-11-09 20:31:18 +0000718
719 add_extra_undef_symbols();
Jon Griffiths4f12e612000-12-14 22:18:22 +0000720 remove_ignored_symbols();
Alexandre Julliard000c13a2000-11-09 20:31:18 +0000721
722 for (i = 0; i < nb_imports; i++)
723 {
724 struct import *imp = dll_imports[i];
725
726 for (j = 0; j < nb_undef_symbols; j++)
727 {
Alexandre Julliardd25878f2002-07-25 00:25:40 +0000728 struct func *func = find_export( undef_symbols[j], imp->exports, imp->nb_exports );
729 if (func)
Alexandre Julliard000c13a2000-11-09 20:31:18 +0000730 {
Alexandre Julliardd25878f2002-07-25 00:25:40 +0000731 add_import_func( imp, func );
Jon Griffiths4f12e612000-12-14 22:18:22 +0000732 free( undef_symbols[j] );
Alexandre Julliard000c13a2000-11-09 20:31:18 +0000733 undef_symbols[j] = NULL;
734 }
735 }
736 /* remove all the holes in the undef symbols list */
Alexandre Julliarddaecaba2003-03-16 23:59:48 +0000737 if (!remove_symbol_holes() && check_unused( imp ))
738 {
739 /* the dll is not used, get rid of it */
740 warning( "%s imported but no symbols used\n", imp->dll );
741 remove_import_dll( i );
742 i--;
743 }
Alexandre Julliard000c13a2000-11-09 20:31:18 +0000744 }
745 return 1;
746}
Alexandre Julliardc585a502000-09-27 23:40:43 +0000747
748/* output the import table of a Win32 module */
Eric Pouech5e32d162000-12-26 01:22:34 +0000749static int output_immediate_imports( FILE *outfile )
Alexandre Julliardc585a502000-09-27 23:40:43 +0000750{
751 int i, j, pos;
Eric Pouech5e32d162000-12-26 01:22:34 +0000752 int nb_imm = nb_imports - nb_delayed;
Alexandre Julliardc585a502000-09-27 23:40:43 +0000753
Eric Pouech5e32d162000-12-26 01:22:34 +0000754 if (!nb_imm) goto done;
Alexandre Julliardc585a502000-09-27 23:40:43 +0000755
756 /* main import header */
757
Marcus Meissnerc9ea5f12000-11-26 04:02:09 +0000758 fprintf( outfile, "\nstatic struct {\n" );
Alexandre Julliardc585a502000-09-27 23:40:43 +0000759 fprintf( outfile, " struct {\n" );
760 fprintf( outfile, " void *OriginalFirstThunk;\n" );
761 fprintf( outfile, " unsigned int TimeDateStamp;\n" );
762 fprintf( outfile, " unsigned int ForwarderChain;\n" );
763 fprintf( outfile, " const char *Name;\n" );
764 fprintf( outfile, " void *FirstThunk;\n" );
Eric Pouech5e32d162000-12-26 01:22:34 +0000765 fprintf( outfile, " } imp[%d];\n", nb_imm+1 );
766 fprintf( outfile, " const char *data[%d];\n",
767 total_imports - total_delayed + nb_imm );
Alexandre Julliardc585a502000-09-27 23:40:43 +0000768 fprintf( outfile, "} imports = {\n {\n" );
769
770 /* list of dlls */
771
772 for (i = j = 0; i < nb_imports; i++)
773 {
Eric Pouech5e32d162000-12-26 01:22:34 +0000774 if (dll_imports[i]->delay) continue;
Alexandre Julliardc585a502000-09-27 23:40:43 +0000775 fprintf( outfile, " { 0, 0, 0, \"%s\", &imports.data[%d] },\n",
776 dll_imports[i]->dll, j );
777 j += dll_imports[i]->nb_imports + 1;
778 }
Eric Pouech5e32d162000-12-26 01:22:34 +0000779
Alexandre Julliardc585a502000-09-27 23:40:43 +0000780 fprintf( outfile, " { 0, 0, 0, 0, 0 },\n" );
781 fprintf( outfile, " },\n {\n" );
782
783 /* list of imported functions */
784
785 for (i = 0; i < nb_imports; i++)
786 {
Eric Pouech5e32d162000-12-26 01:22:34 +0000787 if (dll_imports[i]->delay) continue;
Alexandre Julliardc585a502000-09-27 23:40:43 +0000788 fprintf( outfile, " /* %s */\n", dll_imports[i]->dll );
789 for (j = 0; j < dll_imports[i]->nb_imports; j++)
Alexandre Julliardd25878f2002-07-25 00:25:40 +0000790 {
791 struct func *import = &dll_imports[i]->imports[j];
Alexandre Julliard15a75252002-07-28 17:54:31 +0000792 if (!import->ord_only)
793 {
794 unsigned short ord = import->ordinal;
795 fprintf( outfile, " \"\\%03o\\%03o%s\",\n",
796 *(unsigned char *)&ord, *((unsigned char *)&ord + 1), import->name );
797 }
798 else
799 fprintf( outfile, " (char *)%d,\n", import->ordinal );
Alexandre Julliardd25878f2002-07-25 00:25:40 +0000800 }
Alexandre Julliardc585a502000-09-27 23:40:43 +0000801 fprintf( outfile, " 0,\n" );
802 }
803 fprintf( outfile, " }\n};\n\n" );
804
805 /* thunks for imported functions */
806
807 fprintf( outfile, "#ifndef __GNUC__\nstatic void __asm__dummy_import(void) {\n#endif\n\n" );
Eric Pouech5e32d162000-12-26 01:22:34 +0000808 pos = 20 * (nb_imm + 1); /* offset of imports.data from start of imports */
Josh DuBois0b64cfb2001-02-13 02:06:38 +0000809 fprintf( outfile, "asm(\".data\\n\\t.align %d\\n\"\n", get_alignment(8) );
Eric Pouech5e32d162000-12-26 01:22:34 +0000810 for (i = 0; i < nb_imports; i++)
Alexandre Julliardc585a502000-09-27 23:40:43 +0000811 {
Eric Pouech5e32d162000-12-26 01:22:34 +0000812 if (dll_imports[i]->delay) continue;
Alexandre Julliardc585a502000-09-27 23:40:43 +0000813 for (j = 0; j < dll_imports[i]->nb_imports; j++, pos += 4)
814 {
Alexandre Julliardd25878f2002-07-25 00:25:40 +0000815 struct func *import = &dll_imports[i]->imports[j];
816 fprintf( outfile, " \"\\t" __ASM_FUNC("%s") "\\n\"\n", import->name );
817 fprintf( outfile, " \"\\t.globl " __ASM_NAME("%s") "\\n\"\n", import->name );
818 fprintf( outfile, " \"" __ASM_NAME("%s") ":\\n\\t", import->name);
Ulrich Weigand0108d832000-12-29 05:17:33 +0000819
820#if defined(__i386__)
Alexandre Julliardd25878f2002-07-25 00:25:40 +0000821 if (strstr( import->name, "__wine_call_from_16" ))
Ulrich Weigand0108d832000-12-29 05:17:33 +0000822 fprintf( outfile, ".byte 0x2e\\n\\tjmp *(imports+%d)\\n\\tnop\\n", pos );
Marcus Meissnerc9ea5f12000-11-26 04:02:09 +0000823 else
Ulrich Weigand0108d832000-12-29 05:17:33 +0000824 fprintf( outfile, "jmp *(imports+%d)\\n\\tmovl %%esi,%%esi\\n", pos );
825#elif defined(__sparc__)
826 if ( !UsePIC )
827 {
828 fprintf( outfile, "sethi %%hi(imports+%d), %%g1\\n\\t", pos );
829 fprintf( outfile, "ld [%%g1+%%lo(imports+%d)], %%g1\\n\\t", pos );
830 fprintf( outfile, "jmp %%g1\\n\\tnop\\n" );
831 }
832 else
833 {
834 /* Hmpf. Stupid sparc assembler always interprets global variable
835 names as GOT offsets, so we have to do it the long way ... */
836 fprintf( outfile, "save %%sp, -96, %%sp\\n" );
837 fprintf( outfile, "0:\\tcall 1f\\n\\tnop\\n" );
838 fprintf( outfile, "1:\\tsethi %%hi(imports+%d-0b), %%g1\\n\\t", pos );
839 fprintf( outfile, "or %%g1, %%lo(imports+%d-0b), %%g1\\n\\t", pos );
840 fprintf( outfile, "ld [%%g1+%%o7], %%g1\\n\\t" );
841 fprintf( outfile, "jmp %%g1\\n\\trestore\\n" );
842 }
Josh DuBois0b64cfb2001-02-13 02:06:38 +0000843
Alexandre Julliard346ca952003-08-13 21:57:42 +0000844#elif defined(__powerpc__)
845 fprintf(outfile, "\taddi %s, %s, -0x4\\n\"\n", ppc_reg[1], ppc_reg[1]);
846 fprintf(outfile, "\t\"\\tstw %s, 0(%s)\\n\"\n", ppc_reg[9], ppc_reg[1]);
847 fprintf(outfile, "\t\"\\taddi %s, %s, -0x4\\n\"\n", ppc_reg[1], ppc_reg[1]);
848 fprintf(outfile, "\t\"\\tstw %s, 0(%s)\\n\"\n", ppc_reg[8], ppc_reg[1]);
849 fprintf(outfile, "\t\"\\taddi %s, %s, -0x4\\n\"\n", ppc_reg[1], ppc_reg[1]);
850 fprintf(outfile, "\t\"\\tstw %s, 0(%s)\\n\"\n", ppc_reg[7], ppc_reg[1]);
Josh DuBois0b64cfb2001-02-13 02:06:38 +0000851
Alexandre Julliard346ca952003-08-13 21:57:42 +0000852 fprintf(outfile, "\t\"\\tlis %s, " ppc_high(__ASM_NAME("imports") "+ %d") "\\n\"\n", ppc_reg[9], pos);
853 fprintf(outfile, "\t\"\\tla %s, " ppc_low (__ASM_NAME("imports") "+ %d") "(%s)\\n\"\n", ppc_reg[8], pos, ppc_reg[9]);
854 fprintf(outfile, "\t\"\\tlwz %s, 0(%s)\\n\"\n", ppc_reg[7], ppc_reg[8]);
855 fprintf(outfile, "\t\"\\tmctr %s\\n\"\n", ppc_reg[7]);
Josh DuBois0b64cfb2001-02-13 02:06:38 +0000856
Alexandre Julliard346ca952003-08-13 21:57:42 +0000857 fprintf(outfile, "\t\"\\tlwz %s, 0(%s)\\n\"\n", ppc_reg[7], ppc_reg[1]);
858 fprintf(outfile, "\t\"\\taddi %s, %s, 0x4\\n\"\n", ppc_reg[1], ppc_reg[1]);
859 fprintf(outfile, "\t\"\\tlwz %s, 0(%s)\\n\"\n", ppc_reg[8], ppc_reg[1]);
860 fprintf(outfile, "\t\"\\taddi %s, %s, 0x4\\n\"\n", ppc_reg[1], ppc_reg[1]);
861 fprintf(outfile, "\t\"\\tlwz %s, 0(%s)\\n\"\n", ppc_reg[9], ppc_reg[1]);
862 fprintf(outfile, "\t\"\\taddi %s, %s, 0x4\\n\"\n", ppc_reg[1], ppc_reg[1]);
Josh DuBois0b64cfb2001-02-13 02:06:38 +0000863 fprintf(outfile, "\t\"\\tbctr\\n");
Ulrich Weigand0108d832000-12-29 05:17:33 +0000864#else
865#error You need to define import thunks for your architecture!
866#endif
867 fprintf( outfile, "\"\n" );
Alexandre Julliardc585a502000-09-27 23:40:43 +0000868 }
Ulrich Weigand775fc632000-12-29 17:44:40 +0000869 pos += 4;
Alexandre Julliardc585a502000-09-27 23:40:43 +0000870 }
Gregg Mattinson803eb162002-07-05 00:20:42 +0000871 fprintf( outfile, "\".section\\t\\\".text\\\"\");\n#ifndef __GNUC__\n}\n#endif\n\n" );
Alexandre Julliardc585a502000-09-27 23:40:43 +0000872
873 done:
Eric Pouech5e32d162000-12-26 01:22:34 +0000874 return nb_imm;
875}
876
877/* output the delayed import table of a Win32 module */
878static int output_delayed_imports( FILE *outfile )
879{
880 int i, idx, j, pos;
881
882 if (!nb_delayed) goto done;
883
884 for (i = 0; i < nb_imports; i++)
885 {
886 if (!dll_imports[i]->delay) continue;
887 fprintf( outfile, "static void *__wine_delay_imp_%d_hmod;\n", i);
888 for (j = 0; j < dll_imports[i]->nb_imports; j++)
889 {
890 fprintf( outfile, "void __wine_delay_imp_%d_%s();\n",
Alexandre Julliardd25878f2002-07-25 00:25:40 +0000891 i, dll_imports[i]->imports[j].name );
Eric Pouech5e32d162000-12-26 01:22:34 +0000892 }
893 }
894 fprintf( outfile, "\n" );
895 fprintf( outfile, "static struct {\n" );
896 fprintf( outfile, " struct ImgDelayDescr {\n" );
897 fprintf( outfile, " unsigned int grAttrs;\n" );
898 fprintf( outfile, " const char *szName;\n" );
899 fprintf( outfile, " void **phmod;\n" );
900 fprintf( outfile, " void **pIAT;\n" );
901 fprintf( outfile, " const char **pINT;\n" );
902 fprintf( outfile, " void* pBoundIAT;\n" );
903 fprintf( outfile, " void* pUnloadIAT;\n" );
904 fprintf( outfile, " unsigned long dwTimeStamp;\n" );
905 fprintf( outfile, " } imp[%d];\n", nb_delayed );
906 fprintf( outfile, " void *IAT[%d];\n", total_delayed );
907 fprintf( outfile, " const char *INT[%d];\n", total_delayed );
908 fprintf( outfile, "} delay_imports = {\n" );
909 fprintf( outfile, " {\n" );
910 for (i = j = 0; i < nb_imports; i++)
911 {
912 if (!dll_imports[i]->delay) continue;
913 fprintf( outfile, " { 0, \"%s\", &__wine_delay_imp_%d_hmod, &delay_imports.IAT[%d], &delay_imports.INT[%d], 0, 0, 0 },\n",
914 dll_imports[i]->dll, i, j, j );
915 j += dll_imports[i]->nb_imports;
916 }
917 fprintf( outfile, " },\n {\n" );
918 for (i = 0; i < nb_imports; i++)
919 {
920 if (!dll_imports[i]->delay) continue;
921 fprintf( outfile, " /* %s */\n", dll_imports[i]->dll );
922 for (j = 0; j < dll_imports[i]->nb_imports; j++)
923 {
Alexandre Julliardd25878f2002-07-25 00:25:40 +0000924 fprintf( outfile, " &__wine_delay_imp_%d_%s,\n", i, dll_imports[i]->imports[j].name);
Eric Pouech5e32d162000-12-26 01:22:34 +0000925 }
926 }
927 fprintf( outfile, " },\n {\n" );
928 for (i = 0; i < nb_imports; i++)
929 {
930 if (!dll_imports[i]->delay) continue;
931 fprintf( outfile, " /* %s */\n", dll_imports[i]->dll );
932 for (j = 0; j < dll_imports[i]->nb_imports; j++)
933 {
Alexandre Julliard15a75252002-07-28 17:54:31 +0000934 struct func *import = &dll_imports[i]->imports[j];
935 if (import->ord_only)
936 fprintf( outfile, " (char *)%d,\n", import->ordinal );
937 else
938 fprintf( outfile, " \"%s\",\n", import->name );
Eric Pouech5e32d162000-12-26 01:22:34 +0000939 }
940 }
941 fprintf( outfile, " }\n};\n\n" );
942
Vincent Béron9a624912002-05-31 23:06:46 +0000943 /* check if there's some stub defined. if so, exception struct
944 * is already defined, so don't emit it twice
Eric Pouech5e32d162000-12-26 01:22:34 +0000945 */
946 for (i = 0; i < nb_entry_points; i++) if (EntryPoints[i]->type == TYPE_STUB) break;
947
948 if (i == nb_entry_points) {
949 fprintf( outfile, "struct exc_record {\n" );
950 fprintf( outfile, " unsigned int code, flags;\n" );
951 fprintf( outfile, " void *rec, *addr;\n" );
952 fprintf( outfile, " unsigned int params;\n" );
953 fprintf( outfile, " const void *info[15];\n" );
954 fprintf( outfile, "};\n\n" );
955 fprintf( outfile, "extern void __stdcall RtlRaiseException( struct exc_record * );\n" );
956 }
957
958 fprintf( outfile, "extern void * __stdcall LoadLibraryA(const char*);\n");
959 fprintf( outfile, "extern void * __stdcall GetProcAddress(void *, const char*);\n");
960 fprintf( outfile, "\n" );
961
Ulrich Weigand3e08d462001-01-02 22:22:12 +0000962 fprintf( outfile, "void *__stdcall __wine_delay_load( int idx_nr )\n" );
Eric Pouech5e32d162000-12-26 01:22:34 +0000963 fprintf( outfile, "{\n" );
Ulrich Weigand3e08d462001-01-02 22:22:12 +0000964 fprintf( outfile, " int idx = idx_nr >> 16, nr = idx_nr & 0xffff;\n" );
965 fprintf( outfile, " struct ImgDelayDescr *imd = delay_imports.imp + idx;\n" );
966 fprintf( outfile, " void **pIAT = imd->pIAT + nr;\n" );
967 fprintf( outfile, " const char** pINT = imd->pINT + nr;\n" );
Eric Pouech5e32d162000-12-26 01:22:34 +0000968 fprintf( outfile, " void *fn;\n\n" );
969
970 fprintf( outfile, " if (!*imd->phmod) *imd->phmod = LoadLibraryA(imd->szName);\n" );
Alexandre Julliard15a75252002-07-28 17:54:31 +0000971 fprintf( outfile, " if (*imd->phmod && (fn = GetProcAddress(*imd->phmod, *pINT)))\n");
Eric Pouech5e32d162000-12-26 01:22:34 +0000972 fprintf( outfile, " /* patch IAT with final value */\n" );
973 fprintf( outfile, " return *pIAT = fn;\n" );
974 fprintf( outfile, " else {\n");
975 fprintf( outfile, " struct exc_record rec;\n" );
976 fprintf( outfile, " rec.code = 0x80000100;\n" );
977 fprintf( outfile, " rec.flags = 1;\n" );
978 fprintf( outfile, " rec.rec = 0;\n" );
979 fprintf( outfile, " rec.params = 2;\n" );
980 fprintf( outfile, " rec.info[0] = imd->szName;\n" );
981 fprintf( outfile, " rec.info[1] = *pINT + 2;\n" );
982 fprintf( outfile, "#ifdef __GNUC__\n" );
983 fprintf( outfile, " rec.addr = __builtin_return_address(1);\n" );
984 fprintf( outfile, "#else\n" );
985 fprintf( outfile, " rec.addr = 0;\n" );
986 fprintf( outfile, "#endif\n" );
987 fprintf( outfile, " for (;;) RtlRaiseException( &rec );\n" );
988 fprintf( outfile, " return 0; /* shouldn't go here */\n" );
989 fprintf( outfile, " }\n}\n\n" );
990
991 fprintf( outfile, "#ifndef __GNUC__\n" );
992 fprintf( outfile, "static void __asm__dummy_delay_import(void) {\n" );
993 fprintf( outfile, "#endif\n" );
Ulrich Weigand3e08d462001-01-02 22:22:12 +0000994
Josh DuBois0b64cfb2001-02-13 02:06:38 +0000995 fprintf( outfile, "asm(\".align %d\\n\"\n", get_alignment(8) );
Ulrich Weigand3e08d462001-01-02 22:22:12 +0000996 fprintf( outfile, " \"\\t" __ASM_FUNC("__wine_delay_load_asm") "\\n\"\n" );
Alexandre Julliard65c6d382002-07-22 20:47:11 +0000997 fprintf( outfile, " \"" __ASM_NAME("__wine_delay_load_asm") ":\\n\"\n" );
Ulrich Weigand3e08d462001-01-02 22:22:12 +0000998#if defined(__i386__)
999 fprintf( outfile, " \"\\tpushl %%ecx\\n\\tpushl %%edx\\n\\tpushl %%eax\\n\"\n" );
1000 fprintf( outfile, " \"\\tcall __wine_delay_load\\n\"\n" );
1001 fprintf( outfile, " \"\\tpopl %%edx\\n\\tpopl %%ecx\\n\\tjmp *%%eax\\n\"\n" );
1002#elif defined(__sparc__)
1003 fprintf( outfile, " \"\\tsave %%sp, -96, %%sp\\n\"\n" );
1004 fprintf( outfile, " \"\\tcall __wine_delay_load\\n\"\n" );
1005 fprintf( outfile, " \"\\tmov %%g1, %%o0\\n\"\n" );
1006 fprintf( outfile, " \"\\tjmp %%o0\\n\\trestore\\n\"\n" );
Alexandre Julliard346ca952003-08-13 21:57:42 +00001007#elif defined(__powerpc__)
Marcus Meissner76787912002-08-20 00:00:49 +00001008 /* Save all callee saved registers into a stackframe. */
Alexandre Julliard346ca952003-08-13 21:57:42 +00001009 fprintf( outfile, " \"\\tstwu %s, -48, %s\\n\"\n", ppc_reg[1], ppc_reg[1]);
1010 fprintf( outfile, " \"\\tstw %s, 4, %s\\n\"\n", ppc_reg[3], ppc_reg[1]);
1011 fprintf( outfile, " \"\\tstw %s, 8, %s\\n\"\n", ppc_reg[4], ppc_reg[1]);
1012 fprintf( outfile, " \"\\tstw %s, 12, %s\\n\"\n", ppc_reg[5], ppc_reg[1]);
1013 fprintf( outfile, " \"\\tstw %s, 16, %s\\n\"\n", ppc_reg[6], ppc_reg[1]);
1014 fprintf( outfile, " \"\\tstw %s, 20, %s\\n\"\n", ppc_reg[7], ppc_reg[1]);
1015 fprintf( outfile, " \"\\tstw %s, 24, %s\\n\"\n", ppc_reg[8], ppc_reg[1]);
1016 fprintf( outfile, " \"\\tstw %s, 28, %s\\n\"\n", ppc_reg[9], ppc_reg[1]);
1017 fprintf( outfile, " \"\\tstw %s, 32, %s\\n\"\n", ppc_reg[10], ppc_reg[1]);
1018 fprintf( outfile, " \"\\tstw %s, 36, %s\\n\"\n", ppc_reg[11], ppc_reg[1]);
1019 fprintf( outfile, " \"\\tstw %s, 40, %s\\n\"\n", ppc_reg[12], ppc_reg[1]);
Marcus Meissner76787912002-08-20 00:00:49 +00001020
1021 /* r0 -> r3 (arg1) */
Alexandre Julliard346ca952003-08-13 21:57:42 +00001022 fprintf( outfile, " \"\\tmr %s, %s\\n\"\n", ppc_reg[3], ppc_reg[0]);
Marcus Meissner76787912002-08-20 00:00:49 +00001023
1024 /* save return address */
Alexandre Julliard346ca952003-08-13 21:57:42 +00001025 fprintf( outfile, " \"\\tmflr %s\\n\"\n", ppc_reg[0]);
1026 fprintf( outfile, " \"\\tstw %s, 44, %s\\n\"\n", ppc_reg[0], ppc_reg[1]);
Marcus Meissner76787912002-08-20 00:00:49 +00001027
1028 /* Call the __wine_delay_load function, arg1 is arg1. */
Alexandre Julliard346ca952003-08-13 21:57:42 +00001029 fprintf( outfile, " \"\\tbl " __ASM_NAME("__wine_delay_load") "\\n\"\n");
Marcus Meissner76787912002-08-20 00:00:49 +00001030
1031 /* Load return value from call into ctr register */
Alexandre Julliard346ca952003-08-13 21:57:42 +00001032 fprintf( outfile, " \"\\tmtctr %s\\n\"\n", ppc_reg[3]);
Marcus Meissner76787912002-08-20 00:00:49 +00001033
1034 /* restore all saved registers and drop stackframe. */
Alexandre Julliard346ca952003-08-13 21:57:42 +00001035 fprintf( outfile, " \"\\tlwz %s, 4, %s\\n\"\n", ppc_reg[3], ppc_reg[1]);
1036 fprintf( outfile, " \"\\tlwz %s, 8, %s\\n\"\n", ppc_reg[4], ppc_reg[1]);
1037 fprintf( outfile, " \"\\tlwz %s, 12, %s\\n\"\n", ppc_reg[5], ppc_reg[1]);
1038 fprintf( outfile, " \"\\tlwz %s, 16, %s\\n\"\n", ppc_reg[6], ppc_reg[1]);
1039 fprintf( outfile, " \"\\tlwz %s, 20, %s\\n\"\n", ppc_reg[7], ppc_reg[1]);
1040 fprintf( outfile, " \"\\tlwz %s, 24, %s\\n\"\n", ppc_reg[8], ppc_reg[1]);
1041 fprintf( outfile, " \"\\tlwz %s, 28, %s\\n\"\n", ppc_reg[9], ppc_reg[1]);
1042 fprintf( outfile, " \"\\tlwz %s, 32, %s\\n\"\n", ppc_reg[10], ppc_reg[1]);
1043 fprintf( outfile, " \"\\tlwz %s, 36, %s\\n\"\n", ppc_reg[11], ppc_reg[1]);
1044 fprintf( outfile, " \"\\tlwz %s, 40, %s\\n\"\n", ppc_reg[12], ppc_reg[1]);
Marcus Meissner76787912002-08-20 00:00:49 +00001045
Alexandre Julliard346ca952003-08-13 21:57:42 +00001046 /* Load return value from call into return register */
1047 fprintf( outfile, " \"\\tlwz %s, 44, %s\\n\"\n", ppc_reg[0], ppc_reg[1]);
1048 fprintf( outfile, " \"\\tmtlr %s\\n\"\n", ppc_reg[0]);
1049 fprintf( outfile, " \"\\taddi %s, %s, 48\\n\"\n", ppc_reg[1], ppc_reg[1]);
1050
1051 /* branch to ctr register. */
1052 fprintf( outfile, "\"bctr\\n\"\n");
Ulrich Weigand3e08d462001-01-02 22:22:12 +00001053#else
1054#error You need to defined delayed import thunks for your architecture!
1055#endif
1056
Eric Pouech5e32d162000-12-26 01:22:34 +00001057 for (i = idx = 0; i < nb_imports; i++)
1058 {
Eric Pouech5e32d162000-12-26 01:22:34 +00001059 if (!dll_imports[i]->delay) continue;
Ulrich Weigand3e08d462001-01-02 22:22:12 +00001060 for (j = 0; j < dll_imports[i]->nb_imports; j++)
1061 {
1062 char buffer[128];
Alexandre Julliardd25878f2002-07-25 00:25:40 +00001063 sprintf( buffer, "__wine_delay_imp_%d_%s", i, dll_imports[i]->imports[j].name );
Ulrich Weigand3e08d462001-01-02 22:22:12 +00001064 fprintf( outfile, " \"\\t" __ASM_FUNC("%s") "\\n\"\n", buffer );
Alexandre Julliard65c6d382002-07-22 20:47:11 +00001065 fprintf( outfile, " \"" __ASM_NAME("%s") ":\\n\"\n", buffer );
Ulrich Weigand3e08d462001-01-02 22:22:12 +00001066#if defined(__i386__)
1067 fprintf( outfile, " \"\\tmovl $%d, %%eax\\n\"\n", (idx << 16) | j );
1068 fprintf( outfile, " \"\\tjmp __wine_delay_load_asm\\n\"\n" );
1069#elif defined(__sparc__)
1070 fprintf( outfile, " \"\\tset %d, %%g1\\n\"\n", (idx << 16) | j );
1071 fprintf( outfile, " \"\\tb,a __wine_delay_load_asm\\n\"\n" );
Alexandre Julliard346ca952003-08-13 21:57:42 +00001072#elif defined(__powerpc__)
1073 /* g0 is a function scratch register or so I understand. */
1074 /* First load the upper half-word, and then the lower part */
1075 fprintf( outfile, " \"\\lis %s, %d\\n\"\n", ppc_reg[0], idx);
1076 fprintf( outfile, " \"\\taddi %s, %s, %d\\n\"\n", ppc_reg[0], ppc_reg[0], j);
1077 fprintf( outfile, " \"\\tb " __ASM_NAME("__wine_delay_load_asm") "\\n\"\n");
Ulrich Weigand3e08d462001-01-02 22:22:12 +00001078#else
1079#error You need to defined delayed import thunks for your architecture!
1080#endif
1081 }
1082 idx++;
1083 }
Eric Pouech5e32d162000-12-26 01:22:34 +00001084
Josh DuBois0b64cfb2001-02-13 02:06:38 +00001085 fprintf( outfile, "\n \".data\\n\\t.align %d\\n\"\n", get_alignment(8) );
Ulrich Weigand3e08d462001-01-02 22:22:12 +00001086 pos = nb_delayed * 32;
1087 for (i = 0; i < nb_imports; i++)
1088 {
1089 if (!dll_imports[i]->delay) continue;
Eric Pouech5e32d162000-12-26 01:22:34 +00001090 for (j = 0; j < dll_imports[i]->nb_imports; j++, pos += 4)
1091 {
Alexandre Julliardd25878f2002-07-25 00:25:40 +00001092 struct func *import = &dll_imports[i]->imports[j];
1093 fprintf( outfile, " \"\\t" __ASM_FUNC("%s") "\\n\"\n", import->name );
1094 fprintf( outfile, " \"\\t.globl " __ASM_NAME("%s") "\\n\"\n", import->name );
Marcus Meissner76787912002-08-20 00:00:49 +00001095 fprintf( outfile, " \"" __ASM_NAME("%s") ":\\n\\t\"", import->name);
Ulrich Weigand3e08d462001-01-02 22:22:12 +00001096#if defined(__i386__)
Alexandre Julliardd25878f2002-07-25 00:25:40 +00001097 if (strstr( import->name, "__wine_call_from_16" ))
Marcus Meissner76787912002-08-20 00:00:49 +00001098 fprintf( outfile, "\".byte 0x2e\\n\\tjmp *(delay_imports+%d)\\n\\tnop\\n\"", pos );
Ulrich Weigand3e08d462001-01-02 22:22:12 +00001099 else
Marcus Meissner76787912002-08-20 00:00:49 +00001100 fprintf( outfile, "\"jmp *(delay_imports+%d)\\n\\tmovl %%esi,%%esi\\n\"", pos );
Ulrich Weigand3e08d462001-01-02 22:22:12 +00001101#elif defined(__sparc__)
1102 if ( !UsePIC )
1103 {
Marcus Meissner76787912002-08-20 00:00:49 +00001104 fprintf( outfile, "\"sethi %%hi(delay_imports+%d), %%g1\\n\\t\"", pos );
1105 fprintf( outfile, "\"ld [%%g1+%%lo(delay_imports+%d)], %%g1\\n\\t\"", pos );
1106 fprintf( outfile, "\"jmp %%g1\\n\\tnop\\n\"" );
Ulrich Weigand3e08d462001-01-02 22:22:12 +00001107 }
1108 else
1109 {
1110 /* Hmpf. Stupid sparc assembler always interprets global variable
1111 names as GOT offsets, so we have to do it the long way ... */
Eric Frias1046fe32002-11-06 22:07:38 +00001112 fprintf( outfile, "\"save %%sp, -96, %%sp\\n\"" );
1113 fprintf( outfile, "\"0:\\tcall 1f\\n\\tnop\\n\"" );
1114 fprintf( outfile, "\"1:\\tsethi %%hi(delay_imports+%d-0b), %%g1\\n\\t\"", pos );
1115 fprintf( outfile, "\"or %%g1, %%lo(delay_imports+%d-0b), %%g1\\n\\t\"", pos );
1116 fprintf( outfile, "\"ld [%%g1+%%o7], %%g1\\n\\t\"" );
1117 fprintf( outfile, "\"jmp %%g1\\n\\trestore\\n\"" );
Ulrich Weigand3e08d462001-01-02 22:22:12 +00001118 }
Josh DuBois0b64cfb2001-02-13 02:06:38 +00001119
Alexandre Julliard346ca952003-08-13 21:57:42 +00001120#elif defined(__powerpc__)
1121 fprintf( outfile, "\t addi %s, %s, -0x4\\n\"\n", ppc_reg[1], ppc_reg[1]);
1122 fprintf( outfile, "\t\"\\tstw %s, 0(%s)\\n\"\n", ppc_reg[9], ppc_reg[1]);
1123 fprintf( outfile, "\t\"\\taddi %s, %s, -0x4\\n\"\n", ppc_reg[1], ppc_reg[1]);
1124 fprintf( outfile, "\t\"\\tstw %s, 0(%s)\\n\"\n", ppc_reg[8], ppc_reg[1]);
1125 fprintf( outfile, "\t\"\\taddi %s, %s, -0x4\\n\"\n", ppc_reg[1], ppc_reg[1]);
1126 fprintf( outfile, "\t\"\\tstw %s, 0(%s)\\n\"\n", ppc_reg[7], ppc_reg[1]);
1127 fprintf( outfile, "\t\"\\tlis %s " ppc_high(__ASM_NAME("imports") "+ %d") "\\n\"\n", ppc_reg[9], pos);
1128 fprintf( outfile, "\t\"\\tla %s " ppc_low (__ASM_NAME("imports") "+ %d") "(%s)\\n\"\n", ppc_reg[8], pos, ppc_reg[9]);
1129 fprintf( outfile, "\t\"\\tlwz %s, 0(%s)\\n\"\n", ppc_reg[7], ppc_reg[8]);
1130 fprintf( outfile, "\t\"\\tmtctr %s\\n\"\n", ppc_reg[7]);
Marcus Meissner76787912002-08-20 00:00:49 +00001131
Alexandre Julliard346ca952003-08-13 21:57:42 +00001132 fprintf( outfile, "\t\"\\tlwz %s, 0(%s)\\n\"\n", ppc_reg[7], ppc_reg[1]);
1133 fprintf( outfile, "\t\"\\taddi %s, %s, 0x4\\n\"\n", ppc_reg[1], ppc_reg[1]);
1134 fprintf( outfile, "\t\"\\tlwz %s, 0(%s)\\n\"\n", ppc_reg[8], ppc_reg[1]);
1135 fprintf( outfile, "\t\"\\taddi %s, %s, 0x4\\n\"\n", ppc_reg[1], ppc_reg[1]);
1136 fprintf( outfile, "\t\"\\tlwz %s, 0(%s)\\n\"\n", ppc_reg[9], ppc_reg[1]);
1137 fprintf( outfile, "\t\"\\taddi %s, %s, 0x4\\n\"\n", ppc_reg[1], ppc_reg[1]);
1138 fprintf( outfile, "\t\"\\tbctr\\n");
Ulrich Weigand3e08d462001-01-02 22:22:12 +00001139#else
Josh DuBois0b64cfb2001-02-13 02:06:38 +00001140#error You need to define delayed import thunks for your architecture!
Ulrich Weigand3e08d462001-01-02 22:22:12 +00001141#endif
Marcus Meissner76787912002-08-20 00:00:49 +00001142 fprintf( outfile, "\n" );
Eric Pouech5e32d162000-12-26 01:22:34 +00001143 }
Eric Pouech5e32d162000-12-26 01:22:34 +00001144 }
Gregg Mattinson803eb162002-07-05 00:20:42 +00001145 fprintf( outfile, "\".section \\\".text\\\"\");\n" );
Eric Pouech5e32d162000-12-26 01:22:34 +00001146 fprintf( outfile, "#ifndef __GNUC__\n" );
1147 fprintf( outfile, "}\n" );
1148 fprintf( outfile, "#endif\n" );
1149 fprintf( outfile, "\n" );
1150
1151 done:
1152 return nb_delayed;
1153}
1154
1155/* output the import and delayed import tables of a Win32 module
1156 * returns number of DLLs exported in 'immediate' mode
1157 */
1158int output_imports( FILE *outfile )
1159{
1160 output_delayed_imports( outfile );
1161 return output_immediate_imports( outfile );
Alexandre Julliardc585a502000-09-27 23:40:43 +00001162}