public inbox for crossgcc@sourceware.org
 help / color / mirror / Atom feed
From: "Yann E. MORIN" <yann.morin.1998@anciens.enib.fr>
To: crossgcc@sourceware.org
Cc: Konrad Eisele <konrad@gaisler.com>
Subject: Re: [PATCH 1/1] Add multilib build support for libc target. Libc is build <multilib>-times in seperate sysroot directories. In a last step links are created to reflect the expected multilib structure.
Date: Fri, 23 Dec 2011 23:22:00 -0000	[thread overview]
Message-ID: <201112240022.18409.yann.morin.1998@anciens.enib.fr> (raw)
In-Reply-To: <1321267079-14623-1-git-send-email-konrad@gaisler.com>

Konrad, All,

I am slowly and not-so-smoothly coming up with a sane situation wrt the
multilib patch, but there are still a few quirks I don't get right.

First, I split the code so it is more manageable. You can check it with:

    hg qclone -p http://crosstool-ng.org/hg/crosstool-ng/ct-ng.multilib  \
                 http://crosstool-ng.org/hg/crosstool-ng                 \
                 ct-ng.multilib
    cd ct-ng.multilib
    hg qpush -a

Note, this is a WIP:
 - the last patch is just testing fixes, and is not applied (it's guarded);
 - the penultimate patch (the last one applied) is not clean yet, and I may
   split it further to ease testing.

Second, I have some difficulties understanding the do_libc_backend_rearrange
function. See below.

On Monday 14 November 2011 11:37:59 Konrad Eisele wrote:
[--SNIP--]
> diff --git a/scripts/build/libc/glibc-eglibc.sh-common b/scripts/build/libc/glibc-eglibc.sh-common
> index 2af3a9a..2c77fbf 100644
> --- a/scripts/build/libc/glibc-eglibc.sh-common
> +++ b/scripts/build/libc/glibc-eglibc.sh-common
[--SNIP--]
> +# installation is done into ${CT_SYSROOT_DIR}/${dir}. The multilib prefix has to be included
> +# to reflect the runtime setting.
> +do_libc_backend_rearrange() {
> +    local libc_mode
> +    
> +    while [ $# -ne 0 ]; do
> +        eval "${1// /\\ }"
> +        shift
> +    done
> +    
> +    if [ "${libc_mode}" = "final" ]; then
> +        cross_cc=$(CT_Which "${CT_TARGET}-gcc")
> +        for i in `${cross_cc} --print-multi-lib 2>/dev/null`; do

Can you elaborate what you are trying to achieve with this big loop?
I mean, I can read the code, and I could probably end up making it work,
but could you explain in human-readable form the idea behind this code?

From what I see it does absolutely nothing, because ...

> +           dir="${i%%;*}"
> +          bdir="$(echo ${dir} | ${sed} -r -e 's:/:\\\\/:g')"
> +           if [ "${dir}" != "." ]; then 
> +               flags="$(echo $i | ${sed} -r -e 's/^[^;]*;//' -e 's/@/ -/g')";
> +               CT_DoStep DEBUG "Fixing up multilib location ${CT_SYSROOT_DIR}/${dir}/lib to ${CT_SYSROOT_DIR}/lib/${dir}"
> +               mkdir -p ${CT_SYSROOT_DIR}/lib/${dir}
> +               mkdir -p ${CT_SYSROOT_DIR}/usr/lib/${dir}
> +
> +               # recreate the symbolic links for multilib 
> +               for f in $(find ${CT_SYSROOT_DIR}/usr/lib/${dir}/ -type l -maxdepth 1); do

... of the 'find' here, that scans two newly-created directories (just
above), so they are empty.

Did you mean to scan "${dir}/usr/lib" and not "usr/lib/${dir}" ?

And what about "${dir}/lib" ?

Besides, the options ordering to the 'find' command is wrong, and 'find'
complains loudly. No problem, fixed here.

> +                   fn=`basename $f`
> +                   ln=`readlink $f`
> +                   ln=`basename $ln`
> +		   # go toward root. Count the numer of "/" and asseble a "../.." prefix 
> +                   pre=$( echo ${dir} | awk '{r="";
> +		       c=split($0,b,"/");
> +		       for(i=0;i<c;i++){
> +		           if(i!=0){r=r "/";}
> +			   r=r "..";
> +		       };
> +		       printf("%s",r);
> +		   }')
> +		   CT_Pushd "${CT_SYSROOT_DIR}/usr/lib/${dir}/"
> +                   ln -sf ../../${pre}/lib/${dir}/$ln $fn
> +		   CT_Popd
> +               done
> +
> +               # rewrite the library multiplexers
> +               for l in libc libpthread libgcc_s; do
> +                   for d in lib/${dir} usr/lib/${dir}; do
> +                       if [ -f "${CT_SYSROOT_DIR}/${d}/${l}.so" -a ! -L ${CT_SYSROOT_DIR}/${d}/${l}.so ]; then
> +                           if [ ! -f "${CT_SYSROOT_DIR}/${d}/${l}.so_ori_i" ]; then
> +                               cp ${CT_SYSROOT_DIR}/${d}/${l}.so ${CT_SYSROOT_DIR}/${d}/${l}.so_ori_i
> +                               cat ${CT_SYSROOT_DIR}/${d}/${l}.so_ori_i | ${sed} -r -e "s/\/lib\/$l/\/lib\/$bdir\/$l/g" > ${CT_SYSROOT_DIR}/${d}/${l}.so

With this sed expression, you are not rewriting the dynamic linker path,
which means a multilib variant still uses the default "ld.so".

I think the following sed-expr does the trick (and does not require
the '/' mangling done above):
    "s:/lib/:/lib/${dir}/:g;"

(mangling ':' in ${dir} is not needed, the dirname can not contain a ':',
as ':' is the multilib separator in "gcc -print-multi-lib").

> +			   else
> +			       CT_DoLog WARN "${CT_SYSROOT_DIR}/${d}/${l}.so has already been patched, skipping"
> +                           fi
> +                       fi
> +                   done
> +               done
> +               CT_EndStep
> +           fi
> +        done;

In the end, it leaves everything in "sysroot/${dir}".
It would make much more sense to carefully move the libs in their correct
place, that is:
 - move everything from "sysroot/${dir}/lib"     -> "sysroot/lib/${dir}"
                    and "sysroot/${dir}/usr/lib" -> "sysroot/usr/lib/${dir}"
 - get rid of "sysroot/${dir}" alltogether

That's because gcc will search for things in "sysroot/{usr/,}lib/${dir}/",
not in "sysroot/${dir}/{usr/,}lib/"

Of course, we can go with the symlinks first; once that works, we can look
into doing the move and clean-up.

[--SNIP--]
>      case "${CT_ARCH_FLOAT_HW},${CT_ARCH_FLOAT_SW}" in
> -        y,) extra_config+=("--with-fp");;
> +        y,) # if it is a <multilib> build then check if -msoft-float is given
> +	    if [ "x`expr "${extra_flags}" : '.*-msoft-float.*'`" != "x0" ]; then
> +	    	extra_config+=("--with-fp=no");
> +	    else
> +	    	extra_config+=("--with-fp");
> +	    fi
> +	    ;;
>          ,y) extra_config+=("--without-fp");;
>      esac

