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
29 #ifdef HAVE_SYS_STAT_H
30 # include <sys/stat.h>
37 #include "wine/exception.h"
42 DLLSPEC
*spec
; /* description of the imported dll */
43 char *full_name
; /* full name of the input file */
44 dev_t dev
; /* device/inode of the input file */
46 int delay
; /* delay or not dll loading ? */
47 ORDDEF
**exports
; /* functions exported from this dll */
48 int nb_exports
; /* number of exported functions */
49 ORDDEF
**imports
; /* functions we want to import from this dll */
50 int nb_imports
; /* number of imported functions */
53 static char **undef_symbols
; /* list of undefined symbols */
54 static int nb_undef_symbols
= -1;
55 static int undef_size
;
57 static char **ignore_symbols
; /* list of symbols to ignore */
58 static int nb_ignore_symbols
;
59 static int ignore_size
;
61 static char *ld_tmp_file
; /* ld temp file name */
63 static struct import
**dll_imports
= NULL
;
64 static int nb_imports
= 0; /* number of imported dlls (delayed or not) */
65 static int nb_delayed
= 0; /* number of delayed dlls */
66 static int total_imports
= 0; /* total number of imported functions */
67 static int total_delayed
= 0; /* total number of imported functions in delayed DLLs */
68 static char **delayed_imports
; /* names of delayed import dlls */
69 static int nb_delayed_imports
; /* size of the delayed_imports array */
71 /* list of symbols that are ignored by default */
72 static const char * const default_ignored_symbols
[] =
124 # define ppc_high(mem) "ha16(" mem ")"
125 # define ppc_low(mem) "lo16(" mem ")"
126 static const char * const ppc_reg
[32] = { "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7",
127 "r8", "r9", "r10","r11","r12","r13","r14","r15",
128 "r16","r17","r18","r19","r20","r21","r22","r23",
129 "r24","r25","r26","r27","r28","r29","r30","r31" };
130 # else /* __APPLE__ */
131 # define ppc_high(mem) "(" mem ")@hi"
132 # define ppc_low(mem) "(" mem ")@l"
133 static const char * const ppc_reg
[32] = { "0", "1", "2", "3", "4", "5", "6", "7",
134 "8", "9", "10","11","12","13","14","15",
135 "16","17","18","19","20","21","22","23",
136 "24","25","26","27","28","29","30","31" };
137 # endif /* __APPLE__ */
138 #endif /* __powerpc__ */
140 /* compare function names; helper for resolve_imports */
141 static int name_cmp( const void *name
, const void *entry
)
143 return strcmp( *(const char* const *)name
, *(const char* const *)entry
);
146 /* compare function names; helper for resolve_imports */
147 static int func_cmp( const void *func1
, const void *func2
)
149 const ORDDEF
*odp1
= *(const ORDDEF
* const *)func1
;
150 const ORDDEF
*odp2
= *(const ORDDEF
* const *)func2
;
151 return strcmp( odp1
->name
? odp1
->name
: odp1
->export_name
,
152 odp2
->name
? odp2
->name
: odp2
->export_name
);
155 /* locate a symbol in a (sorted) list */
156 inline static const char *find_symbol( const char *name
, char **table
, int size
)
161 res
= bsearch( &name
, table
, size
, sizeof(*table
), name_cmp
);
164 return res
? *res
: NULL
;
167 /* locate an export in a (sorted) export list */
168 inline static ORDDEF
*find_export( const char *name
, ORDDEF
**table
, int size
)
170 ORDDEF func
, *odp
, **res
= NULL
;
172 func
.name
= (char *)name
;
175 if (table
) res
= bsearch( &odp
, table
, size
, sizeof(*table
), func_cmp
);
176 return res
? *res
: NULL
;
179 /* sort a symbol table */
180 inline static void sort_symbols( char **table
, int size
)
183 qsort( table
, size
, sizeof(*table
), name_cmp
);
186 inline static void output_function_size( FILE *outfile
, const char *name
)
188 #ifdef HAVE_ASM_DOT_SIZE
189 fprintf( outfile
, " \"\\t.size " __ASM_NAME("%s") ", . - " __ASM_NAME("%s") "\\n\"\n", name
, name
);
193 /* free an import structure */
194 static void free_imports( struct import
*imp
)
196 free( imp
->exports
);
197 free( imp
->imports
);
198 free_dll_spec( imp
->spec
);
199 free( imp
->full_name
);
203 /* remove the temp file at exit */
204 static void remove_ld_tmp_file(void)
206 if (ld_tmp_file
) unlink( ld_tmp_file
);
209 /* check whether a given dll is imported in delayed mode */
210 static int is_delayed_import( const char *name
)
214 for (i
= 0; i
< nb_delayed_imports
; i
++)
216 if (!strcmp( delayed_imports
[i
], name
)) return 1;
221 /* check whether a given dll has already been imported */
222 static struct import
*is_already_imported( const char *name
)
226 for (i
= 0; i
< nb_imports
; i
++)
228 if (!strcmp( dll_imports
[i
]->spec
->file_name
, name
)) return dll_imports
[i
];
233 /* open the .so library for a given dll in a specified path */
234 static char *try_library_path( const char *path
, const char *name
)
239 buffer
= xmalloc( strlen(path
) + strlen(name
) + 9 );
240 sprintf( buffer
, "%s/lib%s.def", path
, name
);
242 /* check if the file exists */
243 if ((fd
= open( buffer
, O_RDONLY
)) != -1)
252 /* find the .def import library for a given dll */
253 static char *find_library( const char *name
)
258 for (i
= 0; i
< nb_lib_paths
; i
++)
260 if ((fullname
= try_library_path( lib_path
[i
], name
))) return fullname
;
262 fatal_error( "could not open .def file for %s\n", name
);
266 /* read in the list of exported symbols of an import library */
267 static int read_import_lib( struct import
*imp
)
272 struct import
*prev_imp
;
273 DLLSPEC
*spec
= imp
->spec
;
275 f
= open_input_file( NULL
, imp
->full_name
);
276 fstat( fileno(f
), &stat
);
277 imp
->dev
= stat
.st_dev
;
278 imp
->ino
= stat
.st_ino
;
279 ret
= parse_def_file( f
, spec
);
280 close_input_file( f
);
283 /* check if we already imported that library from a different file */
284 if ((prev_imp
= is_already_imported( spec
->file_name
)))
286 if (prev_imp
->dev
!= imp
->dev
|| prev_imp
->ino
!= imp
->ino
)
287 fatal_error( "%s and %s have the same export name '%s'\n",
288 prev_imp
->full_name
, imp
->full_name
, spec
->file_name
);
289 return 0; /* the same file was already loaded, ignore this one */
292 if (is_delayed_import( spec
->file_name
))
298 imp
->exports
= xmalloc( spec
->nb_entry_points
* sizeof(*imp
->exports
) );
300 for (i
= 0; i
< spec
->nb_entry_points
; i
++)
302 ORDDEF
*odp
= &spec
->entry_points
[i
];
304 if (odp
->type
!= TYPE_STDCALL
&& odp
->type
!= TYPE_CDECL
) continue;
305 if (odp
->flags
& FLAG_PRIVATE
) continue;
306 imp
->exports
[imp
->nb_exports
++] = odp
;
308 imp
->exports
= xrealloc( imp
->exports
, imp
->nb_exports
* sizeof(*imp
->exports
) );
310 qsort( imp
->exports
, imp
->nb_exports
, sizeof(*imp
->exports
), func_cmp
);
314 /* build the dll exported name from the import lib name or path */
315 static char *get_dll_name( const char *name
, const char *filename
)
321 const char *basename
= strrchr( filename
, '/' );
322 if (!basename
) basename
= filename
;
324 if (!strncmp( basename
, "lib", 3 )) basename
+= 3;
325 ret
= xmalloc( strlen(basename
) + 5 );
326 strcpy( ret
, basename
);
327 if (strendswith( ret
, ".def" )) ret
[strlen(ret
)-4] = 0;
331 ret
= xmalloc( strlen(name
) + 5 );
334 if (!strchr( ret
, '.' )) strcat( ret
, ".dll" );
338 /* add a dll to the list of imports */
339 void add_import_dll( const char *name
, const char *filename
)
341 struct import
*imp
= xmalloc( sizeof(*imp
) );
343 imp
->spec
= alloc_dll_spec();
344 imp
->spec
->file_name
= get_dll_name( name
, filename
);
351 if (filename
) imp
->full_name
= xstrdup( filename
);
352 else imp
->full_name
= find_library( name
);
354 if (read_import_lib( imp
))
356 dll_imports
= xrealloc( dll_imports
, (nb_imports
+1) * sizeof(*dll_imports
) );
357 dll_imports
[nb_imports
++] = imp
;
362 if (nb_errors
) exit(1);
366 /* add a library to the list of delayed imports */
367 void add_delayed_import( const char *name
)
370 char *fullname
= get_dll_name( name
, NULL
);
372 delayed_imports
= xrealloc( delayed_imports
, (nb_delayed_imports
+1) * sizeof(*delayed_imports
) );
373 delayed_imports
[nb_delayed_imports
++] = fullname
;
374 if ((imp
= is_already_imported( fullname
)) && !imp
->delay
)
381 /* remove an imported dll, based on its index in the dll_imports array */
382 static void remove_import_dll( int index
)
384 struct import
*imp
= dll_imports
[index
];
386 memmove( &dll_imports
[index
], &dll_imports
[index
+1], sizeof(imp
) * (nb_imports
- index
- 1) );
388 if (imp
->delay
) nb_delayed
--;
392 /* initialize the list of ignored symbols */
393 static void init_ignored_symbols(void)
397 nb_ignore_symbols
= sizeof(default_ignored_symbols
)/sizeof(default_ignored_symbols
[0]);
398 ignore_size
= nb_ignore_symbols
+ 32;
399 ignore_symbols
= xmalloc( ignore_size
* sizeof(*ignore_symbols
) );
400 for (i
= 0; i
< nb_ignore_symbols
; i
++)
401 ignore_symbols
[i
] = xstrdup( default_ignored_symbols
[i
] );
404 /* add a symbol to the ignored symbol list */
405 /* if the name starts with '-' the symbol is removed instead */
406 void add_ignore_symbol( const char *name
)
410 if (!ignore_symbols
) init_ignored_symbols(); /* first time around, fill list with defaults */
412 if (name
[0] == '-') /* remove it */
414 if (!name
[1]) /* remove everything */
416 for (i
= 0; i
< nb_ignore_symbols
; i
++) free( ignore_symbols
[i
] );
417 nb_ignore_symbols
= 0;
421 for (i
= 0; i
< nb_ignore_symbols
; i
++)
423 if (!strcmp( ignore_symbols
[i
], name
+1 ))
425 free( ignore_symbols
[i
] );
426 memmove( &ignore_symbols
[i
], &ignore_symbols
[i
+1], nb_ignore_symbols
- i
- 1 );
434 if (nb_ignore_symbols
== ignore_size
)
437 ignore_symbols
= xrealloc( ignore_symbols
, ignore_size
* sizeof(*ignore_symbols
) );
439 ignore_symbols
[nb_ignore_symbols
++] = xstrdup( name
);
443 /* add a function to the list of imports from a given dll */
444 static void add_import_func( struct import
*imp
, ORDDEF
*func
)
446 imp
->imports
= xrealloc( imp
->imports
, (imp
->nb_imports
+1) * sizeof(*imp
->imports
) );
447 imp
->imports
[imp
->nb_imports
++] = func
;
449 if (imp
->delay
) total_delayed
++;
452 /* add a symbol to the undef list */
453 inline static void add_undef_symbol( const char *name
)
455 if (nb_undef_symbols
== undef_size
)
458 undef_symbols
= xrealloc( undef_symbols
, undef_size
* sizeof(*undef_symbols
) );
460 undef_symbols
[nb_undef_symbols
++] = xstrdup( name
);
463 /* remove all the holes in the undefined symbol list; return the number of removed symbols */
464 static int remove_symbol_holes(void)
467 for (i
= off
= 0; i
< nb_undef_symbols
; i
++)
469 if (!undef_symbols
[i
]) off
++;
470 else undef_symbols
[i
- off
] = undef_symbols
[i
];
472 nb_undef_symbols
-= off
;
476 /* add a symbol to the extra list, but only if needed */
477 static int add_extra_symbol( const char **extras
, int *count
, const char *name
, const DLLSPEC
*spec
)
481 if (!find_symbol( name
, undef_symbols
, nb_undef_symbols
))
483 /* check if the symbol is being exported by this dll */
484 for (i
= 0; i
< spec
->nb_entry_points
; i
++)
486 ORDDEF
*odp
= &spec
->entry_points
[i
];
487 if (odp
->type
== TYPE_STDCALL
||
488 odp
->type
== TYPE_CDECL
||
489 odp
->type
== TYPE_VARARGS
||
490 odp
->type
== TYPE_EXTERN
)
492 if (odp
->name
&& !strcmp( odp
->name
, name
)) return 0;
495 extras
[*count
] = name
;
501 /* add the extra undefined symbols that will be contained in the generated spec file itself */
502 static void add_extra_undef_symbols( const DLLSPEC
*spec
)
504 const char *extras
[10];
505 int i
, count
= 0, nb_stubs
= 0;
506 int kernel_imports
= 0, ntdll_imports
= 0;
508 sort_symbols( undef_symbols
, nb_undef_symbols
);
510 for (i
= 0; i
< spec
->nb_entry_points
; i
++)
512 ORDDEF
*odp
= &spec
->entry_points
[i
];
513 if (odp
->type
== TYPE_STUB
) nb_stubs
++;
516 /* add symbols that will be contained in the spec file itself */
517 if (!(spec
->characteristics
& IMAGE_FILE_DLL
))
519 switch (spec
->subsystem
)
521 case IMAGE_SUBSYSTEM_WINDOWS_GUI
:
522 case IMAGE_SUBSYSTEM_WINDOWS_CUI
:
523 kernel_imports
+= add_extra_symbol( extras
, &count
, "GetCommandLineA", spec
);
524 kernel_imports
+= add_extra_symbol( extras
, &count
, "GetStartupInfoA", spec
);
525 kernel_imports
+= add_extra_symbol( extras
, &count
, "GetModuleHandleA", spec
);
526 kernel_imports
+= add_extra_symbol( extras
, &count
, "ExitProcess", spec
);
532 kernel_imports
+= add_extra_symbol( extras
, &count
, "LoadLibraryA", spec
);
533 kernel_imports
+= add_extra_symbol( extras
, &count
, "FreeLibrary", spec
);
534 kernel_imports
+= add_extra_symbol( extras
, &count
, "GetProcAddress", spec
);
535 kernel_imports
+= add_extra_symbol( extras
, &count
, "RaiseException", spec
);
538 ntdll_imports
+= add_extra_symbol( extras
, &count
, "RtlRaiseException", spec
);
540 /* make sure we import the dlls that contain these functions */
541 if (kernel_imports
) add_import_dll( "kernel32", NULL
);
542 if (ntdll_imports
) add_import_dll( "ntdll", NULL
);
546 for (i
= 0; i
< count
; i
++) add_undef_symbol( extras
[i
] );
547 sort_symbols( undef_symbols
, nb_undef_symbols
);
551 /* check if a given imported dll is not needed, taking forwards into account */
552 static int check_unused( const struct import
* imp
, const DLLSPEC
*spec
)
555 const char *file_name
= imp
->spec
->file_name
;
556 size_t len
= strlen( file_name
);
557 const char *p
= strchr( file_name
, '.' );
558 if (p
&& !strcasecmp( p
, ".dll" )) len
= p
- file_name
;
560 for (i
= spec
->base
; i
<= spec
->limit
; i
++)
562 ORDDEF
*odp
= spec
->ordinals
[i
];
563 if (!odp
|| !(odp
->flags
& FLAG_FORWARD
)) continue;
564 if (!strncasecmp( odp
->link_name
, file_name
, len
) &&
565 odp
->link_name
[len
] == '.')
566 return 0; /* found a forward, it is used */
571 /* combine a list of object files with ld into a single object file */
572 /* returns the name of the combined file */
573 static const char *ldcombine_files( char **argv
)
579 if (output_file_name
&& output_file_name
[0])
581 ld_tmp_file
= xmalloc( strlen(output_file_name
) + 10 );
582 strcpy( ld_tmp_file
, output_file_name
);
583 strcat( ld_tmp_file
, ".XXXXXX.o" );
585 else ld_tmp_file
= xstrdup( "/tmp/winebuild.tmp.XXXXXX.o" );
587 if ((fd
= mkstemps( ld_tmp_file
, 2 ) == -1)) fatal_error( "could not generate a temp file\n" );
589 atexit( remove_ld_tmp_file
);
591 for (i
= 0; argv
[i
]; i
++) len
+= strlen(argv
[i
]) + 1;
592 cmd
= xmalloc( len
+ strlen(ld_tmp_file
) + 8 + strlen(ld_command
) );
593 sprintf( cmd
, "%s -r -o %s", ld_command
, ld_tmp_file
);
594 for (i
= 0; argv
[i
]; i
++) sprintf( cmd
+ strlen(cmd
), " %s", argv
[i
] );
596 if (err
) fatal_error( "%s -r failed with status %d\n", ld_command
, err
);
601 /* read in the list of undefined symbols */
602 void read_undef_symbols( char **argv
)
604 static const char name_prefix
[] = __ASM_NAME("");
605 static const int prefix_len
= sizeof(name_prefix
) - 1;
607 char *cmd
, buffer
[1024];
611 if (!argv
[0]) return;
613 undef_size
= nb_undef_symbols
= 0;
615 /* if we have multiple object files, link them together */
616 if (argv
[1]) name
= ldcombine_files( argv
);
619 cmd
= xmalloc( strlen(nm_command
) + strlen(name
) + 5 );
620 sprintf( cmd
, "%s -u %s", nm_command
, name
);
621 if (!(f
= popen( cmd
, "r" )))
622 fatal_error( "Cannot execute '%s'\n", cmd
);
624 while (fgets( buffer
, sizeof(buffer
), f
))
626 char *p
= buffer
+ strlen(buffer
) - 1;
627 if (p
< buffer
) continue;
628 if (*p
== '\n') *p
-- = 0;
630 while (*p
== ' ') p
++;
631 if (p
[0] == 'U' && p
[1] == ' ' && p
[2]) p
+= 2;
632 if (prefix_len
&& !strncmp( p
, name_prefix
, prefix_len
)) p
+= prefix_len
;
633 add_undef_symbol( p
);
635 if ((err
= pclose( f
))) warning( "%s failed with status %d\n", cmd
, err
);
639 static void remove_ignored_symbols(void)
643 if (!ignore_symbols
) init_ignored_symbols();
644 sort_symbols( ignore_symbols
, nb_ignore_symbols
);
645 for (i
= 0; i
< nb_undef_symbols
; i
++)
647 if (find_symbol( undef_symbols
[i
], ignore_symbols
, nb_ignore_symbols
))
649 free( undef_symbols
[i
] );
650 undef_symbols
[i
] = NULL
;
653 remove_symbol_holes();
656 /* resolve the imports for a Win32 module */
657 int resolve_imports( DLLSPEC
*spec
)
661 if (nb_undef_symbols
== -1) return 0; /* no symbol file specified */
663 add_extra_undef_symbols( spec
);
664 remove_ignored_symbols();
666 for (i
= 0; i
< nb_imports
; i
++)
668 struct import
*imp
= dll_imports
[i
];
670 for (j
= 0; j
< nb_undef_symbols
; j
++)
672 ORDDEF
*odp
= find_export( undef_symbols
[j
], imp
->exports
, imp
->nb_exports
);
675 add_import_func( imp
, odp
);
676 free( undef_symbols
[j
] );
677 undef_symbols
[j
] = NULL
;
680 /* remove all the holes in the undef symbols list */
681 if (!remove_symbol_holes() && check_unused( imp
, spec
))
683 /* the dll is not used, get rid of it */
684 warning( "%s imported but no symbols used\n", imp
->spec
->file_name
);
685 remove_import_dll( i
);
692 /* output the import table of a Win32 module */
693 static int output_immediate_imports( FILE *outfile
)
696 int nb_imm
= nb_imports
- nb_delayed
;
697 static const char import_thunks
[] = "__wine_spec_import_thunks";
699 if (!nb_imm
) goto done
;
701 /* main import header */
703 fprintf( outfile
, "\nstatic struct {\n" );
704 fprintf( outfile
, " struct {\n" );
705 fprintf( outfile
, " void *OriginalFirstThunk;\n" );
706 fprintf( outfile
, " unsigned int TimeDateStamp;\n" );
707 fprintf( outfile
, " unsigned int ForwarderChain;\n" );
708 fprintf( outfile
, " const char *Name;\n" );
709 fprintf( outfile
, " void *FirstThunk;\n" );
710 fprintf( outfile
, " } imp[%d];\n", nb_imm
+1 );
711 fprintf( outfile
, " const char *data[%d];\n",
712 total_imports
- total_delayed
+ nb_imm
);
713 fprintf( outfile
, "} imports = {\n {\n" );
717 for (i
= j
= 0; i
< nb_imports
; i
++)
719 if (dll_imports
[i
]->delay
) continue;
720 fprintf( outfile
, " { 0, 0, 0, \"%s\", &imports.data[%d] },\n",
721 dll_imports
[i
]->spec
->file_name
, j
);
722 j
+= dll_imports
[i
]->nb_imports
+ 1;
725 fprintf( outfile
, " { 0, 0, 0, 0, 0 },\n" );
726 fprintf( outfile
, " },\n {\n" );
728 /* list of imported functions */
730 for (i
= 0; i
< nb_imports
; i
++)
732 if (dll_imports
[i
]->delay
) continue;
733 fprintf( outfile
, " /* %s */\n", dll_imports
[i
]->spec
->file_name
);
734 for (j
= 0; j
< dll_imports
[i
]->nb_imports
; j
++)
736 ORDDEF
*odp
= dll_imports
[i
]->imports
[j
];
737 if (!(odp
->flags
& FLAG_NONAME
))
739 unsigned short ord
= odp
->ordinal
;
740 fprintf( outfile
, " \"\\%03o\\%03o%s\",\n",
741 *(unsigned char *)&ord
, *((unsigned char *)&ord
+ 1), odp
->name
);
744 fprintf( outfile
, " (char *)%d,\n", odp
->ordinal
);
746 fprintf( outfile
, " 0,\n" );
748 fprintf( outfile
, " }\n};\n\n" );
750 /* thunks for imported functions */
752 fprintf( outfile
, "#ifndef __GNUC__\nstatic void __asm__dummy_import(void) {\n#endif\n\n" );
753 pos
= (sizeof(void *) + 2*sizeof(unsigned int) + sizeof(const char *) + sizeof(void *)) *
754 (nb_imm
+ 1); /* offset of imports.data from start of imports */
755 fprintf( outfile
, "asm(\".text\\n\\t.align %d\\n\"\n", get_alignment(8) );
756 fprintf( outfile
, " \"" __ASM_NAME("%s") ":\\n\"\n", import_thunks
);
758 for (i
= 0; i
< nb_imports
; i
++)
760 if (dll_imports
[i
]->delay
) continue;
761 for (j
= 0; j
< dll_imports
[i
]->nb_imports
; j
++, pos
+= sizeof(const char *))
763 ORDDEF
*odp
= dll_imports
[i
]->imports
[j
];
764 const char *name
= odp
->name
? odp
->name
: odp
->export_name
;
765 fprintf( outfile
, " \"\\t" __ASM_FUNC("%s") "\\n\"\n", name
);
766 fprintf( outfile
, " \"\\t.globl " __ASM_NAME("%s") "\\n\"\n", name
);
767 fprintf( outfile
, " \"" __ASM_NAME("%s") ":\\n\\t", name
);
770 #if defined(__i386__)
771 if (strstr( name
, "__wine_call_from_16" ))
772 fprintf( outfile
, ".byte 0x2e\\n\\tjmp *(imports+%d)\\n\\tnop\\n", pos
);
774 fprintf( outfile
, "jmp *(imports+%d)\\n\\tmovl %%esi,%%esi\\n", pos
);
775 #elif defined(__sparc__)
778 fprintf( outfile
, "sethi %%hi(imports+%d), %%g1\\n\\t", pos
);
779 fprintf( outfile
, "ld [%%g1+%%lo(imports+%d)], %%g1\\n\\t", pos
);
780 fprintf( outfile
, "jmp %%g1\\n\\tnop\\n" );
784 /* Hmpf. Stupid sparc assembler always interprets global variable
785 names as GOT offsets, so we have to do it the long way ... */
786 fprintf( outfile
, "save %%sp, -96, %%sp\\n" );
787 fprintf( outfile
, "0:\\tcall 1f\\n\\tnop\\n" );
788 fprintf( outfile
, "1:\\tsethi %%hi(imports+%d-0b), %%g1\\n\\t", pos
);
789 fprintf( outfile
, "or %%g1, %%lo(imports+%d-0b), %%g1\\n\\t", pos
);
790 fprintf( outfile
, "ld [%%g1+%%o7], %%g1\\n\\t" );
791 fprintf( outfile
, "jmp %%g1\\n\\trestore\\n" );
794 #elif defined(__powerpc__)
795 fprintf(outfile
, "\taddi %s, %s, -0x4\\n\"\n", ppc_reg
[1], ppc_reg
[1]);
796 fprintf(outfile
, "\t\"\\tstw %s, 0(%s)\\n\"\n", ppc_reg
[9], ppc_reg
[1]);
797 fprintf(outfile
, "\t\"\\taddi %s, %s, -0x4\\n\"\n", ppc_reg
[1], ppc_reg
[1]);
798 fprintf(outfile
, "\t\"\\tstw %s, 0(%s)\\n\"\n", ppc_reg
[8], ppc_reg
[1]);
799 fprintf(outfile
, "\t\"\\taddi %s, %s, -0x4\\n\"\n", ppc_reg
[1], ppc_reg
[1]);
800 fprintf(outfile
, "\t\"\\tstw %s, 0(%s)\\n\"\n", ppc_reg
[7], ppc_reg
[1]);
802 fprintf(outfile
, "\t\"\\tlis %s, " ppc_high(__ASM_NAME("imports") "+ %d") "\\n\"\n", ppc_reg
[9], pos
);
803 fprintf(outfile
, "\t\"\\tla %s, " ppc_low (__ASM_NAME("imports") "+ %d") "(%s)\\n\"\n", ppc_reg
[8], pos
, ppc_reg
[9]);
804 fprintf(outfile
, "\t\"\\tlwz %s, 0(%s)\\n\"\n", ppc_reg
[7], ppc_reg
[8]);
805 fprintf(outfile
, "\t\"\\tmtctr %s\\n\"\n", ppc_reg
[7]);
807 fprintf(outfile
, "\t\"\\tlwz %s, 0(%s)\\n\"\n", ppc_reg
[7], ppc_reg
[1]);
808 fprintf(outfile
, "\t\"\\taddi %s, %s, 0x4\\n\"\n", ppc_reg
[1], ppc_reg
[1]);
809 fprintf(outfile
, "\t\"\\tlwz %s, 0(%s)\\n\"\n", ppc_reg
[8], ppc_reg
[1]);
810 fprintf(outfile
, "\t\"\\taddi %s, %s, 0x4\\n\"\n", ppc_reg
[1], ppc_reg
[1]);
811 fprintf(outfile
, "\t\"\\tlwz %s, 0(%s)\\n\"\n", ppc_reg
[9], ppc_reg
[1]);
812 fprintf(outfile
, "\t\"\\taddi %s, %s, 0x4\\n\"\n", ppc_reg
[1], ppc_reg
[1]);
813 fprintf(outfile
, "\t\"\\tbctr\\n");
814 #elif defined(__ALPHA__)
815 fprintf( outfile
, "\tlda $0,imports\\n\"\n" );
816 fprintf( outfile
, "\t\"\\tlda $0,%d($0)\\n\"\n", pos
);
817 fprintf( outfile
, "\t\"\\tjmp $31,($0)\\n" );
819 #error You need to define import thunks for your architecture!
821 #endif /*__REACTOS__*/
822 fprintf( outfile
, "\"\n" );
823 output_function_size( outfile
, name
);
827 output_function_size( outfile
, import_thunks
);
828 fprintf( outfile
, " \".text\");\n#ifndef __GNUC__\n}\n#endif\n\n" );
834 /* output the delayed import table of a Win32 module */
835 static int output_delayed_imports( FILE *outfile
, const DLLSPEC
*spec
)
838 static const char delayed_import_loaders
[] = "__wine_spec_delayed_import_loaders";
839 static const char delayed_import_thunks
[] = "__wine_spec_delayed_import_thunks";
841 if (!nb_delayed
) goto done
;
843 fprintf( outfile
, "static void *__wine_delay_imp_hmod[%d];\n", nb_delayed
);
844 for (i
= 0; i
< nb_imports
; i
++)
846 if (!dll_imports
[i
]->delay
) continue;
847 for (j
= 0; j
< dll_imports
[i
]->nb_imports
; j
++)
849 ORDDEF
*odp
= dll_imports
[i
]->imports
[j
];
850 const char *name
= odp
->name
? odp
->name
: odp
->export_name
;
851 fprintf( outfile
, "void __wine_delay_imp_%d_%s();\n", i
, name
);
854 fprintf( outfile
, "\n" );
855 fprintf( outfile
, "static struct {\n" );
856 fprintf( outfile
, " struct ImgDelayDescr {\n" );
857 fprintf( outfile
, " unsigned int grAttrs;\n" );
858 fprintf( outfile
, " const char *szName;\n" );
859 fprintf( outfile
, " void **phmod;\n" );
860 fprintf( outfile
, " void **pIAT;\n" );
861 fprintf( outfile
, " const char **pINT;\n" );
862 fprintf( outfile
, " void* pBoundIAT;\n" );
863 fprintf( outfile
, " void* pUnloadIAT;\n" );
864 fprintf( outfile
, " unsigned long dwTimeStamp;\n" );
865 fprintf( outfile
, " } imp[%d];\n", nb_delayed
);
866 fprintf( outfile
, " void *IAT[%d];\n", total_delayed
);
867 fprintf( outfile
, " const char *INT[%d];\n", total_delayed
);
868 fprintf( outfile
, "} delay_imports = {\n" );
869 fprintf( outfile
, " {\n" );
870 for (i
= j
= 0; i
< nb_imports
; i
++)
872 if (!dll_imports
[i
]->delay
) continue;
873 fprintf( outfile
, " { 0, \"%s\", &__wine_delay_imp_hmod[%d], &delay_imports.IAT[%d], &delay_imports.INT[%d], 0, 0, 0 },\n",
874 dll_imports
[i
]->spec
->file_name
, i
, j
, j
);
875 j
+= dll_imports
[i
]->nb_imports
;
877 fprintf( outfile
, " },\n {\n" );
878 for (i
= 0; i
< nb_imports
; i
++)
880 if (!dll_imports
[i
]->delay
) continue;
881 fprintf( outfile
, " /* %s */\n", dll_imports
[i
]->spec
->file_name
);
882 for (j
= 0; j
< dll_imports
[i
]->nb_imports
; j
++)
884 ORDDEF
*odp
= dll_imports
[i
]->imports
[j
];
885 const char *name
= odp
->name
? odp
->name
: odp
->export_name
;
886 fprintf( outfile
, " &__wine_delay_imp_%d_%s,\n", i
, name
);
889 fprintf( outfile
, " },\n {\n" );
890 for (i
= 0; i
< nb_imports
; i
++)
892 if (!dll_imports
[i
]->delay
) continue;
893 fprintf( outfile
, " /* %s */\n", dll_imports
[i
]->spec
->file_name
);
894 for (j
= 0; j
< dll_imports
[i
]->nb_imports
; j
++)
896 ORDDEF
*odp
= dll_imports
[i
]->imports
[j
];
898 fprintf( outfile
, " (char *)%d,\n", odp
->ordinal
);
900 fprintf( outfile
, " \"%s\",\n", odp
->name
);
903 fprintf( outfile
, " }\n};\n\n" );
905 fprintf( outfile
, "extern void __stdcall RaiseException(unsigned int, unsigned int, unsigned int, const void *args[]);\n" );
906 fprintf( outfile
, "extern void * __stdcall LoadLibraryA(const char*);\n");
907 fprintf( outfile
, "extern void * __stdcall GetProcAddress(void *, const char*);\n");
908 fprintf( outfile
, "\n" );
910 fprintf( outfile
, "void *__stdcall __wine_delay_load( int idx_nr )\n" );
911 fprintf( outfile
, "{\n" );
912 fprintf( outfile
, " int idx = idx_nr >> 16, nr = idx_nr & 0xffff;\n" );
913 fprintf( outfile
, " struct ImgDelayDescr *imd = delay_imports.imp + idx;\n" );
914 fprintf( outfile
, " void **pIAT = imd->pIAT + nr;\n" );
915 fprintf( outfile
, " const char** pINT = imd->pINT + nr;\n" );
916 fprintf( outfile
, " void *fn;\n\n" );
918 fprintf( outfile
, " if (!*imd->phmod) *imd->phmod = LoadLibraryA(imd->szName);\n" );
919 fprintf( outfile
, " if (*imd->phmod && (fn = GetProcAddress(*imd->phmod, *pINT)))\n");
920 fprintf( outfile
, " /* patch IAT with final value */\n" );
921 fprintf( outfile
, " return *pIAT = fn;\n" );
922 fprintf( outfile
, " else {\n");
923 fprintf( outfile
, " const void *args[2];\n" );
924 fprintf( outfile
, " args[0] = imd->szName;\n" );
925 fprintf( outfile
, " args[1] = *pINT;\n" );
926 fprintf( outfile
, " RaiseException( 0x%08x, %d, 2, args );\n",
927 EXCEPTION_WINE_STUB
, EXCEPTION_NONCONTINUABLE
);
928 fprintf( outfile
, " return 0;\n" );
929 fprintf( outfile
, " }\n}\n\n" );
931 fprintf( outfile
, "#ifndef __GNUC__\n" );
932 fprintf( outfile
, "static void __asm__dummy_delay_import(void) {\n" );
933 fprintf( outfile
, "#endif\n" );
935 fprintf( outfile
, "asm(\".align %d\\n\"\n", get_alignment(8) );
936 fprintf( outfile
, " \"" __ASM_NAME("%s") ":\\n\"\n", delayed_import_loaders
);
937 fprintf( outfile
, " \"\\t" __ASM_FUNC("__wine_delay_load_asm") "\\n\"\n" );
938 fprintf( outfile
, " \"" __ASM_NAME("__wine_delay_load_asm") ":\\n\"\n" );
939 #if defined(__i386__)
940 fprintf( outfile
, " \"\\tpushl %%ecx\\n\\tpushl %%edx\\n\\tpushl %%eax\\n\"\n" );
941 fprintf( outfile
, " \"\\tcall __wine_delay_load\\n\"\n" );
942 fprintf( outfile
, " \"\\tpopl %%edx\\n\\tpopl %%ecx\\n\\tjmp *%%eax\\n\"\n" );
943 #elif defined(__sparc__)
944 fprintf( outfile
, " \"\\tsave %%sp, -96, %%sp\\n\"\n" );
945 fprintf( outfile
, " \"\\tcall __wine_delay_load\\n\"\n" );
946 fprintf( outfile
, " \"\\tmov %%g1, %%o0\\n\"\n" );
947 fprintf( outfile
, " \"\\tjmp %%o0\\n\\trestore\\n\"\n" );
948 #elif defined(__powerpc__)
949 # if defined(__APPLE__)
950 /* On darwin an extra 56 bytes must be allowed for the linkage area+param area */
951 # define extra_stack_storage 56
953 # define extra_stack_storage 0
955 /* Save all callee saved registers into a stackframe. */
956 fprintf( outfile
, " \"\\tstwu %s, -%d(%s)\\n\"\n",ppc_reg
[1], 48+extra_stack_storage
, ppc_reg
[1]);
957 fprintf( outfile
, " \"\\tstw %s, %d(%s)\\n\"\n", ppc_reg
[3], 4+extra_stack_storage
, ppc_reg
[1]);
958 fprintf( outfile
, " \"\\tstw %s, %d(%s)\\n\"\n", ppc_reg
[4], 8+extra_stack_storage
, ppc_reg
[1]);
959 fprintf( outfile
, " \"\\tstw %s, %d(%s)\\n\"\n", ppc_reg
[5], 12+extra_stack_storage
, ppc_reg
[1]);
960 fprintf( outfile
, " \"\\tstw %s, %d(%s)\\n\"\n", ppc_reg
[6], 16+extra_stack_storage
, ppc_reg
[1]);
961 fprintf( outfile
, " \"\\tstw %s, %d(%s)\\n\"\n", ppc_reg
[7], 20+extra_stack_storage
, ppc_reg
[1]);
962 fprintf( outfile
, " \"\\tstw %s, %d(%s)\\n\"\n", ppc_reg
[8], 24+extra_stack_storage
, ppc_reg
[1]);
963 fprintf( outfile
, " \"\\tstw %s, %d(%s)\\n\"\n", ppc_reg
[9], 28+extra_stack_storage
, ppc_reg
[1]);
964 fprintf( outfile
, " \"\\tstw %s, %d(%s)\\n\"\n", ppc_reg
[10],32+extra_stack_storage
, ppc_reg
[1]);
965 fprintf( outfile
, " \"\\tstw %s, %d(%s)\\n\"\n", ppc_reg
[11],36+extra_stack_storage
, ppc_reg
[1]);
966 fprintf( outfile
, " \"\\tstw %s, %d(%s)\\n\"\n", ppc_reg
[12],40+extra_stack_storage
, ppc_reg
[1]);
968 /* r0 -> r3 (arg1) */
969 fprintf( outfile
, " \"\\tmr %s, %s\\n\"\n", ppc_reg
[3], ppc_reg
[0]);
971 /* save return address */
972 fprintf( outfile
, " \"\\tmflr %s\\n\"\n", ppc_reg
[0]);
973 fprintf( outfile
, " \"\\tstw %s, %d(%s)\\n\"\n", ppc_reg
[0], 44+extra_stack_storage
, ppc_reg
[1]);
975 /* Call the __wine_delay_load function, arg1 is arg1. */
976 fprintf( outfile
, " \"\\tbl " __ASM_NAME("__wine_delay_load") "\\n\"\n");
978 /* Load return value from call into ctr register */
979 fprintf( outfile
, " \"\\tmtctr %s\\n\"\n", ppc_reg
[3]);
981 /* restore all saved registers and drop stackframe. */
982 fprintf( outfile
, " \"\\tlwz %s, %d(%s)\\n\"\n", ppc_reg
[3], 4+extra_stack_storage
, ppc_reg
[1]);
983 fprintf( outfile
, " \"\\tlwz %s, %d(%s)\\n\"\n", ppc_reg
[4], 8+extra_stack_storage
, ppc_reg
[1]);
984 fprintf( outfile
, " \"\\tlwz %s, %d(%s)\\n\"\n", ppc_reg
[5], 12+extra_stack_storage
, ppc_reg
[1]);
985 fprintf( outfile
, " \"\\tlwz %s, %d(%s)\\n\"\n", ppc_reg
[6], 16+extra_stack_storage
, ppc_reg
[1]);
986 fprintf( outfile
, " \"\\tlwz %s, %d(%s)\\n\"\n", ppc_reg
[7], 20+extra_stack_storage
, ppc_reg
[1]);
987 fprintf( outfile
, " \"\\tlwz %s, %d(%s)\\n\"\n", ppc_reg
[8], 24+extra_stack_storage
, ppc_reg
[1]);
988 fprintf( outfile
, " \"\\tlwz %s, %d(%s)\\n\"\n", ppc_reg
[9], 28+extra_stack_storage
, ppc_reg
[1]);
989 fprintf( outfile
, " \"\\tlwz %s, %d(%s)\\n\"\n", ppc_reg
[10],32+extra_stack_storage
, ppc_reg
[1]);
990 fprintf( outfile
, " \"\\tlwz %s, %d(%s)\\n\"\n", ppc_reg
[11],36+extra_stack_storage
, ppc_reg
[1]);
991 fprintf( outfile
, " \"\\tlwz %s, %d(%s)\\n\"\n", ppc_reg
[12],40+extra_stack_storage
, ppc_reg
[1]);
993 /* Load return value from call into return register */
994 fprintf( outfile
, " \"\\tlwz %s, %d(%s)\\n\"\n", ppc_reg
[0], 44+extra_stack_storage
, ppc_reg
[1]);
995 fprintf( outfile
, " \"\\tmtlr %s\\n\"\n", ppc_reg
[0]);
996 fprintf( outfile
, " \"\\taddi %s, %s, %d\\n\"\n", ppc_reg
[1], ppc_reg
[1], 48+extra_stack_storage
);
998 /* branch to ctr register. */
999 fprintf( outfile
, " \"bctr\\n\"\n");
1000 #elif defined(__ALPHA__)
1001 fprintf( outfile
, " \"\\tjsr $26,__wine_delay_load\\n\"\n" );
1002 fprintf( outfile
, " \"\\tjmp $31,($0)\\n\"\n" );
1004 #error You need to defined delayed import thunks for your architecture!
1006 output_function_size( outfile
, "__wine_delay_load_asm" );
1008 for (i
= idx
= 0; i
< nb_imports
; i
++)
1010 if (!dll_imports
[i
]->delay
) continue;
1011 for (j
= 0; j
< dll_imports
[i
]->nb_imports
; j
++)
1014 ORDDEF
*odp
= dll_imports
[i
]->imports
[j
];
1015 const char *name
= odp
->name
? odp
->name
: odp
->export_name
;
1017 sprintf( buffer
, "__wine_delay_imp_%d_%s", i
, name
);
1018 fprintf( outfile
, " \"\\t" __ASM_FUNC("%s") "\\n\"\n", buffer
);
1019 fprintf( outfile
, " \"" __ASM_NAME("%s") ":\\n\"\n", buffer
);
1020 #if defined(__i386__)
1021 fprintf( outfile
, " \"\\tmovl $%d, %%eax\\n\"\n", (idx
<< 16) | j
);
1022 fprintf( outfile
, " \"\\tjmp __wine_delay_load_asm\\n\"\n" );
1023 #elif defined(__sparc__)
1024 fprintf( outfile
, " \"\\tset %d, %%g1\\n\"\n", (idx
<< 16) | j
);
1025 fprintf( outfile
, " \"\\tb,a __wine_delay_load_asm\\n\"\n" );
1026 #elif defined(__powerpc__)
1028 /* On Darwin we can use r0 and r2 */
1029 /* Upper part in r2 */
1030 fprintf( outfile
, " \"\\tlis %s, %d\\n\"\n", ppc_reg
[2], idx
);
1031 /* Lower part + r2 -> r0, Note we can't use r0 directly */
1032 fprintf( outfile
, " \"\\taddi %s, %s, %d\\n\"\n", ppc_reg
[0], ppc_reg
[2], j
);
1033 fprintf( outfile
, " \"\\tb " __ASM_NAME("__wine_delay_load_asm") "\\n\"\n");
1034 #else /* __APPLE__ */
1035 /* On linux we can't use r2 since r2 is not a scratch register (hold the TOC) */
1036 /* Save r13 on the stack */
1037 fprintf( outfile
, " \"\\taddi %s, %s, -0x4\\n\"\n", ppc_reg
[1], ppc_reg
[1]);
1038 fprintf( outfile
, " \"\\tstw %s, 0(%s)\\n\"\n", ppc_reg
[13], ppc_reg
[1]);
1039 /* Upper part in r13 */
1040 fprintf( outfile
, " \"\\tlis %s, %d\\n\"\n", ppc_reg
[13], idx
);
1041 /* Lower part + r13 -> r0, Note we can't use r0 directly */
1042 fprintf( outfile
, " \"\\taddi %s, %s, %d\\n\"\n", ppc_reg
[0], ppc_reg
[13], j
);
1044 fprintf( outfile
, " \"\\tstw %s, 0(%s)\\n\"\n", ppc_reg
[13], ppc_reg
[1]);
1045 fprintf( outfile
, " \"\\taddic %s, %s, 0x4\\n\"\n", ppc_reg
[1], ppc_reg
[1]);
1046 fprintf( outfile
, " \"\\tb " __ASM_NAME("__wine_delay_load_asm") "\\n\"\n");
1047 #endif /* __APPLE__ */
1048 #elif defined(__ALPHA__)
1049 fprintf( outfile
, " \"\\tlda $0,%d($31)\\n\"\n", j
);
1050 fprintf( outfile
, " \"\\tldah $0,%d($0)\\n\"\n", idx
);
1051 fprintf( outfile
, " \"\\tjmp $31,__wine_delay_load_asm\\n\"\n" );
1053 #error You need to defined delayed import thunks for your architecture!
1055 output_function_size( outfile
, name
);
1059 output_function_size( outfile
, delayed_import_loaders
);
1061 fprintf( outfile
, "\n \".align %d\\n\"\n", get_alignment(8) );
1062 fprintf( outfile
, " \"" __ASM_NAME("%s") ":\\n\"\n", delayed_import_thunks
);
1063 pos
= nb_delayed
* 32;
1064 for (i
= 0; i
< nb_imports
; i
++)
1066 if (!dll_imports
[i
]->delay
) continue;
1067 for (j
= 0; j
< dll_imports
[i
]->nb_imports
; j
++, pos
+= 4)
1069 ORDDEF
*odp
= dll_imports
[i
]->imports
[j
];
1070 const char *name
= odp
->name
? odp
->name
: odp
->export_name
;
1072 fprintf( outfile
, " \"\\t" __ASM_FUNC("%s") "\\n\"\n", name
);
1073 fprintf( outfile
, " \"\\t.globl " __ASM_NAME("%s") "\\n\"\n", name
);
1074 fprintf( outfile
, " \"" __ASM_NAME("%s") ":\\n\\t\"", name
);
1075 #if defined(__i386__)
1076 if (strstr( name
, "__wine_call_from_16" ))
1077 fprintf( outfile
, "\".byte 0x2e\\n\\tjmp *(delay_imports+%d)\\n\\tnop\\n\"", pos
);
1079 fprintf( outfile
, "\"jmp *(delay_imports+%d)\\n\\tmovl %%esi,%%esi\\n\"", pos
);
1080 #elif defined(__sparc__)
1083 fprintf( outfile
, "\"sethi %%hi(delay_imports+%d), %%g1\\n\\t\"", pos
);
1084 fprintf( outfile
, "\"ld [%%g1+%%lo(delay_imports+%d)], %%g1\\n\\t\"", pos
);
1085 fprintf( outfile
, "\"jmp %%g1\\n\\tnop\\n\"" );
1089 /* Hmpf. Stupid sparc assembler always interprets global variable
1090 names as GOT offsets, so we have to do it the long way ... */
1091 fprintf( outfile
, "\"save %%sp, -96, %%sp\\n\"" );
1092 fprintf( outfile
, "\"0:\\tcall 1f\\n\\tnop\\n\"" );
1093 fprintf( outfile
, "\"1:\\tsethi %%hi(delay_imports+%d-0b), %%g1\\n\\t\"", pos
);
1094 fprintf( outfile
, "\"or %%g1, %%lo(delay_imports+%d-0b), %%g1\\n\\t\"", pos
);
1095 fprintf( outfile
, "\"ld [%%g1+%%o7], %%g1\\n\\t\"" );
1096 fprintf( outfile
, "\"jmp %%g1\\n\\trestore\\n\"" );
1099 #elif defined(__powerpc__)
1100 fprintf( outfile
, "\t\"addi %s, %s, -0x4\\n\"\n", ppc_reg
[1], ppc_reg
[1]);
1101 fprintf( outfile
, "\t\"\\tstw %s, 0(%s)\\n\"\n", ppc_reg
[9], ppc_reg
[1]);
1102 fprintf( outfile
, "\t\"\\taddi %s, %s, -0x4\\n\"\n", ppc_reg
[1], ppc_reg
[1]);
1103 fprintf( outfile
, "\t\"\\tstw %s, 0(%s)\\n\"\n", ppc_reg
[8], ppc_reg
[1]);
1104 fprintf( outfile
, "\t\"\\taddi %s, %s, -0x4\\n\"\n", ppc_reg
[1], ppc_reg
[1]);
1105 fprintf( outfile
, "\t\"\\tstw %s, 0(%s)\\n\"\n", ppc_reg
[7], ppc_reg
[1]);
1107 fprintf( outfile
, "\t\"\\tlis %s, " ppc_high(__ASM_NAME("delay_imports") "+ %d") "\\n\"\n", ppc_reg
[9], pos
);
1108 fprintf( outfile
, "\t\"\\tla %s, " ppc_low (__ASM_NAME("delay_imports") "+ %d") "(%s)\\n\"\n", ppc_reg
[8], pos
, ppc_reg
[9]);
1109 fprintf( outfile
, "\t\"\\tlwz %s, 0(%s)\\n\"\n", ppc_reg
[7], ppc_reg
[8]);
1110 fprintf( outfile
, "\t\"\\tmtctr %s\\n\"\n", ppc_reg
[7]);
1112 fprintf( outfile
, "\t\"\\tlwz %s, 0(%s)\\n\"\n", ppc_reg
[7], ppc_reg
[1]);
1113 fprintf( outfile
, "\t\"\\taddi %s, %s, 0x4\\n\"\n", ppc_reg
[1], ppc_reg
[1]);
1114 fprintf( outfile
, "\t\"\\tlwz %s, 0(%s)\\n\"\n", ppc_reg
[8], ppc_reg
[1]);
1115 fprintf( outfile
, "\t\"\\taddi %s, %s, 0x4\\n\"\n", ppc_reg
[1], ppc_reg
[1]);
1116 fprintf( outfile
, "\t\"\\tlwz %s, 0(%s)\\n\"\n", ppc_reg
[9], ppc_reg
[1]);
1117 fprintf( outfile
, "\t\"\\taddi %s, %s, 0x4\\n\"\n", ppc_reg
[1], ppc_reg
[1]);
1118 fprintf( outfile
, "\t\"\\tbctr\\n\"");
1119 #elif defined(__ALPHA__)
1120 fprintf( outfile
, "\t\"lda $0,delay_imports\\n\"\n" );
1121 fprintf( outfile
, "\t\"\\tlda $0,%d($0)\\n\"\n", pos
);
1122 fprintf( outfile
, "\t\"\\tjmp $31,($0)\\n\"" );
1124 #error You need to define delayed import thunks for your architecture!
1126 fprintf( outfile
, "\n" );
1127 output_function_size( outfile
, name
);
1130 output_function_size( outfile
, delayed_import_thunks
);
1131 fprintf( outfile
, ");\n" );
1132 fprintf( outfile
, "#ifndef __GNUC__\n" );
1133 fprintf( outfile
, "}\n" );
1134 fprintf( outfile
, "#endif\n" );
1135 fprintf( outfile
, "\n" );
1141 /* output the import and delayed import tables of a Win32 module
1142 * returns number of DLLs exported in 'immediate' mode
1144 int output_imports( FILE *outfile
, DLLSPEC
*spec
, int *nb_delayed
)
1146 *nb_delayed
= output_delayed_imports( outfile
, spec
);
1147 return output_immediate_imports( outfile
);