Skip to content

Commit cf0c3e6

Browse files
jhofsteemasahir0y
authored andcommitted
kbuild: fix asm-offset generation to work with clang
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. [masahiro: Import Jeroen's work for U-Boot: http://patchwork.ozlabs.org/patch/375026/ Tweak sed script a little to avoid garbage '#' for GCC case, like #define NR_PAGEFLAGS 23 /* __NR_PAGEFLAGS # */ ] Signed-off-by: Jeroen Hofstee <jeroen@myspectrum.nl> Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com> Reviewed-by: Matthias Kaehlcke <mka@chromium.org> Tested-by: Matthias Kaehlcke <mka@chromium.org>
1 parent 7dd47b9 commit cf0c3e6

2 files changed

Lines changed: 9 additions & 5 deletions

File tree

‎include/linux/kbuild.h‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@
22
#define __LINUX_KBUILD_H
33

44
#define DEFINE(sym, val) \
5-
asm volatile("\n->" #sym " %0 " #val : : "i" (val))
5+
asm volatile("\n.ascii \"->" #sym " %0 " #val "\"" : : "i" (val))
66

7-
#define BLANK() asm volatile("\n->" : : )
7+
#define BLANK() asm volatile("\n.ascii \"->\"" : : )
88

99
#define OFFSET(sym, str, mem) \
1010
DEFINE(sym, offsetof(struct str, mem))
1111

1212
#define COMMENT(x) \
13-
asm volatile("\n->#" x)
13+
asm volatile("\n.ascii \"->#" x "\"")
1414

1515
#endif

‎scripts/Makefile.lib‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -413,10 +413,14 @@ cmd_xzmisc = (cat $(filter-out FORCE,$^) | \
413413
# ---------------------------------------------------------------------------
414414

415415
# Default sed regexp - multiline due to syntax constraints
416+
#
417+
# Use [:space:] because LLVM's integrated assembler inserts <tab> around
418+
# the .ascii directive whereas GCC keeps the <space> as-is.
416419
define sed-offsets
417-
"/^->/{s:->#\(.*\):/* \1 */:; \
420+
's:^[[:space:]]*\.ascii[[:space:]]*"\(.*\)".*:\1:; \
421+
/^->/{s:->#\(.*\):/* \1 */:; \
418422
s:^->\([^ ]*\) [\$$#]*\([^ ]*\) \(.*\):#define \1 \2 /* \3 */:; \
419-
s:->::; p;}"
423+
s:->::; p;}'
420424
endef
421425

422426
# Use filechk to avoid rebuilds when a header changes, but the resulting file

0 commit comments

Comments
 (0)