Commit 71ae2d7b authored by Alexandre Julliard's avatar Alexandre Julliard

Beginnings of a crt0 library.

parent aa981732
......@@ -1648,6 +1648,7 @@ dlls/vtdapi.vxd/Makefile
dlls/vwin32.vxd/Makefile
dlls/win32s/Makefile
dlls/winaspi/Makefile
dlls/winecrt0/Makefile
dlls/wined3d/Makefile
dlls/winedos/Makefile
dlls/wineps/Makefile
......
......@@ -191,6 +191,7 @@ SUBDIRS = \
opengl32 \
strmiids \
uuid \
winecrt0 \
wined3d \
x11drv
......@@ -315,6 +316,7 @@ SYMLINKS_SO = \
libdxguid.a \
libstrmiids.a \
libuuid.a \
libwinecrt0.a \
lz32.dll.so \
mapi32.dll.so \
mciavi32.dll.so \
......@@ -1046,6 +1048,9 @@ libstrmiids.a: strmiids/libstrmiids.a
libuuid.a: uuid/libuuid.a
$(RM) $@ && $(LN_S) uuid/libuuid.a $@
libwinecrt0.a: winecrt0/libwinecrt0.a
$(RM) $@ && $(LN_S) winecrt0/libwinecrt0.a $@
# Import libraries
......@@ -1071,7 +1076,8 @@ IMPORT_SYMLINKS = \
libdxerr9.a \
libdxguid.a \
libstrmiids.a \
libuuid.a
libuuid.a \
libwinecrt0.a
IMPORT_LIBS = \
$(IMPORT_SYMLINKS) \
......@@ -1750,6 +1756,7 @@ dxerr9/libdxerr9.a: dxerr9
dxguid/libdxguid.a: dxguid
strmiids/libstrmiids.a: strmiids
uuid/libuuid.a: uuid
winecrt0/libwinecrt0.a: winecrt0
# Rules for auto documentation
......
DLLDEFS = @DLLDEFS@
DLLFLAGS = @DLLFLAGS@
DEFS = -D__WINESRC__ $(DLLDEFS)
TOPSRCDIR = @top_srcdir@
TOPOBJDIR = ../..
SRCDIR = @srcdir@
VPATH = @srcdir@
MODULE = libwinecrt0.a
C_SRCS = \
dll_main.c \
exe_main.c \
exe_wmain.c
all: $(MODULE)
@MAKE_RULES@
$(MODULE): $(OBJS) Makefile.in
$(RM) $@
$(AR) $@ $(OBJS)
$(RANLIB) $@
man doc-html doc-sgml:
### Dependencies:
/*
* DllMain default entry point
*
* Copyright 2005 Alexandre Julliard
*
* 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
*/
#include <stdarg.h>
#include "windef.h"
#include "winbase.h"
BOOL WINAPI DllMain( HINSTANCE inst, DWORD reason, LPVOID reserved )
{
/* if (reason == DLL_PROCESS_ATTACH) DisableThreadLibraryCalls( inst ); */
return TRUE;
}
/*
* main default entry point for exe files
*
* Copyright 2005 Alexandre Julliard
*
* 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
*/
#include <stdarg.h>
#include "windef.h"
#include "winbase.h"
#include "winuser.h"
int main( int argc, char *argv[] )
{
STARTUPINFOA info;
char *cmdline = GetCommandLineA();
int bcount = 0, in_quotes = 0;
while (*cmdline)
{
if ((*cmdline == '\t' || *cmdline == ' ') && !in_quotes) break;
else if (*cmdline == '\\') bcount++;
else if (*cmdline == '\"')
{
if (!(bcount & 1)) in_quotes = !in_quotes;
bcount = 0;
}
else bcount = 0;
cmdline++;
}
while (*cmdline == '\t' || *cmdline == ' ') cmdline++;
GetStartupInfoA( &info );
if (!(info.dwFlags & STARTF_USESHOWWINDOW)) info.wShowWindow = SW_SHOWNORMAL;
return WinMain( GetModuleHandleA(0), 0, cmdline, info.wShowWindow );
}
/*
* main default entry point for Unicode exe files
*
* Copyright 2005 Alexandre Julliard
*
* 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
*/
#include <stdarg.h>
#include "windef.h"
#include "winbase.h"
#include "winuser.h"
int WINAPI wWinMain(HINSTANCE,HINSTANCE,LPWSTR,int);
int wmain( int argc, WCHAR *argv[] )
{
STARTUPINFOW info;
WCHAR *cmdline = GetCommandLineW();
int bcount = 0, in_quotes = 0;
while (*cmdline)
{
if ((*cmdline == '\t' || *cmdline == ' ') && !in_quotes) break;
else if (*cmdline == '\\') bcount++;
else if (*cmdline == '\"')
{
if (!(bcount & 1)) in_quotes = !in_quotes;
bcount = 0;
}
else bcount = 0;
cmdline++;
}
while (*cmdline == '\t' || *cmdline == ' ') cmdline++;
GetStartupInfoW( &info );
if (!(info.dwFlags & STARTF_USESHOWWINDOW)) info.wShowWindow = SW_SHOWNORMAL;
return wWinMain( GetModuleHandleW(0), 0, cmdline, info.wShowWindow );
}
......@@ -3,7 +3,7 @@ TOPOBJDIR = ../..
SRCDIR = @srcdir@
VPATH = @srcdir@
MODULE = uninstaller.exe
APPMODE = -mconsole
APPMODE = -mconsole -Wb,-e,wmain
IMPORTS = shlwapi user32 gdi32 advapi32 kernel32
C_SRCS = \
......
......@@ -3,7 +3,7 @@ TOPOBJDIR = ../..
SRCDIR = @srcdir@
VPATH = @srcdir@
MODULE = winepath.exe
APPMODE = -mconsole
APPMODE = -mconsole -Wb,-e,wmain
IMPORTS = kernel32
C_SRCS = winepath.c
......
......@@ -191,7 +191,7 @@ extern void add_import_dll( const char *name, const char *filename );
extern void add_delayed_import( const char *name );
extern void add_ignore_symbol( const char *name );
extern void add_extra_ld_symbol( const char *name );
extern void read_undef_symbols( char **argv );
extern void read_undef_symbols( DLLSPEC *spec, char **argv );
extern int resolve_imports( DLLSPEC *spec );
extern int output_imports( FILE *outfile, DLLSPEC *spec, int *nb_delayed );
extern void output_import_thunks( FILE *outfile, DLLSPEC *spec );
......
......@@ -585,7 +585,7 @@ static const char *ldcombine_files( char **argv )
}
/* read in the list of undefined symbols */
void read_undef_symbols( char **argv )
void read_undef_symbols( DLLSPEC *spec, char **argv )
{
size_t prefix_len;
FILE *f;
......@@ -595,12 +595,15 @@ void read_undef_symbols( char **argv )
if (!argv[0]) return;
if (spec->init_func) add_extra_ld_symbol( spec->init_func );
else if (spec->characteristics & IMAGE_FILE_DLL) add_extra_ld_symbol( "DllMain" );
else if (spec->subsystem == IMAGE_SUBSYSTEM_NATIVE) add_extra_ld_symbol( "DriverEntry ");
else add_extra_ld_symbol( "main" );
strcpy( name_prefix, asm_name("") );
prefix_len = strlen( name_prefix );
/* if we have multiple object files, link them together */
if (argv[1]) name = ldcombine_files( argv );
else name = argv[0];
name = ldcombine_files( argv );
if (!nm_command) nm_command = xstrdup("nm");
cmd = xmalloc( strlen(nm_command) + strlen(name) + 5 );
......
......@@ -568,7 +568,7 @@ int main(int argc, char **argv)
BuildSpec16File( output_file, spec );
break;
case SPEC_WIN32:
read_undef_symbols( argv );
read_undef_symbols( spec, argv );
BuildSpec32File( output_file, spec );
break;
default: assert(0);
......@@ -580,7 +580,7 @@ int main(int argc, char **argv)
load_resources( argv, spec );
load_import_libs( argv );
if (spec_file_name && !parse_input_file( spec )) break;
read_undef_symbols( argv );
read_undef_symbols( spec, argv );
BuildSpec32File( output_file, spec );
break;
case MODE_DEF:
......
......@@ -65,30 +65,6 @@ static const char *make_internal_name( const ORDDEF *odp, DLLSPEC *spec, const c
return buffer;
}
/*******************************************************************
* declare_weak_function
*
* Output a prototype for a weak function.
*/
static void declare_weak_function( FILE *outfile, const char *ret_type, const char *name, const char *params)
{
fprintf( outfile, "#ifdef __GNUC__\n" );
if (target_platform == PLATFORM_APPLE)
{
fprintf( outfile, "extern %s %s(%s) __attribute__((weak_import));\n", ret_type, name, params );
fprintf( outfile, "static %s (*__wine_spec_weak_%s)(%s) = %s;\n", ret_type, name, params, name );
fprintf( outfile, "#define %s __wine_spec_weak_%s\n", name, name );
fprintf( outfile, "asm(\".weak_reference %s\");\n", asm_name(name) );
}
else fprintf( outfile, "extern %s %s(%s) __attribute__((weak));\n", ret_type, name, params );
fprintf( outfile, "#else\n" );
fprintf( outfile, "extern %s %s(%s);\n", ret_type, name, params );
fprintf( outfile, "static void __asm__dummy_%s(void)", name );
fprintf( outfile, " { asm(\".weak %s\"); }\n", asm_name(name) );
fprintf( outfile, "#endif\n\n" );
}
/*******************************************************************
* output_debug
......@@ -541,7 +517,6 @@ void BuildSpec32File( FILE *outfile, DLLSPEC *spec )
fprintf( outfile, "extern int __wine_main_argc;\n" );
fprintf( outfile, "extern char **__wine_main_argv;\n" );
fprintf( outfile, "extern char **__wine_main_environ;\n" );
fprintf( outfile, "extern unsigned short **__wine_main_wargv;\n" );
if (target_platform == PLATFORM_APPLE)
{
fprintf( outfile, "extern _dyld_func_lookup(char *, void *);" );
......@@ -568,22 +543,17 @@ void BuildSpec32File( FILE *outfile, DLLSPEC *spec )
if (spec->characteristics & IMAGE_FILE_DLL)
{
if (init_func)
if (!init_func) init_func = "DllMain";
fprintf( outfile, "extern int __stdcall %s( void*, unsigned int, void* );\n\n", init_func );
else
{
declare_weak_function( outfile, "int __stdcall", "DllMain", "void*, unsigned int, void*" );
init_func = "DllMain";
}
fprintf( outfile,
"static int __stdcall __wine_dll_main( void *inst, unsigned int reason, void *reserved )\n"
"{\n"
" int ret;\n"
" if (reason == %d && __wine_spec_init_state == 1)\n"
" _init( __wine_main_argc, __wine_main_argv, __wine_main_environ );\n"
" ret = %s ? %s( inst, reason, reserved ) : 1;\n"
" ret = %s( inst, reason, reserved );\n"
" if (reason == %d && __wine_spec_init_state == 1)\n",
DLL_PROCESS_ATTACH, init_func, init_func, DLL_PROCESS_DETACH );
DLL_PROCESS_ATTACH, init_func, DLL_PROCESS_DETACH );
if (!nr_delayed)
fprintf( outfile, " _fini();\n" );
else
......@@ -601,85 +571,54 @@ void BuildSpec32File( FILE *outfile, DLLSPEC *spec )
else switch(spec->subsystem)
{
case IMAGE_SUBSYSTEM_NATIVE:
if (init_func)
if (!init_func) init_func = "DriverEntry";
fprintf( outfile, "extern int __stdcall %s( void*, void* );\n\n", init_func );
else
{
declare_weak_function( outfile, "int __stdcall", "DriverEntry", "void*, void*");
init_func = "DriverEntry";
}
fprintf( outfile,
"static int __stdcall __wine_driver_entry( void *obj, void *path )\n"
"{\n"
" int ret;\n"
" if (__wine_spec_init_state == 1)\n"
" _init( __wine_main_argc, __wine_main_argv, __wine_main_environ );\n"
" ret = %s ? %s( obj, path ) : 0;\n"
" ret = %s( obj, path );\n"
" if (__wine_spec_init_state == 1) _fini();\n"
" return ret;\n"
"}\n",
init_func, init_func );
init_func );
init_func = "__wine_driver_entry";
break;
case IMAGE_SUBSYSTEM_WINDOWS_GUI:
case IMAGE_SUBSYSTEM_WINDOWS_CUI:
if (init_func)
fprintf( outfile, "extern int %s( int argc, char *argv[] );\n", init_func );
else
if (!init_func) init_func = "main";
else if (!strcmp( init_func, "wmain" )) /* FIXME: temp hack for crt0 support */
{
declare_weak_function( outfile, "int", "main", "int argc, char *argv[]" );
declare_weak_function( outfile, "int", "wmain", "int argc, unsigned short *argv[]" );
declare_weak_function( outfile, "int __stdcall", "WinMain", "void *,void *,char *,int" );
fprintf( outfile, "extern int wmain( int argc, unsigned short *argv[] );\n" );
fprintf( outfile, "extern unsigned short **__wine_main_wargv;\n" );
fprintf( outfile,
"\nextern void __stdcall ExitProcess(unsigned int);\n"
"static void __wine_exe_wmain(void)\n"
"{\n"
" int ret;\n"
" if (__wine_spec_init_state == 1)\n"
" _init( __wine_main_argc, __wine_main_argv, __wine_main_environ );\n"
" ret = wmain( __wine_main_argc, __wine_main_wargv );\n"
" if (__wine_spec_init_state == 1) _fini();\n"
" ExitProcess( ret );\n"
"}\n\n" );
init_func = "__wine_exe_wmain";
break;
}
fprintf( outfile, "extern int %s( int argc, char *argv[] );\n", init_func );
fprintf( outfile,
"\ntypedef struct {\n"
" unsigned int cb;\n"
" char *lpReserved, *lpDesktop, *lpTitle;\n"
" unsigned int dwX, dwY, dwXSize, dwYSize;\n"
" unsigned int dwXCountChars, dwYCountChars, dwFillAttribute, dwFlags;\n"
" unsigned short wShowWindow, cbReserved2;\n"
" char *lpReserved2;\n"
" void *hStdInput, *hStdOutput, *hStdError;\n"
"} STARTUPINFOA;\n"
"extern char * __stdcall GetCommandLineA(void);\n"
"extern void * __stdcall GetModuleHandleA(char *);\n"
"extern void __stdcall GetStartupInfoA(STARTUPINFOA *);\n"
"extern void __stdcall ExitProcess(unsigned int);\n"
"\nextern void __stdcall ExitProcess(unsigned int);\n"
"static void __wine_exe_main(void)\n"
"{\n"
" int ret;\n"
" if (__wine_spec_init_state == 1)\n"
" _init( __wine_main_argc, __wine_main_argv, __wine_main_environ );\n" );
if (init_func)
fprintf( outfile,
" ret = %s( __wine_main_argc, __wine_main_argv );\n", init_func );
else
fprintf( outfile,
" if (WinMain) {\n"
" STARTUPINFOA info;\n"
" char *cmdline = GetCommandLineA();\n"
" int bcount=0, in_quotes=0;\n"
" while (*cmdline) {\n"
" if ((*cmdline=='\\t' || *cmdline==' ') && !in_quotes) break;\n"
" else if (*cmdline=='\\\\') bcount++;\n"
" else if (*cmdline=='\\\"') {\n"
" if ((bcount & 1)==0) in_quotes=!in_quotes;\n"
" bcount=0;\n"
" }\n"
" else bcount=0;\n"
" cmdline++;\n"
" }\n"
" while (*cmdline=='\\t' || *cmdline==' ') cmdline++;\n"
" GetStartupInfoA( &info );\n"
" if (!(info.dwFlags & 1)) info.wShowWindow = 1;\n"
" ret = WinMain( GetModuleHandleA(0), 0, cmdline, info.wShowWindow );\n"
" }\n"
" else if (wmain) ret = wmain( __wine_main_argc, __wine_main_wargv );\n"
" else ret = main( __wine_main_argc, __wine_main_argv );\n" );
fprintf( outfile,
" _init( __wine_main_argc, __wine_main_argv, __wine_main_environ );\n"
" ret = %s( __wine_main_argc, __wine_main_argv );\n"
" if (__wine_spec_init_state == 1) _fini();\n"
" ExitProcess( ret );\n"
"}\n\n" );
"}\n\n", init_func );
init_func = "__wine_exe_main";
break;
}
......
......@@ -149,6 +149,7 @@ struct options
int use_msvcrt;
int nostdinc;
int nostdlib;
int nostartfiles;
int nodefaultlibs;
int noshortwchar;
int gui_app;
......@@ -528,6 +529,14 @@ static void build(struct options* opts)
strarray_add(files, "-dkernel32");
}
if (!opts->nostartfiles)
{
char *fullname = NULL;
if (get_lib_type(lib_dirs, "winecrt0", &fullname) == file_arh)
strarray_add(files, strmake("-a%s", fullname));
free( fullname );
}
/* run winebuild to generate the .spec.c file */
spec_args = strarray_alloc();
spec_c_name = get_temp_file(output_name, ".spec.c");
......@@ -888,6 +897,8 @@ int main(int argc, char **argv)
opts.nodefaultlibs = 1;
else if (strcmp("-nostdlib", argv[i]) == 0)
opts.nostdlib = 1;
else if (strcmp("-nostartfiles", argv[i]) == 0)
opts.nostartfiles = 1;
break;
case 'o':
opts.output_name = option_arg;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment