Skip to contentSkip to conversation

Makefile: fix empty MK_ARCH when using ccache

PATCH In review Quentin Schulz 4 participants 5 messages Nov 11, 2024 – Nov 15, 2024 Kbuild

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Makefile: fix empty MK_ARCH when using ccache

From: Quentin Schulz <[email protected]>

One can use ccache by prefixing the typical CROSS_COMPILE value with "ccache " (e.g. "ccache aarch64-gnu-linux-" for Aarch64). This however makes the MK_ARCH empty because sed won't find a match anymore since it expects the CROSS_COMPILE value to start with the actual toolchain (with an unlimited number of white spaces before).

This is failing builds since commit 7506c1566998 ("sandbox: Report host default-filename in native mode").

Add "ccache" prefix to ignore but participate in the matching regex used by sed to identify the target architecture.

---
One can use ccache by prefixing the typical CROSS_COMPILE value with "ccache " (e.g. "ccache aarch64-gnu-linux-" for Aarch64). This however makes the MK_ARCH empty because sed won't find a match anymore since it expects the CROSS_COMPILE value to start with the actual toolchain (with an unlimited number of white spaces before).

This is failing builds since commit 7506c1566998 ("sandbox: Report host default-filename in native mode").

Add "ccache" prefix to ignore but participate in the matching regex used by sed to identify the target architecture.

---
 Makefile | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
Makefile +1 -1
index 7275a02f24ca64ebd46c5dc6e769dcdee9917dca..71743db16fca930567edd67eb77f1c94e9b7b4e9 100644
@@ -21,7 +21,7 @@ include include/host_arch.h
 ifeq ("", "$(CROSS_COMPILE)")
   MK_ARCH="${shell uname -m}"
 else
-  MK_ARCH="${shell echo $(CROSS_COMPILE) | sed -n 's/^[[:space:]]*\([^\/]*\/\)*\([^-]*\)-[^[:space:]]*/\2/p'}"
+  MK_ARCH="${shell echo $(CROSS_COMPILE) | sed -n 's/^\(ccache\)\?[[:space:]]*\([^\/]*\/\)*\([^-]*\)-[^[:space:]]*/\3/p'}"
 endif
 unexport HOST_ARCH
 ifeq ("x86_64", $(MK_ARCH))

---
base-commit: 9c25cd563179cf32cf3b119d5ae78ef8348d0335
change-id: 20241111-mk_arch-ccache-7150482cfde8

Best regards,

Signature · 1 line
Quentin Schulz <[email protected]>
#1 lore raw

Am 11. November 2024 14:20:49 MEZ schrieb Quentin Schulz <[email protected]>:

Quoted 39 lines

From: Quentin Schulz <[email protected]>

One can use ccache by prefixing the typical CROSS_COMPILE value with "ccache " (e.g. "ccache aarch64-gnu-linux-" for Aarch64). This however makes the MK_ARCH empty because sed won't find a match anymore since it expects the CROSS_COMPILE value to start with the actual toolchain (with an unlimited number of white spaces before).

This is failing builds since commit 7506c1566998 ("sandbox: Report host default-filename in native mode").

Add "ccache" prefix to ignore but participate in the matching regex used by sed to identify the target architecture.

---
One can use ccache by prefixing the typical CROSS_COMPILE value with "ccache " (e.g. "ccache aarch64-gnu-linux-" for Aarch64). This however makes the MK_ARCH empty because sed won't find a match anymore since it expects the CROSS_COMPILE value to start with the actual toolchain (with an unlimited number of white spaces before).

This is failing builds since commit 7506c1566998 ("sandbox: Report host default-filename in native mode").

Add "ccache" prefix to ignore but participate in the matching regex used by sed to identify the target architecture.
---
Makefile | 2 +-

