On Mon, Feb 15, 2021 at 7:49 AM Punit Agrawal <[email protected]>
wrote:

> When cross compiling, it would be good to support the following two
> cases -
>
> * Distro provided cross compiler + libraries - This is the case when a
>   distro with multi-arch support (e.g., Debian derivaties)
>
> * Local libraries installation - Needed when the distro doesn't
>   support multi-arch or there's a need to use local installs
>
> Update the libgcc detection to query the compiler regarding the
> location of the libraries - provided the correct CROSS_PREFIX is
> specified. If this fails to find the library, fall back to the hard
> coded location. Also, add a message to inform the user about the
> fallback usage.
>
> Signed-off-by: Punit Agrawal <[email protected]>
> ---
>  scripts/build | 17 ++++++++---------
>  1 file changed, 8 insertions(+), 9 deletions(-)
>
> diff --git a/scripts/build b/scripts/build
> index 5fdcc7a88214..88f48f5e0582 100755
> --- a/scripts/build
> +++ b/scripts/build
> @@ -271,15 +271,14 @@ kernel_end=$(($loader_size+2097151 & ~2097151))
>  cd $OUT
>
>  host_arch=$(uname -m)
> -if [[ "$host_arch" == "x86_64" && "$arch" == 'aarch64' ]]; then
> -       libgcc_s_path=$(${CROSS_PREFIX:-aarch64-linux-gnu-}gcc
> -print-file-name=libgcc_s.so.1)
> -       if [[ "$libgcc_s_path" == "libgcc_s.so.1" ]]; then
> -               libgcc_s_dir=$(readlink -f
> ../downloaded_packages/aarch64/gcc/install/lib64)
> -       else
> -               libgcc_s_dir=$(dirname $(readlink -f $libgcc_s_path))
> -       fi
> -else
> -       libgcc_s_dir=$(dirname $(readlink -f $(gcc
> -print-file-name=libgcc_s.so.1)))
> +CC=${CROSS_PREFIX}gcc
>
On Fedora I cross-compile like this:
./scripts/build mode=release image=tests fs=rofs -j$(nproc) arch=aarch64
--create-disk
So in my case the CROSS_PREFIX is not set at all this would use x86_64 gcc
and fix x86_64 version og libgcc_s.so


> +libgcc_s_dir=$(dirname $(readlink -f $(${CC}
> -print-file-name=libgcc_s.so.1)))
> +if [[ "$libgcc_s_path" == "libgcc_s.so.1" ]]; then
>
Did you mean  libgcc_s_dir? This also probably would not be correct.

> +       cat <<-EOF
> +       Unable to resolve libgcc_s.so.1 using "${CC}".
> +       Looking in ../downloaded_packages/aarch64/gcc/install/lib64
> +       EOF
> +       libgcc_s_dir=$(readlink -f
> ../downloaded_packages/aarch64/gcc/install/lib64)
>  fi

All in all, this does not work on Fedora.

I think this is a more correct version:

*diff --git a/scripts/build b/scripts/build*

*index 5fdcc7a8..b07dfd6e 100755*

*--- a/scripts/build*

*+++ b/scripts/build*

@@ -272,14 +272,20 @@ cd $OUT



 host_arch=$(uname -m)

 if [[ "$host_arch" == "x86_64" && "$arch" == 'aarch64' ]]; then

-       libgcc_s_path=$(${CROSS_PREFIX:-aarch64-linux-gnu-}gcc
-print-file-name=libgcc_s.so.1)

-       if [[ "$libgcc_s_path" == "libgcc_s.so.1" ]]; then

-               libgcc_s_dir=$(readlink -f
../downloaded_packages/aarch64/gcc/install/lib64)

-       else

-               libgcc_s_dir=$(dirname $(readlink -f $libgcc_s_path))

-       fi

+       CC=${CROSS_PREFIX:-aarch64-linux-gnu-}gcc

+else

+       CC=gcc

+fi

+

+libgcc_s_path=$(${CC} -print-file-name=libgcc_s.so.1)

+if [[ "$libgcc_s_path" == "libgcc_s.so.1" ]]; then

+       cat <<-EOF

+       Unable to resolve libgcc_s.so.1 using "${CC}".

+       Looking in ../downloaded_packages/aarch64/gcc/install/lib64

+       EOF

+       libgcc_s_dir=$(readlink -f
../downloaded_packages/aarch64/gcc/install/lib64)

 else

-       libgcc_s_dir=$(dirname $(readlink -f $(gcc
-print-file-name=libgcc_s.so.1)))

+       libgcc_s_dir=$(dirname $(readlink -f $libgcc_s_path))

 fi



 if [ "$export" != "none" ]; then



 if [ "$export" != "none" ]; then
> --
> 2.29.2
>
>

-- 
You received this message because you are subscribed to the Google Groups "OSv 
Development" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/osv-dev/CAL9cFfNO_dC91FbPm8Avk1Zds%2B2DPQe8ObYrybkd%3DDZa%2B_Y6kA%40mail.gmail.com.

Reply via email to