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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
23 #include "wine/port.h"
31 #ifdef HAVE_SYS_STAT_H
32 # include <sys/stat.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 */
56 unsigned int count
, size
;
59 static struct name_table undef_symbols
; /* list of undefined symbols */
60 static struct name_table extra_ld_symbols
; /* list of extra symbols that ld should resolve */
61 static struct name_table delayed_imports
; /* list of delayed import dlls */
62 static struct name_table ext_link_imports
; /* list of external symbols to link to */
64 static struct import
**dll_imports
= NULL
;
65 static int nb_imports
= 0; /* number of imported dlls (delayed or not) */
66 static int nb_delayed
= 0; /* number of delayed dlls */
67 static int total_imports
= 0; /* total number of imported functions */
68 static int total_delayed
= 0; /* total number of imported functions in delayed DLLs */
71 static inline const char *ppc_reg( int reg
)
73 static const char * const ppc_regs
[32] = { "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7",
74 "r8", "r9", "r10","r11","r12","r13","r14","r15",
75 "r16","r17","r18","r19","r20","r21","r22","r23",
76 "r24","r25","r26","r27","r28","r29","r30","r31" };
77 if (target_platform
== PLATFORM_APPLE
) return ppc_regs
[reg
];
78 return ppc_regs
[reg
] + 1; /* skip the 'r' */
81 /* compare function names; helper for resolve_imports */
82 static int name_cmp( const void *name
, const void *entry
)
84 return strcmp( *(const char* const *)name
, *(const char* const *)entry
);
87 /* compare function names; helper for resolve_imports */
88 static int func_cmp( const void *func1
, const void *func2
)
90 const ORDDEF
*odp1
= *(const ORDDEF
* const *)func1
;
91 const ORDDEF
*odp2
= *(const ORDDEF
* const *)func2
;
92 return strcmp( odp1
->name
? odp1
->name
: odp1
->export_name
,
93 odp2
->name
? odp2
->name
: odp2
->export_name
);
96 /* add a name to a name table */
97 static inline void add_name( struct name_table
*table
, const char *name
)
99 if (table
->count
== table
->size
)
101 table
->size
+= (table
->size
/ 2);
102 if (table
->size
< 32) table
->size
= 32;
103 table
->names
= xrealloc( table
->names
, table
->size
* sizeof(*table
->names
) );
105 table
->names
[table
->count
++] = xstrdup( name
);
108 /* remove a name from a name table */
109 static inline void remove_name( struct name_table
*table
, unsigned int idx
)
111 assert( idx
< table
->count
);
112 free( table
->names
[idx
] );
113 memmove( table
->names
+ idx
, table
->names
+ idx
+ 1,
114 (table
->count
- idx
- 1) * sizeof(*table
->names
) );
118 /* make a name table empty */
119 static inline void empty_name_table( struct name_table
*table
)
123 for (i
= 0; i
< table
->count
; i
++) free( table
->names
[i
] );
127 /* locate a name in a (sorted) list */
128 static inline const char *find_name( const char *name
, const struct name_table
*table
)
132 if (table
->count
) res
= bsearch( &name
, table
->names
, table
->count
, sizeof(*table
->names
), name_cmp
);
133 return res
? *res
: NULL
;
136 /* sort a name table */
137 static inline void sort_names( struct name_table
*table
)
139 if (table
->count
) qsort( table
->names
, table
->count
, sizeof(*table
->names
), name_cmp
);
142 /* locate an export in a (sorted) export list */
143 static inline ORDDEF
*find_export( const char *name
, ORDDEF
**table
, int size
)
145 ORDDEF func
, *odp
, **res
= NULL
;
147 func
.name
= xstrdup(name
);
150 if (table
) res
= bsearch( &odp
, table
, size
, sizeof(*table
), func_cmp
);
152 return res
? *res
: NULL
;
155 /* free an import structure */
156 static void free_imports( struct import
*imp
)
158 free( imp
->exports
);
159 free( imp
->imports
);
160 free_dll_spec( imp
->spec
);
161 free( imp
->full_name
);
165 /* check whether a given dll is imported in delayed mode */
166 static int is_delayed_import( const char *name
)
170 for (i
= 0; i
< delayed_imports
.count
; i
++)
172 if (!strcmp( delayed_imports
.names
[i
], name
)) return 1;
177 /* check whether a given dll has already been imported */
178 static struct import
*is_already_imported( const char *name
)
182 for (i
= 0; i
< nb_imports
; i
++)
184 if (!strcmp( dll_imports
[i
]->spec
->file_name
, name
)) return dll_imports
[i
];
189 /* open the .so library for a given dll in a specified path */
190 static char *try_library_path( const char *path
, const char *name
)
195 buffer
= strmake( "%s/lib%s.def", path
, name
);
197 /* check if the file exists */
198 if ((fd
= open( buffer
, O_RDONLY
)) != -1)
207 /* find the .def import library for a given dll */
208 static char *find_library( const char *name
)
213 for (i
= 0; i
< nb_lib_paths
; i
++)
215 if ((fullname
= try_library_path( lib_path
[i
], name
))) return fullname
;
217 fatal_error( "could not open .def file for %s\n", name
);
221 /* read in the list of exported symbols of an import library */
222 static int read_import_lib( struct import
*imp
)
227 struct import
*prev_imp
;
228 DLLSPEC
*spec
= imp
->spec
;
230 f
= open_input_file( NULL
, imp
->full_name
);
231 fstat( fileno(f
), &stat
);
232 imp
->dev
= stat
.st_dev
;
233 imp
->ino
= stat
.st_ino
;
234 ret
= parse_def_file( f
, spec
);
235 close_input_file( f
);
238 /* check if we already imported that library from a different file */
239 if ((prev_imp
= is_already_imported( spec
->file_name
)))
241 if (prev_imp
->dev
!= imp
->dev
|| prev_imp
->ino
!= imp
->ino
)
242 fatal_error( "%s and %s have the same export name '%s'\n",
243 prev_imp
->full_name
, imp
->full_name
, spec
->file_name
);
244 return 0; /* the same file was already loaded, ignore this one */
247 if (is_delayed_import( spec
->file_name
))
253 if (spec
->nb_entry_points
)
255 imp
->exports
= xmalloc( spec
->nb_entry_points
* sizeof(*imp
->exports
) );
256 for (i
= 0; i
< spec
->nb_entry_points
; i
++)
257 imp
->exports
[imp
->nb_exports
++] = &spec
->entry_points
[i
];
258 qsort( imp
->exports
, imp
->nb_exports
, sizeof(*imp
->exports
), func_cmp
);
263 /* build the dll exported name from the import lib name or path */
264 static char *get_dll_name( const char *name
, const char *filename
)
270 const char *basename
= strrchr( filename
, '/' );
271 if (!basename
) basename
= filename
;
273 if (!strncmp( basename
, "lib", 3 )) basename
+= 3;
274 ret
= xmalloc( strlen(basename
) + 5 );
275 strcpy( ret
, basename
);
276 if (strendswith( ret
, ".def" )) ret
[strlen(ret
)-4] = 0;
280 ret
= xmalloc( strlen(name
) + 5 );
283 if (!strchr( ret
, '.' )) strcat( ret
, ".dll" );
287 /* add a dll to the list of imports */
288 void add_import_dll( const char *name
, const char *filename
)
290 struct import
*imp
= xmalloc( sizeof(*imp
) );
292 imp
->spec
= alloc_dll_spec();
293 imp
->spec
->file_name
= get_dll_name( name
, filename
);
300 if (filename
) imp
->full_name
= xstrdup( filename
);
301 else imp
->full_name
= find_library( name
);
303 if (read_import_lib( imp
))
305 dll_imports
= xrealloc( dll_imports
, (nb_imports
+1) * sizeof(*dll_imports
) );
306 dll_imports
[nb_imports
++] = imp
;
311 if (nb_errors
) exit(1);
315 /* add a library to the list of delayed imports */
316 void add_delayed_import( const char *name
)
319 char *fullname
= get_dll_name( name
, NULL
);
321 add_name( &delayed_imports
, fullname
);
322 if ((imp
= is_already_imported( fullname
)) && !imp
->delay
)
330 /* remove an imported dll, based on its index in the dll_imports array */
331 static void remove_import_dll( int index
)
333 struct import
*imp
= dll_imports
[index
];
335 memmove( &dll_imports
[index
], &dll_imports
[index
+1], sizeof(imp
) * (nb_imports
- index
- 1) );
337 if (imp
->delay
) nb_delayed
--;
341 /* add a symbol to the list of extra symbols that ld must resolve */
342 void add_extra_ld_symbol( const char *name
)
344 add_name( &extra_ld_symbols
, name
);
347 /* add a function to the list of imports from a given dll */
348 static void add_import_func( struct import
*imp
, ORDDEF
*func
)
350 imp
->imports
= xrealloc( imp
->imports
, (imp
->nb_imports
+1) * sizeof(*imp
->imports
) );
351 imp
->imports
[imp
->nb_imports
++] = func
;
353 if (imp
->delay
) total_delayed
++;
356 /* get the default entry point for a given spec file */
357 static const char *get_default_entry_point( const DLLSPEC
*spec
)
359 if (spec
->characteristics
& IMAGE_FILE_DLL
) return "__wine_spec_dll_entry";
360 if (spec
->subsystem
== IMAGE_SUBSYSTEM_NATIVE
) return "__wine_spec_drv_entry";
361 if (spec
->type
== SPEC_WIN16
) return "__wine_spec_exe16_entry";
362 return "__wine_spec_exe_entry";
365 /* check if the spec file exports any stubs */
366 static int has_stubs( const DLLSPEC
*spec
)
369 for (i
= 0; i
< spec
->nb_entry_points
; i
++)
371 ORDDEF
*odp
= &spec
->entry_points
[i
];
372 if (odp
->type
== TYPE_STUB
) return 1;
377 /* add the extra undefined symbols that will be contained in the generated spec file itself */
378 static void add_extra_undef_symbols( DLLSPEC
*spec
)
380 if (!spec
->init_func
) spec
->init_func
= xstrdup( get_default_entry_point(spec
) );
381 add_extra_ld_symbol( spec
->init_func
);
382 if (has_stubs( spec
)) add_extra_ld_symbol( "__wine_spec_unimplemented_stub" );
383 if (nb_delayed
) add_extra_ld_symbol( "__wine_spec_delay_load" );
386 /* check if a given imported dll is not needed, taking forwards into account */
387 static int check_unused( const struct import
* imp
, const DLLSPEC
*spec
)
390 const char *file_name
= imp
->spec
->file_name
;
391 size_t len
= strlen( file_name
);
392 const char *p
= strchr( file_name
, '.' );
393 if (p
&& !strcasecmp( p
, ".dll" )) len
= p
- file_name
;
395 for (i
= spec
->base
; i
<= spec
->limit
; i
++)
397 ORDDEF
*odp
= spec
->ordinals
[i
];
398 if (!odp
|| !(odp
->flags
& FLAG_FORWARD
)) continue;
399 if (!strncasecmp( odp
->link_name
, file_name
, len
) &&
400 odp
->link_name
[len
] == '.')
401 return 0; /* found a forward, it is used */
406 /* check if a given forward does exist in one of the imported dlls */
407 static void check_undefined_forwards( DLLSPEC
*spec
)
409 char *link_name
, *api_name
, *dll_name
, *p
;
412 for (i
= 0; i
< spec
->nb_entry_points
; i
++)
414 ORDDEF
*odp
= &spec
->entry_points
[i
];
416 if (!(odp
->flags
& FLAG_FORWARD
)) continue;
418 link_name
= xstrdup( odp
->link_name
);
419 p
= strrchr( link_name
, '.' );
422 dll_name
= get_dll_name( link_name
, NULL
);
424 for (j
= 0; j
< nb_imports
; j
++)
426 struct import
*imp
= dll_imports
[j
];
428 if (strcasecmp( imp
->spec
->file_name
, dll_name
)) continue;
429 if (!find_export( api_name
, imp
->exports
, imp
->nb_exports
))
430 warning( "%s:%d: forward '%s' not found in %s\n",
431 spec
->src_name
, odp
->lineno
, odp
->link_name
, imp
->spec
->file_name
);
435 warning( "%s:%d: forward '%s' not found in the imported dll list\n",
436 spec
->src_name
, odp
->lineno
, odp
->link_name
);
442 /* flag the dll exports that link to an undefined symbol */
443 static void check_undefined_exports( DLLSPEC
*spec
)
447 for (i
= 0; i
< spec
->nb_entry_points
; i
++)
449 ORDDEF
*odp
= &spec
->entry_points
[i
];
450 if (odp
->type
== TYPE_STUB
|| odp
->type
== TYPE_ABS
|| odp
->type
== TYPE_VARIABLE
) continue;
451 if (odp
->flags
& FLAG_FORWARD
) continue;
452 if (find_name( odp
->link_name
, &undef_symbols
))
461 if (link_ext_symbols
)
463 odp
->flags
|= FLAG_EXT_LINK
;
464 add_name( &ext_link_imports
, odp
->link_name
);
466 else error( "%s:%d: function '%s' not defined\n",
467 spec
->src_name
, odp
->lineno
, odp
->link_name
);
470 error( "%s:%d: external symbol '%s' is not a function\n",
471 spec
->src_name
, odp
->lineno
, odp
->link_name
);
478 /* create a .o file that references all the undefined symbols we want to resolve */
479 static char *create_undef_symbols_file( DLLSPEC
*spec
)
481 char *as_file
, *obj_file
;
486 as_file
= get_temp_file_name( output_file_name
, ".s" );
487 if (!(f
= fopen( as_file
, "w" ))) fatal_error( "Cannot create %s\n", as_file
);
488 fprintf( f
, "\t.data\n" );
490 for (i
= 0; i
< spec
->nb_entry_points
; i
++)
492 ORDDEF
*odp
= &spec
->entry_points
[i
];
493 if (odp
->type
== TYPE_STUB
|| odp
->type
== TYPE_ABS
|| odp
->type
== TYPE_VARIABLE
) continue;
494 if (odp
->flags
& FLAG_FORWARD
) continue;
495 fprintf( f
, "\t%s %s\n", get_asm_ptr_keyword(), asm_name(odp
->link_name
) );
497 for (j
= 0; j
< extra_ld_symbols
.count
; j
++)
498 fprintf( f
, "\t%s %s\n", get_asm_ptr_keyword(), asm_name(extra_ld_symbols
.names
[j
]) );
501 obj_file
= get_temp_file_name( output_file_name
, ".o" );
502 assemble_file( as_file
, obj_file
);
506 /* combine a list of object files with ld into a single object file */
507 /* returns the name of the combined file */
508 static const char *ldcombine_files( DLLSPEC
*spec
, char **argv
)
510 char *ld_tmp_file
, *undef_file
;
511 struct strarray
*args
= get_ld_command();
513 undef_file
= create_undef_symbols_file( spec
);
514 ld_tmp_file
= get_temp_file_name( output_file_name
, ".o" );
516 strarray_add( args
, "-r", "-o", ld_tmp_file
, undef_file
, NULL
);
517 strarray_addv( args
, argv
);
519 strarray_free( args
);
523 /* read in the list of undefined symbols */
524 void read_undef_symbols( DLLSPEC
*spec
, char **argv
)
528 const char *prog
= get_nm_command();
529 char *cmd
, buffer
[1024], name_prefix
[16];
533 if (!argv
[0]) return;
535 add_extra_undef_symbols( spec
);
537 strcpy( name_prefix
, asm_name("") );
538 prefix_len
= strlen( name_prefix
);
540 name
= ldcombine_files( spec
, argv
);
542 cmd
= strmake( "%s -u %s", prog
, name
);
543 if (!(f
= popen( cmd
, "r" )))
544 fatal_error( "Cannot execute '%s'\n", cmd
);
546 while (fgets( buffer
, sizeof(buffer
), f
))
548 char *p
= buffer
+ strlen(buffer
) - 1;
549 if (p
< buffer
) continue;
550 if (*p
== '\n') *p
-- = 0;
552 while (*p
== ' ') p
++;
553 if (p
[0] == 'U' && p
[1] == ' ' && p
[2]) p
+= 2;
554 if (prefix_len
&& !strncmp( p
, name_prefix
, prefix_len
)) p
+= prefix_len
;
555 add_name( &undef_symbols
, p
);
557 if ((err
= pclose( f
))) warning( "%s failed with status %d\n", cmd
, err
);
561 /* resolve the imports for a Win32 module */
562 void resolve_imports( DLLSPEC
*spec
)
565 unsigned int j
, removed
;
568 check_undefined_forwards( spec
);
570 for (i
= 0; i
< nb_imports
; i
++)
572 struct import
*imp
= dll_imports
[i
];
574 for (j
= removed
= 0; j
< undef_symbols
.count
; j
++)
576 odp
= find_export( undef_symbols
.names
[j
], imp
->exports
, imp
->nb_exports
);
579 if (odp
->flags
& FLAG_PRIVATE
) continue;
580 if (odp
->type
!= TYPE_STDCALL
&& odp
->type
!= TYPE_CDECL
)
581 warning( "winebuild: Data export '%s' cannot be imported from %s\n",
582 odp
->link_name
, imp
->spec
->file_name
);
585 add_import_func( imp
, odp
);
586 remove_name( &undef_symbols
, j
-- );
593 /* the dll is not used, get rid of it */
594 if (check_unused( imp
, spec
))
595 warning( "winebuild: %s imported but no symbols used\n", imp
->spec
->file_name
);
596 remove_import_dll( i
);
601 sort_names( &undef_symbols
);
602 check_undefined_exports( spec
);
605 /* check if symbol is still undefined */
606 int is_undefined( const char *name
)
608 return find_name( name
, &undef_symbols
) != NULL
;
611 /* output the get_pc thunk if needed */
612 void output_get_pc_thunk(void)
614 if (target_cpu
!= CPU_x86
) return;
616 output( "\n\t.text\n" );
617 output( "\t.align %d\n", get_alignment(4) );
618 output( "\t%s\n", func_declaration("__wine_spec_get_pc_thunk_eax") );
619 output( "%s:\n", asm_name("__wine_spec_get_pc_thunk_eax") );
620 output_cfi( ".cfi_startproc" );
621 output( "\tmovl (%%esp),%%eax\n" );
623 output_cfi( ".cfi_endproc" );
624 output_function_size( "__wine_spec_get_pc_thunk_eax" );
627 /* output a single import thunk */
628 static void output_import_thunk( const char *name
, const char *table
, int pos
)
630 output( "\n\t.align %d\n", get_alignment(4) );
631 output( "\t%s\n", func_declaration(name
) );
632 output( "%s\n", asm_globl(name
) );
633 output_cfi( ".cfi_startproc" );
640 output( "\tjmp *(%s+%d)\n", table
, pos
);
644 output( "\tcall %s\n", asm_name("__wine_spec_get_pc_thunk_eax") );
645 output( "1:\tjmp *%s+%d-1b(%%eax)\n", table
, pos
);
649 output( "\tjmpq *%s+%d(%%rip)\n", table
, pos
);
654 output( "\tsethi %%hi(%s+%d), %%g1\n", table
, pos
);
655 output( "\tld [%%g1+%%lo(%s+%d)], %%g1\n", table
, pos
);
656 output( "\tjmp %%g1\n" );
661 /* Hmpf. Stupid sparc assembler always interprets global variable
662 names as GOT offsets, so we have to do it the long way ... */
663 output( "\tsave %%sp, -96, %%sp\n" );
664 output( "0:\tcall 1f\n" );
666 output( "1:\tsethi %%hi(%s+%d-0b), %%g1\n", table
, pos
);
667 output( "\tor %%g1, %%lo(%s+%d-0b), %%g1\n", table
, pos
);
668 output( "\tld [%%g1+%%o7], %%g1\n" );
669 output( "\tjmp %%g1\n" );
670 output( "\trestore\n" );
674 output( "\tlda $0,%s\n", table
);
675 output( "\tlda $0,%d($0)\n", pos
);
676 output( "\tjmp $31,($0)\n" );
679 output( "\tldr IP,[PC,#0]\n");
680 output( "\tmov PC,PC\n");
681 output( "\t%s %s\n", get_asm_ptr_keyword(), table
);
682 output( "\tldr PC,[IP,#%d]\n", pos
);
685 output( "\tmr %s, %s\n", ppc_reg(0), ppc_reg(31) );
686 if (target_platform
== PLATFORM_APPLE
)
688 output( "\tlis %s, ha16(%s+%d+32768)\n", ppc_reg(31), table
, pos
);
689 output( "\tla %s, lo16(%s+%d)(%s)\n", ppc_reg(31), table
, pos
, ppc_reg(31) );
693 output( "\tlis %s, (%s+%d+32768)@h\n", ppc_reg(31), table
, pos
);
694 output( "\tla %s, (%s+%d)@l(%s)\n", ppc_reg(31), table
, pos
, ppc_reg(31) );
696 output( "\tlwz %s, 0(%s)\n", ppc_reg(31), ppc_reg(31) );
697 output( "\tmtctr %s\n", ppc_reg(31) );
698 output( "\tmr %s, %s\n", ppc_reg(31), ppc_reg(0) );
699 output( "\tbctr\n" );
702 output_cfi( ".cfi_endproc" );
703 output_function_size( name
);
706 /* check if we need an import directory */
707 int has_imports(void)
709 return (nb_imports
- nb_delayed
) > 0;
712 /* output the import table of a Win32 module */
713 static void output_immediate_imports(void)
716 const char *dll_name
;
718 if (nb_imports
== nb_delayed
) return; /* no immediate imports */
720 /* main import header */
722 output( "\n/* import table */\n" );
723 output( "\n\t.data\n" );
724 output( "\t.align %d\n", get_alignment(4) );
725 output( ".L__wine_spec_imports:\n" );
729 for (i
= j
= 0; i
< nb_imports
; i
++)
731 if (dll_imports
[i
]->delay
) continue;
732 dll_name
= make_c_identifier( dll_imports
[i
]->spec
->file_name
);
733 output( "\t.long .L__wine_spec_import_data_names+%d-.L__wine_spec_rva_base\n", /* OriginalFirstThunk */
734 j
* get_ptr_size() );
735 output( "\t.long 0\n" ); /* TimeDateStamp */
736 output( "\t.long 0\n" ); /* ForwarderChain */
737 output( "\t.long .L__wine_spec_import_name_%s-.L__wine_spec_rva_base\n", /* Name */
739 output( "\t.long .L__wine_spec_import_data_ptrs+%d-.L__wine_spec_rva_base\n", /* FirstThunk */
740 j
* get_ptr_size() );
741 j
+= dll_imports
[i
]->nb_imports
+ 1;
743 output( "\t.long 0\n" ); /* OriginalFirstThunk */
744 output( "\t.long 0\n" ); /* TimeDateStamp */
745 output( "\t.long 0\n" ); /* ForwarderChain */
746 output( "\t.long 0\n" ); /* Name */
747 output( "\t.long 0\n" ); /* FirstThunk */
749 output( "\n\t.align %d\n", get_alignment(get_ptr_size()) );
750 output( ".L__wine_spec_import_data_names:\n" );
751 for (i
= 0; i
< nb_imports
; i
++)
753 if (dll_imports
[i
]->delay
) continue;
754 dll_name
= make_c_identifier( dll_imports
[i
]->spec
->file_name
);
755 for (j
= 0; j
< dll_imports
[i
]->nb_imports
; j
++)
757 ORDDEF
*odp
= dll_imports
[i
]->imports
[j
];
758 if (!(odp
->flags
& FLAG_NONAME
))
759 output( "\t%s .L__wine_spec_import_data_%s_%s-.L__wine_spec_rva_base\n",
760 get_asm_ptr_keyword(), dll_name
, odp
->name
);
763 if (get_ptr_size() == 8)
764 output( "\t.quad 0x800000000000%04x\n", odp
->ordinal
);
766 output( "\t.long 0x8000%04x\n", odp
->ordinal
);
769 output( "\t%s 0\n", get_asm_ptr_keyword() );
771 output( ".L__wine_spec_import_data_ptrs:\n" );
772 for (i
= 0; i
< nb_imports
; i
++)
774 if (dll_imports
[i
]->delay
) continue;
775 for (j
= 0; j
< dll_imports
[i
]->nb_imports
; j
++) output( "\t%s 0\n", get_asm_ptr_keyword() );
776 output( "\t%s 0\n", get_asm_ptr_keyword() );
778 output( ".L__wine_spec_imports_end:\n" );
780 for (i
= 0; i
< nb_imports
; i
++)
782 if (dll_imports
[i
]->delay
) continue;
783 dll_name
= make_c_identifier( dll_imports
[i
]->spec
->file_name
);
784 for (j
= 0; j
< dll_imports
[i
]->nb_imports
; j
++)
786 ORDDEF
*odp
= dll_imports
[i
]->imports
[j
];
787 if (!(odp
->flags
& FLAG_NONAME
))
789 output( "\t.align %d\n", get_alignment(2) );
790 output( ".L__wine_spec_import_data_%s_%s:\n", dll_name
, odp
->name
);
791 output( "\t%s %d\n", get_asm_short_keyword(), odp
->ordinal
);
792 output( "\t%s \"%s\"\n", get_asm_string_keyword(), odp
->name
);
797 for (i
= 0; i
< nb_imports
; i
++)
799 if (dll_imports
[i
]->delay
) continue;
800 dll_name
= make_c_identifier( dll_imports
[i
]->spec
->file_name
);
801 output( ".L__wine_spec_import_name_%s:\n\t%s \"%s\"\n",
802 dll_name
, get_asm_string_keyword(), dll_imports
[i
]->spec
->file_name
);
806 /* output the import thunks of a Win32 module */
807 static void output_immediate_import_thunks(void)
810 int nb_imm
= nb_imports
- nb_delayed
;
811 static const char import_thunks
[] = "__wine_spec_import_thunks";
815 output( "\n/* immediate import thunks */\n\n" );
816 output( "\t.text\n" );
817 output( "\t.align %d\n", get_alignment(8) );
818 output( "%s:\n", asm_name(import_thunks
));
820 for (i
= pos
= 0; i
< nb_imports
; i
++)
822 if (dll_imports
[i
]->delay
) continue;
823 for (j
= 0; j
< dll_imports
[i
]->nb_imports
; j
++, pos
+= get_ptr_size())
825 ORDDEF
*odp
= dll_imports
[i
]->imports
[j
];
826 output_import_thunk( odp
->name
? odp
->name
: odp
->export_name
,
827 ".L__wine_spec_import_data_ptrs", pos
);
829 pos
+= get_ptr_size();
831 output_function_size( import_thunks
);
834 /* output the delayed import table of a Win32 module */
835 static void output_delayed_imports( const DLLSPEC
*spec
)
839 if (!nb_delayed
) return;
841 output( "\n/* delayed imports */\n\n" );
842 output( "\t.data\n" );
843 output( "\t.align %d\n", get_alignment(get_ptr_size()) );
844 output( "%s\n", asm_globl("__wine_spec_delay_imports") );
848 for (i
= j
= mod
= 0; i
< nb_imports
; i
++)
850 if (!dll_imports
[i
]->delay
) continue;
851 output( "\t%s 0\n", get_asm_ptr_keyword() ); /* grAttrs */
852 output( "\t%s .L__wine_delay_name_%d\n", /* szName */
853 get_asm_ptr_keyword(), i
);
854 output( "\t%s .L__wine_delay_modules+%d\n", /* phmod */
855 get_asm_ptr_keyword(), mod
* get_ptr_size() );
856 output( "\t%s .L__wine_delay_IAT+%d\n", /* pIAT */
857 get_asm_ptr_keyword(), j
* get_ptr_size() );
858 output( "\t%s .L__wine_delay_INT+%d\n", /* pINT */
859 get_asm_ptr_keyword(), j
* get_ptr_size() );
860 output( "\t%s 0\n", get_asm_ptr_keyword() ); /* pBoundIAT */
861 output( "\t%s 0\n", get_asm_ptr_keyword() ); /* pUnloadIAT */
862 output( "\t%s 0\n", get_asm_ptr_keyword() ); /* dwTimeStamp */
863 j
+= dll_imports
[i
]->nb_imports
;
866 output( "\t%s 0\n", get_asm_ptr_keyword() ); /* grAttrs */
867 output( "\t%s 0\n", get_asm_ptr_keyword() ); /* szName */
868 output( "\t%s 0\n", get_asm_ptr_keyword() ); /* phmod */
869 output( "\t%s 0\n", get_asm_ptr_keyword() ); /* pIAT */
870 output( "\t%s 0\n", get_asm_ptr_keyword() ); /* pINT */
871 output( "\t%s 0\n", get_asm_ptr_keyword() ); /* pBoundIAT */
872 output( "\t%s 0\n", get_asm_ptr_keyword() ); /* pUnloadIAT */
873 output( "\t%s 0\n", get_asm_ptr_keyword() ); /* dwTimeStamp */
875 output( "\n.L__wine_delay_IAT:\n" );
876 for (i
= 0; i
< nb_imports
; i
++)
878 if (!dll_imports
[i
]->delay
) continue;
879 for (j
= 0; j
< dll_imports
[i
]->nb_imports
; j
++)
881 ORDDEF
*odp
= dll_imports
[i
]->imports
[j
];
882 const char *name
= odp
->name
? odp
->name
: odp
->export_name
;
883 output( "\t%s .L__wine_delay_imp_%d_%s\n",
884 get_asm_ptr_keyword(), i
, name
);
888 output( "\n.L__wine_delay_INT:\n" );
889 for (i
= 0; i
< nb_imports
; i
++)
891 if (!dll_imports
[i
]->delay
) continue;
892 for (j
= 0; j
< dll_imports
[i
]->nb_imports
; j
++)
894 ORDDEF
*odp
= dll_imports
[i
]->imports
[j
];
896 output( "\t%s %d\n", get_asm_ptr_keyword(), odp
->ordinal
);
898 output( "\t%s .L__wine_delay_data_%d_%s\n",
899 get_asm_ptr_keyword(), i
, odp
->name
);
903 output( "\n.L__wine_delay_modules:\n" );
904 for (i
= 0; i
< nb_imports
; i
++)
906 if (dll_imports
[i
]->delay
) output( "\t%s 0\n", get_asm_ptr_keyword() );
909 for (i
= 0; i
< nb_imports
; i
++)
911 if (!dll_imports
[i
]->delay
) continue;
912 output( ".L__wine_delay_name_%d:\n", i
);
913 output( "\t%s \"%s\"\n",
914 get_asm_string_keyword(), dll_imports
[i
]->spec
->file_name
);
917 for (i
= 0; i
< nb_imports
; i
++)
919 if (!dll_imports
[i
]->delay
) continue;
920 for (j
= 0; j
< dll_imports
[i
]->nb_imports
; j
++)
922 ORDDEF
*odp
= dll_imports
[i
]->imports
[j
];
923 if (!odp
->name
) continue;
924 output( ".L__wine_delay_data_%d_%s:\n", i
, odp
->name
);
925 output( "\t%s \"%s\"\n", get_asm_string_keyword(), odp
->name
);
928 output_function_size( "__wine_spec_delay_imports" );
931 /* output the delayed import thunks of a Win32 module */
932 static void output_delayed_import_thunks( const DLLSPEC
*spec
)
934 int i
, idx
, j
, pos
, extra_stack_storage
= 0;
935 static const char delayed_import_loaders
[] = "__wine_spec_delayed_import_loaders";
936 static const char delayed_import_thunks
[] = "__wine_spec_delayed_import_thunks";
938 if (!nb_delayed
) return;
940 output( "\n/* delayed import thunks */\n\n" );
941 output( "\t.text\n" );
942 output( "\t.align %d\n", get_alignment(8) );
943 output( "%s:\n", asm_name(delayed_import_loaders
));
944 output( "\t%s\n", func_declaration("__wine_delay_load_asm") );
945 output( "%s:\n", asm_name("__wine_delay_load_asm") );
946 output_cfi( ".cfi_startproc" );
950 output( "\tpushl %%ecx\n" );
951 output_cfi( ".cfi_adjust_cfa_offset 4" );
952 output( "\tpushl %%edx\n" );
953 output_cfi( ".cfi_adjust_cfa_offset 4" );
954 output( "\tpushl %%eax\n" );
955 output_cfi( ".cfi_adjust_cfa_offset 4" );
956 output( "\tcall %s\n", asm_name("__wine_spec_delay_load") );
957 output_cfi( ".cfi_adjust_cfa_offset -4" );
958 output( "\tpopl %%edx\n" );
959 output_cfi( ".cfi_adjust_cfa_offset -4" );
960 output( "\tpopl %%ecx\n" );
961 output_cfi( ".cfi_adjust_cfa_offset -4" );
962 output( "\tjmp *%%eax\n" );
965 output( "\tsubq $88,%%rsp\n" );
966 output_cfi( ".cfi_adjust_cfa_offset 88" );
967 output( "\tmovq %%rdx,80(%%rsp)\n" );
968 output( "\tmovq %%rcx,72(%%rsp)\n" );
969 output( "\tmovq %%r8,64(%%rsp)\n" );
970 output( "\tmovq %%r9,56(%%rsp)\n" );
971 output( "\tmovq %%r10,48(%%rsp)\n" );
972 output( "\tmovq %%r11,40(%%rsp)\n" );
973 output( "\tmovq %%rax,%%rcx\n" );
974 output( "\tcall %s\n", asm_name("__wine_spec_delay_load") );
975 output( "\tmovq 40(%%rsp),%%r11\n" );
976 output( "\tmovq 48(%%rsp),%%r10\n" );
977 output( "\tmovq 56(%%rsp),%%r9\n" );
978 output( "\tmovq 64(%%rsp),%%r8\n" );
979 output( "\tmovq 72(%%rsp),%%rcx\n" );
980 output( "\tmovq 80(%%rsp),%%rdx\n" );
981 output( "\taddq $88,%%rsp\n" );
982 output_cfi( ".cfi_adjust_cfa_offset -88" );
983 output( "\tjmp *%%rax\n" );
986 output( "\tsave %%sp, -96, %%sp\n" );
987 output( "\tcall %s\n", asm_name("__wine_spec_delay_load") );
988 output( "\tmov %%g1, %%o0\n" );
989 output( "\tjmp %%o0\n" );
990 output( "\trestore\n" );
993 output( "\tjsr $26,%s\n", asm_name("__wine_spec_delay_load") );
994 output( "\tjmp $31,($0)\n" );
997 output( "\tstmfd SP!, {r4-r10,FP,LR}\n" );
998 output( "\tmov LR,PC\n");
999 output( "\tadd LR,LR,#8\n");
1000 output( "\tldr PC,[PC,#-4]\n");
1001 output( "\t%s %s\n", get_asm_ptr_keyword(), asm_name("__wine_spec_delay_load") );
1002 output( "\tmov IP,r0\n");
1003 output( "\tldmfd SP!, {r4-r10,FP,LR}\n" );
1004 output( "\tldmfd SP!, {r0-r3}\n" );
1005 output( "\tmov PC,IP\n");
1008 if (target_platform
== PLATFORM_APPLE
) extra_stack_storage
= 56;
1010 /* Save all callee saved registers into a stackframe. */
1011 output( "\tstwu %s, -%d(%s)\n",ppc_reg(1), 48+extra_stack_storage
, ppc_reg(1));
1012 output( "\tstw %s, %d(%s)\n", ppc_reg(3), 4+extra_stack_storage
, ppc_reg(1));
1013 output( "\tstw %s, %d(%s)\n", ppc_reg(4), 8+extra_stack_storage
, ppc_reg(1));
1014 output( "\tstw %s, %d(%s)\n", ppc_reg(5), 12+extra_stack_storage
, ppc_reg(1));
1015 output( "\tstw %s, %d(%s)\n", ppc_reg(6), 16+extra_stack_storage
, ppc_reg(1));
1016 output( "\tstw %s, %d(%s)\n", ppc_reg(7), 20+extra_stack_storage
, ppc_reg(1));
1017 output( "\tstw %s, %d(%s)\n", ppc_reg(8), 24+extra_stack_storage
, ppc_reg(1));
1018 output( "\tstw %s, %d(%s)\n", ppc_reg(9), 28+extra_stack_storage
, ppc_reg(1));
1019 output( "\tstw %s, %d(%s)\n", ppc_reg(10),32+extra_stack_storage
, ppc_reg(1));
1020 output( "\tstw %s, %d(%s)\n", ppc_reg(11),36+extra_stack_storage
, ppc_reg(1));
1021 output( "\tstw %s, %d(%s)\n", ppc_reg(12),40+extra_stack_storage
, ppc_reg(1));
1023 /* r0 -> r3 (arg1) */
1024 output( "\tmr %s, %s\n", ppc_reg(3), ppc_reg(0));
1026 /* save return address */
1027 output( "\tmflr %s\n", ppc_reg(0));
1028 output( "\tstw %s, %d(%s)\n", ppc_reg(0), 44+extra_stack_storage
, ppc_reg(1));
1030 /* Call the __wine_delay_load function, arg1 is arg1. */
1031 output( "\tbl %s\n", asm_name("__wine_spec_delay_load") );
1033 /* Load return value from call into ctr register */
1034 output( "\tmtctr %s\n", ppc_reg(3));
1036 /* restore all saved registers and drop stackframe. */
1037 output( "\tlwz %s, %d(%s)\n", ppc_reg(3), 4+extra_stack_storage
, ppc_reg(1));
1038 output( "\tlwz %s, %d(%s)\n", ppc_reg(4), 8+extra_stack_storage
, ppc_reg(1));
1039 output( "\tlwz %s, %d(%s)\n", ppc_reg(5), 12+extra_stack_storage
, ppc_reg(1));
1040 output( "\tlwz %s, %d(%s)\n", ppc_reg(6), 16+extra_stack_storage
, ppc_reg(1));
1041 output( "\tlwz %s, %d(%s)\n", ppc_reg(7), 20+extra_stack_storage
, ppc_reg(1));
1042 output( "\tlwz %s, %d(%s)\n", ppc_reg(8), 24+extra_stack_storage
, ppc_reg(1));
1043 output( "\tlwz %s, %d(%s)\n", ppc_reg(9), 28+extra_stack_storage
, ppc_reg(1));
1044 output( "\tlwz %s, %d(%s)\n", ppc_reg(10),32+extra_stack_storage
, ppc_reg(1));
1045 output( "\tlwz %s, %d(%s)\n", ppc_reg(11),36+extra_stack_storage
, ppc_reg(1));
1046 output( "\tlwz %s, %d(%s)\n", ppc_reg(12),40+extra_stack_storage
, ppc_reg(1));
1048 /* Load return value from call into return register */
1049 output( "\tlwz %s, %d(%s)\n", ppc_reg(0), 44+extra_stack_storage
, ppc_reg(1));
1050 output( "\tmtlr %s\n", ppc_reg(0));
1051 output( "\taddi %s, %s, %d\n", ppc_reg(1), ppc_reg(1), 48+extra_stack_storage
);
1053 /* branch to ctr register. */
1054 output( "\tbctr\n");
1057 output_cfi( ".cfi_endproc" );
1058 output_function_size( "__wine_delay_load_asm" );
1061 for (i
= idx
= 0; i
< nb_imports
; i
++)
1063 if (!dll_imports
[i
]->delay
) continue;
1064 for (j
= 0; j
< dll_imports
[i
]->nb_imports
; j
++)
1066 ORDDEF
*odp
= dll_imports
[i
]->imports
[j
];
1067 const char *name
= odp
->name
? odp
->name
: odp
->export_name
;
1069 output( ".L__wine_delay_imp_%d_%s:\n", i
, name
);
1070 output_cfi( ".cfi_startproc" );
1074 output( "\tmovl $%d, %%eax\n", (idx
<< 16) | j
);
1075 output( "\tjmp %s\n", asm_name("__wine_delay_load_asm") );
1078 output( "\tmovq $%d,%%rax\n", (idx
<< 16) | j
);
1079 output( "\tjmp %s\n", asm_name("__wine_delay_load_asm") );
1082 output( "\tset %d, %%g1\n", (idx
<< 16) | j
);
1083 output( "\tb,a %s\n", asm_name("__wine_delay_load_asm") );
1086 output( "\tlda $0,%d($31)\n", j
);
1087 output( "\tldah $0,%d($0)\n", idx
);
1088 output( "\tjmp $31,%s\n", asm_name("__wine_delay_load_asm") );
1091 output( "\tstmfd SP!, {r0-r3}\n" );
1092 output( "\tmov r0, #%d\n", idx
);
1093 output( "\tmov r1, #16384\n" );
1094 output( "\tmul r1, r0, r1\n" );
1095 output( "\tmov r0, r1\n" );
1096 output( "\tmov r1, #4\n" );
1097 output( "\tmul r1, r0, r1\n" );
1098 output( "\tmov r0, r1\n" );
1099 output( "\tadd r0, #%d\n", j
);
1100 output( "\tldr PC,[PC,#-4]\n");
1101 output( "\t%s %s\n", get_asm_ptr_keyword(), asm_name("__wine_delay_load_asm") );
1104 switch(target_platform
)
1106 case PLATFORM_APPLE
:
1107 /* On Darwin we can use r0 and r2 */
1108 /* Upper part in r2 */
1109 output( "\tlis %s, %d\n", ppc_reg(2), idx
);
1110 /* Lower part + r2 -> r0, Note we can't use r0 directly */
1111 output( "\taddi %s, %s, %d\n", ppc_reg(0), ppc_reg(2), j
);
1112 output( "\tb %s\n", asm_name("__wine_delay_load_asm") );
1115 /* On linux we can't use r2 since r2 is not a scratch register (hold the TOC) */
1116 /* Save r13 on the stack */
1117 output( "\taddi %s, %s, -0x4\n", ppc_reg(1), ppc_reg(1));
1118 output( "\tstw %s, 0(%s)\n", ppc_reg(13), ppc_reg(1));
1119 /* Upper part in r13 */
1120 output( "\tlis %s, %d\n", ppc_reg(13), idx
);
1121 /* Lower part + r13 -> r0, Note we can't use r0 directly */
1122 output( "\taddi %s, %s, %d\n", ppc_reg(0), ppc_reg(13), j
);
1124 output( "\tstw %s, 0(%s)\n", ppc_reg(13), ppc_reg(1));
1125 output( "\taddic %s, %s, 0x4\n", ppc_reg(1), ppc_reg(1));
1126 output( "\tb %s\n", asm_name("__wine_delay_load_asm") );
1131 output_cfi( ".cfi_endproc" );
1135 output_function_size( delayed_import_loaders
);
1137 output( "\n\t.align %d\n", get_alignment(get_ptr_size()) );
1138 output( "%s:\n", asm_name(delayed_import_thunks
));
1139 for (i
= pos
= 0; i
< nb_imports
; i
++)
1141 if (!dll_imports
[i
]->delay
) continue;
1142 for (j
= 0; j
< dll_imports
[i
]->nb_imports
; j
++, pos
+= get_ptr_size())
1144 ORDDEF
*odp
= dll_imports
[i
]->imports
[j
];
1145 output_import_thunk( odp
->name
? odp
->name
: odp
->export_name
,
1146 ".L__wine_delay_IAT", pos
);
1149 output_function_size( delayed_import_thunks
);
1152 /* output import stubs for exported entry points that link to external symbols */
1153 static void output_external_link_imports( DLLSPEC
*spec
)
1155 unsigned int i
, pos
;
1157 if (!ext_link_imports
.count
) return; /* nothing to do */
1159 sort_names( &ext_link_imports
);
1161 /* get rid of duplicate names */
1162 for (i
= 1; i
< ext_link_imports
.count
; i
++)
1164 if (!strcmp( ext_link_imports
.names
[i
-1], ext_link_imports
.names
[i
] ))
1165 remove_name( &ext_link_imports
, i
-- );
1168 output( "\n/* external link thunks */\n\n" );
1169 output( "\t.data\n" );
1170 output( "\t.align %d\n", get_alignment(get_ptr_size()) );
1171 output( ".L__wine_spec_external_links:\n" );
1172 for (i
= 0; i
< ext_link_imports
.count
; i
++)
1173 output( "\t%s %s\n", get_asm_ptr_keyword(), asm_name(ext_link_imports
.names
[i
]) );
1175 output( "\n\t.text\n" );
1176 output( "\t.align %d\n", get_alignment(get_ptr_size()) );
1177 output( "%s:\n", asm_name("__wine_spec_external_link_thunks") );
1179 for (i
= pos
= 0; i
< ext_link_imports
.count
; i
++)
1181 char *buffer
= strmake( "__wine_spec_ext_link_%s", ext_link_imports
.names
[i
] );
1182 output_import_thunk( buffer
, ".L__wine_spec_external_links", pos
);
1184 pos
+= get_ptr_size();
1186 output_function_size( "__wine_spec_external_link_thunks" );
1189 /*******************************************************************
1192 * Output the functions for stub entry points
1194 void output_stubs( DLLSPEC
*spec
)
1196 const char *name
, *exp_name
;
1199 if (!has_stubs( spec
)) return;
1201 output( "\n/* stub functions */\n\n" );
1202 output( "\t.text\n" );
1204 for (i
= count
= 0; i
< spec
->nb_entry_points
; i
++)
1206 ORDDEF
*odp
= &spec
->entry_points
[i
];
1207 if (odp
->type
!= TYPE_STUB
) continue;
1209 name
= get_stub_name( odp
, spec
);
1210 exp_name
= odp
->name
? odp
->name
: odp
->export_name
;
1211 output( "\t.align %d\n", get_alignment(4) );
1212 output( "\t%s\n", func_declaration(name
) );
1213 output( "%s:\n", asm_name(name
) );
1214 output_cfi( ".cfi_startproc" );
1219 /* flesh out the stub a bit to make safedisc happy */
1220 output(" \tnop\n" );
1221 output(" \tnop\n" );
1222 output(" \tnop\n" );
1223 output(" \tnop\n" );
1224 output(" \tnop\n" );
1225 output(" \tnop\n" );
1226 output(" \tnop\n" );
1227 output(" \tnop\n" );
1228 output(" \tnop\n" );
1230 output( "\tsubl $12,%%esp\n" );
1231 output_cfi( ".cfi_adjust_cfa_offset 12" );
1234 output( "\tcall %s\n", asm_name("__wine_spec_get_pc_thunk_eax") );
1238 output( "\tleal .L%s_string-1b(%%eax),%%ecx\n", name
);
1239 output( "\tmovl %%ecx,4(%%esp)\n" );
1243 output( "\tmovl $%d,4(%%esp)\n", odp
->ordinal
);
1244 output( "\tleal .L__wine_spec_file_name-1b(%%eax),%%ecx\n" );
1245 output( "\tmovl %%ecx,(%%esp)\n" );
1251 output( "\tmovl $.L%s_string,4(%%esp)\n", name
);
1255 output( "\tmovl $%d,4(%%esp)\n", odp
->ordinal
);
1256 output( "\tmovl $.L__wine_spec_file_name,(%%esp)\n" );
1258 output( "\tcall %s\n", asm_name("__wine_spec_unimplemented_stub") );
1261 output( "\tsubq $8,%%rsp\n" );
1262 output_cfi( ".cfi_adjust_cfa_offset 8" );
1263 output( "\tleaq .L__wine_spec_file_name(%%rip),%%rdi\n" );
1266 output( "leaq .L%s_string(%%rip),%%rsi\n", name
);
1270 output( "\tmovq $%d,%%rsi\n", odp
->ordinal
);
1271 output( "\tcall %s\n", asm_name("__wine_spec_unimplemented_stub") );
1276 output_cfi( ".cfi_endproc" );
1277 output_function_size( name
);
1282 output( "\t%s\n", get_asm_string_section() );
1283 for (i
= 0; i
< spec
->nb_entry_points
; i
++)
1285 ORDDEF
*odp
= &spec
->entry_points
[i
];
1286 if (odp
->type
!= TYPE_STUB
) continue;
1287 exp_name
= odp
->name
? odp
->name
: odp
->export_name
;
1290 name
= get_stub_name( odp
, spec
);
1291 output( ".L%s_string:\n", name
);
1292 output( "\t%s \"%s\"\n", get_asm_string_keyword(), exp_name
);
1298 /* output the import and delayed import tables of a Win32 module */
1299 void output_imports( DLLSPEC
*spec
)
1301 output_immediate_imports();
1302 output_delayed_imports( spec
);
1303 output_immediate_import_thunks();
1304 output_delayed_import_thunks( spec
);
1305 output_external_link_imports( spec
);
1306 if (nb_imports
|| ext_link_imports
.count
|| has_stubs(spec
) || has_relays(spec
))
1307 output_get_pc_thunk();
1310 /* output an import library for a Win32 module and additional object files */
1311 void output_import_lib( DLLSPEC
*spec
, char **argv
)
1313 struct strarray
*args
= strarray_init();
1316 if (target_platform
!= PLATFORM_WINDOWS
)
1317 fatal_error( "Unix-style import libraries not supported yet\n" );
1319 def_file
= get_temp_file_name( output_file_name
, ".def" );
1320 fclose( output_file
);
1321 if (!(output_file
= fopen( def_file
, "w" )))
1322 fatal_error( "Unable to create output file '%s'\n", def_file
);
1323 output_def_file( spec
, 0 );
1324 fclose( output_file
);
1327 strarray_add( args
, find_tool( "dlltool", NULL
), "-k", "-l", output_file_name
, "-d", def_file
, NULL
);
1329 strarray_free( args
);
1333 args
= strarray_init();
1334 strarray_add( args
, find_tool( "ar", NULL
), "rs", output_file_name
, NULL
);
1335 strarray_addv( args
, argv
);
1337 strarray_free( args
);
1339 output_file_name
= NULL
;