Skip to content

Commit

Permalink
crt: Use a constructor to process the pseudo relocations
Browse files Browse the repository at this point in the history
This avoids linking in the whole pseudo relocation subsystem if
the module doesn't contain any pseudo relocations.

(GNU ld adds a relocation to pull in _pei386_runtime_relocator if
the binary contains pseudo relocations, but unfortunately it doesn't
work properly, so if the _pei386_runtime_relocator symbol isn't already
pulled in by some other object file, it will fail.)
  • Loading branch information
mstorsjo committed Oct 16, 2020
1 parent d4ac895 commit 6409a8d
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 4 deletions.
2 changes: 0 additions & 2 deletions mingw-w64-crt/crt/crtdll.c
Expand Up @@ -38,7 +38,6 @@

extern void __cdecl _initterm(_PVFV *,_PVFV *);
extern void __main ();
extern void _pei386_runtime_relocator (void);
extern _CRTALLOC(".CRT$XIA") _PIFV __xi_a[];
extern _CRTALLOC(".CRT$XIZ") _PIFV __xi_z[];
extern _CRTALLOC(".CRT$XCA") _PVFV __xc_a[];
Expand Down Expand Up @@ -176,7 +175,6 @@ __DllMainCRTStartup (HANDLE hDllHandle, DWORD dwReason, LPVOID lpreserved)
retcode = FALSE;
goto i__leave;
}
_pei386_runtime_relocator ();
if (dwReason == DLL_PROCESS_ATTACH || dwReason == DLL_THREAD_ATTACH)
{
retcode = _CRT_INIT (hDllHandle, dwReason, lpreserved);
Expand Down
2 changes: 0 additions & 2 deletions mingw-w64-crt/crt/crtexe.c
Expand Up @@ -99,7 +99,6 @@ static int has_cctor = 0;
static _startupinfo startinfo;
extern LPTOP_LEVEL_EXCEPTION_FILTER __mingw_oldexcpt_handler;

extern void _pei386_runtime_relocator (void);
long CALLBACK _gnu_exception_handler (EXCEPTION_POINTERS * exception_data);
#ifdef WPRFLAG
static void duplicate_ppstrings (int ac, wchar_t ***av);
Expand Down Expand Up @@ -278,7 +277,6 @@ __tmainCRTStartup (void)
if (__dyn_tls_init_callback != NULL)
__dyn_tls_init_callback (NULL, DLL_THREAD_ATTACH, NULL);

_pei386_runtime_relocator ();
__mingw_oldexcpt_handler = SetUnhandledExceptionFilter (_gnu_exception_handler);
#if defined(__x86_64__) && !defined(__SEH__)
__mingw_init_ehandler ();
Expand Down
4 changes: 4 additions & 0 deletions mingw-w64-crt/crt/pseudo-reloc.c
Expand Up @@ -21,6 +21,8 @@
#include <stdarg.h>
#include <memory.h>
#include <internal.h>
#include <sect_attribs.h>
#include <corecrt_startup.h>

#if defined(__CYGWIN__)
#include <wchar.h>
Expand Down Expand Up @@ -485,3 +487,5 @@ _pei386_runtime_relocator (void)
restore_modified_sections ();
#endif /* __MINGW64_VERSION_MAJOR */
}

_CRTALLOC(".CRT$XIP") _PVFV __xi_p = _pei386_runtime_relocator;

0 comments on commit 6409a8d

Please sign in to comment.