* [PATCH] kbuild: add support to generate LLVM bitcode files
@ 2014-07-19 1:34 Vinícius Tinti
2014-07-20 10:02 ` Sam Ravnborg
0 siblings, 1 reply; 15+ messages in thread
From: Vinícius Tinti @ 2014-07-19 1:34 UTC (permalink / raw)
To: Michal Marek
Cc: linux-kbuild, linux-kernel, Vinícius Tinti, Behan Webster
Allows kbuild to generate LLVM bitcode files with the .ll extension when
building with Clang.
# c code
CC=clang make kernel/pid.ll
# asm code
CC=clang make arch/arm/kernel/calls.ll
Signed-off-by: Vinícius Tinti <viniciustinti@gmail.com>
Signed-off-by: Behan Webster <behanw@converseincode.com>
---
Makefile | 7 +++++++
scripts/Makefile.build | 18 ++++++++++++++++++
2 files changed, 25 insertions(+)
diff --git a/Makefile b/Makefile
index f3c543d..4eb0d14 100644
--- a/Makefile
+++ b/Makefile
@@ -1484,6 +1484,13 @@ endif
%.symtypes: %.c prepare scripts FORCE
$(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
+ifeq ($(COMPILER),clang)
+%.ll: %.c prepare scripts FORCE
+ $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
+%.ll: %.S prepare scripts FORCE
+ $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
+endif
+
# Modules
/: prepare scripts FORCE
$(cmd_crmodverdir)
diff --git a/scripts/Makefile.build b/scripts/Makefile.build
index bf3e677..9ea19d6 100644
--- a/scripts/Makefile.build
+++ b/scripts/Makefile.build
@@ -174,6 +174,14 @@ cmd_cc_symtypes_c = \
$(obj)/%.symtypes : $(src)/%.c FORCE
$(call cmd,cc_symtypes_c)
+ifeq ($(COMPILER),clang)
+quiet_cmd_cc_ll_c = CC $(quiet_modtag) $@
+cmd_cc_ll_c = $(CC) $(c_flags) $(DISABLE_LTO) -fverbose-asm -emit-llvm -S -o $@ $<
+
+$(obj)/%.ll: $(src)/%.c FORCE
+ $(call if_changed_dep,cc_ll_c)
+endif
+
# C (.c) files
# The C file is compiled and updated dependency information is generated.
# (See cmd_cc_o_c + relevant part of rule_cc_o_c)
@@ -315,6 +323,16 @@ quiet_cmd_asn1_compiler = ASN.1 $@
$(obj)/%-asn1.c $(obj)/%-asn1.h: $(src)/%.asn1 $(objtree)/scripts/asn1_compiler
$(call cmd,asn1_compiler)
+# LLVM bitcode
+# ---------------------------------------------------------------------------
+ifeq ($(COMPILER),clang)
+quiet_cmd_as_ll_S = CPP $(quiet_modtag) $@
+cmd_as_ll_S = $(CPP) $(a_flags) -o $@ $<
+
+$(obj)/%.ll: $(src)/%.S FORCE
+ $(call if_changed_dep,as_ll_S)
+endif
+
# Build the compiled-in targets
# ---------------------------------------------------------------------------
--
2.0.1
^ permalink raw reply related [flat|nested] 15+ messages in thread
* Re: [PATCH] kbuild: add support to generate LLVM bitcode files
2014-07-19 1:34 [PATCH] kbuild: add support to generate LLVM bitcode files Vinícius Tinti
@ 2014-07-20 10:02 ` Sam Ravnborg
2014-07-20 21:04 ` Sam Ravnborg
0 siblings, 1 reply; 15+ messages in thread
From: Sam Ravnborg @ 2014-07-20 10:02 UTC (permalink / raw)
To: Vinícius Tinti
Cc: Michal Marek, linux-kbuild, linux-kernel, Behan Webster
On Fri, Jul 18, 2014 at 10:34:37PM -0300, Vinícius Tinti wrote:
> Allows kbuild to generate LLVM bitcode files with the .ll extension when
> building with Clang.
>
> # c code
> CC=clang make kernel/pid.ll
>
> # asm code
> CC=clang make arch/arm/kernel/calls.ll
>
> Signed-off-by: Vinícius Tinti <viniciustinti@gmail.com>
> Signed-off-by: Behan Webster <behanw@converseincode.com>
> ---
> Makefile | 7 +++++++
> scripts/Makefile.build | 18 ++++++++++++++++++
> 2 files changed, 25 insertions(+)
>
> diff --git a/Makefile b/Makefile
> index f3c543d..4eb0d14 100644
> --- a/Makefile
> +++ b/Makefile
> @@ -1484,6 +1484,13 @@ endif
> %.symtypes: %.c prepare scripts FORCE
> $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
>
> +ifeq ($(COMPILER),clang)
> +%.ll: %.c prepare scripts FORCE
> + $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
> +%.ll: %.S prepare scripts FORCE
> + $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
> +endif
Can we drop the test for $(COMPILER) here?
If one try this with gcc then gcc will just fail if it do not support the clang flags supplied.
And help section should be updated to list .ll too.
> diff --git a/scripts/Makefile.build b/scripts/Makefile.build
> index bf3e677..9ea19d6 100644
> --- a/scripts/Makefile.build
> +++ b/scripts/Makefile.build
> @@ -174,6 +174,14 @@ cmd_cc_symtypes_c = \
> $(obj)/%.symtypes : $(src)/%.c FORCE
> $(call cmd,cc_symtypes_c)
>
> +ifeq ($(COMPILER),clang)
> +quiet_cmd_cc_ll_c = CC $(quiet_modtag) $@
> +cmd_cc_ll_c = $(CC) $(c_flags) $(DISABLE_LTO) -fverbose-asm -emit-llvm -S -o $@ $<
Can we drop the test for COMPILER here too?
Do -fverbose-asm make sense when generating .ll files?
It looks like a leftover from what you copied.
> +# LLVM bitcode
> +# ---------------------------------------------------------------------------
> +ifeq ($(COMPILER),clang)
> +quiet_cmd_as_ll_S = CPP $(quiet_modtag) $@
> +cmd_as_ll_S = $(CPP) $(a_flags) -o $@ $<
> +
> +$(obj)/%.ll: $(src)/%.S FORCE
> + $(call if_changed_dep,as_ll_S)
> +endif
This chunk belongs together with the other chunk.
There is no reason to separate .S => .ll and .c => .ll rules.
The current rules for .c => .lst etc is a mess and not something to be too
much inspired from.
Sam
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [PATCH] kbuild: add support to generate LLVM bitcode files
2014-07-20 10:02 ` Sam Ravnborg
@ 2014-07-20 21:04 ` Sam Ravnborg
2014-07-20 21:30 ` Sam Ravnborg
0 siblings, 1 reply; 15+ messages in thread
From: Sam Ravnborg @ 2014-07-20 21:04 UTC (permalink / raw)
To: Vinícius Tinti
Cc: Michal Marek, linux-kbuild, linux-kernel, Behan Webster
> >
> > +ifeq ($(COMPILER),clang)
> > +quiet_cmd_cc_ll_c = CC $(quiet_modtag) $@
> > +cmd_cc_ll_c = $(CC) $(c_flags) $(DISABLE_LTO) -fverbose-asm -emit-llvm -S -o $@ $<
>
> Can we drop the test for COMPILER here too?
> Do -fverbose-asm make sense when generating .ll files?
> It looks like a leftover from what you copied.
Also $(DISABLE_LTO) looks like a left-over.
It was added to avoid LTO when generating asm-offstes.s which
the original rule is also used for.
So this should be skipped too.
Sam
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [PATCH] kbuild: add support to generate LLVM bitcode files
2014-07-20 21:04 ` Sam Ravnborg
@ 2014-07-20 21:30 ` Sam Ravnborg
2014-07-21 22:42 ` Tinti
0 siblings, 1 reply; 15+ messages in thread
From: Sam Ravnborg @ 2014-07-20 21:30 UTC (permalink / raw)
To: Vinícius Tinti
Cc: Michal Marek, linux-kbuild, linux-kernel, Behan Webster
On Sun, Jul 20, 2014 at 11:04:58PM +0200, Sam Ravnborg wrote:
> > >
> > > +ifeq ($(COMPILER),clang)
> > > +quiet_cmd_cc_ll_c = CC $(quiet_modtag) $@
> > > +cmd_cc_ll_c = $(CC) $(c_flags) $(DISABLE_LTO) -fverbose-asm -emit-llvm -S -o $@ $<
> >
> > Can we drop the test for COMPILER here too?
> > Do -fverbose-asm make sense when generating .ll files?
> > It looks like a leftover from what you copied.
>
> Also $(DISABLE_LTO) looks like a left-over.
> It was added to avoid LTO when generating asm-offstes.s which
> the original rule is also used for.
> So this should be skipped too.
Third thing.
In some places we indent the assignmnet like this:
quiet_cmd_cc_ll_c = CC $(quiet_modtag) $@
cmd_cc_ll_c = $(CC) $(c_flags) ....
This makes it more obvious that the "cmd_cc_ll_c" is actually the same.
Makefile.build does not do this much but please do for these targets.
Sam
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [PATCH] kbuild: add support to generate LLVM bitcode files
2014-07-20 21:30 ` Sam Ravnborg
@ 2014-07-21 22:42 ` Tinti
2014-07-22 0:35 ` Sam Ravnborg
2014-07-23 11:56 ` [PATCH v2] " Vinícius Tinti
0 siblings, 2 replies; 15+ messages in thread
From: Tinti @ 2014-07-21 22:42 UTC (permalink / raw)
To: Sam Ravnborg; +Cc: Michal Marek, linux-kbuild, linux-kernel, Behan Webster
1) Can we drop the test for $(COMPILER) here?
Yes.
2) And help section should be updated to list .ll too.
I will be adding it too.
3) This chunk belongs together with the other chunk.
There is no reason to separate .S => .ll and .c => .ll rules.
Sure. But in fact I was not able to create the .ll from .S and neither
create the .s
from the .S in some assembly files on kernel. Do you know how it works?
4) Also $(DISABLE_LTO) looks like a left-over.
Remove $(DISABLE_LTO)
5) quiet_cmd_cc_ll_c = CC $(quiet_modtag) $@
cmd_cc_ll_c = $(CC) $(c_flags) ....
Understood.
Thanks.
On Sun, Jul 20, 2014 at 6:30 PM, Sam Ravnborg <sam@ravnborg.org> wrote:
> On Sun, Jul 20, 2014 at 11:04:58PM +0200, Sam Ravnborg wrote:
>> > >
>> > > +ifeq ($(COMPILER),clang)
>> > > +quiet_cmd_cc_ll_c = CC $(quiet_modtag) $@
>> > > +cmd_cc_ll_c = $(CC) $(c_flags) $(DISABLE_LTO) -fverbose-asm -emit-llvm -S -o $@ $<
>> >
>> > Can we drop the test for COMPILER here too?
>> > Do -fverbose-asm make sense when generating .ll files?
>> > It looks like a leftover from what you copied.
>>
>> Also $(DISABLE_LTO) looks like a left-over.
>> It was added to avoid LTO when generating asm-offstes.s which
>> the original rule is also used for.
>> So this should be skipped too.
> Third thing.
> In some places we indent the assignmnet like this:
> quiet_cmd_cc_ll_c = CC $(quiet_modtag) $@
> cmd_cc_ll_c = $(CC) $(c_flags) ....
>
> This makes it more obvious that the "cmd_cc_ll_c" is actually the same.
> Makefile.build does not do this much but please do for these targets.
>
> Sam
--
Simplicity is the ultimate sophistication
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [PATCH] kbuild: add support to generate LLVM bitcode files
2014-07-21 22:42 ` Tinti
@ 2014-07-22 0:35 ` Sam Ravnborg
2014-07-23 11:56 ` [PATCH v2] " Vinícius Tinti
1 sibling, 0 replies; 15+ messages in thread
From: Sam Ravnborg @ 2014-07-22 0:35 UTC (permalink / raw)
To: Tinti; +Cc: Michal Marek, linux-kbuild, linux-kernel, Behan Webster
>
> Sure. But in fact I was not able to create the .ll from .S and neither
> create the .s
> from the .S in some assembly files on kernel. Do you know how it works?
make arch/x86/kernel/preempt.s
Works for me.
Something broke in your setup?
Sam
^ permalink raw reply [flat|nested] 15+ messages in thread
* [PATCH v2] kbuild: add support to generate LLVM bitcode files
2014-07-21 22:42 ` Tinti
2014-07-22 0:35 ` Sam Ravnborg
@ 2014-07-23 11:56 ` Vinícius Tinti
2014-07-23 12:00 ` Tinti
1 sibling, 1 reply; 15+ messages in thread
From: Vinícius Tinti @ 2014-07-23 11:56 UTC (permalink / raw)
To: Sam Ravnborg, Michal Marek
Cc: Renato Golin, linux-kbuild, linux-kernel, Vinícius Tinti,
Behan Webster
Allows kbuild to generate LLVM bitcode files with the .ll extension.
# from c code
CC=clang make kernel/pid.ll
# from asm code
CC=clang make arch/x86/kernel/preempt.ll
Signed-off-by: Vinícius Tinti <viniciustinti@gmail.com>
Signed-off-by: Behan Webster <behanw@converseincode.com>
---
.gitignore | 1 +
Makefile | 6 ++++++
scripts/Makefile.build | 14 ++++++++++++++
3 files changed, 21 insertions(+)
diff --git a/.gitignore b/.gitignore
index f4c0b09..c5a7656 100644
--- a/.gitignore
+++ b/.gitignore
@@ -32,6 +32,7 @@
*.lzo
*.patch
*.gcno
+*.ll
modules.builtin
Module.symvers
diff --git a/Makefile b/Makefile
index 6b27741..7826c33 100644
--- a/Makefile
+++ b/Makefile
@@ -1213,6 +1213,8 @@ help:
@echo ' (default: $$(INSTALL_MOD_PATH)/lib/firmware)'
@echo ' dir/ - Build all files in dir and below'
@echo ' dir/file.[oisS] - Build specified target only'
+ @echo ' dir/file.ll - Build the LLVM bitcode file'
+ @echo ' (requires a compiler support for LLVM bitcode generation)'
@echo ' dir/file.lst - Build specified mixed source/assembly target only'
@echo ' (requires a recent binutils and recent build (System.map))'
@echo ' dir/file.ko - Build module including final link'
@@ -1483,6 +1485,10 @@ endif
$(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
%.symtypes: %.c prepare scripts FORCE
$(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
+%.ll: %.c prepare scripts FORCE
+ $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
+%.ll: %.S prepare scripts FORCE
+ $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
# Modules
/: prepare scripts FORCE
diff --git a/scripts/Makefile.build b/scripts/Makefile.build
index bf3e677..4d97e4f 100644
--- a/scripts/Makefile.build
+++ b/scripts/Makefile.build
@@ -174,6 +174,20 @@ cmd_cc_symtypes_c = \
$(obj)/%.symtypes : $(src)/%.c FORCE
$(call cmd,cc_symtypes_c)
+# LLVM bitcode
+# Generate .ll files from .s and .c
+quiet_cmd_cc_ll_c = CC $(quiet_modtag) $@
+ cmd_cc_ll_c = $(CC) $(c_flags) -emit-llvm -S -o $@ $<
+
+$(obj)/%.ll: $(src)/%.c FORCE
+ $(call if_changed_dep,cc_ll_c)
+
+quiet_cmd_as_ll_S = CPP $(quiet_modtag) $@
+ cmd_as_ll_S = $(CPP) $(a_flags) -o $@ $<
+
+$(obj)/%.ll: $(src)/%.S FORCE
+ $(call if_changed_dep,as_ll_S)
+
# C (.c) files
# The C file is compiled and updated dependency information is generated.
# (See cmd_cc_o_c + relevant part of rule_cc_o_c)
--
2.0.1
^ permalink raw reply related [flat|nested] 15+ messages in thread
* Re: [PATCH v2] kbuild: add support to generate LLVM bitcode files
2014-07-23 11:56 ` [PATCH v2] " Vinícius Tinti
@ 2014-07-23 12:00 ` Tinti
2014-09-11 23:13 ` [PATCH v3] " Vinícius Tinti
0 siblings, 1 reply; 15+ messages in thread
From: Tinti @ 2014-07-23 12:00 UTC (permalink / raw)
To: Sam Ravnborg
Cc: Michal Marek, Renato Golin, linux-kbuild, linux-kernel, Behan Webster
On Wed, Jul 23, 2014 at 8:56 AM, Vinícius Tinti <viniciustinti@gmail.com> wrote:
> Allows kbuild to generate LLVM bitcode files with the .ll extension.
>
> # from c code
> CC=clang make kernel/pid.ll
>
> # from asm code
> CC=clang make arch/x86/kernel/preempt.ll
>
> Signed-off-by: Vinícius Tinti <viniciustinti@gmail.com>
> Signed-off-by: Behan Webster <behanw@converseincode.com>
> ---
> .gitignore | 1 +
> Makefile | 6 ++++++
> scripts/Makefile.build | 14 ++++++++++++++
> 3 files changed, 21 insertions(+)
>
> diff --git a/.gitignore b/.gitignore
> index f4c0b09..c5a7656 100644
> --- a/.gitignore
> +++ b/.gitignore
> @@ -32,6 +32,7 @@
> *.lzo
> *.patch
> *.gcno
> +*.ll
> modules.builtin
> Module.symvers
>
> diff --git a/Makefile b/Makefile
> index 6b27741..7826c33 100644
> --- a/Makefile
> +++ b/Makefile
> @@ -1213,6 +1213,8 @@ help:
> @echo ' (default: $$(INSTALL_MOD_PATH)/lib/firmware)'
> @echo ' dir/ - Build all files in dir and below'
> @echo ' dir/file.[oisS] - Build specified target only'
> + @echo ' dir/file.ll - Build the LLVM bitcode file'
> + @echo ' (requires a compiler support for LLVM bitcode generation)'
> @echo ' dir/file.lst - Build specified mixed source/assembly target only'
> @echo ' (requires a recent binutils and recent build (System.map))'
> @echo ' dir/file.ko - Build module including final link'
> @@ -1483,6 +1485,10 @@ endif
> $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
> %.symtypes: %.c prepare scripts FORCE
> $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
> +%.ll: %.c prepare scripts FORCE
> + $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
> +%.ll: %.S prepare scripts FORCE
> + $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
>
> # Modules
> /: prepare scripts FORCE
> diff --git a/scripts/Makefile.build b/scripts/Makefile.build
> index bf3e677..4d97e4f 100644
> --- a/scripts/Makefile.build
> +++ b/scripts/Makefile.build
> @@ -174,6 +174,20 @@ cmd_cc_symtypes_c = \
> $(obj)/%.symtypes : $(src)/%.c FORCE
> $(call cmd,cc_symtypes_c)
>
> +# LLVM bitcode
> +# Generate .ll files from .s and .c
> +quiet_cmd_cc_ll_c = CC $(quiet_modtag) $@
> + cmd_cc_ll_c = $(CC) $(c_flags) -emit-llvm -S -o $@ $<
> +
> +$(obj)/%.ll: $(src)/%.c FORCE
> + $(call if_changed_dep,cc_ll_c)
> +
> +quiet_cmd_as_ll_S = CPP $(quiet_modtag) $@
> + cmd_as_ll_S = $(CPP) $(a_flags) -o $@ $<
> +
> +$(obj)/%.ll: $(src)/%.S FORCE
> + $(call if_changed_dep,as_ll_S)
> +
> # C (.c) files
> # The C file is compiled and updated dependency information is generated.
> # (See cmd_cc_o_c + relevant part of rule_cc_o_c)
> --
> 2.0.1
>
The preempt.s works for me as well the preempt.ll.
The make help now displays about the .ll files but I have not found
other section in Documentation about it. If there is please let me know.
I have also added the *.ll in .gitignore.
Regards
--
Simplicity is the ultimate sophistication
^ permalink raw reply [flat|nested] 15+ messages in thread
* [PATCH v3] kbuild: add support to generate LLVM bitcode files
2014-07-23 12:00 ` Tinti
@ 2014-09-11 23:13 ` Vinícius Tinti
0 siblings, 0 replies; 15+ messages in thread
From: Vinícius Tinti @ 2014-09-11 23:13 UTC (permalink / raw)
To: Michal Marek, Andrew Morton, Behan Webster, Zhao Gang,
Borislav Petkov, Andi Kleen
Cc: linux-kernel, linux-kbuild, Vinícius Tinti
Allows kbuild to generate LLVM bitcode files using '.ll' suffix.
# from c code
CC=clang make kernel/pid.ll
# from asm code
CC=clang make arch/x86/kernel/preempt.ll
Signed-off-by: Vinícius Tinti <viniciustinti@gmail.com>
Signed-off-by: Behan Webster <behanw@converseincode.com>
---
.gitignore | 1 +
Makefile | 6 ++++++
scripts/Makefile.build | 14 ++++++++++++++
3 files changed, 21 insertions(+)
diff --git a/.gitignore b/.gitignore
index e213b27..823b9d6 100644
--- a/.gitignore
+++ b/.gitignore
@@ -32,6 +32,7 @@
*.lzo
*.patch
*.gcno
+*.ll
modules.builtin
Module.symvers
*.dwo
diff --git a/Makefile b/Makefile
index 1a60bdd..cd4a120 100644
--- a/Makefile
+++ b/Makefile
@@ -1250,6 +1250,8 @@ help:
@echo ' (default: $$(INSTALL_MOD_PATH)/lib/firmware)'
@echo ' dir/ - Build all files in dir and below'
@echo ' dir/file.[oisS] - Build specified target only'
+ @echo ' dir/file.ll - Build the LLVM bitcode file'
+ @echo ' (requires compiler support for LLVM bitcode generation)'
@echo ' dir/file.lst - Build specified mixed source/assembly target only'
@echo ' (requires a recent binutils and recent build (System.map))'
@echo ' dir/file.ko - Build module including final link'
@@ -1526,6 +1528,10 @@ endif
$(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
%.symtypes: %.c prepare scripts FORCE
$(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
+%.ll: %.c prepare scripts FORCE
+ $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
+%.ll: %.S prepare scripts FORCE
+ $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
# Modules
/: prepare scripts FORCE
diff --git a/scripts/Makefile.build b/scripts/Makefile.build
index bf3e677..4d97e4f 100644
--- a/scripts/Makefile.build
+++ b/scripts/Makefile.build
@@ -174,6 +174,20 @@ cmd_cc_symtypes_c = \
$(obj)/%.symtypes : $(src)/%.c FORCE
$(call cmd,cc_symtypes_c)
+# LLVM bitcode
+# Generate .ll files from .s and .c
+quiet_cmd_cc_ll_c = CC $(quiet_modtag) $@
+ cmd_cc_ll_c = $(CC) $(c_flags) -emit-llvm -S -o $@ $<
+
+$(obj)/%.ll: $(src)/%.c FORCE
+ $(call if_changed_dep,cc_ll_c)
+
+quiet_cmd_as_ll_S = CPP $(quiet_modtag) $@
+ cmd_as_ll_S = $(CPP) $(a_flags) -o $@ $<
+
+$(obj)/%.ll: $(src)/%.S FORCE
+ $(call if_changed_dep,as_ll_S)
+
# C (.c) files
# The C file is compiled and updated dependency information is generated.
# (See cmd_cc_o_c + relevant part of rule_cc_o_c)
--
2.1.0
^ permalink raw reply related [flat|nested] 15+ messages in thread
* [PATCH v3] kbuild: Add support to generate LLVM bitcode files
@ 2017-04-04 17:27 Matthias Kaehlcke
2017-04-20 18:04 ` Matthias Kaehlcke
2017-04-21 5:02 ` Masahiro Yamada
0 siblings, 2 replies; 15+ messages in thread
From: Matthias Kaehlcke @ 2017-04-04 17:27 UTC (permalink / raw)
To: Michal Marek, Emese Revfy, Kees Cook, Behan Webster,
Luis R . Rodriguez, Vinícius Tinti, Kyeongmin Cho
Cc: linux-kernel, linux-kbuild, Grant Grundler, Michael Davidson,
Greg Hackmann, Peter Foley, Matthias Kaehlcke
From: Vinícius Tinti <viniciustinti@gmail.com>
Add rules to kbuild in order to generate LLVM bitcode files with the .ll
extension when using clang.
# from c code
CC=clang make kernel/pid.ll
# from asm code
CC=clang make arch/x86/kernel/preempt.ll
From: Vinícius Tinti <viniciustinti@gmail.com>
Signed-off-by: Vinícius Tinti <viniciustinti@gmail.com>
Signed-off-by: Behan Webster <behanw@converseincode.com>
Signed-off-by: Matthias Kaehlcke <mka@chromium.org>
---
Resending, original v3 patch: https://patchwork.kernel.org/patch/4891071/
.gitignore | 1 +
Makefile | 6 ++++++
scripts/Makefile.build | 14 ++++++++++++++
3 files changed, 21 insertions(+)
diff --git a/.gitignore b/.gitignore
index c2ed4ecb0acd..0c39aa20b6ba 100644
--- a/.gitignore
+++ b/.gitignore
@@ -33,6 +33,7 @@
*.lzo
*.patch
*.gcno
+*.ll
modules.builtin
Module.symvers
*.dwo
diff --git a/Makefile b/Makefile
index e11989d36c87..d998ce363335 100644
--- a/Makefile
+++ b/Makefile
@@ -1361,6 +1361,8 @@ help:
@echo ' (default: $$(INSTALL_MOD_PATH)/lib/firmware)'
@echo ' dir/ - Build all files in dir and below'
@echo ' dir/file.[ois] - Build specified target only'
+ @echo ' dir/file.ll - Build the LLVM bitcode file'
+ @echo ' (requires compiler support for LLVM bitcode generation)'
@echo ' dir/file.lst - Build specified mixed source/assembly target only'
@echo ' (requires a recent binutils and recent build (System.map))'
@echo ' dir/file.ko - Build module including final link'
@@ -1648,6 +1650,10 @@ endif
$(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
%.symtypes: %.c prepare scripts FORCE
$(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
+%.ll: %.c prepare scripts FORCE
+ $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
+%.ll: %.S prepare scripts FORCE
+ $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
# Modules
/: prepare scripts FORCE
diff --git a/scripts/Makefile.build b/scripts/Makefile.build
index d883116ebaa4..e5a28da2e6fa 100644
--- a/scripts/Makefile.build
+++ b/scripts/Makefile.build
@@ -177,6 +177,20 @@ cmd_cc_symtypes_c = \
$(obj)/%.symtypes : $(src)/%.c FORCE
$(call cmd,cc_symtypes_c)
+# LLVM bitcode
+# Generate .ll files from .s and .c
+quiet_cmd_cc_ll_c = CC $(quiet_modtag) $@
+ cmd_cc_ll_c = $(CC) $(c_flags) -emit-llvm -S -o $@ $<
+
+$(obj)/%.ll: $(src)/%.c FORCE
+ $(call if_changed_dep,cc_ll_c)
+
+quiet_cmd_as_ll_S = CPP $(quiet_modtag) $@
+ cmd_as_ll_S = $(CPP) $(a_flags) -o $@ $<
+
+$(obj)/%.ll: $(src)/%.S FORCE
+ $(call if_changed_dep,as_ll_S)
+
# C (.c) files
# The C file is compiled and updated dependency information is generated.
# (See cmd_cc_o_c + relevant part of rule_cc_o_c)
--
2.12.2.715.g7642488e1d-goog
^ permalink raw reply related [flat|nested] 15+ messages in thread
* Re: [PATCH v3] kbuild: Add support to generate LLVM bitcode files
2017-04-04 17:27 [PATCH v3] kbuild: Add " Matthias Kaehlcke
@ 2017-04-20 18:04 ` Matthias Kaehlcke
2017-04-21 5:02 ` Masahiro Yamada
1 sibling, 0 replies; 15+ messages in thread
From: Matthias Kaehlcke @ 2017-04-20 18:04 UTC (permalink / raw)
To: Masahiro Yamada, Michal Marek, Emese Revfy, Kees Cook,
Behan Webster, Luis R . Rodriguez, Vinícius Tinti,
Kyeongmin Cho
Cc: linux-kernel, linux-kbuild, Grant Grundler, Michael Davidson,
Greg Hackmann, Peter Foley
El Tue, Apr 04, 2017 at 10:27:06AM -0700 Matthias Kaehlcke ha dit:
> From: Vinícius Tinti <viniciustinti@gmail.com>
>
> Add rules to kbuild in order to generate LLVM bitcode files with the .ll
> extension when using clang.
>
> # from c code
> CC=clang make kernel/pid.ll
>
> # from asm code
> CC=clang make arch/x86/kernel/preempt.ll
>
> From: Vinícius Tinti <viniciustinti@gmail.com>
> Signed-off-by: Vinícius Tinti <viniciustinti@gmail.com>
> Signed-off-by: Behan Webster <behanw@converseincode.com>
> Signed-off-by: Matthias Kaehlcke <mka@chromium.org>
> ---
Ping, any comments on this patch?
Thanks
Matthias
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [PATCH v3] kbuild: Add support to generate LLVM bitcode files
2017-04-04 17:27 [PATCH v3] kbuild: Add " Matthias Kaehlcke
2017-04-20 18:04 ` Matthias Kaehlcke
@ 2017-04-21 5:02 ` Masahiro Yamada
2017-04-21 19:55 ` Matthias Kaehlcke
1 sibling, 1 reply; 15+ messages in thread
From: Masahiro Yamada @ 2017-04-21 5:02 UTC (permalink / raw)
To: Matthias Kaehlcke
Cc: Michal Marek, Emese Revfy, Kees Cook, Behan Webster,
Luis R . Rodriguez, Vinícius Tinti, Kyeongmin Cho,
Linux Kernel Mailing List, Linux Kbuild mailing list,
Grant Grundler, Michael Davidson, Greg Hackmann, Peter Foley
Hi Matthias,
2017-04-05 2:27 GMT+09:00 Matthias Kaehlcke <mka@chromium.org>:
> From: Vinícius Tinti <viniciustinti@gmail.com>
>
> Add rules to kbuild in order to generate LLVM bitcode files with the .ll
> extension when using clang.
First, I'd like to be sure about the terminology "LLVM bitcode"
because "bitcode" sounds like human-unreadable binary.
For example, 'man llvm-as' says:
llvm-as is the LLVM assembler. It reads a file containing
human-readable LLVM assembly language, translates it to LLVM
bitcode, and writes the result into a file or to standard output.
As far as I understood:
*.ll - LLVM assembly (human readable file)
*.bc - LLVM bitcode (binary file)
Is this correct?
> # from c code
> CC=clang make kernel/pid.ll
This does not work because CC is overridden in the top-level Makefile.
It should be
make CC=clang kernel/pid.ll
> # from asm code
> CC=clang make arch/x86/kernel/preempt.ll
arch/x86/kernel/preempt.* does not exist
(at least in the latest tree).
> +
> +quiet_cmd_as_ll_S = CPP $(quiet_modtag) $@
> + cmd_as_ll_S = $(CPP) $(a_flags) -o $@ $<
> +
> +$(obj)/%.ll: $(src)/%.S FORCE
> + $(call if_changed_dep,as_ll_S)
> +
I could not understand how this rule can convert
architecture-specific assembly to LLVM intermediate expression.
This is just pre-processing *.S file.
Actually, this is completely the same as the rule *.S -> *.s
quiet_cmd_cpp_s_S = CPP $(quiet_modtag) $@
cmd_cpp_s_S = $(CPP) $(a_flags) -o $@ $<
$(obj)/%.s: $(src)/%.S FORCE
$(call if_changed_dep,cpp_s_S)
--
Best Regards
Masahiro Yamada
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [PATCH v3] kbuild: Add support to generate LLVM bitcode files
2017-04-21 5:02 ` Masahiro Yamada
@ 2017-04-21 19:55 ` Matthias Kaehlcke
2017-04-23 6:57 ` Masahiro Yamada
2017-04-24 2:21 ` Masahiro Yamada
0 siblings, 2 replies; 15+ messages in thread
From: Matthias Kaehlcke @ 2017-04-21 19:55 UTC (permalink / raw)
To: Masahiro Yamada
Cc: Michal Marek, Emese Revfy, Kees Cook, Behan Webster,
Luis R . Rodriguez, Vinícius Tinti, Kyeongmin Cho,
Linux Kernel Mailing List, Linux Kbuild mailing list,
Grant Grundler, Michael Davidson, Greg Hackmann, Peter Foley
Hi Masahiro,
El Fri, Apr 21, 2017 at 02:02:46PM +0900 Masahiro Yamada ha dit:
> 2017-04-05 2:27 GMT+09:00 Matthias Kaehlcke <mka@chromium.org>:
> > From: Vinícius Tinti <viniciustinti@gmail.com>
> >
> > Add rules to kbuild in order to generate LLVM bitcode files with the .ll
> > extension when using clang.
>
>
> First, I'd like to be sure about the terminology "LLVM bitcode"
> because "bitcode" sounds like human-unreadable binary.
>
>
> For example, 'man llvm-as' says:
> llvm-as is the LLVM assembler. It reads a file containing
> human-readable LLVM assembly language, translates it to LLVM
> bitcode, and writes the result into a file or to standard output.
>
>
> As far as I understood:
>
> *.ll - LLVM assembly (human readable file)
> *.bc - LLVM bitcode (binary file)
>
> Is this correct?
Yes, the terminology should be changed to talk about 'LLVM assembly'.
> > # from c code
> > CC=clang make kernel/pid.ll
>
> This does not work because CC is overridden in the top-level Makefile.
> It should be
> make CC=clang kernel/pid.ll
Will change
> > # from asm code
> > CC=clang make arch/x86/kernel/preempt.ll
>
> arch/x86/kernel/preempt.* does not exist
> (at least in the latest tree).
>
>
>
>
> > +
> > +quiet_cmd_as_ll_S = CPP $(quiet_modtag) $@
> > + cmd_as_ll_S = $(CPP) $(a_flags) -o $@ $<
> > +
> > +$(obj)/%.ll: $(src)/%.S FORCE
> > + $(call if_changed_dep,as_ll_S)
> > +
>
> I could not understand how this rule can convert
> architecture-specific assembly to LLVM intermediate expression.
>
> This is just pre-processing *.S file.
>
>
> Actually, this is completely the same as the rule *.S -> *.s
>
> quiet_cmd_cpp_s_S = CPP $(quiet_modtag) $@
> cmd_cpp_s_S = $(CPP) $(a_flags) -o $@ $<
>
> $(obj)/%.s: $(src)/%.S FORCE
> $(call if_changed_dep,cpp_s_S)
Indeed, unsurprisingly the content of a .ll file generated from a .S
is the same as the corresponding .s.
Besides the Makefile rules it isn't clear to me how assembly would be
converted to LLVM IR. I suggest to remove the rules for assembly.
Cheers
Matthias
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [PATCH v3] kbuild: Add support to generate LLVM bitcode files
2017-04-21 19:55 ` Matthias Kaehlcke
@ 2017-04-23 6:57 ` Masahiro Yamada
2017-04-24 2:21 ` Masahiro Yamada
1 sibling, 0 replies; 15+ messages in thread
From: Masahiro Yamada @ 2017-04-23 6:57 UTC (permalink / raw)
To: Matthias Kaehlcke
Cc: Michal Marek, Emese Revfy, Kees Cook, Behan Webster,
Luis R . Rodriguez, Vinícius Tinti, Kyeongmin Cho,
Linux Kernel Mailing List, Linux Kbuild mailing list,
Grant Grundler, Michael Davidson, Greg Hackmann, Peter Foley
Hi Matthias,
2017-04-22 4:55 GMT+09:00 Matthias Kaehlcke <mka@chromium.org>:
> Hi Masahiro,
>
> El Fri, Apr 21, 2017 at 02:02:46PM +0900 Masahiro Yamada ha dit:
>
>> 2017-04-05 2:27 GMT+09:00 Matthias Kaehlcke <mka@chromium.org>:
>> > From: Vinícius Tinti <viniciustinti@gmail.com>
>> >
>> > Add rules to kbuild in order to generate LLVM bitcode files with the .ll
>> > extension when using clang.
>>
>>
>> First, I'd like to be sure about the terminology "LLVM bitcode"
>> because "bitcode" sounds like human-unreadable binary.
>>
>>
>> For example, 'man llvm-as' says:
>> llvm-as is the LLVM assembler. It reads a file containing
>> human-readable LLVM assembly language, translates it to LLVM
>> bitcode, and writes the result into a file or to standard output.
>>
>>
>> As far as I understood:
>>
>> *.ll - LLVM assembly (human readable file)
>> *.bc - LLVM bitcode (binary file)
>>
>> Is this correct?
>
> Yes, the terminology should be changed to talk about 'LLVM assembly'.
>
>> > # from c code
>> > CC=clang make kernel/pid.ll
>>
>> This does not work because CC is overridden in the top-level Makefile.
>> It should be
>> make CC=clang kernel/pid.ll
>
> Will change
>
>> > # from asm code
>> > CC=clang make arch/x86/kernel/preempt.ll
>>
>> arch/x86/kernel/preempt.* does not exist
>> (at least in the latest tree).
>>
>>
>>
>>
>> > +
>> > +quiet_cmd_as_ll_S = CPP $(quiet_modtag) $@
>> > + cmd_as_ll_S = $(CPP) $(a_flags) -o $@ $<
>> > +
>> > +$(obj)/%.ll: $(src)/%.S FORCE
>> > + $(call if_changed_dep,as_ll_S)
>> > +
>>
>> I could not understand how this rule can convert
>> architecture-specific assembly to LLVM intermediate expression.
>>
>> This is just pre-processing *.S file.
>>
>>
>> Actually, this is completely the same as the rule *.S -> *.s
>>
>> quiet_cmd_cpp_s_S = CPP $(quiet_modtag) $@
>> cmd_cpp_s_S = $(CPP) $(a_flags) -o $@ $<
>>
>> $(obj)/%.s: $(src)/%.S FORCE
>> $(call if_changed_dep,cpp_s_S)
>
> Indeed, unsurprisingly the content of a .ll file generated from a .S
> is the same as the corresponding .s.
>
> Besides the Makefile rules it isn't clear to me how assembly would be
> converted to LLVM IR. I suggest to remove the rules for assembly.
>
I agree. This rule should be removed.
--
Best Regards
Masahiro Yamada
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [PATCH v3] kbuild: Add support to generate LLVM bitcode files
2017-04-21 19:55 ` Matthias Kaehlcke
2017-04-23 6:57 ` Masahiro Yamada
@ 2017-04-24 2:21 ` Masahiro Yamada
1 sibling, 0 replies; 15+ messages in thread
From: Masahiro Yamada @ 2017-04-24 2:21 UTC (permalink / raw)
To: Matthias Kaehlcke
Cc: Michal Marek, Emese Revfy, Kees Cook, Behan Webster,
Luis R . Rodriguez, Vinícius Tinti, Kyeongmin Cho,
Linux Kernel Mailing List, Linux Kbuild mailing list,
Grant Grundler, Michael Davidson, Greg Hackmann, Peter Foley
Hi Matthias,
2017-04-22 4:55 GMT+09:00 Matthias Kaehlcke <mka@chromium.org>:
> Hi Masahiro,
>
> El Fri, Apr 21, 2017 at 02:02:46PM +0900 Masahiro Yamada ha dit:
>
>> 2017-04-05 2:27 GMT+09:00 Matthias Kaehlcke <mka@chromium.org>:
>> > From: Vinícius Tinti <viniciustinti@gmail.com>
>> >
>> > Add rules to kbuild in order to generate LLVM bitcode files with the .ll
>> > extension when using clang.
>>
>>
>> First, I'd like to be sure about the terminology "LLVM bitcode"
>> because "bitcode" sounds like human-unreadable binary.
>>
>>
>> For example, 'man llvm-as' says:
>> llvm-as is the LLVM assembler. It reads a file containing
>> human-readable LLVM assembly language, translates it to LLVM
>> bitcode, and writes the result into a file or to standard output.
>>
One more thing:
Please add '*.ll' pattern to the following clean target.
clean: $(clean-dirs)
$(call cmd,rmdirs)
$(call cmd,rmfiles)
@find $(if $(KBUILD_EXTMOD), $(KBUILD_EXTMOD), .) $(RCS_FIND_IGNORE) \
\( -name '*.[oas]' -o -name '*.ko' -o -name '.*.cmd' \
-o -name '*.ko.*' \
-o -name '*.dwo' \
-o -name '*.su' \
-o -name '.*.d' -o -name '.*.tmp' -o -name '*.mod.c' \
-o -name '*.symtypes' -o -name 'modules.order' \
-o -name modules.builtin -o -name '.tmp_*.o.*' \
-o -name '*.c.[012]*.*' \
-o -name '*.gcno' \) -type f -print | xargs rm -f
--
Best Regards
Masahiro Yamada
^ permalink raw reply [flat|nested] 15+ messages in thread
end of thread, other threads:[~2017-04-24 2:22 UTC | newest]
Thread overview: 15+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-07-19 1:34 [PATCH] kbuild: add support to generate LLVM bitcode files Vinícius Tinti
2014-07-20 10:02 ` Sam Ravnborg
2014-07-20 21:04 ` Sam Ravnborg
2014-07-20 21:30 ` Sam Ravnborg
2014-07-21 22:42 ` Tinti
2014-07-22 0:35 ` Sam Ravnborg
2014-07-23 11:56 ` [PATCH v2] " Vinícius Tinti
2014-07-23 12:00 ` Tinti
2014-09-11 23:13 ` [PATCH v3] " Vinícius Tinti
2017-04-04 17:27 [PATCH v3] kbuild: Add " Matthias Kaehlcke
2017-04-20 18:04 ` Matthias Kaehlcke
2017-04-21 5:02 ` Masahiro Yamada
2017-04-21 19:55 ` Matthias Kaehlcke
2017-04-23 6:57 ` Masahiro Yamada
2017-04-24 2:21 ` Masahiro Yamada
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.