1 file changed, 1 insertion(+), 1 deletion(-)
Makefile +0 -0
index 7275a02f24ca64ebd46c5dc6e769dcdee9917dca..71743db16fca930567edd67eb77f1c94e9b7b4e9 100644
@@ -21,7 +21,7 @@ include include/host_arch.h
 ifeq ("", "$(CROSS_COMPILE)")
  MK_ARCH="${shell uname -m}"

else

Makefile include include/host_arch.h · line 24

Quoted 2 lines
Makefile +1 -1
-  MK_ARCH="${shell echo $(CROSS_COMPILE) | sed -n 's/^[[:space:]]*\([^\/]*\/\)*\([^-]*\)-[^[:space:]]*/\2/p'}"
+  MK_ARCH="${shell echo $(CROSS_COMPILE) | sed -n 's/^\(ccache\)\?[[:space:]]*\([^\/]*\/\)*\([^-]*\)-[^[:space:]]*/\3/p'}"

The target architecture cannot be determined in this way.

You could use the riscv64 compiler to compile riscv32 when providing a gcc flag.

You should not make any assumptions about the naming scheme of vendor toolchains.

The correct way is to cross-compile a binary. Then use readelf to retrieve the target architecture.

Best regards

Heinrich

Quoted 9 lines

endif
unexport HOST_ARCH
ifeq ("x86_64", $(MK_ARCH))

---
base-commit: 9c25cd563179cf32cf3b119d5ae78ef8348d0335
change-id: 20241111-mk_arch-ccache-7150482cfde8

Best regards,

#2 lore raw

Hi Heinrich,

Quoted 45 lines · Heinrich Schuchardt

Am 11. November 2024 14:20:49 MEZ schrieb Quentin Schulz <[email protected]>:

Quoted 39 lines

From: Quentin Schulz <[email protected]>

One can use ccache by prefixing the typical CROSS_COMPILE value with "ccache " (e.g. "ccache aarch64-gnu-linux-" for Aarch64). This however makes the MK_ARCH empty because sed won't find a match anymore since it expects the CROSS_COMPILE value to start with the actual toolchain (with an unlimited number of white spaces before).

This is failing builds since commit 7506c1566998 ("sandbox: Report host default-filename in native mode").

Add "ccache" prefix to ignore but participate in the matching regex used by sed to identify the target architecture.

---
One can use ccache by prefixing the typical CROSS_COMPILE value with "ccache " (e.g. "ccache aarch64-gnu-linux-" for Aarch64). This however makes the MK_ARCH empty because sed won't find a match anymore since it expects the CROSS_COMPILE value to start with the actual toolchain (with an unlimited number of white spaces before).

This is failing builds since commit 7506c1566998 ("sandbox: Report host default-filename in native mode").

Add "ccache" prefix to ignore but participate in the matching regex used by sed to identify the target architecture.
---
Makefile | 2 +-

1 file changed, 1 insertion(+), 1 deletion(-)
Makefile +0 -0
index 7275a02f24ca64ebd46c5dc6e769dcdee9917dca..71743db16fca930567edd67eb77f1c94e9b7b4e9 100644
@@ -21,7 +21,7 @@ include include/host_arch.h
 ifeq ("", "$(CROSS_COMPILE)")
   MK_ARCH="${shell uname -m}"

else

Makefile include include/host_arch.h · line 24

Quoted 2 lines
Makefile +1 -1
-  MK_ARCH="${shell echo $(CROSS_COMPILE) | sed -n 's/^[[:space:]]*\([^\/]*\/\)*\([^-]*\)-[^[:space:]]*/\2/p'}"
+  MK_ARCH="${shell echo $(CROSS_COMPILE) | sed -n 's/^\(ccache\)\?[[:space:]]*\([^\/]*\/\)*\([^-]*\)-[^[:space:]]*/\3/p'}"

The target architecture cannot be determined in this way.

Quoted 4 lines

You could use the riscv64 compiler to compile riscv32 when providing a gcc flag.

You should not make any assumptions about the naming scheme of vendor toolchains.

