2000-09-28 01:40:43 +02:00
|
|
|
/*
|
|
|
|
* DLL imports support
|
|
|
|
*
|
2004-02-17 21:36:16 +01:00
|
|
|
* Copyright 2000, 2004 Alexandre Julliard
|
|
|
|
* Copyright 2000 Eric Pouech
|
2002-03-10 00:29:33 +01:00
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
2006-05-18 14:49:52 +02:00
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
2000-09-28 01:40:43 +02:00
|
|
|
*/
|
|
|
|
|
2001-10-14 18:18:52 +02:00
|
|
|
#include "config.h"
|
2002-04-25 23:40:56 +02:00
|
|
|
#include "wine/port.h"
|
2001-10-14 18:18:52 +02:00
|
|
|
|
2005-08-19 12:25:22 +02:00
|
|
|
#include <assert.h>
|
2002-07-25 02:25:40 +02:00
|
|
|
#include <ctype.h>
|
2000-09-28 01:40:43 +02:00
|
|
|
#include <fcntl.h>
|
|
|
|
#include <stdio.h>
|
2001-01-22 03:17:29 +01:00
|
|
|
#include <string.h>
|
2004-03-25 01:40:52 +01:00
|
|
|
#include <stdarg.h>
|
2005-05-06 17:54:41 +02:00
|
|
|
#ifdef HAVE_SYS_STAT_H
|
|
|
|
# include <sys/stat.h>
|
|
|
|
#endif
|
2002-08-17 20:28:43 +02:00
|
|
|
#ifdef HAVE_UNISTD_H
|
|
|
|
# include <unistd.h>
|
|
|
|
#endif
|
2000-09-28 01:40:43 +02:00
|
|
|
|
|
|
|
#include "build.h"
|
|
|
|
|
|
|
|
struct import
|
|
|
|
{
|
2005-05-06 17:54:41 +02:00
|
|
|
DLLSPEC *spec; /* description of the imported dll */
|
|
|
|
char *full_name; /* full name of the input file */
|
|
|
|
dev_t dev; /* device/inode of the input file */
|
|
|
|
ino_t ino;
|
2000-12-26 02:22:34 +01:00
|
|
|
int delay; /* delay or not dll loading ? */
|
2004-02-17 21:36:16 +01:00
|
|
|
ORDDEF **exports; /* functions exported from this dll */
|
2000-11-09 21:31:18 +01:00
|
|
|
int nb_exports; /* number of exported functions */
|
2004-02-17 21:36:16 +01:00
|
|
|
ORDDEF **imports; /* functions we want to import from this dll */
|
2000-09-28 01:40:43 +02:00
|
|
|
int nb_imports; /* number of imported functions */
|
|
|
|
};
|
|
|
|
|
2005-08-19 12:25:22 +02:00
|
|
|
struct name_table
|
|
|
|
{
|
|
|
|
char **names;
|
|
|
|
unsigned int count, size;
|
|
|
|
};
|
2000-09-28 01:40:43 +02:00
|
|
|
|
2005-08-19 12:25:22 +02:00
|
|
|
static struct name_table undef_symbols; /* list of undefined symbols */
|
|
|
|
static struct name_table ignore_symbols; /* list of symbols to ignore */
|
2005-08-19 13:28:56 +02:00
|
|
|
static struct name_table extra_ld_symbols; /* list of extra symbols that ld should resolve */
|
2005-08-19 12:25:22 +02:00
|
|
|
static struct name_table delayed_imports; /* list of delayed import dlls */
|
2005-09-19 19:04:43 +02:00
|
|
|
static struct name_table ext_link_imports; /* list of external symbols to link to */
|
2000-12-14 23:18:22 +01:00
|
|
|
|
2000-09-28 01:40:43 +02:00
|
|
|
static struct import **dll_imports = NULL;
|
2000-12-26 02:22:34 +01:00
|
|
|
static int nb_imports = 0; /* number of imported dlls (delayed or not) */
|
|
|
|
static int nb_delayed = 0; /* number of delayed dlls */
|
|
|
|
static int total_imports = 0; /* total number of imported functions */
|
|
|
|
static int total_delayed = 0; /* total number of imported functions in delayed DLLs */
|
2000-09-28 01:40:43 +02:00
|
|
|
|
2005-06-27 13:23:24 +02:00
|
|
|
|
|
|
|
static inline const char *ppc_reg( int reg )
|
|
|
|
{
|
|
|
|
static const char * const ppc_regs[32] = { "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7",
|
|
|
|
"r8", "r9", "r10","r11","r12","r13","r14","r15",
|
|
|
|
"r16","r17","r18","r19","r20","r21","r22","r23",
|
|
|
|
"r24","r25","r26","r27","r28","r29","r30","r31" };
|
|
|
|
if (target_platform == PLATFORM_APPLE) return ppc_regs[reg];
|
|
|
|
return ppc_regs[reg] + 1; /* skip the 'r' */
|
|
|
|
}
|
2003-08-13 23:57:42 +02:00
|
|
|
|
2000-11-09 21:31:18 +01:00
|
|
|
/* compare function names; helper for resolve_imports */
|
|
|
|
static int name_cmp( const void *name, const void *entry )
|
|
|
|
{
|
2004-05-18 23:27:44 +02:00
|
|
|
return strcmp( *(const char* const *)name, *(const char* const *)entry );
|
2000-11-09 21:31:18 +01:00
|
|
|
}
|
|
|
|
|
2002-07-25 02:25:40 +02:00
|
|
|
/* compare function names; helper for resolve_imports */
|
|
|
|
static int func_cmp( const void *func1, const void *func2 )
|
|
|
|
{
|
2004-05-18 23:27:44 +02:00
|
|
|
const ORDDEF *odp1 = *(const ORDDEF * const *)func1;
|
|
|
|
const ORDDEF *odp2 = *(const ORDDEF * const *)func2;
|
2004-02-17 21:36:16 +01:00
|
|
|
return strcmp( odp1->name ? odp1->name : odp1->export_name,
|
|
|
|
odp2->name ? odp2->name : odp2->export_name );
|
2002-07-25 02:25:40 +02:00
|
|
|
}
|
|
|
|
|
2005-08-19 12:25:22 +02:00
|
|
|
/* add a name to a name table */
|
2007-03-17 11:54:52 +01:00
|
|
|
static inline void add_name( struct name_table *table, const char *name )
|
2000-11-09 21:31:18 +01:00
|
|
|
{
|
2005-08-19 12:25:22 +02:00
|
|
|
if (table->count == table->size)
|
|
|
|
{
|
|
|
|
table->size += (table->size / 2);
|
|
|
|
if (table->size < 32) table->size = 32;
|
|
|
|
table->names = xrealloc( table->names, table->size * sizeof(*table->names) );
|
2000-12-18 04:13:52 +01:00
|
|
|
}
|
2005-08-19 12:25:22 +02:00
|
|
|
table->names[table->count++] = xstrdup( name );
|
|
|
|
}
|
|
|
|
|
|
|
|
/* remove a name from a name table */
|
2007-03-17 11:54:52 +01:00
|
|
|
static inline void remove_name( struct name_table *table, unsigned int idx )
|
2005-08-19 12:25:22 +02:00
|
|
|
{
|
|
|
|
assert( idx < table->count );
|
|
|
|
free( table->names[idx] );
|
|
|
|
memmove( table->names + idx, table->names + idx + 1,
|
|
|
|
(table->count - idx - 1) * sizeof(*table->names) );
|
|
|
|
table->count--;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* make a name table empty */
|
2007-03-17 11:54:52 +01:00
|
|
|
static inline void empty_name_table( struct name_table *table )
|
2005-08-19 12:25:22 +02:00
|
|
|
{
|
|
|
|
unsigned int i;
|
|
|
|
|
|
|
|
for (i = 0; i < table->count; i++) free( table->names[i] );
|
|
|
|
table->count = 0;
|
|
|
|
}
|
2000-12-18 04:13:52 +01:00
|
|
|
|
2005-08-19 12:25:22 +02:00
|
|
|
/* locate a name in a (sorted) list */
|
2007-03-17 11:54:52 +01:00
|
|
|
static inline const char *find_name( const char *name, const struct name_table *table )
|
2005-08-19 12:25:22 +02:00
|
|
|
{
|
|
|
|
char **res = NULL;
|
|
|
|
|
|
|
|
if (table->count) res = bsearch( &name, table->names, table->count, sizeof(*table->names), name_cmp );
|
2000-11-09 21:31:18 +01:00
|
|
|
return res ? *res : NULL;
|
|
|
|
}
|
|
|
|
|
2005-08-19 12:25:22 +02:00
|
|
|
/* sort a name table */
|
2007-03-17 11:54:52 +01:00
|
|
|
static inline void sort_names( struct name_table *table )
|
2005-08-19 12:25:22 +02:00
|
|
|
{
|
|
|
|
if (table->count) qsort( table->names, table->count, sizeof(*table->names), name_cmp );
|
|
|
|
}
|
|
|
|
|
2002-07-25 02:25:40 +02:00
|
|
|
/* locate an export in a (sorted) export list */
|
2007-03-17 11:54:52 +01:00
|
|
|
static inline ORDDEF *find_export( const char *name, ORDDEF **table, int size )
|
2002-07-25 02:25:40 +02:00
|
|
|
{
|
2004-02-17 21:36:16 +01:00
|
|
|
ORDDEF func, *odp, **res = NULL;
|
2002-07-25 02:25:40 +02:00
|
|
|
|
2006-10-11 16:11:04 +02:00
|
|
|
func.name = xstrdup(name);
|
2002-07-25 02:25:40 +02:00
|
|
|
func.ordinal = -1;
|
2004-02-17 21:36:16 +01:00
|
|
|
odp = &func;
|
|
|
|
if (table) res = bsearch( &odp, table, size, sizeof(*table), func_cmp );
|
2006-10-11 16:11:04 +02:00
|
|
|
free( func.name );
|
2004-02-17 21:36:16 +01:00
|
|
|
return res ? *res : NULL;
|
2002-07-25 02:25:40 +02:00
|
|
|
}
|
|
|
|
|
2002-12-12 23:03:14 +01:00
|
|
|
/* free an import structure */
|
|
|
|
static void free_imports( struct import *imp )
|
|
|
|
{
|
|
|
|
free( imp->exports );
|
|
|
|
free( imp->imports );
|
2004-02-17 21:36:16 +01:00
|
|
|
free_dll_spec( imp->spec );
|
2005-05-06 17:54:41 +02:00
|
|
|
free( imp->full_name );
|
2002-12-12 23:03:14 +01:00
|
|
|
free( imp );
|
|
|
|
}
|
|
|
|
|
2005-05-06 17:54:41 +02:00
|
|
|
/* check whether a given dll is imported in delayed mode */
|
|
|
|
static int is_delayed_import( const char *name )
|
|
|
|
{
|
2007-03-03 14:30:03 +01:00
|
|
|
unsigned int i;
|
2005-05-06 17:54:41 +02:00
|
|
|
|
2005-08-19 12:25:22 +02:00
|
|
|
for (i = 0; i < delayed_imports.count; i++)
|
2005-05-06 17:54:41 +02:00
|
|
|
{
|
2005-08-19 12:25:22 +02:00
|
|
|
if (!strcmp( delayed_imports.names[i], name )) return 1;
|
2005-05-06 17:54:41 +02:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2002-12-12 23:03:14 +01:00
|
|
|
/* check whether a given dll has already been imported */
|
2005-05-06 17:54:41 +02:00
|
|
|
static struct import *is_already_imported( const char *name )
|
2002-12-12 23:03:14 +01:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < nb_imports; i++)
|
|
|
|
{
|
2005-05-06 17:54:41 +02:00
|
|
|
if (!strcmp( dll_imports[i]->spec->file_name, name )) return dll_imports[i];
|
2002-12-12 23:03:14 +01:00
|
|
|
}
|
2005-05-06 17:54:41 +02:00
|
|
|
return NULL;
|
2002-12-12 23:03:14 +01:00
|
|
|
}
|
|
|
|
|
2000-11-09 21:31:18 +01:00
|
|
|
/* open the .so library for a given dll in a specified path */
|
|
|
|
static char *try_library_path( const char *path, const char *name )
|
|
|
|
{
|
2002-03-20 23:19:06 +01:00
|
|
|
char *buffer;
|
2000-11-09 21:31:18 +01:00
|
|
|
int fd;
|
|
|
|
|
2002-03-20 23:19:06 +01:00
|
|
|
buffer = xmalloc( strlen(path) + strlen(name) + 9 );
|
2002-12-12 23:03:14 +01:00
|
|
|
sprintf( buffer, "%s/lib%s.def", path, name );
|
|
|
|
|
2000-11-09 21:31:18 +01:00
|
|
|
/* check if the file exists */
|
2002-03-20 23:19:06 +01:00
|
|
|
if ((fd = open( buffer, O_RDONLY )) != -1)
|
|
|
|
{
|
|
|
|
close( fd );
|
|
|
|
return buffer;
|
|
|
|
}
|
|
|
|
free( buffer );
|
|
|
|
return NULL;
|
2000-11-09 21:31:18 +01:00
|
|
|
}
|
|
|
|
|
2005-05-06 17:54:41 +02:00
|
|
|
/* find the .def import library for a given dll */
|
|
|
|
static char *find_library( const char *name )
|
2000-11-09 21:31:18 +01:00
|
|
|
{
|
|
|
|
char *fullname;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < nb_lib_paths; i++)
|
|
|
|
{
|
|
|
|
if ((fullname = try_library_path( lib_path[i], name ))) return fullname;
|
|
|
|
}
|
2004-03-17 21:48:44 +01:00
|
|
|
fatal_error( "could not open .def file for %s\n", name );
|
|
|
|
return NULL;
|
2000-11-09 21:31:18 +01:00
|
|
|
}
|
|
|
|
|
2002-12-12 23:03:14 +01:00
|
|
|
/* read in the list of exported symbols of an import library */
|
2005-05-06 17:54:41 +02:00
|
|
|
static int read_import_lib( struct import *imp )
|
2000-11-09 21:31:18 +01:00
|
|
|
{
|
|
|
|
FILE *f;
|
2004-02-17 21:36:16 +01:00
|
|
|
int i, ret;
|
2005-05-06 17:54:41 +02:00
|
|
|
struct stat stat;
|
|
|
|
struct import *prev_imp;
|
2004-02-17 21:36:16 +01:00
|
|
|
DLLSPEC *spec = imp->spec;
|
2000-11-09 21:31:18 +01:00
|
|
|
|
2005-05-06 17:54:41 +02:00
|
|
|
f = open_input_file( NULL, imp->full_name );
|
|
|
|
fstat( fileno(f), &stat );
|
|
|
|
imp->dev = stat.st_dev;
|
|
|
|
imp->ino = stat.st_ino;
|
2004-02-17 21:36:16 +01:00
|
|
|
ret = parse_def_file( f, spec );
|
|
|
|
close_input_file( f );
|
|
|
|
if (!ret) return 0;
|
2005-05-06 17:54:41 +02:00
|
|
|
|
|
|
|
/* check if we already imported that library from a different file */
|
|
|
|
if ((prev_imp = is_already_imported( spec->file_name )))
|
|
|
|
{
|
|
|
|
if (prev_imp->dev != imp->dev || prev_imp->ino != imp->ino)
|
|
|
|
fatal_error( "%s and %s have the same export name '%s'\n",
|
|
|
|
prev_imp->full_name, imp->full_name, spec->file_name );
|
|
|
|
return 0; /* the same file was already loaded, ignore this one */
|
|
|
|
}
|
|
|
|
|
|
|
|
if (is_delayed_import( spec->file_name ))
|
|
|
|
{
|
|
|
|
imp->delay = 1;
|
|
|
|
nb_delayed++;
|
|
|
|
}
|
2002-12-12 23:03:14 +01:00
|
|
|
|
2007-12-06 21:14:07 +01:00
|
|
|
if (spec->nb_entry_points)
|
2004-02-17 21:36:16 +01:00
|
|
|
{
|
2007-12-06 21:14:07 +01:00
|
|
|
imp->exports = xmalloc( spec->nb_entry_points * sizeof(*imp->exports) );
|
|
|
|
for (i = 0; i < spec->nb_entry_points; i++)
|
|
|
|
imp->exports[imp->nb_exports++] = &spec->entry_points[i];
|
2002-07-25 02:25:40 +02:00
|
|
|
qsort( imp->exports, imp->nb_exports, sizeof(*imp->exports), func_cmp );
|
2007-12-06 21:14:07 +01:00
|
|
|
}
|
2004-02-17 21:36:16 +01:00
|
|
|
return 1;
|
2000-11-09 21:31:18 +01:00
|
|
|
}
|
|
|
|
|
2005-05-06 17:54:41 +02:00
|
|
|
/* build the dll exported name from the import lib name or path */
|
|
|
|
static char *get_dll_name( const char *name, const char *filename )
|
2000-09-28 01:40:43 +02:00
|
|
|
{
|
2005-05-06 17:54:41 +02:00
|
|
|
char *ret;
|
2002-05-09 02:05:48 +02:00
|
|
|
|
2005-05-06 17:54:41 +02:00
|
|
|
if (filename)
|
|
|
|
{
|
|
|
|
const char *basename = strrchr( filename, '/' );
|
|
|
|
if (!basename) basename = filename;
|
|
|
|
else basename++;
|
|
|
|
if (!strncmp( basename, "lib", 3 )) basename += 3;
|
|
|
|
ret = xmalloc( strlen(basename) + 5 );
|
|
|
|
strcpy( ret, basename );
|
|
|
|
if (strendswith( ret, ".def" )) ret[strlen(ret)-4] = 0;
|
|
|
|
}
|
|
|
|
else
|
2002-05-12 01:06:32 +02:00
|
|
|
{
|
2005-05-06 17:54:41 +02:00
|
|
|
ret = xmalloc( strlen(name) + 5 );
|
|
|
|
strcpy( ret, name );
|
2002-05-12 01:06:32 +02:00
|
|
|
}
|
2005-05-06 17:54:41 +02:00
|
|
|
if (!strchr( ret, '.' )) strcat( ret, ".dll" );
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* add a dll to the list of imports */
|
|
|
|
void add_import_dll( const char *name, const char *filename )
|
|
|
|
{
|
|
|
|
struct import *imp = xmalloc( sizeof(*imp) );
|
2002-05-09 02:05:48 +02:00
|
|
|
|
2004-02-17 21:36:16 +01:00
|
|
|
imp->spec = alloc_dll_spec();
|
2005-05-06 17:54:41 +02:00
|
|
|
imp->spec->file_name = get_dll_name( name, filename );
|
|
|
|
imp->delay = 0;
|
2004-02-17 21:36:16 +01:00
|
|
|
imp->imports = NULL;
|
|
|
|
imp->nb_imports = 0;
|
2005-05-06 17:54:41 +02:00
|
|
|
imp->exports = NULL;
|
|
|
|
imp->nb_exports = 0;
|
|
|
|
|
|
|
|
if (filename) imp->full_name = xstrdup( filename );
|
|
|
|
else imp->full_name = find_library( name );
|
2000-11-09 21:31:18 +01:00
|
|
|
|
2005-05-06 17:54:41 +02:00
|
|
|
if (read_import_lib( imp ))
|
2002-12-12 23:03:14 +01:00
|
|
|
{
|
|
|
|
dll_imports = xrealloc( dll_imports, (nb_imports+1) * sizeof(*dll_imports) );
|
|
|
|
dll_imports[nb_imports++] = imp;
|
|
|
|
}
|
2003-03-18 06:30:54 +01:00
|
|
|
else
|
|
|
|
{
|
|
|
|
free_imports( imp );
|
|
|
|
if (nb_errors) exit(1);
|
|
|
|
}
|
2000-09-28 01:40:43 +02:00
|
|
|
}
|
|
|
|
|
2005-05-06 17:54:41 +02:00
|
|
|
/* add a library to the list of delayed imports */
|
|
|
|
void add_delayed_import( const char *name )
|
|
|
|
{
|
|
|
|
struct import *imp;
|
|
|
|
char *fullname = get_dll_name( name, NULL );
|
|
|
|
|
2005-08-19 12:25:22 +02:00
|
|
|
add_name( &delayed_imports, fullname );
|
2005-05-06 17:54:41 +02:00
|
|
|
if ((imp = is_already_imported( fullname )) && !imp->delay)
|
|
|
|
{
|
|
|
|
imp->delay = 1;
|
|
|
|
nb_delayed++;
|
|
|
|
}
|
2005-08-19 12:25:22 +02:00
|
|
|
free( fullname );
|
2005-05-06 17:54:41 +02:00
|
|
|
}
|
|
|
|
|
2003-03-17 00:59:48 +01:00
|
|
|
/* remove an imported dll, based on its index in the dll_imports array */
|
|
|
|
static void remove_import_dll( int index )
|
|
|
|
{
|
|
|
|
struct import *imp = dll_imports[index];
|
|
|
|
|
|
|
|
memmove( &dll_imports[index], &dll_imports[index+1], sizeof(imp) * (nb_imports - index - 1) );
|
|
|
|
nb_imports--;
|
|
|
|
if (imp->delay) nb_delayed--;
|
|
|
|
free_imports( imp );
|
|
|
|
}
|
|
|
|
|
2002-12-12 03:20:47 +01:00
|
|
|
/* add a symbol to the ignored symbol list */
|
|
|
|
/* if the name starts with '-' the symbol is removed instead */
|
2000-12-14 23:18:22 +01:00
|
|
|
void add_ignore_symbol( const char *name )
|
|
|
|
{
|
2005-08-19 12:25:22 +02:00
|
|
|
unsigned int i;
|
2002-12-12 03:20:47 +01:00
|
|
|
|
|
|
|
if (name[0] == '-') /* remove it */
|
2000-12-14 23:18:22 +01:00
|
|
|
{
|
2005-08-19 12:25:22 +02:00
|
|
|
if (!name[1]) empty_name_table( &ignore_symbols ); /* remove everything */
|
|
|
|
else for (i = 0; i < ignore_symbols.count; i++)
|
2002-12-12 03:20:47 +01:00
|
|
|
{
|
2005-08-19 12:25:22 +02:00
|
|
|
if (!strcmp( ignore_symbols.names[i], name+1 )) remove_name( &ignore_symbols, i-- );
|
2002-12-12 03:20:47 +01:00
|
|
|
}
|
2000-12-14 23:18:22 +01:00
|
|
|
}
|
2005-08-19 12:25:22 +02:00
|
|
|
else add_name( &ignore_symbols, name );
|
2000-12-14 23:18:22 +01:00
|
|
|
}
|
|
|
|
|
2005-08-19 13:28:56 +02:00
|
|
|
/* add a symbol to the list of extra symbols that ld must resolve */
|
|
|
|
void add_extra_ld_symbol( const char *name )
|
|
|
|
{
|
|
|
|
add_name( &extra_ld_symbols, name );
|
|
|
|
}
|
|
|
|
|
2000-09-28 01:40:43 +02:00
|
|
|
/* add a function to the list of imports from a given dll */
|
2004-02-17 21:36:16 +01:00
|
|
|
static void add_import_func( struct import *imp, ORDDEF *func )
|
2000-09-28 01:40:43 +02:00
|
|
|
{
|
|
|
|
imp->imports = xrealloc( imp->imports, (imp->nb_imports+1) * sizeof(*imp->imports) );
|
2004-02-17 21:36:16 +01:00
|
|
|
imp->imports[imp->nb_imports++] = func;
|
2000-09-28 01:40:43 +02:00
|
|
|
total_imports++;
|
2000-12-26 02:22:34 +01:00
|
|
|
if (imp->delay) total_delayed++;
|
2000-09-28 01:40:43 +02:00
|
|
|
}
|
2000-11-09 21:31:18 +01:00
|
|
|
|
2005-08-29 16:16:27 +02:00
|
|
|
/* get the default entry point for a given spec file */
|
|
|
|
static const char *get_default_entry_point( const DLLSPEC *spec )
|
2000-11-09 21:31:18 +01:00
|
|
|
{
|
2005-08-29 16:16:27 +02:00
|
|
|
if (spec->characteristics & IMAGE_FILE_DLL) return "__wine_spec_dll_entry";
|
2005-09-02 17:19:42 +02:00
|
|
|
if (spec->subsystem == IMAGE_SUBSYSTEM_NATIVE) return "__wine_spec_drv_entry";
|
2009-02-24 18:02:15 +01:00
|
|
|
if (spec->type == SPEC_WIN16) return "__wine_spec_exe16_entry";
|
2005-08-29 16:16:27 +02:00
|
|
|
return "__wine_spec_exe_entry";
|
|
|
|
}
|
2001-12-11 01:50:33 +01:00
|
|
|
|
2005-09-21 12:57:04 +02:00
|
|
|
/* check if the spec file exports any stubs */
|
|
|
|
static int has_stubs( const DLLSPEC *spec )
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
for (i = 0; i < spec->nb_entry_points; i++)
|
|
|
|
{
|
|
|
|
ORDDEF *odp = &spec->entry_points[i];
|
|
|
|
if (odp->type == TYPE_STUB) return 1;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2005-08-29 16:16:27 +02:00
|
|
|
/* add the extra undefined symbols that will be contained in the generated spec file itself */
|
|
|
|
static void add_extra_undef_symbols( DLLSPEC *spec )
|
|
|
|
{
|
|
|
|
if (!spec->init_func) spec->init_func = xstrdup( get_default_entry_point(spec) );
|
|
|
|
add_extra_ld_symbol( spec->init_func );
|
|
|
|
if (has_stubs( spec )) add_extra_ld_symbol( "__wine_spec_unimplemented_stub" );
|
|
|
|
if (nb_delayed) add_extra_ld_symbol( "__wine_spec_delay_load" );
|
2000-11-09 21:31:18 +01:00
|
|
|
}
|
|
|
|
|
2003-03-17 00:59:48 +01:00
|
|
|
/* check if a given imported dll is not needed, taking forwards into account */
|
2004-02-11 07:41:01 +01:00
|
|
|
static int check_unused( const struct import* imp, const DLLSPEC *spec )
|
2000-11-13 05:46:34 +01:00
|
|
|
{
|
2002-08-28 00:29:26 +02:00
|
|
|
int i;
|
2004-02-17 21:36:16 +01:00
|
|
|
const char *file_name = imp->spec->file_name;
|
|
|
|
size_t len = strlen( file_name );
|
|
|
|
const char *p = strchr( file_name, '.' );
|
|
|
|
if (p && !strcasecmp( p, ".dll" )) len = p - file_name;
|
2000-11-13 05:46:34 +01:00
|
|
|
|
2004-02-11 07:41:01 +01:00
|
|
|
for (i = spec->base; i <= spec->limit; i++)
|
2000-11-13 05:46:34 +01:00
|
|
|
{
|
2004-02-11 07:41:01 +01:00
|
|
|
ORDDEF *odp = spec->ordinals[i];
|
2002-12-15 02:22:40 +01:00
|
|
|
if (!odp || !(odp->flags & FLAG_FORWARD)) continue;
|
2004-02-17 21:36:16 +01:00
|
|
|
if (!strncasecmp( odp->link_name, file_name, len ) &&
|
2000-12-16 00:04:40 +01:00
|
|
|
odp->link_name[len] == '.')
|
2003-03-17 00:59:48 +01:00
|
|
|
return 0; /* found a forward, it is used */
|
2000-11-13 05:46:34 +01:00
|
|
|
}
|
2003-03-17 00:59:48 +01:00
|
|
|
return 1;
|
2000-11-13 05:46:34 +01:00
|
|
|
}
|
|
|
|
|
2007-04-09 07:40:57 +02:00
|
|
|
/* check if a given forward does exist in one of the imported dlls */
|
2007-12-06 21:22:34 +01:00
|
|
|
static void check_undefined_forwards( DLLSPEC *spec )
|
2007-04-09 07:40:57 +02:00
|
|
|
{
|
|
|
|
char *link_name, *api_name, *dll_name, *p;
|
2007-12-06 21:22:34 +01:00
|
|
|
int i, j;
|
2007-04-09 07:40:57 +02:00
|
|
|
|
2007-12-06 21:22:34 +01:00
|
|
|
for (i = 0; i < spec->nb_entry_points; i++)
|
|
|
|
{
|
|
|
|
ORDDEF *odp = &spec->entry_points[i];
|
2007-04-09 07:40:57 +02:00
|
|
|
|
2007-12-06 21:22:34 +01:00
|
|
|
if (!(odp->flags & FLAG_FORWARD)) continue;
|
2007-04-09 07:40:57 +02:00
|
|
|
|
2007-12-06 21:22:34 +01:00
|
|
|
link_name = xstrdup( odp->link_name );
|
|
|
|
p = strrchr( link_name, '.' );
|
|
|
|
*p = 0;
|
|
|
|
api_name = p + 1;
|
|
|
|
dll_name = get_dll_name( link_name, NULL );
|
2007-04-09 07:40:57 +02:00
|
|
|
|
2007-12-06 21:22:34 +01:00
|
|
|
for (j = 0; j < nb_imports; j++)
|
2007-04-09 07:40:57 +02:00
|
|
|
{
|
2007-12-06 21:22:34 +01:00
|
|
|
struct import *imp = dll_imports[j];
|
|
|
|
|
|
|
|
if (strcasecmp( imp->spec->file_name, dll_name )) continue;
|
|
|
|
if (!find_export( api_name, imp->exports, imp->nb_exports ))
|
|
|
|
warning( "%s:%d: forward '%s' not found in %s\n",
|
|
|
|
spec->src_name, odp->lineno, odp->link_name, imp->spec->file_name );
|
|
|
|
break;
|
2007-04-09 07:40:57 +02:00
|
|
|
}
|
2007-12-06 21:22:34 +01:00
|
|
|
if (j == nb_imports)
|
|
|
|
warning( "%s:%d: forward '%s' not found in the imported dll list\n",
|
|
|
|
spec->src_name, odp->lineno, odp->link_name );
|
|
|
|
free( link_name );
|
|
|
|
free( dll_name );
|
2007-04-09 07:40:57 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-09-19 19:04:43 +02:00
|
|
|
/* flag the dll exports that link to an undefined symbol */
|
|
|
|
static void check_undefined_exports( DLLSPEC *spec )
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < spec->nb_entry_points; i++)
|
|
|
|
{
|
|
|
|
ORDDEF *odp = &spec->entry_points[i];
|
2009-12-28 21:42:37 +01:00
|
|
|
if (odp->type == TYPE_STUB || odp->type == TYPE_ABS || odp->type == TYPE_VARIABLE) continue;
|
2007-12-06 21:22:34 +01:00
|
|
|
if (odp->flags & FLAG_FORWARD) continue;
|
2005-09-19 19:04:43 +02:00
|
|
|
if (find_name( odp->link_name, &undef_symbols ))
|
|
|
|
{
|
2006-04-18 20:49:29 +02:00
|
|
|
switch(odp->type)
|
|
|
|
{
|
|
|
|
case TYPE_PASCAL:
|
|
|
|
case TYPE_STDCALL:
|
|
|
|
case TYPE_CDECL:
|
|
|
|
case TYPE_VARARGS:
|
|
|
|
if (link_ext_symbols)
|
|
|
|
{
|
|
|
|
odp->flags |= FLAG_EXT_LINK;
|
|
|
|
add_name( &ext_link_imports, odp->link_name );
|
|
|
|
}
|
|
|
|
else error( "%s:%d: function '%s' not defined\n",
|
|
|
|
spec->src_name, odp->lineno, odp->link_name );
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
error( "%s:%d: external symbol '%s' is not a function\n",
|
|
|
|
spec->src_name, odp->lineno, odp->link_name );
|
|
|
|
break;
|
|
|
|
}
|
2005-09-19 19:04:43 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* create a .o file that references all the undefined symbols we want to resolve */
|
|
|
|
static char *create_undef_symbols_file( DLLSPEC *spec )
|
|
|
|
{
|
2005-09-21 12:22:28 +02:00
|
|
|
char *as_file, *obj_file;
|
2007-03-03 14:30:03 +01:00
|
|
|
int i;
|
|
|
|
unsigned int j;
|
2005-09-19 19:04:43 +02:00
|
|
|
FILE *f;
|
|
|
|
|
|
|
|
as_file = get_temp_file_name( output_file_name, ".s" );
|
|
|
|
if (!(f = fopen( as_file, "w" ))) fatal_error( "Cannot create %s\n", as_file );
|
|
|
|
fprintf( f, "\t.data\n" );
|
|
|
|
|
|
|
|
for (i = 0; i < spec->nb_entry_points; i++)
|
|
|
|
{
|
|
|
|
ORDDEF *odp = &spec->entry_points[i];
|
2010-01-11 20:54:16 +01:00
|
|
|
if (odp->type == TYPE_STUB || odp->type == TYPE_ABS || odp->type == TYPE_VARIABLE) continue;
|
2005-09-19 19:04:43 +02:00
|
|
|
if (odp->flags & FLAG_FORWARD) continue;
|
|
|
|
fprintf( f, "\t%s %s\n", get_asm_ptr_keyword(), asm_name(odp->link_name) );
|
|
|
|
}
|
2007-03-03 14:30:03 +01:00
|
|
|
for (j = 0; j < extra_ld_symbols.count; j++)
|
|
|
|
fprintf( f, "\t%s %s\n", get_asm_ptr_keyword(), asm_name(extra_ld_symbols.names[j]) );
|
2005-09-19 19:04:43 +02:00
|
|
|
fclose( f );
|
|
|
|
|
|
|
|
obj_file = get_temp_file_name( output_file_name, ".o" );
|
2005-09-21 12:22:28 +02:00
|
|
|
assemble_file( as_file, obj_file );
|
2005-09-19 19:04:43 +02:00
|
|
|
return obj_file;
|
|
|
|
}
|
|
|
|
|
2002-08-01 20:34:12 +02:00
|
|
|
/* combine a list of object files with ld into a single object file */
|
|
|
|
/* returns the name of the combined file */
|
2005-09-19 19:04:43 +02:00
|
|
|
static const char *ldcombine_files( DLLSPEC *spec, char **argv )
|
2002-08-01 20:34:12 +02:00
|
|
|
{
|
2005-08-19 13:28:56 +02:00
|
|
|
unsigned int i, len = 0;
|
2009-02-04 19:31:54 +01:00
|
|
|
const char *prog = get_ld_command();
|
2005-09-19 19:04:43 +02:00
|
|
|
char *cmd, *p, *ld_tmp_file, *undef_file;
|
2005-09-19 17:24:13 +02:00
|
|
|
int err;
|
2002-08-01 20:34:12 +02:00
|
|
|
|
2005-09-19 19:04:43 +02:00
|
|
|
undef_file = create_undef_symbols_file( spec );
|
|
|
|
len += strlen(undef_file) + 1;
|
2005-09-19 17:24:13 +02:00
|
|
|
ld_tmp_file = get_temp_file_name( output_file_name, ".o" );
|
2002-08-01 20:34:12 +02:00
|
|
|
for (i = 0; argv[i]; i++) len += strlen(argv[i]) + 1;
|
2009-02-04 19:31:54 +01:00
|
|
|
cmd = p = xmalloc( len + strlen(ld_tmp_file) + 8 + strlen(prog) );
|
|
|
|
p += sprintf( cmd, "%s -r -o %s %s", prog, ld_tmp_file, undef_file );
|
2005-08-19 13:28:56 +02:00
|
|
|
for (i = 0; argv[i]; i++)
|
|
|
|
p += sprintf( p, " %s", argv[i] );
|
2005-09-21 12:22:28 +02:00
|
|
|
if (verbose) fprintf( stderr, "%s\n", cmd );
|
2002-08-01 20:34:12 +02:00
|
|
|
err = system( cmd );
|
2009-02-04 19:31:54 +01:00
|
|
|
if (err) fatal_error( "%s -r failed with status %d\n", prog, err );
|
2002-08-01 20:34:12 +02:00
|
|
|
free( cmd );
|
|
|
|
return ld_tmp_file;
|
|
|
|
}
|
|
|
|
|
2000-11-09 21:31:18 +01:00
|
|
|
/* read in the list of undefined symbols */
|
2005-08-25 13:41:05 +02:00
|
|
|
void read_undef_symbols( DLLSPEC *spec, char **argv )
|
2000-11-09 21:31:18 +01:00
|
|
|
{
|
2005-06-27 13:23:24 +02:00
|
|
|
size_t prefix_len;
|
2000-11-09 21:31:18 +01:00
|
|
|
FILE *f;
|
2009-02-04 19:31:54 +01:00
|
|
|
const char *prog = get_nm_command();
|
2005-06-27 13:23:24 +02:00
|
|
|
char *cmd, buffer[1024], name_prefix[16];
|
2000-11-09 21:31:18 +01:00
|
|
|
int err;
|
2002-08-01 20:34:12 +02:00
|
|
|
const char *name;
|
|
|
|
|
|
|
|
if (!argv[0]) return;
|
2000-11-09 21:31:18 +01:00
|
|
|
|
2005-08-29 16:16:27 +02:00
|
|
|
add_extra_undef_symbols( spec );
|
2005-08-25 17:27:44 +02:00
|
|
|
|
2005-06-27 20:59:54 +02:00
|
|
|
strcpy( name_prefix, asm_name("") );
|
2005-06-27 13:23:24 +02:00
|
|
|
prefix_len = strlen( name_prefix );
|
|
|
|
|
2005-09-19 19:04:43 +02:00
|
|
|
name = ldcombine_files( spec, argv );
|
2002-08-01 20:34:12 +02:00
|
|
|
|
2009-02-04 19:31:54 +01:00
|
|
|
cmd = xmalloc( strlen(prog) + strlen(name) + 5 );
|
|
|
|
sprintf( cmd, "%s -u %s", prog, name );
|
2004-10-08 23:11:18 +02:00
|
|
|
if (!(f = popen( cmd, "r" )))
|
|
|
|
fatal_error( "Cannot execute '%s'\n", cmd );
|
2000-11-09 21:31:18 +01:00
|
|
|
|
|
|
|
while (fgets( buffer, sizeof(buffer), f ))
|
|
|
|
{
|
|
|
|
char *p = buffer + strlen(buffer) - 1;
|
|
|
|
if (p < buffer) continue;
|
|
|
|
if (*p == '\n') *p-- = 0;
|
2003-04-10 20:36:40 +02:00
|
|
|
p = buffer;
|
|
|
|
while (*p == ' ') p++;
|
|
|
|
if (p[0] == 'U' && p[1] == ' ' && p[2]) p += 2;
|
2004-06-18 21:36:26 +02:00
|
|
|
if (prefix_len && !strncmp( p, name_prefix, prefix_len )) p += prefix_len;
|
2005-08-19 12:25:22 +02:00
|
|
|
add_name( &undef_symbols, p );
|
2000-11-09 21:31:18 +01:00
|
|
|
}
|
2004-10-08 23:11:18 +02:00
|
|
|
if ((err = pclose( f ))) warning( "%s failed with status %d\n", cmd, err );
|
|
|
|
free( cmd );
|
2000-11-09 21:31:18 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* resolve the imports for a Win32 module */
|
2010-01-16 15:50:27 +01:00
|
|
|
void resolve_imports( DLLSPEC *spec )
|
2000-11-09 21:31:18 +01:00
|
|
|
{
|
2007-03-03 14:30:03 +01:00
|
|
|
int i;
|
|
|
|
unsigned int j, removed;
|
2005-09-19 17:24:13 +02:00
|
|
|
ORDDEF *odp;
|
2000-11-09 21:31:18 +01:00
|
|
|
|
2005-09-19 17:24:13 +02:00
|
|
|
sort_names( &ignore_symbols );
|
2007-12-06 21:22:34 +01:00
|
|
|
check_undefined_forwards( spec );
|
2000-11-09 21:31:18 +01:00
|
|
|
|
|
|
|
for (i = 0; i < nb_imports; i++)
|
|
|
|
{
|
|
|
|
struct import *imp = dll_imports[i];
|
|
|
|
|
2005-08-19 12:25:22 +02:00
|
|
|
for (j = removed = 0; j < undef_symbols.count; j++)
|
2000-11-09 21:31:18 +01:00
|
|
|
{
|
2005-09-19 17:24:13 +02:00
|
|
|
if (find_name( undef_symbols.names[j], &ignore_symbols )) continue;
|
|
|
|
odp = find_export( undef_symbols.names[j], imp->exports, imp->nb_exports );
|
2004-02-17 21:36:16 +01:00
|
|
|
if (odp)
|
2000-11-09 21:31:18 +01:00
|
|
|
{
|
2007-12-06 21:14:07 +01:00
|
|
|
if (odp->flags & FLAG_PRIVATE) continue;
|
|
|
|
if (odp->type != TYPE_STDCALL && odp->type != TYPE_CDECL)
|
|
|
|
warning( "winebuild: Data export '%s' cannot be imported from %s\n",
|
|
|
|
odp->link_name, imp->spec->file_name );
|
|
|
|
else
|
|
|
|
{
|
|
|
|
add_import_func( imp, odp );
|
|
|
|
remove_name( &undef_symbols, j-- );
|
|
|
|
removed++;
|
|
|
|
}
|
2000-11-09 21:31:18 +01:00
|
|
|
}
|
|
|
|
}
|
2007-12-06 21:44:45 +01:00
|
|
|
if (!removed)
|
2003-03-17 00:59:48 +01:00
|
|
|
{
|
|
|
|
/* the dll is not used, get rid of it */
|
2007-12-06 21:44:45 +01:00
|
|
|
if (check_unused( imp, spec ))
|
|
|
|
warning( "winebuild: %s imported but no symbols used\n", imp->spec->file_name );
|
2003-03-17 00:59:48 +01:00
|
|
|
remove_import_dll( i );
|
|
|
|
i--;
|
|
|
|
}
|
2000-11-09 21:31:18 +01:00
|
|
|
}
|
2005-09-19 19:04:43 +02:00
|
|
|
|
|
|
|
sort_names( &undef_symbols );
|
|
|
|
check_undefined_exports( spec );
|
2010-01-16 15:50:27 +01:00
|
|
|
}
|
2005-09-19 19:04:43 +02:00
|
|
|
|
2010-01-16 15:50:27 +01:00
|
|
|
/* check if symbol is still undefined */
|
|
|
|
int is_undefined( const char *name )
|
|
|
|
{
|
|
|
|
return find_name( name, &undef_symbols ) != NULL;
|
2000-11-09 21:31:18 +01:00
|
|
|
}
|
2000-09-28 01:40:43 +02:00
|
|
|
|
2005-09-18 13:13:54 +02:00
|
|
|
/* output the get_pc thunk if needed */
|
2006-08-11 20:41:29 +02:00
|
|
|
void output_get_pc_thunk(void)
|
2005-09-18 13:13:54 +02:00
|
|
|
{
|
|
|
|
if (target_cpu != CPU_x86) return;
|
|
|
|
if (!UsePIC) return;
|
2006-08-11 20:41:29 +02:00
|
|
|
output( "\n\t.text\n" );
|
|
|
|
output( "\t.align %d\n", get_alignment(4) );
|
|
|
|
output( "\t%s\n", func_declaration("__wine_spec_get_pc_thunk_eax") );
|
|
|
|
output( "%s:\n", asm_name("__wine_spec_get_pc_thunk_eax") );
|
2010-04-12 12:04:50 +02:00
|
|
|
output_cfi( ".cfi_startproc" );
|
|
|
|
output( "\tmovl (%%esp),%%eax\n" );
|
2006-08-11 20:41:29 +02:00
|
|
|
output( "\tret\n" );
|
2010-04-12 12:04:50 +02:00
|
|
|
output_cfi( ".cfi_endproc" );
|
2006-08-11 20:41:29 +02:00
|
|
|
output_function_size( "__wine_spec_get_pc_thunk_eax" );
|
2005-09-18 13:13:54 +02:00
|
|
|
}
|
|
|
|
|
2005-06-16 22:51:50 +02:00
|
|
|
/* output a single import thunk */
|
2006-08-11 20:41:29 +02:00
|
|
|
static void output_import_thunk( const char *name, const char *table, int pos )
|
2005-06-16 22:51:50 +02:00
|
|
|
{
|
2006-08-11 20:41:29 +02:00
|
|
|
output( "\n\t.align %d\n", get_alignment(4) );
|
|
|
|
output( "\t%s\n", func_declaration(name) );
|
|
|
|
output( "%s\n", asm_globl(name) );
|
2010-04-12 12:04:50 +02:00
|
|
|
output_cfi( ".cfi_startproc" );
|
2005-06-16 22:51:50 +02:00
|
|
|
|
2005-06-27 13:23:24 +02:00
|
|
|
switch(target_cpu)
|
2005-06-16 22:51:50 +02:00
|
|
|
{
|
2005-06-27 13:23:24 +02:00
|
|
|
case CPU_x86:
|
|
|
|
if (!UsePIC)
|
2005-06-16 22:51:50 +02:00
|
|
|
{
|
2006-08-11 20:41:29 +02:00
|
|
|
output( "\tjmp *(%s+%d)\n", table, pos );
|
2005-06-16 22:51:50 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2006-08-11 20:41:29 +02:00
|
|
|
output( "\tcall %s\n", asm_name("__wine_spec_get_pc_thunk_eax") );
|
|
|
|
output( "1:\tjmp *%s+%d-1b(%%eax)\n", table, pos );
|
2005-06-16 22:51:50 +02:00
|
|
|
}
|
2005-06-27 13:23:24 +02:00
|
|
|
break;
|
2005-09-16 21:39:42 +02:00
|
|
|
case CPU_x86_64:
|
2006-08-11 20:41:29 +02:00
|
|
|
output( "\tjmpq *%s+%d(%%rip)\n", table, pos );
|
2005-09-16 21:39:42 +02:00
|
|
|
break;
|
2005-06-27 13:23:24 +02:00
|
|
|
case CPU_SPARC:
|
|
|
|
if ( !UsePIC )
|
|
|
|
{
|
2006-08-11 20:41:29 +02:00
|
|
|
output( "\tsethi %%hi(%s+%d), %%g1\n", table, pos );
|
|
|
|
output( "\tld [%%g1+%%lo(%s+%d)], %%g1\n", table, pos );
|
|
|
|
output( "\tjmp %%g1\n" );
|
|
|
|
output( "\tnop\n" );
|
2005-06-27 13:23:24 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Hmpf. Stupid sparc assembler always interprets global variable
|
|
|
|
names as GOT offsets, so we have to do it the long way ... */
|
2006-08-11 20:41:29 +02:00
|
|
|
output( "\tsave %%sp, -96, %%sp\n" );
|
|
|
|
output( "0:\tcall 1f\n" );
|
|
|
|
output( "\tnop\n" );
|
|
|
|
output( "1:\tsethi %%hi(%s+%d-0b), %%g1\n", table, pos );
|
|
|
|
output( "\tor %%g1, %%lo(%s+%d-0b), %%g1\n", table, pos );
|
|
|
|
output( "\tld [%%g1+%%o7], %%g1\n" );
|
|
|
|
output( "\tjmp %%g1\n" );
|
|
|
|
output( "\trestore\n" );
|
2005-06-27 13:23:24 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case CPU_ALPHA:
|
2006-08-11 20:41:29 +02:00
|
|
|
output( "\tlda $0,%s\n", table );
|
|
|
|
output( "\tlda $0,%d($0)\n", pos );
|
|
|
|
output( "\tjmp $31,($0)\n" );
|
2005-06-27 13:23:24 +02:00
|
|
|
break;
|
2009-11-17 20:20:48 +01:00
|
|
|
case CPU_ARM:
|
|
|
|
output( "\tmov r4, #%s\n", table );
|
|
|
|
output( "\tldr r15, [r4, #%d]\n", pos );
|
|
|
|
break;
|
2005-06-27 13:23:24 +02:00
|
|
|
case CPU_POWERPC:
|
2008-05-31 10:51:01 +02:00
|
|
|
output( "\tmr %s, %s\n", ppc_reg(0), ppc_reg(31) );
|
2005-06-27 13:23:24 +02:00
|
|
|
if (target_platform == PLATFORM_APPLE)
|
|
|
|
{
|
2008-05-31 10:51:01 +02:00
|
|
|
output( "\tlis %s, ha16(%s+%d+32768)\n", ppc_reg(31), table, pos );
|
|
|
|
output( "\tla %s, lo16(%s+%d)(%s)\n", ppc_reg(31), table, pos, ppc_reg(31) );
|
2005-06-27 13:23:24 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2008-05-31 10:51:01 +02:00
|
|
|
output( "\tlis %s, (%s+%d+32768)@h\n", ppc_reg(31), table, pos );
|
|
|
|
output( "\tla %s, (%s+%d)@l(%s)\n", ppc_reg(31), table, pos, ppc_reg(31) );
|
2005-06-27 13:23:24 +02:00
|
|
|
}
|
2008-05-31 10:51:01 +02:00
|
|
|
output( "\tlwz %s, 0(%s)\n", ppc_reg(31), ppc_reg(31) );
|
|
|
|
output( "\tmtctr %s\n", ppc_reg(31) );
|
|
|
|
output( "\tmr %s, %s\n", ppc_reg(31), ppc_reg(0) );
|
2006-08-11 20:41:29 +02:00
|
|
|
output( "\tbctr\n" );
|
2005-06-27 13:23:24 +02:00
|
|
|
break;
|
2005-06-16 22:51:50 +02:00
|
|
|
}
|
2010-04-12 12:04:50 +02:00
|
|
|
output_cfi( ".cfi_endproc" );
|
2006-08-11 20:41:29 +02:00
|
|
|
output_function_size( name );
|
2005-06-16 22:51:50 +02:00
|
|
|
}
|
|
|
|
|
2005-09-08 13:35:19 +02:00
|
|
|
/* check if we need an import directory */
|
|
|
|
int has_imports(void)
|
2000-09-28 01:40:43 +02:00
|
|
|
{
|
2005-09-08 13:35:19 +02:00
|
|
|
return (nb_imports - nb_delayed) > 0;
|
2005-09-02 17:36:03 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* output the import table of a Win32 module */
|
2006-08-11 20:41:29 +02:00
|
|
|
static void output_immediate_imports(void)
|
2005-09-02 17:36:03 +02:00
|
|
|
{
|
|
|
|
int i, j;
|
|
|
|
const char *dll_name;
|
|
|
|
|
|
|
|
if (nb_imports == nb_delayed) return; /* no immediate imports */
|
|
|
|
|
2000-09-28 01:40:43 +02:00
|
|
|
/* main import header */
|
|
|
|
|
2006-08-11 20:41:29 +02:00
|
|
|
output( "\n/* import table */\n" );
|
|
|
|
output( "\n\t.data\n" );
|
|
|
|
output( "\t.align %d\n", get_alignment(4) );
|
|
|
|
output( ".L__wine_spec_imports:\n" );
|
2000-09-28 01:40:43 +02:00
|
|
|
|
|
|
|
/* list of dlls */
|
|
|
|
|
|
|
|
for (i = j = 0; i < nb_imports; i++)
|
|
|
|
{
|
2000-12-26 02:22:34 +01:00
|
|
|
if (dll_imports[i]->delay) continue;
|
2005-09-02 17:36:03 +02:00
|
|
|
dll_name = make_c_identifier( dll_imports[i]->spec->file_name );
|
2008-09-04 21:52:58 +02:00
|
|
|
output( "\t.long .L__wine_spec_import_data_names+%d-.L__wine_spec_rva_base\n", /* OriginalFirstThunk */
|
|
|
|
j * get_ptr_size() );
|
2006-08-11 20:41:29 +02:00
|
|
|
output( "\t.long 0\n" ); /* TimeDateStamp */
|
|
|
|
output( "\t.long 0\n" ); /* ForwarderChain */
|
|
|
|
output( "\t.long .L__wine_spec_import_name_%s-.L__wine_spec_rva_base\n", /* Name */
|
2005-09-17 16:39:51 +02:00
|
|
|
dll_name );
|
2006-08-11 20:41:29 +02:00
|
|
|
output( "\t.long .L__wine_spec_import_data_ptrs+%d-.L__wine_spec_rva_base\n", /* FirstThunk */
|
2005-09-08 13:35:19 +02:00
|
|
|
j * get_ptr_size() );
|
2000-09-28 01:40:43 +02:00
|
|
|
j += dll_imports[i]->nb_imports + 1;
|
|
|
|
}
|
2006-08-11 20:41:29 +02:00
|
|
|
output( "\t.long 0\n" ); /* OriginalFirstThunk */
|
|
|
|
output( "\t.long 0\n" ); /* TimeDateStamp */
|
|
|
|
output( "\t.long 0\n" ); /* ForwarderChain */
|
|
|
|
output( "\t.long 0\n" ); /* Name */
|
|
|
|
output( "\t.long 0\n" ); /* FirstThunk */
|
|
|
|
|
|
|
|
output( "\n\t.align %d\n", get_alignment(get_ptr_size()) );
|
2008-09-04 21:52:58 +02:00
|
|
|
output( ".L__wine_spec_import_data_names:\n" );
|
2005-09-02 17:36:03 +02:00
|
|
|
for (i = 0; i < nb_imports; i++)
|
|
|
|
{
|
|
|
|
if (dll_imports[i]->delay) continue;
|
|
|
|
dll_name = make_c_identifier( dll_imports[i]->spec->file_name );
|
|
|
|
for (j = 0; j < dll_imports[i]->nb_imports; j++)
|
|
|
|
{
|
|
|
|
ORDDEF *odp = dll_imports[i]->imports[j];
|
|
|
|
if (!(odp->flags & FLAG_NONAME))
|
2006-08-11 20:41:29 +02:00
|
|
|
output( "\t%s .L__wine_spec_import_data_%s_%s-.L__wine_spec_rva_base\n",
|
2005-09-08 13:35:19 +02:00
|
|
|
get_asm_ptr_keyword(), dll_name, odp->name );
|
2005-09-02 17:36:03 +02:00
|
|
|
else
|
2005-09-17 16:39:51 +02:00
|
|
|
{
|
|
|
|
if (get_ptr_size() == 8)
|
2006-08-11 20:41:29 +02:00
|
|
|
output( "\t.quad 0x800000000000%04x\n", odp->ordinal );
|
2005-09-17 16:39:51 +02:00
|
|
|
else
|
2006-08-11 20:41:29 +02:00
|
|
|
output( "\t.long 0x8000%04x\n", odp->ordinal );
|
2005-09-17 16:39:51 +02:00
|
|
|
}
|
2005-09-02 17:36:03 +02:00
|
|
|
}
|
2006-08-11 20:41:29 +02:00
|
|
|
output( "\t%s 0\n", get_asm_ptr_keyword() );
|
2005-09-02 17:36:03 +02:00
|
|
|
}
|
2008-09-04 21:52:58 +02:00
|
|
|
output( ".L__wine_spec_import_data_ptrs:\n" );
|
|
|
|
for (i = 0; i < nb_imports; i++)
|
|
|
|
{
|
|
|
|
if (dll_imports[i]->delay) continue;
|
|
|
|
for (j = 0; j < dll_imports[i]->nb_imports; j++) output( "\t%s 0\n", get_asm_ptr_keyword() );
|
|
|
|
output( "\t%s 0\n", get_asm_ptr_keyword() );
|
|
|
|
}
|
2006-08-11 20:41:29 +02:00
|
|
|
output( ".L__wine_spec_imports_end:\n" );
|
2000-09-28 01:40:43 +02:00
|
|
|
|
|
|
|
for (i = 0; i < nb_imports; i++)
|
|
|
|
{
|
2000-12-26 02:22:34 +01:00
|
|
|
if (dll_imports[i]->delay) continue;
|
2005-09-02 17:36:03 +02:00
|
|
|
dll_name = make_c_identifier( dll_imports[i]->spec->file_name );
|
2000-09-28 01:40:43 +02:00
|
|
|
for (j = 0; j < dll_imports[i]->nb_imports; j++)
|
2002-07-25 02:25:40 +02:00
|
|
|
{
|
2004-02-17 21:36:16 +01:00
|
|
|
ORDDEF *odp = dll_imports[i]->imports[j];
|
|
|
|
if (!(odp->flags & FLAG_NONAME))
|
2002-07-28 19:54:31 +02:00
|
|
|
{
|
2006-08-11 20:41:29 +02:00
|
|
|
output( "\t.align %d\n", get_alignment(2) );
|
|
|
|
output( ".L__wine_spec_import_data_%s_%s:\n", dll_name, odp->name );
|
|
|
|
output( "\t%s %d\n", get_asm_short_keyword(), odp->ordinal );
|
|
|
|
output( "\t%s \"%s\"\n", get_asm_string_keyword(), odp->name );
|
2002-07-28 19:54:31 +02:00
|
|
|
}
|
2002-07-25 02:25:40 +02:00
|
|
|
}
|
2000-09-28 01:40:43 +02:00
|
|
|
}
|
|
|
|
|
2005-09-02 17:36:03 +02:00
|
|
|
for (i = 0; i < nb_imports; i++)
|
|
|
|
{
|
|
|
|
if (dll_imports[i]->delay) continue;
|
|
|
|
dll_name = make_c_identifier( dll_imports[i]->spec->file_name );
|
2006-08-11 20:41:29 +02:00
|
|
|
output( ".L__wine_spec_import_name_%s:\n\t%s \"%s\"\n",
|
2005-09-02 17:36:03 +02:00
|
|
|
dll_name, get_asm_string_keyword(), dll_imports[i]->spec->file_name );
|
|
|
|
}
|
2005-06-06 17:59:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* output the import thunks of a Win32 module */
|
2006-08-11 20:41:29 +02:00
|
|
|
static void output_immediate_import_thunks(void)
|
2005-06-06 17:59:50 +02:00
|
|
|
{
|
|
|
|
int i, j, pos;
|
|
|
|
int nb_imm = nb_imports - nb_delayed;
|
|
|
|
static const char import_thunks[] = "__wine_spec_import_thunks";
|
|
|
|
|
|
|
|
if (!nb_imm) return;
|
2000-09-28 01:40:43 +02:00
|
|
|
|
2006-08-11 20:41:29 +02:00
|
|
|
output( "\n/* immediate import thunks */\n\n" );
|
|
|
|
output( "\t.text\n" );
|
|
|
|
output( "\t.align %d\n", get_alignment(8) );
|
|
|
|
output( "%s:\n", asm_name(import_thunks));
|
2004-05-18 23:27:44 +02:00
|
|
|
|
2005-09-02 17:36:03 +02:00
|
|
|
for (i = pos = 0; i < nb_imports; i++)
|
2000-09-28 01:40:43 +02:00
|
|
|
{
|
2000-12-26 02:22:34 +01:00
|
|
|
if (dll_imports[i]->delay) continue;
|
2005-09-08 13:35:19 +02:00
|
|
|
for (j = 0; j < dll_imports[i]->nb_imports; j++, pos += get_ptr_size())
|
2000-09-28 01:40:43 +02:00
|
|
|
{
|
2004-02-17 21:36:16 +01:00
|
|
|
ORDDEF *odp = dll_imports[i]->imports[j];
|
2006-08-11 20:41:29 +02:00
|
|
|
output_import_thunk( odp->name ? odp->name : odp->export_name,
|
2005-09-03 17:39:13 +02:00
|
|
|
".L__wine_spec_import_data_ptrs", pos );
|
2000-09-28 01:40:43 +02:00
|
|
|
}
|
2005-09-08 13:35:19 +02:00
|
|
|
pos += get_ptr_size();
|
2000-09-28 01:40:43 +02:00
|
|
|
}
|
2006-08-11 20:41:29 +02:00
|
|
|
output_function_size( import_thunks );
|
2000-12-26 02:22:34 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* output the delayed import table of a Win32 module */
|
2006-08-11 20:41:29 +02:00
|
|
|
static void output_delayed_imports( const DLLSPEC *spec )
|
2000-12-26 02:22:34 +01:00
|
|
|
{
|
2006-04-18 11:23:49 +02:00
|
|
|
int i, j, mod;
|
2000-12-26 02:22:34 +01:00
|
|
|
|
2005-09-02 17:36:03 +02:00
|
|
|
if (!nb_delayed) return;
|
2000-12-26 02:22:34 +01:00
|
|
|
|
2006-08-11 20:41:29 +02:00
|
|
|
output( "\n/* delayed imports */\n\n" );
|
|
|
|
output( "\t.data\n" );
|
|
|
|
output( "\t.align %d\n", get_alignment(get_ptr_size()) );
|
|
|
|
output( "%s\n", asm_globl("__wine_spec_delay_imports") );
|
2005-09-03 17:39:13 +02:00
|
|
|
|
|
|
|
/* list of dlls */
|
|
|
|
|
2006-04-18 11:23:49 +02:00
|
|
|
for (i = j = mod = 0; i < nb_imports; i++)
|
2005-09-03 17:39:13 +02:00
|
|
|
{
|
|
|
|
if (!dll_imports[i]->delay) continue;
|
2006-08-11 20:41:29 +02:00
|
|
|
output( "\t%s 0\n", get_asm_ptr_keyword() ); /* grAttrs */
|
|
|
|
output( "\t%s .L__wine_delay_name_%d\n", /* szName */
|
2005-09-08 13:35:19 +02:00
|
|
|
get_asm_ptr_keyword(), i );
|
2006-08-11 20:41:29 +02:00
|
|
|
output( "\t%s .L__wine_delay_modules+%d\n", /* phmod */
|
2006-04-18 11:23:49 +02:00
|
|
|
get_asm_ptr_keyword(), mod * get_ptr_size() );
|
2006-08-11 20:41:29 +02:00
|
|
|
output( "\t%s .L__wine_delay_IAT+%d\n", /* pIAT */
|
2005-09-08 13:35:19 +02:00
|
|
|
get_asm_ptr_keyword(), j * get_ptr_size() );
|
2006-08-11 20:41:29 +02:00
|
|
|
output( "\t%s .L__wine_delay_INT+%d\n", /* pINT */
|
2005-09-08 13:35:19 +02:00
|
|
|
get_asm_ptr_keyword(), j * get_ptr_size() );
|
2006-08-11 20:41:29 +02:00
|
|
|
output( "\t%s 0\n", get_asm_ptr_keyword() ); /* pBoundIAT */
|
|
|
|
output( "\t%s 0\n", get_asm_ptr_keyword() ); /* pUnloadIAT */
|
|
|
|
output( "\t%s 0\n", get_asm_ptr_keyword() ); /* dwTimeStamp */
|
2005-09-03 17:39:13 +02:00
|
|
|
j += dll_imports[i]->nb_imports;
|
2006-04-18 11:23:49 +02:00
|
|
|
mod++;
|
2005-09-03 17:39:13 +02:00
|
|
|
}
|
2006-08-11 20:41:29 +02:00
|
|
|
output( "\t%s 0\n", get_asm_ptr_keyword() ); /* grAttrs */
|
|
|
|
output( "\t%s 0\n", get_asm_ptr_keyword() ); /* szName */
|
|
|
|
output( "\t%s 0\n", get_asm_ptr_keyword() ); /* phmod */
|
|
|
|
output( "\t%s 0\n", get_asm_ptr_keyword() ); /* pIAT */
|
|
|
|
output( "\t%s 0\n", get_asm_ptr_keyword() ); /* pINT */
|
|
|
|
output( "\t%s 0\n", get_asm_ptr_keyword() ); /* pBoundIAT */
|
|
|
|
output( "\t%s 0\n", get_asm_ptr_keyword() ); /* pUnloadIAT */
|
|
|
|
output( "\t%s 0\n", get_asm_ptr_keyword() ); /* dwTimeStamp */
|
|
|
|
|
|
|
|
output( "\n.L__wine_delay_IAT:\n" );
|
2000-12-26 02:22:34 +01:00
|
|
|
for (i = 0; i < nb_imports; i++)
|
|
|
|
{
|
|
|
|
if (!dll_imports[i]->delay) continue;
|
|
|
|
for (j = 0; j < dll_imports[i]->nb_imports; j++)
|
|
|
|
{
|
2004-02-17 21:36:16 +01:00
|
|
|
ORDDEF *odp = dll_imports[i]->imports[j];
|
|
|
|
const char *name = odp->name ? odp->name : odp->export_name;
|
2006-08-11 20:41:29 +02:00
|
|
|
output( "\t%s .L__wine_delay_imp_%d_%s\n",
|
2005-09-08 13:35:19 +02:00
|
|
|
get_asm_ptr_keyword(), i, name );
|
2000-12-26 02:22:34 +01:00
|
|
|
}
|
|
|
|
}
|
2005-09-03 17:39:13 +02:00
|
|
|
|
2006-08-11 20:41:29 +02:00
|
|
|
output( "\n.L__wine_delay_INT:\n" );
|
2000-12-26 02:22:34 +01:00
|
|
|
for (i = 0; i < nb_imports; i++)
|
|
|
|
{
|
|
|
|
if (!dll_imports[i]->delay) continue;
|
|
|
|
for (j = 0; j < dll_imports[i]->nb_imports; j++)
|
|
|
|
{
|
2004-02-17 21:36:16 +01:00
|
|
|
ORDDEF *odp = dll_imports[i]->imports[j];
|
2005-09-03 17:39:13 +02:00
|
|
|
if (!odp->name)
|
2006-08-11 20:41:29 +02:00
|
|
|
output( "\t%s %d\n", get_asm_ptr_keyword(), odp->ordinal );
|
2005-09-03 17:39:13 +02:00
|
|
|
else
|
2006-08-11 20:41:29 +02:00
|
|
|
output( "\t%s .L__wine_delay_data_%d_%s\n",
|
2005-09-08 13:35:19 +02:00
|
|
|
get_asm_ptr_keyword(), i, odp->name );
|
2000-12-26 02:22:34 +01:00
|
|
|
}
|
|
|
|
}
|
2005-09-03 17:39:13 +02:00
|
|
|
|
2006-08-11 20:41:29 +02:00
|
|
|
output( "\n.L__wine_delay_modules:\n" );
|
2005-09-03 17:39:13 +02:00
|
|
|
for (i = 0; i < nb_imports; i++)
|
|
|
|
{
|
2006-08-11 20:41:29 +02:00
|
|
|
if (dll_imports[i]->delay) output( "\t%s 0\n", get_asm_ptr_keyword() );
|
2005-09-03 17:39:13 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < nb_imports; i++)
|
|
|
|
{
|
|
|
|
if (!dll_imports[i]->delay) continue;
|
2006-08-11 20:41:29 +02:00
|
|
|
output( ".L__wine_delay_name_%d:\n", i );
|
|
|
|
output( "\t%s \"%s\"\n",
|
2005-09-03 17:39:13 +02:00
|
|
|
get_asm_string_keyword(), dll_imports[i]->spec->file_name );
|
|
|
|
}
|
|
|
|
|
2000-12-26 02:22:34 +01:00
|
|
|
for (i = 0; i < nb_imports; i++)
|
|
|
|
{
|
|
|
|
if (!dll_imports[i]->delay) continue;
|
|
|
|
for (j = 0; j < dll_imports[i]->nb_imports; j++)
|
|
|
|
{
|
2004-02-17 21:36:16 +01:00
|
|
|
ORDDEF *odp = dll_imports[i]->imports[j];
|
2005-09-03 17:39:13 +02:00
|
|
|
if (!odp->name) continue;
|
2006-08-11 20:41:29 +02:00
|
|
|
output( ".L__wine_delay_data_%d_%s:\n", i, odp->name );
|
|
|
|
output( "\t%s \"%s\"\n", get_asm_string_keyword(), odp->name );
|
2000-12-26 02:22:34 +01:00
|
|
|
}
|
|
|
|
}
|
2006-08-11 20:41:29 +02:00
|
|
|
output_function_size( "__wine_spec_delay_imports" );
|
2005-06-06 17:59:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* output the delayed import thunks of a Win32 module */
|
2006-08-11 20:41:29 +02:00
|
|
|
static void output_delayed_import_thunks( const DLLSPEC *spec )
|
2005-06-06 17:59:50 +02:00
|
|
|
{
|
2005-06-27 13:23:24 +02:00
|
|
|
int i, idx, j, pos, extra_stack_storage = 0;
|
2005-06-06 17:59:50 +02:00
|
|
|
static const char delayed_import_loaders[] = "__wine_spec_delayed_import_loaders";
|
|
|
|
static const char delayed_import_thunks[] = "__wine_spec_delayed_import_thunks";
|
2000-12-26 02:22:34 +01:00
|
|
|
|
2005-06-06 17:59:50 +02:00
|
|
|
if (!nb_delayed) return;
|
2001-01-02 23:22:12 +01:00
|
|
|
|
2006-08-11 20:41:29 +02:00
|
|
|
output( "\n/* delayed import thunks */\n\n" );
|
|
|
|
output( "\t.text\n" );
|
|
|
|
output( "\t.align %d\n", get_alignment(8) );
|
|
|
|
output( "%s:\n", asm_name(delayed_import_loaders));
|
|
|
|
output( "\t%s\n", func_declaration("__wine_delay_load_asm") );
|
|
|
|
output( "%s:\n", asm_name("__wine_delay_load_asm") );
|
2010-04-12 12:04:50 +02:00
|
|
|
output_cfi( ".cfi_startproc" );
|
2005-06-27 13:23:24 +02:00
|
|
|
switch(target_cpu)
|
|
|
|
{
|
|
|
|
case CPU_x86:
|
2006-08-11 20:41:29 +02:00
|
|
|
output( "\tpushl %%ecx\n" );
|
2010-04-12 12:04:50 +02:00
|
|
|
output_cfi( ".cfi_adjust_cfa_offset 4" );
|
2006-08-11 20:41:29 +02:00
|
|
|
output( "\tpushl %%edx\n" );
|
2010-04-12 12:04:50 +02:00
|
|
|
output_cfi( ".cfi_adjust_cfa_offset 4" );
|
2006-08-11 20:41:29 +02:00
|
|
|
output( "\tpushl %%eax\n" );
|
2010-04-12 12:04:50 +02:00
|
|
|
output_cfi( ".cfi_adjust_cfa_offset 4" );
|
2006-08-11 20:41:29 +02:00
|
|
|
output( "\tcall %s\n", asm_name("__wine_spec_delay_load") );
|
2010-04-12 12:04:50 +02:00
|
|
|
output_cfi( ".cfi_adjust_cfa_offset -4" );
|
2006-08-11 20:41:29 +02:00
|
|
|
output( "\tpopl %%edx\n" );
|
2010-04-12 12:04:50 +02:00
|
|
|
output_cfi( ".cfi_adjust_cfa_offset -4" );
|
2006-08-11 20:41:29 +02:00
|
|
|
output( "\tpopl %%ecx\n" );
|
2010-04-12 12:04:50 +02:00
|
|
|
output_cfi( ".cfi_adjust_cfa_offset -4" );
|
2006-08-11 20:41:29 +02:00
|
|
|
output( "\tjmp *%%eax\n" );
|
2005-06-27 13:23:24 +02:00
|
|
|
break;
|
2005-09-16 21:39:42 +02:00
|
|
|
case CPU_x86_64:
|
2009-06-16 14:26:51 +02:00
|
|
|
output( "\tsubq $88,%%rsp\n" );
|
2010-04-11 12:01:01 +02:00
|
|
|
output_cfi( ".cfi_adjust_cfa_offset 88" );
|
2009-06-16 14:26:51 +02:00
|
|
|
output( "\tmovq %%rdx,80(%%rsp)\n" );
|
|
|
|
output( "\tmovq %%rcx,72(%%rsp)\n" );
|
|
|
|
output( "\tmovq %%r8,64(%%rsp)\n" );
|
|
|
|
output( "\tmovq %%r9,56(%%rsp)\n" );
|
|
|
|
output( "\tmovq %%r10,48(%%rsp)\n" );
|
|
|
|
output( "\tmovq %%r11,40(%%rsp)\n" );
|
2008-12-27 19:58:42 +01:00
|
|
|
output( "\tmovq %%rax,%%rcx\n" );
|
2006-08-11 20:41:29 +02:00
|
|
|
output( "\tcall %s\n", asm_name("__wine_spec_delay_load") );
|
2009-06-16 14:26:51 +02:00
|
|
|
output( "\tmovq 40(%%rsp),%%r11\n" );
|
|
|
|
output( "\tmovq 48(%%rsp),%%r10\n" );
|
|
|
|
output( "\tmovq 56(%%rsp),%%r9\n" );
|
|
|
|
output( "\tmovq 64(%%rsp),%%r8\n" );
|
|
|
|
output( "\tmovq 72(%%rsp),%%rcx\n" );
|
|
|
|
output( "\tmovq 80(%%rsp),%%rdx\n" );
|
|
|
|
output( "\taddq $88,%%rsp\n" );
|
2010-04-11 12:01:01 +02:00
|
|
|
output_cfi( ".cfi_adjust_cfa_offset -88" );
|
2006-08-11 20:41:29 +02:00
|
|
|
output( "\tjmp *%%rax\n" );
|
2005-09-16 21:39:42 +02:00
|
|
|
break;
|
2005-06-27 13:23:24 +02:00
|
|
|
case CPU_SPARC:
|
2006-08-11 20:41:29 +02:00
|
|
|
output( "\tsave %%sp, -96, %%sp\n" );
|
|
|
|
output( "\tcall %s\n", asm_name("__wine_spec_delay_load") );
|
|
|
|
output( "\tmov %%g1, %%o0\n" );
|
|
|
|
output( "\tjmp %%o0\n" );
|
|
|
|
output( "\trestore\n" );
|
2005-06-27 13:23:24 +02:00
|
|
|
break;
|
|
|
|
case CPU_ALPHA:
|
2006-08-11 20:41:29 +02:00
|
|
|
output( "\tjsr $26,%s\n", asm_name("__wine_spec_delay_load") );
|
|
|
|
output( "\tjmp $31,($0)\n" );
|
2005-06-27 13:23:24 +02:00
|
|
|
break;
|
2009-11-17 20:20:48 +01:00
|
|
|
case CPU_ARM:
|
|
|
|
output( "\tstmfd sp!, {r4, r5, r6, r7, r8, r9, r10, lr}\n" );
|
|
|
|
output( "\tblx %s\n", asm_name("__wine_spec_delay_load") );
|
|
|
|
output( "\tldmfd sp!, {r4, r5, r6, r7, r8, r9, r10, pc}\n" );
|
|
|
|
break;
|
2005-06-27 13:23:24 +02:00
|
|
|
case CPU_POWERPC:
|
|
|
|
if (target_platform == PLATFORM_APPLE) extra_stack_storage = 56;
|
|
|
|
|
|
|
|
/* Save all callee saved registers into a stackframe. */
|
2006-08-11 20:41:29 +02:00
|
|
|
output( "\tstwu %s, -%d(%s)\n",ppc_reg(1), 48+extra_stack_storage, ppc_reg(1));
|
|
|
|
output( "\tstw %s, %d(%s)\n", ppc_reg(3), 4+extra_stack_storage, ppc_reg(1));
|
|
|
|
output( "\tstw %s, %d(%s)\n", ppc_reg(4), 8+extra_stack_storage, ppc_reg(1));
|
|
|
|
output( "\tstw %s, %d(%s)\n", ppc_reg(5), 12+extra_stack_storage, ppc_reg(1));
|
|
|
|
output( "\tstw %s, %d(%s)\n", ppc_reg(6), 16+extra_stack_storage, ppc_reg(1));
|
|
|
|
output( "\tstw %s, %d(%s)\n", ppc_reg(7), 20+extra_stack_storage, ppc_reg(1));
|
|
|
|
output( "\tstw %s, %d(%s)\n", ppc_reg(8), 24+extra_stack_storage, ppc_reg(1));
|
|
|
|
output( "\tstw %s, %d(%s)\n", ppc_reg(9), 28+extra_stack_storage, ppc_reg(1));
|
|
|
|
output( "\tstw %s, %d(%s)\n", ppc_reg(10),32+extra_stack_storage, ppc_reg(1));
|
|
|
|
output( "\tstw %s, %d(%s)\n", ppc_reg(11),36+extra_stack_storage, ppc_reg(1));
|
|
|
|
output( "\tstw %s, %d(%s)\n", ppc_reg(12),40+extra_stack_storage, ppc_reg(1));
|
2005-06-27 13:23:24 +02:00
|
|
|
|
|
|
|
/* r0 -> r3 (arg1) */
|
2006-08-11 20:41:29 +02:00
|
|
|
output( "\tmr %s, %s\n", ppc_reg(3), ppc_reg(0));
|
2005-06-27 13:23:24 +02:00
|
|
|
|
|
|
|
/* save return address */
|
2006-08-11 20:41:29 +02:00
|
|
|
output( "\tmflr %s\n", ppc_reg(0));
|
|
|
|
output( "\tstw %s, %d(%s)\n", ppc_reg(0), 44+extra_stack_storage, ppc_reg(1));
|
2005-06-27 13:23:24 +02:00
|
|
|
|
|
|
|
/* Call the __wine_delay_load function, arg1 is arg1. */
|
2006-08-11 20:41:29 +02:00
|
|
|
output( "\tbl %s\n", asm_name("__wine_spec_delay_load") );
|
2005-06-27 13:23:24 +02:00
|
|
|
|
|
|
|
/* Load return value from call into ctr register */
|
2006-08-11 20:41:29 +02:00
|
|
|
output( "\tmtctr %s\n", ppc_reg(3));
|
2005-06-27 13:23:24 +02:00
|
|
|
|
|
|
|
/* restore all saved registers and drop stackframe. */
|
2006-08-11 20:41:29 +02:00
|
|
|
output( "\tlwz %s, %d(%s)\n", ppc_reg(3), 4+extra_stack_storage, ppc_reg(1));
|
|
|
|
output( "\tlwz %s, %d(%s)\n", ppc_reg(4), 8+extra_stack_storage, ppc_reg(1));
|
|
|
|
output( "\tlwz %s, %d(%s)\n", ppc_reg(5), 12+extra_stack_storage, ppc_reg(1));
|
|
|
|
output( "\tlwz %s, %d(%s)\n", ppc_reg(6), 16+extra_stack_storage, ppc_reg(1));
|
|
|
|
output( "\tlwz %s, %d(%s)\n", ppc_reg(7), 20+extra_stack_storage, ppc_reg(1));
|
|
|
|
output( "\tlwz %s, %d(%s)\n", ppc_reg(8), 24+extra_stack_storage, ppc_reg(1));
|
|
|
|
output( "\tlwz %s, %d(%s)\n", ppc_reg(9), 28+extra_stack_storage, ppc_reg(1));
|
|
|
|
output( "\tlwz %s, %d(%s)\n", ppc_reg(10),32+extra_stack_storage, ppc_reg(1));
|
|
|
|
output( "\tlwz %s, %d(%s)\n", ppc_reg(11),36+extra_stack_storage, ppc_reg(1));
|
|
|
|
output( "\tlwz %s, %d(%s)\n", ppc_reg(12),40+extra_stack_storage, ppc_reg(1));
|
2005-06-27 13:23:24 +02:00
|
|
|
|
|
|
|
/* Load return value from call into return register */
|
2006-08-11 20:41:29 +02:00
|
|
|
output( "\tlwz %s, %d(%s)\n", ppc_reg(0), 44+extra_stack_storage, ppc_reg(1));
|
|
|
|
output( "\tmtlr %s\n", ppc_reg(0));
|
|
|
|
output( "\taddi %s, %s, %d\n", ppc_reg(1), ppc_reg(1), 48+extra_stack_storage);
|
2005-06-27 13:23:24 +02:00
|
|
|
|
|
|
|
/* branch to ctr register. */
|
2006-08-11 20:41:29 +02:00
|
|
|
output( "\tbctr\n");
|
2005-06-27 13:23:24 +02:00
|
|
|
break;
|
|
|
|
}
|
2010-04-12 12:04:50 +02:00
|
|
|
output_cfi( ".cfi_endproc" );
|
2006-08-11 20:41:29 +02:00
|
|
|
output_function_size( "__wine_delay_load_asm" );
|
|
|
|
output( "\n" );
|
2001-01-02 23:22:12 +01:00
|
|
|
|
2000-12-26 02:22:34 +01:00
|
|
|
for (i = idx = 0; i < nb_imports; i++)
|
|
|
|
{
|
|
|
|
if (!dll_imports[i]->delay) continue;
|
2001-01-02 23:22:12 +01:00
|
|
|
for (j = 0; j < dll_imports[i]->nb_imports; j++)
|
|
|
|
{
|
2004-02-17 21:36:16 +01:00
|
|
|
ORDDEF *odp = dll_imports[i]->imports[j];
|
|
|
|
const char *name = odp->name ? odp->name : odp->export_name;
|
|
|
|
|
2006-08-11 20:41:29 +02:00
|
|
|
output( ".L__wine_delay_imp_%d_%s:\n", i, name );
|
2010-04-12 12:04:50 +02:00
|
|
|
output_cfi( ".cfi_startproc" );
|
2005-06-27 13:23:24 +02:00
|
|
|
switch(target_cpu)
|
|
|
|
{
|
|
|
|
case CPU_x86:
|
2006-08-11 20:41:29 +02:00
|
|
|
output( "\tmovl $%d, %%eax\n", (idx << 16) | j );
|
|
|
|
output( "\tjmp %s\n", asm_name("__wine_delay_load_asm") );
|
2005-06-27 13:23:24 +02:00
|
|
|
break;
|
2005-09-16 21:39:42 +02:00
|
|
|
case CPU_x86_64:
|
2008-12-27 19:58:42 +01:00
|
|
|
output( "\tmovq $%d,%%rax\n", (idx << 16) | j );
|
2006-08-11 20:41:29 +02:00
|
|
|
output( "\tjmp %s\n", asm_name("__wine_delay_load_asm") );
|
2005-09-16 21:39:42 +02:00
|
|
|
break;
|
2005-06-27 13:23:24 +02:00
|
|
|
case CPU_SPARC:
|
2006-08-11 20:41:29 +02:00
|
|
|
output( "\tset %d, %%g1\n", (idx << 16) | j );
|
|
|
|
output( "\tb,a %s\n", asm_name("__wine_delay_load_asm") );
|
2005-06-27 13:23:24 +02:00
|
|
|
break;
|
|
|
|
case CPU_ALPHA:
|
2006-08-11 20:41:29 +02:00
|
|
|
output( "\tlda $0,%d($31)\n", j);
|
|
|
|
output( "\tldah $0,%d($0)\n", idx);
|
|
|
|
output( "\tjmp $31,%s\n", asm_name("__wine_delay_load_asm") );
|
2005-06-27 13:23:24 +02:00
|
|
|
break;
|
2009-11-17 20:20:48 +01:00
|
|
|
case CPU_ARM:
|
|
|
|
output( "\tb %s\n", asm_name("__wine_delay_load_asm") );
|
|
|
|
break;
|
2005-06-27 13:23:24 +02:00
|
|
|
case CPU_POWERPC:
|
|
|
|
switch(target_platform)
|
|
|
|
{
|
|
|
|
case PLATFORM_APPLE:
|
|
|
|
/* On Darwin we can use r0 and r2 */
|
|
|
|
/* Upper part in r2 */
|
2006-08-11 20:41:29 +02:00
|
|
|
output( "\tlis %s, %d\n", ppc_reg(2), idx);
|
2005-06-27 13:23:24 +02:00
|
|
|
/* Lower part + r2 -> r0, Note we can't use r0 directly */
|
2006-08-11 20:41:29 +02:00
|
|
|
output( "\taddi %s, %s, %d\n", ppc_reg(0), ppc_reg(2), j);
|
|
|
|
output( "\tb %s\n", asm_name("__wine_delay_load_asm") );
|
2005-06-27 13:23:24 +02:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
/* On linux we can't use r2 since r2 is not a scratch register (hold the TOC) */
|
|
|
|
/* Save r13 on the stack */
|
2006-08-11 20:41:29 +02:00
|
|
|
output( "\taddi %s, %s, -0x4\n", ppc_reg(1), ppc_reg(1));
|
|
|
|
output( "\tstw %s, 0(%s)\n", ppc_reg(13), ppc_reg(1));
|
2005-06-27 13:23:24 +02:00
|
|
|
/* Upper part in r13 */
|
2006-08-11 20:41:29 +02:00
|
|
|
output( "\tlis %s, %d\n", ppc_reg(13), idx);
|
2005-06-27 13:23:24 +02:00
|
|
|
/* Lower part + r13 -> r0, Note we can't use r0 directly */
|
2006-08-11 20:41:29 +02:00
|
|
|
output( "\taddi %s, %s, %d\n", ppc_reg(0), ppc_reg(13), j);
|
2005-06-27 13:23:24 +02:00
|
|
|
/* Restore r13 */
|
2006-08-11 20:41:29 +02:00
|
|
|
output( "\tstw %s, 0(%s)\n", ppc_reg(13), ppc_reg(1));
|
|
|
|
output( "\taddic %s, %s, 0x4\n", ppc_reg(1), ppc_reg(1));
|
|
|
|
output( "\tb %s\n", asm_name("__wine_delay_load_asm") );
|
2005-06-27 13:23:24 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2010-04-12 12:04:50 +02:00
|
|
|
output_cfi( ".cfi_endproc" );
|
2001-01-02 23:22:12 +01:00
|
|
|
}
|
|
|
|
idx++;
|
|
|
|
}
|
2006-08-11 20:41:29 +02:00
|
|
|
output_function_size( delayed_import_loaders );
|
2000-12-26 02:22:34 +01:00
|
|
|
|
2006-08-11 20:41:29 +02:00
|
|
|
output( "\n\t.align %d\n", get_alignment(get_ptr_size()) );
|
|
|
|
output( "%s:\n", asm_name(delayed_import_thunks));
|
2005-09-03 17:39:13 +02:00
|
|
|
for (i = pos = 0; i < nb_imports; i++)
|
2001-01-02 23:22:12 +01:00
|
|
|
{
|
|
|
|
if (!dll_imports[i]->delay) continue;
|
2005-09-08 13:35:19 +02:00
|
|
|
for (j = 0; j < dll_imports[i]->nb_imports; j++, pos += get_ptr_size())
|
2000-12-26 02:22:34 +01:00
|
|
|
{
|
2004-02-17 21:36:16 +01:00
|
|
|
ORDDEF *odp = dll_imports[i]->imports[j];
|
2006-08-11 20:41:29 +02:00
|
|
|
output_import_thunk( odp->name ? odp->name : odp->export_name,
|
2005-09-03 17:39:13 +02:00
|
|
|
".L__wine_delay_IAT", pos );
|
2000-12-26 02:22:34 +01:00
|
|
|
}
|
|
|
|
}
|
2006-08-11 20:41:29 +02:00
|
|
|
output_function_size( delayed_import_thunks );
|
2000-12-26 02:22:34 +01:00
|
|
|
}
|
|
|
|
|
2005-09-19 19:04:43 +02:00
|
|
|
/* output import stubs for exported entry points that link to external symbols */
|
2006-08-11 20:41:29 +02:00
|
|
|
static void output_external_link_imports( DLLSPEC *spec )
|
2005-09-19 19:04:43 +02:00
|
|
|
{
|
|
|
|
unsigned int i, pos;
|
|
|
|
|
|
|
|
if (!ext_link_imports.count) return; /* nothing to do */
|
|
|
|
|
|
|
|
sort_names( &ext_link_imports );
|
|
|
|
|
|
|
|
/* get rid of duplicate names */
|
|
|
|
for (i = 1; i < ext_link_imports.count; i++)
|
|
|
|
{
|
|
|
|
if (!strcmp( ext_link_imports.names[i-1], ext_link_imports.names[i] ))
|
|
|
|
remove_name( &ext_link_imports, i-- );
|
|
|
|
}
|
|
|
|
|
2006-08-11 20:41:29 +02:00
|
|
|
output( "\n/* external link thunks */\n\n" );
|
|
|
|
output( "\t.data\n" );
|
|
|
|
output( "\t.align %d\n", get_alignment(get_ptr_size()) );
|
|
|
|
output( ".L__wine_spec_external_links:\n" );
|
2005-09-19 19:04:43 +02:00
|
|
|
for (i = 0; i < ext_link_imports.count; i++)
|
2006-08-11 20:41:29 +02:00
|
|
|
output( "\t%s %s\n", get_asm_ptr_keyword(), asm_name(ext_link_imports.names[i]) );
|
2005-09-19 19:04:43 +02:00
|
|
|
|
2006-08-11 20:41:29 +02:00
|
|
|
output( "\n\t.text\n" );
|
|
|
|
output( "\t.align %d\n", get_alignment(get_ptr_size()) );
|
|
|
|
output( "%s:\n", asm_name("__wine_spec_external_link_thunks") );
|
2005-09-19 19:04:43 +02:00
|
|
|
|
|
|
|
for (i = pos = 0; i < ext_link_imports.count; i++)
|
|
|
|
{
|
|
|
|
char buffer[256];
|
|
|
|
sprintf( buffer, "__wine_spec_ext_link_%s", ext_link_imports.names[i] );
|
2006-08-11 20:41:29 +02:00
|
|
|
output_import_thunk( buffer, ".L__wine_spec_external_links", pos );
|
2005-09-19 19:04:43 +02:00
|
|
|
pos += get_ptr_size();
|
|
|
|
}
|
2006-08-11 20:41:29 +02:00
|
|
|
output_function_size( "__wine_spec_external_link_thunks" );
|
2005-09-19 19:04:43 +02:00
|
|
|
}
|
|
|
|
|
2005-09-21 12:57:04 +02:00
|
|
|
/*******************************************************************
|
|
|
|
* output_stubs
|
|
|
|
*
|
|
|
|
* Output the functions for stub entry points
|
|
|
|
*/
|
2006-08-11 20:41:29 +02:00
|
|
|
void output_stubs( DLLSPEC *spec )
|
2005-09-21 12:57:04 +02:00
|
|
|
{
|
|
|
|
const char *name, *exp_name;
|
2007-04-25 09:51:44 +02:00
|
|
|
int i, count;
|
2005-09-21 12:57:04 +02:00
|
|
|
|
|
|
|
if (!has_stubs( spec )) return;
|
|
|
|
|
2006-08-11 20:41:29 +02:00
|
|
|
output( "\n/* stub functions */\n\n" );
|
|
|
|
output( "\t.text\n" );
|
2005-09-21 12:57:04 +02:00
|
|
|
|
2007-04-25 09:51:44 +02:00
|
|
|
for (i = count = 0; i < spec->nb_entry_points; i++)
|
2005-09-21 12:57:04 +02:00
|
|
|
{
|
|
|
|
ORDDEF *odp = &spec->entry_points[i];
|
|
|
|
if (odp->type != TYPE_STUB) continue;
|
|
|
|
|
|
|
|
name = get_stub_name( odp, spec );
|
|
|
|
exp_name = odp->name ? odp->name : odp->export_name;
|
2006-08-11 20:41:29 +02:00
|
|
|
output( "\t.align %d\n", get_alignment(4) );
|
|
|
|
output( "\t%s\n", func_declaration(name) );
|
|
|
|
output( "%s:\n", asm_name(name) );
|
2010-04-12 12:04:50 +02:00
|
|
|
output_cfi( ".cfi_startproc" );
|
2005-09-21 12:57:04 +02:00
|
|
|
|
2008-12-16 12:20:30 +01:00
|
|
|
switch (target_cpu)
|
2005-09-21 12:57:04 +02:00
|
|
|
{
|
2008-12-16 12:20:30 +01:00
|
|
|
case CPU_x86:
|
|
|
|
/* flesh out the stub a bit to make safedisc happy */
|
|
|
|
output(" \tnop\n" );
|
|
|
|
output(" \tnop\n" );
|
|
|
|
output(" \tnop\n" );
|
|
|
|
output(" \tnop\n" );
|
|
|
|
output(" \tnop\n" );
|
|
|
|
output(" \tnop\n" );
|
|
|
|
output(" \tnop\n" );
|
|
|
|
output(" \tnop\n" );
|
|
|
|
output(" \tnop\n" );
|
|
|
|
|
2010-04-12 12:04:50 +02:00
|
|
|
output( "\tsubl $12,%%esp\n" );
|
|
|
|
output_cfi( ".cfi_adjust_cfa_offset 12" );
|
2008-12-16 12:20:30 +01:00
|
|
|
if (UsePIC)
|
2005-09-21 12:57:04 +02:00
|
|
|
{
|
2008-12-16 12:20:30 +01:00
|
|
|
output( "\tcall %s\n", asm_name("__wine_spec_get_pc_thunk_eax") );
|
|
|
|
output( "1:" );
|
|
|
|
if (exp_name)
|
|
|
|
{
|
|
|
|
output( "\tleal .L%s_string-1b(%%eax),%%ecx\n", name );
|
2010-04-12 12:04:50 +02:00
|
|
|
output( "\tmovl %%ecx,4(%%esp)\n" );
|
2008-12-16 12:20:30 +01:00
|
|
|
count++;
|
|
|
|
}
|
|
|
|
else
|
2010-04-12 12:04:50 +02:00
|
|
|
output( "\tmovl $%d,4(%%esp)\n", odp->ordinal );
|
2008-12-16 12:20:30 +01:00
|
|
|
output( "\tleal .L__wine_spec_file_name-1b(%%eax),%%ecx\n" );
|
2010-04-12 12:04:50 +02:00
|
|
|
output( "\tmovl %%ecx,(%%esp)\n" );
|
2005-09-21 12:57:04 +02:00
|
|
|
}
|
|
|
|
else
|
2008-12-16 12:20:30 +01:00
|
|
|
{
|
|
|
|
if (exp_name)
|
|
|
|
{
|
2010-04-12 12:04:50 +02:00
|
|
|
output( "\tmovl $.L%s_string,4(%%esp)\n", name );
|
2008-12-16 12:20:30 +01:00
|
|
|
count++;
|
|
|
|
}
|
|
|
|
else
|
2010-04-12 12:04:50 +02:00
|
|
|
output( "\tmovl $%d,4(%%esp)\n", odp->ordinal );
|
|
|
|
output( "\tmovl $.L__wine_spec_file_name,(%%esp)\n" );
|
2008-12-16 12:20:30 +01:00
|
|
|
}
|
|
|
|
output( "\tcall %s\n", asm_name("__wine_spec_unimplemented_stub") );
|
|
|
|
break;
|
|
|
|
case CPU_x86_64:
|
2009-06-16 14:26:51 +02:00
|
|
|
output( "\tsubq $8,%%rsp\n" );
|
2010-04-11 12:01:01 +02:00
|
|
|
output_cfi( ".cfi_adjust_cfa_offset 8" );
|
2008-12-16 12:20:30 +01:00
|
|
|
output( "\tleaq .L__wine_spec_file_name(%%rip),%%rdi\n" );
|
2005-09-21 12:57:04 +02:00
|
|
|
if (exp_name)
|
|
|
|
{
|
2008-12-16 12:20:30 +01:00
|
|
|
output( "leaq .L%s_string(%%rip),%%rsi\n", name );
|
2007-04-25 09:51:44 +02:00
|
|
|
count++;
|
2005-09-21 12:57:04 +02:00
|
|
|
}
|
|
|
|
else
|
2008-12-16 12:20:30 +01:00
|
|
|
output( "\tmovq $%d,%%rsi\n", odp->ordinal );
|
|
|
|
output( "\tcall %s\n", asm_name("__wine_spec_unimplemented_stub") );
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
assert(0);
|
2005-09-21 12:57:04 +02:00
|
|
|
}
|
2010-04-12 12:04:50 +02:00
|
|
|
output_cfi( ".cfi_endproc" );
|
2006-08-11 20:41:29 +02:00
|
|
|
output_function_size( name );
|
2005-09-21 12:57:04 +02:00
|
|
|
}
|
|
|
|
|
2007-04-25 09:51:44 +02:00
|
|
|
if (count)
|
2005-09-21 12:57:04 +02:00
|
|
|
{
|
2006-08-11 20:41:29 +02:00
|
|
|
output( "\t%s\n", get_asm_string_section() );
|
2005-09-21 12:57:04 +02:00
|
|
|
for (i = 0; i < spec->nb_entry_points; i++)
|
|
|
|
{
|
|
|
|
ORDDEF *odp = &spec->entry_points[i];
|
|
|
|
if (odp->type != TYPE_STUB) continue;
|
|
|
|
exp_name = odp->name ? odp->name : odp->export_name;
|
|
|
|
if (exp_name)
|
2007-04-25 09:51:44 +02:00
|
|
|
{
|
|
|
|
name = get_stub_name( odp, spec );
|
|
|
|
output( ".L%s_string:\n", name );
|
2006-08-11 20:41:29 +02:00
|
|
|
output( "\t%s \"%s\"\n", get_asm_string_keyword(), exp_name );
|
2007-04-25 09:51:44 +02:00
|
|
|
}
|
2005-09-21 12:57:04 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-09-02 17:36:03 +02:00
|
|
|
/* output the import and delayed import tables of a Win32 module */
|
2006-08-11 20:41:29 +02:00
|
|
|
void output_imports( DLLSPEC *spec )
|
2005-06-06 17:59:50 +02:00
|
|
|
{
|
2006-08-11 20:41:29 +02:00
|
|
|
output_immediate_imports();
|
|
|
|
output_delayed_imports( spec );
|
|
|
|
output_immediate_import_thunks();
|
|
|
|
output_delayed_import_thunks( spec );
|
|
|
|
output_external_link_imports( spec );
|
2005-12-18 10:45:01 +01:00
|
|
|
if (nb_imports || ext_link_imports.count || has_stubs(spec) || has_relays(spec))
|
2006-08-11 20:41:29 +02:00
|
|
|
output_get_pc_thunk();
|
2005-06-06 17:59:50 +02:00
|
|
|
}
|
2009-12-30 11:51:19 +01:00
|
|
|
|
|
|
|
/* output an import library for a Win32 module and additional object files */
|
|
|
|
void output_import_lib( DLLSPEC *spec, char **argv )
|
|
|
|
{
|
|
|
|
char *dlltool, *def_file;
|
|
|
|
char *cmd;
|
|
|
|
int err;
|
|
|
|
|
|
|
|
if (target_platform != PLATFORM_WINDOWS)
|
|
|
|
fatal_error( "Unix-style import libraries not supported yet\n" );
|
|
|
|
|
|
|
|
def_file = get_temp_file_name( output_file_name, ".def" );
|
|
|
|
fclose( output_file );
|
|
|
|
if (!(output_file = fopen( def_file, "w" )))
|
|
|
|
fatal_error( "Unable to create output file '%s'\n", def_file );
|
2009-12-30 12:50:17 +01:00
|
|
|
output_def_file( spec, 0 );
|
2009-12-30 11:51:19 +01:00
|
|
|
fclose( output_file );
|
|
|
|
output_file = NULL;
|
|
|
|
|
|
|
|
dlltool = find_tool( "dlltool", NULL );
|
|
|
|
cmd = xmalloc( strlen(dlltool) + strlen(output_file_name) + strlen(def_file) + 12 );
|
|
|
|
sprintf( cmd, "%s -k -l %s -d %s", dlltool, output_file_name, def_file );
|
|
|
|
if (verbose) fprintf( stderr, "%s\n", cmd );
|
|
|
|
err = system( cmd );
|
|
|
|
if (err) fatal_error( "%s failed with status %d\n", dlltool, err );
|
|
|
|
free( cmd );
|
|
|
|
free( dlltool );
|
|
|
|
|
|
|
|
if (argv[0])
|
|
|
|
{
|
|
|
|
char *ar = find_tool( "ar", NULL );
|
|
|
|
int i, len;
|
|
|
|
|
|
|
|
for (i = len = 0; argv[i]; i++) len += strlen(argv[i]) + 1;
|
|
|
|
cmd = xmalloc( strlen(ar) + strlen(output_file_name) + len + 5 );
|
|
|
|
sprintf( cmd, "%s rs %s", ar, output_file_name );
|
|
|
|
for (i = 0; argv[i]; i++)
|
|
|
|
{
|
|
|
|
strcat( cmd, " " );
|
|
|
|
strcat( cmd, argv[i] );
|
|
|
|
}
|
|
|
|
if (verbose) fprintf( stderr, "%s\n", cmd );
|
|
|
|
err = system( cmd );
|
|
|
|
if (err) fatal_error( "%s failed with status %d\n", dlltool, err );
|
|
|
|
free( cmd );
|
|
|
|
free( ar );
|
|
|
|
}
|
|
|
|
output_file_name = NULL;
|
|
|
|
}
|