On Nov 26 10:16, Jeremy Drake via Cygwin-patches wrote: > On Tue, 26 Nov 2024, Corinna Vinschen wrote: > > > On Nov 25 11:21, Jeremy Drake via Cygwin-patches wrote: > > > +extern const IMAGE_DOS_HEADER > > > +dosheader __asm__ ("__image_base__"); > > > > On second thought, shouldn't we just use GetModuleHandle ("cygwin1.dll") > > instead of going asm here? > > I was hoping to avoid another place where MSYS2 would have to patch the > name change to msys-2.0.dll. I almost went with GetModuleHandleEx > (GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS|GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT) > but the overhead of either call seemed silly when the linker already knows > the address...
Got it. > If the __asm__ setting the symbol name is an issue, pseudo-reloc.cc also > accesses __image_base__ like so: > #ifndef __MINGW_LSYMBOL > #define __MINGW_LSYMBOL(sym) sym > #endif > > extern char __MINGW_LSYMBOL(_image_base__); > > &__MINGW_LSYMBOL(_image_base__) > > I found the __asm__ method cleaner. But I could name the extern > __MINGW_LSYMBOL(_image_base__) instead of dosheader to avoid __asm__. No, that's not necessary. Actually, this code is only used in the non-Cygwin (Mingw-w64) case. For Cygwin, it refers to per_process::image_base, which is the image base of the executable, not the image base of the Cygwin DLL. But you don't really need the asm. Just define extern const IMAGE_DOS_HEADER __image_base__ and use it in the expression extracting FileHeader.Machine. Another point: Theoretically we want wincap to contain static data, which will get inherited by child processes. So, would you mind to add a member cygwin_mach and change cygwin_machine() to an inline function just returning cygwin_mach? Thanks, Corinna