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
);
514 /* read in the list of undefined symbols */
515 void read_undef_symbols( DLLSPEC
*spec
, char **argv
)
519 const char *prog
= get_nm_command();
520 char *cmd
, buffer
[1024], name_prefix
[16];
524 if (!argv
[0]) return;
526 add_extra_undef_symbols( spec
);
528 strcpy( name_prefix
, asm_name("") );
529 prefix_len
= strlen( name_prefix
);
531 name
= ldcombine_files( spec
, argv
);
533 cmd
= strmake( "%s -u %s", prog
, name
);
534 if (!(f
= popen( cmd
, "r" )))
535 fatal_error( "Cannot execute '%s'\n", cmd
);
537 while (fgets( buffer
, sizeof(buffer
), f
))
539 char *p
= buffer
+ strlen(buffer
) - 1;
540 if (p
< buffer
) continue;
541 if (*p
== '\n') *p
-- = 0;
543 while (*p
== ' ') p
++;
544 if (p
[0] == 'U' && p
[1] == ' ' && p
[2]) p
+= 2;
545 if (prefix_len
&& !strncmp( p
, name_prefix
, prefix_len
)) p
+= prefix_len
;
546 add_name( &undef_symbols
, p
);
548 if ((err
= pclose( f
))) warning( "%s failed with status %d\n", cmd
, err
);
552 /* resolve the imports for a Win32 module */
553 void resolve_imports( DLLSPEC
*spec
)
556 unsigned int j
, removed
;
559 check_undefined_forwards( spec
);
561 for (i
= 0; i
< nb_imports
; i
++)
563 struct import
*imp
= dll_imports
[i
];
565 for (j
= removed
= 0; j
< undef_symbols
.count
; j
++)
567 odp
= find_export( undef_symbols
.names
[j
], imp
->exports
, imp
->nb_exports
);
570 if (odp
->flags
& FLAG_PRIVATE
) continue;
571 if (odp
->type
!= TYPE_STDCALL
&& odp
->type
!= TYPE_CDECL
)
572 warning( "winebuild: Data export '%s' cannot be imported from %s\n",
573 odp
->link_name
, imp
->spec
->file_name
);
576 add_import_func( imp
, odp
);
577 remove_name( &undef_symbols
, j
-- );
584 /* the dll is not used, get rid of it */
585 if (check_unused( imp
, spec
))
586 warning( "winebuild: %s imported but no symbols used\n", imp
->spec
->file_name
);
587 remove_import_dll( i
);
592 sort_names( &undef_symbols
);
593 check_undefined_exports( spec
);
596 /* check if symbol is still undefined */
597 int is_undefined( const char *name
)
599 return find_name( name
, &undef_symbols
) != NULL
;
602 /* output the get_pc thunk if needed */
603 void output_get_pc_thunk(void)
605 if (target_cpu
!= CPU_x86
) return;
607 output( "\n\t.text\n" );
608 output( "\t.align %d\n", get_alignment(4) );
609 output( "\t%s\n", func_declaration("__wine_spec_get_pc_thunk_eax") );
610 output( "%s:\n", asm_name("__wine_spec_get_pc_thunk_eax") );
611 output_cfi( ".cfi_startproc" );
612 output( "\tmovl (%%esp),%%eax\n" );
614 output_cfi( ".cfi_endproc" );
615 output_function_size( "__wine_spec_get_pc_thunk_eax" );
618 /* output a single import thunk */
619 static void output_import_thunk( const char *name
, const char *table
, int pos
)
621 output( "\n\t.align %d\n", get_alignment(4) );
622 output( "\t%s\n", func_declaration(name
) );
623 output( "%s\n", asm_globl(name
) );
624 output_cfi( ".cfi_startproc" );
631 output( "\tjmp *(%s+%d)\n", table
, pos
);
635 output( "\tcall %s\n", asm_name("__wine_spec_get_pc_thunk_eax") );
636 output( "1:\tjmp *%s+%d-1b(%%eax)\n", table
, pos
);
640 output( "\tjmpq *%s+%d(%%rip)\n", table
, pos
);
643 output( "\tldr IP,1f\n");
644 output( "\tldr PC,[PC,IP]\n" );
645 output( "1:\t.long %s+%u-(1b+4)\n", table
, pos
);
648 output( "\tadr x9, 1f\n" );
649 output( "\tldur x9, [x9, #0]\n" );
650 if (pos
& 0xf000) output( "\tadd x9, x9, #%u\n", pos
& 0xf000 );
651 if (pos
& 0x0f00) output( "\tadd x9, x9, #%u\n", pos
& 0x0f00 );
652 if (pos
& 0x00f0) output( "\tadd x9, x9, #%u\n", pos
& 0x00f0 );
653 if (pos
& 0x000f) output( "\tadd x9, x9, #%u\n", pos
& 0x000f );
654 output( "\tldur x9, [x9, #0]\n" );
655 output( "\tbr x9\n" );
656 output( "1:\t.quad %s\n", table
);
659 output( "\tmr %s, %s\n", ppc_reg(0), ppc_reg(31) );
660 if (target_platform
== PLATFORM_APPLE
)
662 output( "\tlis %s, ha16(%s+%d+32768)\n", ppc_reg(31), table
, pos
);
663 output( "\tla %s, lo16(%s+%d)(%s)\n", ppc_reg(31), table
, pos
, ppc_reg(31) );
667 output( "\tlis %s, (%s+%d+32768)@h\n", ppc_reg(31), table
, pos
);
668 output( "\tla %s, (%s+%d)@l(%s)\n", ppc_reg(31), table
, pos
, ppc_reg(31) );
670 output( "\tlwz %s, 0(%s)\n", ppc_reg(31), ppc_reg(31) );
671 output( "\tmtctr %s\n", ppc_reg(31) );
672 output( "\tmr %s, %s\n", ppc_reg(31), ppc_reg(0) );
673 output( "\tbctr\n" );
676 output_cfi( ".cfi_endproc" );
677 output_function_size( name
);
680 /* check if we need an import directory */
681 int has_imports(void)
683 return (nb_imports
- nb_delayed
) > 0;
686 /* output the import table of a Win32 module */
687 static void output_immediate_imports(void)
690 const char *dll_name
;
692 if (nb_imports
== nb_delayed
) return; /* no immediate imports */
694 /* main import header */
696 output( "\n/* import table */\n" );
697 output( "\n\t.data\n" );
698 output( "\t.align %d\n", get_alignment(4) );
699 output( ".L__wine_spec_imports:\n" );
703 for (i
= j
= 0; i
< nb_imports
; i
++)
705 if (dll_imports
[i
]->delay
) continue;
706 dll_name
= make_c_identifier( dll_imports
[i
]->spec
->file_name
);
707 output( "\t.long .L__wine_spec_import_data_names+%d-.L__wine_spec_rva_base\n", /* OriginalFirstThunk */
708 j
* get_ptr_size() );
709 output( "\t.long 0\n" ); /* TimeDateStamp */
710 output( "\t.long 0\n" ); /* ForwarderChain */
711 output( "\t.long .L__wine_spec_import_name_%s-.L__wine_spec_rva_base\n", /* Name */
713 output( "\t.long .L__wine_spec_import_data_ptrs+%d-.L__wine_spec_rva_base\n", /* FirstThunk */
714 j
* get_ptr_size() );
715 j
+= dll_imports
[i
]->nb_imports
+ 1;
717 output( "\t.long 0\n" ); /* OriginalFirstThunk */
718 output( "\t.long 0\n" ); /* TimeDateStamp */
719 output( "\t.long 0\n" ); /* ForwarderChain */
720 output( "\t.long 0\n" ); /* Name */
721 output( "\t.long 0\n" ); /* FirstThunk */
723 output( "\n\t.align %d\n", get_alignment(get_ptr_size()) );
724 output( ".L__wine_spec_import_data_names:\n" );
725 for (i
= 0; i
< nb_imports
; i
++)
727 if (dll_imports
[i
]->delay
) continue;
728 dll_name
= make_c_identifier( dll_imports
[i
]->spec
->file_name
);
729 for (j
= 0; j
< dll_imports
[i
]->nb_imports
; j
++)
731 ORDDEF
*odp
= dll_imports
[i
]->imports
[j
];
732 if (!(odp
->flags
& FLAG_NONAME
))
733 output( "\t%s .L__wine_spec_import_data_%s_%s-.L__wine_spec_rva_base\n",
734 get_asm_ptr_keyword(), dll_name
, odp
->name
);
737 if (get_ptr_size() == 8)
738 output( "\t.quad 0x800000000000%04x\n", odp
->ordinal
);
740 output( "\t.long 0x8000%04x\n", odp
->ordinal
);
743 output( "\t%s 0\n", get_asm_ptr_keyword() );
745 output( ".L__wine_spec_import_data_ptrs:\n" );
746 for (i
= 0; i
< nb_imports
; i
++)
748 if (dll_imports
[i
]->delay
) continue;
749 for (j
= 0; j
< dll_imports
[i
]->nb_imports
; j
++) output( "\t%s 0\n", get_asm_ptr_keyword() );
750 output( "\t%s 0\n", get_asm_ptr_keyword() );
752 output( ".L__wine_spec_imports_end:\n" );
754 for (i
= 0; i
< nb_imports
; i
++)
756 if (dll_imports
[i
]->delay
) continue;
757 dll_name
= make_c_identifier( dll_imports
[i
]->spec
->file_name
);
758 for (j
= 0; j
< dll_imports
[i
]->nb_imports
; j
++)
760 ORDDEF
*odp
= dll_imports
[i
]->imports
[j
];
761 if (!(odp
->flags
& FLAG_NONAME
))
763 output( "\t.align %d\n", get_alignment(2) );
764 output( ".L__wine_spec_import_data_%s_%s:\n", dll_name
, odp
->name
);
765 output( "\t.short %d\n", odp
->ordinal
);
766 output( "\t%s \"%s\"\n", get_asm_string_keyword(), odp
->name
);
771 for (i
= 0; i
< nb_imports
; i
++)
773 if (dll_imports
[i
]->delay
) continue;
774 dll_name
= make_c_identifier( dll_imports
[i
]->spec
->file_name
);
775 output( ".L__wine_spec_import_name_%s:\n\t%s \"%s\"\n",
776 dll_name
, get_asm_string_keyword(), dll_imports
[i
]->spec
->file_name
);
780 /* output the import thunks of a Win32 module */
781 static void output_immediate_import_thunks(void)
784 int nb_imm
= nb_imports
- nb_delayed
;
785 static const char import_thunks
[] = "__wine_spec_import_thunks";
789 output( "\n/* immediate import thunks */\n\n" );
790 output( "\t.text\n" );
791 output( "\t.align %d\n", get_alignment(8) );
792 output( "%s:\n", asm_name(import_thunks
));
794 for (i
= pos
= 0; i
< nb_imports
; i
++)
796 if (dll_imports
[i
]->delay
) continue;
797 for (j
= 0; j
< dll_imports
[i
]->nb_imports
; j
++, pos
+= get_ptr_size())
799 ORDDEF
*odp
= dll_imports
[i
]->imports
[j
];
800 output_import_thunk( odp
->name
? odp
->name
: odp
->export_name
,
801 ".L__wine_spec_import_data_ptrs", pos
);
803 pos
+= get_ptr_size();
805 output_function_size( import_thunks
);
808 /* output the delayed import table of a Win32 module */
809 static void output_delayed_imports( const DLLSPEC
*spec
)
813 if (!nb_delayed
) return;
815 output( "\n/* delayed imports */\n\n" );
816 output( "\t.data\n" );
817 output( "\t.align %d\n", get_alignment(get_ptr_size()) );
818 output( "%s\n", asm_globl("__wine_spec_delay_imports") );
822 for (i
= j
= mod
= 0; i
< nb_imports
; i
++)
824 if (!dll_imports
[i
]->delay
) continue;
825 output( "\t%s 0\n", get_asm_ptr_keyword() ); /* grAttrs */
826 output( "\t%s .L__wine_delay_name_%d\n", /* szName */
827 get_asm_ptr_keyword(), i
);
828 output( "\t%s .L__wine_delay_modules+%d\n", /* phmod */
829 get_asm_ptr_keyword(), mod
* get_ptr_size() );
830 output( "\t%s .L__wine_delay_IAT+%d\n", /* pIAT */
831 get_asm_ptr_keyword(), j
* get_ptr_size() );
832 output( "\t%s .L__wine_delay_INT+%d\n", /* pINT */
833 get_asm_ptr_keyword(), j
* get_ptr_size() );
834 output( "\t%s 0\n", get_asm_ptr_keyword() ); /* pBoundIAT */
835 output( "\t%s 0\n", get_asm_ptr_keyword() ); /* pUnloadIAT */
836 output( "\t%s 0\n", get_asm_ptr_keyword() ); /* dwTimeStamp */
837 j
+= dll_imports
[i
]->nb_imports
;
840 output( "\t%s 0\n", get_asm_ptr_keyword() ); /* grAttrs */
841 output( "\t%s 0\n", get_asm_ptr_keyword() ); /* szName */
842 output( "\t%s 0\n", get_asm_ptr_keyword() ); /* phmod */
843 output( "\t%s 0\n", get_asm_ptr_keyword() ); /* pIAT */
844 output( "\t%s 0\n", get_asm_ptr_keyword() ); /* pINT */
845 output( "\t%s 0\n", get_asm_ptr_keyword() ); /* pBoundIAT */
846 output( "\t%s 0\n", get_asm_ptr_keyword() ); /* pUnloadIAT */
847 output( "\t%s 0\n", get_asm_ptr_keyword() ); /* dwTimeStamp */
849 output( "\n.L__wine_delay_IAT:\n" );
850 for (i
= 0; i
< nb_imports
; i
++)
852 if (!dll_imports
[i
]->delay
) continue;
853 for (j
= 0; j
< dll_imports
[i
]->nb_imports
; j
++)
855 ORDDEF
*odp
= dll_imports
[i
]->imports
[j
];
856 const char *name
= odp
->name
? odp
->name
: odp
->export_name
;
857 output( "\t%s .L__wine_delay_imp_%d_%s\n",
858 get_asm_ptr_keyword(), i
, name
);
862 output( "\n.L__wine_delay_INT:\n" );
863 for (i
= 0; i
< nb_imports
; i
++)
865 if (!dll_imports
[i
]->delay
) continue;
866 for (j
= 0; j
< dll_imports
[i
]->nb_imports
; j
++)
868 ORDDEF
*odp
= dll_imports
[i
]->imports
[j
];
870 output( "\t%s %d\n", get_asm_ptr_keyword(), odp
->ordinal
);
872 output( "\t%s .L__wine_delay_data_%d_%s\n",
873 get_asm_ptr_keyword(), i
, odp
->name
);
877 output( "\n.L__wine_delay_modules:\n" );
878 for (i
= 0; i
< nb_imports
; i
++)
880 if (dll_imports
[i
]->delay
) output( "\t%s 0\n", get_asm_ptr_keyword() );
883 for (i
= 0; i
< nb_imports
; i
++)
885 if (!dll_imports
[i
]->delay
) continue;
886 output( ".L__wine_delay_name_%d:\n", i
);
887 output( "\t%s \"%s\"\n",
888 get_asm_string_keyword(), dll_imports
[i
]->spec
->file_name
);
891 for (i
= 0; i
< nb_imports
; i
++)
893 if (!dll_imports
[i
]->delay
) continue;
894 for (j
= 0; j
< dll_imports
[i
]->nb_imports
; j
++)
896 ORDDEF
*odp
= dll_imports
[i
]->imports
[j
];
897 if (!odp
->name
) continue;
898 output( ".L__wine_delay_data_%d_%s:\n", i
, odp
->name
);
899 output( "\t%s \"%s\"\n", get_asm_string_keyword(), odp
->name
);
902 output_function_size( "__wine_spec_delay_imports" );
905 /* output the delayed import thunks of a Win32 module */
906 static void output_delayed_import_thunks( const DLLSPEC
*spec
)
908 int i
, idx
, j
, pos
, extra_stack_storage
= 0;
909 static const char delayed_import_loaders
[] = "__wine_spec_delayed_import_loaders";
910 static const char delayed_import_thunks
[] = "__wine_spec_delayed_import_thunks";
912 if (!nb_delayed
) return;
914 output( "\n/* delayed import thunks */\n\n" );
915 output( "\t.text\n" );
916 output( "\t.align %d\n", get_alignment(8) );
917 output( "%s:\n", asm_name(delayed_import_loaders
));
918 output( "\t%s\n", func_declaration("__wine_delay_load_asm") );
919 output( "%s:\n", asm_name("__wine_delay_load_asm") );
920 output_cfi( ".cfi_startproc" );
924 output( "\tpushl %%ecx\n" );
925 output_cfi( ".cfi_adjust_cfa_offset 4" );
926 output( "\tpushl %%edx\n" );
927 output_cfi( ".cfi_adjust_cfa_offset 4" );
928 output( "\tpushl %%eax\n" );
929 output_cfi( ".cfi_adjust_cfa_offset 4" );
930 output( "\tcall %s\n", asm_name("__wine_spec_delay_load") );
931 output_cfi( ".cfi_adjust_cfa_offset -4" );
932 output( "\tpopl %%edx\n" );
933 output_cfi( ".cfi_adjust_cfa_offset -4" );
934 output( "\tpopl %%ecx\n" );
935 output_cfi( ".cfi_adjust_cfa_offset -4" );
936 output( "\tjmp *%%eax\n" );
939 output( "\tsubq $88,%%rsp\n" );
940 output_cfi( ".cfi_adjust_cfa_offset 88" );
941 output( "\tmovq %%rdx,80(%%rsp)\n" );
942 output( "\tmovq %%rcx,72(%%rsp)\n" );
943 output( "\tmovq %%r8,64(%%rsp)\n" );
944 output( "\tmovq %%r9,56(%%rsp)\n" );
945 output( "\tmovq %%r10,48(%%rsp)\n" );
946 output( "\tmovq %%r11,40(%%rsp)\n" );
947 output( "\tmovq %%rax,%%rcx\n" );
948 output( "\tcall %s\n", asm_name("__wine_spec_delay_load") );
949 output( "\tmovq 40(%%rsp),%%r11\n" );
950 output( "\tmovq 48(%%rsp),%%r10\n" );
951 output( "\tmovq 56(%%rsp),%%r9\n" );
952 output( "\tmovq 64(%%rsp),%%r8\n" );
953 output( "\tmovq 72(%%rsp),%%rcx\n" );
954 output( "\tmovq 80(%%rsp),%%rdx\n" );
955 output( "\taddq $88,%%rsp\n" );
956 output_cfi( ".cfi_adjust_cfa_offset -88" );
957 output( "\tjmp *%%rax\n" );
960 output( "\tpush {r0-r3,FP,LR}\n" );
961 output( "\tmov r0,IP\n" );
962 output( "\tldr IP,2f\n");
963 output( "\tadd IP,PC\n");
964 output( "\tblx IP\n");
965 output( "1:\tmov IP,r0\n");
966 output( "\tpop {r0-r3,FP,LR}\n" );
967 output( "\tbx IP\n");
968 output( "2:\t.long %s-1b\n", asm_name("__wine_spec_delay_load") );
971 output( "\tstp x29, x30, [sp,#-16]!\n" );
972 output( "\tmov x29, sp\n" );
973 output( "\tadr x9, 1f\n" );
974 output( "\tldur x9, [x9, #0]\n" );
975 output( "\tblr x9\n" );
976 output( "\tmov x9, x0\n" );
977 output( "\tldp x29, x30, [sp],#16\n" );
978 output( "\tldp x0, x1, [sp,#16]\n" );
979 output( "\tldp x2, x3, [sp,#32]\n" );
980 output( "\tldp x4, x5, [sp,#48]\n" );
981 output( "\tldp x6, x7, [sp],#80\n" );
982 output( "\tbr x9\n" ); /* or "ret x9" */
983 output( "1:\t.quad %s\n", asm_name("__wine_spec_delay_load") );
986 if (target_platform
== PLATFORM_APPLE
) extra_stack_storage
= 56;
988 /* Save all callee saved registers into a stackframe. */
989 output( "\tstwu %s, -%d(%s)\n",ppc_reg(1), 48+extra_stack_storage
, ppc_reg(1));
990 output( "\tstw %s, %d(%s)\n", ppc_reg(3), 4+extra_stack_storage
, ppc_reg(1));
991 output( "\tstw %s, %d(%s)\n", ppc_reg(4), 8+extra_stack_storage
, ppc_reg(1));
992 output( "\tstw %s, %d(%s)\n", ppc_reg(5), 12+extra_stack_storage
, ppc_reg(1));
993 output( "\tstw %s, %d(%s)\n", ppc_reg(6), 16+extra_stack_storage
, ppc_reg(1));
994 output( "\tstw %s, %d(%s)\n", ppc_reg(7), 20+extra_stack_storage
, ppc_reg(1));
995 output( "\tstw %s, %d(%s)\n", ppc_reg(8), 24+extra_stack_storage
, ppc_reg(1));
996 output( "\tstw %s, %d(%s)\n", ppc_reg(9), 28+extra_stack_storage
, ppc_reg(1));
997 output( "\tstw %s, %d(%s)\n", ppc_reg(10),32+extra_stack_storage
, ppc_reg(1));
998 output( "\tstw %s, %d(%s)\n", ppc_reg(11),36+extra_stack_storage
, ppc_reg(1));
999 output( "\tstw %s, %d(%s)\n", ppc_reg(12),40+extra_stack_storage
, ppc_reg(1));
1001 /* r0 -> r3 (arg1) */
1002 output( "\tmr %s, %s\n", ppc_reg(3), ppc_reg(0));
1004 /* save return address */
1005 output( "\tmflr %s\n", ppc_reg(0));
1006 output( "\tstw %s, %d(%s)\n", ppc_reg(0), 44+extra_stack_storage
, ppc_reg(1));
1008 /* Call the __wine_delay_load function, arg1 is arg1. */
1009 output( "\tbl %s\n", asm_name("__wine_spec_delay_load") );
1011 /* Load return value from call into ctr register */
1012 output( "\tmtctr %s\n", ppc_reg(3));
1014 /* restore all saved registers and drop stackframe. */
1015 output( "\tlwz %s, %d(%s)\n", ppc_reg(3), 4+extra_stack_storage
, ppc_reg(1));
1016 output( "\tlwz %s, %d(%s)\n", ppc_reg(4), 8+extra_stack_storage
, ppc_reg(1));
1017 output( "\tlwz %s, %d(%s)\n", ppc_reg(5), 12+extra_stack_storage
, ppc_reg(1));
1018 output( "\tlwz %s, %d(%s)\n", ppc_reg(6), 16+extra_stack_storage
, ppc_reg(1));
1019 output( "\tlwz %s, %d(%s)\n", ppc_reg(7), 20+extra_stack_storage
, ppc_reg(1));
1020 output( "\tlwz %s, %d(%s)\n", ppc_reg(8), 24+extra_stack_storage
, ppc_reg(1));
1021 output( "\tlwz %s, %d(%s)\n", ppc_reg(9), 28+extra_stack_storage
, ppc_reg(1));
1022 output( "\tlwz %s, %d(%s)\n", ppc_reg(10),32+extra_stack_storage
, ppc_reg(1));
1023 output( "\tlwz %s, %d(%s)\n", ppc_reg(11),36+extra_stack_storage
, ppc_reg(1));
1024 output( "\tlwz %s, %d(%s)\n", ppc_reg(12),40+extra_stack_storage
, ppc_reg(1));
1026 /* Load return value from call into return register */
1027 output( "\tlwz %s, %d(%s)\n", ppc_reg(0), 44+extra_stack_storage
, ppc_reg(1));
1028 output( "\tmtlr %s\n", ppc_reg(0));
1029 output( "\taddi %s, %s, %d\n", ppc_reg(1), ppc_reg(1), 48+extra_stack_storage
);
1031 /* branch to ctr register. */
1032 output( "\tbctr\n");
1035 output_cfi( ".cfi_endproc" );
1036 output_function_size( "__wine_delay_load_asm" );
1039 for (i
= idx
= 0; i
< nb_imports
; i
++)
1041 if (!dll_imports
[i
]->delay
) continue;
1042 for (j
= 0; j
< dll_imports
[i
]->nb_imports
; j
++)
1044 ORDDEF
*odp
= dll_imports
[i
]->imports
[j
];
1045 const char *name
= odp
->name
? odp
->name
: odp
->export_name
;
1047 output( ".L__wine_delay_imp_%d_%s:\n", i
, name
);
1048 output_cfi( ".cfi_startproc" );
1052 output( "\tmovl $%d, %%eax\n", (idx
<< 16) | j
);
1053 output( "\tjmp %s\n", asm_name("__wine_delay_load_asm") );
1056 output( "\tmovq $%d,%%rax\n", (idx
<< 16) | j
);
1057 output( "\tjmp %s\n", asm_name("__wine_delay_load_asm") );
1061 unsigned int mask
, count
= 0, val
= (idx
<< 16) | j
;
1063 for (mask
= 0xff; mask
; mask
<<= 8)
1064 if (val
& mask
) output( "\t%s IP,#%u\n", count
++ ? "add" : "mov", val
& mask
);
1065 if (!count
) output( "\tmov IP,#0\n" );
1066 output( "\tb %s\n", asm_name("__wine_delay_load_asm") );
1070 output( "\tstp x6, x7, [sp,#-80]!\n" );
1071 output( "\tstp x4, x5, [sp,#48]\n" );
1072 output( "\tstp x2, x3, [sp,#32]\n" );
1073 output( "\tstp x0, x1, [sp,#16]\n" );
1074 output( "\tmov x0, #%d\n", idx
);
1075 output( "\tmov x1, #16384\n" );
1076 output( "\tmul x1, x0, x1\n" );
1077 output( "\tmov x0, x1\n" );
1078 output( "\tmov x1, #4\n" );
1079 output( "\tmul x1, x0, x1\n" );
1080 output( "\tmov x0, x1\n" );
1081 output( "\tadd x0, x0, #%d\n", j
);
1082 output( "\tadr x9, 1f\n" );
1083 output( "\tldur x9, [x9, #0]\n" );
1084 output( "\tbr x9\n" );
1085 output( "1:\t.quad %s\n", asm_name("__wine_delay_load_asm") );
1088 switch(target_platform
)
1090 case PLATFORM_APPLE
:
1091 /* On Darwin we can use r0 and r2 */
1092 /* Upper part in r2 */
1093 output( "\tlis %s, %d\n", ppc_reg(2), idx
);
1094 /* Lower part + r2 -> r0, Note we can't use r0 directly */
1095 output( "\taddi %s, %s, %d\n", ppc_reg(0), ppc_reg(2), j
);
1096 output( "\tb %s\n", asm_name("__wine_delay_load_asm") );
1099 /* On linux we can't use r2 since r2 is not a scratch register (hold the TOC) */
1100 /* Save r13 on the stack */
1101 output( "\taddi %s, %s, -0x4\n", ppc_reg(1), ppc_reg(1));
1102 output( "\tstw %s, 0(%s)\n", ppc_reg(13), ppc_reg(1));
1103 /* Upper part in r13 */
1104 output( "\tlis %s, %d\n", ppc_reg(13), idx
);
1105 /* Lower part + r13 -> r0, Note we can't use r0 directly */
1106 output( "\taddi %s, %s, %d\n", ppc_reg(0), ppc_reg(13), j
);
1108 output( "\tstw %s, 0(%s)\n", ppc_reg(13), ppc_reg(1));
1109 output( "\taddic %s, %s, 0x4\n", ppc_reg(1), ppc_reg(1));
1110 output( "\tb %s\n", asm_name("__wine_delay_load_asm") );
1115 output_cfi( ".cfi_endproc" );
1119 output_function_size( delayed_import_loaders
);
1121 output( "\n\t.align %d\n", get_alignment(get_ptr_size()) );
1122 output( "%s:\n", asm_name(delayed_import_thunks
));
1123 for (i
= pos
= 0; i
< nb_imports
; i
++)
1125 if (!dll_imports
[i
]->delay
) continue;
1126 for (j
= 0; j
< dll_imports
[i
]->nb_imports
; j
++, pos
+= get_ptr_size())
1128 ORDDEF
*odp
= dll_imports
[i
]->imports
[j
];
1129 output_import_thunk( odp
->name
? odp
->name
: odp
->export_name
,
1130 ".L__wine_delay_IAT", pos
);
1133 output_function_size( delayed_import_thunks
);
1136 /* output import stubs for exported entry points that link to external symbols */
1137 static void output_external_link_imports( DLLSPEC
*spec
)
1139 unsigned int i
, pos
;
1141 if (!ext_link_imports
.count
) return; /* nothing to do */
1143 sort_names( &ext_link_imports
);
1145 /* get rid of duplicate names */
1146 for (i
= 1; i
< ext_link_imports
.count
; i
++)
1148 if (!strcmp( ext_link_imports
.names
[i
-1], ext_link_imports
.names
[i
] ))
1149 remove_name( &ext_link_imports
, i
-- );
1152 output( "\n/* external link thunks */\n\n" );
1153 output( "\t.data\n" );
1154 output( "\t.align %d\n", get_alignment(get_ptr_size()) );
1155 output( ".L__wine_spec_external_links:\n" );
1156 for (i
= 0; i
< ext_link_imports
.count
; i
++)
1157 output( "\t%s %s\n", get_asm_ptr_keyword(), asm_name(ext_link_imports
.names
[i
]) );
1159 output( "\n\t.text\n" );
1160 output( "\t.align %d\n", get_alignment(get_ptr_size()) );
1161 output( "%s:\n", asm_name("__wine_spec_external_link_thunks") );
1163 for (i
= pos
= 0; i
< ext_link_imports
.count
; i
++)
1165 char *buffer
= strmake( "__wine_spec_ext_link_%s", ext_link_imports
.names
[i
] );
1166 output_import_thunk( buffer
, ".L__wine_spec_external_links", pos
);
1168 pos
+= get_ptr_size();
1170 output_function_size( "__wine_spec_external_link_thunks" );
1173 /*******************************************************************
1176 * Output the functions for stub entry points
1178 void output_stubs( DLLSPEC
*spec
)
1180 const char *name
, *exp_name
;
1183 if (!has_stubs( spec
)) return;
1185 output( "\n/* stub functions */\n\n" );
1186 output( "\t.text\n" );
1188 for (i
= count
= 0; i
< spec
->nb_entry_points
; i
++)
1190 ORDDEF
*odp
= &spec
->entry_points
[i
];
1191 if (odp
->type
!= TYPE_STUB
) continue;
1193 name
= get_stub_name( odp
, spec
);
1194 exp_name
= odp
->name
? odp
->name
: odp
->export_name
;
1195 output( "\t.align %d\n", get_alignment(4) );
1196 output( "\t%s\n", func_declaration(name
) );
1197 output( "%s:\n", asm_name(name
) );
1198 output_cfi( ".cfi_startproc" );
1203 /* flesh out the stub a bit to make safedisc happy */
1204 output(" \tnop\n" );
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" );
1214 output( "\tsubl $12,%%esp\n" );
1215 output_cfi( ".cfi_adjust_cfa_offset 12" );
1218 output( "\tcall %s\n", asm_name("__wine_spec_get_pc_thunk_eax") );
1222 output( "\tleal .L%s_string-1b(%%eax),%%ecx\n", name
);
1223 output( "\tmovl %%ecx,4(%%esp)\n" );
1227 output( "\tmovl $%d,4(%%esp)\n", odp
->ordinal
);
1228 output( "\tleal .L__wine_spec_file_name-1b(%%eax),%%ecx\n" );
1229 output( "\tmovl %%ecx,(%%esp)\n" );
1235 output( "\tmovl $.L%s_string,4(%%esp)\n", name
);
1239 output( "\tmovl $%d,4(%%esp)\n", odp
->ordinal
);
1240 output( "\tmovl $.L__wine_spec_file_name,(%%esp)\n" );
1242 output( "\tcall %s\n", asm_name("__wine_spec_unimplemented_stub") );
1245 output( "\tsubq $8,%%rsp\n" );
1246 output_cfi( ".cfi_adjust_cfa_offset 8" );
1247 output( "\tleaq .L__wine_spec_file_name(%%rip),%%rdi\n" );
1250 output( "leaq .L%s_string(%%rip),%%rsi\n", name
);
1254 output( "\tmovq $%d,%%rsi\n", odp
->ordinal
);
1255 output( "\tcall %s\n", asm_name("__wine_spec_unimplemented_stub") );
1258 output( "\tldr r0,2f\n");
1259 output( "\tadd r0,PC\n");
1260 output( "\tldr r1,2f+4\n");
1264 output( "\tadd r1,PC\n");
1267 output( "\tbl %s\n", asm_name("__wine_spec_unimplemented_stub") );
1268 output( "2:\t.long .L__wine_spec_file_name-1b\n" );
1269 if (exp_name
) output( "\t.long .L%s_string-2b\n", name
);
1270 else output( "\t.long %u\n", odp
->ordinal
);
1273 output( "\tadr x0, 2f\n" );
1274 output( "\tldur x0, [x0, #0]\n" );
1275 output( "\tadr x1, 2f+8\n" );
1276 output( "\tldur x1, [x1, #0]\n" );
1277 output( "\tadr x2, 1f\n" );
1278 output( "\tldur x2, [x2, #0]\n" );
1279 output( "\tblr x2\n" );
1280 output( "1:\t.quad %s\n", asm_name("__wine_spec_unimplemented_stub") );
1281 output( "2:\t.quad %s\n", asm_name("__wine_spec_file_name") );
1284 output( "\t.quad .L%s_string\n", name
);
1287 else output( "\t.quad %u\n", odp
->ordinal
);
1292 output_cfi( ".cfi_endproc" );
1293 output_function_size( name
);
1298 output( "\t%s\n", get_asm_string_section() );
1299 for (i
= 0; i
< spec
->nb_entry_points
; i
++)
1301 ORDDEF
*odp
= &spec
->entry_points
[i
];
1302 if (odp
->type
!= TYPE_STUB
) continue;
1303 exp_name
= odp
->name
? odp
->name
: odp
->export_name
;
1306 name
= get_stub_name( odp
, spec
);
1307 output( ".L%s_string:\n", name
);
1308 output( "\t%s \"%s\"\n", get_asm_string_keyword(), exp_name
);
1314 /* output the import and delayed import tables of a Win32 module */
1315 void output_imports( DLLSPEC
*spec
)
1317 output_immediate_imports();
1318 output_delayed_imports( spec
);
1319 output_immediate_import_thunks();
1320 output_delayed_import_thunks( spec
);
1321 output_external_link_imports( spec
);
1322 if (nb_imports
|| ext_link_imports
.count
|| has_stubs(spec
) || has_relays(spec
))
1323 output_get_pc_thunk();
1326 /* output an import library for a Win32 module and additional object files */
1327 void output_import_lib( DLLSPEC
*spec
, char **argv
)
1329 struct strarray args
;
1331 const char *as_flags
, *m_flag
;
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
);
1349 as_flags
= "--as-flags=--32";
1352 m_flag
= "i386:x86-64";
1353 as_flags
= "--as-flags=--64";
1359 strarray_add( &args
, "-k", "-l", output_file_name
, "-d", def_file
, NULL
);
1361 strarray_add( &args
, "-m", m_flag
, as_flags
, NULL
);
1366 args
= find_tool( "ar", NULL
);
1367 strarray_add( &args
, "rs", output_file_name
, NULL
);
1368 strarray_addv( &args
, argv
);
1371 output_file_name
= NULL
;