0

after reading this answer I immediately thought to myself:

Why exactly do I have to tell whether it's Little or Big Endian? Does it mean that instead of simply copying my binary input data, objcopy mangles the data in some way, depending on the Endianess chosen?

The example at hand was:

objcopy -I binary -O elf(32|64)-(big|little) binblob binblob.o

If this is truly binary data, objcopy shouldn't have to care, right? Whatever reads the data later on would have to, but objcopy shouldn't have to ...

Does objcopy mangle the data based on the bitness and Endianess given by the -O option?

0xC0000022L
  • 20,597
  • 9
  • 86
  • 152
  • Normally you don't have to specify the endianness, as that's either stored in the object file or deduced from the host. – Some programmer dude Jul 31 '19 at 08:37
  • And with binary data you *really* have to care about endianness. Think about the (16-bit) value `0xf0b2`. On a big-endian system that is stored as the two bytes `0xf0` and `0xb2` (in that order), but on a little-endian system the bytes are stored in the order `0xb2` followed by `0xf0`. If you use the wrong endianness you could get the value `0xb2f0` instead. – Some programmer dude Jul 31 '19 at 08:39
  • @Someprogrammerdude if I don't give `-B` how would it deduce it? After all none of `elf32-big`, `elf32-little`, `elf64-big`, `elf64-little` are architecture-specific ... but there isn't something like an `elf-binary` _bfdname_. – 0xC0000022L Jul 31 '19 at 08:39
  • What is the format of `binblob.o`? How was it created? If it's an ELF object file, the byte-order will be specified in the ELF header. As will the word size (32 or 64 bits). – Some programmer dude Jul 31 '19 at 08:42
  • @Someprogrammerdude no I don't have to care about Endianess. In my case the binary data is going to be a string. You make the assumption that the binary data is already in the form of - say - integers or other C types. And that's exactly the question I have: does `objcopy` also make such assumption and if so, how does it mangle the data? Last but not least it would be a whole lot easier if I wouldn't have to give a specific _bdfname_ at all, since the data I want to store is not to be interpreted as some C type (and if it were, I'd take care of conversion _in code_ ... I promise ;)). – 0xC0000022L Jul 31 '19 at 08:42

0 Answers0