Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support cross-compile on aarch64 platform #4271

Merged
merged 1 commit into from
May 31, 2020
Merged

Conversation

catalinii
Copy link
Contributor

This commit enables building openssl on another systems instead of x86_64 (eg. arm)

MilhouseVH
MilhouseVH previously approved these changes Mar 23, 2020
@beta-tester
Copy link

hello,
i just tried to compile LibreELEC image or an add-on on an RPi3B+ for an RPi3
but i get an error while compiling openssl that gcc option -m64 is unknown.
gcc: error: unrecognized command line option ‘-m64’

PROJECT=RPi DEVICE=RPi2 ARCH=arm scripts/create_addon game.libretro.scummvm
...
BUILD      openssl (host)
    TOOLCHAIN      configure
Configuring OpenSSL version 1.1.1d (0x1010104fL) for linux-x86_64
Using os-specific seed configuration
Creating configdata.pm
Creating Makefile

**********************************************************************
***                                                                ***
***   OpenSSL has been successfully configured                     ***
***                                                                ***
***   If you encounter a problem while building, please open an    ***
***   issue on GitHub <https://github.com/openssl/openssl/issues>  ***
***   and include the output from the following command:           ***
***                                                                ***
***       perl configdata.pm --dump                                ***
***                                                                ***
***   (If you are new to OpenSSL, you might want to consult the    ***
***   'Troubleshooting' section in the INSTALL file first)         ***
***                                                                ***
**********************************************************************
Executing (host): make 
/usr/bin/perl "-I." -Mconfigdata "util/dofile.pl" \
    "-oMakefile" crypto/include/internal/bn_conf.h.in > crypto/include/internal/bn_conf.h
/usr/bin/perl "-I." -Mconfigdata "util/dofile.pl" \
    "-oMakefile" crypto/include/internal/dso_conf.h.in > crypto/include/internal/dso_conf.h
/usr/bin/perl "-I." -Mconfigdata "util/dofile.pl" \
    "-oMakefile" i
nclude/openssl/opensslconf.h.in > include/openssl/opensslconf.h
make depend && make _all
make[1]: Entering directory '/home/pi/LibreELEC.tv/build.LibreELEC-RPi2.arm-9.80-devel/build/openssl-1.1.1d/.arm-linux-gnueabihf'
make[1]: Leaving directory '/home/pi/LibreELEC.tv/build.LibreELEC-RPi2.arm-9.80-devel/build/openssl-1.1.1d/.arm-linux-gnueabihf'
make[1]: Entering directory '/home/pi/LibreELEC.tv/build.LibreELEC-RPi2.arm-9.80-devel/build/openssl-1.1.1d/.arm-linux-gnueabihf'
/home/pi/LibreELEC.tv/build.LibreELEC-RPi2.arm-9.80-devel/toolchain/bin/host-gcc  -I. -Iinclude -fPIC -pthread -m64 -Wa,--noexecstack -march=native -O2 -Wall -pipe -I/home/pi/LibreELEC.tv/build.LibreELEC-RPi2.arm-9.80-devel/toolchain/include -Wno-format-security -march=native -O2 -Wall -pipe -Wno-format-security -DOPENSSL_USE_NODELETE -DL_ENDIAN -DOPENSSL_PIC -DOPENSSL_CPUID_OBJ -DOPENSSL_IA32_SSE2 -DOPENSSL_BN_ASM_MONT -DOPENSSL_BN_ASM_MONT5 -DOPENSSL_BN_ASM_GF2m -DSHA1_ASM -DSHA256_ASM -DSHA512_ASM -DKECCAK1600_ASM -DRC4_ASM -DMD5_ASM -DVPAES_ASM -DGHASH_ASM -DECP_NISTZ256_ASM -DX25519_ASM -DPOLY1305_ASM -DOPENSSLDIR="\"/home/pi/LibreELEC.tv/build.LibreELEC-RPi2.arm-9.80-devel/toolchain/etc/ssl\"" -DENGINESDIR="\"/home/pi/LibreELEC.tv/build.LibreELEC-RPi2.arm-9.80-devel/toolchain/lib/engines-1.1\"" -DNDEBUG -I/home/pi/LibreELEC.tv/build.LibreELEC-RPi2.arm-9.80-devel/toolchain/include -MMD -MF apps/app_rand.d.tmp -MT apps/app_rand.o -c -o apps/app_rand.o apps/app_rand.c
gcc: error: unrecognized command line option '-m64'
make[1]: *** [Makefile:708: apps/app_rand.o] Error 1
make[1]: Leaving directory '/home/pi/LibreELEC.tv/build.LibreELEC-RPi2.arm-9.80-devel/build/openssl-1.1.1d/.arm-linux-gnueabihf'
make: *** [Makefile:174: all] Error 2
FAILURE: scripts/build openssl:host during make_host (default)
*********** FAILED COMMAND ***********
make ${PKG_MAKE_OPTS_HOST}
**************************************
FAILURE: scripts/build openssl:host has failed!

