mailing list of musl libc
 help / color / mirror / code / Atom feed
* [musl-cross-make] [PATCH] Fix LINUX_ARCH for aarch64-* TARGET
@ 2017-08-20 20:30 Michael Forney
  2017-08-20 21:30 ` Szabolcs Nagy
  2017-10-20  7:23 ` Michael Forney
  0 siblings, 2 replies; 4+ messages in thread
From: Michael Forney @ 2017-08-20 20:30 UTC (permalink / raw)
  To: musl

'aarch64' is converted to 'arm64' in the TARGET_ARCH_MANGLED assignment,
but then LINUX_ARCH is set the first to the first linux arch which
appears in TARGET_ARCH_MANGLED. Since 'arm' is a substring of 'arm64'
and appears ahead of 'arm64' in sorted order, it gets chosen
incorrectly.

To fix this, use 'lastword' instead of 'firstword'. This should work for
all current linux architectures, but is still not perfect in the
theoretical case where the substring match is not rooted at the
beginning of TARGET_ARCH_MANGLED. So, also replace 'findstring' with an
'if' and 'filter'.
---
 litecross/Makefile | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/litecross/Makefile b/litecross/Makefile
index 371affb..46584fd 100644
--- a/litecross/Makefile
+++ b/litecross/Makefile
@@ -206,7 +206,7 @@ ifneq ($(LINUX_SRCDIR),)
 TARGET_ARCH = $(firstword $(subst -, ,$(TARGET)))
 TARGET_ARCH_MANGLED = $(patsubst i%86,x86,$(patsubst aarch64%,arm64%,$(TARGET_ARCH)))
 LINUX_ARCH_LIST = $(sort $(notdir $(wildcard $(LINUX_SRCDIR)/arch/*)))
-LINUX_ARCH = $(firstword $(foreach a,$(LINUX_ARCH_LIST),$(findstring $(a),$(TARGET_ARCH_MANGLED))))
+LINUX_ARCH = $(lastword $(foreach a,$(LINUX_ARCH_LIST),$(if $(filter $(a)%,$(TARGET_ARCH_MANGLED)),$(a))))
 ifneq ($(LINUX_ARCH),)
 all: kernel-headers
 install: install-kernel-headers
-- 
2.14.0



^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [musl-cross-make] [PATCH] Fix LINUX_ARCH for aarch64-* TARGET
  2017-08-20 20:30 [musl-cross-make] [PATCH] Fix LINUX_ARCH for aarch64-* TARGET Michael Forney
@ 2017-08-20 21:30 ` Szabolcs Nagy
  2017-10-20  7:23 ` Michael Forney
  1 sibling, 0 replies; 4+ messages in thread
From: Szabolcs Nagy @ 2017-08-20 21:30 UTC (permalink / raw)
  To: musl

* Michael Forney <mforney@mforney.org> [2017-08-20 13:30:33 -0700]:
> 'aarch64' is converted to 'arm64' in the TARGET_ARCH_MANGLED assignment,
> but then LINUX_ARCH is set the first to the first linux arch which
> appears in TARGET_ARCH_MANGLED. Since 'arm' is a substring of 'arm64'
> and appears ahead of 'arm64' in sorted order, it gets chosen
> incorrectly.
> 

yes it seems my aarch64 musl toolchain has arm kernel headers
because of this.

> To fix this, use 'lastword' instead of 'firstword'. This should work for
> all current linux architectures, but is still not perfect in the
> theoretical case where the substring match is not rooted at the
> beginning of TARGET_ARCH_MANGLED. So, also replace 'findstring' with an
> 'if' and 'filter'.
> ---
>  litecross/Makefile | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/litecross/Makefile b/litecross/Makefile
> index 371affb..46584fd 100644
> --- a/litecross/Makefile
> +++ b/litecross/Makefile
> @@ -206,7 +206,7 @@ ifneq ($(LINUX_SRCDIR),)
>  TARGET_ARCH = $(firstword $(subst -, ,$(TARGET)))
>  TARGET_ARCH_MANGLED = $(patsubst i%86,x86,$(patsubst aarch64%,arm64%,$(TARGET_ARCH)))
>  LINUX_ARCH_LIST = $(sort $(notdir $(wildcard $(LINUX_SRCDIR)/arch/*)))
> -LINUX_ARCH = $(firstword $(foreach a,$(LINUX_ARCH_LIST),$(findstring $(a),$(TARGET_ARCH_MANGLED))))
> +LINUX_ARCH = $(lastword $(foreach a,$(LINUX_ARCH_LIST),$(if $(filter $(a)%,$(TARGET_ARCH_MANGLED)),$(a))))
>  ifneq ($(LINUX_ARCH),)
>  all: kernel-headers
>  install: install-kernel-headers
> -- 
> 2.14.0


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [musl-cross-make] [PATCH] Fix LINUX_ARCH for aarch64-* TARGET
  2017-08-20 20:30 [musl-cross-make] [PATCH] Fix LINUX_ARCH for aarch64-* TARGET Michael Forney
  2017-08-20 21:30 ` Szabolcs Nagy
@ 2017-10-20  7:23 ` Michael Forney
  2017-10-25 20:08   ` Rich Felker
  1 sibling, 1 reply; 4+ messages in thread
From: Michael Forney @ 2017-10-20  7:23 UTC (permalink / raw)
  To: musl

On 2017-08-20, Michael Forney <mforney@mforney.org> wrote:
> 'aarch64' is converted to 'arm64' in the TARGET_ARCH_MANGLED assignment,
> but then LINUX_ARCH is set the first to the first linux arch which
> appears in TARGET_ARCH_MANGLED. Since 'arm' is a substring of 'arm64'
> and appears ahead of 'arm64' in sorted order, it gets chosen
> incorrectly.
>
> To fix this, use 'lastword' instead of 'firstword'. This should work for
> all current linux architectures, but is still not perfect in the
> theoretical case where the substring match is not rooted at the
> beginning of TARGET_ARCH_MANGLED. So, also replace 'findstring' with an
> 'if' and 'filter'.
> ---
>  litecross/Makefile | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/litecross/Makefile b/litecross/Makefile
> index 371affb..46584fd 100644
> --- a/litecross/Makefile
> +++ b/litecross/Makefile
> @@ -206,7 +206,7 @@ ifneq ($(LINUX_SRCDIR),)
>  TARGET_ARCH = $(firstword $(subst -, ,$(TARGET)))
>  TARGET_ARCH_MANGLED = $(patsubst i%86,x86,$(patsubst
> aarch64%,arm64%,$(TARGET_ARCH)))
>  LINUX_ARCH_LIST = $(sort $(notdir $(wildcard $(LINUX_SRCDIR)/arch/*)))
> -LINUX_ARCH = $(firstword $(foreach a,$(LINUX_ARCH_LIST),$(findstring
> $(a),$(TARGET_ARCH_MANGLED))))
> +LINUX_ARCH = $(lastword $(foreach a,$(LINUX_ARCH_LIST),$(if $(filter
> $(a)%,$(TARGET_ARCH_MANGLED)),$(a))))
>  ifneq ($(LINUX_ARCH),)
>  all: kernel-headers
>  install: install-kernel-headers
> --
> 2.14.0

Since some musl-cross-make patches are getting applied, I'm bumping
this so it doesn't get forgotten. I can also open a github PR if you
prefer.


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Re: [musl-cross-make] [PATCH] Fix LINUX_ARCH for aarch64-* TARGET
  2017-10-20  7:23 ` Michael Forney
@ 2017-10-25 20:08   ` Rich Felker
  0 siblings, 0 replies; 4+ messages in thread
From: Rich Felker @ 2017-10-25 20:08 UTC (permalink / raw)
  To: musl

On Fri, Oct 20, 2017 at 12:23:41AM -0700, Michael Forney wrote:
> On 2017-08-20, Michael Forney <mforney@mforney.org> wrote:
> > 'aarch64' is converted to 'arm64' in the TARGET_ARCH_MANGLED assignment,
> > but then LINUX_ARCH is set the first to the first linux arch which
> > appears in TARGET_ARCH_MANGLED. Since 'arm' is a substring of 'arm64'
> > and appears ahead of 'arm64' in sorted order, it gets chosen
> > incorrectly.
> >
> > To fix this, use 'lastword' instead of 'firstword'. This should work for
> > all current linux architectures, but is still not perfect in the
> > theoretical case where the substring match is not rooted at the
> > beginning of TARGET_ARCH_MANGLED. So, also replace 'findstring' with an
> > 'if' and 'filter'.
> > ---
> >  litecross/Makefile | 2 +-
> >  1 file changed, 1 insertion(+), 1 deletion(-)
> >
> > diff --git a/litecross/Makefile b/litecross/Makefile
> > index 371affb..46584fd 100644
> > --- a/litecross/Makefile
> > +++ b/litecross/Makefile
> > @@ -206,7 +206,7 @@ ifneq ($(LINUX_SRCDIR),)
> >  TARGET_ARCH = $(firstword $(subst -, ,$(TARGET)))
> >  TARGET_ARCH_MANGLED = $(patsubst i%86,x86,$(patsubst
> > aarch64%,arm64%,$(TARGET_ARCH)))
> >  LINUX_ARCH_LIST = $(sort $(notdir $(wildcard $(LINUX_SRCDIR)/arch/*)))
> > -LINUX_ARCH = $(firstword $(foreach a,$(LINUX_ARCH_LIST),$(findstring
> > $(a),$(TARGET_ARCH_MANGLED))))
> > +LINUX_ARCH = $(lastword $(foreach a,$(LINUX_ARCH_LIST),$(if $(filter
> > $(a)%,$(TARGET_ARCH_MANGLED)),$(a))))
> >  ifneq ($(LINUX_ARCH),)
> >  all: kernel-headers
> >  install: install-kernel-headers
> > --
> > 2.14.0
> 
> Since some musl-cross-make patches are getting applied, I'm bumping
> this so it doesn't get forgotten. I can also open a github PR if you
> prefer.

I think it looks right. Going to run a few smoke test builds before I
push it.

Rich


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2017-10-25 20:08 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-08-20 20:30 [musl-cross-make] [PATCH] Fix LINUX_ARCH for aarch64-* TARGET Michael Forney
2017-08-20 21:30 ` Szabolcs Nagy
2017-10-20  7:23 ` Michael Forney
2017-10-25 20:08   ` Rich Felker

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/musl/

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 NNTP newsgroup(s).