linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] Fix compilation errors when using special directory
@ 2021-12-31  7:55 cgel.zte
  2021-12-31 17:05 ` Nathan Chancellor
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: cgel.zte @ 2021-12-31  7:55 UTC (permalink / raw)
  To: masahiroy, michal.lkml, ndesaulniers; +Cc: linux-kbuild, linux-kernel, xu xin

From: xu xin <xu.xin16@zte.com.cn>

When we compile the kernel with cross compilers, if CROSS_COMPILE is
specified by the path containing special directory like '~', some
compilation error will occurs.

Here's an example:

$ make ARCH=x86_64
CROSS_COMPILE=~/x86_64_gcc9.2.0_glibc2.31.0/bin/x86_64-pc-linux-gnu- all

error:./scripts/mkcompile_h: line 64:
~/x86_64_gcc9.2.0_glibc2.31.0/bin/x86_64-pc-linux-gnu-ld: No such file or
directory

Since there are many other similar scripts using these variables, in
order to solve the problem from the source, add realpath in makefile to
turn these variables into absolute paths.

Signed-off-by: xu xin <xu.xin16@zte.com.cn>
---
 Makefile | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)

diff --git a/Makefile b/Makefile
index fe5a4d8e4ac5..cdbb747787ac 100644
--- a/Makefile
+++ b/Makefile
@@ -459,14 +459,14 @@ OBJDUMP		= llvm-objdump
 READELF		= llvm-readelf
 STRIP		= llvm-strip
 else
-CC		= $(CROSS_COMPILE)gcc
-LD		= $(CROSS_COMPILE)ld
-AR		= $(CROSS_COMPILE)ar
-NM		= $(CROSS_COMPILE)nm
-OBJCOPY		= $(CROSS_COMPILE)objcopy
-OBJDUMP		= $(CROSS_COMPILE)objdump
-READELF		= $(CROSS_COMPILE)readelf
-STRIP		= $(CROSS_COMPILE)strip
+CC		= $(realpath $(CROSS_COMPILE))gcc
+LD		= $(realpath $(CROSS_COMPILE))ld
+AR		= $(realpath $(CROSS_COMPILE))ar
+NM		= $(realpath $(CROSS_COMPILE))nm
+OBJCOPY		= $(realpath $(CROSS_COMPILE))objcopy
+OBJDUMP		= $(realpath $(CROSS_COMPILE))objdump
+READELF		= $(realpath $(CROSS_COMPILE))readelf
+STRIP		= $(realpath $(CROSS_COMPILE))strip
 endif
 RUSTC		= rustc
 RUSTDOC		= rustdoc
-- 
2.25.1


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

* Re: [PATCH] Fix compilation errors when using special directory
  2021-12-31  7:55 [PATCH] Fix compilation errors when using special directory cgel.zte
@ 2021-12-31 17:05 ` Nathan Chancellor
  2022-01-03  7:29 ` Masahiro Yamada
  2022-01-04 18:07 ` Nick Desaulniers
  2 siblings, 0 replies; 4+ messages in thread
From: Nathan Chancellor @ 2021-12-31 17:05 UTC (permalink / raw)
  To: cgel.zte
  Cc: masahiroy, michal.lkml, ndesaulniers, linux-kbuild, linux-kernel, xu xin

On Fri, Dec 31, 2021 at 07:55:51AM +0000, cgel.zte@gmail.com wrote:
> From: xu xin <xu.xin16@zte.com.cn>
> 
> When we compile the kernel with cross compilers, if CROSS_COMPILE is
> specified by the path containing special directory like '~', some
> compilation error will occurs.
> 
> Here's an example:
> 
> $ make ARCH=x86_64
> CROSS_COMPILE=~/x86_64_gcc9.2.0_glibc2.31.0/bin/x86_64-pc-linux-gnu- all
> 
> error:./scripts/mkcompile_h: line 64:
> ~/x86_64_gcc9.2.0_glibc2.31.0/bin/x86_64-pc-linux-gnu-ld: No such file or
> directory
> 
> Since there are many other similar scripts using these variables, in
> order to solve the problem from the source, add realpath in makefile to
> turn these variables into absolute paths.

This is not going to work for the traditional approach of CROSS_COMPILE
being just a triple, rather than a full path plus a triple, because

$(realpath $(CROSS_COMPILE))

