_______________________________________________
LLVM Developers mailing list
llvm...@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev
A bit of info from the FreeBSD perspective. In FreeBSD we use ELF Tool
Chain versions of most binutils (addr2line, c++filt, objcopy, nm,
size, strings, strip, readelf) and bespoke versions of other tools
(ar, elfdump, ranlib). The exceptions are as (for which we have no
replacement), ld.bfd (we've switched to LLD for arm64 and are working
on other architectures), and objdump (investigating llvm-objdump,
although it still has some limitations).
That said, I would very much like to see LLVM equivalents for all of
the tools so that we can compare and benchmark against other
implementations, and so that we have an alternative available if it
becomes necessary. I would be happy for llvm-objcopy to exist.
> 1. Use Case: Stripping debug information of an executable to a file
> 6. Use Case: DWARF fission
> 8. Use Case: Adding a gdb index
It seems like these ought to just be done by the linker. We don't yet
use (6) in FreeBSD because our toolchain is still using some ancient
components on most architectures but it is something I very much wish
to start doing.
> 2. Use Case: Stripping debug information of a relocatable object to a file
> Who uses it: None of the 4 projects considered
> 5. Use Case: “Complete stripping” an executable
> Who uses it: None of the 4 projects
> ```sh
> eu-strip --strip-sections foo
> ```
I'd be surprised to find this being used.
> 3. Use Case: Stripping debug information of a shared library to a file
> 4. Use Case: Stripping an executable
> 7. Use Case: Converting an executable to binary
> 9. Use Case: Converting between formats [ELF->PE]
> 12. Use Case: Removing a specific unwanted section
We use these cases in FreeBSD.
One additional use case for you: converting from a binary to an ELF object file
```
objcopy -I binary -O elf64-x86-64 foo.bin foo.o
```
This is sometimes used for embedding binary files for use by drivers and such.
https://github.com/RodAtDISA/llvm-objcopy
https://github.com/tpimh/llvm-objcopy (this fork can be compiled with LLVM master)
The functions of this implementation of objcopy are very, uhm... limited.
I think this topic appeared already several times on this mailing list, so probably we get some information from the previous discussions.
It would be great to have all the binutils in LLVM, so no external toolchain is needed.
Regards,
Dmitry
02.06.2017, 21:35, "Ed Maste via llvm-dev" <llvm...@lists.llvm.org>:
One additional use case for you: converting from a binary to an ELF object file
```
objcopy -I binary -O elf64-x86-64 foo.bin foo.o
```
This is sometimes used for embedding binary files for use by drivers and such.
On Fri, Jun 2, 2017 at 2:34 PM, Ed Maste via llvm-dev <llvm...@lists.llvm.org> wrote:One additional use case for you: converting from a binary to an ELF object file
```
objcopy -I binary -O elf64-x86-64 foo.bin foo.o
```
This is sometimes used for embedding binary files for use by drivers and such.Yea, unfortunately the command-line you actually end up needing is more like:objcopy -I binary -Bi386:x86-64 -Oelf64-x86-64 --rename-section .data=.rodata,alloc,load,readonly,data,contents --add-section .note.GNU-stack=/dev/nullHaving 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. :(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:ld -r -b binary picture.jpg -o foo.oHow 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...
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?gcc main.c -Wl,-b -Wl,binary -Wl,picture.jpg -Wl,-b -Wl,<<something to undo binary mode?>>So, anyways, while this is _possible_ with objcopy, it'd sure be nice if you never needed to use it for that...
(BTW, Apple ld actually has an option "-sectcreate SEGNAME SECTNAME INPUT_FILE", and the clang driver will pass it through to the linker.)
Fantastic! Thanks for all of the input! I'll be considering all of it going forward. The plan right now is just to worry about ELF executables and nothing else. I'm very sympathetic to the "llvm-objtool" change. If everyone is cool with it I'll change the name in the next CL to "llvm-objtool".
To start out I implemented a very basic ELF64LE specific bit of code. I'm currently looking for reviewers on it. The phabricator link is here: https://reviews.llvm.org/D33964. I'd like to find people willing to review this as I work on this going forward as well. I haven't bothered worrying about it but I imagine that this will template fairly easily to support ELF32LE, ELF32BE, and ELF64BE.
Would anyone be willing to let me set them as a reviewer going forward for future CLs?
Fantastic! Thanks for all of the input! I'll be considering all of it going forward. The plan right now is just to worry about ELF executables and nothing else. I'm very sympathetic to the "llvm-objtool" change. If everyone is cool with it I'll change the name in the next CL to "llvm-objtool".
To start out I implemented a very basic ELF64LE specific bit of code. I'm currently looking for reviewers on it. The phabricator link is here: https://reviews.llvm.org/D33964. I'd like to find people willing to review this as I work on this going forward as well. I haven't bothered worrying about it but I imagine that this will template fairly easily to support ELF32LE, ELF32BE, and ELF64BE.