<html>
  <head>
    <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  </head>
  <body>
<div dir="auto">Thanks very much. I have been trying for weeks to figure out what's wrong with some seemingly innocent real-mode code, but didn't have a clue. To make bad worse, after upgrade to Fedora 41, it failed to link. Your fix reminds me something I had overlooked. Now I think I got a little understanding of the problem.<br></div><div dir="auto"><br></div><div dir="auto">UEFI boot loader will make sure BSP is in long mode, before hand off to a kernel. However, 16-bit code is still required, because all AP processors are still in real mode.<br></div><div dir="auto"><br></div><div dir="auto">x86_64 gcc emit elf32, with -m16 flag, despite it is a 64-bit compiler. Thus, we have to objcopy -I elf32-i386 -O elf64-x86-64 to convert it to elf64.<br></div><div dir="auto"><br></div><div dir="auto">I don't think x86_64 ELF spec have ever mentioned REL. As <span class=""><span class="">Stephen Checkoway suggested in </span></span>binutils bug 23261,  it would be better if objcopy convert REL to RELA. Nevertheless according to him, once upon a time, REL did work with ld.bfd.<br></div><div dir="auto"><br></div><div dir="auto">Unfortuanately, REL relocations are broken with ld.bfd, maybe since commit 17c6c3b. I tried ld.lld, now it does respect implicit addend.<br></div><div dir="auto"><br></div><div dir="auto">Dec 17, 2024, 18:59 by jbeulich@suse.com:<br></div><blockquote class="tutanota_quote" style="border-left: 1px solid #93A3B8; padding-left: 10px; margin-left: 5px;"><div dir="auto">The fix for PR binutils/31872 (commit b20ab53f81db) neglected the case<br></div><div dir="auto">of targets with only RELA support, where nevertheless object files using<br></div><div dir="auto">REL exist. In particular objcopy will create such objects for x86-64<br></div><div dir="auto">when converting from an i?86 ELF object (this by itself probably isn't<br></div><div dir="auto">quite right, but we ought to cope with what our own tools are doing).<br></div><div dir="auto"><br></div><div dir="auto">Restore the fallback to the RELA lookup, just without re-introducing the<br></div><div dir="auto">blind NULL de-ref that was there before.<br></div><div dir="auto"><br></div><div dir="auto">--- a/bfd/elfcode.h<br></div><div dir="auto">+++ b/bfd/elfcode.h<br></div><div dir="auto">@@ -1615,7 +1615,8 @@ elf_slurp_reloc_table_from_section (bfd<br></div><div dir="auto">relent->addend = rela.r_addend;<br></div><div dir="auto"><br></div><div dir="auto">res = false;<br></div><div dir="auto">-      if (entsize == sizeof (Elf_External_Rela)<br></div><div dir="auto">+      if ((entsize == sizeof (Elf_External_Rela)<br></div><div dir="auto">+     || ebd->elf_info_to_howto_rel == NULL)<br></div><div dir="auto">&& ebd->elf_info_to_howto != NULL)<br></div><div dir="auto">res = ebd->elf_info_to_howto (abfd, relent, &rela);<br></div><div dir="auto">else if (ebd->elf_info_to_howto_rel != NULL)<br></div></blockquote><div dir="auto"><br></div>  </body>
</html>