File qemu-accel-aarch64.spec of Package qemu-accel-aarch64

%define accel_arch aarch64
#
# spec file for package qemu-accel-%{accel_arch}
#
# Copyright (c) 2012 SUSE LINUX Products GmbH, Nuernberg, Germany.
#
# All modifications and additions to the file contributed by third parties
# remain the property of their copyright owners, unless otherwise agreed
# upon. The license for this file, and modifications and additions to the
# file, is the same license as for the pristine package itself (unless the
# license for the pristine package is not an Open Source License, in which
# case the license is the MIT License). An "Open Source License" is a
# license that conforms to the Open Source Definition (Version 1.9)
# published by the Open Source Initiative.

# Please submit bugfixes or comments via http://bugs.opensuse.org/
#


# Choose which gcc hijack method (if any) to use.
# Only select one of the two at a time!
%define use_icecream 0
%define hijack_gcc 0

Name:           qemu-accel-%{accel_arch}
Version:        1.6.0
Release:        0
AutoReqProv:    off
BuildRequires:  cross-%{accel_arch}-gcc48-icecream-backend
BuildRequires:  deltarpm
BuildRequires:  fdupes
BuildRequires:  gcc-c++
BuildRequires:  gcc-java
BuildRequires:  gettext-runtime
BuildRequires:  gettext-tools
BuildRequires:  m4
# required for xxd
BuildRequires:  vim-base
BuildRequires:  patchelf
BuildRequires:  rpmlint-mini
BuildRequires:  zip
BuildRequires:  unzip
BuildRequires:  deltarpm
%if %use_icecream
BuildRequires:  icecream
BuildRequires:  schroot
%endif
Requires:       coreutils
Summary:        Native binaries for speeding up cross compile
License:        GPL-2.0
Group:          Development/Libraries/Cross
ExclusiveArch:  x86_64
PreReq:         qemu-linux-user

# default path in qemu
%define HOST_ARCH %(echo %{_host_cpu} | sed -e "s/i.86/i586/;s/ppc/powerpc/;s/sparc64.*/sparc64/;s/sparcv.*/sparc/;")
%define icecream_cross_env cross-%{accel_arch}-gcc48-icecream-backend_x86_64
%if %{accel_arch} == "aarch64"
%define our_path /emul/%{HOST_ARCH}-for-arm64
%define binutils_binary_path aarch64-suse-linux
%else
%define our_path /emul/%{HOST_ARCH}-for-arm
%define binutils_binary_path arm-suse-linux-gnueabi
%define QEMU_BINARY qemu-arm
BuildRequires:  cross-arm-binutils
BuildRequires:  qemu-linux-user
%endif

%description
This package is used in %{accel_arch} architecture builds using qemu to speed up builds
with native binaries.
 This should not be installed on systems, it is just intended for qemu environments.

%prep
%setup -q -D -T -n .

%build

%install
binaries="/%_lib/libnsl.so.1 /%_lib/libnss_compat.so.2" # loaded via dlopen by glibc
%ifarch %ix86
  LD="/lib/ld-linux.so.2"
%else
%ifarch x86_64
  LD="/lib64/ld-linux-x86-64.so.2"
%else
  echo "ERROR unhandled arch"
  exit 1
%endif
%endif

# XXX this fails with the following error:
#     /opt/testing/bin/python: error while loading shared libraries: libpython2.7.so.1.0: wrong ELF class: ELFCLASS32

# disabled, because it looks to risky: msgexec,msgfmt,msgcat,msgmerge


for executable in $LD \
   /usr/bin/makedeltarpm
do  
  binaries="$binaries $executable `ldd $executable | sed -n 's,.*=> \(/[^ ]*\) .*,\1,p'`"
done

for binary in $binaries
do
  outfile=%buildroot%{our_path}$(echo $binary | sed 's:cross-compiler-tmp::;s:/opt/cross/%{binutils_binary_path}:/usr:')
  [ -f $outfile ] && continue
  mkdir -p ${outfile%/*}
  cp -aL $binary $outfile
%if %{accel_arch} == "armv7hl" || %{accel_arch} == "armv6hl"
  # XXX hack alert! Only works for armv?hl-on-x86_64
  [ "$(basename $outfile)" = "bash" ] && sed -i 's/x86_64/armv7l/g' "$outfile"
%endif
# XXX: This is bogus code, which just worked for some time, because the x86_64 string
#      (which are required at least in ld-linux) was at the xxd line wrap boarder 
# objdump -s -j .rodata -j .data $outfile | sed 's/^ *\([a-z0-9]*\)/\1:/' | \
#     grep ': ' | grep -v 'file format' | grep -v 'Contents of section' | \
#     xxd -g4 -r - $outfile.data
#   if grep -q "%{HOST_ARCH}" $outfile.data; then
#     echo "ERROR file $binary leaks host information into the guest"
#     exit 1
#   fi
  rm -f $outfile.data
  [ "$binary" == "$LD" ] && continue
  patchelf --debug --set-rpath "%our_path/%_lib:%our_path%_libdir" $outfile
# not all binaries have an .interp section
  if patchelf --print-interpreter $outfile; then
    patchelf --debug --set-interpreter %{our_path}$LD $outfile
  fi
done

%fdupes -s %{buildroot}

export NO_BRP_CHECK_RPATH="true"

%post
set -x
# load the binfmt_misc module
if [ ! -d /proc/sys/fs/binfmt_misc ]; then
  builtin echo "Calling modprobe"
  /sbin/modprobe binfmt_misc
fi

did_mount_it=""

if [ ! -f /proc/sys/fs/binfmt_misc/register ]; then
  builtin echo "mounting binfmt_misc"
  mount binfmt_misc -t binfmt_misc /proc/sys/fs/binfmt_misc
  did_mount_it=1
fi

if [ -e /proc/sys/fs/binfmt_misc/aarch64 ]; then
    builtin echo "Registering aarch64 accelerated handler"
    echo -1 > /proc/sys/fs/binfmt_misc/aarch64 || :
    echo   ':aarch64:M::\x7fELF\x02\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\xb7:\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff:/usr/bin/qemu-aarch64-binfmt:P' > /proc/sys/fs/binfmt_misc/register || :
fi

if [ $did_mount_it ]; then 
  builtin echo "Unmounting again.";
  umount /proc/sys/fs/binfmt_misc
fi

builtin echo "All done"

%files
%defattr(-,root,root)  
/emul

%changelog
openSUSE Build Service is sponsored by