Hi H.J. the symbol addresses taken for __ImageBase addressing scheme are wrong. RIP relative addresses taken from the same section instead are correct. https://github.com/KilianKegel/GNU-ld-for-MicrosoftCOFF-to-LinuxELF#addr32nb-offset-miscalculation I would really appreciate if you could fix this issue. Best regards, Kilian
Created attachment 13230 [details] screenshot wrong offset calculation
Created attachment 13233 [details] A patch Try this.
Created attachment 13234 [details] An updated patch Try this instead.
Created attachment 13240 [details] ineffective bugbatch from 2021-02-18 18:23
Created attachment 13241 [details] original binutils 2.34 ld - on the right side, left side manually corrected version
Created attachment 13242 [details] original binutils 2.35 ld - on the right side, left side manually corrected version
Created attachment 13243 [details] bugfix26583 binutils 2.35 ld - on the right side, left side manually corrected version
Created attachment 13244 [details] bugfix27171 binutils 2.35 ld - on the right side, left side manually corrected version
Created attachment 13245 [details] original binutils 2.36.1 ld - on the right side, left side manually corrected version
Created attachment 13246 [details] bugfix27432 binutils 2.36.1 ld - on the right side, left side manually corrected version
Hi H.J. regrettably, your fix does not help at all. I have uploaded the diff views "ineffective bugbatch from 2021-02-18 18:23" as a ZIP archive if you want to review. But I have found, that in the "original binutils" 2.34 and 2.35 the *displacement* *part* only at offset 0x40103D and 0x401052 is still correct. It got broken beginning with bugfix 26583. I have transferred all changes to the git repository here: https://github.com/KilianKegel/binutils-for-Torito-C-Library.git 0. 235_original_commit_4c74dde9cd52dcedd94b7717b9a829ccf089ce2b 1. 235_bugfix26583_commit_6d23bd49be04c9821ddaff55fc2e8e8409d47750 2. 235_bugfix27171_commit_12b0a802d32d26ce403eba0a4fd808bf65c45257 3. 2361_original_commit_93cead0542c1597dcacc94c60f3716d0171901b0 4. 2361_bugfix27432_commit_aec381629adecb0e2712764142c80ad498b844b4 Thanks, Kilian
Created attachment 13248 [details] A new patch Please try this.
Created attachment 13254 [details] 2361_bugfix_from_2021-02-22_1335UTC.png Hi H.J. your fix works. Please find the appended screenshot. I have not yet tested comprehensively against the previous fixes, but at the first glance: One more perfect solution from you. Thanks a lot, Kilian
The master branch has been updated by H.J. Lu <hjl@sourceware.org>: https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=8c0546e928b557f10cb5aba2a91f3ecee660029d commit 8c0546e928b557f10cb5aba2a91f3ecee660029d Author: H.J. Lu <hjl.tools@gmail.com> Date: Fri Mar 5 18:24:56 2021 -0800 elf/x86-64: Subtract __ImageBase for R_AMD64_IMAGEBASE When linking Windows x86-64 relocatable object files to generate x86-64 ELF executable, we need to subtract __ImageBase, aka __executable_start, for R_AMD64_IMAGEBASE relocation: 1. Add link_info to struct output_elf_obj_tdata to store linker info and _bfd_get_link_info() to retrieve it. 2. Add ldelf_set_output_arch to set up link_info. 3. Add pex64_link_add_symbols to create an indirect reference to __executable_start for __ImageBase to support R_AMD64_IMAGEBASE relocation when adding symbols from Windows x86-64 relocatable object files to generate x86-64 ELF executable. 4. Also subtract __ImageBase for R_AMD64_IMAGEBASE when generating x86-64 ELF executable. bfd/ PR ld/27425 PR ld/27432 * bfd.c (_bfd_get_link_info): New function. * elf-bfd.h (output_elf_obj_tdata): Add link_info. (elf_link_info): New. * libbfd-in.h (_bfd_get_link_info): New prototype. * coff-x86_64.c (coff_amd64_reloc): Also subtract __ImageBase for R_AMD64_IMAGEBASE when generating x86-64 ELF executable. * pe-x86_64.c: Include "coff/internal.h" and "libcoff.h". (pex64_link_add_symbols): New function. (coff_bfd_link_add_symbols): New macro. * libbfd.h: Regenerated. ld/ PR ld/27425 PR ld/27432 * ldelf.c (ldelf_set_output_arch): New function. * ldelf.h (ldelf_set_output_arch): New prototype. * emultempl/elf.em (LDEMUL_SET_OUTPUT_ARCH): Default to ldelf_set_output_arch. * ld-x86-64/pe-x86-64-1.od: Expect __executable_start. * testsuite/ld-x86-64/pe-x86-64-2.od: Likewise. * testsuite/ld-x86-64/pe-x86-64-3.od: Likewise. * testsuite/ld-x86-64/pe-x86-64-4.od: Likewise. * testsuite/ld-x86-64/pe-x86-64-5.od: Likewise. * testsuite/ld-x86-64/pe-x86-64-5.rd: Likewise. * testsuite/ld-x86-64/pe-x86-64-6.obj.bz2: New file. * testsuite/ld-x86-64/pe-x86-64-6.od: Likewise. * testsuite/ld-x86-64/pe-x86-64.exp: Run ld/27425 test.
Fixed for 2.37.