[2/4] gcc-cross-canadian: Install gcc/g++ wrappers for musl

Submitted by Khem Raj on Aug. 20, 2020, 6:57 a.m. | Patch ID: 175469

Details

Message ID 20200820065727.2589128-2-raj.khem@gmail.com
State New
Headers show

Commit Message

Khem Raj Aug. 20, 2020, 6:57 a.m.
gcc needs -mmusl option to be passed in SDK since we ship crossdk compiler
configured for glibc by default, this helps in creating correct
compiler defaults for musl based SDK compilers

[YOCTO #13459]

Signed-off-by: Khem Raj <raj.khem@gmail.com>
Cc: Leon Woestenberg <leon@sidebranch.com>
---
 .../gcc/gcc-cross-canadian.inc                | 20 +++++++++++++++++++
 1 file changed, 20 insertions(+)

Patch hide | download patch | download mbox

diff --git a/meta/recipes-devtools/gcc/gcc-cross-canadian.inc b/meta/recipes-devtools/gcc/gcc-cross-canadian.inc
index 553ef7fe62..49127192e5 100644
--- a/meta/recipes-devtools/gcc/gcc-cross-canadian.inc
+++ b/meta/recipes-devtools/gcc/gcc-cross-canadian.inc
@@ -139,6 +139,26 @@  do_install () {
 	chown -R root:root ${D}
 	
 	cross_canadian_bindirlinks
+
+	for i in linux ${CANADIANEXTRAOS}
+	do
+		for v in ${CANADIANEXTRAVENDOR}
+		do
+			d=${D}${bindir}/../${TARGET_ARCH}$v-$i
+			install -d $d
+			for j in ${TARGET_PREFIX}gcc${EXEEXT} ${TARGET_PREFIX}g++${EXEEXT}
+			do
+				p=${TARGET_ARCH}$v-$i-`echo $j | sed -e s,${TARGET_PREFIX},,`
+				case $i in
+				*musl*)
+					echo "#!/usr/bin/env sh" > $d/$p
+					echo "exec \`dirname \$0\`/../${TARGET_SYS}/$j -mmusl \$@" >> $d/$p
+					chmod 0755 $d/$p
+					;;
+				esac
+			done
+		done
+	done
 }
 
 ELFUTILS = "nativesdk-elfutils"

Comments

Leon Woestenberg Aug. 20, 2020, 12:29 p.m.
Hi Khem,

Thanks for looking into this. I applied your patch on top of our zeus
branch (I think the issue is in zeus, dunfell, master).

On Thu, Aug 20, 2020 at 8:57 AM Khem Raj <raj.khem@gmail.com> wrote:
>
> gcc needs -mmusl option to be passed in SDK since we ship crossdk compiler
> configured for glibc by default, this helps in creating correct
> compiler defaults for musl based SDK compilers
>
> [YOCTO #13459]
>
> diff --git a/meta/recipes-devtools/gcc/gcc-cross-canadian.inc b/meta/recipes-devtools/gcc/gcc-cross-canadian.inc

Can you elaborate why this is the proper solution over just
TARGET_CC_ARCH_append_linux-musl = " --mmusl" in
toolchain-scripts.bbclass?

> +
> +       for i in linux ${CANADIANEXTRAOS}

Why keep linux in here?

> +       do
> +               for v in ${CANADIANEXTRAVENDOR}
> +               do
> +                       d=${D}${bindir}/../${TARGET_ARCH}$v-$i
> +                       install -d $d

Hmm, even for the non-musl case?

> +                       for j in ${TARGET_PREFIX}gcc${EXEEXT} ${TARGET_PREFIX}g++${EXEEXT}
> +                       do
> +                               p=${TARGET_ARCH}$v-$i-`echo $j | sed -e s,${TARGET_PREFIX},,`
> +                               case $i in
> +                               *musl*)
> +                                       echo "#!/usr/bin/env sh" > $d/$p

$d/$p already exists at this point, and it's a softlink to the actual gcc.
The redirected output will end up in the *target* of the softlink;
this replaces the actual gcc compiler binary by a script, which calls
itself.
It ends up being a recursive invocation.

I have added rm -f $d/$p above to fix this locally, while testing.

> +                                       echo "exec \`dirname \$0\`/../${TARGET_SYS}/$j -mmusl \$@" >> $d/$p
> +                                       chmod 0755 $d/$p
> +                                       ;;

Regards,

Leon.
-=-=-=-=-=-=-=-=-=-=-=-
Links: You receive all messages sent to this group.

