diff options
author | Danny Smith <dannysmith@users.sourceforge.net> | 2003-01-01 13:00:39 +0300 |
---|---|---|
committer | Danny Smith <dannysmith@users.sourceforge.net> | 2003-01-01 13:00:39 +0300 |
commit | 353549d7441a2a8fddb4467ee796445e9db30abc (patch) | |
tree | 4c2254b36f5ec6fc0e890f471027fc0be694d6be /winsup/mingw | |
parent | 4f66b246ba438eae815dc0e8ec0887f064b09aab (diff) |
2003-01-01 Danny Smith <dannysmith@users.sourceforge.net>
* 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 <deo@logos-m.ru>
* pseudo-reloc.c: New file.
Diffstat (limited to 'winsup/mingw')
-rw-r--r-- | winsup/mingw/ChangeLog | 15 | ||||
-rw-r--r-- | winsup/mingw/Makefile.in | 7 | ||||
-rw-r--r-- | winsup/mingw/crt1.c | 7 | ||||
-rw-r--r-- | winsup/mingw/dllcrt1.c | 13 | ||||
-rw-r--r-- | winsup/mingw/pseudo-reloc-list.c | 3 | ||||
-rw-r--r-- | winsup/mingw/pseudo-reloc.c | 46 |
6 files changed, 85 insertions, 6 deletions
diff --git a/winsup/mingw/ChangeLog b/winsup/mingw/ChangeLog index 085b18f54..d88f6b245 100644 --- a/winsup/mingw/ChangeLog +++ b/winsup/mingw/ChangeLog @@ -1,3 +1,18 @@ +2003-01-01 Danny Smith <dannysmith@users.sourceforge.net> + + * 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 <deo@logos-m.ru> + + * pseudo-reloc.c: New file. + 2002-12-20 Earnie Boyd <earnie@users.sf.net> * include/_mingw.h: Increment version to 2.4. diff --git a/winsup/mingw/Makefile.in b/winsup/mingw/Makefile.in index 6b1fe8e8b..7b6bf6512 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 ef4623f51..e589b4c14 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 fe351eb10..4538cf793 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 000000000..87a2be247 --- /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 000000000..9fe607d2c --- /dev/null +++ b/winsup/mingw/pseudo-reloc.c @@ -0,0 +1,46 @@ +/* pseudo-reloc.c + + Written by Egor Duda <deo@logos-m.ru> + 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 <windows.h> + +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__); +} |