title: How to make `objcopy` support efi-app target?
body: <p>The following makefile snippet seems to <code>objcopy</code> command line options to convert a <code>.so</code> file into a <code>.efi</code> file.</p>
  
  <pre><code>OBJCOPYFLAGS = \
      -j .text\
      -j .sdata\
      -j .data\
      -j .dynamic\
      -j .dynsym\
      -j .rel\
      -j .rela\
      -j .reloc\
      --target=efi-app-$(TARGET)   &lt;=====HERE
  </code></pre>
  
  <p>It basically extract certain sections from the <code>.so</code> file and into a <code>efi-app</code> target.</p>
  
  <p>But when I use <code>objcopy --info</code> to view all the supported output file formats (see below), there's no <code>efi-app</code> type. </p>
  
  <p><a href="https://i.stack.imgur.com/dL6n3.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/dL6n3.png" alt="enter image description here"></a></p>
  
  <p>So how to make <code>objcopy</code> support <code>efi-app</code> output format?</p>
  
  <h2>ADD 1</h2>
  
  <p>Found a related link:
  <a href="https://forums.gentoo.org/viewtopic-p-7197314.html" rel="nofollow noreferrer">https://forums.gentoo.org/viewtopic-p-7197314.html</a></p>
  
  <p>It seems I need to consider Gentoo Linux distribution and the <a href="https://sourceforge.net/projects/gnu-efi/?source=navbar" rel="nofollow noreferrer">gnu-efi</a> project. </p>
  
  <p>Add the quote below in case the link the broken.</p>
  
  <p>Question:</p>
  
  <blockquote>
    <p>I was interested in learning how to create UEFI applications. I
    installed the gnu-efi ebuild and found in the readme that objcopy
    needs to support efi-app-x86_64. when I do objcopy --help, there is no
    mention of efi-app-x86_64. I tried adding the multitarget useflag with
    no luck. I was wondering if anyone knows how to get a toolchain that
    supports efi or if there are any goosd tutorials ( I have not been
    able to find any) about using gentoo/linux to build efi apps.</p>
  </blockquote>
  
  <p>Answer:</p>
  
  <blockquote>
    <p>First of all, Gentoo's GNU-EFI is at version 3.0i, which is extremely
    old (September, 2009). The current version is 3.0s, although in my
    tests it doesn't work so well (binaries fail to execute). Version 3.0r
    works fine for me, so you might want to try downloading it from its
    Sourceforge page and installing it locally. FWIW, I filed a bug report
    requesting a version bump in April of this year, but it's gotten no
    official action, although this bug report includes links to local
    ebuilds.</p>
    
    <p>As to your main question, my objcopy also doesn't show efi-app-x86_64
    as a target, but it does work. Here's what I get for supported
    targets:</p>
  </blockquote>
  
  <p>Code:   </p>
  
  <pre><code>objcopy: supported targets: elf64-x86-64 elf32-i386 elf32-x86-64 a.out-i386-linux pei-i386 pei-x86-64 elf64-l1om elf64-k1om elf64-little elf64-big elf32-little elf32-big plugin srec symbolsrec verilog tekhex binary ihex
  </code></pre>
  
  <blockquote>
    <p>When I compile my rEFInd using GNU-EFI, I get the following (among
    many other messages) in the make output:</p>
  </blockquote>
  
  <p>Code:   </p>
  
  <pre><code>/usr/bin/objcopy -j .text -j .sdata -j .data -j .dynamic -j .dynsym -j .rel \
        -j .rela -j .reloc --target=efi-app-x86_64 refind_x64.so refind_x64.efi
  </code></pre>
  
  <blockquote>
    <p>This doesn't produce any error, and in fact the binary works fine.</p>
    
    <p>So the bottom line is: Don't worry about it unless it gives you
    problems. If that's the case, post back with details.</p>
    
    <p>One more point: It's possible to compile EFI applications using the
    TianoCore EDK2 rather than GNU-EFI. TianoCore is a complete EFI
    implementation, so it's overkill just to compile EFI applications, but
    it can do the job. It's also got a weird (by Linux standards)
    compilation process, which can make it awkward to install and use from
    Linux. Most EFI programs developed for Linux users, such as the new
    Shim security tool and gummiboot boot loader, use GNU-EFI and won't
    compile with TianoCore. OTOH, TianoCore is much more up-to-date than
    GNU-EFI, and it's the better choice if you want to compile something
    developed with TianoCore or its predecessor development kits, such as
    an EFI shell program. Some tools, such as rEFInd, can be compiled
    either way. (rEFInd's ability to boot BIOS/legacy boot loaders depends
    on TianoCore features, though; you can't launch BIOS/legacy boot
    loaders if you compile rEFInd with GNU-EFI.) You can look at rEFInd's
    BUILDING.txt and Makefiles to learn how to use TianoCore in a more
    Linux/Unix-like manner. In the end, which tool is best may depend on
    what you want to compile (which specific existing program or your own
    program that you're writing from scratch). If you're writing a new
    program, understanding the EFI features you want to use may be
    important.</p>
  </blockquote>