2000-06-23 22:15:35 +02:00
|
|
|
/*
|
|
|
|
* 32-bit spec files
|
|
|
|
*
|
|
|
|
* Copyright 1993 Robert J. Amstadt
|
|
|
|
* Copyright 1995 Martin von Loewis
|
|
|
|
* Copyright 1995, 1996, 1997 Alexandre Julliard
|
|
|
|
* Copyright 1997 Eric Youngdale
|
|
|
|
* Copyright 1999 Ulrich Weigand
|
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-06-23 22:15:35 +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
|
|
|
|
2000-06-23 22:15:35 +02:00
|
|
|
#include <assert.h>
|
2000-11-09 21:31:18 +01:00
|
|
|
#include <ctype.h>
|
2003-09-06 01:08:26 +02:00
|
|
|
#include <stdarg.h>
|
2001-03-21 21:30:46 +01:00
|
|
|
#include <string.h>
|
2000-06-23 22:15:35 +02:00
|
|
|
|
|
|
|
#include "build.h"
|
|
|
|
|
2009-04-09 20:58:43 +02:00
|
|
|
#define IMAGE_FILE_MACHINE_UNKNOWN 0
|
|
|
|
#define IMAGE_FILE_MACHINE_I386 0x014c
|
|
|
|
#define IMAGE_FILE_MACHINE_POWERPC 0x01f0
|
|
|
|
#define IMAGE_FILE_MACHINE_AMD64 0x8664
|
2012-08-16 22:40:14 +02:00
|
|
|
#define IMAGE_FILE_MACHINE_ARMNT 0x01C4
|
2013-09-25 20:51:10 +02:00
|
|
|
#define IMAGE_FILE_MACHINE_ARM64 0xaa64
|
2009-04-09 20:58:43 +02:00
|
|
|
|
|
|
|
#define IMAGE_SIZEOF_NT_OPTIONAL32_HEADER 224
|
|
|
|
#define IMAGE_SIZEOF_NT_OPTIONAL64_HEADER 240
|
|
|
|
|
|
|
|
#define IMAGE_NT_OPTIONAL_HDR32_MAGIC 0x10b
|
|
|
|
#define IMAGE_NT_OPTIONAL_HDR64_MAGIC 0x20b
|
|
|
|
#define IMAGE_ROM_OPTIONAL_HDR_MAGIC 0x107
|
2000-06-23 22:15:35 +02:00
|
|
|
|
2016-03-22 09:59:30 +01:00
|
|
|
int needs_get_pc_thunk = 0;
|
|
|
|
|
2019-12-18 21:05:27 +01:00
|
|
|
static const char builtin_signature[32] = "Wine builtin DLL";
|
|
|
|
static const char fakedll_signature[32] = "Wine placeholder DLL";
|
|
|
|
|
2005-12-18 10:45:01 +01:00
|
|
|
/* check if entry point needs a relay thunk */
|
|
|
|
static inline int needs_relay( const ORDDEF *odp )
|
|
|
|
{
|
|
|
|
/* skip nonexistent entry points */
|
|
|
|
if (!odp) return 0;
|
|
|
|
/* skip non-functions */
|
2011-05-03 13:09:09 +02:00
|
|
|
switch (odp->type)
|
|
|
|
{
|
|
|
|
case TYPE_STDCALL:
|
|
|
|
case TYPE_CDECL:
|
|
|
|
break;
|
|
|
|
case TYPE_STUB:
|
|
|
|
if (odp->u.func.nb_args != -1) break;
|
|
|
|
/* fall through */
|
|
|
|
default:
|
|
|
|
return 0;
|
|
|
|
}
|
2005-12-18 10:45:01 +01:00
|
|
|
/* skip norelay and forward entry points */
|
|
|
|
if (odp->flags & (FLAG_NORELAY|FLAG_FORWARD)) return 0;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2011-05-03 12:49:15 +02:00
|
|
|
static int is_float_arg( const ORDDEF *odp, int arg )
|
2010-08-30 12:41:06 +02:00
|
|
|
{
|
|
|
|
if (arg >= odp->u.func.nb_args) return 0;
|
|
|
|
return (odp->u.func.args[arg] == ARG_FLOAT || odp->u.func.args[arg] == ARG_DOUBLE);
|
|
|
|
}
|
|
|
|
|
2005-12-18 10:45:01 +01:00
|
|
|
/* check if dll will output relay thunks */
|
2016-03-22 09:59:30 +01:00
|
|
|
static int has_relays( DLLSPEC *spec )
|
2005-12-18 10:45:01 +01:00
|
|
|
{
|
2007-03-03 14:30:03 +01:00
|
|
|
int i;
|
2005-12-18 10:45:01 +01:00
|
|
|
|
2017-06-12 20:30:43 +02:00
|
|
|
if (target_cpu != CPU_x86 && target_cpu != CPU_x86_64 &&
|
|
|
|
target_cpu != CPU_ARM && target_cpu != CPU_ARM64)
|
|
|
|
return 0;
|
2005-12-18 10:45:01 +01:00
|
|
|
|
|
|
|
for (i = spec->base; i <= spec->limit; i++)
|
|
|
|
{
|
|
|
|
ORDDEF *odp = spec->ordinals[i];
|
|
|
|
if (needs_relay( odp )) return 1;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-07-06 15:50:00 +02:00
|
|
|
static int get_exports_count( DLLSPEC *spec )
|
|
|
|
{
|
|
|
|
if (unix_lib) return 0;
|
|
|
|
if (spec->base > spec->limit) return 0;
|
|
|
|
return spec->limit - spec->base + 1;
|
|
|
|
}
|
|
|
|
|
2017-12-07 11:14:02 +01:00
|
|
|
static int cmp_func_args( const void *p1, const void *p2 )
|
|
|
|
{
|
|
|
|
const ORDDEF *odp1 = *(const ORDDEF **)p1;
|
|
|
|
const ORDDEF *odp2 = *(const ORDDEF **)p2;
|
|
|
|
|
|
|
|
return odp2->u.func.nb_args - odp1->u.func.nb_args;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void get_arg_string( ORDDEF *odp, char str[MAX_ARGUMENTS + 1] )
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < odp->u.func.nb_args; i++)
|
|
|
|
{
|
|
|
|
switch (odp->u.func.args[i])
|
|
|
|
{
|
|
|
|
case ARG_STR: str[i] = 's'; break;
|
|
|
|
case ARG_WSTR: str[i] = 'w'; break;
|
|
|
|
case ARG_FLOAT: str[i] = 'f'; break;
|
|
|
|
case ARG_DOUBLE: str[i] = 'd'; break;
|
|
|
|
case ARG_INT64:
|
|
|
|
case ARG_INT128:
|
|
|
|
if (get_ptr_size() == 4)
|
|
|
|
{
|
|
|
|
str[i] = (odp->u.func.args[i] == ARG_INT64) ? 'j' : 'k';
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
/* fall through */
|
|
|
|
case ARG_LONG:
|
|
|
|
case ARG_PTR:
|
|
|
|
default:
|
|
|
|
str[i] = 'i';
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2019-02-27 17:11:08 +01:00
|
|
|
if (odp->flags & (FLAG_THISCALL | FLAG_FASTCALL)) str[0] = 't';
|
|
|
|
if ((odp->flags & FLAG_FASTCALL) && odp->u.func.nb_args > 1) str[1] = 't';
|
2017-12-07 11:14:02 +01:00
|
|
|
|
|
|
|
/* append return value */
|
|
|
|
if (get_ptr_size() == 4 && (odp->flags & FLAG_RET64))
|
|
|
|
strcpy( str + i, "J" );
|
|
|
|
else
|
|
|
|
strcpy( str + i, "I" );
|
|
|
|
}
|
|
|
|
|
2019-03-06 10:37:12 +01:00
|
|
|
static void output_data_directories( const char *names[16] )
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < 16; i++)
|
|
|
|
{
|
|
|
|
if (names[i])
|
|
|
|
{
|
|
|
|
output_rva( "%s", names[i] );
|
|
|
|
output( "\t.long %s_end - %s\n", names[i], names[i] );
|
|
|
|
}
|
|
|
|
else output( "\t.long 0,0\n" );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-12-07 11:14:02 +01:00
|
|
|
/*******************************************************************
|
|
|
|
* build_args_string
|
|
|
|
*/
|
|
|
|
static char *build_args_string( DLLSPEC *spec )
|
|
|
|
{
|
|
|
|
int i, count = 0, len = 1;
|
|
|
|
char *p, *buffer;
|
|
|
|
char str[MAX_ARGUMENTS + 2];
|
|
|
|
ORDDEF **funcs;
|
|
|
|
|
|
|
|
funcs = xmalloc( (spec->limit + 1 - spec->base) * sizeof(*funcs) );
|
|
|
|
for (i = spec->base; i <= spec->limit; i++)
|
|
|
|
{
|
|
|
|
ORDDEF *odp = spec->ordinals[i];
|
|
|
|
|
|
|
|
if (!needs_relay( odp )) continue;
|
|
|
|
funcs[count++] = odp;
|
|
|
|
len += odp->u.func.nb_args + 1;
|
|
|
|
}
|
|
|
|
/* sort functions by decreasing number of arguments */
|
|
|
|
qsort( funcs, count, sizeof(*funcs), cmp_func_args );
|
|
|
|
buffer = xmalloc( len );
|
|
|
|
buffer[0] = 0;
|
|
|
|
/* build the arguments string, reusing substrings where possible */
|
|
|
|
for (i = 0; i < count; i++)
|
|
|
|
{
|
|
|
|
get_arg_string( funcs[i], str );
|
|
|
|
if (!(p = strstr( buffer, str )))
|
|
|
|
{
|
|
|
|
p = buffer + strlen( buffer );
|
|
|
|
strcpy( p, str );
|
|
|
|
}
|
|
|
|
funcs[i]->u.func.args_str_offset = p - buffer;
|
|
|
|
}
|
|
|
|
free( funcs );
|
|
|
|
return buffer;
|
|
|
|
}
|
|
|
|
|
2005-12-18 10:45:01 +01:00
|
|
|
/*******************************************************************
|
|
|
|
* output_relay_debug
|
|
|
|
*
|
|
|
|
* Output entry points for relay debugging
|
|
|
|
*/
|
2006-08-11 20:41:29 +02:00
|
|
|
static void output_relay_debug( DLLSPEC *spec )
|
2005-12-18 10:45:01 +01:00
|
|
|
{
|
2017-12-07 11:14:02 +01:00
|
|
|
int i;
|
2005-12-18 10:45:01 +01:00
|
|
|
|
|
|
|
/* first the table of entry point offsets */
|
|
|
|
|
2006-08-11 20:41:29 +02:00
|
|
|
output( "\t%s\n", get_asm_rodata_section() );
|
|
|
|
output( "\t.align %d\n", get_alignment(4) );
|
|
|
|
output( ".L__wine_spec_relay_entry_point_offsets:\n" );
|
2005-12-18 10:45:01 +01:00
|
|
|
|
|
|
|
for (i = spec->base; i <= spec->limit; i++)
|
|
|
|
{
|
|
|
|
ORDDEF *odp = spec->ordinals[i];
|
|
|
|
|
|
|
|
if (needs_relay( odp ))
|
2006-08-11 20:41:29 +02:00
|
|
|
output( "\t.long .L__wine_spec_relay_entry_point_%d-__wine_spec_relay_entry_points\n", i );
|
2005-12-18 10:45:01 +01:00
|
|
|
else
|
2006-08-11 20:41:29 +02:00
|
|
|
output( "\t.long 0\n" );
|
2005-12-18 10:45:01 +01:00
|
|
|
}
|
|
|
|
|
2017-12-07 11:14:02 +01:00
|
|
|
/* then the strings of argument types */
|
2005-12-18 10:45:01 +01:00
|
|
|
|
2017-12-07 11:14:02 +01:00
|
|
|
output( ".L__wine_spec_relay_args_string:\n" );
|
|
|
|
output( "\t%s \"%s\"\n", get_asm_string_keyword(), build_args_string( spec ));
|
2005-12-18 10:45:01 +01:00
|
|
|
|
|
|
|
/* then the relay thunks */
|
|
|
|
|
2006-08-11 20:41:29 +02:00
|
|
|
output( "\t.text\n" );
|
|
|
|
output( "__wine_spec_relay_entry_points:\n" );
|
|
|
|
output( "\tnop\n" ); /* to avoid 0 offset */
|
2005-12-18 10:45:01 +01:00
|
|
|
|
|
|
|
for (i = spec->base; i <= spec->limit; i++)
|
|
|
|
{
|
|
|
|
ORDDEF *odp = spec->ordinals[i];
|
|
|
|
|
|
|
|
if (!needs_relay( odp )) continue;
|
|
|
|
|
2008-12-27 19:59:55 +01:00
|
|
|
switch (target_cpu)
|
2005-12-18 10:45:01 +01:00
|
|
|
{
|
2008-12-27 19:59:55 +01:00
|
|
|
case CPU_x86:
|
2019-03-01 12:39:39 +01:00
|
|
|
output( "\t.align %d\n", get_alignment(4) );
|
|
|
|
output( "\t.long 0x90909090,0x90909090\n" );
|
|
|
|
output( ".L__wine_spec_relay_entry_point_%d:\n", i );
|
|
|
|
output_cfi( ".cfi_startproc" );
|
|
|
|
output( "\t.byte 0x8b,0xff,0x55,0x8b,0xec,0x5d\n" ); /* hotpatch prolog */
|
2019-02-27 17:11:08 +01:00
|
|
|
if (odp->flags & (FLAG_THISCALL | FLAG_FASTCALL)) /* add the register arguments */
|
2010-08-24 19:44:01 +02:00
|
|
|
{
|
|
|
|
output( "\tpopl %%eax\n" );
|
2019-02-27 17:11:08 +01:00
|
|
|
if ((odp->flags & FLAG_FASTCALL) && get_args_size( odp ) > 4) output( "\tpushl %%edx\n" );
|
2010-08-24 19:44:01 +02:00
|
|
|
output( "\tpushl %%ecx\n" );
|
|
|
|
output( "\tpushl %%eax\n" );
|
|
|
|
}
|
2017-12-07 11:14:02 +01:00
|
|
|
output( "\tpushl $%u\n", (odp->u.func.args_str_offset << 16) | (i - spec->base) );
|
2011-07-06 21:53:37 +02:00
|
|
|
output_cfi( ".cfi_adjust_cfa_offset 4" );
|
2008-12-27 19:59:55 +01:00
|
|
|
|
|
|
|
if (UsePIC)
|
|
|
|
{
|
|
|
|
output( "\tcall %s\n", asm_name("__wine_spec_get_pc_thunk_eax") );
|
|
|
|
output( "1:\tleal .L__wine_spec_relay_descr-1b(%%eax),%%eax\n" );
|
2016-03-22 09:59:30 +01:00
|
|
|
needs_get_pc_thunk = 1;
|
2008-12-27 19:59:55 +01:00
|
|
|
}
|
|
|
|
else output( "\tmovl $.L__wine_spec_relay_descr,%%eax\n" );
|
|
|
|
output( "\tpushl %%eax\n" );
|
2011-07-06 21:53:37 +02:00
|
|
|
output_cfi( ".cfi_adjust_cfa_offset 4" );
|
2008-12-27 19:59:55 +01:00
|
|
|
|
2017-07-26 10:42:48 +02:00
|
|
|
output( "\tcall *4(%%eax)\n" );
|
2017-12-07 11:14:02 +01:00
|
|
|
output_cfi( ".cfi_adjust_cfa_offset -8" );
|
2019-02-27 17:09:51 +01:00
|
|
|
if (odp->type == TYPE_STDCALL)
|
2017-12-07 11:14:02 +01:00
|
|
|
output( "\tret $%u\n", get_args_size( odp ));
|
2005-12-18 10:45:01 +01:00
|
|
|
else
|
2017-07-26 10:42:48 +02:00
|
|
|
output( "\tret\n" );
|
2019-03-01 12:39:39 +01:00
|
|
|
output_cfi( ".cfi_endproc" );
|
2008-12-27 19:59:55 +01:00
|
|
|
break;
|
|
|
|
|
2012-07-15 16:41:56 +02:00
|
|
|
case CPU_ARM:
|
2014-02-11 20:46:25 +01:00
|
|
|
{
|
|
|
|
unsigned int mask, val, count = 0;
|
2017-12-14 11:44:57 +01:00
|
|
|
int j, has_float = 0;
|
|
|
|
|
|
|
|
if (strcmp( float_abi_option, "soft" ))
|
|
|
|
for (j = 0; j < odp->u.func.nb_args && !has_float; j++)
|
|
|
|
has_float = is_float_arg( odp, j );
|
2014-02-11 20:46:25 +01:00
|
|
|
|
2017-12-07 11:14:02 +01:00
|
|
|
val = (odp->u.func.args_str_offset << 16) | (i - spec->base);
|
2019-03-01 12:39:39 +01:00
|
|
|
output( "\t.align %d\n", get_alignment(4) );
|
|
|
|
output( ".L__wine_spec_relay_entry_point_%d:\n", i );
|
|
|
|
output_cfi( ".cfi_startproc" );
|
2017-12-14 11:44:57 +01:00
|
|
|
output( "\tpush {r0-r3}\n" );
|
2012-07-15 16:41:56 +02:00
|
|
|
output( "\tmov r2, SP\n");
|
2017-12-14 11:44:57 +01:00
|
|
|
if (has_float) output( "\tvpush {s0-s15}\n" );
|
2017-12-07 11:14:02 +01:00
|
|
|
output( "\tpush {LR}\n" );
|
2014-02-11 20:46:25 +01:00
|
|
|
output( "\tsub SP, #4\n");
|
|
|
|
for (mask = 0xff; mask; mask <<= 8)
|
|
|
|
if (val & mask) output( "\t%s r1,#%u\n", count++ ? "add" : "mov", val & mask );
|
|
|
|
if (!count) output( "\tmov r1,#0\n" );
|
|
|
|
output( "\tldr r0, 2f\n");
|
|
|
|
output( "\tadd r0, PC\n");
|
|
|
|
output( "\tldr IP, [r0, #4]\n");
|
|
|
|
output( "1:\tblx IP\n");
|
|
|
|
output( "\tldr IP, [SP, #4]\n" );
|
2017-12-14 11:44:57 +01:00
|
|
|
output( "\tadd SP, #%u\n", 24 + (has_float ? 64 : 0) );
|
2014-02-11 20:46:25 +01:00
|
|
|
output( "\tbx IP\n");
|
|
|
|
output( "2:\t.long .L__wine_spec_relay_descr-1b\n" );
|
2019-03-01 12:39:39 +01:00
|
|
|
output_cfi( ".cfi_endproc" );
|
2012-07-15 16:41:56 +02:00
|
|
|
break;
|
2014-02-11 20:46:25 +01:00
|
|
|
}
|
2012-07-15 16:41:56 +02:00
|
|
|
|
2017-06-12 20:30:43 +02:00
|
|
|
case CPU_ARM64:
|
2019-03-01 12:39:39 +01:00
|
|
|
output( "\t.align %d\n", get_alignment(4) );
|
|
|
|
output( ".L__wine_spec_relay_entry_point_%d:\n", i );
|
|
|
|
output_cfi( ".cfi_startproc" );
|
2017-12-07 11:14:02 +01:00
|
|
|
switch (odp->u.func.nb_args)
|
2017-06-12 20:30:43 +02:00
|
|
|
{
|
|
|
|
default:
|
|
|
|
case 8:
|
|
|
|
case 7: output( "\tstp x6, x7, [SP,#-16]!\n" );
|
|
|
|
/* fall through */
|
|
|
|
case 6:
|
|
|
|
case 5: output( "\tstp x4, x5, [SP,#-16]!\n" );
|
|
|
|
/* fall through */
|
|
|
|
case 4:
|
|
|
|
case 3: output( "\tstp x2, x3, [SP,#-16]!\n" );
|
|
|
|
/* fall through */
|
|
|
|
case 2:
|
|
|
|
case 1: output( "\tstp x0, x1, [SP,#-16]!\n" );
|
|
|
|
/* fall through */
|
|
|
|
case 0: break;
|
|
|
|
}
|
2017-12-07 11:14:02 +01:00
|
|
|
output( "\tmov x2, SP\n");
|
2017-06-12 20:30:43 +02:00
|
|
|
output( "\tstp x29, x30, [SP,#-16]!\n" );
|
|
|
|
output( "\tstp x8, x9, [SP,#-16]!\n" );
|
2017-12-07 11:14:02 +01:00
|
|
|
output( "\tmov w1, #%u\n", odp->u.func.args_str_offset << 16 );
|
2017-06-12 20:30:43 +02:00
|
|
|
if (i - spec->base) output( "\tadd w1, w1, #%u\n", i - spec->base );
|
2020-08-14 13:54:14 +02:00
|
|
|
output( "\tadrp x0, %s\n", arm64_page(".L__wine_spec_relay_descr") );
|
|
|
|
output( "\tadd x0, x0, #%s\n", arm64_pageoff(".L__wine_spec_relay_descr") );
|
2017-06-12 20:30:43 +02:00
|
|
|
output( "\tldr x3, [x0, #8]\n");
|
|
|
|
output( "\tblr x3\n");
|
|
|
|
output( "\tadd SP, SP, #16\n" );
|
|
|
|
output( "\tldp x29, x30, [SP], #16\n" );
|
2017-12-07 11:14:02 +01:00
|
|
|
if (odp->u.func.nb_args)
|
|
|
|
output( "\tadd SP, SP, #%u\n", 8 * ((min(odp->u.func.nb_args, 8) + 1) & ~1) );
|
2017-06-12 20:30:43 +02:00
|
|
|
output( "\tret\n");
|
2019-03-01 12:39:39 +01:00
|
|
|
output_cfi( ".cfi_endproc" );
|
2017-06-12 20:30:43 +02:00
|
|
|
break;
|
|
|
|
|
2008-12-27 19:59:55 +01:00
|
|
|
case CPU_x86_64:
|
2019-03-01 12:39:39 +01:00
|
|
|
output( "\t.align %d\n", get_alignment(4) );
|
|
|
|
output( "\t.long 0x90909090,0x90909090\n" );
|
|
|
|
output( ".L__wine_spec_relay_entry_point_%d:\n", i );
|
|
|
|
output_cfi( ".cfi_startproc" );
|
2017-12-07 11:14:02 +01:00
|
|
|
switch (odp->u.func.nb_args)
|
2010-08-30 12:41:06 +02:00
|
|
|
{
|
2017-12-07 11:14:02 +01:00
|
|
|
default: output( "\tmovq %%%s,32(%%rsp)\n", is_float_arg( odp, 3 ) ? "xmm3" : "r9" );
|
2011-03-29 15:33:04 +02:00
|
|
|
/* fall through */
|
2017-12-07 11:14:02 +01:00
|
|
|
case 3: output( "\tmovq %%%s,24(%%rsp)\n", is_float_arg( odp, 2 ) ? "xmm2" : "r8" );
|
2011-03-29 15:33:04 +02:00
|
|
|
/* fall through */
|
2017-12-07 11:14:02 +01:00
|
|
|
case 2: output( "\tmovq %%%s,16(%%rsp)\n", is_float_arg( odp, 1 ) ? "xmm1" : "rdx" );
|
2011-03-29 15:33:04 +02:00
|
|
|
/* fall through */
|
2017-12-07 11:14:02 +01:00
|
|
|
case 1: output( "\tmovq %%%s,8(%%rsp)\n", is_float_arg( odp, 0 ) ? "xmm0" : "rcx" );
|
2011-03-29 15:33:04 +02:00
|
|
|
/* fall through */
|
2010-08-30 12:41:06 +02:00
|
|
|
case 0: break;
|
|
|
|
}
|
2017-12-07 11:14:02 +01:00
|
|
|
output( "\tmovl $%u,%%edx\n", (odp->u.func.args_str_offset << 16) | (i - spec->base) );
|
2008-12-27 19:59:55 +01:00
|
|
|
output( "\tleaq .L__wine_spec_relay_descr(%%rip),%%rcx\n" );
|
2011-01-27 14:08:57 +01:00
|
|
|
output( "\tcallq *8(%%rcx)\n" );
|
2008-12-27 19:59:55 +01:00
|
|
|
output( "\tret\n" );
|
2019-03-01 12:39:39 +01:00
|
|
|
output_cfi( ".cfi_endproc" );
|
2008-12-27 19:59:55 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
assert(0);
|
2005-12-18 10:45:01 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-06-23 22:15:35 +02:00
|
|
|
/*******************************************************************
|
|
|
|
* output_exports
|
|
|
|
*
|
|
|
|
* Output the export table for a Win32 module.
|
|
|
|
*/
|
2009-02-24 18:02:15 +01:00
|
|
|
void output_exports( DLLSPEC *spec )
|
2000-06-23 22:15:35 +02:00
|
|
|
{
|
2005-06-06 17:59:50 +02:00
|
|
|
int i, fwd_size = 0;
|
2019-06-21 12:08:44 +02:00
|
|
|
int needs_imports = 0;
|
2019-05-16 21:33:47 +02:00
|
|
|
int needs_relay = has_relays( spec );
|
2020-07-06 15:50:00 +02:00
|
|
|
int nr_exports = get_exports_count( spec );
|
2019-03-19 10:02:02 +01:00
|
|
|
const char *func_ptr = (target_platform == PLATFORM_WINDOWS) ? ".rva" : get_asm_ptr_keyword();
|
2019-06-21 12:08:44 +02:00
|
|
|
const char *name;
|
2000-06-23 22:15:35 +02:00
|
|
|
|
2005-06-06 17:59:50 +02:00
|
|
|
if (!nr_exports) return;
|
2000-12-11 04:42:20 +01:00
|
|
|
|
2006-08-11 20:41:29 +02:00
|
|
|
output( "\n/* export table */\n\n" );
|
2019-03-13 10:51:24 +01:00
|
|
|
output( "\t%s\n", get_asm_export_section() );
|
2006-08-11 20:41:29 +02:00
|
|
|
output( "\t.align %d\n", get_alignment(4) );
|
|
|
|
output( ".L__wine_spec_exports:\n" );
|
2000-12-11 04:42:20 +01:00
|
|
|
|
|
|
|
/* export directory header */
|
2000-06-23 22:15:35 +02:00
|
|
|
|
2006-08-11 20:41:29 +02:00
|
|
|
output( "\t.long 0\n" ); /* Characteristics */
|
|
|
|
output( "\t.long 0\n" ); /* TimeDateStamp */
|
|
|
|
output( "\t.long 0\n" ); /* MajorVersion/MinorVersion */
|
2019-03-06 10:13:45 +01:00
|
|
|
output_rva( ".L__wine_spec_exp_names" ); /* Name */
|
2006-08-11 20:41:29 +02:00
|
|
|
output( "\t.long %u\n", spec->base ); /* Base */
|
|
|
|
output( "\t.long %u\n", nr_exports ); /* NumberOfFunctions */
|
|
|
|
output( "\t.long %u\n", spec->nb_names ); /* NumberOfNames */
|
2019-03-06 10:13:45 +01:00
|
|
|
output_rva( ".L__wine_spec_exports_funcs " ); /* AddressOfFunctions */
|
2004-02-11 07:41:01 +01:00
|
|
|
if (spec->nb_names)
|
2000-06-23 22:15:35 +02:00
|
|
|
{
|
2019-03-06 10:13:45 +01:00
|
|
|
output_rva( ".L__wine_spec_exp_name_ptrs" ); /* AddressOfNames */
|
|
|
|
output_rva( ".L__wine_spec_exp_ordinals" ); /* AddressOfNameOrdinals */
|
2000-06-23 22:15:35 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2006-08-11 20:41:29 +02:00
|
|
|
output( "\t.long 0\n" ); /* AddressOfNames */
|
|
|
|
output( "\t.long 0\n" ); /* AddressOfNameOrdinals */
|
2000-06-23 22:15:35 +02:00
|
|
|
}
|
|
|
|
|
2000-12-11 04:42:20 +01:00
|
|
|
/* output the function pointers */
|
2000-06-23 22:15:35 +02:00
|
|
|
|
2006-08-11 20:41:29 +02:00
|
|
|
output( "\n.L__wine_spec_exports_funcs:\n" );
|
2004-02-11 07:41:01 +01:00
|
|
|
for (i = spec->base; i <= spec->limit; i++)
|
2000-06-23 22:15:35 +02:00
|
|
|
{
|
2004-02-11 07:41:01 +01:00
|
|
|
ORDDEF *odp = spec->ordinals[i];
|
2019-03-19 10:02:02 +01:00
|
|
|
if (!odp) output( "\t%s 0\n",
|
|
|
|
(target_platform == PLATFORM_WINDOWS) ? ".long" : get_asm_ptr_keyword() );
|
2000-06-23 22:15:35 +02:00
|
|
|
else switch(odp->type)
|
|
|
|
{
|
|
|
|
case TYPE_EXTERN:
|
|
|
|
case TYPE_STDCALL:
|
|
|
|
case TYPE_VARARGS:
|
|
|
|
case TYPE_CDECL:
|
2005-09-19 19:04:43 +02:00
|
|
|
if (odp->flags & FLAG_FORWARD)
|
2002-12-15 02:22:40 +01:00
|
|
|
{
|
2019-03-19 10:02:02 +01:00
|
|
|
output( "\t%s .L__wine_spec_forwards+%u\n", func_ptr, fwd_size );
|
2005-09-19 19:04:43 +02:00
|
|
|
fwd_size += strlen(odp->link_name) + 1;
|
|
|
|
}
|
2019-06-21 12:08:44 +02:00
|
|
|
else if ((odp->flags & FLAG_IMPORT) && (target_cpu == CPU_x86 || target_cpu == CPU_x86_64))
|
|
|
|
{
|
|
|
|
name = odp->name ? odp->name : odp->export_name;
|
|
|
|
if (name) output( "\t%s %s_%s\n", func_ptr, asm_name("__wine_spec_imp"), name );
|
|
|
|
else output( "\t%s %s_%u\n", func_ptr, asm_name("__wine_spec_imp"), i );
|
|
|
|
needs_imports = 1;
|
|
|
|
}
|
2005-09-19 19:04:43 +02:00
|
|
|
else if (odp->flags & FLAG_EXT_LINK)
|
|
|
|
{
|
2019-03-19 10:02:02 +01:00
|
|
|
output( "\t%s %s_%s\n", func_ptr, asm_name("__wine_spec_ext_link"), odp->link_name );
|
2002-12-15 02:22:40 +01:00
|
|
|
}
|
2003-03-17 05:56:10 +01:00
|
|
|
else
|
|
|
|
{
|
2019-03-19 10:02:02 +01:00
|
|
|
output( "\t%s %s\n", func_ptr, asm_name( get_link_name( odp )));
|
2003-03-17 05:56:10 +01:00
|
|
|
}
|
2000-06-23 22:15:35 +02:00
|
|
|
break;
|
|
|
|
case TYPE_STUB:
|
2019-03-19 10:02:02 +01:00
|
|
|
output( "\t%s %s\n", func_ptr, asm_name( get_stub_name( odp, spec )) );
|
2000-06-23 22:15:35 +02:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
assert(0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-02-11 07:41:01 +01:00
|
|
|
if (spec->nb_names)
|
2000-06-23 22:15:35 +02:00
|
|
|
{
|
2000-12-11 04:42:20 +01:00
|
|
|
/* output the function name pointers */
|
2000-06-23 22:15:35 +02:00
|
|
|
|
2004-02-11 07:41:01 +01:00
|
|
|
int namepos = strlen(spec->file_name) + 1;
|
2000-12-11 04:42:20 +01:00
|
|
|
|
2006-08-11 20:41:29 +02:00
|
|
|
output( "\n.L__wine_spec_exp_name_ptrs:\n" );
|
2004-02-11 07:41:01 +01:00
|
|
|
for (i = 0; i < spec->nb_names; i++)
|
2000-06-23 22:15:35 +02:00
|
|
|
{
|
2019-03-06 10:13:45 +01:00
|
|
|
output_rva( ".L__wine_spec_exp_names + %u", namepos );
|
2004-02-11 07:41:01 +01:00
|
|
|
namepos += strlen(spec->names[i]->name) + 1;
|
2000-06-23 22:15:35 +02:00
|
|
|
}
|
2000-12-11 04:42:20 +01:00
|
|
|
|
2000-06-23 22:15:35 +02:00
|
|
|
/* output the function ordinals */
|
|
|
|
|
2006-08-11 20:41:29 +02:00
|
|
|
output( "\n.L__wine_spec_exp_ordinals:\n" );
|
2004-02-11 07:41:01 +01:00
|
|
|
for (i = 0; i < spec->nb_names; i++)
|
2000-06-23 22:15:35 +02:00
|
|
|
{
|
2013-03-08 21:37:05 +01:00
|
|
|
output( "\t.short %d\n", spec->names[i]->ordinal - spec->base );
|
2000-12-11 04:42:20 +01:00
|
|
|
}
|
2004-02-11 07:41:01 +01:00
|
|
|
if (spec->nb_names % 2)
|
2000-12-11 04:42:20 +01:00
|
|
|
{
|
2013-03-08 21:37:05 +01:00
|
|
|
output( "\t.short 0\n" );
|
2000-06-23 22:15:35 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-16 21:33:47 +02:00
|
|
|
if (needs_relay)
|
|
|
|
{
|
|
|
|
output( "\t.long 0xdeb90002\n" ); /* magic */
|
|
|
|
if (target_platform == PLATFORM_WINDOWS) output_rva( ".L__wine_spec_relay_descr" );
|
|
|
|
else output( "\t.long 0\n" );
|
|
|
|
}
|
|
|
|
|
2005-08-23 22:08:37 +02:00
|
|
|
/* output the export name strings */
|
|
|
|
|
2006-08-11 20:41:29 +02:00
|
|
|
output( "\n.L__wine_spec_exp_names:\n" );
|
|
|
|
output( "\t%s \"%s\"\n", get_asm_string_keyword(), spec->file_name );
|
2005-08-23 22:08:37 +02:00
|
|
|
for (i = 0; i < spec->nb_names; i++)
|
2006-08-11 20:41:29 +02:00
|
|
|
output( "\t%s \"%s\"\n",
|
2005-08-23 22:08:37 +02:00
|
|
|
get_asm_string_keyword(), spec->names[i]->name );
|
|
|
|
|
2000-12-11 04:42:20 +01:00
|
|
|
/* output forward strings */
|
2000-06-23 22:15:35 +02:00
|
|
|
|
|
|
|
if (fwd_size)
|
|
|
|
{
|
2006-08-11 20:41:29 +02:00
|
|
|
output( "\n.L__wine_spec_forwards:\n" );
|
2004-02-11 07:41:01 +01:00
|
|
|
for (i = spec->base; i <= spec->limit; i++)
|
2000-06-23 22:15:35 +02: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))
|
2006-08-11 20:41:29 +02:00
|
|
|
output( "\t%s \"%s\"\n", get_asm_string_keyword(), odp->link_name );
|
2000-06-23 22:15:35 +02:00
|
|
|
}
|
|
|
|
}
|
2019-03-12 10:02:04 +01:00
|
|
|
|
2000-06-23 22:15:35 +02:00
|
|
|
/* output relays */
|
|
|
|
|
2019-06-21 12:08:44 +02:00
|
|
|
if (needs_relay)
|
2000-06-23 22:15:35 +02:00
|
|
|
{
|
2019-06-21 12:08:44 +02:00
|
|
|
if (target_platform == PLATFORM_WINDOWS)
|
|
|
|
{
|
|
|
|
output( "\t.data\n" );
|
|
|
|
output( "\t.align %d\n", get_alignment(get_ptr_size()) );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
output( "\t.align %d\n", get_alignment(get_ptr_size()) );
|
|
|
|
output( ".L__wine_spec_exports_end:\n" );
|
|
|
|
}
|
|
|
|
|
|
|
|
output( ".L__wine_spec_relay_descr:\n" );
|
|
|
|
output( "\t%s 0xdeb90002\n", get_asm_ptr_keyword() ); /* magic */
|
|
|
|
output( "\t%s 0\n", get_asm_ptr_keyword() ); /* relay func */
|
|
|
|
output( "\t%s 0\n", get_asm_ptr_keyword() ); /* private data */
|
|
|
|
output( "\t%s __wine_spec_relay_entry_points\n", get_asm_ptr_keyword() );
|
|
|
|
output( "\t%s .L__wine_spec_relay_entry_point_offsets\n", get_asm_ptr_keyword() );
|
|
|
|
output( "\t%s .L__wine_spec_relay_args_string\n", get_asm_ptr_keyword() );
|
|
|
|
|
|
|
|
output_relay_debug( spec );
|
2019-05-16 21:33:47 +02:00
|
|
|
}
|
2019-06-21 12:08:44 +02:00
|
|
|
else if (target_platform != PLATFORM_WINDOWS)
|
2019-05-16 21:33:47 +02:00
|
|
|
{
|
2019-06-21 12:08:44 +02:00
|
|
|
output( "\t.align %d\n", get_alignment(get_ptr_size()) );
|
|
|
|
output( ".L__wine_spec_exports_end:\n" );
|
2019-05-16 21:33:47 +02:00
|
|
|
output( "\t%s 0\n", get_asm_ptr_keyword() );
|
2005-12-18 10:45:01 +01:00
|
|
|
}
|
2001-12-15 00:14:22 +01:00
|
|
|
|
2019-06-21 12:08:44 +02:00
|
|
|
/* output import thunks */
|
|
|
|
|
|
|
|
if (!needs_imports) return;
|
|
|
|
output( "\t.text\n" );
|
|
|
|
for (i = spec->base; i <= spec->limit; i++)
|
|
|
|
{
|
|
|
|
ORDDEF *odp = spec->ordinals[i];
|
|
|
|
if (!odp) continue;
|
|
|
|
if (!(odp->flags & FLAG_IMPORT)) continue;
|
|
|
|
|
|
|
|
name = odp->name ? odp->name : odp->export_name;
|
|
|
|
|
|
|
|
output( "\t.align %d\n", get_alignment(4) );
|
|
|
|
output( "\t.long 0x90909090,0x90909090\n" );
|
|
|
|
if (name) output( "%s_%s:\n", asm_name("__wine_spec_imp"), name );
|
|
|
|
else output( "%s_%u:\n", asm_name("__wine_spec_imp"), i );
|
|
|
|
output_cfi( ".cfi_startproc" );
|
2000-06-23 22:15:35 +02:00
|
|
|
|
2019-06-21 12:08:44 +02:00
|
|
|
switch (target_cpu)
|
|
|
|
{
|
|
|
|
case CPU_x86:
|
|
|
|
output( "\t.byte 0x8b,0xff,0x55,0x8b,0xec,0x5d\n" ); /* hotpatch prolog */
|
|
|
|
if (UsePIC)
|
|
|
|
{
|
|
|
|
output( "\tcall %s\n", asm_name("__wine_spec_get_pc_thunk_eax") );
|
|
|
|
output( "1:\tjmp *__imp_%s-1b(%%eax)\n", asm_name( get_link_name( odp )));
|
|
|
|
needs_get_pc_thunk = 1;
|
|
|
|
}
|
2019-08-27 10:12:10 +02:00
|
|
|
else output( "\tjmp *__imp_%s\n", asm_name( get_link_name( odp )));
|
2019-06-21 12:08:44 +02:00
|
|
|
break;
|
|
|
|
case CPU_x86_64:
|
2020-06-26 11:42:39 +02:00
|
|
|
output( "\t.byte 0x48,0x8d,0xa4,0x24,0x00,0x00,0x00,0x00\n" ); /* hotpatch prolog */
|
2019-06-21 12:08:44 +02:00
|
|
|
output( "\tjmp *__imp_%s(%%rip)\n", asm_name( get_link_name( odp )));
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
assert(0);
|
|
|
|
}
|
|
|
|
output_cfi( ".cfi_endproc" );
|
|
|
|
}
|
2000-06-23 22:15:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*******************************************************************
|
2009-02-24 18:02:15 +01:00
|
|
|
* output_module
|
2000-06-23 22:15:35 +02:00
|
|
|
*
|
2009-02-24 18:02:15 +01:00
|
|
|
* Output the module data.
|
2000-06-23 22:15:35 +02:00
|
|
|
*/
|
2009-02-24 18:02:15 +01:00
|
|
|
void output_module( DLLSPEC *spec )
|
2000-06-23 22:15:35 +02:00
|
|
|
{
|
2005-09-15 11:42:22 +02:00
|
|
|
int machine = 0;
|
2005-06-27 13:23:24 +02:00
|
|
|
unsigned int page_size = get_page_size();
|
2019-03-06 10:37:12 +01:00
|
|
|
const char *data_dirs[16] = { NULL };
|
2000-06-23 22:15:35 +02:00
|
|
|
|
|
|
|
/* Reserve some space for the PE header */
|
|
|
|
|
2008-07-22 13:26:45 +02:00
|
|
|
switch (target_platform)
|
2008-01-16 20:27:35 +01:00
|
|
|
{
|
2019-06-04 12:38:43 +02:00
|
|
|
case PLATFORM_WINDOWS:
|
|
|
|
return; /* nothing to do */
|
2008-07-22 13:26:45 +02:00
|
|
|
case PLATFORM_APPLE:
|
2008-01-16 20:27:35 +01:00
|
|
|
output( "\t.text\n" );
|
|
|
|
output( "\t.align %d\n", get_alignment(page_size) );
|
|
|
|
output( "__wine_spec_pe_header:\n" );
|
|
|
|
output( "\t.space 65536\n" );
|
2008-07-22 13:26:45 +02:00
|
|
|
break;
|
|
|
|
case PLATFORM_SOLARIS:
|
|
|
|
output( "\n\t.section \".text\",\"ax\"\n" );
|
|
|
|
output( "__wine_spec_pe_header:\n" );
|
|
|
|
output( "\t.skip %u\n", 65536 + page_size );
|
|
|
|
break;
|
|
|
|
default:
|
2008-05-31 10:49:49 +02:00
|
|
|
switch(target_cpu)
|
|
|
|
{
|
|
|
|
case CPU_x86:
|
|
|
|
case CPU_x86_64:
|
2012-06-25 00:20:50 +02:00
|
|
|
output( "\n\t.section \".init\",\"ax\"\n" );
|
2008-05-31 10:49:49 +02:00
|
|
|
output( "\tjmp 1f\n" );
|
|
|
|
break;
|
2009-11-17 20:20:48 +01:00
|
|
|
case CPU_ARM:
|
2012-06-25 00:20:50 +02:00
|
|
|
output( "\n\t.section \".text\",\"ax\"\n" );
|
|
|
|
output( "\tb 1f\n" );
|
2012-04-29 21:43:14 +02:00
|
|
|
break;
|
2013-01-16 00:43:01 +01:00
|
|
|
case CPU_ARM64:
|
2008-05-31 10:49:49 +02:00
|
|
|
case CPU_POWERPC:
|
2012-06-25 00:20:50 +02:00
|
|
|
output( "\n\t.section \".init\",\"ax\"\n" );
|
2008-05-31 10:49:49 +02:00
|
|
|
output( "\tb 1f\n" );
|
|
|
|
break;
|
|
|
|
}
|
2008-01-16 20:27:35 +01:00
|
|
|
output( "__wine_spec_pe_header:\n" );
|
2008-01-16 17:51:59 +01:00
|
|
|
output( "\t.skip %u\n", 65536 + page_size );
|
2008-01-16 20:27:35 +01:00
|
|
|
output( "1:\n" );
|
2008-07-22 13:26:45 +02:00
|
|
|
break;
|
2008-01-16 20:27:35 +01:00
|
|
|
}
|
2000-10-23 23:33:06 +02:00
|
|
|
|
2000-09-28 01:40:43 +02:00
|
|
|
/* Output the NT header */
|
|
|
|
|
2006-08-11 20:41:29 +02:00
|
|
|
output( "\n\t.data\n" );
|
|
|
|
output( "\t.align %d\n", get_alignment(get_ptr_size()) );
|
2020-04-15 17:49:09 +02:00
|
|
|
output( "\t.globl %s\n", asm_name("__wine_spec_nt_header") );
|
|
|
|
output( "%s:\n", asm_name("__wine_spec_nt_header") );
|
2006-08-11 20:41:29 +02:00
|
|
|
output( ".L__wine_spec_rva_base:\n" );
|
2005-09-07 13:44:16 +02:00
|
|
|
|
2009-04-09 20:58:43 +02:00
|
|
|
output( "\t.long 0x4550\n" ); /* Signature */
|
2005-06-27 13:23:24 +02:00
|
|
|
switch(target_cpu)
|
|
|
|
{
|
2005-09-07 13:44:16 +02:00
|
|
|
case CPU_x86: machine = IMAGE_FILE_MACHINE_I386; break;
|
2005-09-07 15:31:37 +02:00
|
|
|
case CPU_x86_64: machine = IMAGE_FILE_MACHINE_AMD64; break;
|
2013-03-08 21:35:13 +01:00
|
|
|
case CPU_POWERPC: machine = IMAGE_FILE_MACHINE_POWERPC; break;
|
2012-08-16 22:40:14 +02:00
|
|
|
case CPU_ARM: machine = IMAGE_FILE_MACHINE_ARMNT; break;
|
2013-01-16 00:43:01 +01:00
|
|
|
case CPU_ARM64: machine = IMAGE_FILE_MACHINE_ARM64; break;
|
2005-06-27 13:23:24 +02:00
|
|
|
}
|
2013-03-08 21:37:05 +01:00
|
|
|
output( "\t.short 0x%04x\n", /* Machine */
|
|
|
|
machine );
|
|
|
|
output( "\t.short 0\n" ); /* NumberOfSections */
|
2006-08-11 20:41:29 +02:00
|
|
|
output( "\t.long 0\n" ); /* TimeDateStamp */
|
|
|
|
output( "\t.long 0\n" ); /* PointerToSymbolTable */
|
|
|
|
output( "\t.long 0\n" ); /* NumberOfSymbols */
|
2013-03-08 21:37:05 +01:00
|
|
|
output( "\t.short %d\n", /* SizeOfOptionalHeader */
|
2005-09-08 13:35:19 +02:00
|
|
|
get_ptr_size() == 8 ? IMAGE_SIZEOF_NT_OPTIONAL64_HEADER : IMAGE_SIZEOF_NT_OPTIONAL32_HEADER );
|
2013-03-08 21:37:05 +01:00
|
|
|
output( "\t.short 0x%04x\n", /* Characteristics */
|
|
|
|
spec->characteristics );
|
|
|
|
output( "\t.short 0x%04x\n", /* Magic */
|
2005-09-08 13:35:19 +02:00
|
|
|
get_ptr_size() == 8 ? IMAGE_NT_OPTIONAL_HDR64_MAGIC : IMAGE_NT_OPTIONAL_HDR32_MAGIC );
|
2014-08-21 05:57:24 +02:00
|
|
|
output( "\t.byte 7\n" ); /* MajorLinkerVersion */
|
|
|
|
output( "\t.byte 10\n" ); /* MinorLinkerVersion */
|
2006-08-11 20:41:29 +02:00
|
|
|
output( "\t.long 0\n" ); /* SizeOfCode */
|
|
|
|
output( "\t.long 0\n" ); /* SizeOfInitializedData */
|
|
|
|
output( "\t.long 0\n" ); /* SizeOfUninitializedData */
|
2005-09-17 16:39:51 +02:00
|
|
|
/* note: we expand the AddressOfEntryPoint field on 64-bit by overwriting the BaseOfCode field */
|
2006-08-11 20:41:29 +02:00
|
|
|
output( "\t%s %s\n", /* AddressOfEntryPoint */
|
2009-02-24 17:53:06 +01:00
|
|
|
get_asm_ptr_keyword(), spec->init_func ? asm_name(spec->init_func) : "0" );
|
2005-09-15 11:42:22 +02:00
|
|
|
if (get_ptr_size() == 4)
|
2005-09-17 16:39:51 +02:00
|
|
|
{
|
2006-08-11 20:41:29 +02:00
|
|
|
output( "\t.long 0\n" ); /* BaseOfCode */
|
|
|
|
output( "\t.long 0\n" ); /* BaseOfData */
|
2005-09-17 16:39:51 +02:00
|
|
|
}
|
2006-08-11 20:41:29 +02:00
|
|
|
output( "\t%s __wine_spec_pe_header\n", /* ImageBase */
|
2005-09-08 13:35:19 +02:00
|
|
|
get_asm_ptr_keyword() );
|
2006-08-11 20:41:29 +02:00
|
|
|
output( "\t.long %u\n", page_size ); /* SectionAlignment */
|
|
|
|
output( "\t.long %u\n", page_size ); /* FileAlignment */
|
2013-03-08 21:37:05 +01:00
|
|
|
output( "\t.short 1,0\n" ); /* Major/MinorOperatingSystemVersion */
|
|
|
|
output( "\t.short 0,0\n" ); /* Major/MinorImageVersion */
|
|
|
|
output( "\t.short %u,%u\n", /* Major/MinorSubsystemVersion */
|
|
|
|
spec->subsystem_major, spec->subsystem_minor );
|
2006-08-11 20:41:29 +02:00
|
|
|
output( "\t.long 0\n" ); /* Win32VersionValue */
|
2019-03-06 10:13:45 +01:00
|
|
|
output_rva( "%s", asm_name("_end") ); /* SizeOfImage */
|
2006-08-11 20:41:29 +02:00
|
|
|
output( "\t.long %u\n", page_size ); /* SizeOfHeaders */
|
|
|
|
output( "\t.long 0\n" ); /* CheckSum */
|
2013-03-08 21:37:05 +01:00
|
|
|
output( "\t.short 0x%04x\n", /* Subsystem */
|
|
|
|
spec->subsystem );
|
|
|
|
output( "\t.short 0x%04x\n", /* DllCharacteristics */
|
|
|
|
spec->dll_characteristics );
|
2006-08-11 20:41:29 +02:00
|
|
|
output( "\t%s %u,%u\n", /* SizeOfStackReserve/Commit */
|
2005-09-08 13:35:19 +02:00
|
|
|
get_asm_ptr_keyword(), (spec->stack_size ? spec->stack_size : 1024) * 1024, page_size );
|
2006-08-11 20:41:29 +02:00
|
|
|
output( "\t%s %u,%u\n", /* SizeOfHeapReserve/Commit */
|
2005-09-08 13:35:19 +02:00
|
|
|
get_asm_ptr_keyword(), (spec->heap_size ? spec->heap_size : 1024) * 1024, page_size );
|
2006-08-11 20:41:29 +02:00
|
|
|
output( "\t.long 0\n" ); /* LoaderFlags */
|
|
|
|
output( "\t.long 16\n" ); /* NumberOfRvaAndSizes */
|
2000-06-23 22:15:35 +02:00
|
|
|
|
2020-07-06 15:50:00 +02:00
|
|
|
if (get_exports_count( spec ))
|
2019-03-06 10:37:12 +01:00
|
|
|
data_dirs[0] = ".L__wine_spec_exports"; /* DataDirectory[IMAGE_DIRECTORY_ENTRY_EXPORT] */
|
|
|
|
if (has_imports())
|
|
|
|
data_dirs[1] = ".L__wine_spec_imports"; /* DataDirectory[IMAGE_DIRECTORY_ENTRY_IMPORT] */
|
|
|
|
if (spec->nb_resources)
|
|
|
|
data_dirs[2] = ".L__wine_spec_resources"; /* DataDirectory[IMAGE_DIRECTORY_ENTRY_RESOURCE] */
|
2005-09-07 13:44:16 +02:00
|
|
|
|
2019-03-06 10:37:12 +01:00
|
|
|
output_data_directories( data_dirs );
|
2006-08-11 20:41:29 +02:00
|
|
|
|
2005-09-15 11:42:22 +02:00
|
|
|
if (target_platform == PLATFORM_APPLE)
|
2006-08-11 20:41:29 +02:00
|
|
|
output( "\t.lcomm %s,4\n", asm_name("_end") );
|
2009-02-24 18:02:15 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*******************************************************************
|
2019-03-06 10:10:30 +01:00
|
|
|
* output_spec32_file
|
2009-02-24 18:02:15 +01:00
|
|
|
*
|
|
|
|
* Build a Win32 C file from a spec file.
|
|
|
|
*/
|
2019-03-06 10:10:30 +01:00
|
|
|
void output_spec32_file( DLLSPEC *spec )
|
2009-02-24 18:02:15 +01:00
|
|
|
{
|
2016-03-22 09:59:30 +01:00
|
|
|
needs_get_pc_thunk = 0;
|
2019-03-04 14:31:48 +01:00
|
|
|
open_output_file();
|
2009-02-24 18:02:15 +01:00
|
|
|
output_standard_file_header();
|
|
|
|
output_module( spec );
|
2006-08-11 20:41:29 +02:00
|
|
|
output_stubs( spec );
|
|
|
|
output_exports( spec );
|
|
|
|
output_imports( spec );
|
2020-07-07 10:42:23 +02:00
|
|
|
output_syscalls( spec );
|
2016-03-22 09:59:30 +01:00
|
|
|
if (needs_get_pc_thunk) output_get_pc_thunk();
|
2006-08-11 20:41:29 +02:00
|
|
|
output_resources( spec );
|
|
|
|
output_gnu_stack_note();
|
2019-03-04 14:31:48 +01:00
|
|
|
close_output_file();
|
2000-06-23 22:15:35 +02:00
|
|
|
}
|
2002-02-04 19:48:18 +01:00
|
|
|
|
|
|
|
|
2009-08-14 14:16:38 +02:00
|
|
|
/*******************************************************************
|
|
|
|
* output_fake_module
|
|
|
|
*
|
|
|
|
* Build a fake binary module from a spec file.
|
|
|
|
*/
|
|
|
|
void output_fake_module( DLLSPEC *spec )
|
|
|
|
{
|
|
|
|
static const unsigned char dll_code_section[] = { 0x31, 0xc0, /* xor %eax,%eax */
|
|
|
|
0xc2, 0x0c, 0x00 }; /* ret $12 */
|
|
|
|
|
|
|
|
static const unsigned char exe_code_section[] = { 0xb8, 0x01, 0x00, 0x00, 0x00, /* movl $1,%eax */
|
|
|
|
0xc2, 0x04, 0x00 }; /* ret $4 */
|
|
|
|
|
|
|
|
const unsigned int page_size = get_page_size();
|
|
|
|
const unsigned int section_align = page_size;
|
|
|
|
const unsigned int file_align = 0x200;
|
|
|
|
const unsigned int reloc_size = 8;
|
2019-12-18 21:05:27 +01:00
|
|
|
const unsigned int lfanew = 0x40 + sizeof(fakedll_signature);
|
2009-08-14 14:16:38 +02:00
|
|
|
const unsigned int nb_sections = 2 + (spec->nb_resources != 0);
|
|
|
|
const unsigned int text_size = (spec->characteristics & IMAGE_FILE_DLL) ?
|
|
|
|
sizeof(dll_code_section) : sizeof(exe_code_section);
|
|
|
|
unsigned char *resources;
|
|
|
|
unsigned int resources_size;
|
|
|
|
unsigned int image_size = 3 * section_align;
|
|
|
|
|
|
|
|
resolve_imports( spec );
|
|
|
|
output_bin_resources( spec, 3 * section_align );
|
|
|
|
resources = output_buffer;
|
|
|
|
resources_size = output_buffer_pos;
|
|
|
|
if (resources_size) image_size += (resources_size + section_align - 1) & ~(section_align - 1);
|
|
|
|
|
|
|
|
init_output_buffer();
|
|
|
|
|
|
|
|
put_word( 0x5a4d ); /* e_magic */
|
|
|
|
put_word( 0x40 ); /* e_cblp */
|
|
|
|
put_word( 0x01 ); /* e_cp */
|
|
|
|
put_word( 0 ); /* e_crlc */
|
|
|
|
put_word( lfanew / 16 ); /* e_cparhdr */
|
|
|
|
put_word( 0x0000 ); /* e_minalloc */
|
|
|
|
put_word( 0xffff ); /* e_maxalloc */
|
|
|
|
put_word( 0x0000 ); /* e_ss */
|
|
|
|
put_word( 0x00b8 ); /* e_sp */
|
|
|
|
put_word( 0 ); /* e_csum */
|
|
|
|
put_word( 0 ); /* e_ip */
|
|
|
|
put_word( 0 ); /* e_cs */
|
|
|
|
put_word( lfanew ); /* e_lfarlc */
|
|
|
|
put_word( 0 ); /* e_ovno */
|
|
|
|
put_dword( 0 ); /* e_res */
|
|
|
|
put_dword( 0 );
|
|
|
|
put_word( 0 ); /* e_oemid */
|
|
|
|
put_word( 0 ); /* e_oeminfo */
|
|
|
|
put_dword( 0 ); /* e_res2 */
|
|
|
|
put_dword( 0 );
|
|
|
|
put_dword( 0 );
|
|
|
|
put_dword( 0 );
|
|
|
|
put_dword( 0 );
|
|
|
|
put_dword( lfanew );
|
|
|
|
|
|
|
|
put_data( fakedll_signature, sizeof(fakedll_signature) );
|
|
|
|
|
|
|
|
put_dword( 0x4550 ); /* Signature */
|
|
|
|
switch(target_cpu)
|
|
|
|
{
|
|
|
|
case CPU_x86: put_word( IMAGE_FILE_MACHINE_I386 ); break;
|
|
|
|
case CPU_x86_64: put_word( IMAGE_FILE_MACHINE_AMD64 ); break;
|
|
|
|
case CPU_POWERPC: put_word( IMAGE_FILE_MACHINE_POWERPC ); break;
|
2012-08-16 22:40:14 +02:00
|
|
|
case CPU_ARM: put_word( IMAGE_FILE_MACHINE_ARMNT ); break;
|
2013-01-16 00:43:01 +01:00
|
|
|
case CPU_ARM64: put_word( IMAGE_FILE_MACHINE_ARM64 ); break;
|
2009-08-14 14:16:38 +02:00
|
|
|
}
|
|
|
|
put_word( nb_sections ); /* NumberOfSections */
|
|
|
|
put_dword( 0 ); /* TimeDateStamp */
|
|
|
|
put_dword( 0 ); /* PointerToSymbolTable */
|
|
|
|
put_dword( 0 ); /* NumberOfSymbols */
|
|
|
|
put_word( get_ptr_size() == 8 ?
|
|
|
|
IMAGE_SIZEOF_NT_OPTIONAL64_HEADER :
|
|
|
|
IMAGE_SIZEOF_NT_OPTIONAL32_HEADER ); /* SizeOfOptionalHeader */
|
|
|
|
put_word( spec->characteristics ); /* Characteristics */
|
|
|
|
put_word( get_ptr_size() == 8 ?
|
|
|
|
IMAGE_NT_OPTIONAL_HDR64_MAGIC :
|
|
|
|
IMAGE_NT_OPTIONAL_HDR32_MAGIC ); /* Magic */
|
2014-08-21 05:57:24 +02:00
|
|
|
put_byte( 7 ); /* MajorLinkerVersion */
|
|
|
|
put_byte( 10 ); /* MinorLinkerVersion */
|
2009-08-14 14:16:38 +02:00
|
|
|
put_dword( text_size ); /* SizeOfCode */
|
|
|
|
put_dword( 0 ); /* SizeOfInitializedData */
|
|
|
|
put_dword( 0 ); /* SizeOfUninitializedData */
|
|
|
|
put_dword( section_align ); /* AddressOfEntryPoint */
|
|
|
|
put_dword( section_align ); /* BaseOfCode */
|
|
|
|
if (get_ptr_size() == 4) put_dword( 0 ); /* BaseOfData */
|
|
|
|
put_pword( 0x10000000 ); /* ImageBase */
|
|
|
|
put_dword( section_align ); /* SectionAlignment */
|
|
|
|
put_dword( file_align ); /* FileAlignment */
|
|
|
|
put_word( 1 ); /* MajorOperatingSystemVersion */
|
|
|
|
put_word( 0 ); /* MinorOperatingSystemVersion */
|
|
|
|
put_word( 0 ); /* MajorImageVersion */
|
|
|
|
put_word( 0 ); /* MinorImageVersion */
|
|
|
|
put_word( spec->subsystem_major ); /* MajorSubsystemVersion */
|
|
|
|
put_word( spec->subsystem_minor ); /* MinorSubsystemVersion */
|
|
|
|
put_dword( 0 ); /* Win32VersionValue */
|
|
|
|
put_dword( image_size ); /* SizeOfImage */
|
|
|
|
put_dword( file_align ); /* SizeOfHeaders */
|
|
|
|
put_dword( 0 ); /* CheckSum */
|
|
|
|
put_word( spec->subsystem ); /* Subsystem */
|
|
|
|
put_word( spec->dll_characteristics ); /* DllCharacteristics */
|
|
|
|
put_pword( (spec->stack_size ? spec->stack_size : 1024) * 1024 ); /* SizeOfStackReserve */
|
|
|
|
put_pword( page_size ); /* SizeOfStackCommit */
|
|
|
|
put_pword( (spec->heap_size ? spec->heap_size : 1024) * 1024 ); /* SizeOfHeapReserve */
|
|
|
|
put_pword( page_size ); /* SizeOfHeapCommit */
|
|
|
|
put_dword( 0 ); /* LoaderFlags */
|
|
|
|
put_dword( 16 ); /* NumberOfRvaAndSizes */
|
|
|
|
|
|
|
|
put_dword( 0 ); put_dword( 0 ); /* DataDirectory[IMAGE_DIRECTORY_ENTRY_EXPORT] */
|
|
|
|
put_dword( 0 ); put_dword( 0 ); /* DataDirectory[IMAGE_DIRECTORY_ENTRY_IMPORT] */
|
|
|
|
if (resources_size) /* DataDirectory[IMAGE_DIRECTORY_ENTRY_RESOURCE] */
|
|
|
|
{
|
|
|
|
put_dword( 3 * section_align );
|
|
|
|
put_dword( resources_size );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
put_dword( 0 );
|
|
|
|
put_dword( 0 );
|
|
|
|
}
|
|
|
|
|
|
|
|
put_dword( 0 ); put_dword( 0 ); /* DataDirectory[IMAGE_DIRECTORY_ENTRY_EXCEPTION] */
|
|
|
|
put_dword( 0 ); put_dword( 0 ); /* DataDirectory[IMAGE_DIRECTORY_ENTRY_SECURITY] */
|
|
|
|
put_dword( 2 * section_align ); /* DataDirectory[IMAGE_DIRECTORY_ENTRY_BASERELOC] */
|
|
|
|
put_dword( reloc_size );
|
|
|
|
put_dword( 0 ); put_dword( 0 ); /* DataDirectory[IMAGE_DIRECTORY_ENTRY_DEBUG] */
|
|
|
|
put_dword( 0 ); put_dword( 0 ); /* DataDirectory[IMAGE_DIRECTORY_ENTRY_COPYRIGHT] */
|
|
|
|
put_dword( 0 ); put_dword( 0 ); /* DataDirectory[IMAGE_DIRECTORY_ENTRY_GLOBALPTR] */
|
|
|
|
put_dword( 0 ); put_dword( 0 ); /* DataDirectory[IMAGE_DIRECTORY_ENTRY_TLS] */
|
|
|
|
put_dword( 0 ); put_dword( 0 ); /* DataDirectory[IMAGE_DIRECTORY_ENTRY_LOAD_CONFIG] */
|
|
|
|
put_dword( 0 ); put_dword( 0 ); /* DataDirectory[IMAGE_DIRECTORY_ENTRY_BOUND_IMPORT] */
|
|
|
|
put_dword( 0 ); put_dword( 0 ); /* DataDirectory[IMAGE_DIRECTORY_ENTRY_IAT] */
|
|
|
|
put_dword( 0 ); put_dword( 0 ); /* DataDirectory[IMAGE_DIRECTORY_ENTRY_DELAY_IMPORT] */
|
|
|
|
put_dword( 0 ); put_dword( 0 ); /* DataDirectory[IMAGE_DIRECTORY_ENTRY_COM_DESCRIPTOR] */
|
|
|
|
put_dword( 0 ); put_dword( 0 ); /* DataDirectory[15] */
|
|
|
|
|
|
|
|
/* .text section */
|
|
|
|
put_data( ".text\0\0", 8 ); /* Name */
|
|
|
|
put_dword( section_align ); /* VirtualSize */
|
|
|
|
put_dword( section_align ); /* VirtualAddress */
|
|
|
|
put_dword( text_size ); /* SizeOfRawData */
|
|
|
|
put_dword( file_align ); /* PointerToRawData */
|
|
|
|
put_dword( 0 ); /* PointerToRelocations */
|
|
|
|
put_dword( 0 ); /* PointerToLinenumbers */
|
|
|
|
put_word( 0 ); /* NumberOfRelocations */
|
|
|
|
put_word( 0 ); /* NumberOfLinenumbers */
|
|
|
|
put_dword( 0x60000020 /* CNT_CODE|MEM_EXECUTE|MEM_READ */ ); /* Characteristics */
|
|
|
|
|
|
|
|
/* .reloc section */
|
|
|
|
put_data( ".reloc\0", 8 ); /* Name */
|
|
|
|
put_dword( section_align ); /* VirtualSize */
|
|
|
|
put_dword( 2 * section_align );/* VirtualAddress */
|
|
|
|
put_dword( reloc_size ); /* SizeOfRawData */
|
|
|
|
put_dword( 2 * file_align ); /* PointerToRawData */
|
|
|
|
put_dword( 0 ); /* PointerToRelocations */
|
|
|
|
put_dword( 0 ); /* PointerToLinenumbers */
|
|
|
|
put_word( 0 ); /* NumberOfRelocations */
|
|
|
|
put_word( 0 ); /* NumberOfLinenumbers */
|
|
|
|
put_dword( 0x42000040 /* CNT_INITIALIZED_DATA|MEM_DISCARDABLE|MEM_READ */ ); /* Characteristics */
|
|
|
|
|
|
|
|
/* .rsrc section */
|
|
|
|
if (resources_size)
|
|
|
|
{
|
|
|
|
put_data( ".rsrc\0\0", 8 ); /* Name */
|
|
|
|
put_dword( (resources_size + section_align - 1) & ~(section_align - 1) ); /* VirtualSize */
|
|
|
|
put_dword( 3 * section_align );/* VirtualAddress */
|
|
|
|
put_dword( resources_size ); /* SizeOfRawData */
|
|
|
|
put_dword( 3 * file_align ); /* PointerToRawData */
|
|
|
|
put_dword( 0 ); /* PointerToRelocations */
|
|
|
|
put_dword( 0 ); /* PointerToLinenumbers */
|
|
|
|
put_word( 0 ); /* NumberOfRelocations */
|
|
|
|
put_word( 0 ); /* NumberOfLinenumbers */
|
|
|
|
put_dword( 0x40000040 /* CNT_INITIALIZED_DATA|MEM_READ */ ); /* Characteristics */
|
|
|
|
}
|
|
|
|
|
|
|
|
/* .text contents */
|
|
|
|
align_output( file_align );
|
|
|
|
if (spec->characteristics & IMAGE_FILE_DLL)
|
|
|
|
put_data( dll_code_section, sizeof(dll_code_section) );
|
|
|
|
else
|
|
|
|
put_data( exe_code_section, sizeof(exe_code_section) );
|
|
|
|
|
|
|
|
/* .reloc contents */
|
|
|
|
align_output( file_align );
|
|
|
|
put_dword( 0 ); /* VirtualAddress */
|
|
|
|
put_dword( 0 ); /* SizeOfBlock */
|
|
|
|
|
|
|
|
/* .rsrc contents */
|
|
|
|
if (resources_size)
|
|
|
|
{
|
|
|
|
align_output( file_align );
|
|
|
|
put_data( resources, resources_size );
|
|
|
|
}
|
|
|
|
flush_output_buffer();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-02-04 19:48:18 +01:00
|
|
|
/*******************************************************************
|
2009-12-30 12:50:17 +01:00
|
|
|
* output_def_file
|
2002-02-04 19:48:18 +01:00
|
|
|
*
|
|
|
|
* Build a Win32 def file from a spec file.
|
|
|
|
*/
|
2019-08-25 18:49:23 +02:00
|
|
|
void output_def_file( DLLSPEC *spec, int import_only )
|
2002-02-04 19:48:18 +01:00
|
|
|
{
|
2009-12-30 12:32:17 +01:00
|
|
|
DLLSPEC *spec32 = NULL;
|
2002-07-28 19:54:31 +02:00
|
|
|
const char *name;
|
2005-07-26 20:57:19 +02:00
|
|
|
int i, total;
|
2002-02-04 19:48:18 +01:00
|
|
|
|
2009-12-30 12:32:17 +01:00
|
|
|
if (spec->type == SPEC_WIN16)
|
|
|
|
{
|
|
|
|
spec32 = alloc_dll_spec();
|
|
|
|
add_16bit_exports( spec32, spec );
|
|
|
|
spec = spec32;
|
|
|
|
}
|
|
|
|
|
2005-03-15 16:42:32 +01:00
|
|
|
if (spec_file_name)
|
2006-08-11 20:41:29 +02:00
|
|
|
output( "; File generated automatically from %s; do not edit!\n\n",
|
2005-03-15 16:42:32 +01:00
|
|
|
spec_file_name );
|
|
|
|
else
|
2006-08-11 20:41:29 +02:00
|
|
|
output( "; File generated automatically; do not edit!\n\n" );
|
2002-02-04 19:48:18 +01:00
|
|
|
|
2006-08-11 20:41:29 +02:00
|
|
|
output( "LIBRARY %s\n\n", spec->file_name);
|
|
|
|
output( "EXPORTS\n");
|
2002-02-04 19:48:18 +01:00
|
|
|
|
|
|
|
/* Output the exports and relay entry points */
|
|
|
|
|
2005-07-26 20:57:19 +02:00
|
|
|
for (i = total = 0; i < spec->nb_entry_points; i++)
|
2002-02-04 19:48:18 +01:00
|
|
|
{
|
2004-02-11 07:41:01 +01:00
|
|
|
const ORDDEF *odp = &spec->entry_points[i];
|
2019-03-20 12:33:14 +01:00
|
|
|
int is_data = 0, is_private = odp->flags & FLAG_PRIVATE;
|
2002-07-28 19:54:31 +02:00
|
|
|
|
|
|
|
if (odp->name) name = odp->name;
|
|
|
|
else if (odp->export_name) name = odp->export_name;
|
|
|
|
else continue;
|
|
|
|
|
2019-03-20 12:33:14 +01:00
|
|
|
if (!is_private) total++;
|
2019-08-25 18:49:23 +02:00
|
|
|
if (import_only && odp->type == TYPE_STUB) continue;
|
2005-07-26 20:57:19 +02:00
|
|
|
|
2019-05-16 10:12:42 +02:00
|
|
|
if ((odp->flags & FLAG_FASTCALL) && target_platform == PLATFORM_WINDOWS)
|
|
|
|
name = strmake( "@%s", name );
|
|
|
|
|
2006-08-11 20:41:29 +02:00
|
|
|
output( " %s", name );
|
2002-02-04 19:48:18 +01:00
|
|
|
|
|
|
|
switch(odp->type)
|
|
|
|
{
|
|
|
|
case TYPE_EXTERN:
|
2002-12-12 03:20:47 +01:00
|
|
|
is_data = 1;
|
|
|
|
/* fall through */
|
2002-02-04 19:48:18 +01:00
|
|
|
case TYPE_VARARGS:
|
|
|
|
case TYPE_CDECL:
|
|
|
|
/* try to reduce output */
|
2019-08-25 18:49:23 +02:00
|
|
|
if(!import_only && (strcmp(name, odp->link_name) || (odp->flags & FLAG_FORWARD)))
|
2006-08-11 20:41:29 +02:00
|
|
|
output( "=%s", odp->link_name );
|
2002-02-04 19:48:18 +01:00
|
|
|
break;
|
|
|
|
case TYPE_STDCALL:
|
|
|
|
{
|
2010-08-30 12:06:19 +02:00
|
|
|
int at_param = get_args_size( odp );
|
2008-12-03 22:37:07 +01:00
|
|
|
if (!kill_at && target_cpu == CPU_x86) output( "@%d", at_param );
|
2019-08-25 18:49:23 +02:00
|
|
|
if (import_only) break;
|
2002-12-15 02:22:40 +01:00
|
|
|
if (odp->flags & FLAG_FORWARD)
|
2006-08-11 20:41:29 +02:00
|
|
|
output( "=%s", odp->link_name );
|
2002-12-15 02:22:40 +01:00
|
|
|
else if (strcmp(name, odp->link_name)) /* try to reduce output */
|
2019-03-06 10:12:55 +01:00
|
|
|
output( "=%s", get_link_name( odp ));
|
2002-02-04 19:48:18 +01:00
|
|
|
break;
|
|
|
|
}
|
2019-03-20 12:33:14 +01:00
|
|
|
case TYPE_STUB:
|
|
|
|
if (!kill_at && target_cpu == CPU_x86) output( "@%d", get_args_size( odp ));
|
|
|
|
is_private = 1;
|
|
|
|
break;
|
2002-02-04 19:48:18 +01:00
|
|
|
default:
|
|
|
|
assert(0);
|
|
|
|
}
|
2006-08-11 20:41:29 +02:00
|
|
|
output( " @%d", odp->ordinal );
|
2007-10-26 12:47:40 +02:00
|
|
|
if (!odp->name || (odp->flags & FLAG_ORDINAL)) output( " NONAME" );
|
2006-08-11 20:41:29 +02:00
|
|
|
if (is_data) output( " DATA" );
|
2019-03-20 12:33:14 +01:00
|
|
|
if (is_private) output( " PRIVATE" );
|
2006-08-11 20:41:29 +02:00
|
|
|
output( "\n" );
|
2002-02-04 19:48:18 +01:00
|
|
|
}
|
2005-07-26 20:57:19 +02:00
|
|
|
if (!total) warning( "%s: Import library doesn't export anything\n", spec->file_name );
|
2009-12-30 12:32:17 +01:00
|
|
|
if (spec32) free_dll_spec( spec32 );
|
2002-02-04 19:48:18 +01:00
|
|
|
}
|
2019-12-18 21:05:27 +01:00
|
|
|
|
|
|
|
|
|
|
|
/*******************************************************************
|
|
|
|
* make_builtin_files
|
|
|
|
*/
|
|
|
|
void make_builtin_files( char *argv[] )
|
|
|
|
{
|
|
|
|
int i, fd;
|
|
|
|
struct
|
|
|
|
{
|
|
|
|
unsigned short e_magic;
|
|
|
|
unsigned short unused[29];
|
|
|
|
unsigned int e_lfanew;
|
|
|
|
} header;
|
|
|
|
|
|
|
|
for (i = 0; argv[i]; i++)
|
|
|
|
{
|
|
|
|
if ((fd = open( argv[i], O_RDWR | O_BINARY )) == -1) fatal_perror( "Cannot open %s", argv[i] );
|
|
|
|
if (read( fd, &header, sizeof(header) ) == sizeof(header) && !memcmp( &header.e_magic, "MZ", 2 ))
|
|
|
|
{
|
|
|
|
if (header.e_lfanew < sizeof(header) + sizeof(builtin_signature))
|
|
|
|
fatal_error( "%s: Not enough space (%x) for Wine signature\n", argv[i], header.e_lfanew );
|
|
|
|
write( fd, builtin_signature, sizeof(builtin_signature) );
|
|
|
|
}
|
|
|
|
else fatal_error( "%s: Unrecognized file format\n", argv[i] );
|
|
|
|
close( fd );
|
|
|
|
}
|
|
|
|
}
|
2020-04-16 12:21:23 +02:00
|
|
|
|
|
|
|
static void fixup_elf32( const char *name, int fd, void *header, size_t header_size )
|
|
|
|
{
|
|
|
|
struct
|
|
|
|
{
|
|
|
|
unsigned char e_ident[16];
|
|
|
|
unsigned short e_type;
|
|
|
|
unsigned short e_machine;
|
|
|
|
unsigned int e_version;
|
|
|
|
unsigned int e_entry;
|
|
|
|
unsigned int e_phoff;
|
|
|
|
unsigned int e_shoff;
|
|
|
|
unsigned int e_flags;
|
|
|
|
unsigned short e_ehsize;
|
|
|
|
unsigned short e_phentsize;
|
|
|
|
unsigned short e_phnum;
|
|
|
|
unsigned short e_shentsize;
|
|
|
|
unsigned short e_shnum;
|
|
|
|
unsigned short e_shstrndx;
|
|
|
|
} *elf = header;
|
|
|
|
struct
|
|
|
|
{
|
|
|
|
unsigned int p_type;
|
|
|
|
unsigned int p_offset;
|
|
|
|
unsigned int p_vaddr;
|
|
|
|
unsigned int p_paddr;
|
|
|
|
unsigned int p_filesz;
|
|
|
|
unsigned int p_memsz;
|
|
|
|
unsigned int p_flags;
|
|
|
|
unsigned int p_align;
|
|
|
|
} *phdr;
|
|
|
|
struct
|
|
|
|
{
|
|
|
|
unsigned int d_tag;
|
|
|
|
unsigned int d_val;
|
|
|
|
} *dyn;
|
|
|
|
|
|
|
|
unsigned int i, size;
|
|
|
|
|
|
|
|
if (header_size < sizeof(*elf)) return;
|
|
|
|
if (elf->e_ident[6] != 1 /* EV_CURRENT */) return;
|
|
|
|
|
|
|
|
size = elf->e_phnum * elf->e_phentsize;
|
|
|
|
phdr = xmalloc( size );
|
|
|
|
lseek( fd, elf->e_phoff, SEEK_SET );
|
|
|
|
if (read( fd, phdr, size ) != size) return;
|
|
|
|
|
|
|
|
for (i = 0; i < elf->e_phnum; i++)
|
|
|
|
{
|
|
|
|
if (phdr->p_type == 2 /* PT_DYNAMIC */ ) break;
|
|
|
|
phdr = (void *)((char *)phdr + elf->e_phentsize);
|
|
|
|
}
|
|
|
|
if (i == elf->e_phnum) return;
|
|
|
|
|
|
|
|
dyn = xmalloc( phdr->p_filesz );
|
|
|
|
lseek( fd, phdr->p_offset, SEEK_SET );
|
|
|
|
if (read( fd, dyn, phdr->p_filesz ) != phdr->p_filesz) return;
|
|
|
|
for (i = 0; i < phdr->p_filesz / sizeof(*dyn) && dyn[i].d_tag; i++)
|
|
|
|
{
|
|
|
|
switch (dyn[i].d_tag)
|
|
|
|
{
|
|
|
|
case 25: dyn[i].d_tag = 0x60009990; break; /* DT_INIT_ARRAY */
|
|
|
|
case 27: dyn[i].d_tag = 0x60009991; break; /* DT_INIT_ARRAYSZ */
|
|
|
|
case 12: dyn[i].d_tag = 0x60009992; break; /* DT_INIT */
|
|
|
|
}
|
|
|
|
}
|
|
|
|
lseek( fd, phdr->p_offset, SEEK_SET );
|
|
|
|
write( fd, dyn, phdr->p_filesz );
|
|
|
|
}
|
|
|
|
|
|
|
|
static void fixup_elf64( const char *name, int fd, void *header, size_t header_size )
|
|
|
|
{
|
|
|
|
struct
|
|
|
|
{
|
|
|
|
unsigned char e_ident[16];
|
|
|
|
unsigned short e_type;
|
|
|
|
unsigned short e_machine;
|
|
|
|
unsigned int e_version;
|
|
|
|
unsigned __int64 e_entry;
|
|
|
|
unsigned __int64 e_phoff;
|
|
|
|
unsigned __int64 e_shoff;
|
|
|
|
unsigned int e_flags;
|
|
|
|
unsigned short e_ehsize;
|
|
|
|
unsigned short e_phentsize;
|
|
|
|
unsigned short e_phnum;
|
|
|
|
unsigned short e_shentsize;
|
|
|
|
unsigned short e_shnum;
|
|
|
|
unsigned short e_shstrndx;
|
|
|
|
} *elf = header;
|
|
|
|
struct
|
|
|
|
{
|
|
|
|
unsigned int p_type;
|
|
|
|
unsigned int p_flags;
|
|
|
|
unsigned __int64 p_offset;
|
|
|
|
unsigned __int64 p_vaddr;
|
|
|
|
unsigned __int64 p_paddr;
|
|
|
|
unsigned __int64 p_filesz;
|
|
|
|
unsigned __int64 p_memsz;
|
|
|
|
unsigned __int64 p_align;
|
|
|
|
} *phdr;
|
|
|
|
struct
|
|
|
|
{
|
|
|
|
unsigned __int64 d_tag;
|
|
|
|
unsigned __int64 d_val;
|
|
|
|
} *dyn;
|
|
|
|
|
|
|
|
unsigned int i, size;
|
|
|
|
|
|
|
|
if (header_size < sizeof(*elf)) return;
|
|
|
|
if (elf->e_ident[6] != 1 /* EV_CURRENT */) return;
|
|
|
|
|
|
|
|
size = elf->e_phnum * elf->e_phentsize;
|
|
|
|
phdr = xmalloc( size );
|
|
|
|
lseek( fd, elf->e_phoff, SEEK_SET );
|
|
|
|
if (read( fd, phdr, size ) != size) return;
|
|
|
|
|
|
|
|
for (i = 0; i < elf->e_phnum; i++)
|
|
|
|
{
|
|
|
|
if (phdr->p_type == 2 /* PT_DYNAMIC */ ) break;
|
|
|
|
phdr = (void *)((char *)phdr + elf->e_phentsize);
|
|
|
|
}
|
|
|
|
if (i == elf->e_phnum) return;
|
|
|
|
|
|
|
|
dyn = xmalloc( phdr->p_filesz );
|
|
|
|
lseek( fd, phdr->p_offset, SEEK_SET );
|
|
|
|
if (read( fd, dyn, phdr->p_filesz ) != phdr->p_filesz) return;
|
|
|
|
for (i = 0; i < phdr->p_filesz / sizeof(*dyn) && dyn[i].d_tag; i++)
|
|
|
|
{
|
|
|
|
switch (dyn[i].d_tag)
|
|
|
|
{
|
|
|
|
case 25: dyn[i].d_tag = 0x60009990; break; /* DT_INIT_ARRAY */
|
|
|
|
case 27: dyn[i].d_tag = 0x60009991; break; /* DT_INIT_ARRAYSZ */
|
|
|
|
case 12: dyn[i].d_tag = 0x60009992; break; /* DT_INIT */
|
|
|
|
}
|
|
|
|
}
|
|
|
|
lseek( fd, phdr->p_offset, SEEK_SET );
|
|
|
|
write( fd, dyn, phdr->p_filesz );
|
|
|
|
}
|
|
|
|
|
|
|
|
/*******************************************************************
|
|
|
|
* fixup_constructors
|
|
|
|
*/
|
|
|
|
void fixup_constructors( char *argv[] )
|
|
|
|
{
|
|
|
|
int i, fd, size;
|
|
|
|
unsigned int header[64];
|
|
|
|
|
|
|
|
for (i = 0; argv[i]; i++)
|
|
|
|
{
|
|
|
|
if ((fd = open( argv[i], O_RDWR | O_BINARY )) == -1) fatal_perror( "Cannot open %s", argv[i] );
|
|
|
|
size = read( fd, &header, sizeof(header) );
|
|
|
|
if (size > 5)
|
|
|
|
{
|
|
|
|
if (!memcmp( header, "\177ELF\001", 5 )) fixup_elf32( argv[i], fd, header, size );
|
|
|
|
else if (!memcmp( header, "\177ELF\002", 5 )) fixup_elf64( argv[i], fd, header, size );
|
|
|
|
}
|
|
|
|
close( fd );
|
|
|
|
}
|
|
|
|
}
|