GNU LD provides __ImageBase symbol since 2.19. This is standard windows
symbol and should be used instead of custom gnu _image_base__ symbol.
For compatibility with older GNU LD versions, define __ImageBase as weak
alias to _image_base__ symbol.
This allows to remove all #ifdef hacks for older GNU LD versions as with
this change __ImageBase works correctly with all GNU LD versions.
---
mingw-w64-crt/Makefile.am | 2 +-
mingw-w64-crt/crt/__imagebase.c | 17 +++++++++++++++++
mingw-w64-crt/crt/crtexe.c | 5 -----
mingw-w64-crt/crt/crtexewin.c | 3 ---
mingw-w64-crt/crt/pesect.c | 9 ---------
mingw-w64-crt/crt/pseudo-reloc.c | 6 +-----
mingw-w64-crt/libsrc/dloadhelper.c | 1 -
mingw-w64-crt/misc/delayimp.c | 1 -
8 files changed, 19 insertions(+), 25 deletions(-)
create mode 100644 mingw-w64-crt/crt/__imagebase.c
diff --git a/mingw-w64-crt/Makefile.am b/mingw-w64-crt/Makefile.am
index 2056b344dd3e..9a12d408d5f7 100644
--- a/mingw-w64-crt/Makefile.am
+++ b/mingw-w64-crt/Makefile.am
@@ -122,7 +122,7 @@ src_libmingw32=include/oscalls.h include/internal.h
include/sect_attribs.h \
crt/crtexewin.c crt/dll_argv.c crt/gccmain.c crt/natstart.c
crt/pseudo-reloc-list.c crt/wildcard.c \
crt/charmax.c crt/ucrtexewin.c crt/dllargv.c crt/_newmode.c
crt/tlssup.c crt/xncommod.c \
crt/cinitexe.c crt/merr.c crt/pesect.c crt/udllargc.c
crt/xthdloc.c crt/CRT_fp10.c \
- crt/mingw_custom.c crt/mingw_helpers.c \
+ crt/mingw_custom.c crt/mingw_helpers.c crt/__imagebase.c \
crt/pseudo-reloc.c crt/udll_argv.c \
crt/usermatherr.c \
crt/xtxtmode.c crt/crt_handler.c \
diff --git a/mingw-w64-crt/crt/__imagebase.c b/mingw-w64-crt/crt/__imagebase.c
new file mode 100644
index 000000000000..82504f3c3f26
--- /dev/null
+++ b/mingw-w64-crt/crt/__imagebase.c
@@ -0,0 +1,17 @@
+/**
+ * This file has no copyright assigned and is placed in the Public Domain.
+ * This file is part of the mingw-w64 runtime package.
+ * No warranty is given; refer to the file DISCLAIMER.PD within this package.
+ */
+#include <_mingw_mac.h>
+
+/* GNU LD provides __ImageBase symbol since 2.19. In previous versions this
symbol is named
+ * _image_base__ and it is still available. For compatibility with older GNU
LD versions define
+ * __ImageBase symbol as weak alias to _image_base__ symbol. Weak alias cause
that new GNU LD
+ * versions ignores this weak symbol. Note that gcc does not allow declaring
weak alias to external
+ * symbol, so it defined via inline assembly which allows it. */
+#define ASM_SYM(sym) __MINGW64_STRINGIFY(__MINGW_USYMBOL(sym))
+asm (
+".weak\t" ASM_SYM(__ImageBase) "\n\t"
+".set\t" ASM_SYM(__ImageBase) "," ASM_SYM(_image_base__)
+);
diff --git a/mingw-w64-crt/crt/crtexe.c b/mingw-w64-crt/crt/crtexe.c
index 99e310017eec..1656b0ee0006 100644
--- a/mingw-w64-crt/crt/crtexe.c
+++ b/mingw-w64-crt/crt/crtexe.c
@@ -35,11 +35,6 @@ extern char *** __MINGW_IMP_SYMBOL(__initenv);
#define __initenv (* __MINGW_IMP_SYMBOL(__initenv))
#endif
-/* Hack, for bug in ld. Will be removed soon. */
-#if defined(__GNUC__)
-#define __ImageBase __MINGW_LSYMBOL(_image_base__)
-#endif
-/* This symbol is defined by ld. */
extern IMAGE_DOS_HEADER __ImageBase;
extern void _fpreset (void);
diff --git a/mingw-w64-crt/crt/crtexewin.c b/mingw-w64-crt/crt/crtexewin.c
index 33ac1979e331..26179fa905bb 100644
--- a/mingw-w64-crt/crt/crtexewin.c
+++ b/mingw-w64-crt/crt/crtexewin.c
@@ -14,9 +14,6 @@
#define SPACECHAR _T(' ')
#define DQUOTECHAR _T('\"')
-#if defined(__GNUC__)
-#define __ImageBase __MINGW_LSYMBOL(_image_base__)
-#endif
extern IMAGE_DOS_HEADER __ImageBase;
int _tmain (int, _TCHAR **, _TCHAR **);
diff --git a/mingw-w64-crt/crt/pesect.c b/mingw-w64-crt/crt/pesect.c
index 28c34f8caddb..b7f0b181097e 100644
--- a/mingw-w64-crt/crt/pesect.c
+++ b/mingw-w64-crt/crt/pesect.c
@@ -7,16 +7,7 @@
#include <windows.h>
#include <string.h>
-#if defined (_WIN64) && defined (__ia64__)
-#error FIXME: Unsupported __ImageBase implementation.
-#else
-#ifdef __GNUC__
-/* Hack, for bug in ld. Will be removed soon. */
-#define __ImageBase __MINGW_LSYMBOL(_image_base__)
-#endif
-/* This symbol is defined by the linker. */
extern IMAGE_DOS_HEADER __ImageBase;
-#endif
WINBOOL _ValidateImageBase (PBYTE);
diff --git a/mingw-w64-crt/crt/pseudo-reloc.c b/mingw-w64-crt/crt/pseudo-reloc.c
index d4589ca66350..5a64e0d37b18 100644
--- a/mingw-w64-crt/crt/pseudo-reloc.c
+++ b/mingw-w64-crt/crt/pseudo-reloc.c
@@ -48,7 +48,7 @@
extern char __RUNTIME_PSEUDO_RELOC_LIST__;
extern char __RUNTIME_PSEUDO_RELOC_LIST_END__;
-extern IMAGE_DOS_HEADER __MINGW_LSYMBOL(_image_base__);
+extern IMAGE_DOS_HEADER __ImageBase;
void _pei386_runtime_relocator (void);
@@ -499,11 +499,7 @@ _pei386_runtime_relocator (void)
do_pseudo_reloc (&__RUNTIME_PSEUDO_RELOC_LIST__,
&__RUNTIME_PSEUDO_RELOC_LIST_END__,
-#ifdef __GNUC__
- &__MINGW_LSYMBOL(_image_base__)
-#else
&__ImageBase
-#endif
);
#ifdef __MINGW64_VERSION_MAJOR
restore_modified_sections ();
diff --git a/mingw-w64-crt/libsrc/dloadhelper.c
b/mingw-w64-crt/libsrc/dloadhelper.c
index ce3a57914b92..85c1a1130157 100644
--- a/mingw-w64-crt/libsrc/dloadhelper.c
+++ b/mingw-w64-crt/libsrc/dloadhelper.c
@@ -15,7 +15,6 @@
*/
typedef DWORD NTSTATUS;
-#define __ImageBase __MINGW_LSYMBOL(_image_base__)
extern IMAGE_DOS_HEADER __ImageBase;
/* this typedef is missing from the Windows SDK header, but is present in
diff --git a/mingw-w64-crt/misc/delayimp.c b/mingw-w64-crt/misc/delayimp.c
index 26afde8079ae..ca4b51ad161d 100644
--- a/mingw-w64-crt/misc/delayimp.c
+++ b/mingw-w64-crt/misc/delayimp.c
@@ -47,7 +47,6 @@ static unsigned IndexFromPImgThunkData(PCImgThunkData
pitdCur,PCImgThunkData pit
return (unsigned) (pitdCur - pitdBase);
}
-#define __ImageBase __MINGW_LSYMBOL(_image_base__)
extern IMAGE_DOS_HEADER __ImageBase;
#define PtrFromRVA(RVA) (((PBYTE)&__ImageBase) + (RVA))
--
2.20.1
_______________________________________________
Mingw-w64-public mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/mingw-w64-public