Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
qemu-arm hello world fail [SOLVED]
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Gentoo on ARM
View previous topic :: View next topic  
Author Message
cmrd
n00b
n00b


Joined: 13 Jul 2014
Posts: 44

PostPosted: Mon Dec 14, 2015 4:02 pm    Post subject: qemu-arm hello world fail [SOLVED] Reply with quote

Hi,

I'm trying to make an arm qemu user chroot. When I attempt to run any arm binary with qemu-arm, there is an infinite loop, resulting in the command hanging until cancelled. I did strace chroot... , and got the exact same results as on the following hello world program so I'll post that instead for brevity. I'm on a hardened profile, but I'm led to believe that's not the issue as there's nothing from grsec in dmesg, and changing pax markings has no effect but I'll post my config anyway.

Kernel config: https://bpaste.net/show/1f2b2a4935a5

QEMU USE flags:
Code:
% cat /etc/portage/package.use/qemu
app-emulation/qemu spice tls usb usbredir vte static-user qemu_user_targets_arm qemu_user_targets_x86_64
% emerge -pv qemu
...
[ebuild   R    ] app-emulation/qemu-2.4.0-r1::gentoo  USE="aio alsa caps curl fdt filecaps gtk jpeg ncurses nls opengl pin-upstream-blobs png seccomp spice ssh static-user threads tls usb usbredir uuid vhost-net vnc vte xattr -accessibility -bluetooth -debug (-glusterfs) -gtk2 -infiniband -iscsi -lzo -nfs -numa -pulseaudio -python -rbd -sasl -sdl -sdl2 (-selinux) -smartcard -snappy -static -static-softmmu -systemtap -tci {-test} -vde -virtfs -xen -xfs" PYTHON_TARGETS="python2_7" QEMU_SOFTMMU_TARGETS="x86_64 -aarch64 -alpha -arm -cris -i386 -lm32 -m68k -microblaze -microblazeel -mips -mips64 -mips64el -mipsel -moxie -or32 -ppc -ppc64 -ppcemb -s390x -sh4 -sh4eb -sparc -sparc64 -tricore -unicore32 -xtensa -xtensaeb" QEMU_USER_TARGETS="arm x86_64 -aarch64 -alpha -armeb -cris -i386 -m68k -microblaze -microblazeel -mips -mips64 -mips64el -mipsel -mipsn32 -mipsn32el -or32 -ppc -ppc64 -ppc64abi32 -ppc64le -s390x -sh4 -sh4eb -sparc -sparc32plus -sparc64 -unicore32"


QEMU BINFMT:
Code:
% rc-status | grep qemu
 qemu-binfmt                                                       [  started  ]
% cat /proc/sys/fs/binfmt_misc/arm
enabled
interpreter /usr/bin/qemu-arm
flags: OC
offset 0
magic 7f454c4601010100000000000000000002002800
mask ffffffffffffff00ffffffffffff00fffeffffff