I am assuming nothing more than what we are already assuming for the last three and half years, c.f. f7691a6d736bec7915c227ac14076f9993a27367.

Cheers,
Quentin

#3 lore raw
Quoted 48 lines · Quentin Schulz

Hi Heinrich,

Quoted 45 lines · Heinrich Schuchardt

Am 11. November 2024 14:20:49 MEZ schrieb Quentin Schulz <[email protected]>:

Quoted 39 lines

From: Quentin Schulz <[email protected]>

One can use ccache by prefixing the typical CROSS_COMPILE value with "ccache " (e.g. "ccache aarch64-gnu-linux-" for Aarch64). This however makes the MK_ARCH empty because sed won't find a match anymore since it expects the CROSS_COMPILE value to start with the actual toolchain (with an unlimited number of white spaces before).

This is failing builds since commit 7506c1566998 ("sandbox: Report host default-filename in native mode").

Add "ccache" prefix to ignore but participate in the matching regex used by sed to identify the target architecture.

---
One can use ccache by prefixing the typical CROSS_COMPILE value with "ccache " (e.g. "ccache aarch64-gnu-linux-" for Aarch64). This however makes the MK_ARCH empty because sed won't find a match anymore since it expects the CROSS_COMPILE value to start with the actual toolchain (with an unlimited number of white spaces before).

This is failing builds since commit 7506c1566998 ("sandbox: Report host default-filename in native mode").

Add "ccache" prefix to ignore but participate in the matching regex used by sed to identify the target architecture.
---
Makefile | 2 +-

1 file changed, 1 insertion(+), 1 deletion(-)
Makefile +0 -0
index 7275a02f24ca64ebd46c5dc6e769dcdee9917dca..71743db16fca930567edd67eb77f1c94e9b7b4e9 100644
@@ -21,7 +21,7 @@ include include/host_arch.h
 ifeq ("", "$(CROSS_COMPILE)")
   MK_ARCH="${shell uname -m}"

else

Makefile include include/host_arch.h · line 24

Quoted 2 lines
Makefile +1 -1
-  MK_ARCH="${shell echo $(CROSS_COMPILE) | sed -n 's/^[[:space:]]*\([^\/]*\/\)*\([^-]*\)-[^[:space:]]*/\2/p'}"
+  MK_ARCH="${shell echo $(CROSS_COMPILE) | sed -n 's/^\(ccache\)\?[[:space:]]*\([^\/]*\/\)*\([^-]*\)-[^[:space:]]*/\3/p'}"

The target architecture cannot be determined in this way.

Quoted 7 lines
Quoted 4 lines

You could use the riscv64 compiler to compile riscv32 when providing a gcc flag.

You should not make any assumptions about the naming scheme of vendor toolchains.

I am assuming nothing more than what we are already assuming for the last three and half years, c.f. f7691a6d736bec7915c227ac14076f9993a27367.

Yes and also, ugh, I wonder if that works right for using clang, too. It does for how I use it, which involves setting CROSS_COMPILE anyhow but I don't know if the LLVM-only option would work. Of course I also don't know if that works today. The original logic is fragile, this makes it no more or less fragile, and I'm not 100% sure I like that everyone know has to set and test against HOST_ARCH, which we weren't before 7506c1566998 ("sandbox: Report host default-filename in native mode").

This should probably come in just after I tag -rc2 as it's a fix at least.

Signature · 1 line
Tom
#4 lore raw
In reply to Quentin Schulz
Quoted 10 lines · Quentin Schulz

One can use ccache by prefixing the typical CROSS_COMPILE value with "ccache " (e.g. "ccache aarch64-gnu-linux-" for Aarch64). This however makes the MK_ARCH empty because sed won't find a match anymore since it expects the CROSS_COMPILE value to start with the actual toolchain (with an unlimited number of white spaces before).

This is failing builds since commit 7506c1566998 ("sandbox: Report host default-filename in native mode").

[...]

Applied to u-boot/master, thanks!

Signature · 1 line
Tom