GNU objcopy can support output formats like elf32-i386-freebsd and elf64-x86-64-freebsd. The only difference from their regular non-freebsd counterparts that I have observed is that the freebsd versions set the OS/ABI field to ELFOSABI_FREEBSD. This patch sets the OS/ABI field accordingly whenever --output-format is specified.
Details
Diff Detail
- Repository
- rL LLVM
Event Timeline
The objcopy on my machine doesn't seem to be built w/ the freebsd bfd targets enabled, so I can't repro, but this seems fine. Two interesting things I found while comparing against the source:
- For older FreeBSDs (<= 4.0), objcopy actually copies the string "FreeBSD" into e_ident [1]. This seems to work because there's enough padding bytes. (I suggest we don't do this, but I found it to be interesting trivia).
- In the method that actually sets the OSABI member [2], if the OSABI field is still ELFOSABI_NONE, it will change it to ELFOSABI_GNU if the object contains GNU symbols. Does this seem useful to do?
12065 /* To make things simpler for the loader on Linux systems we set the 12066 osabi field to ELFOSABI_GNU if the binary contains symbols of 12067 the STT_GNU_IFUNC type or STB_GNU_UNIQUE binding. */ 12068 if (i_ehdrp->e_ident[EI_OSABI] == ELFOSABI_NONE 12069 && elf_tdata (abfd)->has_gnu_symbols) 12070 i_ehdrp->e_ident[EI_OSABI] = ELFOSABI_GNU;
[1] https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;a=blob;f=bfd/elf32-i386.c;h=79cd8c65bc150781b9783cfc591b08fc36785890;hb=HEAD#l4414
[2] https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;a=blob;f=bfd/elf.c;h=73fb86971f3dcc0461ba17d5d24d3cf7add41761;hb=HEAD#l12055
It does seem somewhat useful, but it looks like a different, only tangetially-related, behaviour, so I'll file a bug for that, especially as I imagine it will slow down the tool (it'll have to keep track of all symbols that are GNU symbols).
tools/llvm-objcopy/ELF/ELFObjcopy.cpp | ||
---|---|---|
229 ↗ | (On Diff #191698) | Oh. Was this place tested? Seems not. |
tools/llvm-objcopy/ELF/ELFObjcopy.cpp | ||
---|---|---|
229 ↗ | (On Diff #191698) | Yeah, I noticed this when I was uploading this patch. I've got a note on my desk to look at adding a test for this section (the Machine line immediately above it is also untested). Given the block is already untested, are you happy for this to be tested in a separate patch, or would you prefer it being part of this one? |
tools/llvm-objcopy/ELF/ELFObjcopy.cpp | ||
---|---|---|
229 ↗ | (On Diff #191698) |
I think it's fine to do in a separate patch then. |
I've filed https://bugs.llvm.org/show_bug.cgi?id=41196 for the GNU OSABI issue, and created D59691 for the test coverage addition.