The hello world:
Code:
% cat hello.c
#include <stdio.h>
int main(){
    printf("Cross-compilation!\n");
    return 0;
}
% armv7a-hardfloat-linux-gnueabihf-gcc hello.c
% file a.out
a.out: ELF 32-bit LSB shared object, ARM, EABI5 version 1 (SYSV), dynamically linked, interpreter /lib/ld-linux-armhf.so.3, for GNU/Linux 2.6.32, not stripped
% time qemu-arm a.out
^C
qemu-arm a.out  3.03s user 4.27s system 100% cpu 7.296 total
% timeout 0.01 strace qemu-arm a.out
execve("/usr/bin/qemu-arm", ["qemu-arm", "a.out"], [/* 44 vars */]) = 0
uname({sys="Linux", node="ditto", ...}) = 0
brk(0)                                  = 0x63c69540
brk(0x63c6a780)                         = 0x63c6a780
arch_prctl(ARCH_SET_FS, 0x63c69e40)     = 0
set_tid_address(0x63c6a110)             = 4575
set_robust_list(0x63c6a120, 24)         = 0
rt_sigaction(SIGRTMIN, {0x6012a210, [], SA_RESTORER|SA_SIGINFO, 0x60131220}, NULL, 8) = 0
rt_sigaction(SIGRT_1, {0x6012a2b0, [], SA_RESTORER|SA_RESTART|SA_SIGINFO, 0x60131220}, NULL, 8) = 0
rt_sigprocmask(SIG_UNBLOCK, [RTMIN RT_1], NULL, 8) = 0
getrlimit(RLIMIT_STACK, {rlim_cur=8192*1024, rlim_max=RLIM64_INFINITY}) = 0
readlink("/proc/self/exe", "/usr/bin/qemu-arm", 4096) = 17
brk(0x63c8b780)                         = 0x63c8b780
brk(0x63c8c000)                         = 0x63c8c000
rt_sigprocmask(SIG_SETMASK, ~[RTMIN RT_1], [], 8) = 0
mmap(NULL, 8392704, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS|MAP_STACK, -1, 0) = 0x323a4306000
mprotect(0x323a4306000, 4096, PROT_NONE) = 0
clone(child_stack=0x323a4b05df0, flags=CLONE_VM|CLONE_FS|CLONE_FILES|CLONE_SIGHAND|CLONE_THREAD|CLONE_SYSVSEM|CLONE_SETTLS|CLONE_PARENT_SETTID|CLONE_CHILD_CLEARTID, parent_tidptr=0x323a4b069d0, tls=0x323a4b06700, child_tidptr=0x323a4b069d0) = 4576
rt_sigprocmask(SIG_SETMASK, [], NULL, 8) = 0
gettimeofday({1450108365, 655758}, NULL) = 0
getrlimit(RLIMIT_STACK, {rlim_cur=8192*1024, rlim_max=RLIM64_INFINITY}) = 0
time(NULL)                              = 1450108365
openat(AT_FDCWD, "/usr/gnemul/qemu-arm", O_RDONLY|O_NONBLOCK|O_DIRECTORY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
uname({sys="Linux", node="ditto", ...}) = 0
mprotect(0x60539000, 33558528, PROT_READ|PROT_WRITE|PROT_EXEC) = 0
madvise(0x60539650, 33554432, MADV_HUGEPAGE) = -1 EINVAL (Invalid argument)
mmap(NULL, 50331648, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x323a1306000
brk(0x63cad000)                         = 0x63cad000
mmap(NULL, 4143972352, PROT_NONE, MAP_PRIVATE|MAP_ANONYMOUS|MAP_NORESERVE, -1, 0) = 0x322aa306000
mmap(0x323aa2f6000, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x323a4b33000
munmap(0x323a4b33000, 4096)             = 0
munmap(0x322aa306000, 4143972352)       = 0
mmap(0x1000, 4143972352, PROT_NONE, MAP_PRIVATE|MAP_ANONYMOUS|MAP_NORESERVE, -1, 0) = 0x322aa306000
mmap(0x323aa2f6000, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x323a4b33000
munmap(0x323a4b33000, 4096)             = 0
munmap(0x322aa306000, 4143972352)       = 0
mmap(0x2000, 4143972352, PROT_NONE, MAP_PRIVATE|MAP_ANONYMOUS|MAP_NORESERVE, -1, 0) = 0x322aa306000
mmap(0x323aa2f6000, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x323a4b33000
munmap(0x323a4b33000, 4096)             = 0
munmap(0x322aa306000, 4143972352)       = 0
Process 4575 detached
 <detached ...>


So now I'm stuck. What can I try?

Edit:

My emerge --info:
Code:
Portage 2.2.24 (python 3.4.3-final-0, hardened/linux/amd64/no-multilib, gcc-4.9.3, glibc-2.21-r1, 4.1.7-hardened-r1 x86_64)
=================================================================
System uname: Linux-4.1.7-hardened-r1-x86_64-AMD_FX-tm-8350_Eight-Core_Processor-with-gentoo-2.2
KiB Mem:    12258980 total,   9819676 free
KiB Swap:    5242876 total,   5242876 free
Timestamp of repository gentoo: Mon, 14 Dec 2015 16:00:01 +0000
sh bash 4.3_p39
ld GNU ld (Gentoo 2.25.1 p1.1) 2.25.1
app-shells/bash:          4.3_p39::gentoo
dev-java/java-config:     2.2.0::gentoo
dev-lang/perl:            5.20.2::gentoo
dev-lang/python:          2.7.10-r1::gentoo, 3.4.3::gentoo
dev-util/cmake:           3.3.1-r1::gentoo
dev-util/pkgconfig:       0.28-r2::gentoo
sys-apps/baselayout:      2.2::gentoo
sys-apps/openrc:          0.18.4::gentoo
sys-apps/sandbox:         2.6-r1::gentoo
sys-devel/autoconf:       2.13::gentoo, 2.69::gentoo
sys-devel/automake:       1.11.6-r1::gentoo, 1.12.6::gentoo, 1.13.4::gentoo, 1.14.1::gentoo, 1.15::gentoo
sys-devel/binutils:       2.25.1-r1::gentoo
sys-devel/gcc:            4.9.3::gentoo
sys-devel/gcc-config:     1.7.3::gentoo
sys-devel/libtool:        2.4.6::gentoo
sys-devel/make:           4.1-r1::gentoo
sys-kernel/linux-headers: 3.18::gentoo (virtual/os-headers)
sys-libs/glibc:           2.21-r1::gentoo
Repositories:

gentoo
    location: /usr/portage
    sync-type: rsync
    sync-uri: rsync://rsync.gentoo.org/gentoo-portage
    priority: -1000

local-crossdev
    location: /usr/local/portage-crossdev
    masters: gentoo
    priority: 10

ACCEPT_KEYWORDS="amd64"
ACCEPT_LICENSE="* -@EULA"
CBUILD="x86_64-pc-linux-gnu"
CFLAGS="-march=native -O2 -pipe"
CHOST="x86_64-pc-linux-gnu"
CONFIG_PROTECT="/etc /usr/share/gnupg/qualified.txt"
CONFIG_PROTECT_MASK="/etc/ca-certificates.conf /etc/dconf /etc/env.d /etc/fonts/fonts.conf /etc/gconf /etc/gentoo-release /etc/revdep-rebuild /etc/sandbox.d /etc/terminfo /etc/texmf/language.dat.d /etc/texmf/language.def.d /etc/texmf/updmap.d /etc/texmf/web2c"
CXXFLAGS="-march=native -O2 -pipe"
DISTDIR="/usr/portage/distfiles"
FCFLAGS="-O2 -pipe"
FEATURES="assume-digests binpkg-logs config-protect-if-modified distlocks ebuild-locks fixlafiles merge-sync news parallel-fetch preserve-libs protect-owned sandbox sfperms strict unknown-features-warn unmerge-logs unmerge-orphans userfetch userpriv usersandbox usersync xattr"
FFLAGS="-O2 -pipe"
GENTOO_MIRRORS="http://mirror.qubenet.net/mirror/gentoo/"
LANG="en_GB.utf8"
LDFLAGS="-Wl,-O1 -Wl,--as-needed"
MAKEOPTS="-j7"
PKGDIR="/usr/portage/packages"
PORTAGE_CONFIGROOT="/"
PORTAGE_RSYNC_OPTS="--recursive --links --safe-links --perms --times --omit-dir-times --compress --force --whole-file --delete --stats --human-readable --timeout=180 --exclude=/distfiles --exclude=/local --exclude=/packages"
PORTAGE_TMPDIR="/var/tmp"
USE="X acl alsa amd64 berkdb bzip2 cli cracklib crypt cryptsetup cxx device-mapper dri ffmpeg gdbm git glamor gtk hardened iconv jpeg justify mdadm mmx mmxext modules mp3 mtp ncurses nls nptl offensive opengl openmp otr pax_kernel pcre pie png qt5 readline rtmp seccomp session smp sse sse2 ssh ssl ssp tcpd threads udev unicode urandom vaapi vdpau vim-syntax xattr xcb xft xinerama xkb xtpax zlib zsh-completion" ABI_X86="64" ALSA_CARDS="ali5451 als4000 atiixp atiixp-modem bt87x ca0106 cmipci emu10k1x ens1370 ens1371 es1938 es1968 fm801 hda-intel intel8x0 intel8x0m maestro3 trident usb-audio via82xx via82xx-modem ymfpci" APACHE2_MODULES="authn_core authz_core socache_shmcb unixd actions alias auth_basic authn_alias authn_anon authn_dbm authn_default authn_file authz_dbm authz_default authz_groupfile authz_host authz_owner authz_user autoindex cache cgi cgid dav dav_fs dav_lock deflate dir disk_cache env expires ext_filter file_cache filter headers include info log_config logio mem_cache mime mime_magic negotiation rewrite setenvif speling status unique_id userdir usertrack vhost_alias" CALLIGRA_FEATURES="kexi words flow plan sheets stage tables krita karbon braindump author" CAMERAS="ptp2" COLLECTD_PLUGINS="df interface irq load memory rrdtool swap syslog" CPU_FLAGS_X86="mmx mmxext sse sse2" ELIBC="glibc" GPSD_PROTOCOLS="ashtech aivdm earthmate evermore fv18 garmin garmintxt gpsclock itrax mtk3301 nmea ntrip navcom oceanserver oldstyle oncore rtcm104v2 rtcm104v3 sirf superstar2 timing tsip tripmate tnt ublox ubx" INPUT_DEVICES="evdev" KERNEL="linux" LCD_DEVICES="bayrad cfontz cfontz633 glk hd44780 lb216 lcdm001 mtxorb ncurses text" LIBREOFFICE_EXTENSIONS="presenter-console presenter-minimizer" LINGUAS="en" OFFICE_IMPLEMENTATION="libreoffice" PHP_TARGETS="php5-5" PYTHON_SINGLE_TARGET="python2_7" PYTHON_TARGETS="python2_7 python3_4" RUBY_TARGETS="ruby20 ruby21" USERLAND="GNU" VIDEO_CARDS="radeon radeonsi amdgpu" XTABLES_ADDONS="quota2 psd pknock lscan length2 ipv4options ipset ipp2p iface geoip fuzzy condition tee tarpit sysrq steal rawnat logmark ipmark dhcpmac delude chaos account"
Unset:  CC, CPPFLAGS, CTARGET, CXX, EMERGE_DEFAULT_OPTS, INSTALL_MASK, LC_ALL, PORTAGE_BUNZIP2_COMMAND, PORTAGE_COMPRESS, PORTAGE_COMPRESS_FLAGS, PORTAGE_RSYNC_EXTRA_OPTS, USE_PYTHON


Last edited by cmrd on Mon Dec 14, 2015 9:05 pm; edited 1 time in total
Back to top
View user's profile Send private message
NeddySeagoon
Administrator
Administrator


Joined: 05 Jul 2003
Posts: 54232
Location: 56N 3W

PostPosted: Mon Dec 14, 2015 7:19 pm    Post subject: Reply with quote

cmrd,

By default, cross compiling gets the dynamic linker name wrong.
Code:
$ ls /lib/ld-* -l
-rwxr-xr-x 1 root root 134192 Aug  8 15:34 /lib/ld-2.21.so
lrwxrwxrwx 1 root root     10 Aug  8 15:33 /lib/ld-linux-armhf.so.3 -> ld-2.21.so
lrwxrwxrwx 1 root root     19 Sep 10  2013 /lib/ld-linux.so.3 -> ld-linux-armhf.so.3

Notice I have two symlinks on my Raspberry Pi.

Check that /lib/ld-linux-armhf.so.3 exists in your ARM chroot.
Symlink it to your real ld* if you need to.
_________________
Regards,

NeddySeagoon

Computer users fall into two groups:-
those that do backups
those that have never had a hard drive fail.
Back to top
View user's profile Send private message
cmrd
n00b
n00b


Joined: 13 Jul 2014
Posts: 44

PostPosted: Mon Dec 14, 2015 7:28 pm    Post subject: Reply with quote

Hi NeddySeagoon,

Unfortunately I have the exact same files in my chroot:

Code:
% ls {chroot_dir}/lib | grep ld
ld-2.21.so
ld-linux-armhf.so.3
Back to top
View user's profile Send private message
cmrd
n00b
n00b


Joined: 13 Jul 2014
Posts: 44

PostPosted: Mon Dec 14, 2015 9:05 pm    Post subject: Reply with quote

Fixed by setting pax flags (initially RANDMMAP) on /usr/bin/qemu-arm and {chroot_dir}/bin/qemu-arm .
Running hello world required setting correct QEMU_LD_PREFIX.
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Gentoo on ARM All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum