Leveraging objdump extensions for better autoconf cross-compilation support?

Philip Prindeville philipp_subx@redfish-solutions.com
Mon Oct 16 04:35:00 GMT 2017


Hi.

I was recently trying to update a few packages, and I noticed that certain tests were being executed and run (on the build host, of course) to extract information about the machine for which compilation was supposedly being done (i.e. the target).

This was a disconnect, of course, since the build host was an x86_64 and the target machine was armv7.

You’d have things like:

#include <stdio.h>

int main(int argc, char *argv[])
{
    printf(“sizeof long=%u\n”, sizeof(long));
    exit(0);
}

or whatever being compiled and run.

What if you could get by with:

const unsigned size_long = sizeof(long);

and compile that, and then use “objdump” (or "$(TARGET_CROSS)objdump” in this case) with some new options to dump the value of some arbitrary data (or in this case, non-executable text) symbol as a byte-stream in hex?

(Yes, with a lot of effort, we could probably do this with just “objdump -D” but that would be a lot more hairy... and probably quite error-prone).

In this case, the data might look like “00 00 00 04” (32-bit big endian), or “08 00 00 00 00 00 00” (64-bit little endian), etc.

Then you wouldn’t need to run the program, just cross-compile it and look at the way constants are represented by the compiler (and architecture, obviously).

You could detect:

* endianness
* sizes various types like “int”, “long”, “long long”, “double”, “double double”, or “long double”, “void *”, etc.
* floating point representation (i.e. VAX, IBM, IEEE, etc. formats, etc).

I think one of the reason that a lot of embedded platforms run out-of-date software is because updating to the latest version frequently involves re-visiting cross-compilation issues, which makes doing those updates less than turn-key.

If we could take (most of) the pain out of cross-compilation, then maybe the “Internet of Things” would be less synonymous with the “Internet of embedded platforms running out-of-date and known-to-be exploitable software”.

Yes, some things would still be difficult to detect about the target system, like if certain system calls were quirky, etc. but we could reduce cross-compilation complexity by an order of magnitude.

Thoughts?

-Philip




More information about the Binutils mailing list