Put generated import table code into .text segment.
[wine/dcerpc.git] / tools / winebuild / import.c
blobec17fe81bfb77a64935da635ff2811c97d2425b3
1 /*
2 * DLL imports support
4 * Copyright 2000, 2004 Alexandre Julliard
5 * Copyright 2000 Eric Pouech
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.
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.
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
22 #include "config.h"
23 #include "wine/port.h"
25 #include <ctype.h>
26 #include <fcntl.h>
27 #include <stdio.h>
28 #include <string.h>
29 #include <stdarg.h>
30 #ifdef HAVE_UNISTD_H
31 # include <unistd.h>
32 #endif
34 #include "windef.h"
35 #include "winbase.h"
36 #include "build.h"
38 struct import
40 DLLSPEC *spec; /* description of the imported dll */
41 int delay; /* delay or not dll loading ? */
42 ORDDEF **exports; /* functions exported from this dll */
43 int nb_exports; /* number of exported functions */
44 ORDDEF **imports; /* functions we want to import from this dll */
45 int nb_imports; /* number of imported functions */
48 static char **undef_symbols; /* list of undefined symbols */
49 static int nb_undef_symbols = -1;
50 static int undef_size;
52 static char **ignore_symbols; /* list of symbols to ignore */
53 static int nb_ignore_symbols;
54 static int ignore_size;
56 static char *ld_tmp_file; /* ld temp file name */
58 static struct import **dll_imports = NULL;
59 static int nb_imports = 0; /* number of imported dlls (delayed or not) */
60 static int nb_delayed = 0; /* number of delayed dlls */
61 static int total_imports = 0; /* total number of imported functions */
62 static int total_delayed = 0; /* total number of imported functions in delayed DLLs */
64 /* list of symbols that are ignored by default */
65 static const char * const default_ignored_symbols[] =
67 "abs",
68 "acos",
69 "asin",
70 "atan",
71 "atan2",
72 "atof",
73 "atoi",
74 "atol",
75 "bsearch",
76 "ceil",
77 "cos",
78 "cosh",
79 "exp",
80 "fabs",
81 "floor",
82 "fmod",
83 "frexp",
84 "labs",
85 "log",
86 "log10",
87 "memchr",
88 "memcmp",
89 "memcpy",
90 "memmove",
91 "memset",
92 "modf",
93 "pow",
94 "qsort",
95 "sin",
96 "sinh",
97 "sqrt",
98 "strcat",
99 "strchr",
100 "strcmp",
101 "strcpy",
102 "strcspn",
103 "strlen",
104 "strncat",
105 "strncmp",
106 "strncpy",
107 "strpbrk",
108 "strrchr",
109 "strspn",
110 "strstr",
111 "tan",
112 "tanh"
115 #ifdef __powerpc__
116 # ifdef __APPLE__
117 # define ppc_high(mem) "ha16(" mem ")"
118 # define ppc_low(mem) "lo16(" mem ")"
119 static const char * const ppc_reg[32] = { "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7",
120 "r8", "r9", "r10","r11","r12","r13","r14","r15",
121 "r16","r17","r18","r19","r20","r21","r22","r23",
122 "r24","r25","r26","r27","r28","r29","r30","r31" };
123 # else /* __APPLE__ */
124 # define ppc_high(mem) "(" mem ")@hi"
125 # define ppc_low(mem) "(" mem ")@l"
126 static const char * const ppc_reg[32] = { "0", "1", "2", "3", "4", "5", "6", "7",
127 "8", "9", "10","11","12","13","14","15",
128 "16","17","18","19","20","21","22","23",
129 "24","25","26","27","28","29","30","31" };
130 # endif /* __APPLE__ */
131 #endif /* __powerpc__ */
133 /* compare function names; helper for resolve_imports */
134 static int name_cmp( const void *name, const void *entry )
136 return strcmp( *(const char* const *)name, *(const char* const *)entry );
139 /* compare function names; helper for resolve_imports */
140 static int func_cmp( const void *func1, const void *func2 )
142 const ORDDEF *odp1 = *(const ORDDEF * const *)func1;
143 const ORDDEF *odp2 = *(const ORDDEF * const *)func2;
144 return strcmp( odp1->name ? odp1->name : odp1->export_name,
145 odp2->name ? odp2->name : odp2->export_name );
148 /* locate a symbol in a (sorted) list */
149 inline static const char *find_symbol( const char *name, char **table, int size )
151 char **res = NULL;
153 if (table) {
154 res = bsearch( &name, table, size, sizeof(*table), name_cmp );
157 return res ? *res : NULL;
160 /* locate an export in a (sorted) export list */
161 inline static ORDDEF *find_export( const char *name, ORDDEF **table, int size )
163 ORDDEF func, *odp, **res = NULL;
165 func.name = (char *)name;
166 func.ordinal = -1;
167 odp = &func;
168 if (table) res = bsearch( &odp, table, size, sizeof(*table), func_cmp );
169 return res ? *res : NULL;
172 /* sort a symbol table */
173 inline static void sort_symbols( char **table, int size )
175 if (table )
176 qsort( table, size, sizeof(*table), name_cmp );
179 inline static void output_function_size( FILE *outfile, const char *name )
181 #ifdef HAVE_ASM_DOT_SIZE
182 fprintf( outfile, " \"\\t.size " __ASM_NAME("%s") ", . - " __ASM_NAME("%s") "\\n\"\n", name, name);
183 #endif
186 /* free an import structure */
187 static void free_imports( struct import *imp )
189 free( imp->exports );
190 free( imp->imports );
191 free_dll_spec( imp->spec );
192 free( imp );
195 /* remove the temp file at exit */
196 static void remove_ld_tmp_file(void)
198 if (ld_tmp_file) unlink( ld_tmp_file );
201 /* check whether a given dll has already been imported */
202 static int is_already_imported( const char *name )
204 int i;
206 for (i = 0; i < nb_imports; i++)
208 if (!strcmp( dll_imports[i]->spec->file_name, name )) return 1;
210 return 0;
213 /* open the .so library for a given dll in a specified path */
214 static char *try_library_path( const char *path, const char *name )
216 char *buffer;
217 int fd;
219 buffer = xmalloc( strlen(path) + strlen(name) + 9 );
220 sprintf( buffer, "%s/lib%s.def", path, name );
222 /* check if the file exists */
223 if ((fd = open( buffer, O_RDONLY )) != -1)
225 close( fd );
226 return buffer;
228 free( buffer );
229 return NULL;
232 /* open the .so library for a given dll */
233 static char *open_library( const char *name )
235 char *fullname;
236 int i;
238 for (i = 0; i < nb_lib_paths; i++)
240 if ((fullname = try_library_path( lib_path[i], name ))) return fullname;
242 fatal_error( "could not open .def file for %s\n", name );
243 return NULL;
246 /* read in the list of exported symbols of an import library */
247 static int read_import_lib( const char *name, struct import *imp )
249 FILE *f;
250 char *fullname;
251 int i, ret;
252 DLLSPEC *spec = imp->spec;
254 imp->exports = NULL;
255 imp->nb_exports = 0;
257 fullname = open_library( name );
258 f = open_input_file( NULL, fullname );
259 free( fullname );
261 ret = parse_def_file( f, spec );
262 close_input_file( f );
263 if (!ret) return 0;
264 if (is_already_imported( spec->file_name )) return 0;
266 imp->exports = xmalloc( spec->nb_entry_points * sizeof(*imp->exports) );
268 for (i = 0; i < spec->nb_entry_points; i++)
270 ORDDEF *odp = &spec->entry_points[i];
272 if (odp->type != TYPE_STDCALL && odp->type != TYPE_CDECL) continue;
273 if (odp->flags & FLAG_PRIVATE) continue;
274 imp->exports[imp->nb_exports++] = odp;
276 imp->exports = xrealloc( imp->exports, imp->nb_exports * sizeof(*imp->exports) );
277 if (imp->nb_exports)
278 qsort( imp->exports, imp->nb_exports, sizeof(*imp->exports), func_cmp );
279 return 1;
282 /* add a dll to the list of imports */
283 void add_import_dll( const char *name, int delay )
285 struct import *imp;
286 char *fullname;
288 fullname = xmalloc( strlen(name) + 5 );
289 strcpy( fullname, name );
290 if (!strchr( fullname, '.' )) strcat( fullname, ".dll" );
292 /* check if we already imported it */
293 if (is_already_imported( fullname ))
295 free( fullname );
296 return;
299 imp = xmalloc( sizeof(*imp) );
300 imp->spec = alloc_dll_spec();
301 imp->spec->file_name = fullname;
302 imp->delay = delay;
303 imp->imports = NULL;
304 imp->nb_imports = 0;
305 if (delay) nb_delayed++;
307 if (read_import_lib( name, imp ))
309 dll_imports = xrealloc( dll_imports, (nb_imports+1) * sizeof(*dll_imports) );
310 dll_imports[nb_imports++] = imp;
312 else
314 free_imports( imp );
315 if (nb_errors) exit(1);
319 /* remove an imported dll, based on its index in the dll_imports array */
320 static void remove_import_dll( int index )
322 struct import *imp = dll_imports[index];
324 memmove( &dll_imports[index], &dll_imports[index+1], sizeof(imp) * (nb_imports - index - 1) );
325 nb_imports--;
326 if (imp->delay) nb_delayed--;
327 free_imports( imp );
330 /* initialize the list of ignored symbols */
331 static void init_ignored_symbols(void)
333 int i;
335 nb_ignore_symbols = sizeof(default_ignored_symbols)/sizeof(default_ignored_symbols[0]);
336 ignore_size = nb_ignore_symbols + 32;
337 ignore_symbols = xmalloc( ignore_size * sizeof(*ignore_symbols) );
338 for (i = 0; i < nb_ignore_symbols; i++)
339 ignore_symbols[i] = xstrdup( default_ignored_symbols[i] );
342 /* add a symbol to the ignored symbol list */
343 /* if the name starts with '-' the symbol is removed instead */
344 void add_ignore_symbol( const char *name )
346 int i;
348 if (!ignore_symbols) init_ignored_symbols(); /* first time around, fill list with defaults */
350 if (name[0] == '-') /* remove it */
352 if (!name[1]) /* remove everything */
354 for (i = 0; i < nb_ignore_symbols; i++) free( ignore_symbols[i] );
355 nb_ignore_symbols = 0;
357 else
359 for (i = 0; i < nb_ignore_symbols; i++)
361 if (!strcmp( ignore_symbols[i], name+1 ))
363 free( ignore_symbols[i] );
364 memmove( &ignore_symbols[i], &ignore_symbols[i+1], nb_ignore_symbols - i - 1 );
365 nb_ignore_symbols--;
370 else
372 if (nb_ignore_symbols == ignore_size)
374 ignore_size += 32;
375 ignore_symbols = xrealloc( ignore_symbols, ignore_size * sizeof(*ignore_symbols) );
377 ignore_symbols[nb_ignore_symbols++] = xstrdup( name );
381 /* add a function to the list of imports from a given dll */
382 static void add_import_func( struct import *imp, ORDDEF *func )
384 imp->imports = xrealloc( imp->imports, (imp->nb_imports+1) * sizeof(*imp->imports) );
385 imp->imports[imp->nb_imports++] = func;
386 total_imports++;
387 if (imp->delay) total_delayed++;
390 /* add a symbol to the undef list */
391 inline static void add_undef_symbol( const char *name )
393 if (nb_undef_symbols == undef_size)
395 undef_size += 128;
396 undef_symbols = xrealloc( undef_symbols, undef_size * sizeof(*undef_symbols) );
398 undef_symbols[nb_undef_symbols++] = xstrdup( name );
401 /* remove all the holes in the undefined symbol list; return the number of removed symbols */
402 static int remove_symbol_holes(void)
404 int i, off;
405 for (i = off = 0; i < nb_undef_symbols; i++)
407 if (!undef_symbols[i]) off++;
408 else undef_symbols[i - off] = undef_symbols[i];
410 nb_undef_symbols -= off;
411 return off;
414 /* add a symbol to the extra list, but only if needed */
415 static int add_extra_symbol( const char **extras, int *count, const char *name, const DLLSPEC *spec )
417 int i;
419 if (!find_symbol( name, undef_symbols, nb_undef_symbols ))
421 /* check if the symbol is being exported by this dll */
422 for (i = 0; i < spec->nb_entry_points; i++)
424 ORDDEF *odp = &spec->entry_points[i];
425 if (odp->type == TYPE_STDCALL ||
426 odp->type == TYPE_CDECL ||
427 odp->type == TYPE_VARARGS ||
428 odp->type == TYPE_EXTERN)
430 if (odp->name && !strcmp( odp->name, name )) return 0;
433 extras[*count] = name;
434 (*count)++;
436 return 1;
439 /* add the extra undefined symbols that will be contained in the generated spec file itself */
440 static void add_extra_undef_symbols( const DLLSPEC *spec )
442 const char *extras[10];
443 int i, count = 0, nb_stubs = 0, nb_regs = 0;
444 int kernel_imports = 0, ntdll_imports = 0;
446 sort_symbols( undef_symbols, nb_undef_symbols );
448 for (i = 0; i < spec->nb_entry_points; i++)
450 ORDDEF *odp = &spec->entry_points[i];
451 if (odp->type == TYPE_STUB) nb_stubs++;
452 if (odp->flags & FLAG_REGISTER) nb_regs++;
455 /* add symbols that will be contained in the spec file itself */
456 if (!(spec->characteristics & IMAGE_FILE_DLL))
458 switch (spec->subsystem)
460 case IMAGE_SUBSYSTEM_WINDOWS_GUI:
461 case IMAGE_SUBSYSTEM_WINDOWS_CUI:
462 kernel_imports += add_extra_symbol( extras, &count, "GetCommandLineA", spec );
463 kernel_imports += add_extra_symbol( extras, &count, "GetStartupInfoA", spec );
464 kernel_imports += add_extra_symbol( extras, &count, "GetModuleHandleA", spec );
465 kernel_imports += add_extra_symbol( extras, &count, "ExitProcess", spec );
466 break;
469 if (nb_delayed)
471 kernel_imports += add_extra_symbol( extras, &count, "LoadLibraryA", spec );
472 kernel_imports += add_extra_symbol( extras, &count, "GetProcAddress", spec );
474 if (nb_regs)
475 ntdll_imports += add_extra_symbol( extras, &count, "__wine_call_from_32_regs", spec );
476 if (nb_delayed || nb_stubs)
477 ntdll_imports += add_extra_symbol( extras, &count, "RtlRaiseException", spec );
479 /* make sure we import the dlls that contain these functions */
480 if (kernel_imports) add_import_dll( "kernel32", 0 );
481 if (ntdll_imports) add_import_dll( "ntdll", 0 );
483 if (count)
485 for (i = 0; i < count; i++) add_undef_symbol( extras[i] );
486 sort_symbols( undef_symbols, nb_undef_symbols );
490 /* check if a given imported dll is not needed, taking forwards into account */
491 static int check_unused( const struct import* imp, const DLLSPEC *spec )
493 int i;
494 const char *file_name = imp->spec->file_name;
495 size_t len = strlen( file_name );
496 const char *p = strchr( file_name, '.' );
497 if (p && !strcasecmp( p, ".dll" )) len = p - file_name;
499 for (i = spec->base; i <= spec->limit; i++)
501 ORDDEF *odp = spec->ordinals[i];
502 if (!odp || !(odp->flags & FLAG_FORWARD)) continue;
503 if (!strncasecmp( odp->link_name, file_name, len ) &&
504 odp->link_name[len] == '.')
505 return 0; /* found a forward, it is used */
507 return 1;
510 /* combine a list of object files with ld into a single object file */
511 /* returns the name of the combined file */
512 static const char *ldcombine_files( char **argv )
514 int i, len = 0;
515 char *cmd;
516 int fd, err;
518 if (output_file_name && output_file_name[0])
520 ld_tmp_file = xmalloc( strlen(output_file_name) + 10 );
521 strcpy( ld_tmp_file, output_file_name );
522 strcat( ld_tmp_file, ".XXXXXX.o" );
524 else ld_tmp_file = xstrdup( "/tmp/winebuild.tmp.XXXXXX.o" );
526 if ((fd = mkstemps( ld_tmp_file, 2 ) == -1)) fatal_error( "could not generate a temp file\n" );
527 close( fd );
528 atexit( remove_ld_tmp_file );
530 for (i = 0; argv[i]; i++) len += strlen(argv[i]) + 1;
531 cmd = xmalloc( len + strlen(ld_tmp_file) + 8 + strlen(ld_command) );
532 sprintf( cmd, "%s -r -o %s", ld_command, ld_tmp_file );
533 for (i = 0; argv[i]; i++) sprintf( cmd + strlen(cmd), " %s", argv[i] );
534 err = system( cmd );
535 if (err) fatal_error( "%s -r failed with status %d\n", ld_command, err );
536 free( cmd );
537 return ld_tmp_file;
540 /* read in the list of undefined symbols */
541 void read_undef_symbols( char **argv )
543 static const char name_prefix[] = __ASM_NAME("");
544 static const int prefix_len = sizeof(name_prefix) - 1;
545 FILE *f;
546 char *cmd, buffer[1024];
547 int err;
548 const char *name;
550 if (!argv[0]) return;
552 undef_size = nb_undef_symbols = 0;
554 /* if we have multiple object files, link them together */
555 if (argv[1]) name = ldcombine_files( argv );
556 else name = argv[0];
558 cmd = xmalloc( strlen(nm_command) + strlen(name) + 5 );
559 sprintf( cmd, "%s -u %s", nm_command, name );
560 if (!(f = popen( cmd, "r" )))
561 fatal_error( "Cannot execute '%s'\n", cmd );
563 while (fgets( buffer, sizeof(buffer), f ))
565 char *p = buffer + strlen(buffer) - 1;
566 if (p < buffer) continue;
567 if (*p == '\n') *p-- = 0;
568 p = buffer;
569 while (*p == ' ') p++;
570 if (p[0] == 'U' && p[1] == ' ' && p[2]) p += 2;
571 if (prefix_len && !strncmp( p, name_prefix, prefix_len )) p += prefix_len;
572 add_undef_symbol( p );
574 if ((err = pclose( f ))) warning( "%s failed with status %d\n", cmd, err );
575 free( cmd );
578 static void remove_ignored_symbols(void)
580 int i;
582 if (!ignore_symbols) init_ignored_symbols();
583 sort_symbols( ignore_symbols, nb_ignore_symbols );
584 for (i = 0; i < nb_undef_symbols; i++)
586 if (find_symbol( undef_symbols[i], ignore_symbols, nb_ignore_symbols ))
588 free( undef_symbols[i] );
589 undef_symbols[i] = NULL;
592 remove_symbol_holes();
595 /* resolve the imports for a Win32 module */
596 int resolve_imports( DLLSPEC *spec )
598 int i, j;
600 if (nb_undef_symbols == -1) return 0; /* no symbol file specified */
602 add_extra_undef_symbols( spec );
603 remove_ignored_symbols();
605 for (i = 0; i < nb_imports; i++)
607 struct import *imp = dll_imports[i];
609 for (j = 0; j < nb_undef_symbols; j++)
611 ORDDEF *odp = find_export( undef_symbols[j], imp->exports, imp->nb_exports );
612 if (odp)
614 add_import_func( imp, odp );
615 free( undef_symbols[j] );
616 undef_symbols[j] = NULL;
619 /* remove all the holes in the undef symbols list */
620 if (!remove_symbol_holes() && check_unused( imp, spec ))
622 /* the dll is not used, get rid of it */
623 warning( "%s imported but no symbols used\n", imp->spec->file_name );
624 remove_import_dll( i );
625 i--;
628 return 1;
631 /* output the import table of a Win32 module */
632 static int output_immediate_imports( FILE *outfile )
634 int i, j, pos;
635 int nb_imm = nb_imports - nb_delayed;
636 static const char import_thunks[] = "__wine_spec_import_thunks";
638 if (!nb_imm) goto done;
640 /* main import header */
642 fprintf( outfile, "\nstatic struct {\n" );
643 fprintf( outfile, " struct {\n" );
644 fprintf( outfile, " void *OriginalFirstThunk;\n" );
645 fprintf( outfile, " unsigned int TimeDateStamp;\n" );
646 fprintf( outfile, " unsigned int ForwarderChain;\n" );
647 fprintf( outfile, " const char *Name;\n" );
648 fprintf( outfile, " void *FirstThunk;\n" );
649 fprintf( outfile, " } imp[%d];\n", nb_imm+1 );
650 fprintf( outfile, " const char *data[%d];\n",
651 total_imports - total_delayed + nb_imm );
652 fprintf( outfile, "} imports = {\n {\n" );
654 /* list of dlls */
656 for (i = j = 0; i < nb_imports; i++)
658 if (dll_imports[i]->delay) continue;
659 fprintf( outfile, " { 0, 0, 0, \"%s\", &imports.data[%d] },\n",
660 dll_imports[i]->spec->file_name, j );
661 j += dll_imports[i]->nb_imports + 1;
664 fprintf( outfile, " { 0, 0, 0, 0, 0 },\n" );
665 fprintf( outfile, " },\n {\n" );
667 /* list of imported functions */
669 for (i = 0; i < nb_imports; i++)
671 if (dll_imports[i]->delay) continue;
672 fprintf( outfile, " /* %s */\n", dll_imports[i]->spec->file_name );
673 for (j = 0; j < dll_imports[i]->nb_imports; j++)
675 ORDDEF *odp = dll_imports[i]->imports[j];
676 if (!(odp->flags & FLAG_NONAME))
678 unsigned short ord = odp->ordinal;
679 fprintf( outfile, " \"\\%03o\\%03o%s\",\n",
680 *(unsigned char *)&ord, *((unsigned char *)&ord + 1), odp->name );
682 else
683 fprintf( outfile, " (char *)%d,\n", odp->ordinal );
685 fprintf( outfile, " 0,\n" );
687 fprintf( outfile, " }\n};\n\n" );
689 /* thunks for imported functions */
691 fprintf( outfile, "#ifndef __GNUC__\nstatic void __asm__dummy_import(void) {\n#endif\n\n" );
692 pos = (sizeof(void *) + 2*sizeof(unsigned int) + sizeof(const char *) + sizeof(void *)) *
693 (nb_imm + 1); /* offset of imports.data from start of imports */
694 fprintf( outfile, "asm(\".text\\n\\t.align %d\\n\"\n", get_alignment(8) );
695 fprintf( outfile, " \"" __ASM_NAME("%s") ":\\n\"\n", import_thunks);
697 for (i = 0; i < nb_imports; i++)
699 if (dll_imports[i]->delay) continue;
700 for (j = 0; j < dll_imports[i]->nb_imports; j++, pos += sizeof(const char *))
702 ORDDEF *odp = dll_imports[i]->imports[j];
703 const char *name = odp->name ? odp->name : odp->export_name;
704 fprintf( outfile, " \"\\t" __ASM_FUNC("%s") "\\n\"\n", name );
705 fprintf( outfile, " \"\\t.globl " __ASM_NAME("%s") "\\n\"\n", name );
706 fprintf( outfile, " \"" __ASM_NAME("%s") ":\\n\\t", name);
708 #if defined(__i386__)
709 if (strstr( name, "__wine_call_from_16" ))
710 fprintf( outfile, ".byte 0x2e\\n\\tjmp *(imports+%d)\\n\\tnop\\n", pos );
711 else
712 fprintf( outfile, "jmp *(imports+%d)\\n\\tmovl %%esi,%%esi\\n", pos );
713 #elif defined(__sparc__)
714 if ( !UsePIC )
716 fprintf( outfile, "sethi %%hi(imports+%d), %%g1\\n\\t", pos );
717 fprintf( outfile, "ld [%%g1+%%lo(imports+%d)], %%g1\\n\\t", pos );
718 fprintf( outfile, "jmp %%g1\\n\\tnop\\n" );
720 else
722 /* Hmpf. Stupid sparc assembler always interprets global variable
723 names as GOT offsets, so we have to do it the long way ... */
724 fprintf( outfile, "save %%sp, -96, %%sp\\n" );
725 fprintf( outfile, "0:\\tcall 1f\\n\\tnop\\n" );
726 fprintf( outfile, "1:\\tsethi %%hi(imports+%d-0b), %%g1\\n\\t", pos );
727 fprintf( outfile, "or %%g1, %%lo(imports+%d-0b), %%g1\\n\\t", pos );
728 fprintf( outfile, "ld [%%g1+%%o7], %%g1\\n\\t" );
729 fprintf( outfile, "jmp %%g1\\n\\trestore\\n" );
732 #elif defined(__powerpc__)
733 fprintf(outfile, "\taddi %s, %s, -0x4\\n\"\n", ppc_reg[1], ppc_reg[1]);
734 fprintf(outfile, "\t\"\\tstw %s, 0(%s)\\n\"\n", ppc_reg[9], ppc_reg[1]);
735 fprintf(outfile, "\t\"\\taddi %s, %s, -0x4\\n\"\n", ppc_reg[1], ppc_reg[1]);
736 fprintf(outfile, "\t\"\\tstw %s, 0(%s)\\n\"\n", ppc_reg[8], ppc_reg[1]);
737 fprintf(outfile, "\t\"\\taddi %s, %s, -0x4\\n\"\n", ppc_reg[1], ppc_reg[1]);
738 fprintf(outfile, "\t\"\\tstw %s, 0(%s)\\n\"\n", ppc_reg[7], ppc_reg[1]);
740 fprintf(outfile, "\t\"\\tlis %s, " ppc_high(__ASM_NAME("imports") "+ %d") "\\n\"\n", ppc_reg[9], pos);
741 fprintf(outfile, "\t\"\\tla %s, " ppc_low (__ASM_NAME("imports") "+ %d") "(%s)\\n\"\n", ppc_reg[8], pos, ppc_reg[9]);
742 fprintf(outfile, "\t\"\\tlwz %s, 0(%s)\\n\"\n", ppc_reg[7], ppc_reg[8]);
743 fprintf(outfile, "\t\"\\tmtctr %s\\n\"\n", ppc_reg[7]);
745 fprintf(outfile, "\t\"\\tlwz %s, 0(%s)\\n\"\n", ppc_reg[7], ppc_reg[1]);
746 fprintf(outfile, "\t\"\\taddi %s, %s, 0x4\\n\"\n", ppc_reg[1], ppc_reg[1]);
747 fprintf(outfile, "\t\"\\tlwz %s, 0(%s)\\n\"\n", ppc_reg[8], ppc_reg[1]);
748 fprintf(outfile, "\t\"\\taddi %s, %s, 0x4\\n\"\n", ppc_reg[1], ppc_reg[1]);
749 fprintf(outfile, "\t\"\\tlwz %s, 0(%s)\\n\"\n", ppc_reg[9], ppc_reg[1]);
750 fprintf(outfile, "\t\"\\taddi %s, %s, 0x4\\n\"\n", ppc_reg[1], ppc_reg[1]);
751 fprintf(outfile, "\t\"\\tbctr\\n");
752 #elif defined(__ALPHA__)
753 fprintf( outfile, "\tlda $0,imports\\n\"\n" );
754 fprintf( outfile, "\t\"\\tlda $0,%d($0)\\n\"\n", pos);
755 fprintf( outfile, "\t\"\\tjmp $31,($0)\\n" );
756 #else
757 #error You need to define import thunks for your architecture!
758 #endif
759 fprintf( outfile, "\"\n" );
760 output_function_size( outfile, name );
762 pos += 4;
764 output_function_size( outfile, import_thunks );
765 fprintf( outfile, " \".text\");\n#ifndef __GNUC__\n}\n#endif\n\n" );
767 done:
768 return nb_imm;
771 /* output the delayed import table of a Win32 module */
772 static int output_delayed_imports( FILE *outfile, const DLLSPEC *spec )
774 int i, idx, j, pos;
775 static const char delayed_import_loaders[] = "__wine_spec_delayed_import_loaders";
776 static const char delayed_import_thunks[] = "__wine_spec_delayed_import_thunks";
778 if (!nb_delayed) goto done;
780 for (i = 0; i < nb_imports; i++)
782 if (!dll_imports[i]->delay) continue;
783 fprintf( outfile, "static void *__wine_delay_imp_%d_hmod;\n", i);
784 for (j = 0; j < dll_imports[i]->nb_imports; j++)
786 ORDDEF *odp = dll_imports[i]->imports[j];
787 const char *name = odp->name ? odp->name : odp->export_name;
788 fprintf( outfile, "void __wine_delay_imp_%d_%s();\n", i, name );
791 fprintf( outfile, "\n" );
792 fprintf( outfile, "static struct {\n" );
793 fprintf( outfile, " struct ImgDelayDescr {\n" );
794 fprintf( outfile, " unsigned int grAttrs;\n" );
795 fprintf( outfile, " const char *szName;\n" );
796 fprintf( outfile, " void **phmod;\n" );
797 fprintf( outfile, " void **pIAT;\n" );
798 fprintf( outfile, " const char **pINT;\n" );
799 fprintf( outfile, " void* pBoundIAT;\n" );
800 fprintf( outfile, " void* pUnloadIAT;\n" );
801 fprintf( outfile, " unsigned long dwTimeStamp;\n" );
802 fprintf( outfile, " } imp[%d];\n", nb_delayed );
803 fprintf( outfile, " void *IAT[%d];\n", total_delayed );
804 fprintf( outfile, " const char *INT[%d];\n", total_delayed );
805 fprintf( outfile, "} delay_imports = {\n" );
806 fprintf( outfile, " {\n" );
807 for (i = j = 0; i < nb_imports; i++)
809 if (!dll_imports[i]->delay) continue;
810 fprintf( outfile, " { 0, \"%s\", &__wine_delay_imp_%d_hmod, &delay_imports.IAT[%d], &delay_imports.INT[%d], 0, 0, 0 },\n",
811 dll_imports[i]->spec->file_name, i, j, j );
812 j += dll_imports[i]->nb_imports;
814 fprintf( outfile, " },\n {\n" );
815 for (i = 0; i < nb_imports; i++)
817 if (!dll_imports[i]->delay) continue;
818 fprintf( outfile, " /* %s */\n", dll_imports[i]->spec->file_name );
819 for (j = 0; j < dll_imports[i]->nb_imports; j++)
821 ORDDEF *odp = dll_imports[i]->imports[j];
822 const char *name = odp->name ? odp->name : odp->export_name;
823 fprintf( outfile, " &__wine_delay_imp_%d_%s,\n", i, name );
826 fprintf( outfile, " },\n {\n" );
827 for (i = 0; i < nb_imports; i++)
829 if (!dll_imports[i]->delay) continue;
830 fprintf( outfile, " /* %s */\n", dll_imports[i]->spec->file_name );
831 for (j = 0; j < dll_imports[i]->nb_imports; j++)
833 ORDDEF *odp = dll_imports[i]->imports[j];
834 if (!odp->name)
835 fprintf( outfile, " (char *)%d,\n", odp->ordinal );
836 else
837 fprintf( outfile, " \"%s\",\n", odp->name );
840 fprintf( outfile, " }\n};\n\n" );
842 /* check if there's some stub defined. if so, exception struct
843 * is already defined, so don't emit it twice
845 for (i = 0; i < spec->nb_entry_points; i++) if (spec->entry_points[i].type == TYPE_STUB) break;
847 if (i == spec->nb_entry_points) {
848 fprintf( outfile, "struct exc_record {\n" );
849 fprintf( outfile, " unsigned int code, flags;\n" );
850 fprintf( outfile, " void *rec, *addr;\n" );
851 fprintf( outfile, " unsigned int params;\n" );
852 fprintf( outfile, " const void *info[15];\n" );
853 fprintf( outfile, "};\n\n" );
854 fprintf( outfile, "extern void __stdcall RtlRaiseException( struct exc_record * );\n" );
857 fprintf( outfile, "extern void * __stdcall LoadLibraryA(const char*);\n");
858 fprintf( outfile, "extern void * __stdcall GetProcAddress(void *, const char*);\n");
859 fprintf( outfile, "\n" );
861 fprintf( outfile, "void *__stdcall __wine_delay_load( int idx_nr )\n" );
862 fprintf( outfile, "{\n" );
863 fprintf( outfile, " int idx = idx_nr >> 16, nr = idx_nr & 0xffff;\n" );
864 fprintf( outfile, " struct ImgDelayDescr *imd = delay_imports.imp + idx;\n" );
865 fprintf( outfile, " void **pIAT = imd->pIAT + nr;\n" );
866 fprintf( outfile, " const char** pINT = imd->pINT + nr;\n" );
867 fprintf( outfile, " void *fn;\n\n" );
869 fprintf( outfile, " if (!*imd->phmod) *imd->phmod = LoadLibraryA(imd->szName);\n" );
870 fprintf( outfile, " if (*imd->phmod && (fn = GetProcAddress(*imd->phmod, *pINT)))\n");
871 fprintf( outfile, " /* patch IAT with final value */\n" );
872 fprintf( outfile, " return *pIAT = fn;\n" );
873 fprintf( outfile, " else {\n");
874 fprintf( outfile, " struct exc_record rec;\n" );
875 fprintf( outfile, " rec.code = 0x80000100;\n" );
876 fprintf( outfile, " rec.flags = 1;\n" );
877 fprintf( outfile, " rec.rec = 0;\n" );
878 fprintf( outfile, " rec.params = 2;\n" );
879 fprintf( outfile, " rec.info[0] = imd->szName;\n" );
880 fprintf( outfile, " rec.info[1] = *pINT;\n" );
881 fprintf( outfile, "#ifdef __GNUC__\n" );
882 fprintf( outfile, " rec.addr = __builtin_return_address(1);\n" );
883 fprintf( outfile, "#else\n" );
884 fprintf( outfile, " rec.addr = 0;\n" );
885 fprintf( outfile, "#endif\n" );
886 fprintf( outfile, " for (;;) RtlRaiseException( &rec );\n" );
887 fprintf( outfile, " return 0; /* shouldn't go here */\n" );
888 fprintf( outfile, " }\n}\n\n" );
890 fprintf( outfile, "#ifndef __GNUC__\n" );
891 fprintf( outfile, "static void __asm__dummy_delay_import(void) {\n" );
892 fprintf( outfile, "#endif\n" );
894 fprintf( outfile, "asm(\".align %d\\n\"\n", get_alignment(8) );
895 fprintf( outfile, " \"" __ASM_NAME("%s") ":\\n\"\n", delayed_import_loaders);
896 fprintf( outfile, " \"\\t" __ASM_FUNC("__wine_delay_load_asm") "\\n\"\n" );
897 fprintf( outfile, " \"" __ASM_NAME("__wine_delay_load_asm") ":\\n\"\n" );
898 #if defined(__i386__)
899 fprintf( outfile, " \"\\tpushl %%ecx\\n\\tpushl %%edx\\n\\tpushl %%eax\\n\"\n" );
900 fprintf( outfile, " \"\\tcall __wine_delay_load\\n\"\n" );
901 fprintf( outfile, " \"\\tpopl %%edx\\n\\tpopl %%ecx\\n\\tjmp *%%eax\\n\"\n" );
902 #elif defined(__sparc__)
903 fprintf( outfile, " \"\\tsave %%sp, -96, %%sp\\n\"\n" );
904 fprintf( outfile, " \"\\tcall __wine_delay_load\\n\"\n" );
905 fprintf( outfile, " \"\\tmov %%g1, %%o0\\n\"\n" );
906 fprintf( outfile, " \"\\tjmp %%o0\\n\\trestore\\n\"\n" );
907 #elif defined(__powerpc__)
908 # if defined(__APPLE__)
909 /* On darwin an extra 56 bytes must be allowed for the linkage area+param area */
910 # define extra_stack_storage 56
911 # else
912 # define extra_stack_storage 0
913 # endif
914 /* Save all callee saved registers into a stackframe. */
915 fprintf( outfile, " \"\\tstwu %s, -%d(%s)\\n\"\n",ppc_reg[1], 48+extra_stack_storage, ppc_reg[1]);
916 fprintf( outfile, " \"\\tstw %s, %d(%s)\\n\"\n", ppc_reg[3], 4+extra_stack_storage, ppc_reg[1]);
917 fprintf( outfile, " \"\\tstw %s, %d(%s)\\n\"\n", ppc_reg[4], 8+extra_stack_storage, ppc_reg[1]);
918 fprintf( outfile, " \"\\tstw %s, %d(%s)\\n\"\n", ppc_reg[5], 12+extra_stack_storage, ppc_reg[1]);
919 fprintf( outfile, " \"\\tstw %s, %d(%s)\\n\"\n", ppc_reg[6], 16+extra_stack_storage, ppc_reg[1]);
920 fprintf( outfile, " \"\\tstw %s, %d(%s)\\n\"\n", ppc_reg[7], 20+extra_stack_storage, ppc_reg[1]);
921 fprintf( outfile, " \"\\tstw %s, %d(%s)\\n\"\n", ppc_reg[8], 24+extra_stack_storage, ppc_reg[1]);
922 fprintf( outfile, " \"\\tstw %s, %d(%s)\\n\"\n", ppc_reg[9], 28+extra_stack_storage, ppc_reg[1]);
923 fprintf( outfile, " \"\\tstw %s, %d(%s)\\n\"\n", ppc_reg[10],32+extra_stack_storage, ppc_reg[1]);
924 fprintf( outfile, " \"\\tstw %s, %d(%s)\\n\"\n", ppc_reg[11],36+extra_stack_storage, ppc_reg[1]);
925 fprintf( outfile, " \"\\tstw %s, %d(%s)\\n\"\n", ppc_reg[12],40+extra_stack_storage, ppc_reg[1]);
927 /* r0 -> r3 (arg1) */
928 fprintf( outfile, " \"\\tmr %s, %s\\n\"\n", ppc_reg[3], ppc_reg[0]);
930 /* save return address */
931 fprintf( outfile, " \"\\tmflr %s\\n\"\n", ppc_reg[0]);
932 fprintf( outfile, " \"\\tstw %s, %d(%s)\\n\"\n", ppc_reg[0], 44+extra_stack_storage, ppc_reg[1]);
934 /* Call the __wine_delay_load function, arg1 is arg1. */
935 fprintf( outfile, " \"\\tbl " __ASM_NAME("__wine_delay_load") "\\n\"\n");
937 /* Load return value from call into ctr register */
938 fprintf( outfile, " \"\\tmtctr %s\\n\"\n", ppc_reg[3]);
940 /* restore all saved registers and drop stackframe. */
941 fprintf( outfile, " \"\\tlwz %s, %d(%s)\\n\"\n", ppc_reg[3], 4+extra_stack_storage, ppc_reg[1]);
942 fprintf( outfile, " \"\\tlwz %s, %d(%s)\\n\"\n", ppc_reg[4], 8+extra_stack_storage, ppc_reg[1]);
943 fprintf( outfile, " \"\\tlwz %s, %d(%s)\\n\"\n", ppc_reg[5], 12+extra_stack_storage, ppc_reg[1]);
944 fprintf( outfile, " \"\\tlwz %s, %d(%s)\\n\"\n", ppc_reg[6], 16+extra_stack_storage, ppc_reg[1]);
945 fprintf( outfile, " \"\\tlwz %s, %d(%s)\\n\"\n", ppc_reg[7], 20+extra_stack_storage, ppc_reg[1]);
946 fprintf( outfile, " \"\\tlwz %s, %d(%s)\\n\"\n", ppc_reg[8], 24+extra_stack_storage, ppc_reg[1]);
947 fprintf( outfile, " \"\\tlwz %s, %d(%s)\\n\"\n", ppc_reg[9], 28+extra_stack_storage, ppc_reg[1]);
948 fprintf( outfile, " \"\\tlwz %s, %d(%s)\\n\"\n", ppc_reg[10],32+extra_stack_storage, ppc_reg[1]);
949 fprintf( outfile, " \"\\tlwz %s, %d(%s)\\n\"\n", ppc_reg[11],36+extra_stack_storage, ppc_reg[1]);
950 fprintf( outfile, " \"\\tlwz %s, %d(%s)\\n\"\n", ppc_reg[12],40+extra_stack_storage, ppc_reg[1]);
952 /* Load return value from call into return register */
953 fprintf( outfile, " \"\\tlwz %s, %d(%s)\\n\"\n", ppc_reg[0], 44+extra_stack_storage, ppc_reg[1]);
954 fprintf( outfile, " \"\\tmtlr %s\\n\"\n", ppc_reg[0]);
955 fprintf( outfile, " \"\\taddi %s, %s, %d\\n\"\n", ppc_reg[1], ppc_reg[1], 48+extra_stack_storage);
957 /* branch to ctr register. */
958 fprintf( outfile, " \"bctr\\n\"\n");
959 #elif defined(__ALPHA__)
960 fprintf( outfile, " \"\\tjsr $26,__wine_delay_load\\n\"\n" );
961 fprintf( outfile, " \"\\tjmp $31,($0)\\n\"\n" );
962 #else
963 #error You need to defined delayed import thunks for your architecture!
964 #endif
965 output_function_size( outfile, "__wine_delay_load_asm" );
967 for (i = idx = 0; i < nb_imports; i++)
969 if (!dll_imports[i]->delay) continue;
970 for (j = 0; j < dll_imports[i]->nb_imports; j++)
972 char buffer[128];
973 ORDDEF *odp = dll_imports[i]->imports[j];
974 const char *name = odp->name ? odp->name : odp->export_name;
976 sprintf( buffer, "__wine_delay_imp_%d_%s", i, name );
977 fprintf( outfile, " \"\\t" __ASM_FUNC("%s") "\\n\"\n", buffer );
978 fprintf( outfile, " \"" __ASM_NAME("%s") ":\\n\"\n", buffer );
979 #if defined(__i386__)
980 fprintf( outfile, " \"\\tmovl $%d, %%eax\\n\"\n", (idx << 16) | j );
981 fprintf( outfile, " \"\\tjmp __wine_delay_load_asm\\n\"\n" );
982 #elif defined(__sparc__)
983 fprintf( outfile, " \"\\tset %d, %%g1\\n\"\n", (idx << 16) | j );
984 fprintf( outfile, " \"\\tb,a __wine_delay_load_asm\\n\"\n" );
985 #elif defined(__powerpc__)
986 #ifdef __APPLE__
987 /* On Darwin we can use r0 and r2 */
988 /* Upper part in r2 */
989 fprintf( outfile, " \"\\tlis %s, %d\\n\"\n", ppc_reg[2], idx);
990 /* Lower part + r2 -> r0, Note we can't use r0 directly */
991 fprintf( outfile, " \"\\taddi %s, %s, %d\\n\"\n", ppc_reg[0], ppc_reg[2], j);
992 fprintf( outfile, " \"\\tb " __ASM_NAME("__wine_delay_load_asm") "\\n\"\n");
993 #else /* __APPLE__ */
994 /* On linux we can't use r2 since r2 is not a scratch register (hold the TOC) */
995 /* Save r13 on the stack */
996 fprintf( outfile, " \"\\taddi %s, %s, -0x4\\n\"\n", ppc_reg[1], ppc_reg[1]);
997 fprintf( outfile, " \"\\tstw %s, 0(%s)\\n\"\n", ppc_reg[13], ppc_reg[1]);
998 /* Upper part in r13 */
999 fprintf( outfile, " \"\\tlis %s, %d\\n\"\n", ppc_reg[13], idx);
1000 /* Lower part + r13 -> r0, Note we can't use r0 directly */
1001 fprintf( outfile, " \"\\taddi %s, %s, %d\\n\"\n", ppc_reg[0], ppc_reg[13], j);
1002 /* Restore r13 */
1003 fprintf( outfile, " \"\\tstw %s, 0(%s)\\n\"\n", ppc_reg[13], ppc_reg[1]);
1004 fprintf( outfile, " \"\\taddic %s, %s, 0x4\\n\"\n", ppc_reg[1], ppc_reg[1]);
1005 fprintf( outfile, " \"\\tb " __ASM_NAME("__wine_delay_load_asm") "\\n\"\n");
1006 #endif /* __APPLE__ */
1007 #elif defined(__ALPHA__)
1008 fprintf( outfile, " \"\\tlda $0,%d($31)\\n\"\n", j);
1009 fprintf( outfile, " \"\\tldah $0,%d($0)\\n\"\n", idx);
1010 fprintf( outfile, " \"\\tjmp $31,__wine_delay_load_asm\\n\"\n" );
1011 #else
1012 #error You need to defined delayed import thunks for your architecture!
1013 #endif
1014 output_function_size( outfile, name );
1016 idx++;
1018 output_function_size( outfile, delayed_import_loaders );
1020 fprintf( outfile, "\n \".align %d\\n\"\n", get_alignment(8) );
1021 fprintf( outfile, " \"" __ASM_NAME("%s") ":\\n\"\n", delayed_import_thunks);
1022 pos = nb_delayed * 32;
1023 for (i = 0; i < nb_imports; i++)
1025 if (!dll_imports[i]->delay) continue;
1026 for (j = 0; j < dll_imports[i]->nb_imports; j++, pos += 4)
1028 ORDDEF *odp = dll_imports[i]->imports[j];
1029 const char *name = odp->name ? odp->name : odp->export_name;
1031 fprintf( outfile, " \"\\t" __ASM_FUNC("%s") "\\n\"\n", name );
1032 fprintf( outfile, " \"\\t.globl " __ASM_NAME("%s") "\\n\"\n", name );
1033 fprintf( outfile, " \"" __ASM_NAME("%s") ":\\n\\t\"", name );
1034 #if defined(__i386__)
1035 if (strstr( name, "__wine_call_from_16" ))
1036 fprintf( outfile, "\".byte 0x2e\\n\\tjmp *(delay_imports+%d)\\n\\tnop\\n\"", pos );
1037 else
1038 fprintf( outfile, "\"jmp *(delay_imports+%d)\\n\\tmovl %%esi,%%esi\\n\"", pos );
1039 #elif defined(__sparc__)
1040 if ( !UsePIC )
1042 fprintf( outfile, "\"sethi %%hi(delay_imports+%d), %%g1\\n\\t\"", pos );
1043 fprintf( outfile, "\"ld [%%g1+%%lo(delay_imports+%d)], %%g1\\n\\t\"", pos );
1044 fprintf( outfile, "\"jmp %%g1\\n\\tnop\\n\"" );
1046 else
1048 /* Hmpf. Stupid sparc assembler always interprets global variable
1049 names as GOT offsets, so we have to do it the long way ... */
1050 fprintf( outfile, "\"save %%sp, -96, %%sp\\n\"" );
1051 fprintf( outfile, "\"0:\\tcall 1f\\n\\tnop\\n\"" );
1052 fprintf( outfile, "\"1:\\tsethi %%hi(delay_imports+%d-0b), %%g1\\n\\t\"", pos );
1053 fprintf( outfile, "\"or %%g1, %%lo(delay_imports+%d-0b), %%g1\\n\\t\"", pos );
1054 fprintf( outfile, "\"ld [%%g1+%%o7], %%g1\\n\\t\"" );
1055 fprintf( outfile, "\"jmp %%g1\\n\\trestore\\n\"" );
1058 #elif defined(__powerpc__)
1059 fprintf( outfile, "\t\"addi %s, %s, -0x4\\n\"\n", ppc_reg[1], ppc_reg[1]);
1060 fprintf( outfile, "\t\"\\tstw %s, 0(%s)\\n\"\n", ppc_reg[9], ppc_reg[1]);
1061 fprintf( outfile, "\t\"\\taddi %s, %s, -0x4\\n\"\n", ppc_reg[1], ppc_reg[1]);
1062 fprintf( outfile, "\t\"\\tstw %s, 0(%s)\\n\"\n", ppc_reg[8], ppc_reg[1]);
1063 fprintf( outfile, "\t\"\\taddi %s, %s, -0x4\\n\"\n", ppc_reg[1], ppc_reg[1]);
1064 fprintf( outfile, "\t\"\\tstw %s, 0(%s)\\n\"\n", ppc_reg[7], ppc_reg[1]);
1066 fprintf( outfile, "\t\"\\tlis %s, " ppc_high(__ASM_NAME("delay_imports") "+ %d") "\\n\"\n", ppc_reg[9], pos);
1067 fprintf( outfile, "\t\"\\tla %s, " ppc_low (__ASM_NAME("delay_imports") "+ %d") "(%s)\\n\"\n", ppc_reg[8], pos, ppc_reg[9]);
1068 fprintf( outfile, "\t\"\\tlwz %s, 0(%s)\\n\"\n", ppc_reg[7], ppc_reg[8]);
1069 fprintf( outfile, "\t\"\\tmtctr %s\\n\"\n", ppc_reg[7]);
1071 fprintf( outfile, "\t\"\\tlwz %s, 0(%s)\\n\"\n", ppc_reg[7], ppc_reg[1]);
1072 fprintf( outfile, "\t\"\\taddi %s, %s, 0x4\\n\"\n", ppc_reg[1], ppc_reg[1]);
1073 fprintf( outfile, "\t\"\\tlwz %s, 0(%s)\\n\"\n", ppc_reg[8], ppc_reg[1]);
1074 fprintf( outfile, "\t\"\\taddi %s, %s, 0x4\\n\"\n", ppc_reg[1], ppc_reg[1]);
1075 fprintf( outfile, "\t\"\\tlwz %s, 0(%s)\\n\"\n", ppc_reg[9], ppc_reg[1]);
1076 fprintf( outfile, "\t\"\\taddi %s, %s, 0x4\\n\"\n", ppc_reg[1], ppc_reg[1]);
1077 fprintf( outfile, "\t\"\\tbctr\\n\"");
1078 #elif defined(__ALPHA__)
1079 fprintf( outfile, "\t\"lda $0,delay_imports\\n\"\n" );
1080 fprintf( outfile, "\t\"\\tlda $0,%d($0)\\n\"\n", pos);
1081 fprintf( outfile, "\t\"\\tjmp $31,($0)\\n\"" );
1082 #else
1083 #error You need to define delayed import thunks for your architecture!
1084 #endif
1085 fprintf( outfile, "\n" );
1086 output_function_size( outfile, name );
1089 output_function_size( outfile, delayed_import_thunks );
1090 fprintf( outfile, ");\n" );
1091 fprintf( outfile, "#ifndef __GNUC__\n" );
1092 fprintf( outfile, "}\n" );
1093 fprintf( outfile, "#endif\n" );
1094 fprintf( outfile, "\n" );
1096 done:
1097 return nb_delayed;
1100 /* output the import and delayed import tables of a Win32 module
1101 * returns number of DLLs exported in 'immediate' mode
1103 int output_imports( FILE *outfile, DLLSPEC *spec )
1105 output_delayed_imports( outfile, spec );
1106 return output_immediate_imports( outfile );