is going to evaluate to nothing in that case:

$ make -skj"$(nproc)" ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- defconfig all
warning: ld does not support --fix-cortex-a53-843419; kernel may be susceptible to erratum
ld: unrecognised emulation mode: aarch64linux
Supported emulations: elf_x86_64 elf32_x86_64 elf_i386 elf_iamcu elf_l1om elf_k1om i386pep i386pe
make[2]: *** [arch/arm64/kernel/vdso/Makefile:57: arch/arm64/kernel/vdso/vdso.so.dbg] Error 1
...

Why not just change '~' to '$HOME' in your build scripts so that it is
evaluated before the make command begins?

> Signed-off-by: xu xin <xu.xin16@zte.com.cn>
> ---
>  Makefile | 16 ++++++++--------
>  1 file changed, 8 insertions(+), 8 deletions(-)
> 
> diff --git a/Makefile b/Makefile
> index fe5a4d8e4ac5..cdbb747787ac 100644
> --- a/Makefile
> +++ b/Makefile
> @@ -459,14 +459,14 @@ OBJDUMP		= llvm-objdump
>  READELF		= llvm-readelf
>  STRIP		= llvm-strip
>  else
> -CC		= $(CROSS_COMPILE)gcc
> -LD		= $(CROSS_COMPILE)ld
> -AR		= $(CROSS_COMPILE)ar
> -NM		= $(CROSS_COMPILE)nm
> -OBJCOPY		= $(CROSS_COMPILE)objcopy
> -OBJDUMP		= $(CROSS_COMPILE)objdump
> -READELF		= $(CROSS_COMPILE)readelf
> -STRIP		= $(CROSS_COMPILE)strip
> +CC		= $(realpath $(CROSS_COMPILE))gcc
> +LD		= $(realpath $(CROSS_COMPILE))ld
> +AR		= $(realpath $(CROSS_COMPILE))ar
> +NM		= $(realpath $(CROSS_COMPILE))nm
> +OBJCOPY		= $(realpath $(CROSS_COMPILE))objcopy
> +OBJDUMP		= $(realpath $(CROSS_COMPILE))objdump
> +READELF		= $(realpath $(CROSS_COMPILE))readelf
> +STRIP		= $(realpath $(CROSS_COMPILE))strip
>  endif
>  RUSTC		= rustc
>  RUSTDOC		= rustdoc
> -- 
> 2.25.1
> 

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