The following log for this failure is available:
  /home/pi/LibreELEC.tv/build.LibreELEC-RPi2.arm-9.80-devel/.threads/logs/7.log

>>> openssl:host seq 7 >>>
[006/155] [FAIL] build   openssl:host

The following log for this failure is available:
  /home/pi/LibreELEC.tv/build.LibreELEC-RPi2.arm-9.80-devel/.threads/logs/7.log

7.log

@beta-tester
Copy link

oops, sorry, i didn't recognized, that i used the unpatched package.mk file...

with the patched version i get the following error:

BUILD      openssl (host)
    TOOLCHAIN      configure
Usage: Configure [no-<cipher> ...] [enable-<cipher> ...] [-Dxxx] [-lxxx] [-Lxxx] [-fxxx] [-Kxxx] [no-hw-xxx|no-hw] [[no-]threads] [[no-]shared] [[no-]zlib|zlib-dynamic] [no-asm] [no-egd] [sctp] [386] [--prefix=DIR] [--openssldir=OPENSSLDIR] [--with-xxx[=vvv]] [--config=FILE] os/compiler[:flags]

pick os/compiler from:
BS2000-OSD BSD-generic32 BSD-generic64 BSD-ia64 BSD-sparc64 BSD-sparcv8 
BSD-x86 BSD-x86-elf BSD-x86_64 Cygwin Cygwin-i386 Cygwin-i486 Cygwin-i586 
Cygwin-i686 Cygwin-x86 Cygwin-x86_64 DJGPP MPE/iX-gcc UEFI UWIN VC-CE VC-WIN32 
VC-WIN32-ARM VC-WIN32-ONECORE VC-WIN64-ARM VC-WIN64A VC-WIN64A-ONECORE 
VC-WIN64A-masm VC-WIN64I aix-cc aix-gcc aix64-cc aix64-gcc android-arm 
android-arm64 android-armeabi android-mips android-mips64 android-x86 
android-x86_64 android64 android64-aarch64 android64-mips64 android64-x86_64 
bsdi-elf-gcc cc darwin-i386-cc darwin-ppc-cc darwin64-ppc-cc 
darwin64-x86_64-cc gcc haiku-x86 haiku-x86_64 hpux-ia64-cc hpux-ia64-gcc 
hpux-parisc-cc hpux-parisc-gcc hpux-parisc1_1-cc hpux-parisc1_1-gcc 
hpux64-ia64-cc hpux64-ia64-gcc hpux64-parisc2-cc hpux64-parisc2-gcc hurd-x86 
ios-cross ios-xcrun ios64-cross ios64-xcrun iossimulator-xcrun iphoneos-cross 
irix-mips3-cc irix-mips3-gcc irix64-mips4-cc irix64-mips4-gcc linux-aarch64 
linux-alpha-gcc linux-aout linux-arm64ilp32 linux-armv4 linux-c64xplus 
linux-elf linux-generic32 linux-generic64 linux-ia64 linux-mips32 linux-mips64 
linux-ppc linux-ppc64 linux-ppc64le linux-sparcv8 linux-sparcv9 linux-x32 
linux-x86 linux-x86-clang linux-x86_64 linux-x86_64-clang linux32-s390x 
linux64-mips64 linux64-s390x linux64-sparcv9 mingw mingw64 nextstep 
nextstep3.3 sco5-cc sco5-gcc solaris-sparcv7-cc solaris-sparcv7-gcc 
solaris-sparcv8-cc solaris-sparcv8-gcc solaris-sparcv9-cc solaris-sparcv9-gcc 
solaris-x86-gcc solaris64-sparcv9-cc solaris64-sparcv9-gcc solaris64-x86_64-cc 
solaris64-x86_64-gcc tru64-alpha-cc tru64-alpha-gcc uClinux-dist 
uClinux-dist64 unixware-2.0 unixware-2.1 unixware-7 unixware-7-gcc vms-alpha 
vms-alpha-p32 vms-alpha-p64 vms-ia64 vms-ia64-p32 vms-ia64-p64 vos-gcc 
vxworks-mips vxworks-ppc405 vxworks-ppc60x vxworks-ppc750 vxworks-ppc750-debug 
vxworks-ppc860 vxworks-ppcgen vxworks-simlinux 