Floats are not the only thing we have to account for. For example, some
archs can define big/little multilib. And most probably other stuff
as well...

Well... Time for some rejoicing !
Merry X-Mas to All, and a Happy New Year! Cheers !

Regards,
Yann E. MORIN.

-- 
.-----------------.--------------------.------------------.--------------------.
|  Yann E. MORIN  | Real-Time Embedded | /"\ ASCII RIBBON | Erics' conspiracy: |
| +33 662 376 056 | Software  Designer | \ / CAMPAIGN     |  ___               |
| +33 223 225 172 `------------.-------:  X  AGAINST      |  \e/  There is no  |
| http://ymorin.is-a-geek.org/ | _/*\_ | / \ HTML MAIL    |   v   conspiracy.  |
'------------------------------^-------^------------------^--------------------'

--
For unsubscribe information see http://sourceware.org/lists.html#faq

  parent reply	other threads:[~2011-12-23 23:22 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-11-14 10:45 Konrad Eisele
2011-12-12 23:07 ` [PATCH 1/1] Add multilib build support for libc target Yann E. MORIN
2011-12-13  8:38   ` Konrad Eisele
2011-12-13 17:15     ` Yann E. MORIN
2011-12-23 23:22 ` Yann E. MORIN [this message]
2011-12-24 21:10   ` [PATCH 1/1] Add multilib build support for libc target. Libc is build <multilib>-times in seperate sysroot directories. In a last step links are created to reflect the expected multilib structure konrad.gaisler
2011-12-26 16:57     ` Yann E. MORIN
2011-12-26 19:03       ` konrad.gaisler
2011-12-26 21:30         ` Yann E. MORIN
2011-12-26 17:29     ` Yann E. MORIN
2011-12-27 23:57   ` [PATCH 1/1] Add multilib build support [...] Yann E. MORIN
2011-12-31 18:01   ` Yann E. MORIN
2012-01-02  7:17     ` konrad.gaisler
  -- strict thread matches above, loose matches on Subject: below --
2011-11-14 10:38 simple multilib option Konrad Eisele
2011-11-14 10:55 ` [PATCH 1/1] Add multilib build support for libc target. Libc is build <multilib>-times in seperate sysroot directories. In a last step links are created to reflect the expected multilib structure Konrad Eisele

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=201112240022.18409.yann.morin.1998@anciens.enib.fr \
    --to=yann.morin.1998@anciens.enib.fr \
    --cc=crossgcc@sourceware.org \
    --cc=konrad@gaisler.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).