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
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 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
|
|
|
|
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
|
|
|
|
2004-03-25 01:40:52 +01:00
|
|
|
#include "windef.h"
|
|
|
|
#include "winbase.h"
|
2005-05-07 17:06:30 +02:00
|
|
|
#include "wine/exception.h"
|
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 */
|
|
|
|
};
|
|
|
|
|
2000-11-09 21:31:18 +01:00
|
|
|
static char **undef_symbols; /* list of undefined symbols */
|
2000-11-12 04:45:55 +01:00
|
|
|
static int nb_undef_symbols = -1;
|
|
|
|
static int undef_size;
|
2000-09-28 01:40:43 +02:00
|
|
|
|
2000-12-14 23:18:22 +01:00
|
|
|
static char **ignore_symbols; /* list of symbols to ignore */
|
|
|
|
static int nb_ignore_symbols;
|
|
|
|
static int ignore_size;
|
|
|
|
|
2002-08-28 00:29:26 +02:00
|
|
|
static char *ld_tmp_file; /* ld temp file name */
|
2002-08-01 20:34:12 +02: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 */
|
2005-05-06 17:54:41 +02:00
|
|
|
static char **delayed_imports; /* names of delayed import dlls */
|
|
|
|
static int nb_delayed_imports; /* size of the delayed_imports array */
|
2000-09-28 01:40:43 +02:00
|
|
|
|
2002-12-12 03:20:47 +01:00
|
|
|
/* list of symbols that are ignored by default */
|
|
|
|
static const char * const default_ignored_symbols[] =
|
|
|
|
{
|
|
|
|
"abs",
|
|
|
|
"acos",
|
|
|
|
"asin",
|
|
|
|
"atan",
|
|
|
|
"atan2",
|
|
|
|
"atof",
|
|
|
|
"atoi",
|
|
|
|
"atol",
|
|
|
|
"bsearch",
|
|
|
|
"ceil",
|
|
|
|
"cos",
|
|
|
|
"cosh",
|
|
|
|
"exp",
|
|
|
|
"fabs",
|
|
|
|
"floor",
|
|
|
|
"fmod",
|
|
|
|
"frexp",
|
|
|
|
"labs",
|
|
|
|
"log",
|
|
|
|
"log10",
|
|
|
|
"memchr",
|
|
|
|
"memcmp",
|
|
|
|
"memcpy",
|
|
|
|
"memmove",
|
|
|
|
"memset",
|
|
|
|
"modf",
|
|
|
|
"pow",
|
|
|
|
"qsort",
|
|
|
|
"sin",
|
|
|
|
"sinh",
|
|
|
|
"sqrt",
|
|
|
|
"strcat",
|
|
|
|
"strchr",
|
|
|
|
"strcmp",
|
|
|
|
"strcpy",
|
|
|
|
"strcspn",
|
|
|
|
"strlen",
|
|
|
|
"strncat",
|
|
|
|
"strncmp",
|
|
|
|
"strncpy",
|
|
|
|
"strpbrk",
|
|
|
|
"strrchr",
|
|
|
|
"strspn",
|
|
|
|
"strstr",
|
|
|
|
"tan",
|
2002-12-20 01:36:18 +01:00
|
|
|
"tanh"
|
2002-12-12 03:20:47 +01: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
|
|
|
}
|
|
|
|
|
2000-11-09 21:31:18 +01:00
|
|
|
/* locate a symbol in a (sorted) list */
|
|
|
|
inline static const char *find_symbol( const char *name, char **table, int size )
|
|
|
|
{
|
2000-12-18 04:13:52 +01:00
|
|
|
char **res = NULL;
|
|
|
|
|
|
|
|
if (table) {
|
|
|
|
res = bsearch( &name, table, size, sizeof(*table), name_cmp );
|
|
|
|
}
|
|
|
|
|
2000-11-09 21:31:18 +01:00
|
|
|
return res ? *res : NULL;
|
|
|
|
}
|
|
|
|
|
2002-07-25 02:25:40 +02:00
|
|
|
/* locate an export in a (sorted) export list */
|
2004-02-17 21:36:16 +01:00
|
|
|
inline static 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
|
|
|
|
2002-12-12 23:03:14 +01:00
|
|
|
func.name = (char *)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 );
|
|
|
|
return res ? *res : NULL;
|
2002-07-25 02:25:40 +02:00
|
|
|
}
|
|
|
|
|
2000-11-09 21:31:18 +01:00
|
|
|
/* sort a symbol table */
|
|
|
|
inline static void sort_symbols( char **table, int size )
|
|
|
|
{
|
2000-12-29 06:17:33 +01:00
|
|
|
if (table )
|
|
|
|
qsort( table, size, sizeof(*table), name_cmp );
|
2000-11-09 21:31:18 +01:00
|
|
|
}
|
|
|
|
|
2004-06-18 21:36:26 +02:00
|
|
|
inline static void output_function_size( FILE *outfile, const char *name )
|
|
|
|
{
|
2005-06-27 13:23:24 +02:00
|
|
|
const char *size = func_size( name );
|
|
|
|
if (size[0]) fprintf( outfile, " \"\\t%s\\n\"\n", size );
|
2004-06-18 21:36:26 +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 );
|
|
|
|
}
|
|
|
|
|
2002-08-01 20:34:12 +02:00
|
|
|
/* remove the temp file at exit */
|
|
|
|
static void remove_ld_tmp_file(void)
|
|
|
|
{
|
|
|
|
if (ld_tmp_file) unlink( ld_tmp_file );
|
|
|
|
}
|
|
|
|
|
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 )
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < nb_delayed_imports; i++)
|
|
|
|
{
|
|
|
|
if (!strcmp( delayed_imports[i], name )) return 1;
|
|
|
|
}
|
|
|
|
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
|
|
|
|
2004-02-17 21:36:16 +01:00
|
|
|
imp->exports = xmalloc( spec->nb_entry_points * sizeof(*imp->exports) );
|
2002-12-12 23:03:14 +01:00
|
|
|
|
2004-02-17 21:36:16 +01:00
|
|
|
for (i = 0; i < spec->nb_entry_points; i++)
|
|
|
|
{
|
|
|
|
ORDDEF *odp = &spec->entry_points[i];
|
2000-11-09 21:31:18 +01:00
|
|
|
|
2004-02-17 21:36:16 +01:00
|
|
|
if (odp->type != TYPE_STDCALL && odp->type != TYPE_CDECL) continue;
|
|
|
|
if (odp->flags & FLAG_PRIVATE) continue;
|
|
|
|
imp->exports[imp->nb_exports++] = odp;
|
2000-11-09 21:31:18 +01:00
|
|
|
}
|
2004-02-17 21:36:16 +01:00
|
|
|
imp->exports = xrealloc( imp->exports, imp->nb_exports * sizeof(*imp->exports) );
|
2002-07-25 02:25:40 +02:00
|
|
|
if (imp->nb_exports)
|
|
|
|
qsort( imp->exports, imp->nb_exports, sizeof(*imp->exports), func_cmp );
|
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 );
|
|
|
|
|
|
|
|
delayed_imports = xrealloc( delayed_imports, (nb_delayed_imports+1) * sizeof(*delayed_imports) );
|
|
|
|
delayed_imports[nb_delayed_imports++] = fullname;
|
|
|
|
if ((imp = is_already_imported( fullname )) && !imp->delay)
|
|
|
|
{
|
|
|
|
imp->delay = 1;
|
|
|
|
nb_delayed++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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
|
|
|
/* initialize the list of ignored symbols */
|
|
|
|
static void init_ignored_symbols(void)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
nb_ignore_symbols = sizeof(default_ignored_symbols)/sizeof(default_ignored_symbols[0]);
|
|
|
|
ignore_size = nb_ignore_symbols + 32;
|
|
|
|
ignore_symbols = xmalloc( ignore_size * sizeof(*ignore_symbols) );
|
|
|
|
for (i = 0; i < nb_ignore_symbols; i++)
|
|
|
|
ignore_symbols[i] = xstrdup( default_ignored_symbols[i] );
|
|
|
|
}
|
|
|
|
|
|
|
|
/* 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 )
|
|
|
|
{
|
2002-12-12 03:20:47 +01:00
|
|
|
int i;
|
|
|
|
|
|
|
|
if (!ignore_symbols) init_ignored_symbols(); /* first time around, fill list with defaults */
|
|
|
|
|
|
|
|
if (name[0] == '-') /* remove it */
|
2000-12-14 23:18:22 +01:00
|
|
|
{
|
2002-12-12 03:20:47 +01:00
|
|
|
if (!name[1]) /* remove everything */
|
|
|
|
{
|
|
|
|
for (i = 0; i < nb_ignore_symbols; i++) free( ignore_symbols[i] );
|
|
|
|
nb_ignore_symbols = 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
for (i = 0; i < nb_ignore_symbols; i++)
|
|
|
|
{
|
|
|
|
if (!strcmp( ignore_symbols[i], name+1 ))
|
|
|
|
{
|
|
|
|
free( ignore_symbols[i] );
|
|
|
|
memmove( &ignore_symbols[i], &ignore_symbols[i+1], nb_ignore_symbols - i - 1 );
|
|
|
|
nb_ignore_symbols--;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (nb_ignore_symbols == ignore_size)
|
|
|
|
{
|
|
|
|
ignore_size += 32;
|
|
|
|
ignore_symbols = xrealloc( ignore_symbols, ignore_size * sizeof(*ignore_symbols) );
|
|
|
|
}
|
|
|
|
ignore_symbols[nb_ignore_symbols++] = xstrdup( name );
|
2000-12-14 23:18:22 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
|
|
|
/* add a symbol to the undef list */
|
|
|
|
inline static void add_undef_symbol( const char *name )
|
|
|
|
{
|
|
|
|
if (nb_undef_symbols == undef_size)
|
|
|
|
{
|
|
|
|
undef_size += 128;
|
|
|
|
undef_symbols = xrealloc( undef_symbols, undef_size * sizeof(*undef_symbols) );
|
|
|
|
}
|
|
|
|
undef_symbols[nb_undef_symbols++] = xstrdup( name );
|
|
|
|
}
|
|
|
|
|
2000-12-14 23:18:22 +01:00
|
|
|
/* remove all the holes in the undefined symbol list; return the number of removed symbols */
|
|
|
|
static int remove_symbol_holes(void)
|
|
|
|
{
|
|
|
|
int i, off;
|
|
|
|
for (i = off = 0; i < nb_undef_symbols; i++)
|
|
|
|
{
|
|
|
|
if (!undef_symbols[i]) off++;
|
|
|
|
else undef_symbols[i - off] = undef_symbols[i];
|
|
|
|
}
|
|
|
|
nb_undef_symbols -= off;
|
|
|
|
return off;
|
|
|
|
}
|
|
|
|
|
2002-05-25 23:09:15 +02:00
|
|
|
/* add a symbol to the extra list, but only if needed */
|
2004-02-11 07:41:01 +01:00
|
|
|
static int add_extra_symbol( const char **extras, int *count, const char *name, const DLLSPEC *spec )
|
2002-05-25 23:09:15 +02:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
if (!find_symbol( name, undef_symbols, nb_undef_symbols ))
|
|
|
|
{
|
|
|
|
/* check if the symbol is being exported by this dll */
|
2004-02-11 07:41:01 +01:00
|
|
|
for (i = 0; i < spec->nb_entry_points; i++)
|
2002-05-25 23:09:15 +02:00
|
|
|
{
|
2004-02-11 07:41:01 +01:00
|
|
|
ORDDEF *odp = &spec->entry_points[i];
|
2002-05-25 23:09:15 +02:00
|
|
|
if (odp->type == TYPE_STDCALL ||
|
|
|
|
odp->type == TYPE_CDECL ||
|
|
|
|
odp->type == TYPE_VARARGS ||
|
|
|
|
odp->type == TYPE_EXTERN)
|
|
|
|
{
|
2002-07-28 19:54:31 +02:00
|
|
|
if (odp->name && !strcmp( odp->name, name )) return 0;
|
2002-05-25 23:09:15 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
extras[*count] = name;
|
|
|
|
(*count)++;
|
|
|
|
}
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2000-11-09 21:31:18 +01:00
|
|
|
/* add the extra undefined symbols that will be contained in the generated spec file itself */
|
2004-02-11 07:41:01 +01:00
|
|
|
static void add_extra_undef_symbols( const DLLSPEC *spec )
|
2000-11-09 21:31:18 +01:00
|
|
|
{
|
2001-12-11 01:50:33 +01:00
|
|
|
const char *extras[10];
|
2005-05-07 20:47:22 +02:00
|
|
|
int i, count = 0, nb_stubs = 0;
|
2002-05-25 23:09:15 +02:00
|
|
|
int kernel_imports = 0, ntdll_imports = 0;
|
2000-11-09 21:31:18 +01:00
|
|
|
|
|
|
|
sort_symbols( undef_symbols, nb_undef_symbols );
|
|
|
|
|
2004-02-11 07:41:01 +01:00
|
|
|
for (i = 0; i < spec->nb_entry_points; i++)
|
2002-05-17 01:17:37 +02:00
|
|
|
{
|
2004-02-11 07:41:01 +01:00
|
|
|
ORDDEF *odp = &spec->entry_points[i];
|
2002-05-17 01:17:37 +02:00
|
|
|
if (odp->type == TYPE_STUB) nb_stubs++;
|
|
|
|
}
|
|
|
|
|
2000-11-09 21:31:18 +01:00
|
|
|
/* add symbols that will be contained in the spec file itself */
|
2004-03-25 01:40:52 +01:00
|
|
|
if (!(spec->characteristics & IMAGE_FILE_DLL))
|
2000-11-09 21:31:18 +01:00
|
|
|
{
|
2004-03-25 01:40:52 +01:00
|
|
|
switch (spec->subsystem)
|
|
|
|
{
|
|
|
|
case IMAGE_SUBSYSTEM_WINDOWS_GUI:
|
2004-04-08 06:41:14 +02:00
|
|
|
case IMAGE_SUBSYSTEM_WINDOWS_CUI:
|
2004-03-25 01:40:52 +01:00
|
|
|
kernel_imports += add_extra_symbol( extras, &count, "GetCommandLineA", spec );
|
|
|
|
kernel_imports += add_extra_symbol( extras, &count, "GetStartupInfoA", spec );
|
|
|
|
kernel_imports += add_extra_symbol( extras, &count, "GetModuleHandleA", spec );
|
|
|
|
kernel_imports += add_extra_symbol( extras, &count, "ExitProcess", spec );
|
|
|
|
break;
|
|
|
|
}
|
2000-11-09 21:31:18 +01:00
|
|
|
}
|
2000-12-26 02:22:34 +01:00
|
|
|
if (nb_delayed)
|
|
|
|
{
|
2004-02-11 07:41:01 +01:00
|
|
|
kernel_imports += add_extra_symbol( extras, &count, "LoadLibraryA", spec );
|
2005-05-24 12:13:30 +02:00
|
|
|
kernel_imports += add_extra_symbol( extras, &count, "FreeLibrary", spec );
|
2004-02-11 07:41:01 +01:00
|
|
|
kernel_imports += add_extra_symbol( extras, &count, "GetProcAddress", spec );
|
2005-05-07 17:06:30 +02:00
|
|
|
kernel_imports += add_extra_symbol( extras, &count, "RaiseException", spec );
|
2000-12-26 02:22:34 +01:00
|
|
|
}
|
2005-05-07 17:06:30 +02:00
|
|
|
if (nb_stubs)
|
2004-02-11 07:41:01 +01:00
|
|
|
ntdll_imports += add_extra_symbol( extras, &count, "RtlRaiseException", spec );
|
2000-12-15 04:38:11 +01:00
|
|
|
|
2002-05-17 01:17:37 +02:00
|
|
|
/* make sure we import the dlls that contain these functions */
|
2005-05-06 17:54:41 +02:00
|
|
|
if (kernel_imports) add_import_dll( "kernel32", NULL );
|
|
|
|
if (ntdll_imports) add_import_dll( "ntdll", NULL );
|
2001-12-11 01:50:33 +01:00
|
|
|
|
2000-11-09 21:31:18 +01:00
|
|
|
if (count)
|
|
|
|
{
|
|
|
|
for (i = 0; i < count; i++) add_undef_symbol( extras[i] );
|
|
|
|
sort_symbols( undef_symbols, nb_undef_symbols );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
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 */
|
|
|
|
static const char *ldcombine_files( char **argv )
|
|
|
|
{
|
|
|
|
int i, len = 0;
|
2004-10-08 23:11:18 +02:00
|
|
|
char *cmd;
|
2002-08-01 20:34:12 +02:00
|
|
|
int fd, err;
|
|
|
|
|
2002-08-28 00:29:26 +02:00
|
|
|
if (output_file_name && output_file_name[0])
|
|
|
|
{
|
2003-03-20 22:07:49 +01:00
|
|
|
ld_tmp_file = xmalloc( strlen(output_file_name) + 10 );
|
2002-08-28 00:29:26 +02:00
|
|
|
strcpy( ld_tmp_file, output_file_name );
|
2003-03-20 22:07:49 +01:00
|
|
|
strcat( ld_tmp_file, ".XXXXXX.o" );
|
2002-08-28 00:29:26 +02:00
|
|
|
}
|
2003-03-20 22:07:49 +01:00
|
|
|
else ld_tmp_file = xstrdup( "/tmp/winebuild.tmp.XXXXXX.o" );
|
2002-08-28 00:29:26 +02:00
|
|
|
|
2003-03-20 22:07:49 +01:00
|
|
|
if ((fd = mkstemps( ld_tmp_file, 2 ) == -1)) fatal_error( "could not generate a temp file\n" );
|
2002-08-01 20:34:12 +02:00
|
|
|
close( fd );
|
|
|
|
atexit( remove_ld_tmp_file );
|
|
|
|
|
2005-07-01 18:17:44 +02:00
|
|
|
if (!ld_command) ld_command = xstrdup("ld");
|
2002-08-01 20:34:12 +02:00
|
|
|
for (i = 0; argv[i]; i++) len += strlen(argv[i]) + 1;
|
2004-10-08 23:11:18 +02:00
|
|
|
cmd = xmalloc( len + strlen(ld_tmp_file) + 8 + strlen(ld_command) );
|
|
|
|
sprintf( cmd, "%s -r -o %s", ld_command, ld_tmp_file );
|
2002-08-01 20:34:12 +02:00
|
|
|
for (i = 0; argv[i]; i++) sprintf( cmd + strlen(cmd), " %s", argv[i] );
|
|
|
|
err = system( cmd );
|
2004-10-08 23:11:18 +02:00
|
|
|
if (err) fatal_error( "%s -r failed with status %d\n", ld_command, 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 */
|
2002-08-01 20:34:12 +02:00
|
|
|
void read_undef_symbols( 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;
|
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-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 );
|
|
|
|
|
2000-11-09 21:31:18 +01:00
|
|
|
undef_size = nb_undef_symbols = 0;
|
|
|
|
|
2002-08-01 20:34:12 +02:00
|
|
|
/* if we have multiple object files, link them together */
|
|
|
|
if (argv[1]) name = ldcombine_files( argv );
|
|
|
|
else name = argv[0];
|
|
|
|
|
2005-07-01 18:17:44 +02:00
|
|
|
if (!nm_command) nm_command = xstrdup("nm");
|
2004-10-08 23:11:18 +02:00
|
|
|
cmd = xmalloc( strlen(nm_command) + strlen(name) + 5 );
|
|
|
|
sprintf( cmd, "%s -u %s", nm_command, name );
|
|
|
|
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;
|
2000-12-29 06:17:33 +01:00
|
|
|
add_undef_symbol( 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
|
|
|
}
|
|
|
|
|
2000-12-14 23:18:22 +01:00
|
|
|
static void remove_ignored_symbols(void)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
2002-12-12 03:20:47 +01:00
|
|
|
if (!ignore_symbols) init_ignored_symbols();
|
2000-12-14 23:18:22 +01:00
|
|
|
sort_symbols( ignore_symbols, nb_ignore_symbols );
|
|
|
|
for (i = 0; i < nb_undef_symbols; i++)
|
|
|
|
{
|
|
|
|
if (find_symbol( undef_symbols[i], ignore_symbols, nb_ignore_symbols ))
|
|
|
|
{
|
|
|
|
free( undef_symbols[i] );
|
|
|
|
undef_symbols[i] = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
remove_symbol_holes();
|
|
|
|
}
|
|
|
|
|
2000-11-09 21:31:18 +01:00
|
|
|
/* resolve the imports for a Win32 module */
|
2004-02-11 07:41:01 +01:00
|
|
|
int resolve_imports( DLLSPEC *spec )
|
2000-11-09 21:31:18 +01:00
|
|
|
{
|
2000-12-14 23:18:22 +01:00
|
|
|
int i, j;
|
2000-11-09 21:31:18 +01:00
|
|
|
|
2000-11-12 04:45:55 +01:00
|
|
|
if (nb_undef_symbols == -1) return 0; /* no symbol file specified */
|
2000-11-09 21:31:18 +01:00
|
|
|
|
2004-02-11 07:41:01 +01:00
|
|
|
add_extra_undef_symbols( spec );
|
2000-12-14 23:18:22 +01:00
|
|
|
remove_ignored_symbols();
|
2000-11-09 21:31:18 +01:00
|
|
|
|
|
|
|
for (i = 0; i < nb_imports; i++)
|
|
|
|
{
|
|
|
|
struct import *imp = dll_imports[i];
|
|
|
|
|
|
|
|
for (j = 0; j < nb_undef_symbols; j++)
|
|
|
|
{
|
2004-02-17 21:36:16 +01:00
|
|
|
ORDDEF *odp = find_export( undef_symbols[j], imp->exports, imp->nb_exports );
|
|
|
|
if (odp)
|
2000-11-09 21:31:18 +01:00
|
|
|
{
|
2004-02-17 21:36:16 +01:00
|
|
|
add_import_func( imp, odp );
|
2000-12-14 23:18:22 +01:00
|
|
|
free( undef_symbols[j] );
|
2000-11-09 21:31:18 +01:00
|
|
|
undef_symbols[j] = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* remove all the holes in the undef symbols list */
|
2004-02-11 07:41:01 +01:00
|
|
|
if (!remove_symbol_holes() && check_unused( imp, spec ))
|
2003-03-17 00:59:48 +01:00
|
|
|
{
|
|
|
|
/* the dll is not used, get rid of it */
|
2004-02-17 21:36:16 +01:00
|
|
|
warning( "%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
|
|
|
}
|
|
|
|
return 1;
|
|
|
|
}
|
2000-09-28 01:40:43 +02:00
|
|
|
|
2005-06-16 22:51:50 +02:00
|
|
|
/* output a single import thunk */
|
|
|
|
static void output_import_thunk( FILE *outfile, const char *name, const char *table, int pos )
|
|
|
|
{
|
2005-07-01 17:49:39 +02:00
|
|
|
fprintf( outfile, " \"\\t.align %d\\n\"\n", get_alignment(4) );
|
2005-06-27 13:23:24 +02:00
|
|
|
fprintf( outfile, " \"\\t%s\\n\"\n", func_declaration(name) );
|
2005-06-27 20:59:54 +02:00
|
|
|
fprintf( outfile, " \"\\t.globl %s\\n\"\n", asm_name(name) );
|
|
|
|
fprintf( outfile, " \"%s:\\n\"\n", asm_name(name) );
|
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
|
|
|
{
|
2005-06-27 13:23:24 +02:00
|
|
|
if (strstr( name, "__wine_call_from_16" )) fprintf( outfile, " \"\\t.byte 0x2e\\n\"\n" );
|
|
|
|
fprintf( outfile, " \"\\tjmp *(imports+%d)\\n\"\n", pos );
|
2005-06-16 22:51:50 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2005-06-27 13:23:24 +02:00
|
|
|
if (!strcmp( name, "__wine_call_from_32_regs" ) ||
|
|
|
|
!strcmp( name, "__wine_call_from_16_regs" ))
|
|
|
|
{
|
|
|
|
/* special case: need to preserve all registers */
|
|
|
|
fprintf( outfile, " \"\\tpushl %%eax\\n\"\n" );
|
|
|
|
fprintf( outfile, " \"\\tcall .L__wine_spec_%s\\n\"\n", name );
|
|
|
|
fprintf( outfile, " \".L__wine_spec_%s:\\n\"\n", name );
|
|
|
|
fprintf( outfile, " \"\\tpopl %%eax\\n\"\n" );
|
|
|
|
if (!strcmp( name, "__wine_call_from_16_regs" ))
|
|
|
|
fprintf( outfile, " \"\\t.byte 0x2e\\n\"\n" );
|
2005-07-01 17:49:39 +02:00
|
|
|
fprintf( outfile, " \"\\tmovl %s+%d-.L__wine_spec_%s(%%eax),%%eax\\n\"\n",
|
|
|
|
asm_name(table), pos, name );
|
|
|
|
fprintf( outfile, " \"\\txchgl %%eax,(%%esp)\\n\"\n" );
|
2005-06-27 13:23:24 +02:00
|
|
|
fprintf( outfile, " \"\\tret\\n\"\n" );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
fprintf( outfile, " \"\\tcall .L__wine_spec_%s\\n\"\n", name );
|
|
|
|
fprintf( outfile, " \".L__wine_spec_%s:\\n\"\n", name );
|
|
|
|
fprintf( outfile, " \"\\tpopl %%eax\\n\"\n" );
|
|
|
|
if (strstr( name, "__wine_call_from_16" ))
|
|
|
|
fprintf( outfile, " \"\\t.byte 0x2e\\n\"\n" );
|
2005-07-01 17:49:39 +02:00
|
|
|
fprintf( outfile, " \"\\tjmp *%s+%d-.L__wine_spec_%s(%%eax)\\n\"\n",
|
|
|
|
asm_name(table), pos, name );
|
2005-06-27 13:23:24 +02:00
|
|
|
}
|
2005-06-16 22:51:50 +02:00
|
|
|
}
|
2005-06-27 13:23:24 +02:00
|
|
|
break;
|
|
|
|
case CPU_SPARC:
|
|
|
|
if ( !UsePIC )
|
|
|
|
{
|
|
|
|
fprintf( outfile, " \"\\tsethi %%hi(%s+%d), %%g1\\n\"\n", table, pos );
|
|
|
|
fprintf( outfile, " \"\\tld [%%g1+%%lo(%s+%d)], %%g1\\n\"\n", table, pos );
|
|
|
|
fprintf( outfile, " \"\\tjmp %%g1\\n\\tnop\\n\"\n" );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Hmpf. Stupid sparc assembler always interprets global variable
|
|
|
|
names as GOT offsets, so we have to do it the long way ... */
|
|
|
|
fprintf( outfile, " \"\\tsave %%sp, -96, %%sp\\n\"\n" );
|
|
|
|
fprintf( outfile, " \"0:\\tcall 1f\\n\\tnop\\n\"\n" );
|
|
|
|
fprintf( outfile, " \"1:\\tsethi %%hi(%s+%d-0b), %%g1\\n\"\n", table, pos );
|
|
|
|
fprintf( outfile, " \"\\tor %%g1, %%lo(%s+%d-0b), %%g1\\n\"\n", table, pos );
|
|
|
|
fprintf( outfile, " \"\\tld [%%g1+%%o7], %%g1\\n\"\n" );
|
|
|
|
fprintf( outfile, " \"\\tjmp %%g1\\n\\trestore\\n\"\n" );
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case CPU_ALPHA:
|
|
|
|
fprintf( outfile, " \"\\tlda $0,%s\\n\"\n", table );
|
|
|
|
fprintf( outfile, " \"\\tlda $0,%d($0)\\n\"\n", pos);
|
|
|
|
fprintf( outfile, " \"\\tjmp $31,($0)\\n\"\n" );
|
|
|
|
break;
|
|
|
|
case CPU_POWERPC:
|
|
|
|
fprintf(outfile, " \"\\taddi %s, %s, -0x4\\n\"\n", ppc_reg(1), ppc_reg(1));
|
|
|
|
fprintf(outfile, " \"\\tstw %s, 0(%s)\\n\"\n", ppc_reg(9), ppc_reg(1));
|
|
|
|
fprintf(outfile, " \"\\taddi %s, %s, -0x4\\n\"\n", ppc_reg(1), ppc_reg(1));
|
|
|
|
fprintf(outfile, " \"\\tstw %s, 0(%s)\\n\"\n", ppc_reg(8), ppc_reg(1));
|
|
|
|
fprintf(outfile, " \"\\taddi %s, %s, -0x4\\n\"\n", ppc_reg(1), ppc_reg(1));
|
|
|
|
fprintf(outfile, " \"\\tstw %s, 0(%s)\\n\"\n", ppc_reg(7), ppc_reg(1));
|
|
|
|
if (target_platform == PLATFORM_APPLE)
|
|
|
|
{
|
2005-06-27 20:59:54 +02:00
|
|
|
fprintf(outfile, " \"\\tlis %s, ha16(%s+%d)\\n\"\n",
|
|
|
|
ppc_reg(9), asm_name(table), pos);
|
|
|
|
fprintf(outfile, " \"\\tla %s, lo16(%s+%d)(%s)\\n\"\n",
|
|
|
|
ppc_reg(8), asm_name(table), pos, ppc_reg(9));
|
2005-06-27 13:23:24 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2005-06-27 20:59:54 +02:00
|
|
|
fprintf(outfile, " \"\\tlis %s, (%s+%d)@hi\\n\"\n",
|
|
|
|
ppc_reg(9), asm_name(table), pos);
|
|
|
|
fprintf(outfile, " \"\\tla %s, (%s+%d)@l(%s)\\n\"\n",
|
|
|
|
ppc_reg(8), asm_name(table), pos, ppc_reg(9));
|
2005-06-27 13:23:24 +02:00
|
|
|
}
|
|
|
|
fprintf(outfile, " \"\\tlwz %s, 0(%s)\\n\"\n", ppc_reg(7), ppc_reg(8));
|
|
|
|
fprintf(outfile, " \"\\tmtctr %s\\n\"\n", ppc_reg(7));
|
|
|
|
fprintf(outfile, " \"\\tlwz %s, 0(%s)\\n\"\n", ppc_reg(7), ppc_reg(1));
|
|
|
|
fprintf(outfile, " \"\\taddi %s, %s, 0x4\\n\"\n", ppc_reg(1), ppc_reg(1));
|
|
|
|
fprintf(outfile, " \"\\tlwz %s, 0(%s)\\n\"\n", ppc_reg(8), ppc_reg(1));
|
|
|
|
fprintf(outfile, " \"\\taddi %s, %s, 0x4\\n\"\n", ppc_reg(1), ppc_reg(1));
|
|
|
|
fprintf(outfile, " \"\\tlwz %s, 0(%s)\\n\"\n", ppc_reg(9), ppc_reg(1));
|
|
|
|
fprintf(outfile, " \"\\taddi %s, %s, 0x4\\n\"\n", ppc_reg(1), ppc_reg(1));
|
|
|
|
fprintf(outfile, " \"\\tbctr\\n\"\n");
|
|
|
|
break;
|
2005-06-16 22:51:50 +02:00
|
|
|
}
|
|
|
|
output_function_size( outfile, name );
|
|
|
|
}
|
|
|
|
|
2000-09-28 01:40:43 +02:00
|
|
|
/* output the import table of a Win32 module */
|
2000-12-26 02:22:34 +01:00
|
|
|
static int output_immediate_imports( FILE *outfile )
|
2000-09-28 01:40:43 +02:00
|
|
|
{
|
2005-06-06 17:59:50 +02:00
|
|
|
int i, j, nb_imm = nb_imports - nb_delayed;
|
2000-09-28 01:40:43 +02:00
|
|
|
|
2005-06-06 17:59:50 +02:00
|
|
|
if (!nb_imm) return 0;
|
2000-09-28 01:40:43 +02:00
|
|
|
|
|
|
|
/* main import header */
|
|
|
|
|
2000-11-26 05:02:09 +01:00
|
|
|
fprintf( outfile, "\nstatic struct {\n" );
|
2000-09-28 01:40:43 +02:00
|
|
|
fprintf( outfile, " struct {\n" );
|
|
|
|
fprintf( outfile, " void *OriginalFirstThunk;\n" );
|
|
|
|
fprintf( outfile, " unsigned int TimeDateStamp;\n" );
|
|
|
|
fprintf( outfile, " unsigned int ForwarderChain;\n" );
|
|
|
|
fprintf( outfile, " const char *Name;\n" );
|
|
|
|
fprintf( outfile, " void *FirstThunk;\n" );
|
2000-12-26 02:22:34 +01:00
|
|
|
fprintf( outfile, " } imp[%d];\n", nb_imm+1 );
|
|
|
|
fprintf( outfile, " const char *data[%d];\n",
|
|
|
|
total_imports - total_delayed + nb_imm );
|
2000-09-28 01:40:43 +02:00
|
|
|
fprintf( outfile, "} imports = {\n {\n" );
|
|
|
|
|
|
|
|
/* 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;
|
2000-09-28 01:40:43 +02:00
|
|
|
fprintf( outfile, " { 0, 0, 0, \"%s\", &imports.data[%d] },\n",
|
2004-02-17 21:36:16 +01:00
|
|
|
dll_imports[i]->spec->file_name, j );
|
2000-09-28 01:40:43 +02:00
|
|
|
j += dll_imports[i]->nb_imports + 1;
|
|
|
|
}
|
2000-12-26 02:22:34 +01:00
|
|
|
|
2000-09-28 01:40:43 +02:00
|
|
|
fprintf( outfile, " { 0, 0, 0, 0, 0 },\n" );
|
|
|
|
fprintf( outfile, " },\n {\n" );
|
|
|
|
|
|
|
|
/* list of imported functions */
|
|
|
|
|
|
|
|
for (i = 0; i < nb_imports; i++)
|
|
|
|
{
|
2000-12-26 02:22:34 +01:00
|
|
|
if (dll_imports[i]->delay) continue;
|
2004-02-17 21:36:16 +01:00
|
|
|
fprintf( outfile, " /* %s */\n", 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
|
|
|
{
|
2004-02-17 21:36:16 +01:00
|
|
|
unsigned short ord = odp->ordinal;
|
2002-07-28 19:54:31 +02:00
|
|
|
fprintf( outfile, " \"\\%03o\\%03o%s\",\n",
|
2004-02-17 21:36:16 +01:00
|
|
|
*(unsigned char *)&ord, *((unsigned char *)&ord + 1), odp->name );
|
2002-07-28 19:54:31 +02:00
|
|
|
}
|
|
|
|
else
|
2004-02-17 21:36:16 +01:00
|
|
|
fprintf( outfile, " (char *)%d,\n", odp->ordinal );
|
2002-07-25 02:25:40 +02:00
|
|
|
}
|
2000-09-28 01:40:43 +02:00
|
|
|
fprintf( outfile, " 0,\n" );
|
|
|
|
}
|
|
|
|
fprintf( outfile, " }\n};\n\n" );
|
|
|
|
|
2005-06-06 17:59:50 +02:00
|
|
|
return nb_imm;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* output the import thunks of a Win32 module */
|
|
|
|
static void output_immediate_import_thunks( FILE *outfile )
|
|
|
|
{
|
|
|
|
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
|
|
|
|
2004-10-14 02:26:08 +02:00
|
|
|
pos = (sizeof(void *) + 2*sizeof(unsigned int) + sizeof(const char *) + sizeof(void *)) *
|
|
|
|
(nb_imm + 1); /* offset of imports.data from start of imports */
|
2005-06-06 17:59:50 +02:00
|
|
|
fprintf( outfile, "/* immediate import thunks */\n" );
|
2005-02-09 15:06:32 +01:00
|
|
|
fprintf( outfile, "asm(\".text\\n\\t.align %d\\n\"\n", get_alignment(8) );
|
2005-06-27 20:59:54 +02:00
|
|
|
fprintf( outfile, " \"%s:\\n\"\n", asm_name(import_thunks));
|
2004-05-18 23:27:44 +02:00
|
|
|
|
2000-12-26 02:22:34 +01:00
|
|
|
for (i = 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;
|
2004-10-14 02:26:08 +02:00
|
|
|
for (j = 0; j < dll_imports[i]->nb_imports; j++, pos += sizeof(const char *))
|
2000-09-28 01:40:43 +02:00
|
|
|
{
|
2004-02-17 21:36:16 +01:00
|
|
|
ORDDEF *odp = dll_imports[i]->imports[j];
|
2005-06-16 22:51:50 +02:00
|
|
|
output_import_thunk( outfile, odp->name ? odp->name : odp->export_name,
|
|
|
|
"imports", pos );
|
2000-09-28 01:40:43 +02:00
|
|
|
}
|
2000-12-29 18:44:40 +01:00
|
|
|
pos += 4;
|
2000-09-28 01:40:43 +02:00
|
|
|
}
|
2004-06-18 21:36:26 +02:00
|
|
|
output_function_size( outfile, import_thunks );
|
2005-06-06 17:59:50 +02:00
|
|
|
fprintf( outfile, ");\n" );
|
2000-12-26 02:22:34 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* output the delayed import table of a Win32 module */
|
2004-02-11 07:41:01 +01:00
|
|
|
static int output_delayed_imports( FILE *outfile, const DLLSPEC *spec )
|
2000-12-26 02:22:34 +01:00
|
|
|
{
|
2005-06-06 17:59:50 +02:00
|
|
|
int i, j;
|
2000-12-26 02:22:34 +01:00
|
|
|
|
2005-06-06 17:59:50 +02:00
|
|
|
if (!nb_delayed) return 0;
|
2000-12-26 02:22:34 +01:00
|
|
|
|
2005-05-24 12:13:30 +02:00
|
|
|
fprintf( outfile, "static void *__wine_delay_imp_hmod[%d];\n", nb_delayed );
|
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;
|
|
|
|
fprintf( outfile, "void __wine_delay_imp_%d_%s();\n", i, name );
|
2000-12-26 02:22:34 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
fprintf( outfile, "\n" );
|
|
|
|
fprintf( outfile, "static struct {\n" );
|
|
|
|
fprintf( outfile, " struct ImgDelayDescr {\n" );
|
|
|
|
fprintf( outfile, " unsigned int grAttrs;\n" );
|
|
|
|
fprintf( outfile, " const char *szName;\n" );
|
|
|
|
fprintf( outfile, " void **phmod;\n" );
|
|
|
|
fprintf( outfile, " void **pIAT;\n" );
|
|
|
|
fprintf( outfile, " const char **pINT;\n" );
|
|
|
|
fprintf( outfile, " void* pBoundIAT;\n" );
|
|
|
|
fprintf( outfile, " void* pUnloadIAT;\n" );
|
|
|
|
fprintf( outfile, " unsigned long dwTimeStamp;\n" );
|
|
|
|
fprintf( outfile, " } imp[%d];\n", nb_delayed );
|
|
|
|
fprintf( outfile, " void *IAT[%d];\n", total_delayed );
|
|
|
|
fprintf( outfile, " const char *INT[%d];\n", total_delayed );
|
|
|
|
fprintf( outfile, "} delay_imports = {\n" );
|
|
|
|
fprintf( outfile, " {\n" );
|
|
|
|
for (i = j = 0; i < nb_imports; i++)
|
|
|
|
{
|
|
|
|
if (!dll_imports[i]->delay) continue;
|
2005-05-24 12:13:30 +02:00
|
|
|
fprintf( outfile, " { 0, \"%s\", &__wine_delay_imp_hmod[%d], &delay_imports.IAT[%d], &delay_imports.INT[%d], 0, 0, 0 },\n",
|
2004-02-17 21:36:16 +01:00
|
|
|
dll_imports[i]->spec->file_name, i, j, j );
|
2000-12-26 02:22:34 +01:00
|
|
|
j += dll_imports[i]->nb_imports;
|
|
|
|
}
|
|
|
|
fprintf( outfile, " },\n {\n" );
|
|
|
|
for (i = 0; i < nb_imports; i++)
|
|
|
|
{
|
|
|
|
if (!dll_imports[i]->delay) continue;
|
2004-02-17 21:36:16 +01:00
|
|
|
fprintf( outfile, " /* %s */\n", dll_imports[i]->spec->file_name );
|
2000-12-26 02:22:34 +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;
|
|
|
|
fprintf( outfile, " &__wine_delay_imp_%d_%s,\n", i, name );
|
2000-12-26 02:22:34 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
fprintf( outfile, " },\n {\n" );
|
|
|
|
for (i = 0; i < nb_imports; i++)
|
|
|
|
{
|
|
|
|
if (!dll_imports[i]->delay) continue;
|
2004-02-17 21:36:16 +01:00
|
|
|
fprintf( outfile, " /* %s */\n", dll_imports[i]->spec->file_name );
|
2000-12-26 02:22:34 +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];
|
|
|
|
if (!odp->name)
|
|
|
|
fprintf( outfile, " (char *)%d,\n", odp->ordinal );
|
2002-07-28 19:54:31 +02:00
|
|
|
else
|
2004-02-17 21:36:16 +01:00
|
|
|
fprintf( outfile, " \"%s\",\n", odp->name );
|
2000-12-26 02:22:34 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
fprintf( outfile, " }\n};\n\n" );
|
|
|
|
|
2005-05-07 17:06:30 +02:00
|
|
|
fprintf( outfile, "extern void __stdcall RaiseException(unsigned int, unsigned int, unsigned int, const void *args[]);\n" );
|
2000-12-26 02:22:34 +01:00
|
|
|
fprintf( outfile, "extern void * __stdcall LoadLibraryA(const char*);\n");
|
|
|
|
fprintf( outfile, "extern void * __stdcall GetProcAddress(void *, const char*);\n");
|
|
|
|
fprintf( outfile, "\n" );
|
|
|
|
|
2001-01-02 23:22:12 +01:00
|
|
|
fprintf( outfile, "void *__stdcall __wine_delay_load( int idx_nr )\n" );
|
2000-12-26 02:22:34 +01:00
|
|
|
fprintf( outfile, "{\n" );
|
2001-01-02 23:22:12 +01:00
|
|
|
fprintf( outfile, " int idx = idx_nr >> 16, nr = idx_nr & 0xffff;\n" );
|
|
|
|
fprintf( outfile, " struct ImgDelayDescr *imd = delay_imports.imp + idx;\n" );
|
|
|
|
fprintf( outfile, " void **pIAT = imd->pIAT + nr;\n" );
|
|
|
|
fprintf( outfile, " const char** pINT = imd->pINT + nr;\n" );
|
2000-12-26 02:22:34 +01:00
|
|
|
fprintf( outfile, " void *fn;\n\n" );
|
|
|
|
|
|
|
|
fprintf( outfile, " if (!*imd->phmod) *imd->phmod = LoadLibraryA(imd->szName);\n" );
|
2002-07-28 19:54:31 +02:00
|
|
|
fprintf( outfile, " if (*imd->phmod && (fn = GetProcAddress(*imd->phmod, *pINT)))\n");
|
2000-12-26 02:22:34 +01:00
|
|
|
fprintf( outfile, " /* patch IAT with final value */\n" );
|
|
|
|
fprintf( outfile, " return *pIAT = fn;\n" );
|
|
|
|
fprintf( outfile, " else {\n");
|
2005-05-07 17:06:30 +02:00
|
|
|
fprintf( outfile, " const void *args[2];\n" );
|
|
|
|
fprintf( outfile, " args[0] = imd->szName;\n" );
|
|
|
|
fprintf( outfile, " args[1] = *pINT;\n" );
|
|
|
|
fprintf( outfile, " RaiseException( 0x%08x, %d, 2, args );\n",
|
|
|
|
EXCEPTION_WINE_STUB, EH_NONCONTINUABLE );
|
|
|
|
fprintf( outfile, " return 0;\n" );
|
2005-06-06 17:59:50 +02:00
|
|
|
fprintf( outfile, " }\n}\n" );
|
|
|
|
|
|
|
|
return nb_delayed;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* output the delayed import thunks of a Win32 module */
|
|
|
|
static void output_delayed_import_thunks( FILE *outfile, const DLLSPEC *spec )
|
|
|
|
{
|
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
|
|
|
|
2005-06-06 17:59:50 +02:00
|
|
|
fprintf( outfile, "/* delayed import thunks */\n" );
|
|
|
|
fprintf( outfile, "asm(\".text\\n\"\n" );
|
|
|
|
fprintf( outfile, " \"\\t.align %d\\n\"\n", get_alignment(8) );
|
2005-06-27 20:59:54 +02:00
|
|
|
fprintf( outfile, " \"%s:\\n\"\n", asm_name(delayed_import_loaders));
|
2005-06-27 13:23:24 +02:00
|
|
|
fprintf( outfile, " \"\\t%s\\n\"\n", func_declaration("__wine_delay_load_asm") );
|
2005-06-27 20:59:54 +02:00
|
|
|
fprintf( outfile, " \"%s:\\n\"\n", asm_name("__wine_delay_load_asm") );
|
2005-06-27 13:23:24 +02:00
|
|
|
switch(target_cpu)
|
|
|
|
{
|
|
|
|
case CPU_x86:
|
|
|
|
fprintf( outfile, " \"\\tpushl %%ecx\\n\\tpushl %%edx\\n\\tpushl %%eax\\n\"\n" );
|
2005-06-27 20:59:54 +02:00
|
|
|
fprintf( outfile, " \"\\tcall %s\\n\"\n", asm_name("__wine_delay_load") );
|
2005-06-27 13:23:24 +02:00
|
|
|
fprintf( outfile, " \"\\tpopl %%edx\\n\\tpopl %%ecx\\n\\tjmp *%%eax\\n\"\n" );
|
|
|
|
break;
|
|
|
|
case CPU_SPARC:
|
|
|
|
fprintf( outfile, " \"\\tsave %%sp, -96, %%sp\\n\"\n" );
|
2005-06-27 20:59:54 +02:00
|
|
|
fprintf( outfile, " \"\\tcall %s\\n\"\n", asm_name("__wine_delay_load") );
|
2005-06-27 13:23:24 +02:00
|
|
|
fprintf( outfile, " \"\\tmov %%g1, %%o0\\n\"\n" );
|
|
|
|
fprintf( outfile, " \"\\tjmp %%o0\\n\\trestore\\n\"\n" );
|
|
|
|
break;
|
|
|
|
case CPU_ALPHA:
|
2005-06-27 20:59:54 +02:00
|
|
|
fprintf( outfile, " \"\\tjsr $26,%s\\n\"\n", asm_name("__wine_delay_load") );
|
2005-06-27 13:23:24 +02:00
|
|
|
fprintf( outfile, " \"\\tjmp $31,($0)\\n\"\n" );
|
|
|
|
break;
|
|
|
|
case CPU_POWERPC:
|
|
|
|
if (target_platform == PLATFORM_APPLE) extra_stack_storage = 56;
|
|
|
|
|
|
|
|
/* Save all callee saved registers into a stackframe. */
|
|
|
|
fprintf( outfile, " \"\\tstwu %s, -%d(%s)\\n\"\n",ppc_reg(1), 48+extra_stack_storage, ppc_reg(1));
|
|
|
|
fprintf( outfile, " \"\\tstw %s, %d(%s)\\n\"\n", ppc_reg(3), 4+extra_stack_storage, ppc_reg(1));
|
|
|
|
fprintf( outfile, " \"\\tstw %s, %d(%s)\\n\"\n", ppc_reg(4), 8+extra_stack_storage, ppc_reg(1));
|
|
|
|
fprintf( outfile, " \"\\tstw %s, %d(%s)\\n\"\n", ppc_reg(5), 12+extra_stack_storage, ppc_reg(1));
|
|
|
|
fprintf( outfile, " \"\\tstw %s, %d(%s)\\n\"\n", ppc_reg(6), 16+extra_stack_storage, ppc_reg(1));
|
|
|
|
fprintf( outfile, " \"\\tstw %s, %d(%s)\\n\"\n", ppc_reg(7), 20+extra_stack_storage, ppc_reg(1));
|
|
|
|
fprintf( outfile, " \"\\tstw %s, %d(%s)\\n\"\n", ppc_reg(8), 24+extra_stack_storage, ppc_reg(1));
|
|
|
|
fprintf( outfile, " \"\\tstw %s, %d(%s)\\n\"\n", ppc_reg(9), 28+extra_stack_storage, ppc_reg(1));
|
|
|
|
fprintf( outfile, " \"\\tstw %s, %d(%s)\\n\"\n", ppc_reg(10),32+extra_stack_storage, ppc_reg(1));
|
|
|
|
fprintf( outfile, " \"\\tstw %s, %d(%s)\\n\"\n", ppc_reg(11),36+extra_stack_storage, ppc_reg(1));
|
|
|
|
fprintf( outfile, " \"\\tstw %s, %d(%s)\\n\"\n", ppc_reg(12),40+extra_stack_storage, ppc_reg(1));
|
|
|
|
|
|
|
|
/* r0 -> r3 (arg1) */
|
|
|
|
fprintf( outfile, " \"\\tmr %s, %s\\n\"\n", ppc_reg(3), ppc_reg(0));
|
|
|
|
|
|
|
|
/* save return address */
|
|
|
|
fprintf( outfile, " \"\\tmflr %s\\n\"\n", ppc_reg(0));
|
|
|
|
fprintf( outfile, " \"\\tstw %s, %d(%s)\\n\"\n", ppc_reg(0), 44+extra_stack_storage, ppc_reg(1));
|
|
|
|
|
|
|
|
/* Call the __wine_delay_load function, arg1 is arg1. */
|
2005-06-27 20:59:54 +02:00
|
|
|
fprintf( outfile, " \"\\tbl %s\\n\"\n", asm_name("__wine_delay_load") );
|
2005-06-27 13:23:24 +02:00
|
|
|
|
|
|
|
/* Load return value from call into ctr register */
|
|
|
|
fprintf( outfile, " \"\\tmtctr %s\\n\"\n", ppc_reg(3));
|
|
|
|
|
|
|
|
/* restore all saved registers and drop stackframe. */
|
|
|
|
fprintf( outfile, " \"\\tlwz %s, %d(%s)\\n\"\n", ppc_reg(3), 4+extra_stack_storage, ppc_reg(1));
|
|
|
|
fprintf( outfile, " \"\\tlwz %s, %d(%s)\\n\"\n", ppc_reg(4), 8+extra_stack_storage, ppc_reg(1));
|
|
|
|
fprintf( outfile, " \"\\tlwz %s, %d(%s)\\n\"\n", ppc_reg(5), 12+extra_stack_storage, ppc_reg(1));
|
|
|
|
fprintf( outfile, " \"\\tlwz %s, %d(%s)\\n\"\n", ppc_reg(6), 16+extra_stack_storage, ppc_reg(1));
|
|
|
|
fprintf( outfile, " \"\\tlwz %s, %d(%s)\\n\"\n", ppc_reg(7), 20+extra_stack_storage, ppc_reg(1));
|
|
|
|
fprintf( outfile, " \"\\tlwz %s, %d(%s)\\n\"\n", ppc_reg(8), 24+extra_stack_storage, ppc_reg(1));
|
|
|
|
fprintf( outfile, " \"\\tlwz %s, %d(%s)\\n\"\n", ppc_reg(9), 28+extra_stack_storage, ppc_reg(1));
|
|
|
|
fprintf( outfile, " \"\\tlwz %s, %d(%s)\\n\"\n", ppc_reg(10),32+extra_stack_storage, ppc_reg(1));
|
|
|
|
fprintf( outfile, " \"\\tlwz %s, %d(%s)\\n\"\n", ppc_reg(11),36+extra_stack_storage, ppc_reg(1));
|
|
|
|
fprintf( outfile, " \"\\tlwz %s, %d(%s)\\n\"\n", ppc_reg(12),40+extra_stack_storage, ppc_reg(1));
|
|
|
|
|
|
|
|
/* Load return value from call into return register */
|
|
|
|
fprintf( outfile, " \"\\tlwz %s, %d(%s)\\n\"\n", ppc_reg(0), 44+extra_stack_storage, ppc_reg(1));
|
|
|
|
fprintf( outfile, " \"\\tmtlr %s\\n\"\n", ppc_reg(0));
|
|
|
|
fprintf( outfile, " \"\\taddi %s, %s, %d\\n\"\n", ppc_reg(1), ppc_reg(1), 48+extra_stack_storage);
|
|
|
|
|
|
|
|
/* branch to ctr register. */
|
|
|
|
fprintf( outfile, " \"bctr\\n\"\n");
|
|
|
|
break;
|
|
|
|
}
|
2004-06-18 21:36:26 +02:00
|
|
|
output_function_size( outfile, "__wine_delay_load_asm" );
|
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++)
|
|
|
|
{
|
|
|
|
char buffer[128];
|
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;
|
|
|
|
|
|
|
|
sprintf( buffer, "__wine_delay_imp_%d_%s", i, name );
|
2005-06-27 13:23:24 +02:00
|
|
|
fprintf( outfile, " \"\\t%s\\n\"\n", func_declaration(buffer) );
|
2005-06-27 20:59:54 +02:00
|
|
|
fprintf( outfile, " \"%s:\\n\"\n", asm_name(buffer) );
|
2005-06-27 13:23:24 +02:00
|
|
|
switch(target_cpu)
|
|
|
|
{
|
|
|
|
case CPU_x86:
|
|
|
|
fprintf( outfile, " \"\\tmovl $%d, %%eax\\n\"\n", (idx << 16) | j );
|
2005-06-27 20:59:54 +02:00
|
|
|
fprintf( outfile, " \"\\tjmp %s\\n\"\n", asm_name("__wine_delay_load_asm") );
|
2005-06-27 13:23:24 +02:00
|
|
|
break;
|
|
|
|
case CPU_SPARC:
|
|
|
|
fprintf( outfile, " \"\\tset %d, %%g1\\n\"\n", (idx << 16) | j );
|
2005-06-27 20:59:54 +02:00
|
|
|
fprintf( outfile, " \"\\tb,a %s\\n\"\n", asm_name("__wine_delay_load_asm") );
|
2005-06-27 13:23:24 +02:00
|
|
|
break;
|
|
|
|
case CPU_ALPHA:
|
|
|
|
fprintf( outfile, " \"\\tlda $0,%d($31)\\n\"\n", j);
|
|
|
|
fprintf( outfile, " \"\\tldah $0,%d($0)\\n\"\n", idx);
|
2005-06-27 20:59:54 +02:00
|
|
|
fprintf( outfile, " \"\\tjmp $31,%s\\n\"\n", asm_name("__wine_delay_load_asm") );
|
2005-06-27 13:23:24 +02:00
|
|
|
break;
|
|
|
|
case CPU_POWERPC:
|
|
|
|
switch(target_platform)
|
|
|
|
{
|
|
|
|
case PLATFORM_APPLE:
|
|
|
|
/* On Darwin we can use r0 and r2 */
|
|
|
|
/* Upper part in r2 */
|
|
|
|
fprintf( outfile, " \"\\tlis %s, %d\\n\"\n", ppc_reg(2), idx);
|
|
|
|
/* Lower part + r2 -> r0, Note we can't use r0 directly */
|
|
|
|
fprintf( outfile, " \"\\taddi %s, %s, %d\\n\"\n", ppc_reg(0), ppc_reg(2), j);
|
2005-06-27 20:59:54 +02:00
|
|
|
fprintf( outfile, " \"\\tb %s\\n\"\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 */
|
|
|
|
fprintf( outfile, " \"\\taddi %s, %s, -0x4\\n\"\n", ppc_reg(1), ppc_reg(1));
|
|
|
|
fprintf( outfile, " \"\\tstw %s, 0(%s)\\n\"\n", ppc_reg(13), ppc_reg(1));
|
|
|
|
/* Upper part in r13 */
|
|
|
|
fprintf( outfile, " \"\\tlis %s, %d\\n\"\n", ppc_reg(13), idx);
|
|
|
|
/* Lower part + r13 -> r0, Note we can't use r0 directly */
|
|
|
|
fprintf( outfile, " \"\\taddi %s, %s, %d\\n\"\n", ppc_reg(0), ppc_reg(13), j);
|
|
|
|
/* Restore r13 */
|
|
|
|
fprintf( outfile, " \"\\tstw %s, 0(%s)\\n\"\n", ppc_reg(13), ppc_reg(1));
|
|
|
|
fprintf( outfile, " \"\\taddic %s, %s, 0x4\\n\"\n", ppc_reg(1), ppc_reg(1));
|
2005-06-27 20:59:54 +02:00
|
|
|
fprintf( outfile, " \"\\tb %s\\n\"\n", asm_name("__wine_delay_load_asm") );
|
2005-06-27 13:23:24 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2004-06-18 21:36:26 +02:00
|
|
|
output_function_size( outfile, name );
|
2001-01-02 23:22:12 +01:00
|
|
|
}
|
|
|
|
idx++;
|
|
|
|
}
|
2004-06-18 21:36:26 +02:00
|
|
|
output_function_size( outfile, delayed_import_loaders );
|
2000-12-26 02:22:34 +01:00
|
|
|
|
2005-02-09 15:06:32 +01:00
|
|
|
fprintf( outfile, "\n \".align %d\\n\"\n", get_alignment(8) );
|
2005-06-27 20:59:54 +02:00
|
|
|
fprintf( outfile, " \"%s:\\n\"\n", asm_name(delayed_import_thunks));
|
2001-01-02 23:22:12 +01:00
|
|
|
pos = nb_delayed * 32;
|
|
|
|
for (i = 0; i < nb_imports; i++)
|
|
|
|
{
|
|
|
|
if (!dll_imports[i]->delay) continue;
|
2000-12-26 02:22:34 +01:00
|
|
|
for (j = 0; j < dll_imports[i]->nb_imports; j++, pos += 4)
|
|
|
|
{
|
2004-02-17 21:36:16 +01:00
|
|
|
ORDDEF *odp = dll_imports[i]->imports[j];
|
2005-06-16 22:51:50 +02:00
|
|
|
output_import_thunk( outfile, odp->name ? odp->name : odp->export_name,
|
|
|
|
"delay_imports", pos );
|
2000-12-26 02:22:34 +01:00
|
|
|
}
|
|
|
|
}
|
2004-06-18 21:36:26 +02:00
|
|
|
output_function_size( outfile, delayed_import_thunks );
|
2005-02-09 15:06:32 +01:00
|
|
|
fprintf( outfile, ");\n" );
|
2000-12-26 02:22:34 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* output the import and delayed import tables of a Win32 module
|
|
|
|
* returns number of DLLs exported in 'immediate' mode
|
|
|
|
*/
|
2005-05-24 12:13:30 +02:00
|
|
|
int output_imports( FILE *outfile, DLLSPEC *spec, int *nb_delayed )
|
2000-12-26 02:22:34 +01:00
|
|
|
{
|
2005-05-24 12:13:30 +02:00
|
|
|
*nb_delayed = output_delayed_imports( outfile, spec );
|
|
|
|
return output_immediate_imports( outfile );
|
2000-09-28 01:40:43 +02:00
|
|
|
}
|
2005-06-06 17:59:50 +02:00
|
|
|
|
|
|
|
/* output the import and delayed import thunks of a Win32 module */
|
|
|
|
void output_import_thunks( FILE *outfile, DLLSPEC *spec )
|
|
|
|
{
|
|
|
|
output_delayed_import_thunks( outfile, spec );
|
|
|
|
output_immediate_import_thunks( outfile );
|
|
|
|
}
|