title: Inconsistent format detection by ld
body: <p>I’m writing a custom bootloader (like a lot of people on the internet seem to be actually doing :D) for the sake of it without any library.</p>
  <p>Here is my target setup:</p>
  <ul>
  <li>The first sector is written in asm (Nasm i386 in 16 bits mode), called bootloader in the code. It will load the next sectors using the BIOS and jump to a label called <code>bootram_entry</code>.</li>
  <li>An arbitrary amount of sectors (hard coded to one right now) is made of Rust code (custom target, using LLVM target i386-unknown-none-code16) and will be in charge of setting up base services and load the kernel. It is called bootram, in reference to the initramfs from the Linux project.</li>
  <li>Those two objects are compiled using their respective tools, as you can see in the Makefile (GitHub link at the bottom of the post). They target the <code>elf32-i386</code> format, as it seems to be what one should use when a x86_64 CPU is in 16 bits real mode, from what I could gather (please tell me if I’m wrong). As shown by <code>objdump -f *.o</code>, they do indeed have this format.</li>
  <li>Those two objects are then linked together using a linker script (<code>boot.ld</code>), using a MEMORY section to ensure that the 0x7c00 offset is respected and to give the bootloader a reference to <code>bootram_entry</code>. It is linked to the same format (<code>elf32-i386</code>) and then copied to a binary file using <code>objcopy</code> so I can have some debugging symbols for <code>gdb</code>.</li>
  </ul>
  <p>Here is the catch though: when running <code>make build</code>, both the bootloader and bootram compile correctly to the right format, but <code>ld</code> rejects them by saying that they use the wrong architecture, despite <code>objdump</code> saying that they do not.
  You can find a screenshot of what I’m mentioning right here:</p>
  <p><a href="https://i.stack.imgur.com/mJpW4.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/mJpW4.jpg" alt="output screenshot" /></a></p>
  <p>The source code can be found on this temporary repo: <a href="https://github.com/Akarys42/bootloader/tree/wip" rel="nofollow noreferrer">https://github.com/Akarys42/bootloader/tree/wip</a></p>
  <p>If you wish to try to run it, you’ll obviously need binutils, nasm, rust and cargo (nightly) and the <code>cargo-src</code> component (<code>rustup component add rust-src</code>)</p>
  <p>Any help would be really appreciated! Thank you in advance!</p>