diff mbox series

[v2,4/7] kbuild: fix asm-offset generation to work with clang

Message ID 20201001072234.143703-5-thuth@redhat.com
State New, archived
Headers show
Series Update travis CI | expand

Commit Message

Thomas Huth Oct. 1, 2020, 7:22 a.m. UTC
KBuild abuses the asm statement to write to a file and
clang chokes about these invalid asm statements. Hack it
even more by fooling this is actual valid asm code.

This is an adaption of the Linux kernel commit cf0c3e68aa81f992b0
which in turn is based on a patch for the U-Boot:
  http://patchwork.ozlabs.org/patch/375026/

Signed-off-by: Thomas Huth <thuth@redhat.com>
---
 lib/kbuild.h            | 6 +++---
 scripts/asm-offsets.mak | 5 +++--
 2 files changed, 6 insertions(+), 5 deletions(-)

Comments

Andrew Jones Oct. 1, 2020, 9:12 a.m. UTC | #1
On Thu, Oct 01, 2020 at 09:22:31AM +0200, Thomas Huth wrote:
> KBuild abuses the asm statement to write to a file and
> clang chokes about these invalid asm statements. Hack it
> even more by fooling this is actual valid asm code.
> 
> This is an adaption of the Linux kernel commit cf0c3e68aa81f992b0
> which in turn is based on a patch for the U-Boot:
>   http://patchwork.ozlabs.org/patch/375026/
> 
> Signed-off-by: Thomas Huth <thuth@redhat.com>
> ---
>  lib/kbuild.h            | 6 +++---
>  scripts/asm-offsets.mak | 5 +++--
>  2 files changed, 6 insertions(+), 5 deletions(-)
>

 
Reviewed-by: Andrew Jones <drjones@redhat.com>
Tested-by: Andrew Jones <drjones@redhat.com>
diff mbox series

Patch

diff --git a/lib/kbuild.h b/lib/kbuild.h
index ab99db6..79644e5 100644
--- a/lib/kbuild.h
+++ b/lib/kbuild.h
@@ -1,8 +1,8 @@ 
 #ifndef _KBUILD_H_
 #define _KBUILD_H_
 #define DEFINE(sym, val) \
-	asm volatile("\n->" #sym " %0 " #val : : "i" (val))
+	asm volatile("\n.ascii \"->" #sym " %0 " #val "\"" : : "i" (val))
 #define OFFSET(sym, str, mem)	DEFINE(sym, offsetof(struct str, mem))
-#define COMMENT(x)		asm volatile("\n->#" x)
-#define BLANK()			asm volatile("\n->" : : )
+#define COMMENT(x)		asm volatile("\n.ascii \"->#" x "\"")
+#define BLANK()			asm volatile("\n.ascii \"->\"" : : )
 #endif
diff --git a/scripts/asm-offsets.mak b/scripts/asm-offsets.mak
index b35da09..7b64162 100644
--- a/scripts/asm-offsets.mak
+++ b/scripts/asm-offsets.mak
@@ -8,10 +8,11 @@ 
 #
 
 define sed-y
-	"/^->/{s:->#\(.*\):/* \1 */:; \
+	's:^[[:space:]]*\.ascii[[:space:]]*"\(.*\)".*:\1:; \
+	/^->/{s:->#\(.*\):/* \1 */:; \
 	s:^->\([^ ]*\) [\$$#]*\([-0-9]*\) \(.*\):#define \1 \2 /* \3 */:; \
 	s:^->\([^ ]*\) [\$$#]*\([^ ]*\) \(.*\):#define \1 \2 /* \3 */:; \
-	s:->::; p;}"
+	s:->::; p;}'
 endef
 
 define make_asm_offsets