NOTE: If in doubt, on Unix-ish systems use './config'.
Configuring OpenSSL version 1.1.1d (0x1010104fL) for linux-armv7l
Using os-specific seed configuration
FAILURE: scripts/build openssl:host during configure_host (package.mk)
*********** FAILED COMMAND ***********
./Configure $PKG_CONFIGURE_OPTS_HOST $PKG_CONFIGURE_OPTS_SHARED linux-$(uname -m) $CFLAGS $LDFLAGS
**************************************
FAILURE: scripts/build openssl:host has failed!

7.log

@chewitt
Copy link
Member

chewitt commented Mar 24, 2020

We have no issue with the change in this PR but we do not support (or have any plans to support) building LE images on arm hardware; we support cross-compile of arm images from an x86_64 build host only. The -m64 error means that something is not setting the right build flags (CFLAGS probably). This is a "working as designed, so not a bug" issue so please take further commentary to the forums. Thanks.

@beta-tester
Copy link

ok... sorry for my comments here.

@catalinii
Copy link
Contributor Author

I can adjust the patch to be able to compile also on armv7 platforms. My experience is that other things will fail but at least solving one problem at a time.

@beta-tester
Copy link

beta-tester commented Mar 25, 2020

I can adjust the patch to be able to compile also on armv7 platforms. My experience is that other things will fail but at least solving one problem at a time.

@chewitt @catalinii, to me there is no need.
other packages makes problems as well to compile on a RPi.

so i switched to a PC and cross-compile the software for the RPi.
on a PC it goes so much smoother and quicker to compile.

EDIT: i corrected username.

@chewitt
Copy link
Member

chewitt commented Mar 25, 2020

To be clear, we have no objections to people finding/fixing the issues that prevent native compile on other architectures, but if there's more than a couple of nip/tuck changes needed it would be best to queue everything up and submit a single superset PR so our build-system maintainers can understand the overal picture and critique the summed changes. Sending macro changes over many PRs results in people wondering "where is this going?" and "when does this end?" and the natural and correct response will be to refuse the changes.

NB: I'm still not sure why anyone would ever want to compile LE images on ARM boards; it's going to be painfully slow compared to any x86_64 chip from the last decade :)

@catalinii
Copy link
Contributor Author

