winemac: Track drawn surface region to reduce black flicker for new or resized windows.
[wine.git] / tools / winebuild / import.c
blob3756c7519a97fb2ace3091e5d0cb69a152efbb2f
1 /*
2 * DLL imports support
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
22 #include "config.h"
23 #include "wine/port.h"
25 #include <assert.h>
26 #include <ctype.h>
27 #include <fcntl.h>
28 #include <stdio.h>
29 #include <string.h>
30 #include <stdarg.h>
31 #ifdef HAVE_SYS_STAT_H
32 # include <sys/stat.h>
33 #endif
34 #ifdef HAVE_UNISTD_H
35 # include <unistd.h>
36 #endif
38 #include "build.h"
40 struct import
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 */
45 ino_t ino;
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 */
53 struct name_table
55 char **names;
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) );
115 table->count--;
118 /* make a name table empty */
119 static inline void empty_name_table( struct name_table *table )
121 unsigned int i;
123 for (i = 0; i < table->count; i++) free( table->names[i] );
124 table->count = 0;
127 /* locate a name in a (sorted) list */
128 static inline const char *find_name( const char *name, const struct name_table *table )
130 char **res = NULL;
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);
148 func.ordinal = -1;
149 odp = &func;
150 if (table) res = bsearch( &odp, table, size, sizeof(*table), func_cmp );
151 free( func.name );
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 );
162 free( imp );
165 /* check whether a given dll is imported in delayed mode */
166 static int is_delayed_import( const char *name )
168 unsigned int i;
170 for (i = 0; i < delayed_imports.count; i++)
172 if (!strcmp( delayed_imports.names[i], name )) return 1;
174 return 0;
177 /* check whether a given dll has already been imported */
178 static struct import *is_already_imported( const char *name )
180 int i;
182 for (i = 0; i < nb_imports; i++)
184 if (!strcmp( dll_imports[i]->spec->file_name, name )) return dll_imports[i];
186 return NULL;
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 )
192 char *buffer;
193 int fd;
195 buffer = strmake( "%s/lib%s.def", path, name );
197 /* check if the file exists */
198 if ((fd = open( buffer, O_RDONLY )) != -1)
200 close( fd );
201 return buffer;
203 free( buffer );
204 return NULL;
207 /* find the .def import library for a given dll */
208 static char *find_library( const char *name )
210 char *fullname;
211 int i;
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 );
218 return NULL;
221 /* read in the list of exported symbols of an import library */
222 static int read_import_lib( struct import *imp )
224 FILE *f;
225 int i, ret;
226 struct stat stat;
227 struct import *prev_imp;
228 DLLSPEC *spec = imp->spec;
230 f = open_input_file( NULL, imp->full_name );
231 fstat( fileno(f), &stat );
232 imp->dev = stat.st_dev;
233 imp->ino = stat.st_ino;
234 ret = parse_def_file( f, spec );
235 close_input_file( f );
236 if (!ret) return 0;
238 /* check if we already imported that library from a different file */
239 if ((prev_imp = is_already_imported( spec->file_name )))
241 if (prev_imp->dev != imp->dev || prev_imp->ino != imp->ino)
242 fatal_error( "%s and %s have the same export name '%s'\n",
243 prev_imp->full_name, imp->full_name, spec->file_name );
244 return 0; /* the same file was already loaded, ignore this one */
247 if (is_delayed_import( spec->file_name ))
249 imp->delay = 1;
250 nb_delayed++;
253 if (spec->nb_entry_points)
255 imp->exports = xmalloc( spec->nb_entry_points * sizeof(*imp->exports) );
256 for (i = 0; i < spec->nb_entry_points; i++)
257 imp->exports[imp->nb_exports++] = &spec->entry_points[i];
258 qsort( imp->exports, imp->nb_exports, sizeof(*imp->exports), func_cmp );
260 return 1;
263 /* build the dll exported name from the import lib name or path */
264 static char *get_dll_name( const char *name, const char *filename )
266 char *ret;
268 if (filename)
270 const char *basename = strrchr( filename, '/' );
271 if (!basename) basename = filename;
272 else basename++;
273 if (!strncmp( basename, "lib", 3 )) basename += 3;
274 ret = xmalloc( strlen(basename) + 5 );
275 strcpy( ret, basename );
276 if (strendswith( ret, ".def" )) ret[strlen(ret)-4] = 0;
278 else
280 ret = xmalloc( strlen(name) + 5 );
281 strcpy( ret, name );
283 if (!strchr( ret, '.' )) strcat( ret, ".dll" );
284 return ret;
287 /* add a dll to the list of imports */
288 void add_import_dll( const char *name, const char *filename )
290 struct import *imp = xmalloc( sizeof(*imp) );
292 imp->spec = alloc_dll_spec();
293 imp->spec->file_name = get_dll_name( name, filename );
294 imp->delay = 0;
295 imp->imports = NULL;
296 imp->nb_imports = 0;
297 imp->exports = NULL;
298 imp->nb_exports = 0;
300 if (filename) imp->full_name = xstrdup( filename );
301 else imp->full_name = find_library( name );
303 if (read_import_lib( imp ))
305 dll_imports = xrealloc( dll_imports, (nb_imports+1) * sizeof(*dll_imports) );
306 dll_imports[nb_imports++] = imp;
308 else
310 free_imports( imp );
311 if (nb_errors) exit(1);
315 /* add a library to the list of delayed imports */
316 void add_delayed_import( const char *name )
318 struct import *imp;
319 char *fullname = get_dll_name( name, NULL );
321 add_name( &delayed_imports, fullname );
322 if ((imp = is_already_imported( fullname )) && !imp->delay)
324 imp->delay = 1;
325 nb_delayed++;
327 free( fullname );
330 /* remove an imported dll, based on its index in the dll_imports array */
331 static void remove_import_dll( int index )
333 struct import *imp = dll_imports[index];
335 memmove( &dll_imports[index], &dll_imports[index+1], sizeof(imp) * (nb_imports - index - 1) );
336 nb_imports--;
337 if (imp->delay) nb_delayed--;
338 free_imports( imp );
341 /* add a symbol to the list of extra symbols that ld must resolve */
342 void add_extra_ld_symbol( const char *name )
344 add_name( &extra_ld_symbols, name );
347 /* add a function to the list of imports from a given dll */
348 static void add_import_func( struct import *imp, ORDDEF *func )
350 imp->imports = xrealloc( imp->imports, (imp->nb_imports+1) * sizeof(*imp->imports) );
351 imp->imports[imp->nb_imports++] = func;
352 total_imports++;
353 if (imp->delay) total_delayed++;
356 /* get the default entry point for a given spec file */
357 static const char *get_default_entry_point( const DLLSPEC *spec )
359 if (spec->characteristics & IMAGE_FILE_DLL) return "__wine_spec_dll_entry";
360 if (spec->subsystem == IMAGE_SUBSYSTEM_NATIVE) return "__wine_spec_drv_entry";
361 if (spec->type == SPEC_WIN16) return "__wine_spec_exe16_entry";
362 return "__wine_spec_exe_entry";
365 /* check if the spec file exports any stubs */
366 static int has_stubs( const DLLSPEC *spec )
368 int i;
369 for (i = 0; i < spec->nb_entry_points; i++)
371 ORDDEF *odp = &spec->entry_points[i];
372 if (odp->type == TYPE_STUB) return 1;
374 return 0;
377 /* add the extra undefined symbols that will be contained in the generated spec file itself */
378 static void add_extra_undef_symbols( DLLSPEC *spec )
380 if (!spec->init_func) spec->init_func = xstrdup( get_default_entry_point(spec) );
381 add_extra_ld_symbol( spec->init_func );
382 if (has_stubs( spec )) add_extra_ld_symbol( "__wine_spec_unimplemented_stub" );
383 if (nb_delayed) add_extra_ld_symbol( "__wine_spec_delay_load" );
386 /* check if a given imported dll is not needed, taking forwards into account */
387 static int check_unused( const struct import* imp, const DLLSPEC *spec )
389 int i;
390 const char *file_name = imp->spec->file_name;
391 size_t len = strlen( file_name );
392 const char *p = strchr( file_name, '.' );
393 if (p && !strcasecmp( p, ".dll" )) len = p - file_name;
395 for (i = spec->base; i <= spec->limit; i++)
397 ORDDEF *odp = spec->ordinals[i];
398 if (!odp || !(odp->flags & FLAG_FORWARD)) continue;
399 if (!strncasecmp( odp->link_name, file_name, len ) &&
400 odp->link_name[len] == '.')
401 return 0; /* found a forward, it is used */
403 return 1;
406 /* check if a given forward does exist in one of the imported dlls */
407 static void check_undefined_forwards( DLLSPEC *spec )
409 char *link_name, *api_name, *dll_name, *p;
410 int i, j;
412 for (i = 0; i < spec->nb_entry_points; i++)
414 ORDDEF *odp = &spec->entry_points[i];
416 if (!(odp->flags & FLAG_FORWARD)) continue;
418 link_name = xstrdup( odp->link_name );
419 p = strrchr( link_name, '.' );
420 *p = 0;
421 api_name = p + 1;
422 dll_name = get_dll_name( link_name, NULL );
424 for (j = 0; j < nb_imports; j++)
426 struct import *imp = dll_imports[j];
428 if (strcasecmp( imp->spec->file_name, dll_name )) continue;
429 if (!find_export( api_name, imp->exports, imp->nb_exports ))
430 warning( "%s:%d: forward '%s' not found in %s\n",
431 spec->src_name, odp->lineno, odp->link_name, imp->spec->file_name );
432 break;
434 if (j == nb_imports)
435 warning( "%s:%d: forward '%s' not found in the imported dll list\n",
436 spec->src_name, odp->lineno, odp->link_name );
437 free( link_name );
438 free( dll_name );
442 /* flag the dll exports that link to an undefined symbol */
443 static void check_undefined_exports( DLLSPEC *spec )
445 int i;
447 for (i = 0; i < spec->nb_entry_points; i++)
449 ORDDEF *odp = &spec->entry_points[i];
450 if (odp->type == TYPE_STUB || odp->type == TYPE_ABS || odp->type == TYPE_VARIABLE) continue;
451 if (odp->flags & FLAG_FORWARD) continue;
452 if (find_name( odp->link_name, &undef_symbols ))
454 switch(odp->type)
456 case TYPE_PASCAL:
457 case TYPE_STDCALL:
458 case TYPE_CDECL:
459 case TYPE_VARARGS:
460 case TYPE_THISCALL:
461 if (link_ext_symbols)
463 odp->flags |= FLAG_EXT_LINK;
464 add_name( &ext_link_imports, odp->link_name );
466 else error( "%s:%d: function '%s' not defined\n",
467 spec->src_name, odp->lineno, odp->link_name );
468 break;
469 default:
470 error( "%s:%d: external symbol '%s' is not a function\n",
471 spec->src_name, odp->lineno, odp->link_name );
472 break;
478 /* create a .o file that references all the undefined symbols we want to resolve */
479 static char *create_undef_symbols_file( DLLSPEC *spec )
481 char *as_file, *obj_file;
482 int i;
483 unsigned int j;
484 FILE *f;
486 as_file = get_temp_file_name( output_file_name, ".s" );
487 if (!(f = fopen( as_file, "w" ))) fatal_error( "Cannot create %s\n", as_file );
488 fprintf( f, "\t.data\n" );
490 for (i = 0; i < spec->nb_entry_points; i++)
492 ORDDEF *odp = &spec->entry_points[i];
493 if (odp->type == TYPE_STUB || odp->type == TYPE_ABS || odp->type == TYPE_VARIABLE) continue;
494 if (odp->flags & FLAG_FORWARD) continue;
495 fprintf( f, "\t%s %s\n", get_asm_ptr_keyword(), asm_name(odp->link_name) );
497 for (j = 0; j < extra_ld_symbols.count; j++)
498 fprintf( f, "\t%s %s\n", get_asm_ptr_keyword(), asm_name(extra_ld_symbols.names[j]) );
499 fclose( f );
501 obj_file = get_temp_file_name( output_file_name, ".o" );
502 assemble_file( as_file, obj_file );
503 return obj_file;
506 /* combine a list of object files with ld into a single object file */
507 /* returns the name of the combined file */
508 static const char *ldcombine_files( DLLSPEC *spec, char **argv )
510 char *ld_tmp_file, *undef_file;
511 struct strarray *args = get_ld_command();
513 undef_file = create_undef_symbols_file( spec );
514 ld_tmp_file = get_temp_file_name( output_file_name, ".o" );
516 strarray_add( args, "-r", "-o", ld_tmp_file, undef_file, NULL );
517 strarray_addv( args, argv );
518 spawn( args );
519 strarray_free( args );
520 return ld_tmp_file;
523 /* read in the list of undefined symbols */
524 void read_undef_symbols( DLLSPEC *spec, char **argv )
526 size_t prefix_len;
527 FILE *f;
528 const char *prog = get_nm_command();
529 char *cmd, buffer[1024], name_prefix[16];
530 int err;
531 const char *name;
533 if (!argv[0]) return;
535 add_extra_undef_symbols( spec );
537 strcpy( name_prefix, asm_name("") );
538 prefix_len = strlen( name_prefix );
540 name = ldcombine_files( spec, argv );
542 cmd = strmake( "%s -u %s", prog, name );
543 if (!(f = popen( cmd, "r" )))
544 fatal_error( "Cannot execute '%s'\n", cmd );
546 while (fgets( buffer, sizeof(buffer), f ))
548 char *p = buffer + strlen(buffer) - 1;
549 if (p < buffer) continue;
550 if (*p == '\n') *p-- = 0;
551 p = buffer;
552 while (*p == ' ') p++;
553 if (p[0] == 'U' && p[1] == ' ' && p[2]) p += 2;
554 if (prefix_len && !strncmp( p, name_prefix, prefix_len )) p += prefix_len;
555 add_name( &undef_symbols, p );
557 if ((err = pclose( f ))) warning( "%s failed with status %d\n", cmd, err );
558 free( cmd );
561 /* resolve the imports for a Win32 module */
562 void resolve_imports( DLLSPEC *spec )
564 int i;
565 unsigned int j, removed;
566 ORDDEF *odp;
568 check_undefined_forwards( spec );
570 for (i = 0; i < nb_imports; i++)
572 struct import *imp = dll_imports[i];
574 for (j = removed = 0; j < undef_symbols.count; j++)
576 odp = find_export( undef_symbols.names[j], imp->exports, imp->nb_exports );
577 if (odp)
579 if (odp->flags & FLAG_PRIVATE) continue;
580 if (odp->type != TYPE_STDCALL && odp->type != TYPE_CDECL)
581 warning( "winebuild: Data export '%s' cannot be imported from %s\n",
582 odp->link_name, imp->spec->file_name );
583 else
585 add_import_func( imp, odp );
586 remove_name( &undef_symbols, j-- );
587 removed++;
591 if (!removed)
593 /* the dll is not used, get rid of it */
594 if (check_unused( imp, spec ))
595 warning( "winebuild: %s imported but no symbols used\n", imp->spec->file_name );
596 remove_import_dll( i );
597 i--;
601 sort_names( &undef_symbols );
602 check_undefined_exports( spec );
605 /* check if symbol is still undefined */
606 int is_undefined( const char *name )
608 return find_name( name, &undef_symbols ) != NULL;
611 /* output the get_pc thunk if needed */
612 void output_get_pc_thunk(void)
614 if (target_cpu != CPU_x86) return;
615 if (!UsePIC) return;
616 output( "\n\t.text\n" );
617 output( "\t.align %d\n", get_alignment(4) );
618 output( "\t%s\n", func_declaration("__wine_spec_get_pc_thunk_eax") );
619 output( "%s:\n", asm_name("__wine_spec_get_pc_thunk_eax") );
620 output_cfi( ".cfi_startproc" );
621 output( "\tmovl (%%esp),%%eax\n" );
622 output( "\tret\n" );
623 output_cfi( ".cfi_endproc" );
624 output_function_size( "__wine_spec_get_pc_thunk_eax" );
627 /* output a single import thunk */
628 static void output_import_thunk( const char *name, const char *table, int pos )
630 output( "\n\t.align %d\n", get_alignment(4) );
631 output( "\t%s\n", func_declaration(name) );
632 output( "%s\n", asm_globl(name) );
633 output_cfi( ".cfi_startproc" );
635 switch(target_cpu)
637 case CPU_x86:
638 if (!UsePIC)
640 output( "\tjmp *(%s+%d)\n", table, pos );
642 else
644 output( "\tcall %s\n", asm_name("__wine_spec_get_pc_thunk_eax") );
645 output( "1:\tjmp *%s+%d-1b(%%eax)\n", table, pos );
647 break;
648 case CPU_x86_64:
649 output( "\tjmpq *%s+%d(%%rip)\n", table, pos );
650 break;
651 case CPU_ARM:
652 output( "\tldr IP,[PC,#0]\n");
653 output( "\tldr PC,[IP,#%d]\n", pos);
654 output( "\t.long %s\n", table );
655 break;
656 case CPU_ARM64:
657 output( "\tadr x9, 1f\n" );
658 output( "\tldur x9, [x9, #0]\n" );
659 if (pos & 0xf000) output( "\tadd x9, x9, #%u\n", pos & 0xf000 );
660 if (pos & 0x0f00) output( "\tadd x9, x9, #%u\n", pos & 0x0f00 );
661 if (pos & 0x00f0) output( "\tadd x9, x9, #%u\n", pos & 0x00f0 );
662 if (pos & 0x000f) output( "\tadd x9, x9, #%u\n", pos & 0x000f );
663 output( "\tldur x9, [x9, #0]\n" );
664 output( "\tbr x9\n" );
665 output( "1:\t.quad %s\n", table );
666 break;
667 case CPU_POWERPC:
668 output( "\tmr %s, %s\n", ppc_reg(0), ppc_reg(31) );
669 if (target_platform == PLATFORM_APPLE)
671 output( "\tlis %s, ha16(%s+%d+32768)\n", ppc_reg(31), table, pos );
672 output( "\tla %s, lo16(%s+%d)(%s)\n", ppc_reg(31), table, pos, ppc_reg(31) );
674 else
676 output( "\tlis %s, (%s+%d+32768)@h\n", ppc_reg(31), table, pos );
677 output( "\tla %s, (%s+%d)@l(%s)\n", ppc_reg(31), table, pos, ppc_reg(31) );
679 output( "\tlwz %s, 0(%s)\n", ppc_reg(31), ppc_reg(31) );
680 output( "\tmtctr %s\n", ppc_reg(31) );
681 output( "\tmr %s, %s\n", ppc_reg(31), ppc_reg(0) );
682 output( "\tbctr\n" );
683 break;
685 output_cfi( ".cfi_endproc" );
686 output_function_size( name );
689 /* check if we need an import directory */
690 int has_imports(void)
692 return (nb_imports - nb_delayed) > 0;
695 /* output the import table of a Win32 module */
696 static void output_immediate_imports(void)
698 int i, j;
699 const char *dll_name;
701 if (nb_imports == nb_delayed) return; /* no immediate imports */
703 /* main import header */
705 output( "\n/* import table */\n" );
706 output( "\n\t.data\n" );
707 output( "\t.align %d\n", get_alignment(4) );
708 output( ".L__wine_spec_imports:\n" );
710 /* list of dlls */
712 for (i = j = 0; i < nb_imports; i++)
714 if (dll_imports[i]->delay) continue;
715 dll_name = make_c_identifier( dll_imports[i]->spec->file_name );
716 output( "\t.long .L__wine_spec_import_data_names+%d-.L__wine_spec_rva_base\n", /* OriginalFirstThunk */
717 j * get_ptr_size() );
718 output( "\t.long 0\n" ); /* TimeDateStamp */
719 output( "\t.long 0\n" ); /* ForwarderChain */
720 output( "\t.long .L__wine_spec_import_name_%s-.L__wine_spec_rva_base\n", /* Name */
721 dll_name );
722 output( "\t.long .L__wine_spec_import_data_ptrs+%d-.L__wine_spec_rva_base\n", /* FirstThunk */
723 j * get_ptr_size() );
724 j += dll_imports[i]->nb_imports + 1;
726 output( "\t.long 0\n" ); /* OriginalFirstThunk */
727 output( "\t.long 0\n" ); /* TimeDateStamp */
728 output( "\t.long 0\n" ); /* ForwarderChain */
729 output( "\t.long 0\n" ); /* Name */
730 output( "\t.long 0\n" ); /* FirstThunk */
732 output( "\n\t.align %d\n", get_alignment(get_ptr_size()) );
733 output( ".L__wine_spec_import_data_names:\n" );
734 for (i = 0; i < nb_imports; i++)
736 if (dll_imports[i]->delay) continue;
737 dll_name = make_c_identifier( dll_imports[i]->spec->file_name );
738 for (j = 0; j < dll_imports[i]->nb_imports; j++)
740 ORDDEF *odp = dll_imports[i]->imports[j];
741 if (!(odp->flags & FLAG_NONAME))
742 output( "\t%s .L__wine_spec_import_data_%s_%s-.L__wine_spec_rva_base\n",
743 get_asm_ptr_keyword(), dll_name, odp->name );
744 else
746 if (get_ptr_size() == 8)
747 output( "\t.quad 0x800000000000%04x\n", odp->ordinal );
748 else
749 output( "\t.long 0x8000%04x\n", odp->ordinal );
752 output( "\t%s 0\n", get_asm_ptr_keyword() );
754 output( ".L__wine_spec_import_data_ptrs:\n" );
755 for (i = 0; i < nb_imports; i++)
757 if (dll_imports[i]->delay) continue;
758 for (j = 0; j < dll_imports[i]->nb_imports; j++) output( "\t%s 0\n", get_asm_ptr_keyword() );
759 output( "\t%s 0\n", get_asm_ptr_keyword() );
761 output( ".L__wine_spec_imports_end:\n" );
763 for (i = 0; i < nb_imports; i++)
765 if (dll_imports[i]->delay) continue;
766 dll_name = make_c_identifier( dll_imports[i]->spec->file_name );
767 for (j = 0; j < dll_imports[i]->nb_imports; j++)
769 ORDDEF *odp = dll_imports[i]->imports[j];
770 if (!(odp->flags & FLAG_NONAME))
772 output( "\t.align %d\n", get_alignment(2) );
773 output( ".L__wine_spec_import_data_%s_%s:\n", dll_name, odp->name );
774 output( "\t.short %d\n", odp->ordinal );
775 output( "\t%s \"%s\"\n", get_asm_string_keyword(), odp->name );
780 for (i = 0; i < nb_imports; i++)
782 if (dll_imports[i]->delay) continue;
783 dll_name = make_c_identifier( dll_imports[i]->spec->file_name );
784 output( ".L__wine_spec_import_name_%s:\n\t%s \"%s\"\n",
785 dll_name, get_asm_string_keyword(), dll_imports[i]->spec->file_name );
789 /* output the import thunks of a Win32 module */
790 static void output_immediate_import_thunks(void)
792 int i, j, pos;
793 int nb_imm = nb_imports - nb_delayed;
794 static const char import_thunks[] = "__wine_spec_import_thunks";
796 if (!nb_imm) return;
798 output( "\n/* immediate import thunks */\n\n" );
799 output( "\t.text\n" );
800 output( "\t.align %d\n", get_alignment(8) );
801 output( "%s:\n", asm_name(import_thunks));
803 for (i = pos = 0; i < nb_imports; i++)
805 if (dll_imports[i]->delay) continue;
806 for (j = 0; j < dll_imports[i]->nb_imports; j++, pos += get_ptr_size())
808 ORDDEF *odp = dll_imports[i]->imports[j];
809 output_import_thunk( odp->name ? odp->name : odp->export_name,
810 ".L__wine_spec_import_data_ptrs", pos );
812 pos += get_ptr_size();
814 output_function_size( import_thunks );
817 /* output the delayed import table of a Win32 module */
818 static void output_delayed_imports( const DLLSPEC *spec )
820 int i, j, mod;
822 if (!nb_delayed) return;
824 output( "\n/* delayed imports */\n\n" );
825 output( "\t.data\n" );
826 output( "\t.align %d\n", get_alignment(get_ptr_size()) );
827 output( "%s\n", asm_globl("__wine_spec_delay_imports") );
829 /* list of dlls */
831 for (i = j = mod = 0; i < nb_imports; i++)
833 if (!dll_imports[i]->delay) continue;
834 output( "\t%s 0\n", get_asm_ptr_keyword() ); /* grAttrs */
835 output( "\t%s .L__wine_delay_name_%d\n", /* szName */
836 get_asm_ptr_keyword(), i );
837 output( "\t%s .L__wine_delay_modules+%d\n", /* phmod */
838 get_asm_ptr_keyword(), mod * get_ptr_size() );
839 output( "\t%s .L__wine_delay_IAT+%d\n", /* pIAT */
840 get_asm_ptr_keyword(), j * get_ptr_size() );
841 output( "\t%s .L__wine_delay_INT+%d\n", /* pINT */
842 get_asm_ptr_keyword(), j * get_ptr_size() );
843 output( "\t%s 0\n", get_asm_ptr_keyword() ); /* pBoundIAT */
844 output( "\t%s 0\n", get_asm_ptr_keyword() ); /* pUnloadIAT */
845 output( "\t%s 0\n", get_asm_ptr_keyword() ); /* dwTimeStamp */
846 j += dll_imports[i]->nb_imports;
847 mod++;
849 output( "\t%s 0\n", get_asm_ptr_keyword() ); /* grAttrs */
850 output( "\t%s 0\n", get_asm_ptr_keyword() ); /* szName */
851 output( "\t%s 0\n", get_asm_ptr_keyword() ); /* phmod */
852 output( "\t%s 0\n", get_asm_ptr_keyword() ); /* pIAT */
853 output( "\t%s 0\n", get_asm_ptr_keyword() ); /* pINT */
854 output( "\t%s 0\n", get_asm_ptr_keyword() ); /* pBoundIAT */
855 output( "\t%s 0\n", get_asm_ptr_keyword() ); /* pUnloadIAT */
856 output( "\t%s 0\n", get_asm_ptr_keyword() ); /* dwTimeStamp */
858 output( "\n.L__wine_delay_IAT:\n" );
859 for (i = 0; i < nb_imports; i++)
861 if (!dll_imports[i]->delay) continue;
862 for (j = 0; j < dll_imports[i]->nb_imports; j++)
864 ORDDEF *odp = dll_imports[i]->imports[j];
865 const char *name = odp->name ? odp->name : odp->export_name;
866 output( "\t%s .L__wine_delay_imp_%d_%s\n",
867 get_asm_ptr_keyword(), i, name );
871 output( "\n.L__wine_delay_INT:\n" );
872 for (i = 0; i < nb_imports; i++)
874 if (!dll_imports[i]->delay) continue;
875 for (j = 0; j < dll_imports[i]->nb_imports; j++)
877 ORDDEF *odp = dll_imports[i]->imports[j];
878 if (!odp->name)
879 output( "\t%s %d\n", get_asm_ptr_keyword(), odp->ordinal );
880 else
881 output( "\t%s .L__wine_delay_data_%d_%s\n",
882 get_asm_ptr_keyword(), i, odp->name );
886 output( "\n.L__wine_delay_modules:\n" );
887 for (i = 0; i < nb_imports; i++)
889 if (dll_imports[i]->delay) output( "\t%s 0\n", get_asm_ptr_keyword() );
892 for (i = 0; i < nb_imports; i++)
894 if (!dll_imports[i]->delay) continue;
895 output( ".L__wine_delay_name_%d:\n", i );
896 output( "\t%s \"%s\"\n",
897 get_asm_string_keyword(), dll_imports[i]->spec->file_name );
900 for (i = 0; i < nb_imports; i++)
902 if (!dll_imports[i]->delay) continue;
903 for (j = 0; j < dll_imports[i]->nb_imports; j++)
905 ORDDEF *odp = dll_imports[i]->imports[j];
906 if (!odp->name) continue;
907 output( ".L__wine_delay_data_%d_%s:\n", i, odp->name );
908 output( "\t%s \"%s\"\n", get_asm_string_keyword(), odp->name );
911 output_function_size( "__wine_spec_delay_imports" );
914 /* output the delayed import thunks of a Win32 module */
915 static void output_delayed_import_thunks( const DLLSPEC *spec )
917 int i, idx, j, pos, extra_stack_storage = 0;
918 static const char delayed_import_loaders[] = "__wine_spec_delayed_import_loaders";
919 static const char delayed_import_thunks[] = "__wine_spec_delayed_import_thunks";
921 if (!nb_delayed) return;
923 output( "\n/* delayed import thunks */\n\n" );
924 output( "\t.text\n" );
925 output( "\t.align %d\n", get_alignment(8) );
926 output( "%s:\n", asm_name(delayed_import_loaders));
927 output( "\t%s\n", func_declaration("__wine_delay_load_asm") );
928 output( "%s:\n", asm_name("__wine_delay_load_asm") );
929 output_cfi( ".cfi_startproc" );
930 switch(target_cpu)
932 case CPU_x86:
933 output( "\tpushl %%ecx\n" );
934 output_cfi( ".cfi_adjust_cfa_offset 4" );
935 output( "\tpushl %%edx\n" );
936 output_cfi( ".cfi_adjust_cfa_offset 4" );
937 output( "\tpushl %%eax\n" );
938 output_cfi( ".cfi_adjust_cfa_offset 4" );
939 output( "\tcall %s\n", asm_name("__wine_spec_delay_load") );
940 output_cfi( ".cfi_adjust_cfa_offset -4" );
941 output( "\tpopl %%edx\n" );
942 output_cfi( ".cfi_adjust_cfa_offset -4" );
943 output( "\tpopl %%ecx\n" );
944 output_cfi( ".cfi_adjust_cfa_offset -4" );
945 output( "\tjmp *%%eax\n" );
946 break;
947 case CPU_x86_64:
948 output( "\tsubq $88,%%rsp\n" );
949 output_cfi( ".cfi_adjust_cfa_offset 88" );
950 output( "\tmovq %%rdx,80(%%rsp)\n" );
951 output( "\tmovq %%rcx,72(%%rsp)\n" );
952 output( "\tmovq %%r8,64(%%rsp)\n" );
953 output( "\tmovq %%r9,56(%%rsp)\n" );
954 output( "\tmovq %%r10,48(%%rsp)\n" );
955 output( "\tmovq %%r11,40(%%rsp)\n" );
956 output( "\tmovq %%rax,%%rcx\n" );
957 output( "\tcall %s\n", asm_name("__wine_spec_delay_load") );
958 output( "\tmovq 40(%%rsp),%%r11\n" );
959 output( "\tmovq 48(%%rsp),%%r10\n" );
960 output( "\tmovq 56(%%rsp),%%r9\n" );
961 output( "\tmovq 64(%%rsp),%%r8\n" );
962 output( "\tmovq 72(%%rsp),%%rcx\n" );
963 output( "\tmovq 80(%%rsp),%%rdx\n" );
964 output( "\taddq $88,%%rsp\n" );
965 output_cfi( ".cfi_adjust_cfa_offset -88" );
966 output( "\tjmp *%%rax\n" );
967 break;
968 case CPU_ARM:
969 output( "\tstmfd SP!, {r4-r10,FP,LR}\n" );
970 output( "\tmov LR,PC\n");
971 output( "\tadd LR,LR,#8\n");
972 output( "\tldr PC,[PC,#-4]\n");
973 output( "\t.long %s\n", asm_name("__wine_spec_delay_load") );
974 output( "\tmov IP,r0\n");
975 output( "\tldmfd SP!, {r4-r10,FP,LR}\n" );
976 output( "\tldmfd SP!, {r0-r3}\n" );
977 output( "\tmov PC,IP\n");
978 break;
979 case CPU_ARM64:
980 output( "\tstp x29, x30, [sp,#-16]!\n" );
981 output( "\tmov x29, sp\n" );
982 output( "\tadr x9, 1f\n" );
983 output( "\tldur x9, [x9, #0]\n" );
984 output( "\tblr x9\n" );
985 output( "\tmov x9, x0\n" );
986 output( "\tldp x29, x30, [sp],#16\n" );
987 output( "\tldp x0, x1, [sp,#16]\n" );
988 output( "\tldp x2, x3, [sp,#32]\n" );
989 output( "\tldp x4, x5, [sp,#48]\n" );
990 output( "\tldp x6, x7, [sp],#80\n" );
991 output( "\tbr x9\n" ); /* or "ret x9" */
992 output( "1:\t.quad %s\n", asm_name("__wine_spec_delay_load") );
993 break;
994 case CPU_POWERPC:
995 if (target_platform == PLATFORM_APPLE) extra_stack_storage = 56;
997 /* Save all callee saved registers into a stackframe. */
998 output( "\tstwu %s, -%d(%s)\n",ppc_reg(1), 48+extra_stack_storage, ppc_reg(1));
999 output( "\tstw %s, %d(%s)\n", ppc_reg(3), 4+extra_stack_storage, ppc_reg(1));
1000 output( "\tstw %s, %d(%s)\n", ppc_reg(4), 8+extra_stack_storage, ppc_reg(1));
1001 output( "\tstw %s, %d(%s)\n", ppc_reg(5), 12+extra_stack_storage, ppc_reg(1));
1002 output( "\tstw %s, %d(%s)\n", ppc_reg(6), 16+extra_stack_storage, ppc_reg(1));
1003 output( "\tstw %s, %d(%s)\n", ppc_reg(7), 20+extra_stack_storage, ppc_reg(1));
1004 output( "\tstw %s, %d(%s)\n", ppc_reg(8), 24+extra_stack_storage, ppc_reg(1));
1005 output( "\tstw %s, %d(%s)\n", ppc_reg(9), 28+extra_stack_storage, ppc_reg(1));
1006 output( "\tstw %s, %d(%s)\n", ppc_reg(10),32+extra_stack_storage, ppc_reg(1));
1007 output( "\tstw %s, %d(%s)\n", ppc_reg(11),36+extra_stack_storage, ppc_reg(1));
1008 output( "\tstw %s, %d(%s)\n", ppc_reg(12),40+extra_stack_storage, ppc_reg(1));
1010 /* r0 -> r3 (arg1) */
1011 output( "\tmr %s, %s\n", ppc_reg(3), ppc_reg(0));
1013 /* save return address */
1014 output( "\tmflr %s\n", ppc_reg(0));
1015 output( "\tstw %s, %d(%s)\n", ppc_reg(0), 44+extra_stack_storage, ppc_reg(1));
1017 /* Call the __wine_delay_load function, arg1 is arg1. */
1018 output( "\tbl %s\n", asm_name("__wine_spec_delay_load") );
1020 /* Load return value from call into ctr register */
1021 output( "\tmtctr %s\n", ppc_reg(3));
1023 /* restore all saved registers and drop stackframe. */
1024 output( "\tlwz %s, %d(%s)\n", ppc_reg(3), 4+extra_stack_storage, ppc_reg(1));
1025 output( "\tlwz %s, %d(%s)\n", ppc_reg(4), 8+extra_stack_storage, ppc_reg(1));
1026 output( "\tlwz %s, %d(%s)\n", ppc_reg(5), 12+extra_stack_storage, ppc_reg(1));
1027 output( "\tlwz %s, %d(%s)\n", ppc_reg(6), 16+extra_stack_storage, ppc_reg(1));
1028 output( "\tlwz %s, %d(%s)\n", ppc_reg(7), 20+extra_stack_storage, ppc_reg(1));
1029 output( "\tlwz %s, %d(%s)\n", ppc_reg(8), 24+extra_stack_storage, ppc_reg(1));
1030 output( "\tlwz %s, %d(%s)\n", ppc_reg(9), 28+extra_stack_storage, ppc_reg(1));
1031 output( "\tlwz %s, %d(%s)\n", ppc_reg(10),32+extra_stack_storage, ppc_reg(1));
1032 output( "\tlwz %s, %d(%s)\n", ppc_reg(11),36+extra_stack_storage, ppc_reg(1));
1033 output( "\tlwz %s, %d(%s)\n", ppc_reg(12),40+extra_stack_storage, ppc_reg(1));
1035 /* Load return value from call into return register */
1036 output( "\tlwz %s, %d(%s)\n", ppc_reg(0), 44+extra_stack_storage, ppc_reg(1));
1037 output( "\tmtlr %s\n", ppc_reg(0));
1038 output( "\taddi %s, %s, %d\n", ppc_reg(1), ppc_reg(1), 48+extra_stack_storage);
1040 /* branch to ctr register. */
1041 output( "\tbctr\n");
1042 break;
1044 output_cfi( ".cfi_endproc" );
1045 output_function_size( "__wine_delay_load_asm" );
1046 output( "\n" );
1048 for (i = idx = 0; i < nb_imports; i++)
1050 if (!dll_imports[i]->delay) continue;
1051 for (j = 0; j < dll_imports[i]->nb_imports; j++)
1053 ORDDEF *odp = dll_imports[i]->imports[j];
1054 const char *name = odp->name ? odp->name : odp->export_name;
1056 output( ".L__wine_delay_imp_%d_%s:\n", i, name );
1057 output_cfi( ".cfi_startproc" );
1058 switch(target_cpu)
1060 case CPU_x86:
1061 output( "\tmovl $%d, %%eax\n", (idx << 16) | j );
1062 output( "\tjmp %s\n", asm_name("__wine_delay_load_asm") );
1063 break;
1064 case CPU_x86_64:
1065 output( "\tmovq $%d,%%rax\n", (idx << 16) | j );
1066 output( "\tjmp %s\n", asm_name("__wine_delay_load_asm") );
1067 break;
1068 case CPU_ARM:
1069 output( "\tstmfd SP!, {r0-r3}\n" );
1070 output( "\tmov r0, #%d\n", idx );
1071 output( "\tmov r1, #16384\n" );
1072 output( "\tmul r1, r0, r1\n" );
1073 output( "\tmov r0, r1\n" );
1074 output( "\tmov r1, #4\n" );
1075 output( "\tmul r1, r0, r1\n" );
1076 output( "\tmov r0, r1\n" );
1077 output( "\tadd r0, #%d\n", j );
1078 output( "\tldr PC,[PC,#-4]\n");
1079 output( "\t.long %s\n", asm_name("__wine_delay_load_asm") );
1080 break;
1081 case CPU_ARM64:
1082 output( "\tstp x6, x7, [sp,#-80]!\n" );
1083 output( "\tstp x4, x5, [sp,#48]\n" );
1084 output( "\tstp x2, x3, [sp,#32]\n" );
1085 output( "\tstp x0, x1, [sp,#16]\n" );
1086 output( "\tmov x0, #%d\n", idx );
1087 output( "\tmov x1, #16384\n" );
1088 output( "\tmul x1, x0, x1\n" );
1089 output( "\tmov x0, x1\n" );
1090 output( "\tmov x1, #4\n" );
1091 output( "\tmul x1, x0, x1\n" );
1092 output( "\tmov x0, x1\n" );
1093 output( "\tadd x0, x0, #%d\n", j );
1094 output( "\tadr x9, 1f\n" );
1095 output( "\tldur x9, [x9, #0]\n" );
1096 output( "\tbr x9\n" );
1097 output( "1:\t.quad %s\n", asm_name("__wine_delay_load_asm") );
1098 break;
1099 case CPU_POWERPC:
1100 switch(target_platform)
1102 case PLATFORM_APPLE:
1103 /* On Darwin we can use r0 and r2 */
1104 /* Upper part in r2 */
1105 output( "\tlis %s, %d\n", ppc_reg(2), idx);
1106 /* Lower part + r2 -> r0, Note we can't use r0 directly */
1107 output( "\taddi %s, %s, %d\n", ppc_reg(0), ppc_reg(2), j);
1108 output( "\tb %s\n", asm_name("__wine_delay_load_asm") );
1109 break;
1110 default:
1111 /* On linux we can't use r2 since r2 is not a scratch register (hold the TOC) */
1112 /* Save r13 on the stack */
1113 output( "\taddi %s, %s, -0x4\n", ppc_reg(1), ppc_reg(1));
1114 output( "\tstw %s, 0(%s)\n", ppc_reg(13), ppc_reg(1));
1115 /* Upper part in r13 */
1116 output( "\tlis %s, %d\n", ppc_reg(13), idx);
1117 /* Lower part + r13 -> r0, Note we can't use r0 directly */
1118 output( "\taddi %s, %s, %d\n", ppc_reg(0), ppc_reg(13), j);
1119 /* Restore r13 */
1120 output( "\tstw %s, 0(%s)\n", ppc_reg(13), ppc_reg(1));
1121 output( "\taddic %s, %s, 0x4\n", ppc_reg(1), ppc_reg(1));
1122 output( "\tb %s\n", asm_name("__wine_delay_load_asm") );
1123 break;
1125 break;
1127 output_cfi( ".cfi_endproc" );
1129 idx++;
1131 output_function_size( delayed_import_loaders );
1133 output( "\n\t.align %d\n", get_alignment(get_ptr_size()) );
1134 output( "%s:\n", asm_name(delayed_import_thunks));
1135 for (i = pos = 0; i < nb_imports; i++)
1137 if (!dll_imports[i]->delay) continue;
1138 for (j = 0; j < dll_imports[i]->nb_imports; j++, pos += get_ptr_size())
1140 ORDDEF *odp = dll_imports[i]->imports[j];
1141 output_import_thunk( odp->name ? odp->name : odp->export_name,
1142 ".L__wine_delay_IAT", pos );
1145 output_function_size( delayed_import_thunks );
1148 /* output import stubs for exported entry points that link to external symbols */
1149 static void output_external_link_imports( DLLSPEC *spec )
1151 unsigned int i, pos;
1153 if (!ext_link_imports.count) return; /* nothing to do */
1155 sort_names( &ext_link_imports );
1157 /* get rid of duplicate names */
1158 for (i = 1; i < ext_link_imports.count; i++)
1160 if (!strcmp( ext_link_imports.names[i-1], ext_link_imports.names[i] ))
1161 remove_name( &ext_link_imports, i-- );
1164 output( "\n/* external link thunks */\n\n" );
1165 output( "\t.data\n" );
1166 output( "\t.align %d\n", get_alignment(get_ptr_size()) );
1167 output( ".L__wine_spec_external_links:\n" );
1168 for (i = 0; i < ext_link_imports.count; i++)
1169 output( "\t%s %s\n", get_asm_ptr_keyword(), asm_name(ext_link_imports.names[i]) );
1171 output( "\n\t.text\n" );
1172 output( "\t.align %d\n", get_alignment(get_ptr_size()) );
1173 output( "%s:\n", asm_name("__wine_spec_external_link_thunks") );
1175 for (i = pos = 0; i < ext_link_imports.count; i++)
1177 char *buffer = strmake( "__wine_spec_ext_link_%s", ext_link_imports.names[i] );
1178 output_import_thunk( buffer, ".L__wine_spec_external_links", pos );
1179 free( buffer );
1180 pos += get_ptr_size();
1182 output_function_size( "__wine_spec_external_link_thunks" );
1185 /*******************************************************************
1186 * output_stubs
1188 * Output the functions for stub entry points
1190 void output_stubs( DLLSPEC *spec )
1192 const char *name, *exp_name;
1193 int i, count;
1195 if (!has_stubs( spec )) return;
1197 output( "\n/* stub functions */\n\n" );
1198 output( "\t.text\n" );
1200 for (i = count = 0; i < spec->nb_entry_points; i++)
1202 ORDDEF *odp = &spec->entry_points[i];
1203 if (odp->type != TYPE_STUB) continue;
1205 name = get_stub_name( odp, spec );
1206 exp_name = odp->name ? odp->name : odp->export_name;
1207 output( "\t.align %d\n", get_alignment(4) );
1208 output( "\t%s\n", func_declaration(name) );
1209 output( "%s:\n", asm_name(name) );
1210 output_cfi( ".cfi_startproc" );
1212 switch (target_cpu)
1214 case CPU_x86:
1215 /* flesh out the stub a bit to make safedisc happy */
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" );
1223 output(" \tnop\n" );
1224 output(" \tnop\n" );
1226 output( "\tsubl $12,%%esp\n" );
1227 output_cfi( ".cfi_adjust_cfa_offset 12" );
1228 if (UsePIC)
1230 output( "\tcall %s\n", asm_name("__wine_spec_get_pc_thunk_eax") );
1231 output( "1:" );
1232 if (exp_name)
1234 output( "\tleal .L%s_string-1b(%%eax),%%ecx\n", name );
1235 output( "\tmovl %%ecx,4(%%esp)\n" );
1236 count++;
1238 else
1239 output( "\tmovl $%d,4(%%esp)\n", odp->ordinal );
1240 output( "\tleal .L__wine_spec_file_name-1b(%%eax),%%ecx\n" );
1241 output( "\tmovl %%ecx,(%%esp)\n" );
1243 else
1245 if (exp_name)
1247 output( "\tmovl $.L%s_string,4(%%esp)\n", name );
1248 count++;
1250 else
1251 output( "\tmovl $%d,4(%%esp)\n", odp->ordinal );
1252 output( "\tmovl $.L__wine_spec_file_name,(%%esp)\n" );
1254 output( "\tcall %s\n", asm_name("__wine_spec_unimplemented_stub") );
1255 break;
1256 case CPU_x86_64:
1257 output( "\tsubq $8,%%rsp\n" );
1258 output_cfi( ".cfi_adjust_cfa_offset 8" );
1259 output( "\tleaq .L__wine_spec_file_name(%%rip),%%rdi\n" );
1260 if (exp_name)
1262 output( "leaq .L%s_string(%%rip),%%rsi\n", name );
1263 count++;
1265 else
1266 output( "\tmovq $%d,%%rsi\n", odp->ordinal );
1267 output( "\tcall %s\n", asm_name("__wine_spec_unimplemented_stub") );
1268 break;
1269 case CPU_ARM:
1270 output( "\tldr r0,[PC,#0]\n");
1271 output( "\tmov PC,PC\n");
1272 output( "\t.long .L__wine_spec_file_name\n" );
1273 output( "\tldr r1,[PC,#0]\n");
1274 output( "\tmov PC,PC\n");
1275 if (exp_name)
1277 output( "\t.long .L%s_string\n", name );
1278 count++;
1280 else
1281 output( "\t.long %d\n", odp->ordinal );
1282 output( "\tbl %s\n", asm_name("__wine_spec_unimplemented_stub") );
1283 break;
1284 default:
1285 assert(0);
1287 output_cfi( ".cfi_endproc" );
1288 output_function_size( name );
1291 if (count)
1293 output( "\t%s\n", get_asm_string_section() );
1294 for (i = 0; i < spec->nb_entry_points; i++)
1296 ORDDEF *odp = &spec->entry_points[i];
1297 if (odp->type != TYPE_STUB) continue;
1298 exp_name = odp->name ? odp->name : odp->export_name;
1299 if (exp_name)
1301 name = get_stub_name( odp, spec );
1302 output( ".L%s_string:\n", name );
1303 output( "\t%s \"%s\"\n", get_asm_string_keyword(), exp_name );
1309 /* output the import and delayed import tables of a Win32 module */
1310 void output_imports( DLLSPEC *spec )
1312 output_immediate_imports();
1313 output_delayed_imports( spec );
1314 output_immediate_import_thunks();
1315 output_delayed_import_thunks( spec );
1316 output_external_link_imports( spec );
1317 if (nb_imports || ext_link_imports.count || has_stubs(spec) || has_relays(spec))
1318 output_get_pc_thunk();
1321 /* output an import library for a Win32 module and additional object files */
1322 void output_import_lib( DLLSPEC *spec, char **argv )
1324 struct strarray *args = strarray_init();
1325 char *def_file;
1327 if (target_platform != PLATFORM_WINDOWS)
1328 fatal_error( "Unix-style import libraries not supported yet\n" );
1330 def_file = get_temp_file_name( output_file_name, ".def" );
1331 fclose( output_file );
1332 if (!(output_file = fopen( def_file, "w" )))
1333 fatal_error( "Unable to create output file '%s'\n", def_file );
1334 output_def_file( spec, 0 );
1335 fclose( output_file );
1336 output_file = NULL;
1338 strarray_add( args, find_tool( "dlltool", NULL ), "-k", "-l", output_file_name, "-d", def_file, NULL );
1339 spawn( args );
1340 strarray_free( args );
1342 if (argv[0])
1344 args = strarray_init();
1345 strarray_add( args, find_tool( "ar", NULL ), "rs", output_file_name, NULL );
1346 strarray_addv( args, argv );
1347 spawn( args );
1348 strarray_free( args );
1350 output_file_name = NULL;