<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Fri, Jun 2, 2017 at 2:34 PM, Ed Maste via llvm-dev <span dir="ltr"><<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">One additional use case for you: converting from a binary to an ELF object file<br>
```<br>
objcopy -I binary -O elf64-x86-64 foo.bin foo.o<br>
```<br>
This is sometimes used for embedding binary files for use by drivers and such.<br></blockquote><div><br></div><div>Yea, unfortunately the command-line you actually end up needing is more like:</div><div>  objcopy -I binary -Bi386:x86-64 -Oelf64-x86-64 --rename-section .data=.rodata,alloc,load,<wbr>readonly,data,contents --add-section .note.GNU-stack=/dev/null<br></div><div><br></div><div>Having to manually invoke objcopy and know what to specify for the -B and -O options, and to know you need the .note.GNU-stack section, and how to move it into rodata...it's really all quite terrible. Nobody should have to do that. :(</div><div><br></div><div>There's also the "-b binary" flag to GNU ld (both bfd and gold). But, you typically need to do a dedicated "link" for that. You do:</div><div>  ld -r -b binary picture.jpg -o foo.o</div><div>How does ld know what output format to use here? It's gotta just choose the default, which is kinda poor...or the user needs to know how to spell an "emulation" and output format...<br></div><div><br></div><div>You could imagine trying to use -Wl to put it with the compile command, but what do you use to switch back to the normal object format?<br></div><div>  gcc main.c -Wl,-b -Wl,binary -Wl,picture.jpg -Wl,-b -Wl,<<something to undo binary mode?>></div><div><br></div><div>So, anyways, while this is _possible_ with objcopy, it'd sure be nice if you never needed to use it for that...</div><div><br></div><div>(BTW, Apple ld actually has an option "-sectcreate SEGNAME SECTNAME INPUT_FILE", and the clang driver will pass it through to the linker.)</div></div></div></div>