For me personally as I for not have a PC (and don't plan to buy any) compiling on arm64 is much easier than buying a cloud instance (and paying for it). If it is could compile over night in the first instance would be great...
I totally agree that compilation will be faster on x86, but getting it easier to compile on other platforms will help the users contribute faster to the project.

@chewitt
Copy link
Member

chewitt commented Mar 25, 2020

For the record, what are you building on (hardware and distro)?

@catalinii
Copy link
Contributor Author

Rockpro64 armbian buster.

My point was about multiple commits was that I may not be able to finish the job (time commitments), I can get at least few fixes out and then someone else (or me) can bridge the gap.

@catalinii
Copy link
Contributor Author

@chewitt,

I added few more patches. Most of them are fixing the rockchip build by adjusting patches.

The interesting one is d12bc7e
which I tried to keep as simple as possible.
Could you take a look and let me know if you have any comments ?

Thanks

@catalinii
Copy link
Contributor Author

Also to get it to compile I had to add qemu-user-binfmt, ld.so and libc for x64 because rk utilities are on x64 only.

Because there is no aarch64 compiler for arm platform, I think adding arm might be more difficult so I will not include it in those patches.

config/path Outdated Show resolved Hide resolved
@chewitt
Copy link
Member

chewitt commented Mar 28, 2020

btw, I noticed Merge remote-tracking branch 'upstream/master' in the log. If you rebase against upstream/master the merge commits will be dropped. Please also squash/fixup and rebase and force-push changes as you go. Also, house-style for commit messages is "package: description of change" .. makes things easier to review, thanks.

@chewitt chewitt changed the title Fix openssl build on non-x86_64 platforms Support cross-compile on non-x86_64 platforms Mar 28, 2020
@catalinii catalinii force-pushed the master branch 2 times, most recently from b8cea87 to e727734 Compare March 28, 2020 19:21
@catalinii
Copy link
Contributor Author

catalinii commented Mar 28, 2020

I cleaned a bit the patches and I think is ready to merge.

Please let me know if you have other comments.

Do you think there is a point to add to the compilation wiki steps for arm64?
apt-get install qemu-user-binfmt
copy from a x64 system the following files:
/lib64/ld-linux-x86-64.so.2 /lib/x86_64-linux-gnu/libc.so.6

@catalinii catalinii changed the title Support cross-compile on non-x86_64 platforms Support cross-compile on aarch64 platform Mar 28, 2020
config/path Outdated Show resolved Hide resolved
@catalinii catalinii force-pushed the master branch 3 times, most recently from b0eee12 to e407a33 Compare March 29, 2020 01:46
@MilhouseVH MilhouseVH dismissed their stale review March 29, 2020 02:30

Scope changed considerably since original review

@MilhouseVH MilhouseVH removed their request for review March 29, 2020 02:30
@catalinii catalinii force-pushed the master branch 2 times, most recently from f1bc3a5 to 8fd9201 Compare March 29, 2020 03:24
@catalinii
Copy link
Contributor Author

Updated.

Included also the dependencies needed for the build. Can you review that as well ?

@@ -122,6 +122,17 @@ if [ -n "${DISTRO_DEPS_PKG}" ] ; then
deps_pkg+=(${DISTRO_DEPS_PKG})
fi

# aarch64 dependencies
if [ "${MACHINE_HARDWARE_NAME}" = "aarch64" ]; then
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

scripts/checkdeps does not source config/options. It did until fairly recently, see db6d111 so you'd need to go down that rabbit hole and fix that issue before being able to source config/options again. In this case we only call scripts/checkdeps once per build, so use $(uname -m) rather than try to source config/options.

What happens if/when the soname versions (.2, .6 etc) change?

Is building qemu-x86_64 and qemu-user-binfmt an option?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I replaced with uname -m. I think it is clear that way considering that all the places checkdeps is already called already calls config/options before. As a result I have changed the commit.

Related to libc:
This is required by the rockchip utilities part of rkbin package. Considering that may not change very frequently I am not sure this will be an issue mid term.
Compiling libc for x86_64 always may be an overkill as we need to use an x86_64 gcc.

@catalinii
Copy link
Contributor Author

@MilhouseVH, please let me know if you have further questions related to the commit ?

@MilhouseVH
Copy link
Contributor

@catalinii so with this PR, what state are we in, are you able to build an image entirely on aarch64? The next step would be all addons... I'm sure there's more issues there! :)

In terms of the build system config and scripts changes, I don't have much of an issue - I am a bit uncomfortable with specific soname versions being hard coded in scripts/checkdeps as that's likely to bite us at some point (maybe we'll have to support multiple versions?) but if there's no better solution then... meh.

For the Rockchip, u-boot and other aarch64/linaro changes I can't really comment as that's not an area I'm familiar with - @chewitt, @jernejsk, @Kwiboo any thoughts?

@catalinii
Copy link
Contributor Author

I was able to build an older version of the repository (@Kwiboo's mainline-rockchip branch).
The image build that way boots perfectly on my device.

I tried to build the current master, but that fails compiling mali-midgard and is failing on x86 as well.

@catalinii
Copy link
Contributor Author

@chewitt, @jernejsk, @Kwiboo can you guys take a look ?

Thanks

@150balbes
Copy link
Contributor

@catalinii
I think using the build on the device itself is very promising and would like to participate in the development. It seems that many people do not even understand what opportunities this opens. I ran Ubuntu 18 on one of my RK3399 (Armbian-TV version with the latest 5.6 core). Added a patch. When I run the build, I get this error. As far as I understand, there is not enough package (perhaps need to add amd64 turnips to apt) ?


Copy from a working x86_64 system:
/lib64/libc.so.6
/lib/x86_64-linux-gnu/libc.so.6
**** Your system lacks the following tools needed to build ****
/lib64/ld-linux-x86-64.so.2 provided by libc6:amd64
/lib/x86_64-linux-gnu/libc.so.6 provided by libc6:amd64
**** You seem to use a ubuntu system ****
Would you like to install the needed tools? (y/n) y
Reading package lists... Done
Building dependency tree
Reading state information... Done
E: Unable to locate package libc6:amd64
E: Unable to locate package libc6:amd64
**** The following packages were not installed correctly ****
/lib64/ld-linux-x86-64.so.2 provided by libc6:amd64
/lib/x86_64-linux-gnu/libc.so.6 provided by libc6:amd64


*********** FAILED COMMAND ***********
${SCRIPTS}/checkdeps


Makefile:12: recipe for target 'image' failed
make: *** [image] Error 1

@150balbes
Copy link
Contributor

I did not carefully read the previous message (where it says that this should be done manually). Added these files and the build started. :)

If can resolve the issue of distributing the build between multiple devices (cluster), this will allow to build faster than on a PC and with less power consumption :)

