[llvm-dev] [lld] supporting binary-to-ELF conversion

Ed Maste via llvm-dev llvm-dev at lists.llvm.org
Mon Mar 14 11:24:27 PDT 2016


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.


More information about the llvm-dev mailing list