From: Danny S. <dan...@cl...> - 2003-07-18 03:42:31
Attachments:
crt_malloc.diff
|
----- Original Message ----- From: "Earnie Boyd" <ear...@ya...> To: "Danny Smith" <dan...@ya...> Sent: Thursday, 17 July 2003 12:06 Subject: Re: __USE_CRTIMP in mingw runtime startup code. > Danny Smith wrote: > > > > The problem with using LoadLibrary/GetProcAddress to fix the problem is that > > we don't know which msvcrt library the user wants. > > > > Read the bfd headers to find it? > > Earnie. Hi, This is a follw-up on correspondence with Earnie about problem with user-defined malloc. __dllonexit always uses the dll malloc if it need to realloc the atexit table. Thus the dlcrt1.c startup code needs to use the same malloc. Attached is one way to prevent user defined free/malloc from being used in CRT startup code. Marking with __CRTIMP also works but causes problems with multiple definitions. The one drawback I see in the approach in attached patch is that __msvrct_dll_string will be exported from user dll if either explicit or implicit --export-all is used. That can be fixed with a trivial patch to ld. But, maybe exporting mscvrt version strings is actually useful, for checking whether different dll's depend on different mscvrt versions. |
From: Earnie B. <ear...@ya...> - 2003-07-18 11:16:10
|
Danny Smith wrote: > > ------------------------------------------------------------------------ > > ChangeLog > > * dllcrt1.c (__mscvrt_dll_string): Declare extern variable. > (DllMainCRTStartup): Use GetModuleHandle/GetProcAddress to get > malloc and free from the msvcrt library designated by > __mscvrt_dll_string. > * crtdll.c: New file, defining __mscvrt_dll_string. Do you really want __mscvrt_dll_string, I'm already confused with it. Why not __msvcrt_dll_string? > * msvcrt.c: Ditto. Only one source is sufficient. Create multiple targets with that source using macro substitution. > * msvcrtd.c: Ditto. > * msvcr70.c: Ditto. > * msvcr70d.c: Ditto. > * msvcr71.c: Ditto. > * msvcr71d.c: Ditto. > Makefile.in: Compile new files. Add objects to respective import > libs. > Earnie |
From: Danny S. <dan...@cl...> - 2003-07-18 19:37:16
|
----- Original Message ----- From: "Earnie Boyd" <ear...@ya...> To: <min...@li...> Sent: Friday, 18 July 2003 12:15 Subject: Re: [MinGW-dvlpr] Fw: __USE_CRTIMP in mingw runtime startup code. > Danny Smith wrote: > > > > ---------------------------------------------------------------------- -- > > > > ChangeLog > > > > * dllcrt1.c (__mscvrt_dll_string): Declare extern variable. > > (DllMainCRTStartup): Use GetModuleHandle/GetProcAddress to get > > malloc and free from the msvcrt library designated by > > __mscvrt_dll_string. > > * crtdll.c: New file, defining __mscvrt_dll_string. > > Do you really want __mscvrt_dll_string, I'm already confused with it. > Why not __msvcrt_dll_string? > A typo. __msvcrt_dll_string it is. Danny > > * msvcrt.c: Ditto. > > Only one source is sufficient. Create multiple targets with that source > using macro substitution. > > > * msvcrtd.c: Ditto. > > * msvcr70.c: Ditto. > > * msvcr70d.c: Ditto. > > * msvcr71.c: Ditto. > > * msvcr71d.c: Ditto. > > Makefile.in: Compile new files. Add objects to respective import > > libs. > > > > Earnie > > > > ------------------------------------------------------- > This SF.net email is sponsored by: VM Ware > With VMware you can run multiple operating systems on a single machine. > WITHOUT REBOOTING! Mix Linux / Windows / Novell virtual machines at the > same time. Free trial click here: http://www.vmware.com/wl/offer/345/0 > _______________________________________________ > MinGW-dvlpr mailing list > Min...@li... > https://lists.sourceforge.net/lists/listinfo/mingw-dvlpr |
From: Danny S. <dan...@cl...> - 2003-07-18 23:10:20
Attachments:
crt_malloc[2].diff
|
----- Original Message ----- From: "Earnie Boyd" <ear...@ya...> To: <min...@li...> Sent: Friday, 18 July 2003 12:15 Subject: Re: [MinGW-dvlpr] Fw: __USE_CRTIMP in mingw runtime startup code. > Danny Smith wrote: > > > > ---------------------------------------------------------------------- -- > > > > ChangeLog > > > > * dllcrt1.c (__mscvrt_dll_string): Declare extern variable. > > (DllMainCRTStartup): Use GetModuleHandle/GetProcAddress to get > > malloc and free from the msvcrt library designated by > > __mscvrt_dll_string. > > * crtdll.c: New file, defining __mscvrt_dll_string. > > Do you really want __mscvrt_dll_string, I'm already confused with it. > Why not __msvcrt_dll_string? > > > * msvcrt.c: Ditto. > > Only one source is sufficient. Create multiple targets with that source > using macro substitution. > > > * msvcrtd.c: Ditto. > > * msvcr70.c: Ditto. > > * msvcr70d.c: Ditto. > > * msvcr71.c: Ditto. > > * msvcr71d.c: Ditto. > > Makefile.in: Compile new files. Add objects to respective import > > libs. > > > > Earnie > Attached is revised patch. Danny: |
From: Earnie B. <ear...@ya...> - 2003-07-20 17:49:18
|
Go for it. Earnie. Danny Smith wrote: > ----- Original Message ----- > From: "Earnie Boyd" <ear...@ya...> > To: <min...@li...> > Sent: Friday, 18 July 2003 12:15 > Subject: Re: [MinGW-dvlpr] Fw: __USE_CRTIMP in mingw runtime startup > code. > > > >>Danny Smith wrote: >> >>---------------------------------------------------------------------- > > -- > >>>ChangeLog >>> >>>* dllcrt1.c (__mscvrt_dll_string): Declare extern variable. >>>(DllMainCRTStartup): Use GetModuleHandle/GetProcAddress to get >>>malloc and free from the msvcrt library designated by >>>__mscvrt_dll_string. >>>* crtdll.c: New file, defining __mscvrt_dll_string. >> >>Do you really want __mscvrt_dll_string, I'm already confused with it. >>Why not __msvcrt_dll_string? >> >> >>>* msvcrt.c: Ditto. >> >>Only one source is sufficient. Create multiple targets with that > > source > >>using macro substitution. >> >> >>>* msvcrtd.c: Ditto. >>>* msvcr70.c: Ditto. >>>* msvcr70d.c: Ditto. >>>* msvcr71.c: Ditto. >>>* msvcr71d.c: Ditto. >>>Makefile.in: Compile new files. Add objects to respective import >>>libs. >>> >> >>Earnie >> > > > > Attached is revised patch. > > Danny: > > > > ------------------------------------------------------------------------ > > ChangeLog > > * dllcrt1.c (__mscvrt_dll_string): Declare extern variable. > (DllMainCRTStartup): Use GetModuleHandle/GetProcAddress to get > malloc and free from the msvcrt library designated by > __msvcrt_dll_string. > * msvcrt_version.c: New file, > Makefile.in: (crtdll.o, msvcrt.o, msvcrtd.o, msvcr70.o > msvcr70d.o, msvcr71.o, msvcr71d.o): Build from msvcrt_version.c, > and add to respective import libs. > > Index: Makefile.in > =================================================================== > RCS file: /cvs/src/src/winsup/mingw/Makefile.in,v > retrieving revision 1.41 > diff -c -3 -p -r1.41 Makefile.in > *** Makefile.in 18 Jun 2003 13:54:46 -0000 1.41 > --- Makefile.in 18 Jul 2003 21:30:14 -0000 > *************** MINGW_OBJS = CRTglob.o CRTfmode.o CRTini > *** 157,162 **** > --- 157,167 ---- > MOLD_OBJS = isascii.o iscsym.o iscsymf.o toascii.o \ > strcasecmp.o strncasecmp.o wcscmpi.o > > + EXTRA_LIB_OBJS = crtdll.o \ > + msvcrt.o msvcrtd.o \ > + msvcr70.o msvcr70d.o \ > + msvcr71.o msvcr71d.o > + > LIBS = libcrtdll.a \ > libmsvcrt.a libmsvcrtd.a \ > libmsvcr70.a libmsvcr70d.a \ > *************** mthr.c mthr_init.c mthr_stub.c readme.tx > *** 178,190 **** > isascii.c iscsym.c iscsymf.c toascii.c \ > strcasecmp.c strncasecmp.c wcscmpi.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@ > > ! all: $(CRT0S) $(LIBS) $(all_dlls_host) > @$(MAKE) subdirs DO=$@ $(FLAGS_TO_PASS) > > all_dlls_host: $(DLLS) > --- 183,195 ---- > isascii.c iscsym.c iscsymf.c toascii.c \ > strcasecmp.c strncasecmp.c wcscmpi.c \ > CRT_fp8.c CRT_fp10.c test_headers.c txtmode.c binmode.c pseudo-reloc.c \ > ! pseudo-reloc-list.c msvcrt_version.c > > > all_dlls_host = @all_dlls_host@ > install_dlls_host = @install_dlls_host@ > > ! all: $(CRT0S) $(EXTRA_LIB_OBJS) $(LIBS) $(all_dlls_host) > @$(MAKE) subdirs DO=$@ $(FLAGS_TO_PASS) > > all_dlls_host: $(DLLS) > *************** msvcr71.def msvcr71d.def \ > *** 250,255 **** > --- 255,267 ---- > -D__MSVCRT__ -C -E -P \ > -xc-header $? > $@ > > + crtdll.o \ > + msvcrt.o msvcrtd.o \ > + msvcr70.o msvcr70d.o \ > + msvcr71.o msvcr71d.o \ > + : msvcrt_version.c > + $(CC) -c -DMSVCRT_VER=\"$(basename $(notdir $@)).dll\" $? -o $@ > + > moldname-crtdll.def: moldname.def.in > $(CC) -DRUNTIME=crtdll \ > -D__FILENAME__=moldname-crtdll.def \ > *************** libmoldnamed.a: moldname-msvcrt.def $(MO > *** 286,291 **** > --- 298,304 ---- > $(AR) rc $@ $(MOLD_OBJS) > $(RANLIB) $@ > > + > # The special rules are necessary. > crt1.o dllcrt1.o: > $(CC) -c -D__CRTDLL__ -U__MSVCRT__ $(ALL_CFLAGS) $< -o $@ > *************** force: > *** 426,434 **** > # > # Dependancies > # > ! libcrtdll.a: crtdll.def > ! libmsvcrt.a: msvcrt.def > ! libmsvcrtd.a: msvcrtd.def > CRT_noglob.o: CRT_noglob.c > CRTfmode.o: CRTfmode.c > CRTglob.o: CRTglob.c > --- 439,447 ---- > # > # Dependancies > # > ! libcrtdll.a: crtdll.def crtdll.o > ! libmsvcrt.a: msvcrt.def msvcrt.o > ! libmsvcrtd.a: msvcrtd.def msvcrtd.o > CRT_noglob.o: CRT_noglob.c > CRTfmode.o: CRTfmode.c > CRTglob.o: CRTglob.c > *************** config.status: configure > *** 455,460 **** > --- 468,478 ---- > $(SHELL) config.status --recheck > > .SUFFIXES: .y $(SUFFIXES) .cc .def .a > + > + lib%.a : %.def %.o > + $(DLLTOOL) --as=$(AS) -k --dllname $*.dll --output-lib lib$*.a --def $< > + $(AR) r $@ $*.o > + $(RANLIB) $@ > > lib%.a:%.def > $(DLLTOOL) --as=$(AS) -k --dllname $*.dll --output-lib lib$*.a --def $< > Index: dllcrt1.c > =================================================================== > RCS file: /cvs/src/src/winsup/mingw/dllcrt1.c,v > retrieving revision 1.3 > diff -c -3 -p -r1.3 dllcrt1.c > *** dllcrt1.c 1 Jan 2003 10:00:39 -0000 1.3 > --- dllcrt1.c 18 Jul 2003 21:30:14 -0000 > *************** extern BOOL WINAPI DllMain (HANDLE, DWOR > *** 56,65 **** > --- 56,77 ---- > > extern void _pei386_runtime_relocator (void); > > + > + /* Use GetModuleHandle/GetProcAddress to get malloc and free from > + the msvcrt library, so that we don't get clobbered by user-defined > + malloc/free. */ > + > + /* This lives as a static component of the import lib. */ > + extern const char* __msvcrt_dll_string; > + > + static HMODULE hMSVCRT; > + > + > BOOL WINAPI > DllMainCRTStartup (HANDLE hDll, DWORD dwReason, LPVOID lpReserved) > { > BOOL bRet; > + void* (* p_crt_malloc) (size_t); > > if (dwReason == DLL_PROCESS_ATTACH) > { > *************** DllMainCRTStartup (HANDLE hDll, DWORD dw > *** 68,77 **** > printf ("%s: DLL_PROCESS_ATTACH (%d)\n", __FUNCTION__); > #endif > > /* Initialize private atexit table for this dll. > 32 is min size required by ANSI */ > > ! first_atexit = (p_atexit_fn*) malloc (32 * sizeof (p_atexit_fn)); > if (first_atexit == NULL ) /* can't allocate memory */ > { > errno=ENOMEM; > --- 80,93 ---- > printf ("%s: DLL_PROCESS_ATTACH (%d)\n", __FUNCTION__); > #endif > > + hMSVCRT = GetModuleHandle (__msvcrt_dll_string); > + p_crt_malloc = > + (void* (*) (size_t)) GetProcAddress (hMSVCRT, "malloc"); > + > /* Initialize private atexit table for this dll. > 32 is min size required by ANSI */ > > ! first_atexit = (p_atexit_fn*) p_crt_malloc (32 * sizeof (p_atexit_fn)); > if (first_atexit == NULL ) /* can't allocate memory */ > { > errno=ENOMEM; > *************** __dll_exit(void) > *** 142,147 **** > --- 158,165 ---- > { > if ( first_atexit ) > { > + void (* p_crt_free) (void*) > + = (void(*)(void*)) GetProcAddress (hMSVCRT, "free"); > p_atexit_fn* __last = next_atexit - 1; > while ( __last >= first_atexit ) > { > *************** __dll_exit(void) > *** 155,161 **** > } > __last--; > } > ! free ( first_atexit ) ; > first_atexit = NULL ; > } > /* > --- 173,179 ---- > } > __last--; > } > ! p_crt_free ( first_atexit ) ; > first_atexit = NULL ; > } > /* > *************** __dll_exit(void) > *** 170,176 **** > * The atexit exported from msvcrt.dll causes problems in DLLs. > * Here, we override the exported version of atexit with one that passes the > * private table initialised in DllMainCRTStartup to __dllonexit. > ! * That means we have to hide the mscvrt.dll atexit because the > * atexit defined here gets __dllonexit from the same lib. > */ > > --- 188,194 ---- > * The atexit exported from msvcrt.dll causes problems in DLLs. > * Here, we override the exported version of atexit with one that passes the > * private table initialised in DllMainCRTStartup to __dllonexit. > ! * That means we have to hide the msvcrt.dll atexit because the > * atexit defined here gets __dllonexit from the same lib. > */ > > *** /dev/null Fri Jul 18 22:50:44 2003 > --- msvcrt_version.c Fri Jul 18 22:19:15 2003 > *************** > *** 0 **** > --- 1 ---- > + const char __msvcrt_dll_string[] = MSVCRT_VER; |
From: Danny S. <dan...@cl...> - 2003-07-20 20:54:49
|
----- Original Message ----- From: "Earnie Boyd" <ear...@ya...> To: <min...@li...> Sent: Sunday, 20 July 2003 18:48 Subject: Re: [MinGW-dvlpr] Fw: __USE_CRTIMP in mingw runtime startup code. > Go for it. > > Earnie. ====snip==== There was a thinko in my patch, dllcrt1.c. > > + > > + /* This lives as a static component of the import lib. */ > > + extern const char* __msvcrt_dll_string; > > + should be: extern const char __msvcrt_dll_string[]; Otherwise it will not work unless you are very lucky. With that correction, Duncan reports, in private correspondence, that his malloc/atexit problem is fixed. I won't apply this yet. I'm still concerned about exporting __msvcrt_dll_string (__msvcrt_dll_name might be a more meaningful name for the symbol) from every dll that is built using --export-all. Maybe it would be useful to do so (eg, to distingush a dll built with a debug malloc/free), but I think that should be left up to the user. We could add the libmsvcr* libs to the filter in ld that excludes system libs by default. Danny |
From: Earnie B. <ear...@ya...> - 2003-07-20 21:20:12
|
Danny Smith wrote: > > We could add the libmsvcr* libs to the filter in ld that excludes > system libs by default. > Yes, I think so. What about the other default libraries being excluded as well? Or perhaps they are already? Earnie. |
From: Earnie B. <ear...@ya...> - 2003-07-20 21:29:06
|
Earnie Boyd wrote: > Danny Smith wrote: > >> >> We could add the libmsvcr* libs to the filter in ld that excludes >> system libs by default. >> > > Yes, I think so. > > What about the other default libraries being excluded as well? Or > perhaps they are already? > Perhaps some globally defined specified symbol should be used to indicate exclusion? Some symbol named something like __SYSTEMLIBRARY__. Earnie. |
From: Danny S. <dan...@cl...> - 2003-07-20 22:22:35
|
----- Original Message ----- From: "Earnie Boyd" <ear...@ya...> To: <min...@li...> Sent: Sunday, 20 July 2003 22:28 Subject: Re: [MinGW-dvlpr] Fw: __USE_CRTIMP in mingw runtime startup code. > Earnie Boyd wrote: > > Danny Smith wrote: > > > >> > >> We could add the libmsvcr* libs to the filter in ld that excludes > >> system libs by default. > >> > > > > Yes, I think so. > > > > What about the other default libraries being excluded as well? Or > > perhaps they are already? > > > This is what get excluded now: /* Do not specify library suffix explicitly, to allow for dllized versions. */ static autofilter_entry_type autofilter_liblist[] = { { "libcygwin", 9 }, { "libgcc", 6 }, { "libstdc++", 9 }, { "libmingw32", 10 }, { "libmingwex", 10 }, { "libg2c", 6 }, { "libsupc++", 9 }, { "libobjc", 7 }, { "libgcj", 6 }, { NULL, 0 } }; static autofilter_entry_type autofilter_objlist[] = { { "crt0.o", 6 }, { "crt1.o", 6 }, { "crt2.o", 6 }, { "dllcrt1.o", 9 }, { "dllcrt2.o", 9 }, { "gcrt0.o", 7 }, { "gcrt1.o", 7 }, { "gcrt2.o", 7 }, { "crtbegin.o", 10 }, { "crtend.o", 8 }, { NULL, 0 } }; plus some additonal symbols specified by prefix or full name. We could just add __mscvrt_dll_name to the latter. What would be really useful would be an __attribute__((no_dllexport)), similar to the ELF __attribute__((visibility (hidden))), which tells ld that this symbol is not to be exported from shared libraries. I think it could be done just like dllexport is handled now by putting in .drective section. and having ld scan that to exclude symbols. But how would that affect object compatibility with MS linker? > Perhaps some globally defined specified symbol should be used to > indicate exclusion? Some symbol named something like __SYSTEMLIBRARY__. > > Earnie. > > > > ------------------------------------------------------- > This SF.net email is sponsored by: VM Ware > With VMware you can run multiple operating systems on a single machine. > WITHOUT REBOOTING! Mix Linux / Windows / Novell virtual machines at the > same time. Free trial click here: http://www.vmware.com/wl/offer/345/0 > _______________________________________________ > MinGW-dvlpr mailing list > Min...@li... > https://lists.sourceforge.net/lists/listinfo/mingw-dvlpr |
From: Danny S. <dan...@cl...> - 2003-07-22 01:00:46
Attachments:
crt_malloc[3].diff
|
----- Original Message ----- From: "Earnie Boyd" <ear...@ya...> To: <min...@li...> Sent: Sunday, 20 July 2003 22:28 Subject: Re: [MinGW-dvlpr] Fw: __USE_CRTIMP in mingw runtime startup code. > Earnie Boyd wrote: > > Danny Smith wrote: > > > >> > >> We could add the libmsvcr* libs to the filter in ld that excludes > >> system libs by default. > >> > > > > Yes, I think so. > > Take 3. Renaming the version string to __msvcrt_dll_iname prevents it from being exported, because symbols ending with _iname are excluded from default auto-export. I think we should add libmsvcr* to default exclude lists anyway though. Danny Danny. > _______________________________________________ > MinGW-dvlpr mailing list > Min...@li... > https://lists.sourceforge.net/lists/listinfo/mingw-dvlpr |