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
;
229 int delayed
= is_delayed_import( spec
->file_name
);
231 f
= open_input_file( NULL
, imp
->full_name
);
232 fstat( fileno(f
), &stat
);
233 imp
->dev
= stat
.st_dev
;
234 imp
->ino
= stat
.st_ino
;
235 ret
= parse_def_file( f
, spec
);
236 close_input_file( f
);
239 /* check if we already imported that library from a different file */
240 if ((prev_imp
= is_already_imported( spec
->file_name
)))
242 if (prev_imp
->dev
!= imp
->dev
|| prev_imp
->ino
!= imp
->ino
)
243 fatal_error( "%s and %s have the same export name '%s'\n",
244 prev_imp
->full_name
, imp
->full_name
, spec
->file_name
);
245 return 0; /* the same file was already loaded, ignore this one */
254 if (spec
->nb_entry_points
)
256 imp
->exports
= xmalloc( spec
->nb_entry_points
* sizeof(*imp
->exports
) );
257 for (i
= 0; i
< spec
->nb_entry_points
; i
++)
258 imp
->exports
[imp
->nb_exports
++] = &spec
->entry_points
[i
];
259 qsort( imp
->exports
, imp
->nb_exports
, sizeof(*imp
->exports
), func_cmp
);
264 /* build the dll exported name from the import lib name or path */
265 static char *get_dll_name( const char *name
, const char *filename
)
271 const char *basename
= strrchr( filename
, '/' );
272 if (!basename
) basename
= filename
;
274 if (!strncmp( basename
, "lib", 3 )) basename
+= 3;
275 ret
= xmalloc( strlen(basename
) + 5 );
276 strcpy( ret
, basename
);
277 if (strendswith( ret
, ".def" )) ret
[strlen(ret
)-4] = 0;
281 ret
= xmalloc( strlen(name
) + 5 );
284 if (!strchr( ret
, '.' )) strcat( ret
, ".dll" );
288 /* add a dll to the list of imports */
289 void add_import_dll( const char *name
, const char *filename
)
291 struct import
*imp
= xmalloc( sizeof(*imp
) );
293 imp
->spec
= alloc_dll_spec();
294 imp
->spec
->file_name
= get_dll_name( name
, filename
);
301 if (filename
) imp
->full_name
= xstrdup( filename
);
302 else imp
->full_name
= find_library( name
);
304 if (read_import_lib( imp
))
306 dll_imports
= xrealloc( dll_imports
, (nb_imports
+1) * sizeof(*dll_imports
) );
307 dll_imports
[nb_imports
++] = imp
;
312 if (nb_errors
) exit(1);
316 /* add a library to the list of delayed imports */
317 void add_delayed_import( const char *name
)
320 char *fullname
= get_dll_name( name
, NULL
);
322 add_name( &delayed_imports
, fullname
);
323 if ((imp
= is_already_imported( fullname
)) && !imp
->delay
)
331 /* remove an imported dll, based on its index in the dll_imports array */
332 static void remove_import_dll( int index
)
334 struct import
*imp
= dll_imports
[index
];
336 memmove( &dll_imports
[index
], &dll_imports
[index
+1], sizeof(imp
) * (nb_imports
- index
- 1) );
338 if (imp
->delay
) nb_delayed
--;
342 /* add a symbol to the list of extra symbols that ld must resolve */
343 void add_extra_ld_symbol( const char *name
)
345 add_name( &extra_ld_symbols
, name
);
348 /* add a function to the list of imports from a given dll */
349 static void add_import_func( struct import
*imp
, ORDDEF
*func
)
351 imp
->imports
= xrealloc( imp
->imports
, (imp
->nb_imports
+1) * sizeof(*imp
->imports
) );
352 imp
->imports
[imp
->nb_imports
++] = func
;
354 if (imp
->delay
) total_delayed
++;
357 /* get the default entry point for a given spec file */
358 static const char *get_default_entry_point( const DLLSPEC
*spec
)
360 if (spec
->characteristics
& IMAGE_FILE_DLL
) return "__wine_spec_dll_entry";
361 if (spec
->subsystem
== IMAGE_SUBSYSTEM_NATIVE
) return "__wine_spec_drv_entry";
362 if (spec
->type
== SPEC_WIN16
) return "__wine_spec_exe16_entry";
363 return "__wine_spec_exe_entry";
366 /* check if the spec file exports any stubs */
367 static int has_stubs( const DLLSPEC
*spec
)
370 for (i
= 0; i
< spec
->nb_entry_points
; i
++)
372 ORDDEF
*odp
= &spec
->entry_points
[i
];
373 if (odp
->type
== TYPE_STUB
) return 1;
378 /* add the extra undefined symbols that will be contained in the generated spec file itself */
379 static void add_extra_undef_symbols( DLLSPEC
*spec
)
381 if (!spec
->init_func
) spec
->init_func
= xstrdup( get_default_entry_point(spec
) );
382 add_extra_ld_symbol( spec
->init_func
);
383 if (has_stubs( spec
)) add_extra_ld_symbol( "__wine_spec_unimplemented_stub" );
384 if (nb_delayed
) add_extra_ld_symbol( "__wine_spec_delay_load" );
387 /* check if a given imported dll is not needed, taking forwards into account */
388 static int check_unused( const struct import
* imp
, const DLLSPEC
*spec
)
391 const char *file_name
= imp
->spec
->file_name
;
392 size_t len
= strlen( file_name
);
393 const char *p
= strchr( file_name
, '.' );
394 if (p
&& !strcasecmp( p
, ".dll" )) len
= p
- file_name
;
396 for (i
= spec
->base
; i
<= spec
->limit
; i
++)
398 ORDDEF
*odp
= spec
->ordinals
[i
];
399 if (!odp
|| !(odp
->flags
& FLAG_FORWARD
)) continue;
400 if (!strncasecmp( odp
->link_name
, file_name
, len
) &&
401 odp
->link_name
[len
] == '.')
402 return 0; /* found a forward, it is used */
407 /* check if a given forward does exist in one of the imported dlls */
408 static void check_undefined_forwards( DLLSPEC
*spec
)
410 char *link_name
, *api_name
, *dll_name
, *p
;
413 for (i
= 0; i
< spec
->nb_entry_points
; i
++)
415 ORDDEF
*odp
= &spec
->entry_points
[i
];
417 if (!(odp
->flags
& FLAG_FORWARD
)) continue;
419 link_name
= xstrdup( odp
->link_name
);
420 p
= strrchr( link_name
, '.' );
423 dll_name
= get_dll_name( link_name
, NULL
);
425 for (j
= 0; j
< nb_imports
; j
++)
427 struct import
*imp
= dll_imports
[j
];
429 if (strcasecmp( imp
->spec
->file_name
, dll_name
)) continue;
430 if (!find_export( api_name
, imp
->exports
, imp
->nb_exports
))
431 warning( "%s:%d: forward '%s' not found in %s\n",
432 spec
->src_name
, odp
->lineno
, odp
->link_name
, imp
->spec
->file_name
);
436 warning( "%s:%d: forward '%s' not found in the imported dll list\n",
437 spec
->src_name
, odp
->lineno
, odp
->link_name
);
443 /* flag the dll exports that link to an undefined symbol */
444 static void check_undefined_exports( DLLSPEC
*spec
)
448 for (i
= 0; i
< spec
->nb_entry_points
; i
++)
450 ORDDEF
*odp
= &spec
->entry_points
[i
];
451 if (odp
->type
== TYPE_STUB
|| odp
->type
== TYPE_ABS
|| odp
->type
== TYPE_VARIABLE
) continue;
452 if (odp
->flags
& FLAG_FORWARD
) continue;
453 if (find_name( odp
->link_name
, &undef_symbols
))
462 if (link_ext_symbols
)
464 odp
->flags
|= FLAG_EXT_LINK
;
465 add_name( &ext_link_imports
, odp
->link_name
);
467 else error( "%s:%d: function '%s' not defined\n",
468 spec
->src_name
, odp
->lineno
, odp
->link_name
);
471 error( "%s:%d: external symbol '%s' is not a function\n",
472 spec
->src_name
, odp
->lineno
, odp
->link_name
);
479 /* create a .o file that references all the undefined symbols we want to resolve */
480 static char *create_undef_symbols_file( DLLSPEC
*spec
)
482 char *as_file
, *obj_file
;
487 as_file
= get_temp_file_name( output_file_name
, ".s" );
488 if (!(f
= fopen( as_file
, "w" ))) fatal_error( "Cannot create %s\n", as_file
);
489 fprintf( f
, "\t.data\n" );
491 for (i
= 0; i
< spec
->nb_entry_points
; i
++)
493 ORDDEF
*odp
= &spec
->entry_points
[i
];
494 if (odp
->type
== TYPE_STUB
|| odp
->type
== TYPE_ABS
|| odp
->type
== TYPE_VARIABLE
) continue;
495 if (odp
->flags
& FLAG_FORWARD
) continue;
496 fprintf( f
, "\t%s %s\n", get_asm_ptr_keyword(), asm_name(odp
->link_name
) );
498 for (j
= 0; j
< extra_ld_symbols
.count
; j
++)
499 fprintf( f
, "\t%s %s\n", get_asm_ptr_keyword(), asm_name(extra_ld_symbols
.names
[j
]) );
502 obj_file
= get_temp_file_name( output_file_name
, ".o" );
503 assemble_file( as_file
, obj_file
);
507 /* combine a list of object files with ld into a single object file */
508 /* returns the name of the combined file */
509 static const char *ldcombine_files( DLLSPEC
*spec
, char **argv
)
511 char *ld_tmp_file
, *undef_file
;
512 struct strarray
*args
= get_ld_command();
514 undef_file
= create_undef_symbols_file( spec
);
515 ld_tmp_file
= get_temp_file_name( output_file_name
, ".o" );
517 strarray_add( args
, "-r", "-o", ld_tmp_file
, undef_file
, NULL
);
518 strarray_addv( args
, argv
);
520 strarray_free( args
);
524 /* read in the list of undefined symbols */
525 void read_undef_symbols( DLLSPEC
*spec
, char **argv
)
529 const char *prog
= get_nm_command();
530 char *cmd
, buffer
[1024], name_prefix
[16];
534 if (!argv
[0]) return;
536 add_extra_undef_symbols( spec
);
538 strcpy( name_prefix
, asm_name("") );
539 prefix_len
= strlen( name_prefix
);
541 name
= ldcombine_files( spec
, argv
);
543 cmd
= strmake( "%s -u %s", prog
, name
);
544 if (!(f
= popen( cmd
, "r" )))
545 fatal_error( "Cannot execute '%s'\n", cmd
);
547 while (fgets( buffer
, sizeof(buffer
), f
))
549 char *p
= buffer
+ strlen(buffer
) - 1;
550 if (p
< buffer
) continue;
551 if (*p
== '\n') *p
-- = 0;
553 while (*p
== ' ') p
++;
554 if (p
[0] == 'U' && p
[1] == ' ' && p
[2]) p
+= 2;
555 if (prefix_len
&& !strncmp( p
, name_prefix
, prefix_len
)) p
+= prefix_len
;
556 add_name( &undef_symbols
, p
);
558 if ((err
= pclose( f
))) warning( "%s failed with status %d\n", cmd
, err
);
562 /* resolve the imports for a Win32 module */
563 void resolve_imports( DLLSPEC
*spec
)
566 unsigned int j
, removed
;
569 check_undefined_forwards( spec
);
571 for (i
= 0; i
< nb_imports
; i
++)
573 struct import
*imp
= dll_imports
[i
];
575 for (j
= removed
= 0; j
< undef_symbols
.count
; j
++)
577 odp
= find_export( undef_symbols
.names
[j
], imp
->exports
, imp
->nb_exports
);
580 if (odp
->flags
& FLAG_PRIVATE
) continue;
581 if (odp
->type
!= TYPE_STDCALL
&& odp
->type
!= TYPE_CDECL
)
582 warning( "winebuild: Data export '%s' cannot be imported from %s\n",
583 odp
->link_name
, imp
->spec
->file_name
);
586 add_import_func( imp
, odp
);
587 remove_name( &undef_symbols
, j
-- );
594 /* the dll is not used, get rid of it */
595 if (check_unused( imp
, spec
))
596 warning( "winebuild: %s imported but no symbols used\n", imp
->spec
->file_name
);
597 remove_import_dll( i
);
602 sort_names( &undef_symbols
);
603 check_undefined_exports( spec
);
606 /* check if symbol is still undefined */
607 int is_undefined( const char *name
)
609 return find_name( name
, &undef_symbols
) != NULL
;
612 /* output the get_pc thunk if needed */
613 void output_get_pc_thunk(void)
615 if (target_cpu
!= CPU_x86
) return;
617 output( "\n\t.text\n" );
618 output( "\t.align %d\n", get_alignment(4) );
619 output( "\t%s\n", func_declaration("__wine_spec_get_pc_thunk_eax") );
620 output( "%s:\n", asm_name("__wine_spec_get_pc_thunk_eax") );
621 output_cfi( ".cfi_startproc" );
622 output( "\tmovl (%%esp),%%eax\n" );
624 output_cfi( ".cfi_endproc" );
625 output_function_size( "__wine_spec_get_pc_thunk_eax" );
628 /* output a single import thunk */
629 static void output_import_thunk( const char *name
, const char *table
, int pos
)
631 output( "\n\t.align %d\n", get_alignment(4) );
632 output( "\t%s\n", func_declaration(name
) );
633 output( "%s\n", asm_globl(name
) );
634 output_cfi( ".cfi_startproc" );
641 output( "\tjmp *(%s+%d)\n", table
, pos
);
645 output( "\tcall %s\n", asm_name("__wine_spec_get_pc_thunk_eax") );
646 output( "1:\tjmp *%s+%d-1b(%%eax)\n", table
, pos
);
650 output( "\tjmpq *%s+%d(%%rip)\n", table
, pos
);
653 output( "\tldr IP,1f\n");
654 output( "\tldr PC,[PC,IP]\n" );
655 output( "1:\t.long %s+%u-(1b+4)\n", table
, pos
);
658 output( "\tadr x9, 1f\n" );
659 output( "\tldur x9, [x9, #0]\n" );
660 if (pos
& 0xf000) output( "\tadd x9, x9, #%u\n", pos
& 0xf000 );
661 if (pos
& 0x0f00) output( "\tadd x9, x9, #%u\n", pos
& 0x0f00 );
662 if (pos
& 0x00f0) output( "\tadd x9, x9, #%u\n", pos
& 0x00f0 );
663 if (pos
& 0x000f) output( "\tadd x9, x9, #%u\n", pos
& 0x000f );
664 output( "\tldur x9, [x9, #0]\n" );
665 output( "\tbr x9\n" );
666 output( "1:\t.quad %s\n", table
);
669 output( "\tmr %s, %s\n", ppc_reg(0), ppc_reg(31) );
670 if (target_platform
== PLATFORM_APPLE
)
672 output( "\tlis %s, ha16(%s+%d+32768)\n", ppc_reg(31), table
, pos
);
673 output( "\tla %s, lo16(%s+%d)(%s)\n", ppc_reg(31), table
, pos
, ppc_reg(31) );
677 output( "\tlis %s, (%s+%d+32768)@h\n", ppc_reg(31), table
, pos
);
678 output( "\tla %s, (%s+%d)@l(%s)\n", ppc_reg(31), table
, pos
, ppc_reg(31) );
680 output( "\tlwz %s, 0(%s)\n", ppc_reg(31), ppc_reg(31) );
681 output( "\tmtctr %s\n", ppc_reg(31) );
682 output( "\tmr %s, %s\n", ppc_reg(31), ppc_reg(0) );
683 output( "\tbctr\n" );
686 output_cfi( ".cfi_endproc" );
687 output_function_size( name
);
690 /* check if we need an import directory */
691 int has_imports(void)
693 return (nb_imports
- nb_delayed
) > 0;
696 /* output the import table of a Win32 module */
697 static void output_immediate_imports(void)
700 const char *dll_name
;
702 if (nb_imports
== nb_delayed
) return; /* no immediate imports */
704 /* main import header */
706 output( "\n/* import table */\n" );
707 output( "\n\t.data\n" );
708 output( "\t.align %d\n", get_alignment(4) );
709 output( ".L__wine_spec_imports:\n" );
713 for (i
= j
= 0; i
< nb_imports
; i
++)
715 if (dll_imports
[i
]->delay
) continue;
716 dll_name
= make_c_identifier( dll_imports
[i
]->spec
->file_name
);
717 output( "\t.long .L__wine_spec_import_data_names+%d-.L__wine_spec_rva_base\n", /* OriginalFirstThunk */
718 j
* get_ptr_size() );
719 output( "\t.long 0\n" ); /* TimeDateStamp */
720 output( "\t.long 0\n" ); /* ForwarderChain */
721 output( "\t.long .L__wine_spec_import_name_%s-.L__wine_spec_rva_base\n", /* Name */
723 output( "\t.long .L__wine_spec_import_data_ptrs+%d-.L__wine_spec_rva_base\n", /* FirstThunk */
724 j
* get_ptr_size() );
725 j
+= dll_imports
[i
]->nb_imports
+ 1;
727 output( "\t.long 0\n" ); /* OriginalFirstThunk */
728 output( "\t.long 0\n" ); /* TimeDateStamp */
729 output( "\t.long 0\n" ); /* ForwarderChain */
730 output( "\t.long 0\n" ); /* Name */
731 output( "\t.long 0\n" ); /* FirstThunk */
733 output( "\n\t.align %d\n", get_alignment(get_ptr_size()) );
734 output( ".L__wine_spec_import_data_names:\n" );
735 for (i
= 0; i
< nb_imports
; i
++)
737 if (dll_imports
[i
]->delay
) continue;
738 dll_name
= make_c_identifier( dll_imports
[i
]->spec
->file_name
);
739 for (j
= 0; j
< dll_imports
[i
]->nb_imports
; j
++)
741 ORDDEF
*odp
= dll_imports
[i
]->imports
[j
];
742 if (!(odp
->flags
& FLAG_NONAME
))
743 output( "\t%s .L__wine_spec_import_data_%s_%s-.L__wine_spec_rva_base\n",
744 get_asm_ptr_keyword(), dll_name
, odp
->name
);
747 if (get_ptr_size() == 8)
748 output( "\t.quad 0x800000000000%04x\n", odp
->ordinal
);
750 output( "\t.long 0x8000%04x\n", odp
->ordinal
);
753 output( "\t%s 0\n", get_asm_ptr_keyword() );
755 output( ".L__wine_spec_import_data_ptrs:\n" );
756 for (i
= 0; i
< nb_imports
; i
++)
758 if (dll_imports
[i
]->delay
) continue;
759 for (j
= 0; j
< dll_imports
[i
]->nb_imports
; j
++) output( "\t%s 0\n", get_asm_ptr_keyword() );
760 output( "\t%s 0\n", get_asm_ptr_keyword() );
762 output( ".L__wine_spec_imports_end:\n" );
764 for (i
= 0; i
< nb_imports
; i
++)
766 if (dll_imports
[i
]->delay
) continue;
767 dll_name
= make_c_identifier( dll_imports
[i
]->spec
->file_name
);
768 for (j
= 0; j
< dll_imports
[i
]->nb_imports
; j
++)
770 ORDDEF
*odp
= dll_imports
[i
]->imports
[j
];
771 if (!(odp
->flags
& FLAG_NONAME
))
773 output( "\t.align %d\n", get_alignment(2) );
774 output( ".L__wine_spec_import_data_%s_%s:\n", dll_name
, odp
->name
);
775 output( "\t.short %d\n", odp
->ordinal
);
776 output( "\t%s \"%s\"\n", get_asm_string_keyword(), odp
->name
);
781 for (i
= 0; i
< nb_imports
; i
++)
783 if (dll_imports
[i
]->delay
) continue;
784 dll_name
= make_c_identifier( dll_imports
[i
]->spec
->file_name
);
785 output( ".L__wine_spec_import_name_%s:\n\t%s \"%s\"\n",
786 dll_name
, get_asm_string_keyword(), dll_imports
[i
]->spec
->file_name
);
790 /* output the import thunks of a Win32 module */
791 static void output_immediate_import_thunks(void)
794 int nb_imm
= nb_imports
- nb_delayed
;
795 static const char import_thunks
[] = "__wine_spec_import_thunks";
799 output( "\n/* immediate import thunks */\n\n" );
800 output( "\t.text\n" );
801 output( "\t.align %d\n", get_alignment(8) );
802 output( "%s:\n", asm_name(import_thunks
));
804 for (i
= pos
= 0; i
< nb_imports
; i
++)
806 if (dll_imports
[i
]->delay
) continue;
807 for (j
= 0; j
< dll_imports
[i
]->nb_imports
; j
++, pos
+= get_ptr_size())
809 ORDDEF
*odp
= dll_imports
[i
]->imports
[j
];
810 output_import_thunk( odp
->name
? odp
->name
: odp
->export_name
,
811 ".L__wine_spec_import_data_ptrs", pos
);
813 pos
+= get_ptr_size();
815 output_function_size( import_thunks
);
818 /* output the delayed import table of a Win32 module */
819 static void output_delayed_imports( const DLLSPEC
*spec
)
823 if (!nb_delayed
) return;
825 output( "\n/* delayed imports */\n\n" );
826 output( "\t.data\n" );
827 output( "\t.align %d\n", get_alignment(get_ptr_size()) );
828 output( "%s\n", asm_globl("__wine_spec_delay_imports") );
832 for (i
= j
= mod
= 0; i
< nb_imports
; i
++)
834 if (!dll_imports
[i
]->delay
) continue;
835 output( "\t%s 0\n", get_asm_ptr_keyword() ); /* grAttrs */
836 output( "\t%s .L__wine_delay_name_%d\n", /* szName */
837 get_asm_ptr_keyword(), i
);
838 output( "\t%s .L__wine_delay_modules+%d\n", /* phmod */
839 get_asm_ptr_keyword(), mod
* get_ptr_size() );
840 output( "\t%s .L__wine_delay_IAT+%d\n", /* pIAT */
841 get_asm_ptr_keyword(), j
* get_ptr_size() );
842 output( "\t%s .L__wine_delay_INT+%d\n", /* pINT */
843 get_asm_ptr_keyword(), j
* get_ptr_size() );
844 output( "\t%s 0\n", get_asm_ptr_keyword() ); /* pBoundIAT */
845 output( "\t%s 0\n", get_asm_ptr_keyword() ); /* pUnloadIAT */
846 output( "\t%s 0\n", get_asm_ptr_keyword() ); /* dwTimeStamp */
847 j
+= dll_imports
[i
]->nb_imports
;
850 output( "\t%s 0\n", get_asm_ptr_keyword() ); /* grAttrs */
851 output( "\t%s 0\n", get_asm_ptr_keyword() ); /* szName */
852 output( "\t%s 0\n", get_asm_ptr_keyword() ); /* phmod */
853 output( "\t%s 0\n", get_asm_ptr_keyword() ); /* pIAT */
854 output( "\t%s 0\n", get_asm_ptr_keyword() ); /* pINT */
855 output( "\t%s 0\n", get_asm_ptr_keyword() ); /* pBoundIAT */
856 output( "\t%s 0\n", get_asm_ptr_keyword() ); /* pUnloadIAT */
857 output( "\t%s 0\n", get_asm_ptr_keyword() ); /* dwTimeStamp */
859 output( "\n.L__wine_delay_IAT:\n" );
860 for (i
= 0; i
< nb_imports
; i
++)
862 if (!dll_imports
[i
]->delay
) continue;
863 for (j
= 0; j
< dll_imports
[i
]->nb_imports
; j
++)
865 ORDDEF
*odp
= dll_imports
[i
]->imports
[j
];
866 const char *name
= odp
->name
? odp
->name
: odp
->export_name
;
867 output( "\t%s .L__wine_delay_imp_%d_%s\n",
868 get_asm_ptr_keyword(), i
, name
);
872 output( "\n.L__wine_delay_INT:\n" );
873 for (i
= 0; i
< nb_imports
; i
++)
875 if (!dll_imports
[i
]->delay
) continue;
876 for (j
= 0; j
< dll_imports
[i
]->nb_imports
; j
++)
878 ORDDEF
*odp
= dll_imports
[i
]->imports
[j
];
880 output( "\t%s %d\n", get_asm_ptr_keyword(), odp
->ordinal
);
882 output( "\t%s .L__wine_delay_data_%d_%s\n",
883 get_asm_ptr_keyword(), i
, odp
->name
);
887 output( "\n.L__wine_delay_modules:\n" );
888 for (i
= 0; i
< nb_imports
; i
++)
890 if (dll_imports
[i
]->delay
) output( "\t%s 0\n", get_asm_ptr_keyword() );
893 for (i
= 0; i
< nb_imports
; i
++)
895 if (!dll_imports
[i
]->delay
) continue;
896 output( ".L__wine_delay_name_%d:\n", i
);
897 output( "\t%s \"%s\"\n",
898 get_asm_string_keyword(), dll_imports
[i
]->spec
->file_name
);
901 for (i
= 0; i
< nb_imports
; i
++)
903 if (!dll_imports
[i
]->delay
) continue;
904 for (j
= 0; j
< dll_imports
[i
]->nb_imports
; j
++)
906 ORDDEF
*odp
= dll_imports
[i
]->imports
[j
];
907 if (!odp
->name
) continue;
908 output( ".L__wine_delay_data_%d_%s:\n", i
, odp
->name
);
909 output( "\t%s \"%s\"\n", get_asm_string_keyword(), odp
->name
);
912 output_function_size( "__wine_spec_delay_imports" );
915 /* output the delayed import thunks of a Win32 module */
916 static void output_delayed_import_thunks( const DLLSPEC
*spec
)
918 int i
, idx
, j
, pos
, extra_stack_storage
= 0;
919 static const char delayed_import_loaders
[] = "__wine_spec_delayed_import_loaders";
920 static const char delayed_import_thunks
[] = "__wine_spec_delayed_import_thunks";
922 if (!nb_delayed
) return;
924 output( "\n/* delayed import thunks */\n\n" );
925 output( "\t.text\n" );
926 output( "\t.align %d\n", get_alignment(8) );
927 output( "%s:\n", asm_name(delayed_import_loaders
));
928 output( "\t%s\n", func_declaration("__wine_delay_load_asm") );
929 output( "%s:\n", asm_name("__wine_delay_load_asm") );
930 output_cfi( ".cfi_startproc" );
934 output( "\tpushl %%ecx\n" );
935 output_cfi( ".cfi_adjust_cfa_offset 4" );
936 output( "\tpushl %%edx\n" );
937 output_cfi( ".cfi_adjust_cfa_offset 4" );
938 output( "\tpushl %%eax\n" );
939 output_cfi( ".cfi_adjust_cfa_offset 4" );
940 output( "\tcall %s\n", asm_name("__wine_spec_delay_load") );
941 output_cfi( ".cfi_adjust_cfa_offset -4" );
942 output( "\tpopl %%edx\n" );
943 output_cfi( ".cfi_adjust_cfa_offset -4" );
944 output( "\tpopl %%ecx\n" );
945 output_cfi( ".cfi_adjust_cfa_offset -4" );
946 output( "\tjmp *%%eax\n" );
949 output( "\tsubq $88,%%rsp\n" );
950 output_cfi( ".cfi_adjust_cfa_offset 88" );
951 output( "\tmovq %%rdx,80(%%rsp)\n" );
952 output( "\tmovq %%rcx,72(%%rsp)\n" );
953 output( "\tmovq %%r8,64(%%rsp)\n" );
954 output( "\tmovq %%r9,56(%%rsp)\n" );
955 output( "\tmovq %%r10,48(%%rsp)\n" );
956 output( "\tmovq %%r11,40(%%rsp)\n" );
957 output( "\tmovq %%rax,%%rcx\n" );
958 output( "\tcall %s\n", asm_name("__wine_spec_delay_load") );
959 output( "\tmovq 40(%%rsp),%%r11\n" );
960 output( "\tmovq 48(%%rsp),%%r10\n" );
961 output( "\tmovq 56(%%rsp),%%r9\n" );
962 output( "\tmovq 64(%%rsp),%%r8\n" );
963 output( "\tmovq 72(%%rsp),%%rcx\n" );
964 output( "\tmovq 80(%%rsp),%%rdx\n" );
965 output( "\taddq $88,%%rsp\n" );
966 output_cfi( ".cfi_adjust_cfa_offset -88" );
967 output( "\tjmp *%%rax\n" );
970 output( "\tpush {r0-r3,FP,LR}\n" );
971 output( "\tmov r0,IP\n" );
972 output( "\tldr IP,2f\n");
973 output( "\tadd IP,PC\n");
974 output( "\tblx IP\n");
975 output( "1:\tmov IP,r0\n");
976 output( "\tpop {r0-r3,FP,LR}\n" );
977 output( "\tbx IP\n");
978 output( "2:\t.long %s-1b\n", asm_name("__wine_spec_delay_load") );
981 output( "\tstp x29, x30, [sp,#-16]!\n" );
982 output( "\tmov x29, sp\n" );
983 output( "\tadr x9, 1f\n" );
984 output( "\tldur x9, [x9, #0]\n" );
985 output( "\tblr x9\n" );
986 output( "\tmov x9, x0\n" );
987 output( "\tldp x29, x30, [sp],#16\n" );
988 output( "\tldp x0, x1, [sp,#16]\n" );
989 output( "\tldp x2, x3, [sp,#32]\n" );
990 output( "\tldp x4, x5, [sp,#48]\n" );
991 output( "\tldp x6, x7, [sp],#80\n" );
992 output( "\tbr x9\n" ); /* or "ret x9" */
993 output( "1:\t.quad %s\n", asm_name("__wine_spec_delay_load") );
996 if (target_platform
== PLATFORM_APPLE
) extra_stack_storage
= 56;
998 /* Save all callee saved registers into a stackframe. */
999 output( "\tstwu %s, -%d(%s)\n",ppc_reg(1), 48+extra_stack_storage
, ppc_reg(1));
1000 output( "\tstw %s, %d(%s)\n", ppc_reg(3), 4+extra_stack_storage
, ppc_reg(1));
1001 output( "\tstw %s, %d(%s)\n", ppc_reg(4), 8+extra_stack_storage
, ppc_reg(1));
1002 output( "\tstw %s, %d(%s)\n", ppc_reg(5), 12+extra_stack_storage
, ppc_reg(1));
1003 output( "\tstw %s, %d(%s)\n", ppc_reg(6), 16+extra_stack_storage
, ppc_reg(1));
1004 output( "\tstw %s, %d(%s)\n", ppc_reg(7), 20+extra_stack_storage
, ppc_reg(1));
1005 output( "\tstw %s, %d(%s)\n", ppc_reg(8), 24+extra_stack_storage
, ppc_reg(1));
1006 output( "\tstw %s, %d(%s)\n", ppc_reg(9), 28+extra_stack_storage
, ppc_reg(1));
1007 output( "\tstw %s, %d(%s)\n", ppc_reg(10),32+extra_stack_storage
, ppc_reg(1));
1008 output( "\tstw %s, %d(%s)\n", ppc_reg(11),36+extra_stack_storage
, ppc_reg(1));
1009 output( "\tstw %s, %d(%s)\n", ppc_reg(12),40+extra_stack_storage
, ppc_reg(1));
1011 /* r0 -> r3 (arg1) */
1012 output( "\tmr %s, %s\n", ppc_reg(3), ppc_reg(0));
1014 /* save return address */
1015 output( "\tmflr %s\n", ppc_reg(0));
1016 output( "\tstw %s, %d(%s)\n", ppc_reg(0), 44+extra_stack_storage
, ppc_reg(1));
1018 /* Call the __wine_delay_load function, arg1 is arg1. */
1019 output( "\tbl %s\n", asm_name("__wine_spec_delay_load") );
1021 /* Load return value from call into ctr register */
1022 output( "\tmtctr %s\n", ppc_reg(3));
1024 /* restore all saved registers and drop stackframe. */
1025 output( "\tlwz %s, %d(%s)\n", ppc_reg(3), 4+extra_stack_storage
, ppc_reg(1));
1026 output( "\tlwz %s, %d(%s)\n", ppc_reg(4), 8+extra_stack_storage
, ppc_reg(1));
1027 output( "\tlwz %s, %d(%s)\n", ppc_reg(5), 12+extra_stack_storage
, ppc_reg(1));
1028 output( "\tlwz %s, %d(%s)\n", ppc_reg(6), 16+extra_stack_storage
, ppc_reg(1));
1029 output( "\tlwz %s, %d(%s)\n", ppc_reg(7), 20+extra_stack_storage
, ppc_reg(1));
1030 output( "\tlwz %s, %d(%s)\n", ppc_reg(8), 24+extra_stack_storage
, ppc_reg(1));
1031 output( "\tlwz %s, %d(%s)\n", ppc_reg(9), 28+extra_stack_storage
, ppc_reg(1));
1032 output( "\tlwz %s, %d(%s)\n", ppc_reg(10),32+extra_stack_storage
, ppc_reg(1));
1033 output( "\tlwz %s, %d(%s)\n", ppc_reg(11),36+extra_stack_storage
, ppc_reg(1));
1034 output( "\tlwz %s, %d(%s)\n", ppc_reg(12),40+extra_stack_storage
, ppc_reg(1));
1036 /* Load return value from call into return register */
1037 output( "\tlwz %s, %d(%s)\n", ppc_reg(0), 44+extra_stack_storage
, ppc_reg(1));
1038 output( "\tmtlr %s\n", ppc_reg(0));
1039 output( "\taddi %s, %s, %d\n", ppc_reg(1), ppc_reg(1), 48+extra_stack_storage
);
1041 /* branch to ctr register. */
1042 output( "\tbctr\n");
1045 output_cfi( ".cfi_endproc" );
1046 output_function_size( "__wine_delay_load_asm" );
1049 for (i
= idx
= 0; i
< nb_imports
; i
++)
1051 if (!dll_imports
[i
]->delay
) continue;
1052 for (j
= 0; j
< dll_imports
[i
]->nb_imports
; j
++)
1054 ORDDEF
*odp
= dll_imports
[i
]->imports
[j
];
1055 const char *name
= odp
->name
? odp
->name
: odp
->export_name
;
1057 output( ".L__wine_delay_imp_%d_%s:\n", i
, name
);
1058 output_cfi( ".cfi_startproc" );
1062 output( "\tmovl $%d, %%eax\n", (idx
<< 16) | j
);
1063 output( "\tjmp %s\n", asm_name("__wine_delay_load_asm") );
1066 output( "\tmovq $%d,%%rax\n", (idx
<< 16) | j
);
1067 output( "\tjmp %s\n", asm_name("__wine_delay_load_asm") );
1071 unsigned int mask
, count
= 0, val
= (idx
<< 16) | j
;
1073 for (mask
= 0xff; mask
; mask
<<= 8)
1074 if (val
& mask
) output( "\t%s IP,#%u\n", count
++ ? "add" : "mov", val
& mask
);
1075 if (!count
) output( "\tmov IP,#0\n" );
1076 output( "\tb %s\n", asm_name("__wine_delay_load_asm") );
1080 output( "\tstp x6, x7, [sp,#-80]!\n" );
1081 output( "\tstp x4, x5, [sp,#48]\n" );
1082 output( "\tstp x2, x3, [sp,#32]\n" );
1083 output( "\tstp x0, x1, [sp,#16]\n" );
1084 output( "\tmov x0, #%d\n", idx
);
1085 output( "\tmov x1, #16384\n" );
1086 output( "\tmul x1, x0, x1\n" );
1087 output( "\tmov x0, x1\n" );
1088 output( "\tmov x1, #4\n" );
1089 output( "\tmul x1, x0, x1\n" );
1090 output( "\tmov x0, x1\n" );
1091 output( "\tadd x0, x0, #%d\n", j
);
1092 output( "\tadr x9, 1f\n" );
1093 output( "\tldur x9, [x9, #0]\n" );
1094 output( "\tbr x9\n" );
1095 output( "1:\t.quad %s\n", asm_name("__wine_delay_load_asm") );
1098 switch(target_platform
)
1100 case PLATFORM_APPLE
:
1101 /* On Darwin we can use r0 and r2 */
1102 /* Upper part in r2 */
1103 output( "\tlis %s, %d\n", ppc_reg(2), idx
);
1104 /* Lower part + r2 -> r0, Note we can't use r0 directly */
1105 output( "\taddi %s, %s, %d\n", ppc_reg(0), ppc_reg(2), j
);
1106 output( "\tb %s\n", asm_name("__wine_delay_load_asm") );
1109 /* On linux we can't use r2 since r2 is not a scratch register (hold the TOC) */
1110 /* Save r13 on the stack */
1111 output( "\taddi %s, %s, -0x4\n", ppc_reg(1), ppc_reg(1));
1112 output( "\tstw %s, 0(%s)\n", ppc_reg(13), ppc_reg(1));
1113 /* Upper part in r13 */
1114 output( "\tlis %s, %d\n", ppc_reg(13), idx
);
1115 /* Lower part + r13 -> r0, Note we can't use r0 directly */
1116 output( "\taddi %s, %s, %d\n", ppc_reg(0), ppc_reg(13), j
);
1118 output( "\tstw %s, 0(%s)\n", ppc_reg(13), ppc_reg(1));
1119 output( "\taddic %s, %s, 0x4\n", ppc_reg(1), ppc_reg(1));
1120 output( "\tb %s\n", asm_name("__wine_delay_load_asm") );
1125 output_cfi( ".cfi_endproc" );
1129 output_function_size( delayed_import_loaders
);
1131 output( "\n\t.align %d\n", get_alignment(get_ptr_size()) );
1132 output( "%s:\n", asm_name(delayed_import_thunks
));
1133 for (i
= pos
= 0; i
< nb_imports
; i
++)
1135 if (!dll_imports
[i
]->delay
) continue;
1136 for (j
= 0; j
< dll_imports
[i
]->nb_imports
; j
++, pos
+= get_ptr_size())
1138 ORDDEF
*odp
= dll_imports
[i
]->imports
[j
];
1139 output_import_thunk( odp
->name
? odp
->name
: odp
->export_name
,
1140 ".L__wine_delay_IAT", pos
);
1143 output_function_size( delayed_import_thunks
);
1146 /* output import stubs for exported entry points that link to external symbols */
1147 static void output_external_link_imports( DLLSPEC
*spec
)
1149 unsigned int i
, pos
;
1151 if (!ext_link_imports
.count
) return; /* nothing to do */
1153 sort_names( &ext_link_imports
);
1155 /* get rid of duplicate names */
1156 for (i
= 1; i
< ext_link_imports
.count
; i
++)
1158 if (!strcmp( ext_link_imports
.names
[i
-1], ext_link_imports
.names
[i
] ))
1159 remove_name( &ext_link_imports
, i
-- );
1162 output( "\n/* external link thunks */\n\n" );
1163 output( "\t.data\n" );
1164 output( "\t.align %d\n", get_alignment(get_ptr_size()) );
1165 output( ".L__wine_spec_external_links:\n" );
1166 for (i
= 0; i
< ext_link_imports
.count
; i
++)
1167 output( "\t%s %s\n", get_asm_ptr_keyword(), asm_name(ext_link_imports
.names
[i
]) );
1169 output( "\n\t.text\n" );
1170 output( "\t.align %d\n", get_alignment(get_ptr_size()) );
1171 output( "%s:\n", asm_name("__wine_spec_external_link_thunks") );
1173 for (i
= pos
= 0; i
< ext_link_imports
.count
; i
++)
1175 char *buffer
= strmake( "__wine_spec_ext_link_%s", ext_link_imports
.names
[i
] );
1176 output_import_thunk( buffer
, ".L__wine_spec_external_links", pos
);
1178 pos
+= get_ptr_size();
1180 output_function_size( "__wine_spec_external_link_thunks" );
1183 /*******************************************************************
1186 * Output the functions for stub entry points
1188 void output_stubs( DLLSPEC
*spec
)
1190 const char *name
, *exp_name
;
1193 if (!has_stubs( spec
)) return;
1195 output( "\n/* stub functions */\n\n" );
1196 output( "\t.text\n" );
1198 for (i
= count
= 0; i
< spec
->nb_entry_points
; i
++)
1200 ORDDEF
*odp
= &spec
->entry_points
[i
];
1201 if (odp
->type
!= TYPE_STUB
) continue;
1203 name
= get_stub_name( odp
, spec
);
1204 exp_name
= odp
->name
? odp
->name
: odp
->export_name
;
1205 output( "\t.align %d\n", get_alignment(4) );
1206 output( "\t%s\n", func_declaration(name
) );
1207 output( "%s:\n", asm_name(name
) );
1208 output_cfi( ".cfi_startproc" );
1213 /* flesh out the stub a bit to make safedisc happy */
1214 output(" \tnop\n" );
1215 output(" \tnop\n" );
1216 output(" \tnop\n" );
1217 output(" \tnop\n" );
1218 output(" \tnop\n" );
1219 output(" \tnop\n" );
1220 output(" \tnop\n" );
1221 output(" \tnop\n" );
1222 output(" \tnop\n" );
1224 output( "\tsubl $12,%%esp\n" );
1225 output_cfi( ".cfi_adjust_cfa_offset 12" );
1228 output( "\tcall %s\n", asm_name("__wine_spec_get_pc_thunk_eax") );
1232 output( "\tleal .L%s_string-1b(%%eax),%%ecx\n", name
);
1233 output( "\tmovl %%ecx,4(%%esp)\n" );
1237 output( "\tmovl $%d,4(%%esp)\n", odp
->ordinal
);
1238 output( "\tleal .L__wine_spec_file_name-1b(%%eax),%%ecx\n" );
1239 output( "\tmovl %%ecx,(%%esp)\n" );
1245 output( "\tmovl $.L%s_string,4(%%esp)\n", name
);
1249 output( "\tmovl $%d,4(%%esp)\n", odp
->ordinal
);
1250 output( "\tmovl $.L__wine_spec_file_name,(%%esp)\n" );
1252 output( "\tcall %s\n", asm_name("__wine_spec_unimplemented_stub") );
1255 output( "\tsubq $8,%%rsp\n" );
1256 output_cfi( ".cfi_adjust_cfa_offset 8" );
1257 output( "\tleaq .L__wine_spec_file_name(%%rip),%%rdi\n" );
1260 output( "leaq .L%s_string(%%rip),%%rsi\n", name
);
1264 output( "\tmovq $%d,%%rsi\n", odp
->ordinal
);
1265 output( "\tcall %s\n", asm_name("__wine_spec_unimplemented_stub") );
1268 output( "\tldr r0,2f\n");
1269 output( "\tadd r0,PC\n");
1270 output( "\tldr r1,2f+4\n");
1274 output( "\tadd r1,PC\n");
1277 output( "\tbl %s\n", asm_name("__wine_spec_unimplemented_stub") );
1278 output( "2:\t.long .L__wine_spec_file_name-1b\n" );
1279 if (exp_name
) output( "\t.long .L%s_string-2b\n", name
);
1280 else output( "\t.long %u\n", odp
->ordinal
);
1285 output_cfi( ".cfi_endproc" );
1286 output_function_size( name
);
1291 output( "\t%s\n", get_asm_string_section() );
1292 for (i
= 0; i
< spec
->nb_entry_points
; i
++)
1294 ORDDEF
*odp
= &spec
->entry_points
[i
];
1295 if (odp
->type
!= TYPE_STUB
) continue;
1296 exp_name
= odp
->name
? odp
->name
: odp
->export_name
;
1299 name
= get_stub_name( odp
, spec
);
1300 output( ".L%s_string:\n", name
);
1301 output( "\t%s \"%s\"\n", get_asm_string_keyword(), exp_name
);
1307 /* output the import and delayed import tables of a Win32 module */
1308 void output_imports( DLLSPEC
*spec
)
1310 output_immediate_imports();
1311 output_delayed_imports( spec
);
1312 output_immediate_import_thunks();
1313 output_delayed_import_thunks( spec
);
1314 output_external_link_imports( spec
);
1315 if (nb_imports
|| ext_link_imports
.count
|| has_stubs(spec
) || has_relays(spec
))
1316 output_get_pc_thunk();
1319 /* output an import library for a Win32 module and additional object files */
1320 void output_import_lib( DLLSPEC
*spec
, char **argv
)
1322 struct strarray
*args
;
1325 if (target_platform
!= PLATFORM_WINDOWS
)
1326 fatal_error( "Unix-style import libraries not supported yet\n" );
1328 def_file
= get_temp_file_name( output_file_name
, ".def" );
1329 fclose( output_file
);
1330 if (!(output_file
= fopen( def_file
, "w" )))
1331 fatal_error( "Unable to create output file '%s'\n", def_file
);
1332 output_def_file( spec
, 0 );
1333 fclose( output_file
);
1336 args
= find_tool( "dlltool", NULL
);
1337 strarray_add( args
, "-k", "-l", output_file_name
, "-d", def_file
, NULL
);
1339 strarray_free( args
);
1343 args
= find_tool( "ar", NULL
);
1344 strarray_add( args
, "rs", output_file_name
, NULL
);
1345 strarray_addv( args
, argv
);
1347 strarray_free( args
);
1349 output_file_name
= NULL
;