[gccsdk] ELF files compiled under Raspbian

Theo Markettos theo at markettos.org.uk
Mon Jul 2 16:12:39 PDT 2018

On Mon, Jul 02, 2018 at 03:39:30PM +0100, Gavin Wraith wrote:
> If I compile and statically link some C and
> gas source files under Raspbian on an Rpi3
> will the resulting ELF file, after possibly
> altering its 7-th word with elfedit, run
> under RISC OS 5.24 (also on an Rpi3)?

No, since:

a) they'll be linked to run at a different address than RISC OS' default of

b) they'll be linked against a different C library, typically glibc, which
will try and make Linux syscalls.  It would be possible to put something in
the OS to catch them and do the right RISC OS thing (roughly what Unixlib
does but at runtime, as for instance FreeBSD compat-linux and Windows
Subsystem for Linux do), but that thing doesn't exist.

c) it's actually quite difficult to link against glibc statically (some
issue to do with pluggable authentication modules which are set up at
runtime) so you either have to link with glibc dynamically or use a
different libc (musl, uclibc, libstand) - but still the same problem

If your code didn't use syscalls or libc at all (even implicit calls, eg it
was pure assembler) you'd avoid b) and c) but still run into a).  You might
get a little further compiling/linking as PIC (position independent code)
but I suspect the ELF environment won't set things up correctly to run the
PIC binary.


(just commenting from first principles - I have no particular inside
knowledge of RISC OS ELF.  Someone who does can be more authoritative than

More information about the gcc mailing list