From 353549d7441a2a8fddb4467ee796445e9db30abc Mon Sep 17 00:00:00 2001 From: Danny Smith Date: Wed, 1 Jan 2003 10:00:39 +0000 Subject: 2003-01-01 Danny Smith * pseudo-reloc.c (do_pseudo_reloc): Make static. * pseudo-reloc-list.c: New file. * crt1.c (_pei386_runtime_relocator): Declare. (__mingw_CRTStartup): Call it. * dllcrt1.c (_pei386_runtime_relocator): Declare. (DllMainCRTStartup): Call it. * Makefile.in: Add pseudo-reloc.o pseude-reloc-list.o to libmingw32.a. 2003-01-01 Egor Duda * pseudo-reloc.c: New file. --- winsup/mingw/ChangeLog | 15 +++++++++++++ winsup/mingw/Makefile.in | 7 ++++-- winsup/mingw/crt1.c | 7 ++++++ winsup/mingw/dllcrt1.c | 13 ++++++++---- winsup/mingw/pseudo-reloc-list.c | 3 +++ winsup/mingw/pseudo-reloc.c | 46 ++++++++++++++++++++++++++++++++++++++++ 6 files changed, 85 insertions(+), 6 deletions(-) create mode 100644 winsup/mingw/pseudo-reloc-list.c create mode 100644 winsup/mingw/pseudo-reloc.c diff --git a/winsup/mingw/ChangeLog b/winsup/mingw/ChangeLog index 085b18f..d88f6b2 100644 --- a/winsup/mingw/ChangeLog +++ b/winsup/mingw/ChangeLog @@ -1,3 +1,18 @@ +2003-01-01 Danny Smith + + * pseudo-reloc.c (do_pseudo_reloc): Make static. + * pseudo-reloc-list.c: New file. + * crt1.c (_pei386_runtime_relocator): Declare. + (__mingw_CRTStartup): Call it. + * dllcrt1.c (_pei386_runtime_relocator): Declare. + (DllMainCRTStartup): Call it. + * Makefile.in: Add pseudo-reloc.o pseude-reloc-list.o to + libmingw32.a. + +2003-01-01 Egor Duda + + * pseudo-reloc.c: New file. + 2002-12-20 Earnie Boyd * include/_mingw.h: Increment version to 2.4. diff --git a/winsup/mingw/Makefile.in b/winsup/mingw/Makefile.in index 6b1fe8e..7b6bf65 100644 --- a/winsup/mingw/Makefile.in +++ b/winsup/mingw/Makefile.in @@ -150,7 +150,8 @@ FLAGS_TO_PASS:=\ CRT0S = crt1.o dllcrt1.o crt2.o dllcrt2.o CRT_noglob.o crtmt.o crtst.o \ CRT_fp8.o CRT_fp10.o txtmode.o binmode.o MINGW_OBJS = CRTglob.o CRTfmode.o CRTinit.o dllmain.o gccmain.o \ - main.o crtst.o mthr_stub.o CRT_fp10.o txtmode.o + main.o crtst.o mthr_stub.o CRT_fp10.o txtmode.o \ + pseudo-reloc.o pseudo-reloc-list.o MOLD_OBJS = ctype_old.o string_old.o LIBS = libcrtdll.a libmsvcrt.a libmsvcrt20.a libmsvcrt40.a libmingw32.a \ @@ -164,7 +165,9 @@ crt1.c crtdll.def crtmt.c crtst.c ctype_old.c dllcrt1.c dllmain.c \ gccmain.c init.c install-sh jamfile main.c mkinstalldirs moldname-crtdll.def \ moldname-msvcrt.def moldname.def moldname.def.in msvcrt.def msvcrt20.def \ msvcrt40.def mthr.c mthr_init.c mthr_stub.c readme.txt string_old.c \ -CRT_fp8.c CRT_fp10.c test_headers.c txtmode.c binmode.c +CRT_fp8.c CRT_fp10.c test_headers.c txtmode.c binmode.c pseudo-reloc.c \ +pseudo-reloc-list.c + all_dlls_host = @all_dlls_host@ install_dlls_host = @install_dlls_host@ diff --git a/winsup/mingw/crt1.c b/winsup/mingw/crt1.c index ef4623f..e589b4c 100644 --- a/winsup/mingw/crt1.c +++ b/winsup/mingw/crt1.c @@ -47,6 +47,9 @@ * a-good-idea use of include. */ #include "init.c" + +extern void _pei386_runtime_relocator (void); + extern int main (int, char **, char **); /* @@ -203,6 +206,10 @@ __mingw_CRTStartup () */ _mingw32_init_fmode (); + + /* Adust references to dllimported data that have non-zero offsets. */ + _pei386_runtime_relocator (); + /* * Call the main function. If the user does not supply one * the one in the 'libmingw32.a' library will be linked in, and diff --git a/winsup/mingw/dllcrt1.c b/winsup/mingw/dllcrt1.c index fe351eb..4538cf7 100644 --- a/winsup/mingw/dllcrt1.c +++ b/winsup/mingw/dllcrt1.c @@ -54,6 +54,7 @@ p_atexit_fn __dllonexit (p_atexit_fn, p_atexit_fn**, p_atexit_fn**); extern BOOL WINAPI DllMain (HANDLE, DWORD, LPVOID); +extern void _pei386_runtime_relocator (void); BOOL WINAPI DllMainCRTStartup (HANDLE hDll, DWORD dwReason, LPVOID lpReserved) @@ -62,6 +63,11 @@ DllMainCRTStartup (HANDLE hDll, DWORD dwReason, LPVOID lpReserved) if (dwReason == DLL_PROCESS_ATTACH) { + +#ifdef DEBUG + printf ("%s: DLL_PROCESS_ATTACH (%d)\n", __FUNCTION__); +#endif + /* Initialize private atexit table for this dll. 32 is min size required by ANSI */ @@ -74,11 +80,10 @@ DllMainCRTStartup (HANDLE hDll, DWORD dwReason, LPVOID lpReserved) *first_atexit = NULL; next_atexit = first_atexit; -#ifdef DEBUG - printf ("%s: DLL_PROCESS_ATTACH (%d)\n", __FUNCTION__); -#endif + /* Adust references to dllimported data (from other DLL's) + that have non-zero offsets. */ + _pei386_runtime_relocator (); - #ifdef __GNUC__ /* From libgcc.a, __main calls global class constructors, __do_global_ctors, which registers __do_global_dtors diff --git a/winsup/mingw/pseudo-reloc-list.c b/winsup/mingw/pseudo-reloc-list.c new file mode 100644 index 0000000..87a2be2 --- /dev/null +++ b/winsup/mingw/pseudo-reloc-list.c @@ -0,0 +1,3 @@ +/* Define here in .bss in case not defined by linker script. */ +char __RUNTIME_PSEUDO_RELOC_LIST_END__ = 0; +char __RUNTIME_PSEUDO_RELOC_LIST__ = 0; diff --git a/winsup/mingw/pseudo-reloc.c b/winsup/mingw/pseudo-reloc.c new file mode 100644 index 0000000..9fe607d --- /dev/null +++ b/winsup/mingw/pseudo-reloc.c @@ -0,0 +1,46 @@ +/* pseudo-reloc.c + + Written by Egor Duda + THIS SOFTWARE IS NOT COPYRIGHTED + + This source code is offered for use in the public domain. You may + use, modify or distribute it freely. + + This code is distributed in the hope that it will be useful but + WITHOUT ANY WARRANTY. ALL WARRENTIES, EXPRESS OR IMPLIED ARE HEREBY + DISCLAMED. This includes but is not limited to warrenties of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +*/ + +#include + +extern char __RUNTIME_PSEUDO_RELOC_LIST__; +extern char __RUNTIME_PSEUDO_RELOC_LIST_END__; +extern char _image_base__; + +typedef struct + { + DWORD addend; + DWORD target; + } +runtime_pseudo_reloc; + +static void +do_pseudo_reloc (void* start, void* end, void* base) +{ + DWORD reloc_target; + runtime_pseudo_reloc* r; + for (r = (runtime_pseudo_reloc*) start; r < (runtime_pseudo_reloc*) end; r++) + { + reloc_target = (DWORD) base + r->target; + *((DWORD*) reloc_target) += r->addend; + } +} + +void +_pei386_runtime_relocator () +{ + do_pseudo_reloc (&__RUNTIME_PSEUDO_RELOC_LIST__, + &__RUNTIME_PSEUDO_RELOC_LIST_END__, + &_image_base__); +} -- cgit v1.1