Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 478140 - MIPS binfmt_misc example command not working with self-compiled binaries
Summary: MIPS binfmt_misc example command not working with self-compiled binaries
Status: RESOLVED NEEDINFO
Alias: None
Product: [OLD] Docs on www.gentoo.org
Classification: Unclassified
Component: Other documents (show other bugs)
Hardware: All Linux
: Normal normal (vote)
Assignee: Embedded Gentoo Team
URL: http://www.gentoo.org/proj/en/base/em...
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2013-07-25 14:21 UTC by Alessandro Di Federico
Modified: 2014-06-06 01:51 UTC (History)
2 users (show)

See Also:
Package list:
Runtime testing required: ---


Attachments
Patch to ignore EI_OSABI in binfmt (qemu-chroot-binfmt-ignore-eos_abi.patch,2.30 KB, patch)
2013-07-25 14:46 UTC, Alessandro Di Federico
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Alessandro Di Federico 2013-07-25 14:21:45 UTC
Hi, I'm using qemu-mips in a MIPS gentoo chroot (I used stage3-mips1-20130711.tar.bz2). Everything seems to work fine except self-built binaries, since they escape the magic string in the example shown here:

http://www.gentoo.org/proj/en/base/embedded/handbook/?part=1&chap=5

Using a binary diff program I noticed that the problem is the 8th byte, which is set to 0x01 instead of 0x00. Ignoring that byte in the bitmask solves the problem.

Original:
echo ':mips:M::\x7fELF\x01\x02\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x08:\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff:/usr/bin/qemu-mips:' > /proc/sys/fs/binfmt_misc/register

Fixed:
echo ':mips:M::\x7fELF\x01\x02\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x08:\xff\xff\xff\xff\xff\xff\xff\x00\x00\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff:/usr/bin/qemu-mips:' > /proc/sys/fs/binfmt_misc/register

Looks like a problem in the EI_OSABI ELF field (from `man elf`):

EI_OSABI    This byte identifies the operating system and ABI to which the object is targeted.  Some fields in other ELF structures have flags and values that have
                               platform-specific meanings; the interpretation of those fields is determined by the value of this byte.  E.g.:

                               ELFOSABI_NONE       Same as ELFOSABI_SYSV
                               ELFOSABI_SYSV       UNIX System V ABI.

Same meaning, different values.
Comment 1 Alessandro Di Federico 2013-07-25 14:46:32 UTC
Created attachment 354186 [details, diff]
Patch to ignore EI_OSABI in binfmt

Other platforms might suffer the same problem, but to avoid problems with untested configurations I'm not fixing them here.
Comment 2 Sven Vermeulen (RETIRED) gentoo-dev 2013-08-01 19:19:31 UTC
Hi @embedded team, I think this is for you guys
Comment 3 SpanKY gentoo-dev 2013-08-17 18:00:47 UTC
we take things straight from the qemu project (scripts/qemu-binfmt-conf.sh).  so the patch probably should be sent upstream to the qemu project.
Comment 4 SpanKY gentoo-dev 2014-06-06 01:51:03 UTC
ELFOSABI_NONE & ELFOSABI_SYSV have a value of 0x00.  ELFOSABI_HPUX has 0x01 and generating ELFs with that would be broken.