4 * Copyright 2000 Alexandre Julliard
20 char *dll
; /* dll name */
21 int delay
; /* delay or not dll loading ? */
22 char **exports
; /* functions exported from this dll */
23 int nb_exports
; /* number of exported functions */
24 char **imports
; /* functions we want to import from this dll */
25 int nb_imports
; /* number of imported functions */
26 int lineno
; /* line in .spec file where import is defined */
29 static char **undef_symbols
; /* list of undefined symbols */
30 static int nb_undef_symbols
= -1;
31 static int undef_size
;
33 static char **ignore_symbols
; /* list of symbols to ignore */
34 static int nb_ignore_symbols
;
35 static int ignore_size
;
37 static struct import
**dll_imports
= NULL
;
38 static int nb_imports
= 0; /* number of imported dlls (delayed or not) */
39 static int nb_delayed
= 0; /* number of delayed dlls */
40 static int total_imports
= 0; /* total number of imported functions */
41 static int total_delayed
= 0; /* total number of imported functions in delayed DLLs */
43 /* compare function names; helper for resolve_imports */
44 static int name_cmp( const void *name
, const void *entry
)
46 return strcmp( *(char **)name
, *(char **)entry
);
49 /* locate a symbol in a (sorted) list */
50 inline static const char *find_symbol( const char *name
, char **table
, int size
)
55 res
= bsearch( &name
, table
, size
, sizeof(*table
), name_cmp
);
58 return res
? *res
: NULL
;
61 /* sort a symbol table */
62 inline static void sort_symbols( char **table
, int size
)
65 qsort( table
, size
, sizeof(*table
), name_cmp
);
68 /* open the .so library for a given dll in a specified path */
69 static char *try_library_path( const char *path
, const char *name
)
74 buffer
= xmalloc( strlen(path
) + strlen(name
) + 8 );
75 sprintf( buffer
, "%s/lib%s", path
, name
);
76 p
= buffer
+ strlen(buffer
) - 4;
77 if (!strcmp( p
, ".dll" )) *p
= 0;
78 strcat( buffer
, ".so" );
79 /* check if the file exists */
80 if ((fd
= open( buffer
, O_RDONLY
)) == -1) return NULL
;
85 /* open the .so library for a given dll */
86 static char *open_library( const char *name
)
91 for (i
= 0; i
< nb_lib_paths
; i
++)
93 if ((fullname
= try_library_path( lib_path
[i
], name
))) return fullname
;
95 if (!(fullname
= try_library_path( ".", name
)))
96 fatal_error( "could not open .so file for %s\n", name
);
100 /* read in the list of exported symbols of a .so */
101 static void read_exported_symbols( const char *name
, struct import
*imp
)
105 char *fullname
, *cmdline
;
110 imp
->nb_exports
= size
= 0;
112 if (!(ext
= strrchr( name
, '.' ))) ext
= name
+ strlen(name
);
114 if (!(fullname
= open_library( name
))) return;
115 cmdline
= xmalloc( strlen(fullname
) + 4 );
116 sprintf( cmdline
, "nm %s", fullname
);
119 if (!(f
= popen( cmdline
, "r" )))
120 fatal_error( "Cannot execute '%s'\n", cmdline
);
122 while (fgets( buffer
, sizeof(buffer
), f
))
124 char *p
= buffer
+ strlen(buffer
) - 1;
125 if (p
< buffer
) continue;
126 if (*p
== '\n') *p
-- = 0;
127 if (!(p
= strstr( buffer
, "__wine_dllexport_" ))) continue;
129 if (strncmp( p
, name
, ext
- name
)) continue;
131 if (*p
++ != '_') continue;
133 if (imp
->nb_exports
== size
)
136 imp
->exports
= xrealloc( imp
->exports
, size
* sizeof(*imp
->exports
) );
138 imp
->exports
[imp
->nb_exports
++] = xstrdup( p
);
140 if ((err
= pclose( f
))) fatal_error( "%s error %d\n", cmdline
, err
);
142 sort_symbols( imp
->exports
, imp
->nb_exports
);
145 /* add a dll to the list of imports */
146 void add_import_dll( const char *name
, int delay
)
148 struct import
*imp
= xmalloc( sizeof(*imp
) );
149 imp
->dll
= xstrdup( name
);
153 /* GetToken for the file name has swallowed the '\n', hence pointing to next line */
154 imp
->lineno
= current_line
- 1;
156 if (delay
) nb_delayed
++;
157 read_exported_symbols( name
, imp
);
159 dll_imports
= xrealloc( dll_imports
, (nb_imports
+1) * sizeof(*dll_imports
) );
160 dll_imports
[nb_imports
++] = imp
;
163 /* Add a symbol to the ignored symbol list */
164 void add_ignore_symbol( const char *name
)
166 if (nb_ignore_symbols
== ignore_size
)
169 ignore_symbols
= xrealloc( ignore_symbols
, ignore_size
* sizeof(*ignore_symbols
) );
171 ignore_symbols
[nb_ignore_symbols
++] = xstrdup( name
);
174 /* add a function to the list of imports from a given dll */
175 static void add_import_func( struct import
*imp
, const char *name
)
177 imp
->imports
= xrealloc( imp
->imports
, (imp
->nb_imports
+1) * sizeof(*imp
->imports
) );
178 imp
->imports
[imp
->nb_imports
++] = xstrdup( name
);
180 if (imp
->delay
) total_delayed
++;
183 /* add a symbol to the undef list */
184 inline static void add_undef_symbol( const char *name
)
186 if (nb_undef_symbols
== undef_size
)
189 undef_symbols
= xrealloc( undef_symbols
, undef_size
* sizeof(*undef_symbols
) );
191 undef_symbols
[nb_undef_symbols
++] = xstrdup( name
);
194 /* remove all the holes in the undefined symbol list; return the number of removed symbols */
195 static int remove_symbol_holes(void)
198 for (i
= off
= 0; i
< nb_undef_symbols
; i
++)
200 if (!undef_symbols
[i
]) off
++;
201 else undef_symbols
[i
- off
] = undef_symbols
[i
];
203 nb_undef_symbols
-= off
;
207 /* add the extra undefined symbols that will be contained in the generated spec file itself */
208 static void add_extra_undef_symbols(void)
210 const char *extras
[10];
213 #define ADD_SYM(name) \
214 do { if (!find_symbol( extras[count] = (name), undef_symbols, \
215 nb_undef_symbols )) count++; } while(0)
217 sort_symbols( undef_symbols
, nb_undef_symbols
);
219 /* add symbols that will be contained in the spec file itself */
224 case SPEC_MODE_GUIEXE
:
225 ADD_SYM( "GetCommandLineA" );
226 ADD_SYM( "GetStartupInfoA" );
227 ADD_SYM( "GetModuleHandleA" );
229 case SPEC_MODE_CUIEXE
:
230 ADD_SYM( "__wine_get_main_args" );
231 ADD_SYM( "ExitProcess" );
233 case SPEC_MODE_GUIEXE_UNICODE
:
234 ADD_SYM( "GetCommandLineA" );
235 ADD_SYM( "GetStartupInfoA" );
236 ADD_SYM( "GetModuleHandleA" );
238 case SPEC_MODE_CUIEXE_UNICODE
:
239 ADD_SYM( "__wine_get_wmain_args" );
240 ADD_SYM( "ExitProcess" );
243 ADD_SYM( "RtlRaiseException" );
246 ADD_SYM( "LoadLibraryA" );
247 ADD_SYM( "GetProcAddress" );
250 for (i
= 0; i
< nb_entry_points
; i
++)
252 ORDDEF
*odp
= EntryPoints
[i
];
253 if (odp
->flags
& FLAG_REGISTER
)
255 ADD_SYM( "__wine_call_from_32_regs" );
262 for (i
= 0; i
< count
; i
++) add_undef_symbol( extras
[i
] );
263 sort_symbols( undef_symbols
, nb_undef_symbols
);
267 /* warn if a given dll is not used, but check forwards first */
268 static void warn_unused( const struct import
* imp
)
271 size_t len
= strlen(imp
->dll
);
272 const char *p
= strchr( imp
->dll
, '.' );
273 if (p
&& !strcasecmp( p
, ".dll" )) len
= p
- imp
->dll
;
275 for (i
= Base
; i
<= Limit
; i
++)
277 ORDDEF
*odp
= Ordinals
[i
];
278 if (!odp
|| odp
->type
!= TYPE_FORWARD
) continue;
279 if (!strncasecmp( odp
->link_name
, imp
->dll
, len
) &&
280 odp
->link_name
[len
] == '.')
281 return; /* found an import, do not warn */
283 /* switch current_line temporarily to the line of the import declaration */
284 curline
= current_line
;
285 current_line
= imp
->lineno
;
286 warning( "%s imported but no symbols used\n", imp
->dll
);
287 current_line
= curline
;
290 /* read in the list of undefined symbols */
291 void read_undef_symbols( const char *name
)
297 undef_size
= nb_undef_symbols
= 0;
299 sprintf( buffer
, "nm -u %s", name
);
300 if (!(f
= popen( buffer
, "r" )))
301 fatal_error( "Cannot execute '%s'\n", buffer
);
303 while (fgets( buffer
, sizeof(buffer
), f
))
305 char *p
= buffer
+ strlen(buffer
) - 1;
306 if (p
< buffer
) continue;
307 if (*p
== '\n') *p
-- = 0;
308 p
= buffer
; while (*p
== ' ') p
++;
309 add_undef_symbol( p
);
311 if ((err
= pclose( f
))) fatal_error( "nm -u %s error %d\n", name
, err
);
314 static void remove_ignored_symbols(void)
318 sort_symbols( ignore_symbols
, nb_ignore_symbols
);
319 for (i
= 0; i
< nb_undef_symbols
; i
++)
321 if (find_symbol( undef_symbols
[i
], ignore_symbols
, nb_ignore_symbols
))
323 free( undef_symbols
[i
] );
324 undef_symbols
[i
] = NULL
;
327 remove_symbol_holes();
330 /* resolve the imports for a Win32 module */
331 int resolve_imports( void )
335 if (nb_undef_symbols
== -1) return 0; /* no symbol file specified */
337 add_extra_undef_symbols();
338 remove_ignored_symbols();
340 for (i
= 0; i
< nb_imports
; i
++)
342 struct import
*imp
= dll_imports
[i
];
344 for (j
= 0; j
< nb_undef_symbols
; j
++)
346 const char *res
= find_symbol( undef_symbols
[j
], imp
->exports
, imp
->nb_exports
);
349 add_import_func( imp
, res
);
350 free( undef_symbols
[j
] );
351 undef_symbols
[j
] = NULL
;
354 /* remove all the holes in the undef symbols list */
355 if (!remove_symbol_holes()) warn_unused( imp
);
360 /* output the import table of a Win32 module */
361 static int output_immediate_imports( FILE *outfile
)
364 int nb_imm
= nb_imports
- nb_delayed
;
366 if (!nb_imm
) goto done
;
368 /* main import header */
370 fprintf( outfile
, "\nstatic struct {\n" );
371 fprintf( outfile
, " struct {\n" );
372 fprintf( outfile
, " void *OriginalFirstThunk;\n" );
373 fprintf( outfile
, " unsigned int TimeDateStamp;\n" );
374 fprintf( outfile
, " unsigned int ForwarderChain;\n" );
375 fprintf( outfile
, " const char *Name;\n" );
376 fprintf( outfile
, " void *FirstThunk;\n" );
377 fprintf( outfile
, " } imp[%d];\n", nb_imm
+1 );
378 fprintf( outfile
, " const char *data[%d];\n",
379 total_imports
- total_delayed
+ nb_imm
);
380 fprintf( outfile
, "} imports = {\n {\n" );
384 for (i
= j
= 0; i
< nb_imports
; i
++)
386 if (dll_imports
[i
]->delay
) continue;
387 fprintf( outfile
, " { 0, 0, 0, \"%s\", &imports.data[%d] },\n",
388 dll_imports
[i
]->dll
, j
);
389 j
+= dll_imports
[i
]->nb_imports
+ 1;
392 fprintf( outfile
, " { 0, 0, 0, 0, 0 },\n" );
393 fprintf( outfile
, " },\n {\n" );
395 /* list of imported functions */
397 for (i
= 0; i
< nb_imports
; i
++)
399 if (dll_imports
[i
]->delay
) continue;
400 fprintf( outfile
, " /* %s */\n", dll_imports
[i
]->dll
);
401 for (j
= 0; j
< dll_imports
[i
]->nb_imports
; j
++)
402 fprintf( outfile
, " \"\\0\\0%s\",\n", dll_imports
[i
]->imports
[j
] );
403 fprintf( outfile
, " 0,\n" );
405 fprintf( outfile
, " }\n};\n\n" );
407 /* thunks for imported functions */
409 fprintf( outfile
, "#ifndef __GNUC__\nstatic void __asm__dummy_import(void) {\n#endif\n\n" );
410 pos
= 20 * (nb_imm
+ 1); /* offset of imports.data from start of imports */
411 fprintf( outfile
, "asm(\".data\\n\\t.align %d\\n\"\n", get_alignment(8) );
412 for (i
= 0; i
< nb_imports
; i
++)
414 if (dll_imports
[i
]->delay
) continue;
415 for (j
= 0; j
< dll_imports
[i
]->nb_imports
; j
++, pos
+= 4)
417 fprintf( outfile
, " \"\\t" __ASM_FUNC("%s") "\\n\"\n",
418 dll_imports
[i
]->imports
[j
] );
419 fprintf( outfile
, " \"\\t.globl " PREFIX
"%s\\n\"\n",
420 dll_imports
[i
]->imports
[j
] );
425 fprintf( outfile
, " \"" PREFIX
"%s:\\n\\t", dll_imports
[i
]->imports
[j
] );
427 #if defined(__i386__)
428 if (strstr( dll_imports
[i
]->imports
[j
], "__wine_call_from_16" ))
429 fprintf( outfile
, ".byte 0x2e\\n\\tjmp *(imports+%d)\\n\\tnop\\n", pos
);
431 fprintf( outfile
, "jmp *(imports+%d)\\n\\tmovl %%esi,%%esi\\n", pos
);
432 #elif defined(__sparc__)
435 fprintf( outfile
, "sethi %%hi(imports+%d), %%g1\\n\\t", pos
);
436 fprintf( outfile
, "ld [%%g1+%%lo(imports+%d)], %%g1\\n\\t", pos
);
437 fprintf( outfile
, "jmp %%g1\\n\\tnop\\n" );
441 /* Hmpf. Stupid sparc assembler always interprets global variable
442 names as GOT offsets, so we have to do it the long way ... */
443 fprintf( outfile
, "save %%sp, -96, %%sp\\n" );
444 fprintf( outfile
, "0:\\tcall 1f\\n\\tnop\\n" );
445 fprintf( outfile
, "1:\\tsethi %%hi(imports+%d-0b), %%g1\\n\\t", pos
);
446 fprintf( outfile
, "or %%g1, %%lo(imports+%d-0b), %%g1\\n\\t", pos
);
447 fprintf( outfile
, "ld [%%g1+%%o7], %%g1\\n\\t" );
448 fprintf( outfile
, "jmp %%g1\\n\\trestore\\n" );
451 #elif defined(__PPC__)
452 fprintf(outfile
, "\taddi 1, 1, -0x4\\n\"\n");
453 fprintf(outfile
, "\t\"\\tstw 9, 0(1)\\n\"\n");
454 fprintf(outfile
, "\t\"\\taddi 1, 1, -0x4\\n\"\n");
455 fprintf(outfile
, "\t\"\\tstw 8, 0(1)\\n\"\n");
456 fprintf(outfile
, "\t\"\\taddi 1, 1, -0x4\\n\"\n");
457 fprintf(outfile
, "\t\"\\tstw 7, 0(1)\\n\"\n");
459 fprintf(outfile
, "\t\"\\tlis 9,imports+%d@ha\\n\"\n", pos
);
460 fprintf(outfile
, "\t\"\\tla 8,imports+%d@l(9)\\n\"\n", pos
);
461 fprintf(outfile
, "\t\"\\tlwz 7, 0(8)\\n\"\n");
462 fprintf(outfile
, "\t\"\\tmtctr 7\\n\"\n");
464 fprintf(outfile
, "\t\"\\tlwz 7, 0(1)\\n\"\n");
465 fprintf(outfile
, "\t\"\\taddi 1, 1, 0x4\\n\"\n");
466 fprintf(outfile
, "\t\"\\tlwz 8, 0(1)\\n\"\n");
467 fprintf(outfile
, "\t\"\\taddi 1, 1, 0x4\\n\"\n");
468 fprintf(outfile
, "\t\"\\tlwz 9, 0(1)\\n\"\n");
469 fprintf(outfile
, "\t\"\\taddi 1, 1, 0x4\\n\"\n");
470 fprintf(outfile
, "\t\"\\tbctr\\n");
472 #error You need to define import thunks for your architecture!
474 fprintf( outfile
, "\"\n" );
478 fprintf( outfile
, "\".previous\");\n#ifndef __GNUC__\n}\n#endif\n\n" );
484 /* output the delayed import table of a Win32 module */
485 static int output_delayed_imports( FILE *outfile
)
489 if (!nb_delayed
) goto done
;
491 for (i
= 0; i
< nb_imports
; i
++)
493 if (!dll_imports
[i
]->delay
) continue;
494 fprintf( outfile
, "static void *__wine_delay_imp_%d_hmod;\n", i
);
495 for (j
= 0; j
< dll_imports
[i
]->nb_imports
; j
++)
497 fprintf( outfile
, "void __wine_delay_imp_%d_%s();\n",
498 i
, dll_imports
[i
]->imports
[j
] );
501 fprintf( outfile
, "\n" );
502 fprintf( outfile
, "static struct {\n" );
503 fprintf( outfile
, " struct ImgDelayDescr {\n" );
504 fprintf( outfile
, " unsigned int grAttrs;\n" );
505 fprintf( outfile
, " const char *szName;\n" );
506 fprintf( outfile
, " void **phmod;\n" );
507 fprintf( outfile
, " void **pIAT;\n" );
508 fprintf( outfile
, " const char **pINT;\n" );
509 fprintf( outfile
, " void* pBoundIAT;\n" );
510 fprintf( outfile
, " void* pUnloadIAT;\n" );
511 fprintf( outfile
, " unsigned long dwTimeStamp;\n" );
512 fprintf( outfile
, " } imp[%d];\n", nb_delayed
);
513 fprintf( outfile
, " void *IAT[%d];\n", total_delayed
);
514 fprintf( outfile
, " const char *INT[%d];\n", total_delayed
);
515 fprintf( outfile
, "} delay_imports = {\n" );
516 fprintf( outfile
, " {\n" );
517 for (i
= j
= 0; i
< nb_imports
; i
++)
519 if (!dll_imports
[i
]->delay
) continue;
520 fprintf( outfile
, " { 0, \"%s\", &__wine_delay_imp_%d_hmod, &delay_imports.IAT[%d], &delay_imports.INT[%d], 0, 0, 0 },\n",
521 dll_imports
[i
]->dll
, i
, j
, j
);
522 j
+= dll_imports
[i
]->nb_imports
;
524 fprintf( outfile
, " },\n {\n" );
525 for (i
= 0; i
< nb_imports
; i
++)
527 if (!dll_imports
[i
]->delay
) continue;
528 fprintf( outfile
, " /* %s */\n", dll_imports
[i
]->dll
);
529 for (j
= 0; j
< dll_imports
[i
]->nb_imports
; j
++)
531 fprintf( outfile
, " &__wine_delay_imp_%d_%s,\n", i
, dll_imports
[i
]->imports
[j
] );
534 fprintf( outfile
, " },\n {\n" );
535 for (i
= 0; i
< nb_imports
; i
++)
537 if (!dll_imports
[i
]->delay
) continue;
538 fprintf( outfile
, " /* %s */\n", dll_imports
[i
]->dll
);
539 for (j
= 0; j
< dll_imports
[i
]->nb_imports
; j
++)
541 fprintf( outfile
, " \"\\0\\0%s\",\n", dll_imports
[i
]->imports
[j
] );
544 fprintf( outfile
, " }\n};\n\n" );
546 /* check if there's some stub defined. if so, exception struct
547 * is already defined, so don't emit it twice
549 for (i
= 0; i
< nb_entry_points
; i
++) if (EntryPoints
[i
]->type
== TYPE_STUB
) break;
551 if (i
== nb_entry_points
) {
552 fprintf( outfile
, "struct exc_record {\n" );
553 fprintf( outfile
, " unsigned int code, flags;\n" );
554 fprintf( outfile
, " void *rec, *addr;\n" );
555 fprintf( outfile
, " unsigned int params;\n" );
556 fprintf( outfile
, " const void *info[15];\n" );
557 fprintf( outfile
, "};\n\n" );
558 fprintf( outfile
, "extern void __stdcall RtlRaiseException( struct exc_record * );\n" );
561 fprintf( outfile
, "extern void * __stdcall LoadLibraryA(const char*);\n");
562 fprintf( outfile
, "extern void * __stdcall GetProcAddress(void *, const char*);\n");
563 fprintf( outfile
, "\n" );
565 fprintf( outfile
, "void *__stdcall __wine_delay_load( int idx_nr )\n" );
566 fprintf( outfile
, "{\n" );
567 fprintf( outfile
, " int idx = idx_nr >> 16, nr = idx_nr & 0xffff;\n" );
568 fprintf( outfile
, " struct ImgDelayDescr *imd = delay_imports.imp + idx;\n" );
569 fprintf( outfile
, " void **pIAT = imd->pIAT + nr;\n" );
570 fprintf( outfile
, " const char** pINT = imd->pINT + nr;\n" );
571 fprintf( outfile
, " void *fn;\n\n" );
573 fprintf( outfile
, " if (!*imd->phmod) *imd->phmod = LoadLibraryA(imd->szName);\n" );
574 fprintf( outfile
, " if (*imd->phmod && (fn = GetProcAddress(*imd->phmod, *pINT + 2)))\n");
575 fprintf( outfile
, " /* patch IAT with final value */\n" );
576 fprintf( outfile
, " return *pIAT = fn;\n" );
577 fprintf( outfile
, " else {\n");
578 fprintf( outfile
, " struct exc_record rec;\n" );
579 fprintf( outfile
, " rec.code = 0x80000100;\n" );
580 fprintf( outfile
, " rec.flags = 1;\n" );
581 fprintf( outfile
, " rec.rec = 0;\n" );
582 fprintf( outfile
, " rec.params = 2;\n" );
583 fprintf( outfile
, " rec.info[0] = imd->szName;\n" );
584 fprintf( outfile
, " rec.info[1] = *pINT + 2;\n" );
585 fprintf( outfile
, "#ifdef __GNUC__\n" );
586 fprintf( outfile
, " rec.addr = __builtin_return_address(1);\n" );
587 fprintf( outfile
, "#else\n" );
588 fprintf( outfile
, " rec.addr = 0;\n" );
589 fprintf( outfile
, "#endif\n" );
590 fprintf( outfile
, " for (;;) RtlRaiseException( &rec );\n" );
591 fprintf( outfile
, " return 0; /* shouldn't go here */\n" );
592 fprintf( outfile
, " }\n}\n\n" );
594 fprintf( outfile
, "#ifndef __GNUC__\n" );
595 fprintf( outfile
, "static void __asm__dummy_delay_import(void) {\n" );
596 fprintf( outfile
, "#endif\n" );
598 fprintf( outfile
, "asm(\".align %d\\n\"\n", get_alignment(8) );
599 fprintf( outfile
, " \"\\t" __ASM_FUNC("__wine_delay_load_asm") "\\n\"\n" );
600 fprintf( outfile
, " \"" PREFIX
"__wine_delay_load_asm:\\n\"\n" );
601 #if defined(__i386__)
602 fprintf( outfile
, " \"\\tpushl %%ecx\\n\\tpushl %%edx\\n\\tpushl %%eax\\n\"\n" );
603 fprintf( outfile
, " \"\\tcall __wine_delay_load\\n\"\n" );
604 fprintf( outfile
, " \"\\tpopl %%edx\\n\\tpopl %%ecx\\n\\tjmp *%%eax\\n\"\n" );
605 #elif defined(__sparc__)
606 fprintf( outfile
, " \"\\tsave %%sp, -96, %%sp\\n\"\n" );
607 fprintf( outfile
, " \"\\tcall __wine_delay_load\\n\"\n" );
608 fprintf( outfile
, " \"\\tmov %%g1, %%o0\\n\"\n" );
609 fprintf( outfile
, " \"\\tjmp %%o0\\n\\trestore\\n\"\n" );
610 #elif defined(__PPC__)
611 fprintf(outfile
, "#error: DELAYED IMPORTS NOT SUPPORTED ON PPC!!!\n");
613 #error You need to defined delayed import thunks for your architecture!
616 for (i
= idx
= 0; i
< nb_imports
; i
++)
618 if (!dll_imports
[i
]->delay
) continue;
619 for (j
= 0; j
< dll_imports
[i
]->nb_imports
; j
++)
622 sprintf( buffer
, "__wine_delay_imp_%d_%s", i
, dll_imports
[i
]->imports
[j
]);
623 fprintf( outfile
, " \"\\t" __ASM_FUNC("%s") "\\n\"\n", buffer
);
624 fprintf( outfile
, " \"" PREFIX
"%s:\\n\"\n", buffer
);
625 #if defined(__i386__)
626 fprintf( outfile
, " \"\\tmovl $%d, %%eax\\n\"\n", (idx
<< 16) | j
);
627 fprintf( outfile
, " \"\\tjmp __wine_delay_load_asm\\n\"\n" );
628 #elif defined(__sparc__)
629 fprintf( outfile
, " \"\\tset %d, %%g1\\n\"\n", (idx
<< 16) | j
);
630 fprintf( outfile
, " \"\\tb,a __wine_delay_load_asm\\n\"\n" );
631 #elif defined(__PPC__)
632 fprintf(outfile
, "#error: DELAYED IMPORTS NOT SUPPORTED ON PPC!!!\n");
634 #error You need to defined delayed import thunks for your architecture!
640 fprintf( outfile
, "\n \".data\\n\\t.align %d\\n\"\n", get_alignment(8) );
641 pos
= nb_delayed
* 32;
642 for (i
= 0; i
< nb_imports
; i
++)
644 if (!dll_imports
[i
]->delay
) continue;
645 for (j
= 0; j
< dll_imports
[i
]->nb_imports
; j
++, pos
+= 4)
647 fprintf( outfile
, " \"\\t" __ASM_FUNC("%s") "\\n\"\n",
648 dll_imports
[i
]->imports
[j
] );
649 fprintf( outfile
, " \"\\t.globl " PREFIX
"%s\\n\"\n",
650 dll_imports
[i
]->imports
[j
] );
651 fprintf( outfile
, " \"" PREFIX
"%s:\\n\\t", dll_imports
[i
]->imports
[j
] );
652 #if defined(__i386__)
653 if (strstr( dll_imports
[i
]->imports
[j
], "__wine_call_from_16" ))
654 fprintf( outfile
, ".byte 0x2e\\n\\tjmp *(delay_imports+%d)\\n\\tnop\\n", pos
);
656 fprintf( outfile
, "jmp *(delay_imports+%d)\\n\\tmovl %%esi,%%esi\\n", pos
);
657 #elif defined(__sparc__)
660 fprintf( outfile
, "sethi %%hi(delay_imports+%d), %%g1\\n\\t", pos
);
661 fprintf( outfile
, "ld [%%g1+%%lo(delay_imports+%d)], %%g1\\n\\t", pos
);
662 fprintf( outfile
, "jmp %%g1\\n\\tnop\\n" );
666 /* Hmpf. Stupid sparc assembler always interprets global variable
667 names as GOT offsets, so we have to do it the long way ... */
668 fprintf( outfile
, "save %%sp, -96, %%sp\\n" );
669 fprintf( outfile
, "0:\\tcall 1f\\n\\tnop\\n" );
670 fprintf( outfile
, "1:\\tsethi %%hi(delay_imports+%d-0b), %%g1\\n\\t", pos
);
671 fprintf( outfile
, "or %%g1, %%lo(delay_imports+%d-0b), %%g1\\n\\t", pos
);
672 fprintf( outfile
, "ld [%%g1+%%o7], %%g1\\n\\t" );
673 fprintf( outfile
, "jmp %%g1\\n\\trestore\\n" );
676 #elif defined(__PPC__)
677 fprintf(outfile
, "#error: DELAYED IMPORTS NOT SUPPORTED ON PPC!!!\n");
679 #error You need to define delayed import thunks for your architecture!
681 fprintf( outfile
, "\"\n" );
684 fprintf( outfile
, "\".previous\");\n" );
685 fprintf( outfile
, "#ifndef __GNUC__\n" );
686 fprintf( outfile
, "}\n" );
687 fprintf( outfile
, "#endif\n" );
688 fprintf( outfile
, "\n" );
694 /* output the import and delayed import tables of a Win32 module
695 * returns number of DLLs exported in 'immediate' mode
697 int output_imports( FILE *outfile
)
699 output_delayed_imports( outfile
);
700 return output_immediate_imports( outfile
);