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 /* locate a name in a (sorted) list */
119 static inline const char *find_name( const char *name
, const struct name_table
*table
)
123 if (table
->count
) res
= bsearch( &name
, table
->names
, table
->count
, sizeof(*table
->names
), name_cmp
);
124 return res
? *res
: NULL
;
127 /* sort a name table */
128 static inline void sort_names( struct name_table
*table
)
130 if (table
->count
) qsort( table
->names
, table
->count
, sizeof(*table
->names
), name_cmp
);
133 /* locate an export in a (sorted) export list */
134 static inline ORDDEF
*find_export( const char *name
, ORDDEF
**table
, int size
)
136 ORDDEF func
, *odp
, **res
= NULL
;
138 func
.name
= xstrdup(name
);
141 if (table
) res
= bsearch( &odp
, table
, size
, sizeof(*table
), func_cmp
);
143 return res
? *res
: NULL
;
146 /* free an import structure */
147 static void free_imports( struct import
*imp
)
149 free( imp
->exports
);
150 free( imp
->imports
);
151 free_dll_spec( imp
->spec
);
152 free( imp
->full_name
);
156 /* check whether a given dll is imported in delayed mode */
157 static int is_delayed_import( const char *name
)
161 for (i
= 0; i
< delayed_imports
.count
; i
++)
163 if (!strcmp( delayed_imports
.names
[i
], name
)) return 1;
168 /* check whether a given dll has already been imported */
169 static struct import
*is_already_imported( const char *name
)
173 for (i
= 0; i
< nb_imports
; i
++)
175 if (!strcmp( dll_imports
[i
]->spec
->file_name
, name
)) return dll_imports
[i
];
180 /* open the .so library for a given dll in a specified path */
181 static char *try_library_path( const char *path
, const char *name
)
186 buffer
= strmake( "%s/lib%s.def", path
, name
);
188 /* check if the file exists */
189 if ((fd
= open( buffer
, O_RDONLY
)) != -1)
198 /* find the .def import library for a given dll */
199 static char *find_library( const char *name
)
204 for (i
= 0; i
< nb_lib_paths
; i
++)
206 if ((fullname
= try_library_path( lib_path
[i
], name
))) return fullname
;
208 fatal_error( "could not open .def file for %s\n", name
);
212 /* read in the list of exported symbols of an import library */
213 static int read_import_lib( struct import
*imp
)
218 struct import
*prev_imp
;
219 DLLSPEC
*spec
= imp
->spec
;
220 int delayed
= is_delayed_import( spec
->file_name
);
222 f
= open_input_file( NULL
, imp
->full_name
);
223 fstat( fileno(f
), &stat
);
224 imp
->dev
= stat
.st_dev
;
225 imp
->ino
= stat
.st_ino
;
226 ret
= parse_def_file( f
, spec
);
227 close_input_file( f
);
230 /* check if we already imported that library from a different file */
231 if ((prev_imp
= is_already_imported( spec
->file_name
)))
233 if (prev_imp
->dev
!= imp
->dev
|| prev_imp
->ino
!= imp
->ino
)
234 fatal_error( "%s and %s have the same export name '%s'\n",
235 prev_imp
->full_name
, imp
->full_name
, spec
->file_name
);
236 return 0; /* the same file was already loaded, ignore this one */
245 if (spec
->nb_entry_points
)
247 imp
->exports
= xmalloc( spec
->nb_entry_points
* sizeof(*imp
->exports
) );
248 for (i
= 0; i
< spec
->nb_entry_points
; i
++)
249 imp
->exports
[imp
->nb_exports
++] = &spec
->entry_points
[i
];
250 qsort( imp
->exports
, imp
->nb_exports
, sizeof(*imp
->exports
), func_cmp
);
255 /* build the dll exported name from the import lib name or path */
256 static char *get_dll_name( const char *name
, const char *filename
)
262 const char *basename
= strrchr( filename
, '/' );
263 if (!basename
) basename
= filename
;
265 if (!strncmp( basename
, "lib", 3 )) basename
+= 3;
266 ret
= xmalloc( strlen(basename
) + 5 );
267 strcpy( ret
, basename
);
268 if (strendswith( ret
, ".def" )) ret
[strlen(ret
)-4] = 0;
272 ret
= xmalloc( strlen(name
) + 5 );
275 if (!strchr( ret
, '.' )) strcat( ret
, ".dll" );
279 /* add a dll to the list of imports */
280 void add_import_dll( const char *name
, const char *filename
)
282 struct import
*imp
= xmalloc( sizeof(*imp
) );
284 imp
->spec
= alloc_dll_spec();
285 imp
->spec
->file_name
= get_dll_name( name
, filename
);
292 if (filename
) imp
->full_name
= xstrdup( filename
);
293 else imp
->full_name
= find_library( name
);
295 if (read_import_lib( imp
))
297 dll_imports
= xrealloc( dll_imports
, (nb_imports
+1) * sizeof(*dll_imports
) );
298 dll_imports
[nb_imports
++] = imp
;
303 if (nb_errors
) exit(1);
307 /* add a library to the list of delayed imports */
308 void add_delayed_import( const char *name
)
311 char *fullname
= get_dll_name( name
, NULL
);
313 add_name( &delayed_imports
, fullname
);
314 if ((imp
= is_already_imported( fullname
)) && !imp
->delay
)
322 /* remove an imported dll, based on its index in the dll_imports array */
323 static void remove_import_dll( int index
)
325 struct import
*imp
= dll_imports
[index
];
327 memmove( &dll_imports
[index
], &dll_imports
[index
+1], sizeof(imp
) * (nb_imports
- index
- 1) );
329 if (imp
->delay
) nb_delayed
--;
333 /* add a symbol to the list of extra symbols that ld must resolve */
334 void add_extra_ld_symbol( const char *name
)
336 add_name( &extra_ld_symbols
, name
);
339 /* add a function to the list of imports from a given dll */
340 static void add_import_func( struct import
*imp
, ORDDEF
*func
)
342 imp
->imports
= xrealloc( imp
->imports
, (imp
->nb_imports
+1) * sizeof(*imp
->imports
) );
343 imp
->imports
[imp
->nb_imports
++] = func
;
345 if (imp
->delay
) total_delayed
++;
348 /* get the default entry point for a given spec file */
349 static const char *get_default_entry_point( const DLLSPEC
*spec
)
351 if (spec
->characteristics
& IMAGE_FILE_DLL
) return "__wine_spec_dll_entry";
352 if (spec
->subsystem
== IMAGE_SUBSYSTEM_NATIVE
) return "__wine_spec_drv_entry";
353 if (spec
->type
== SPEC_WIN16
) return "__wine_spec_exe16_entry";
354 return "__wine_spec_exe_entry";
357 /* check if the spec file exports any stubs */
358 static int has_stubs( const DLLSPEC
*spec
)
361 for (i
= 0; i
< spec
->nb_entry_points
; i
++)
363 ORDDEF
*odp
= &spec
->entry_points
[i
];
364 if (odp
->type
== TYPE_STUB
) return 1;
369 /* add the extra undefined symbols that will be contained in the generated spec file itself */
370 static void add_extra_undef_symbols( DLLSPEC
*spec
)
372 if (!spec
->init_func
) spec
->init_func
= xstrdup( get_default_entry_point(spec
) );
373 add_extra_ld_symbol( spec
->init_func
);
374 if (has_stubs( spec
)) add_extra_ld_symbol( "__wine_spec_unimplemented_stub" );
375 if (nb_delayed
) add_extra_ld_symbol( "__wine_spec_delay_load" );
378 /* check if a given imported dll is not needed, taking forwards into account */
379 static int check_unused( const struct import
* imp
, const DLLSPEC
*spec
)
382 const char *file_name
= imp
->spec
->file_name
;
383 size_t len
= strlen( file_name
);
384 const char *p
= strchr( file_name
, '.' );
385 if (p
&& !strcasecmp( p
, ".dll" )) len
= p
- file_name
;
387 for (i
= spec
->base
; i
<= spec
->limit
; i
++)
389 ORDDEF
*odp
= spec
->ordinals
[i
];
390 if (!odp
|| !(odp
->flags
& FLAG_FORWARD
)) continue;
391 if (!strncasecmp( odp
->link_name
, file_name
, len
) &&
392 odp
->link_name
[len
] == '.')
393 return 0; /* found a forward, it is used */
398 /* check if a given forward does exist in one of the imported dlls */
399 static void check_undefined_forwards( DLLSPEC
*spec
)
401 char *link_name
, *api_name
, *dll_name
, *p
;
404 for (i
= 0; i
< spec
->nb_entry_points
; i
++)
406 ORDDEF
*odp
= &spec
->entry_points
[i
];
408 if (!(odp
->flags
& FLAG_FORWARD
)) continue;
410 link_name
= xstrdup( odp
->link_name
);
411 p
= strrchr( link_name
, '.' );
414 dll_name
= get_dll_name( link_name
, NULL
);
416 for (j
= 0; j
< nb_imports
; j
++)
418 struct import
*imp
= dll_imports
[j
];
420 if (strcasecmp( imp
->spec
->file_name
, dll_name
)) continue;
421 if (!find_export( api_name
, imp
->exports
, imp
->nb_exports
))
422 warning( "%s:%d: forward '%s' not found in %s\n",
423 spec
->src_name
, odp
->lineno
, odp
->link_name
, imp
->spec
->file_name
);
427 warning( "%s:%d: forward '%s' not found in the imported dll list\n",
428 spec
->src_name
, odp
->lineno
, odp
->link_name
);
434 /* flag the dll exports that link to an undefined symbol */
435 static void check_undefined_exports( DLLSPEC
*spec
)
439 for (i
= 0; i
< spec
->nb_entry_points
; i
++)
441 ORDDEF
*odp
= &spec
->entry_points
[i
];
442 if (odp
->type
== TYPE_STUB
|| odp
->type
== TYPE_ABS
|| odp
->type
== TYPE_VARIABLE
) continue;
443 if (odp
->flags
& FLAG_FORWARD
) continue;
444 if (find_name( odp
->link_name
, &undef_symbols
))
453 if (link_ext_symbols
)
455 odp
->flags
|= FLAG_EXT_LINK
;
456 add_name( &ext_link_imports
, odp
->link_name
);
458 else error( "%s:%d: function '%s' not defined\n",
459 spec
->src_name
, odp
->lineno
, odp
->link_name
);
462 error( "%s:%d: external symbol '%s' is not a function\n",
463 spec
->src_name
, odp
->lineno
, odp
->link_name
);
470 /* create a .o file that references all the undefined symbols we want to resolve */
471 static char *create_undef_symbols_file( DLLSPEC
*spec
)
473 char *as_file
, *obj_file
;
478 as_file
= get_temp_file_name( output_file_name
, ".s" );
479 if (!(f
= fopen( as_file
, "w" ))) fatal_error( "Cannot create %s\n", as_file
);
480 fprintf( f
, "\t.data\n" );
482 for (i
= 0; i
< spec
->nb_entry_points
; i
++)
484 ORDDEF
*odp
= &spec
->entry_points
[i
];
485 if (odp
->type
== TYPE_STUB
|| odp
->type
== TYPE_ABS
|| odp
->type
== TYPE_VARIABLE
) continue;
486 if (odp
->flags
& FLAG_FORWARD
) continue;
487 fprintf( f
, "\t%s %s\n", get_asm_ptr_keyword(), asm_name(odp
->link_name
) );
489 for (j
= 0; j
< extra_ld_symbols
.count
; j
++)
490 fprintf( f
, "\t%s %s\n", get_asm_ptr_keyword(), asm_name(extra_ld_symbols
.names
[j
]) );
493 obj_file
= get_temp_file_name( output_file_name
, ".o" );
494 assemble_file( as_file
, obj_file
);
498 /* combine a list of object files with ld into a single object file */
499 /* returns the name of the combined file */
500 static const char *ldcombine_files( DLLSPEC
*spec
, char **argv
)
502 char *ld_tmp_file
, *undef_file
;
503 struct strarray
*args
= get_ld_command();
505 undef_file
= create_undef_symbols_file( spec
);
506 ld_tmp_file
= get_temp_file_name( output_file_name
, ".o" );
508 strarray_add( args
, "-r", "-o", ld_tmp_file
, undef_file
, NULL
);
509 strarray_addv( args
, argv
);
511 strarray_free( args
);
515 /* read in the list of undefined symbols */
516 void read_undef_symbols( DLLSPEC
*spec
, char **argv
)
520 const char *prog
= get_nm_command();
521 char *cmd
, buffer
[1024], name_prefix
[16];
525 if (!argv
[0]) return;
527 add_extra_undef_symbols( spec
);
529 strcpy( name_prefix
, asm_name("") );
530 prefix_len
= strlen( name_prefix
);
532 name
= ldcombine_files( spec
, argv
);
534 cmd
= strmake( "%s -u %s", prog
, name
);
535 if (!(f
= popen( cmd
, "r" )))
536 fatal_error( "Cannot execute '%s'\n", cmd
);
538 while (fgets( buffer
, sizeof(buffer
), f
))
540 char *p
= buffer
+ strlen(buffer
) - 1;
541 if (p
< buffer
) continue;
542 if (*p
== '\n') *p
-- = 0;
544 while (*p
== ' ') p
++;
545 if (p
[0] == 'U' && p
[1] == ' ' && p
[2]) p
+= 2;
546 if (prefix_len
&& !strncmp( p
, name_prefix
, prefix_len
)) p
+= prefix_len
;
547 add_name( &undef_symbols
, p
);
549 if ((err
= pclose( f
))) warning( "%s failed with status %d\n", cmd
, err
);
553 /* resolve the imports for a Win32 module */
554 void resolve_imports( DLLSPEC
*spec
)
557 unsigned int j
, removed
;
560 check_undefined_forwards( spec
);
562 for (i
= 0; i
< nb_imports
; i
++)
564 struct import
*imp
= dll_imports
[i
];
566 for (j
= removed
= 0; j
< undef_symbols
.count
; j
++)
568 odp
= find_export( undef_symbols
.names
[j
], imp
->exports
, imp
->nb_exports
);
571 if (odp
->flags
& FLAG_PRIVATE
) continue;
572 if (odp
->type
!= TYPE_STDCALL
&& odp
->type
!= TYPE_CDECL
)
573 warning( "winebuild: Data export '%s' cannot be imported from %s\n",
574 odp
->link_name
, imp
->spec
->file_name
);
577 add_import_func( imp
, odp
);
578 remove_name( &undef_symbols
, j
-- );
585 /* the dll is not used, get rid of it */
586 if (check_unused( imp
, spec
))
587 warning( "winebuild: %s imported but no symbols used\n", imp
->spec
->file_name
);
588 remove_import_dll( i
);
593 sort_names( &undef_symbols
);
594 check_undefined_exports( spec
);
597 /* check if symbol is still undefined */
598 int is_undefined( const char *name
)
600 return find_name( name
, &undef_symbols
) != NULL
;
603 /* output the get_pc thunk if needed */
604 void output_get_pc_thunk(void)
606 if (target_cpu
!= CPU_x86
) return;
608 output( "\n\t.text\n" );
609 output( "\t.align %d\n", get_alignment(4) );
610 output( "\t%s\n", func_declaration("__wine_spec_get_pc_thunk_eax") );
611 output( "%s:\n", asm_name("__wine_spec_get_pc_thunk_eax") );
612 output_cfi( ".cfi_startproc" );
613 output( "\tmovl (%%esp),%%eax\n" );
615 output_cfi( ".cfi_endproc" );
616 output_function_size( "__wine_spec_get_pc_thunk_eax" );
619 /* output a single import thunk */
620 static void output_import_thunk( const char *name
, const char *table
, int pos
)
622 output( "\n\t.align %d\n", get_alignment(4) );
623 output( "\t%s\n", func_declaration(name
) );
624 output( "%s\n", asm_globl(name
) );
625 output_cfi( ".cfi_startproc" );
632 output( "\tjmp *(%s+%d)\n", table
, pos
);
636 output( "\tcall %s\n", asm_name("__wine_spec_get_pc_thunk_eax") );
637 output( "1:\tjmp *%s+%d-1b(%%eax)\n", table
, pos
);
641 output( "\tjmpq *%s+%d(%%rip)\n", table
, pos
);
644 output( "\tldr IP,1f\n");
645 output( "\tldr PC,[PC,IP]\n" );
646 output( "1:\t.long %s+%u-(1b+4)\n", table
, pos
);
649 output( "\tadr x9, 1f\n" );
650 output( "\tldur x9, [x9, #0]\n" );
651 if (pos
& 0xf000) output( "\tadd x9, x9, #%u\n", pos
& 0xf000 );
652 if (pos
& 0x0f00) output( "\tadd x9, x9, #%u\n", pos
& 0x0f00 );
653 if (pos
& 0x00f0) output( "\tadd x9, x9, #%u\n", pos
& 0x00f0 );
654 if (pos
& 0x000f) output( "\tadd x9, x9, #%u\n", pos
& 0x000f );
655 output( "\tldur x9, [x9, #0]\n" );
656 output( "\tbr x9\n" );
657 output( "1:\t.quad %s\n", table
);
660 output( "\tmr %s, %s\n", ppc_reg(0), ppc_reg(31) );
661 if (target_platform
== PLATFORM_APPLE
)
663 output( "\tlis %s, ha16(%s+%d+32768)\n", ppc_reg(31), table
, pos
);
664 output( "\tla %s, lo16(%s+%d)(%s)\n", ppc_reg(31), table
, pos
, ppc_reg(31) );
668 output( "\tlis %s, (%s+%d+32768)@h\n", ppc_reg(31), table
, pos
);
669 output( "\tla %s, (%s+%d)@l(%s)\n", ppc_reg(31), table
, pos
, ppc_reg(31) );
671 output( "\tlwz %s, 0(%s)\n", ppc_reg(31), ppc_reg(31) );
672 output( "\tmtctr %s\n", ppc_reg(31) );
673 output( "\tmr %s, %s\n", ppc_reg(31), ppc_reg(0) );
674 output( "\tbctr\n" );
677 output_cfi( ".cfi_endproc" );
678 output_function_size( name
);
681 /* check if we need an import directory */
682 int has_imports(void)
684 return (nb_imports
- nb_delayed
) > 0;
687 /* output the import table of a Win32 module */
688 static void output_immediate_imports(void)
691 const char *dll_name
;
693 if (nb_imports
== nb_delayed
) return; /* no immediate imports */
695 /* main import header */
697 output( "\n/* import table */\n" );
698 output( "\n\t.data\n" );
699 output( "\t.align %d\n", get_alignment(4) );
700 output( ".L__wine_spec_imports:\n" );
704 for (i
= j
= 0; i
< nb_imports
; i
++)
706 if (dll_imports
[i
]->delay
) continue;
707 dll_name
= make_c_identifier( dll_imports
[i
]->spec
->file_name
);
708 output( "\t.long .L__wine_spec_import_data_names+%d-.L__wine_spec_rva_base\n", /* OriginalFirstThunk */
709 j
* get_ptr_size() );
710 output( "\t.long 0\n" ); /* TimeDateStamp */
711 output( "\t.long 0\n" ); /* ForwarderChain */
712 output( "\t.long .L__wine_spec_import_name_%s-.L__wine_spec_rva_base\n", /* Name */
714 output( "\t.long .L__wine_spec_import_data_ptrs+%d-.L__wine_spec_rva_base\n", /* FirstThunk */
715 j
* get_ptr_size() );
716 j
+= dll_imports
[i
]->nb_imports
+ 1;
718 output( "\t.long 0\n" ); /* OriginalFirstThunk */
719 output( "\t.long 0\n" ); /* TimeDateStamp */
720 output( "\t.long 0\n" ); /* ForwarderChain */
721 output( "\t.long 0\n" ); /* Name */
722 output( "\t.long 0\n" ); /* FirstThunk */
724 output( "\n\t.align %d\n", get_alignment(get_ptr_size()) );
725 output( ".L__wine_spec_import_data_names:\n" );
726 for (i
= 0; i
< nb_imports
; i
++)
728 if (dll_imports
[i
]->delay
) continue;
729 dll_name
= make_c_identifier( dll_imports
[i
]->spec
->file_name
);
730 for (j
= 0; j
< dll_imports
[i
]->nb_imports
; j
++)
732 ORDDEF
*odp
= dll_imports
[i
]->imports
[j
];
733 if (!(odp
->flags
& FLAG_NONAME
))
734 output( "\t%s .L__wine_spec_import_data_%s_%s-.L__wine_spec_rva_base\n",
735 get_asm_ptr_keyword(), dll_name
, odp
->name
);
738 if (get_ptr_size() == 8)
739 output( "\t.quad 0x800000000000%04x\n", odp
->ordinal
);
741 output( "\t.long 0x8000%04x\n", odp
->ordinal
);
744 output( "\t%s 0\n", get_asm_ptr_keyword() );
746 output( ".L__wine_spec_import_data_ptrs:\n" );
747 for (i
= 0; i
< nb_imports
; i
++)
749 if (dll_imports
[i
]->delay
) continue;
750 for (j
= 0; j
< dll_imports
[i
]->nb_imports
; j
++) output( "\t%s 0\n", get_asm_ptr_keyword() );
751 output( "\t%s 0\n", get_asm_ptr_keyword() );
753 output( ".L__wine_spec_imports_end:\n" );
755 for (i
= 0; i
< nb_imports
; i
++)
757 if (dll_imports
[i
]->delay
) continue;
758 dll_name
= make_c_identifier( dll_imports
[i
]->spec
->file_name
);
759 for (j
= 0; j
< dll_imports
[i
]->nb_imports
; j
++)
761 ORDDEF
*odp
= dll_imports
[i
]->imports
[j
];
762 if (!(odp
->flags
& FLAG_NONAME
))
764 output( "\t.align %d\n", get_alignment(2) );
765 output( ".L__wine_spec_import_data_%s_%s:\n", dll_name
, odp
->name
);
766 output( "\t.short %d\n", odp
->ordinal
);
767 output( "\t%s \"%s\"\n", get_asm_string_keyword(), odp
->name
);
772 for (i
= 0; i
< nb_imports
; i
++)
774 if (dll_imports
[i
]->delay
) continue;
775 dll_name
= make_c_identifier( dll_imports
[i
]->spec
->file_name
);
776 output( ".L__wine_spec_import_name_%s:\n\t%s \"%s\"\n",
777 dll_name
, get_asm_string_keyword(), dll_imports
[i
]->spec
->file_name
);
781 /* output the import thunks of a Win32 module */
782 static void output_immediate_import_thunks(void)
785 int nb_imm
= nb_imports
- nb_delayed
;
786 static const char import_thunks
[] = "__wine_spec_import_thunks";
790 output( "\n/* immediate import thunks */\n\n" );
791 output( "\t.text\n" );
792 output( "\t.align %d\n", get_alignment(8) );
793 output( "%s:\n", asm_name(import_thunks
));
795 for (i
= pos
= 0; i
< nb_imports
; i
++)
797 if (dll_imports
[i
]->delay
) continue;
798 for (j
= 0; j
< dll_imports
[i
]->nb_imports
; j
++, pos
+= get_ptr_size())
800 ORDDEF
*odp
= dll_imports
[i
]->imports
[j
];
801 output_import_thunk( odp
->name
? odp
->name
: odp
->export_name
,
802 ".L__wine_spec_import_data_ptrs", pos
);
804 pos
+= get_ptr_size();
806 output_function_size( import_thunks
);
809 /* output the delayed import table of a Win32 module */
810 static void output_delayed_imports( const DLLSPEC
*spec
)
814 if (!nb_delayed
) return;
816 output( "\n/* delayed imports */\n\n" );
817 output( "\t.data\n" );
818 output( "\t.align %d\n", get_alignment(get_ptr_size()) );
819 output( "%s\n", asm_globl("__wine_spec_delay_imports") );
823 for (i
= j
= mod
= 0; i
< nb_imports
; i
++)
825 if (!dll_imports
[i
]->delay
) continue;
826 output( "\t%s 0\n", get_asm_ptr_keyword() ); /* grAttrs */
827 output( "\t%s .L__wine_delay_name_%d\n", /* szName */
828 get_asm_ptr_keyword(), i
);
829 output( "\t%s .L__wine_delay_modules+%d\n", /* phmod */
830 get_asm_ptr_keyword(), mod
* get_ptr_size() );
831 output( "\t%s .L__wine_delay_IAT+%d\n", /* pIAT */
832 get_asm_ptr_keyword(), j
* get_ptr_size() );
833 output( "\t%s .L__wine_delay_INT+%d\n", /* pINT */
834 get_asm_ptr_keyword(), j
* get_ptr_size() );
835 output( "\t%s 0\n", get_asm_ptr_keyword() ); /* pBoundIAT */
836 output( "\t%s 0\n", get_asm_ptr_keyword() ); /* pUnloadIAT */
837 output( "\t%s 0\n", get_asm_ptr_keyword() ); /* dwTimeStamp */
838 j
+= dll_imports
[i
]->nb_imports
;
841 output( "\t%s 0\n", get_asm_ptr_keyword() ); /* grAttrs */
842 output( "\t%s 0\n", get_asm_ptr_keyword() ); /* szName */
843 output( "\t%s 0\n", get_asm_ptr_keyword() ); /* phmod */
844 output( "\t%s 0\n", get_asm_ptr_keyword() ); /* pIAT */
845 output( "\t%s 0\n", get_asm_ptr_keyword() ); /* pINT */
846 output( "\t%s 0\n", get_asm_ptr_keyword() ); /* pBoundIAT */
847 output( "\t%s 0\n", get_asm_ptr_keyword() ); /* pUnloadIAT */
848 output( "\t%s 0\n", get_asm_ptr_keyword() ); /* dwTimeStamp */
850 output( "\n.L__wine_delay_IAT:\n" );
851 for (i
= 0; i
< nb_imports
; i
++)
853 if (!dll_imports
[i
]->delay
) continue;
854 for (j
= 0; j
< dll_imports
[i
]->nb_imports
; j
++)
856 ORDDEF
*odp
= dll_imports
[i
]->imports
[j
];
857 const char *name
= odp
->name
? odp
->name
: odp
->export_name
;
858 output( "\t%s .L__wine_delay_imp_%d_%s\n",
859 get_asm_ptr_keyword(), i
, name
);
863 output( "\n.L__wine_delay_INT:\n" );
864 for (i
= 0; i
< nb_imports
; i
++)
866 if (!dll_imports
[i
]->delay
) continue;
867 for (j
= 0; j
< dll_imports
[i
]->nb_imports
; j
++)
869 ORDDEF
*odp
= dll_imports
[i
]->imports
[j
];
871 output( "\t%s %d\n", get_asm_ptr_keyword(), odp
->ordinal
);
873 output( "\t%s .L__wine_delay_data_%d_%s\n",
874 get_asm_ptr_keyword(), i
, odp
->name
);
878 output( "\n.L__wine_delay_modules:\n" );
879 for (i
= 0; i
< nb_imports
; i
++)
881 if (dll_imports
[i
]->delay
) output( "\t%s 0\n", get_asm_ptr_keyword() );
884 for (i
= 0; i
< nb_imports
; i
++)
886 if (!dll_imports
[i
]->delay
) continue;
887 output( ".L__wine_delay_name_%d:\n", i
);
888 output( "\t%s \"%s\"\n",
889 get_asm_string_keyword(), dll_imports
[i
]->spec
->file_name
);
892 for (i
= 0; i
< nb_imports
; i
++)
894 if (!dll_imports
[i
]->delay
) continue;
895 for (j
= 0; j
< dll_imports
[i
]->nb_imports
; j
++)
897 ORDDEF
*odp
= dll_imports
[i
]->imports
[j
];
898 if (!odp
->name
) continue;
899 output( ".L__wine_delay_data_%d_%s:\n", i
, odp
->name
);
900 output( "\t%s \"%s\"\n", get_asm_string_keyword(), odp
->name
);
903 output_function_size( "__wine_spec_delay_imports" );
906 /* output the delayed import thunks of a Win32 module */
907 static void output_delayed_import_thunks( const DLLSPEC
*spec
)
909 int i
, idx
, j
, pos
, extra_stack_storage
= 0;
910 static const char delayed_import_loaders
[] = "__wine_spec_delayed_import_loaders";
911 static const char delayed_import_thunks
[] = "__wine_spec_delayed_import_thunks";
913 if (!nb_delayed
) return;
915 output( "\n/* delayed import thunks */\n\n" );
916 output( "\t.text\n" );
917 output( "\t.align %d\n", get_alignment(8) );
918 output( "%s:\n", asm_name(delayed_import_loaders
));
919 output( "\t%s\n", func_declaration("__wine_delay_load_asm") );
920 output( "%s:\n", asm_name("__wine_delay_load_asm") );
921 output_cfi( ".cfi_startproc" );
925 output( "\tpushl %%ecx\n" );
926 output_cfi( ".cfi_adjust_cfa_offset 4" );
927 output( "\tpushl %%edx\n" );
928 output_cfi( ".cfi_adjust_cfa_offset 4" );
929 output( "\tpushl %%eax\n" );
930 output_cfi( ".cfi_adjust_cfa_offset 4" );
931 output( "\tcall %s\n", asm_name("__wine_spec_delay_load") );
932 output_cfi( ".cfi_adjust_cfa_offset -4" );
933 output( "\tpopl %%edx\n" );
934 output_cfi( ".cfi_adjust_cfa_offset -4" );
935 output( "\tpopl %%ecx\n" );
936 output_cfi( ".cfi_adjust_cfa_offset -4" );
937 output( "\tjmp *%%eax\n" );
940 output( "\tsubq $88,%%rsp\n" );
941 output_cfi( ".cfi_adjust_cfa_offset 88" );
942 output( "\tmovq %%rdx,80(%%rsp)\n" );
943 output( "\tmovq %%rcx,72(%%rsp)\n" );
944 output( "\tmovq %%r8,64(%%rsp)\n" );
945 output( "\tmovq %%r9,56(%%rsp)\n" );
946 output( "\tmovq %%r10,48(%%rsp)\n" );
947 output( "\tmovq %%r11,40(%%rsp)\n" );
948 output( "\tmovq %%rax,%%rcx\n" );
949 output( "\tcall %s\n", asm_name("__wine_spec_delay_load") );
950 output( "\tmovq 40(%%rsp),%%r11\n" );
951 output( "\tmovq 48(%%rsp),%%r10\n" );
952 output( "\tmovq 56(%%rsp),%%r9\n" );
953 output( "\tmovq 64(%%rsp),%%r8\n" );
954 output( "\tmovq 72(%%rsp),%%rcx\n" );
955 output( "\tmovq 80(%%rsp),%%rdx\n" );
956 output( "\taddq $88,%%rsp\n" );
957 output_cfi( ".cfi_adjust_cfa_offset -88" );
958 output( "\tjmp *%%rax\n" );
961 output( "\tpush {r0-r3,FP,LR}\n" );
962 output( "\tmov r0,IP\n" );
963 output( "\tldr IP,2f\n");
964 output( "\tadd IP,PC\n");
965 output( "\tblx IP\n");
966 output( "1:\tmov IP,r0\n");
967 output( "\tpop {r0-r3,FP,LR}\n" );
968 output( "\tbx IP\n");
969 output( "2:\t.long %s-1b\n", asm_name("__wine_spec_delay_load") );
972 output( "\tstp x29, x30, [sp,#-16]!\n" );
973 output( "\tmov x29, sp\n" );
974 output( "\tadr x9, 1f\n" );
975 output( "\tldur x9, [x9, #0]\n" );
976 output( "\tblr x9\n" );
977 output( "\tmov x9, x0\n" );
978 output( "\tldp x29, x30, [sp],#16\n" );
979 output( "\tldp x0, x1, [sp,#16]\n" );
980 output( "\tldp x2, x3, [sp,#32]\n" );
981 output( "\tldp x4, x5, [sp,#48]\n" );
982 output( "\tldp x6, x7, [sp],#80\n" );
983 output( "\tbr x9\n" ); /* or "ret x9" */
984 output( "1:\t.quad %s\n", asm_name("__wine_spec_delay_load") );
987 if (target_platform
== PLATFORM_APPLE
) extra_stack_storage
= 56;
989 /* Save all callee saved registers into a stackframe. */
990 output( "\tstwu %s, -%d(%s)\n",ppc_reg(1), 48+extra_stack_storage
, ppc_reg(1));
991 output( "\tstw %s, %d(%s)\n", ppc_reg(3), 4+extra_stack_storage
, ppc_reg(1));
992 output( "\tstw %s, %d(%s)\n", ppc_reg(4), 8+extra_stack_storage
, ppc_reg(1));
993 output( "\tstw %s, %d(%s)\n", ppc_reg(5), 12+extra_stack_storage
, ppc_reg(1));
994 output( "\tstw %s, %d(%s)\n", ppc_reg(6), 16+extra_stack_storage
, ppc_reg(1));
995 output( "\tstw %s, %d(%s)\n", ppc_reg(7), 20+extra_stack_storage
, ppc_reg(1));
996 output( "\tstw %s, %d(%s)\n", ppc_reg(8), 24+extra_stack_storage
, ppc_reg(1));
997 output( "\tstw %s, %d(%s)\n", ppc_reg(9), 28+extra_stack_storage
, ppc_reg(1));
998 output( "\tstw %s, %d(%s)\n", ppc_reg(10),32+extra_stack_storage
, ppc_reg(1));
999 output( "\tstw %s, %d(%s)\n", ppc_reg(11),36+extra_stack_storage
, ppc_reg(1));
1000 output( "\tstw %s, %d(%s)\n", ppc_reg(12),40+extra_stack_storage
, ppc_reg(1));
1002 /* r0 -> r3 (arg1) */
1003 output( "\tmr %s, %s\n", ppc_reg(3), ppc_reg(0));
1005 /* save return address */
1006 output( "\tmflr %s\n", ppc_reg(0));
1007 output( "\tstw %s, %d(%s)\n", ppc_reg(0), 44+extra_stack_storage
, ppc_reg(1));
1009 /* Call the __wine_delay_load function, arg1 is arg1. */
1010 output( "\tbl %s\n", asm_name("__wine_spec_delay_load") );
1012 /* Load return value from call into ctr register */
1013 output( "\tmtctr %s\n", ppc_reg(3));
1015 /* restore all saved registers and drop stackframe. */
1016 output( "\tlwz %s, %d(%s)\n", ppc_reg(3), 4+extra_stack_storage
, ppc_reg(1));
1017 output( "\tlwz %s, %d(%s)\n", ppc_reg(4), 8+extra_stack_storage
, ppc_reg(1));
1018 output( "\tlwz %s, %d(%s)\n", ppc_reg(5), 12+extra_stack_storage
, ppc_reg(1));
1019 output( "\tlwz %s, %d(%s)\n", ppc_reg(6), 16+extra_stack_storage
, ppc_reg(1));
1020 output( "\tlwz %s, %d(%s)\n", ppc_reg(7), 20+extra_stack_storage
, ppc_reg(1));
1021 output( "\tlwz %s, %d(%s)\n", ppc_reg(8), 24+extra_stack_storage
, ppc_reg(1));
1022 output( "\tlwz %s, %d(%s)\n", ppc_reg(9), 28+extra_stack_storage
, ppc_reg(1));
1023 output( "\tlwz %s, %d(%s)\n", ppc_reg(10),32+extra_stack_storage
, ppc_reg(1));
1024 output( "\tlwz %s, %d(%s)\n", ppc_reg(11),36+extra_stack_storage
, ppc_reg(1));
1025 output( "\tlwz %s, %d(%s)\n", ppc_reg(12),40+extra_stack_storage
, ppc_reg(1));
1027 /* Load return value from call into return register */
1028 output( "\tlwz %s, %d(%s)\n", ppc_reg(0), 44+extra_stack_storage
, ppc_reg(1));
1029 output( "\tmtlr %s\n", ppc_reg(0));
1030 output( "\taddi %s, %s, %d\n", ppc_reg(1), ppc_reg(1), 48+extra_stack_storage
);
1032 /* branch to ctr register. */
1033 output( "\tbctr\n");
1036 output_cfi( ".cfi_endproc" );
1037 output_function_size( "__wine_delay_load_asm" );
1040 for (i
= idx
= 0; i
< nb_imports
; i
++)
1042 if (!dll_imports
[i
]->delay
) continue;
1043 for (j
= 0; j
< dll_imports
[i
]->nb_imports
; j
++)
1045 ORDDEF
*odp
= dll_imports
[i
]->imports
[j
];
1046 const char *name
= odp
->name
? odp
->name
: odp
->export_name
;
1048 output( ".L__wine_delay_imp_%d_%s:\n", i
, name
);
1049 output_cfi( ".cfi_startproc" );
1053 output( "\tmovl $%d, %%eax\n", (idx
<< 16) | j
);
1054 output( "\tjmp %s\n", asm_name("__wine_delay_load_asm") );
1057 output( "\tmovq $%d,%%rax\n", (idx
<< 16) | j
);
1058 output( "\tjmp %s\n", asm_name("__wine_delay_load_asm") );
1062 unsigned int mask
, count
= 0, val
= (idx
<< 16) | j
;
1064 for (mask
= 0xff; mask
; mask
<<= 8)
1065 if (val
& mask
) output( "\t%s IP,#%u\n", count
++ ? "add" : "mov", val
& mask
);
1066 if (!count
) output( "\tmov IP,#0\n" );
1067 output( "\tb %s\n", asm_name("__wine_delay_load_asm") );
1071 output( "\tstp x6, x7, [sp,#-80]!\n" );
1072 output( "\tstp x4, x5, [sp,#48]\n" );
1073 output( "\tstp x2, x3, [sp,#32]\n" );
1074 output( "\tstp x0, x1, [sp,#16]\n" );
1075 output( "\tmov x0, #%d\n", idx
);
1076 output( "\tmov x1, #16384\n" );
1077 output( "\tmul x1, x0, x1\n" );
1078 output( "\tmov x0, x1\n" );
1079 output( "\tmov x1, #4\n" );
1080 output( "\tmul x1, x0, x1\n" );
1081 output( "\tmov x0, x1\n" );
1082 output( "\tadd x0, x0, #%d\n", j
);
1083 output( "\tadr x9, 1f\n" );
1084 output( "\tldur x9, [x9, #0]\n" );
1085 output( "\tbr x9\n" );
1086 output( "1:\t.quad %s\n", asm_name("__wine_delay_load_asm") );
1089 switch(target_platform
)
1091 case PLATFORM_APPLE
:
1092 /* On Darwin we can use r0 and r2 */
1093 /* Upper part in r2 */
1094 output( "\tlis %s, %d\n", ppc_reg(2), idx
);
1095 /* Lower part + r2 -> r0, Note we can't use r0 directly */
1096 output( "\taddi %s, %s, %d\n", ppc_reg(0), ppc_reg(2), j
);
1097 output( "\tb %s\n", asm_name("__wine_delay_load_asm") );
1100 /* On linux we can't use r2 since r2 is not a scratch register (hold the TOC) */
1101 /* Save r13 on the stack */
1102 output( "\taddi %s, %s, -0x4\n", ppc_reg(1), ppc_reg(1));
1103 output( "\tstw %s, 0(%s)\n", ppc_reg(13), ppc_reg(1));
1104 /* Upper part in r13 */
1105 output( "\tlis %s, %d\n", ppc_reg(13), idx
);
1106 /* Lower part + r13 -> r0, Note we can't use r0 directly */
1107 output( "\taddi %s, %s, %d\n", ppc_reg(0), ppc_reg(13), j
);
1109 output( "\tstw %s, 0(%s)\n", ppc_reg(13), ppc_reg(1));
1110 output( "\taddic %s, %s, 0x4\n", ppc_reg(1), ppc_reg(1));
1111 output( "\tb %s\n", asm_name("__wine_delay_load_asm") );
1116 output_cfi( ".cfi_endproc" );
1120 output_function_size( delayed_import_loaders
);
1122 output( "\n\t.align %d\n", get_alignment(get_ptr_size()) );
1123 output( "%s:\n", asm_name(delayed_import_thunks
));
1124 for (i
= pos
= 0; i
< nb_imports
; i
++)
1126 if (!dll_imports
[i
]->delay
) continue;
1127 for (j
= 0; j
< dll_imports
[i
]->nb_imports
; j
++, pos
+= get_ptr_size())
1129 ORDDEF
*odp
= dll_imports
[i
]->imports
[j
];
1130 output_import_thunk( odp
->name
? odp
->name
: odp
->export_name
,
1131 ".L__wine_delay_IAT", pos
);
1134 output_function_size( delayed_import_thunks
);
1137 /* output import stubs for exported entry points that link to external symbols */
1138 static void output_external_link_imports( DLLSPEC
*spec
)
1140 unsigned int i
, pos
;
1142 if (!ext_link_imports
.count
) return; /* nothing to do */
1144 sort_names( &ext_link_imports
);
1146 /* get rid of duplicate names */
1147 for (i
= 1; i
< ext_link_imports
.count
; i
++)
1149 if (!strcmp( ext_link_imports
.names
[i
-1], ext_link_imports
.names
[i
] ))
1150 remove_name( &ext_link_imports
, i
-- );
1153 output( "\n/* external link thunks */\n\n" );
1154 output( "\t.data\n" );
1155 output( "\t.align %d\n", get_alignment(get_ptr_size()) );
1156 output( ".L__wine_spec_external_links:\n" );
1157 for (i
= 0; i
< ext_link_imports
.count
; i
++)
1158 output( "\t%s %s\n", get_asm_ptr_keyword(), asm_name(ext_link_imports
.names
[i
]) );
1160 output( "\n\t.text\n" );
1161 output( "\t.align %d\n", get_alignment(get_ptr_size()) );
1162 output( "%s:\n", asm_name("__wine_spec_external_link_thunks") );
1164 for (i
= pos
= 0; i
< ext_link_imports
.count
; i
++)
1166 char *buffer
= strmake( "__wine_spec_ext_link_%s", ext_link_imports
.names
[i
] );
1167 output_import_thunk( buffer
, ".L__wine_spec_external_links", pos
);
1169 pos
+= get_ptr_size();
1171 output_function_size( "__wine_spec_external_link_thunks" );
1174 /*******************************************************************
1177 * Output the functions for stub entry points
1179 void output_stubs( DLLSPEC
*spec
)
1181 const char *name
, *exp_name
;
1184 if (!has_stubs( spec
)) return;
1186 output( "\n/* stub functions */\n\n" );
1187 output( "\t.text\n" );
1189 for (i
= count
= 0; i
< spec
->nb_entry_points
; i
++)
1191 ORDDEF
*odp
= &spec
->entry_points
[i
];
1192 if (odp
->type
!= TYPE_STUB
) continue;
1194 name
= get_stub_name( odp
, spec
);
1195 exp_name
= odp
->name
? odp
->name
: odp
->export_name
;
1196 output( "\t.align %d\n", get_alignment(4) );
1197 output( "\t%s\n", func_declaration(name
) );
1198 output( "%s:\n", asm_name(name
) );
1199 output_cfi( ".cfi_startproc" );
1204 /* flesh out the stub a bit to make safedisc happy */
1205 output(" \tnop\n" );
1206 output(" \tnop\n" );
1207 output(" \tnop\n" );
1208 output(" \tnop\n" );
1209 output(" \tnop\n" );
1210 output(" \tnop\n" );
1211 output(" \tnop\n" );
1212 output(" \tnop\n" );
1213 output(" \tnop\n" );
1215 output( "\tsubl $12,%%esp\n" );
1216 output_cfi( ".cfi_adjust_cfa_offset 12" );
1219 output( "\tcall %s\n", asm_name("__wine_spec_get_pc_thunk_eax") );
1223 output( "\tleal .L%s_string-1b(%%eax),%%ecx\n", name
);
1224 output( "\tmovl %%ecx,4(%%esp)\n" );
1228 output( "\tmovl $%d,4(%%esp)\n", odp
->ordinal
);
1229 output( "\tleal .L__wine_spec_file_name-1b(%%eax),%%ecx\n" );
1230 output( "\tmovl %%ecx,(%%esp)\n" );
1236 output( "\tmovl $.L%s_string,4(%%esp)\n", name
);
1240 output( "\tmovl $%d,4(%%esp)\n", odp
->ordinal
);
1241 output( "\tmovl $.L__wine_spec_file_name,(%%esp)\n" );
1243 output( "\tcall %s\n", asm_name("__wine_spec_unimplemented_stub") );
1246 output( "\tsubq $8,%%rsp\n" );
1247 output_cfi( ".cfi_adjust_cfa_offset 8" );
1248 output( "\tleaq .L__wine_spec_file_name(%%rip),%%rdi\n" );
1251 output( "leaq .L%s_string(%%rip),%%rsi\n", name
);
1255 output( "\tmovq $%d,%%rsi\n", odp
->ordinal
);
1256 output( "\tcall %s\n", asm_name("__wine_spec_unimplemented_stub") );
1259 output( "\tldr r0,2f\n");
1260 output( "\tadd r0,PC\n");
1261 output( "\tldr r1,2f+4\n");
1265 output( "\tadd r1,PC\n");
1268 output( "\tbl %s\n", asm_name("__wine_spec_unimplemented_stub") );
1269 output( "2:\t.long .L__wine_spec_file_name-1b\n" );
1270 if (exp_name
) output( "\t.long .L%s_string-2b\n", name
);
1271 else output( "\t.long %u\n", odp
->ordinal
);
1274 output( "\tadr x0, 2f\n" );
1275 output( "\tldur x0, [x0, #0]\n" );
1276 output( "\tadr x1, 2f+8\n" );
1277 output( "\tldur x1, [x1, #0]\n" );
1278 output( "\tadr x2, 1f\n" );
1279 output( "\tldur x2, [x2, #0]\n" );
1280 output( "\tblr x2\n" );
1281 output( "1:\t.quad %s\n", asm_name("__wine_spec_unimplemented_stub") );
1282 output( "2:\t.quad %s\n", asm_name("__wine_spec_file_name") );
1285 output( "\t.quad .L%s_string\n", name
);
1288 else output( "\t.quad %u\n", odp
->ordinal
);
1293 output_cfi( ".cfi_endproc" );
1294 output_function_size( name
);
1299 output( "\t%s\n", get_asm_string_section() );
1300 for (i
= 0; i
< spec
->nb_entry_points
; i
++)
1302 ORDDEF
*odp
= &spec
->entry_points
[i
];
1303 if (odp
->type
!= TYPE_STUB
) continue;
1304 exp_name
= odp
->name
? odp
->name
: odp
->export_name
;
1307 name
= get_stub_name( odp
, spec
);
1308 output( ".L%s_string:\n", name
);
1309 output( "\t%s \"%s\"\n", get_asm_string_keyword(), exp_name
);
1315 /* output the import and delayed import tables of a Win32 module */
1316 void output_imports( DLLSPEC
*spec
)
1318 output_immediate_imports();
1319 output_delayed_imports( spec
);
1320 output_immediate_import_thunks();
1321 output_delayed_import_thunks( spec
);
1322 output_external_link_imports( spec
);
1323 if (nb_imports
|| ext_link_imports
.count
|| has_stubs(spec
) || has_relays(spec
))
1324 output_get_pc_thunk();
1327 /* output an import library for a Win32 module and additional object files */
1328 void output_import_lib( DLLSPEC
*spec
, char **argv
)
1330 struct strarray
*args
;
1333 if (target_platform
!= PLATFORM_WINDOWS
)
1334 fatal_error( "Unix-style import libraries not supported yet\n" );
1336 def_file
= get_temp_file_name( output_file_name
, ".def" );
1337 fclose( output_file
);
1338 if (!(output_file
= fopen( def_file
, "w" )))
1339 fatal_error( "Unable to create output file '%s'\n", def_file
);
1340 output_def_file( spec
, 0 );
1341 fclose( output_file
);
1344 args
= find_tool( "dlltool", NULL
);
1345 strarray_add( args
, "-k", "-l", output_file_name
, "-d", def_file
, NULL
);
1347 strarray_free( args
);
1351 args
= find_tool( "ar", NULL
);
1352 strarray_add( args
, "rs", output_file_name
, NULL
);
1353 strarray_addv( args
, argv
);
1355 strarray_free( args
);
1357 output_file_name
= NULL
;