title: How to build ELF on MacOS using LLVM?
body: <p>I am trying to build ELF-file using <strong>LLVM</strong> (from <strong>Homebrew</strong>) but I can't get how to link it.</p>
  
  <p>My files:<br>
  <strong>multiboot2.h</strong>:  </p>
  
  <pre><code>struct multiboot2_header_t {
  // Stub
  } multiboot2_header __attribute__((section(".multiboot")));
  </code></pre>
  
  <p><strong>kernel.c</strong>:  </p>
  
  <pre><code>#include "multiboot2.h"
  
  void _start() {
  // Stub
  }
  </code></pre>
  
  <p><strong>linker.ld</strong>:  </p>
  
  <pre><code>ENTRY(_start)
  
  SECTIONS
  {
      .text: {
      /* link the multiboot struct here */
      . = ALIGN(8);
      KEEP(*(.multiboot))
      /* place all of your code afterwards */
      *(.text)
      }
  }
  </code></pre>
  
  <p>I can compile it to object file <strong>kernel.o</strong> by command <code>clang -c -o kernel.o kernel.c --target x86_64-none-gnu</code> but I can't get how to link this object file using my linker script.</p>
  
  <p><strong>P.S.</strong> Before I never worked with <strong>LLVM</strong> and <strong>linker</strong> directly, only <strong>GNU GCC</strong> building simple Linux apps.</p>