Ed Maste via llvm-dev
2016-Mar-14 18:24 UTC
[llvm-dev] [lld] supporting binary-to-ELF conversion
One of the issues I reported in using lld as the FreeBSD base system linker is that the base system currently uses ld -r to convert a binary file (device firmware image) into an ELF object:> A tool for loading firmware into a wireless USB device includes a > built-in copy of the firmware image, and the image is converted to an > ELF file using ld -r.The invocation is: ld -b binary -d -warn-common -r -d -o ar5523.o ar5523.bin which produces an object with a .data section containing the binary data, and symbols for the start, end, and size. I think the -d here has no effect and could be dropped, but we do not support "-b binary" in lld. Originally I thought this is somewhat strange functionality for a linker to support, and assumed there'd be no interest in adding support to lld. It could be addressed in FreeBSD by using objcopy or just converting the binary blob to a C array and treating it as another source file. That said, I was surprised to find that gold also supports this use, so perhaps it's less strange than I thought. Before I go and make a change in FreeBSD I want to see what others think about supporting "-b binary" in lld.
Rui Ueyama via llvm-dev
2016-Mar-14 21:32 UTC
[llvm-dev] [lld] supporting binary-to-ELF conversion
That command uses the linker to wrap a blob with an ELF header. This is an interesting feature, but it seems to me that that is too specific to some special use case. Linkers are, well, to link stuff, and in this case this links nothing. If the linker hadn't supported "-b binary", they would have done this in a different way. I think this use case should be done using objdump. You can create an empty ELF file using as or something, and copy the blob to .text section using objcopy, no? On Mon, Mar 14, 2016 at 11:24 AM, Ed Maste via llvm-dev < llvm-dev at lists.llvm.org> wrote:> One of the issues I reported in using lld as the FreeBSD base system > linker is that the base system currently uses ld -r to convert a > binary file (device firmware image) into an ELF object: > > > A tool for loading firmware into a wireless USB device includes a > > built-in copy of the firmware image, and the image is converted to an > > ELF file using ld -r. > > The invocation is: > ld -b binary -d -warn-common -r -d -o ar5523.o ar5523.bin > which produces an object with a .data section containing the binary > data, and symbols for the start, end, and size. > > I think the -d here has no effect and could be dropped, but we do not > support "-b binary" in lld. Originally I thought this is somewhat > strange functionality for a linker to support, and assumed there'd be > no interest in adding support to lld. > > It could be addressed in FreeBSD by using objcopy or just converting > the binary blob to a C array and treating it as another source file. > > That said, I was surprised to find that gold also supports this use, > so perhaps it's less strange than I thought. Before I go and make a > change in FreeBSD I want to see what others think about supporting "-b > binary" in lld. > _______________________________________________ > LLVM Developers mailing list > llvm-dev at lists.llvm.org > http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev >-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20160314/3eb00d9a/attachment.html>
Reid Kleckner via llvm-dev
2016-Mar-14 21:41 UTC
[llvm-dev] [lld] supporting binary-to-ELF conversion
Another easy way to do this is to have a .s file that uses .incbin in the appropriate section. It also lets you create symbols for the start and end of the data, which is nice. On Mon, Mar 14, 2016 at 2:32 PM, Rui Ueyama via llvm-dev < llvm-dev at lists.llvm.org> wrote:> That command uses the linker to wrap a blob with an ELF header. This is an > interesting feature, but it seems to me that that is too specific to some > special use case. Linkers are, well, to link stuff, and in this case this > links nothing. If the linker hadn't supported "-b binary", they would have > done this in a different way. > > I think this use case should be done using objdump. You can create an > empty ELF file using as or something, and copy the blob to .text section > using objcopy, no? > > On Mon, Mar 14, 2016 at 11:24 AM, Ed Maste via llvm-dev < > llvm-dev at lists.llvm.org> wrote: > >> One of the issues I reported in using lld as the FreeBSD base system >> linker is that the base system currently uses ld -r to convert a >> binary file (device firmware image) into an ELF object: >> >> > A tool for loading firmware into a wireless USB device includes a >> > built-in copy of the firmware image, and the image is converted to an >> > ELF file using ld -r. >> >> The invocation is: >> ld -b binary -d -warn-common -r -d -o ar5523.o ar5523.bin >> which produces an object with a .data section containing the binary >> data, and symbols for the start, end, and size. >> >> I think the -d here has no effect and could be dropped, but we do not >> support "-b binary" in lld. Originally I thought this is somewhat >> strange functionality for a linker to support, and assumed there'd be >> no interest in adding support to lld. >> >> It could be addressed in FreeBSD by using objcopy or just converting >> the binary blob to a C array and treating it as another source file. >> >> That said, I was surprised to find that gold also supports this use, >> so perhaps it's less strange than I thought. Before I go and make a >> change in FreeBSD I want to see what others think about supporting "-b >> binary" in lld. >> _______________________________________________ >> LLVM Developers mailing list >> llvm-dev at lists.llvm.org >> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev >> > > > _______________________________________________ > LLVM Developers mailing list > llvm-dev at lists.llvm.org > http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev > >-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20160314/33c48078/attachment-0001.html>
Justin Hibbits via llvm-dev
2016-Mar-14 21:46 UTC
[llvm-dev] [lld] supporting binary-to-ELF conversion
I've used objcopy to create an ELF from a bin for linking at $PREVJOB. I think this makes more sense than using ld for the task. - Justin On Mon, Mar 14, 2016 at 1:24 PM, Ed Maste via llvm-dev <llvm-dev at lists.llvm.org> wrote:> One of the issues I reported in using lld as the FreeBSD base system > linker is that the base system currently uses ld -r to convert a > binary file (device firmware image) into an ELF object: > >> A tool for loading firmware into a wireless USB device includes a >> built-in copy of the firmware image, and the image is converted to an >> ELF file using ld -r. > > The invocation is: > ld -b binary -d -warn-common -r -d -o ar5523.o ar5523.bin > which produces an object with a .data section containing the binary > data, and symbols for the start, end, and size. > > I think the -d here has no effect and could be dropped, but we do not > support "-b binary" in lld. Originally I thought this is somewhat > strange functionality for a linker to support, and assumed there'd be > no interest in adding support to lld. > > It could be addressed in FreeBSD by using objcopy or just converting > the binary blob to a C array and treating it as another source file. > > That said, I was surprised to find that gold also supports this use, > so perhaps it's less strange than I thought. Before I go and make a > change in FreeBSD I want to see what others think about supporting "-b > binary" in lld. > _______________________________________________ > LLVM Developers mailing list > llvm-dev at lists.llvm.org > http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev
Ed Maste via llvm-dev
2016-Mar-14 22:46 UTC
[llvm-dev] [lld] supporting binary-to-ELF conversion
On 14 March 2016 at 21:32, Rui Ueyama <ruiu at google.com> wrote:> That command uses the linker to wrap a blob with an ELF header. This is an > interesting feature, but it seems to me that that is too specific to some > special use case. Linkers are, well, to link stuff, and in this case this > links nothing. If the linker hadn't supported "-b binary", they would have > done this in a different way.Ok, that was my thought as well. I only second-guessed it when I found gold supports it, since as far as I know the intent of gold's design was to support only ELF linking.> I think this use case should be done using objdump. You can create an empty > ELF file using as or something, and copy the blob to .text section using > objcopy, no?Yes, objcopy works much as ld -r for this use case, except that objcopy needs the output machine type to be specified explicitly. This is probably another argument against supporting it in lld, actually -- we'd need the notion of a default output format.