* Re: [PATCH] Fix compilation errors when using special directory
  2021-12-31  7:55 [PATCH] Fix compilation errors when using special directory cgel.zte
  2021-12-31 17:05 ` Nathan Chancellor
@ 2022-01-03  7:29 ` Masahiro Yamada
  2022-01-04 18:07 ` Nick Desaulniers
  2 siblings, 0 replies; 4+ messages in thread
From: Masahiro Yamada @ 2022-01-03  7:29 UTC (permalink / raw)
  To: cgel.zte
  Cc: Michal Marek, Nick Desaulniers, Linux Kbuild mailing list,
	Linux Kernel Mailing List, xu xin

On Fri, Dec 31, 2021 at 4:56 PM <cgel.zte@gmail.com> wrote:
>
> From: xu xin <xu.xin16@zte.com.cn>
>
> When we compile the kernel with cross compilers, if CROSS_COMPILE is
> specified by the path containing special directory like '~', some
> compilation error will occurs.
>
> Here's an example:
>
> $ make ARCH=x86_64
> CROSS_COMPILE=~/x86_64_gcc9.2.0_glibc2.31.0/bin/x86_64-pc-linux-gnu- all
>
> error:./scripts/mkcompile_h: line 64:
> ~/x86_64_gcc9.2.0_glibc2.31.0/bin/x86_64-pc-linux-gnu-ld: No such file or
> directory
>
> Since there are many other similar scripts using these variables, in
> order to solve the problem from the source, add realpath in makefile to
> turn these variables into absolute paths.
>
> Signed-off-by: xu xin <xu.xin16@zte.com.cn>


This depends on what shell you are using.


If you use a modern shell like bash,
~ is expanded into the home directory path
on the shell side.

So, Make will see the absolute path.
In contrast, dash does not expand ~.


[Test code]
$(warning CROSS_COMPILE is $(CROSS_COMPILE))
all:
        @:



[Result]
masahiro@grover:/tmp$ bash
masahiro@grover:/tmp$ make
CROSS_COMPILE=~/x86_64_gcc9.2.0_glibc2.31.0/bin/x86_64-pc-linux-gnu-
all
Makefile:1: CROSS_COMPILE is
/home/masahiro/x86_64_gcc9.2.0_glibc2.31.0/bin/x86_64-pc-linux-gnu-
masahiro@grover:/tmp$ dash
$ make CROSS_COMPILE=~/x86_64_gcc9.2.0_glibc2.31.0/bin/x86_64-pc-linux-gnu- all
Makefile:1: CROSS_COMPILE is
~/x86_64_gcc9.2.0_glibc2.31.0/bin/x86_64-pc-linux-gnu-





Moreover, your patch does not work at all because
the $(realpath ) built-in function does not expand ~.

~ is a shell's special character (and only some shells recognize it).
GNU Make is completely agnostic about such a character.



If you are using such a shell that does not understand ~,
as Nathan suggested, you can use $HOME.



> ---
>  Makefile | 16 ++++++++--------
>  1 file changed, 8 insertions(+), 8 deletions(-)
>
> diff --git a/Makefile b/Makefile
> index fe5a4d8e4ac5..cdbb747787ac 100644
> --- a/Makefile
> +++ b/Makefile
> @@ -459,14 +459,14 @@ OBJDUMP           = llvm-objdump
>  READELF                = llvm-readelf
>  STRIP          = llvm-strip
>  else
> -CC             = $(CROSS_COMPILE)gcc
> -LD             = $(CROSS_COMPILE)ld
> -AR             = $(CROSS_COMPILE)ar
> -NM             = $(CROSS_COMPILE)nm
> -OBJCOPY                = $(CROSS_COMPILE)objcopy
> -OBJDUMP                = $(CROSS_COMPILE)objdump
> -READELF                = $(CROSS_COMPILE)readelf
> -STRIP          = $(CROSS_COMPILE)strip
> +CC             = $(realpath $(CROSS_COMPILE))gcc
> +LD             = $(realpath $(CROSS_COMPILE))ld
> +AR             = $(realpath $(CROSS_COMPILE))ar
> +NM             = $(realpath $(CROSS_COMPILE))nm
> +OBJCOPY                = $(realpath $(CROSS_COMPILE))objcopy
> +OBJDUMP                = $(realpath $(CROSS_COMPILE))objdump
> +READELF                = $(realpath $(CROSS_COMPILE))readelf
> +STRIP          = $(realpath $(CROSS_COMPILE))strip
>  endif
>  RUSTC          = rustc
>  RUSTDOC                = rustdoc
> --
> 2.25.1
>


--
Best Regards
Masahiro Yamada

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

* Re: [PATCH] Fix compilation errors when using special directory
  2021-12-31  7:55 [PATCH] Fix compilation errors when using special directory cgel.zte
  2021-12-31 17:05 ` Nathan Chancellor
  2022-01-03  7:29 ` Masahiro Yamada
@ 2022-01-04 18:07 ` Nick Desaulniers
  2 siblings, 0 replies; 4+ messages in thread
From: Nick Desaulniers @ 2022-01-04 18:07 UTC (permalink / raw)
  To: cgel.zte; +Cc: masahiroy, michal.lkml, linux-kbuild, linux-kernel, xu xin

On Thu, Dec 30, 2021 at 11:55 PM <cgel.zte@gmail.com> wrote:
>
> From: xu xin <xu.xin16@zte.com.cn>
>
> When we compile the kernel with cross compilers, if CROSS_COMPILE is
> specified by the path containing special directory like '~', some
> compilation error will occurs.
>
> Here's an example:
>
> $ make ARCH=x86_64
> CROSS_COMPILE=~/x86_64_gcc9.2.0_glibc2.31.0/bin/x86_64-pc-linux-gnu- all

I guess you could replace ~ with `$(realpath ...)` in the above
command line invocation of make?
-- 
Thanks,
~Nick Desaulniers

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

end of thread, other threads:[~2022-01-04 18:07 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-12-31  7:55 [PATCH] Fix compilation errors when using special directory cgel.zte
2021-12-31 17:05 ` Nathan Chancellor
2022-01-03  7:29 ` Masahiro Yamada
2022-01-04 18:07 ` Nick Desaulniers

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).