This is the mail archive of the binutils@sourceware.org mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

objcopy, binary inputs, and e_machine


if i use objcopy to take a binary file and convert it to an ELF, the default 
e_machine is set to None for most people.  for example:
echo moo > moo.bin
objcopy -I binary -O elf32-i386 moo.bin moo.elf
readelf -h moo.elf
<machine is set to EM_NONE rather than EM_I386>
using the -B option doesnt seem to make a difference.  --alt-machine-code does 
work, but that kind of sucks because you need to know the numerical value for 
your EM_XXX.

this behavior is because the objcopy sets the arch/mach of the output to match 
the input, and since this is a binary input, the arch/mach are set to none.  
the common ELF bfd then sets the default e_machine based on the arch -- if 
it's unknown (like the binary bfd), then it gets set to EM_NONE.  otherwise 
it's taken from the bfd.  there is a comment in the ELF code about using 
elf_backend_final_write_processing, but that seems like overkill to have every 
arch elf bfd do basically the same thing:
elf_elfheader(abfd)->e_machine = ELF_MACHINE_CODE;

if i change my elf32-bfin.c to do this, then i get the expected behavior -- 
e_machine is set as i'd expect.  the elf32-avr.c backend is already doing 
this, but is this really the route i should also go or isnt there a saner 
route that'd work for everyone ?
-mike

Attachment: signature.asc
Description: This is a digitally signed message part.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]