View/Reply Online (#141669): https://lists.openembedded.org/g/openembedded-core/message/141669
Mute This Topic: https://lists.openembedded.org/mt/76303186/3617530
Group Owner: openembedded-core+owner@lists.openembedded.org
Unsubscribe: https://lists.openembedded.org/g/openembedded-core/unsub  [oe-patchwork@oe-patch.openembedded.org]
-=-=-=-=-=-=-=-=-=-=-=-
Leon Woestenberg Aug. 20, 2020, 3:15 p.m.
With the rm -f $d/$p added, the links generated earlier are first
removed, then replaced by the wrapper, as expected.
We have tested this to work correctly.

(This fixes the bug where the first echo ... > would write to the
softlink target, the actual gcc binary.)

This is what I have locally in my meta-fixes overlay:

meta-fixes/recipes-devtools/gcc/gcc-cross-canadian_%.bbappend:
do_install_append () {
       for i in linux ${CANADIANEXTRAOS}
       do
               for v in ${CANADIANEXTRAVENDOR}
               do
                       d=${D}${bindir}/../${TARGET_ARCH}$v-$i
                       install -d $d
                       for j in ${TARGET_PREFIX}gcc${EXEEXT}
${TARGET_PREFIX}g++${EXEEXT}
                       do
                               p=${TARGET_ARCH}$v-$i-`echo $j | sed -e
s,${TARGET_PREFIX},,`
                               case $i in
                               *musl*)
                                       # %d/$p is a link to the
compiler, if we redirect output to it, the target will be overwritten
                                       rm -f $d/$p
                                       echo "#!/usr/bin/env sh" > $d/$p
                                       echo "exec \`dirname
\$0\`/../${TARGET_SYS}/$j -mmusl \$@" >> $d/$p
                                       chmod 0755 $d/$p
                                       ;;
                               esac
                       done
               done
       done
}

Regards.

Leon.
-=-=-=-=-=-=-=-=-=-=-=-
Links: You receive all messages sent to this group.

View/Reply Online (#141673): https://lists.openembedded.org/g/openembedded-core/message/141673
Mute This Topic: https://lists.openembedded.org/mt/76303186/3617530
Group Owner: openembedded-core+owner@lists.openembedded.org
Unsubscribe: https://lists.openembedded.org/g/openembedded-core/unsub  [oe-patchwork@oe-patch.openembedded.org]
-=-=-=-=-=-=-=-=-=-=-=-
Khem Raj Aug. 20, 2020, 5:05 p.m.
On Thu, Aug 20, 2020 at 5:29 AM Leon Woestenberg <leon@sidebranch.com> wrote:
>
> Hi Khem,
>
> Thanks for looking into this. I applied your patch on top of our zeus
> branch (I think the issue is in zeus, dunfell, master).
>
> On Thu, Aug 20, 2020 at 8:57 AM Khem Raj <raj.khem@gmail.com> wrote:
> >
> > gcc needs -mmusl option to be passed in SDK since we ship crossdk compiler
> > configured for glibc by default, this helps in creating correct
> > compiler defaults for musl based SDK compilers
> >
> > [YOCTO #13459]
> >
> > diff --git a/meta/recipes-devtools/gcc/gcc-cross-canadian.inc b/meta/recipes-devtools/gcc/gcc-cross-canadian.inc
>
> Can you elaborate why this is the proper solution over just
> TARGET_CC_ARCH_append_linux-musl = " --mmusl" in
> toolchain-scripts.bbclass?

this helps in keeping signatures the same when building SDK for musl
as well as glibc, changing TARGET_CC_ARCH based on target OS means
signatures will change for sdk environment recipe.

>
> > +
> > +       for i in linux ${CANADIANEXTRAOS}
>
> Why keep linux in here?
>
> > +       do
> > +               for v in ${CANADIANEXTRAVENDOR}
> > +               do
> > +                       d=${D}${bindir}/../${TARGET_ARCH}$v-$i
> > +                       install -d $d
>
> Hmm, even for the non-musl case?

this whole logic is taken from cross-canadian bbclass.

>
> > +                       for j in ${TARGET_PREFIX}gcc${EXEEXT} ${TARGET_PREFIX}g++${EXEEXT}
> > +                       do
> > +                               p=${TARGET_ARCH}$v-$i-`echo $j | sed -e s,${TARGET_PREFIX},,`
> > +                               case $i in
> > +                               *musl*)
> > +                                       echo "#!/usr/bin/env sh" > $d/$p
>
> $d/$p already exists at this point, and it's a softlink to the actual gcc.
> The redirected output will end up in the *target* of the softlink;
> this replaces the actual gcc compiler binary by a script, which calls
> itself.
> It ends up being a recursive invocation.
>
> I have added rm -f $d/$p above to fix this locally, while testing.

you should have tried v2

>
> > +                                       echo "exec \`dirname \$0\`/../${TARGET_SYS}/$j -mmusl \$@" >> $d/$p
> > +                                       chmod 0755 $d/$p
> > +                                       ;;
>
> Regards,
>
> Leon.
-=-=-=-=-=-=-=-=-=-=-=-
Links: You receive all messages sent to this group.

View/Reply Online (#141677): https://lists.openembedded.org/g/openembedded-core/message/141677
Mute This Topic: https://lists.openembedded.org/mt/76303186/3617530
Group Owner: openembedded-core+owner@lists.openembedded.org
Unsubscribe: https://lists.openembedded.org/g/openembedded-core/unsub  [oe-patchwork@oe-patch.openembedded.org]
-=-=-=-=-=-=-=-=-=-=-=-