@150balbes
Copy link
Contributor

After fixing some small things, managed to build images for all AW + RK + AML platforms. Now I will test the operation of the build images.

Thanks for the initial commit and a kick in the right direction. :)

By the way, the build time on RK3399\4Gb RAM + NVMe (nanopc-t4) is approximately equal to the build time on a PC i7 in virtual machine mode with parameters of 4 cores, 4GB RAM, 100GB SSD. :)

@catalinii
Copy link
Contributor Author

Are there some improvement needed on top of this commit ?

@150balbes
Copy link
Contributor

I will describe what I changed, and you will decide for yourself what and how to change in the commit. :)

  1. To run on Ubuntu, I changed the package name.

deps_pkg+=(qemu)

https://github.com/LibreELEC/LibreELEC.tv/pull/4271/files#diff-02608e660344401b79d29a5733e20ab6R133

  1. Maybe this is not correct and I have something not configured, but for u-boot build (when using utilities for x86), I added a prefix.

https://github.com/150balbes/LibreELEC.tv/blob/amlogic-master/projects/ARM/devices/ARM-ALL/bootloader/install#L4

https://github.com/150balbes/LibreELEC.tv/blob/amlogic-master/projects/ARM/devices/ARM-ALL/bootloader/install#L61

https://github.com/150balbes/LibreELEC.tv/blob/amlogic-master/projects/ARM/devices/ARM-ALL/bootloader/install#L352

  1. the package (u-boot-script) has a package (u-boot-tools) in its dependencies, but it causes a build error, I removed it from the package's dependencies (u-boot-script).

The rest I didn't change and the aarch64 build was successful for all the platforms I use (Allwinner + Rockchip + Amlogic). Images collected on ARM RK3399\S922X work without problems. I checked the build of Addons, almost all of them are collected (except for 12 Addons), but I haven't checked their work yet. It would be good to automate the addition of two libraries for QEMU, for example, as an archive with auto-extracting to the right place, as in the source code.

@150balbes
Copy link
Contributor

150balbes commented Apr 9, 2020

Fixed the u-boot-tools build.

"Side" effect when switching to build on ARM, the error of building several packages for aarch64 (Pillow simplejson pycryptodome) disappeared. Now the arm and aarch64 images are identical. :)

@150balbes
Copy link
Contributor

The build for arm (32bit) passed without errors.

The full build time (along with downloading the source code) on the Odroid N2 + USB SSD was 4 hours and 50 minutes.

@catalinii
Copy link
Contributor Author

  1. for me qemu-user-binfmt installs the binfmt hooks so 2 is not needed.
    On ubuntu you don't have that qemu-user-binfmt package?
    If you have it once installed and once you have the libc.so.6 for x64 you should be able to run directly x86 binaries on your system (eg tools/loaderimage)

I did not see (3) in my environment

@150balbes
Copy link
Contributor

150balbes commented Apr 28, 2020

fix for u-boot-tools

make_host() {

if [ "${MACHINE_HARDWARE_NAME}" = "aarch64" ]; then
make defconfig
else
make qemu-x86_64_defconfig
fi
make tools-only
}

@150balbes
Copy link
Contributor

IMHO this patch contains "extra" elements that are not directly related to the build system itself (they change the data for the build of a specific platform RK3399).
It is better to remove them from PR. If @Kwiboo or someone else sends changes regarding the build for RK, this may cause an overlay.

@MilhouseVH
Copy link
Contributor

Needs a rebase.

@catalinii
Copy link
Contributor Author

@MilhouseVH, dropped the other 2 patches and rebased on the current master

Thanks

@ghost
Copy link

ghost commented May 16, 2020

@chewitt @jernejsk @Kwiboo can you guys take a look at this patch and let me know if something else needs to be added or it can be merged?

@CvH
Copy link
Member

CvH commented May 31, 2020

nobody complained further so merge it and fix possible problems if they appear

@CvH CvH merged commit cb97caf into LibreELEC:master May 31, 2020
@catalinii
Copy link
Contributor Author

Thanks @CvH ... I will test this further and provide new fixes if that is the case

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants