Skip to contentSkip to conversation

gen_compile_commands: add assembly files to compilation database

PATCH In review Benjamin Gray 5 participants 5 messages Jul 19, 2023 – Jul 23, 2023

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 gen_compile_commands: add assembly files to compilation database

Like C source files, tooling can find it useful to have the assembly source file compilation recorded.

The .S extension appears to used across all architectures.

---

For example, I'm prototyping adding ASM support to clangd. It can use this information to determine the architecture, macros definitions, include paths, etc. on a per-file basis. I can capture this during compilation with tools like bear, but given this script exists and the change is trivial it seems like a good idea to adjust this script too.

---
 scripts/clang-tools/gen_compile_commands.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
scripts/clang-tools/gen_compile_commands.py +1 -1
index 15ba56527acd..a84cc5737c2c 100755
@@ -19,7 +19,7 @@ _DEFAULT_OUTPUT = 'compile_commands.json'
 _DEFAULT_LOG_LEVEL = 'WARNING'
 
 _FILENAME_PATTERN = r'^\..*\.cmd$'
-_LINE_PATTERN = r'^savedcmd_[^ ]*\.o := (.* )([^ ]*\.c) *(;|$)'
+_LINE_PATTERN = r'^savedcmd_[^ ]*\.o := (.* )([^ ]*\.[cS]) *(;|$)'
 _VALID_LOG_LEVELS = ['DEBUG', 'INFO', 'WARNING', 'ERROR', 'CRITICAL']
 # The tools/ directory adopts a different build system, and produces .cmd
 # files in a different format. Do not support it.
Signature · 1 line
2.41.0
Reviewed-by on v1 1/1
#1 lore raw
Quoted 30 lines · Benjamin Gray

Like C source files, tooling can find it useful to have the assembly source file compilation recorded.

The .S extension appears to used across all architectures.

---

For example, I'm prototyping adding ASM support to clangd. It can use this information to determine the architecture, macros definitions, include paths, etc. on a per-file basis. I can capture this during compilation with tools like bear, but given this script exists and the change is trivial it seems like a good idea to adjust this script too.
---
scripts/clang-tools/gen_compile_commands.py | 2 +-

1 file changed, 1 insertion(+), 1 deletion(-)
scripts/clang-tools/gen_compile_commands.py +0 -0
index 15ba56527acd..a84cc5737c2c 100755
@@ -19,7 +19,7 @@ _DEFAULT_OUTPUT = 'compile_commands.json'

_DEFAULT_LOG_LEVEL = 'WARNING'

_FILENAME_PATTERN = r'^\..*\.cmd$'

scripts/clang-tools/gen_compile_commands.py +1 -1
-_LINE_PATTERN = r'^savedcmd_[^ ]*\.o := (.* )([^ ]*\.c) *(;|$)'
+_LINE_PATTERN = r'^savedcmd_[^ ]*\.o := (.* )([^ ]*\.[cS]) *(;|$)'

_VALID_LOG_LEVELS = ['DEBUG', 'INFO', 'WARNING', 'ERROR', 'CRITICAL'] # The tools/ directory adopts a different build system, and produces .cmd

Quoted 4 lines
# files in a different format. Do not support it.
Signature · 1 line
2.41.0

Yes, this is also useful for my tool ccls:)
I agree that for assembly files, the compile_commands.json entries are
only useful for C preprocessing directives like #include and macros, so
.S files are needed but .s files are not. In addition, the kernel doesn't seem to have .s files.

maintainer Reviewed-by on v1 1/1
#2 lore raw
In reply to Benjamin Gray
Quoted 5 lines · Benjamin Gray

Like C source files, tooling can find it useful to have the assembly source file compilation recorded.

The .S extension appears to used across all architectures.

Quoted 8 lines

---

For example, I'm prototyping adding ASM support to clangd. It can use this information to determine the architecture, macros definitions, include paths, etc. on a per-file basis. I can capture this during compilation with tools like bear, but given this script exists and the

Right, this script was written specifically to avoid relying on external dependencies to generate a compile_commands file, so modifying this script is definitely the right thing to allow this to work for anyone working on the kernel and using the built-in kbuild targets for the static analyzer and compile_commands.json.

Quoted 1 line

change is trivial it seems like a good idea to adjust this script too.

Thanks for the patch, this seems reasonable.

Quoted 21 lines
---
 scripts/clang-tools/gen_compile_commands.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
scripts/clang-tools/gen_compile_commands.py +1 -1
index 15ba56527acd..a84cc5737c2c 100755
@@ -19,7 +19,7 @@ _DEFAULT_OUTPUT = 'compile_commands.json'
 _DEFAULT_LOG_LEVEL = 'WARNING'
 
 _FILENAME_PATTERN = r'^\..*\.cmd$'
-_LINE_PATTERN = r'^savedcmd_[^ ]*\.o := (.* )([^ ]*\.c) *(;|$)'
+_LINE_PATTERN = r'^savedcmd_[^ ]*\.o := (.* )([^ ]*\.[cS]) *(;|$)'
 _VALID_LOG_LEVELS = ['DEBUG', 'INFO', 'WARNING', 'ERROR', 'CRITICAL']
 # The tools/ directory adopts a different build system, and produces .cmd
 # files in a different format. Do not support it.
Signature · 1 line
2.41.0
reviewer Reviewed-by on v1 1/1
#3 lore raw
In reply to Benjamin Gray
Quoted 8 lines · Benjamin Gray

Like C source files, tooling can find it useful to have the assembly source file compilation recorded.

The .S extension appears to used across all architectures.

Quoted 7 lines

---

For example, I'm prototyping adding ASM support to clangd. It can use this information to determine the architecture, macros definitions, include paths, etc. on a per-file basis. I can capture this during compilation with tools like bear, but given this script exists and the change is trivial it seems like a good idea to adjust this script too.

Sounds cool, thanks for the patch!

Feel free to subscribe us to the clangd patches; we might have bandwidth to help review, or can at least follow along on progress.

Quoted 21 lines
---
 scripts/clang-tools/gen_compile_commands.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
scripts/clang-tools/gen_compile_commands.py +1 -2
index 15ba56527acd..a84cc5737c2c 100755
@@ -19,7 +19,7 @@ _DEFAULT_OUTPUT = 'compile_commands.json'
 _DEFAULT_LOG_LEVEL = 'WARNING'
 
 _FILENAME_PATTERN = r'^\..*\.cmd$'
-_LINE_PATTERN = r'^savedcmd_[^ ]*\.o := (.* )([^ ]*\.c) *(;|$)'
+_LINE_PATTERN = r'^savedcmd_[^ ]*\.o := (.* )([^ ]*\.[cS]) *(;|$)'
 _VALID_LOG_LEVELS = ['DEBUG', 'INFO', 'WARNING', 'ERROR', 'CRITICAL']
 # The tools/ directory adopts a different build system, and produces .cmd
 # files in a different format. Do not support it.
--

2.41.0

Signature · 2 lines
Thanks,
~Nick Desaulniers
#4 lore raw
In reply to Benjamin Gray
Quoted 9 lines · Benjamin Gray

Like C source files, tooling can find it useful to have the assembly source file compilation recorded.

The .S extension appears to used across all architectures.

---

Applied to linux-kbuild.
Thanks.

Quoted 26 lines

For example, I'm prototyping adding ASM support to clangd. It can use this information to determine the architecture, macros definitions, include paths, etc. on a per-file basis. I can capture this during compilation with tools like bear, but given this script exists and the change is trivial it seems like a good idea to adjust this script too.

---
 scripts/clang-tools/gen_compile_commands.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
scripts/clang-tools/gen_compile_commands.py +1 -2
index 15ba56527acd..a84cc5737c2c 100755
@@ -19,7 +19,7 @@ _DEFAULT_OUTPUT = 'compile_commands.json'
 _DEFAULT_LOG_LEVEL = 'WARNING'
 
 _FILENAME_PATTERN = r'^\..*\.cmd$'
-_LINE_PATTERN = r'^savedcmd_[^ ]*\.o := (.* )([^ ]*\.c) *(;|$)'
+_LINE_PATTERN = r'^savedcmd_[^ ]*\.o := (.* )([^ ]*\.[cS]) *(;|$)'
 _VALID_LOG_LEVELS = ['DEBUG', 'INFO', 'WARNING', 'ERROR', 'CRITICAL']
 # The tools/ directory adopts a different build system, and produces .cmd
 # files in a different format. Do not support it.
--

2.41.0

Signature · 2 lines
Best Regards
Masahiro Yamada