On Sat., 19 Nov 2022 11:54 Pali Rohár <[email protected]> wrote: > On Saturday 19 November 2022 17:12:12 LIU Hao wrote: > > 在 2022-11-18 23:40, Pali Rohár 写道: > > > 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. > > > --- > > > > Generally speaking, one shouldn't use weak symbols when targeting > Windows. I > > haven't investigated though, but many times weak symbols result in null > or > > faulty addresses. > > Interesting, I did not know that there are issues with weak symbols. All > my tests with weak symbols passed, I have not spotted any issue. > > They were/are problematic mostly when using GCC+ld.bfd and putting weak symbols inside DLL to later use it from other DLL or executable. There have been multiple patches over the years that improve this situation but IIRC using them inside static libraries is mostly fine with newer Binutils. Still requiring Binutils with working weak symbols would in fact drop support for more versions than just hardcoding 2.19. One of the serious issues was fixed just in Binutils 2.35. Interestingly most of these issues do not apply with GCC+LLD or Clang+ld.bfd and I think none apply to Clang+LLD.
> > Thus, weak symbols are unacceptable; but removal of references to > > `__image_base__` seems fine, if dropping support for binutils 2.18 is > > acceptable. BTW 2.19 was released in 2008 [1]. > > > > [1] https://lists.gnu.org/archive/html/info-gnu/2008-10/msg00014.html > > Another option is to detect at ./configure time if linker accepts > __ImageBase symbol. And if not then define __ImageBase as normal > (non-weak) symbol. Should be pretty simple. > > > _______________________________________________ > Mingw-w64-public mailing list > [email protected] > https://lists.sourceforge.net/lists/listinfo/mingw-w64-public > _______________________________________________ Mingw-w64-public mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/mingw-w64-public
