How to obtain the BFD architecture specification for the current platform?

3.9k views Asked by At

I've embedded a text file in a C program using the following method: http://www.linuxjournal.com/content/embedding-file-executable-aka-hello-world-version-5967

a.out:prog.c file.text
    objcopy --input binary --output elf64-x86-64 --binary-architecture i386 file.text file.o
    gcc prog.c file.o

objcopy requires to specify the target with the "--output" option.

How can I set "--output" in Makefile so objcopy will use the user's architecture ?

Thanks.

1

There are 1 answers

3
thiton On

Firstly: You are not trying to emulate the -b capability of the GCC ld, are you? In more verbose terms: The GCC ld can actually load a number of binary formats, see the documentation. If that's what you want to achieve, something like:

 gcc prog.c -Wl,-b -Wl,binary file.o

might save you the whole objcopy call.

While I'm not able to find documentation on the issue, the output of objdump -i seems to be sorted by preference, so

 `objdump -i | head -n 2 | tail -n 1`

should expand to the usual target architecture. Stating again: I have no documentation on this behaviour, so better don't rely blindly on it.