Skip to contentSkip to conversation

checkpatch: add warning for avoiding .L prefix symbols in assembly files

PATCH In review Aditya Srivastava 3 participants 11 messages Jan 16, 2021 – Jan 19, 2021 Checkpatch

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 checkpatch: add warning for avoiding .L prefix symbols in assembly files

Local symbols prefixed with '.L' do not emit symbol table entries, as they have special meaning for the assembler.

'.L' prefixed symbols can be used within a code region, but should be avoided for denoting a range of code via 'SYM_*_START/END' annotations.

Add a new check to emit warning on finding the usage of '.L' symbols in '.S' files.

---
 scripts/checkpatch.pl | 6 ++++++
 1 file changed, 6 insertions(+)
scripts/checkpatch.pl +6 -0
index 7030c4d6d126..87d96a039e64 100755
@@ -3590,6 +3590,12 @@ sub process {
 			}
 		}
 
+# check for .L prefix local symbols in .S files
+		if ($realfile =~ /\.S$/ && $line =~ /\.L\S+/) {
+			WARN("AVOID_L_PREFIX",
+			     "Avoid using '.L' prefixed local symbol names for denoting a range of code via 'SYM_*_START/END' annotations; see Documentation/asm-annotations.rst\n" . $herecurr);
+		}
+
 # check we are in a valid source file C or perl if not then ignore this hunk
 		next if ($realfile !~ /\.(h|c|pl|dtsi|dts)$/);
 
Signature · 6 lines
2.17.1

_______________________________________________
Linux-kernel-mentees mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees
#1 lore raw
Quoted 35 lines · Aditya Srivastava

Local symbols prefixed with '.L' do not emit symbol table entries, as they have special meaning for the assembler.

'.L' prefixed symbols can be used within a code region, but should be avoided for denoting a range of code via 'SYM_*_START/END' annotations.

Add a new check to emit warning on finding the usage of '.L' symbols in '.S' files.

---
 scripts/checkpatch.pl | 6 ++++++
 1 file changed, 6 insertions(+)
scripts/checkpatch.pl +6 -1
index 7030c4d6d126..87d96a039e64 100755
@@ -3590,6 +3590,12 @@ sub process {
                        }
                }
 
+# check for .L prefix local symbols in .S files
+               if ($realfile =~ /\.S$/ && $line =~ /\.L\S+/) {
+                       WARN("AVOID_L_PREFIX",
+                            "Avoid using '.L' prefixed local symbol names for denoting a range of code via 'SYM_*_START/END' annotations; see Documentation/asm-annotations.rst\n" . $herecurr);
+               }
+
 # check we are in a valid source file C or perl if not then ignore this hunk
                next if ($realfile !~ /\.(h|c|pl|dtsi|dts)$/);
 
--
Quoted 1 line

2.17.1

From an earlier conversation:

Quoted 3 lines

So basically, you can use an .L symbol *inside* a function or a code segment, you just can't use the .L symbol to contain the code using a SYM_*_START/END annotation pair.

So this check warns on all uses of the .L prefix
I think that might be incorrect.

Thanks,
Dwaipayan.
_______________________________________________
Linux-kernel-mentees mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees

author
#2 lore raw
Quoted 39 lines · Dwaipayan Ray
Quoted 35 lines · Aditya Srivastava

Local symbols prefixed with '.L' do not emit symbol table entries, as they have special meaning for the assembler.

'.L' prefixed symbols can be used within a code region, but should be avoided for denoting a range of code via 'SYM_*_START/END' annotations.

Add a new check to emit warning on finding the usage of '.L' symbols in '.S' files.

---
 scripts/checkpatch.pl | 6 ++++++
 1 file changed, 6 insertions(+)
scripts/checkpatch.pl +6 -1
index 7030c4d6d126..87d96a039e64 100755
@@ -3590,6 +3590,12 @@ sub process {
                        }
                }
 
+# check for .L prefix local symbols in .S files
+               if ($realfile =~ /\.S$/ && $line =~ /\.L\S+/) {
+                       WARN("AVOID_L_PREFIX",
+                            "Avoid using '.L' prefixed local symbol names for denoting a range of code via 'SYM_*_START/END' annotations; see Documentation/asm-annotations.rst\n" . $herecurr);
+               }
+
 # check we are in a valid source file C or perl if not then ignore this hunk
                next if ($realfile !~ /\.(h|c|pl|dtsi|dts)$/);
 
--
Quoted 1 line

2.17.1

From an earlier conversation:

Quoted 7 lines
Quoted 3 lines

So basically, you can use an .L symbol *inside* a function or a code segment, you just can't use the .L symbol to contain the code using a SYM_*_START/END annotation pair.

So this check warns on all uses of the .L prefix
I think that might be incorrect.

Hey Dwaipayan,
I think you missed this:

Quoted 5 lines

- If the line contains ".L" prefixed symbol, give user a warning/check, so that they can ensure that the line is not inside START/END block. (As we may not be able to make sure about the same, if the START/END line is not in the patch; otherwise we could run a while loop)

At best, I think, we could use $context_function, which should work for patches, but again, this will not work for files.

Do you have any suggestions?

Thanks
Aditya
_______________________________________________
Linux-kernel-mentees mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees

#3 lore raw
Quoted 45 lines · Aditya
Quoted 43 lines · Dwaipayan Ray
Quoted 35 lines · Aditya Srivastava

Local symbols prefixed with '.L' do not emit symbol table entries, as they have special meaning for the assembler.

'.L' prefixed symbols can be used within a code region, but should be avoided for denoting a range of code via 'SYM_*_START/END' annotations.

Add a new check to emit warning on finding the usage of '.L' symbols in '.S' files.

---
 scripts/checkpatch.pl | 6 ++++++
 1 file changed, 6 insertions(+)
scripts/checkpatch.pl +6 -1
index 7030c4d6d126..87d96a039e64 100755
@@ -3590,6 +3590,12 @@ sub process {
                        }
                }
 
+# check for .L prefix local symbols in .S files
+               if ($realfile =~ /\.S$/ && $line =~ /\.L\S+/) {
+                       WARN("AVOID_L_PREFIX",
+                            "Avoid using '.L' prefixed local symbol names for denoting a range of code via 'SYM_*_START/END' annotations; see Documentation/asm-annotations.rst\n" . $herecurr);
+               }
+
 # check we are in a valid source file C or perl if not then ignore this hunk
                next if ($realfile !~ /\.(h|c|pl|dtsi|dts)$/);
 
--
Quoted 1 line

2.17.1

From an earlier conversation:

Quoted 3 lines

So basically, you can use an .L symbol *inside* a function or a code segment, you just can't use the .L symbol to contain the code using a SYM_*_START/END annotation pair.

Quoted 13 lines
Quoted 3 lines

So this check warns on all uses of the .L prefix
I think that might be incorrect.

Hey Dwaipayan,
I think you missed this:

Quoted 5 lines

- If the line contains ".L" prefixed symbol, give user a warning/check, so that they can ensure that the line is not inside START/END block. (As we may not be able to make sure about the same, if the START/END line is not in the patch; otherwise we could run a while loop)

Then again what percentage of users actually intended to use it in a local scope? That is actually a correct usage and checkpatch will keep complaining - there will be no way to remove the warning.

Quoted 5 lines

At best, I think, we could use $context_function, which should work for patches, but again, this will not work for files.

Do you have any suggestions?

Does $context_function work for .S files? Am not sure. But again that will not help much.

The main concern is not to allow .L prefix within a SYM_*_START...SYM_*_END annotation pair.

That means something like this will be disallowed:

SYM_FUNC_START(memset)

    .L ... etc

SYM_FUNC_END(memset)

One possible way can be to extract the context after getting a SYM_*_START. Following which the lines could be checked for a .L preifx.

But complexity wise I dont know if it would be worth it.

Thanks & Regards,
Dwaipayan.
_______________________________________________
Linux-kernel-mentees mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees

author
#4 lore raw
Quoted 72 lines · Dwaipayan Ray
Quoted 45 lines · Aditya
Quoted 43 lines · Dwaipayan Ray
Quoted 35 lines · Aditya Srivastava

Local symbols prefixed with '.L' do not emit symbol table entries, as they have special meaning for the assembler.

'.L' prefixed symbols can be used within a code region, but should be avoided for denoting a range of code via 'SYM_*_START/END' annotations.

Add a new check to emit warning on finding the usage of '.L' symbols in '.S' files.

---
 scripts/checkpatch.pl | 6 ++++++
 1 file changed, 6 insertions(+)
scripts/checkpatch.pl +6 -1
index 7030c4d6d126..87d96a039e64 100755
@@ -3590,6 +3590,12 @@ sub process {
                        }
                }
 
+# check for .L prefix local symbols in .S files
+               if ($realfile =~ /\.S$/ && $line =~ /\.L\S+/) {
+                       WARN("AVOID_L_PREFIX",
+                            "Avoid using '.L' prefixed local symbol names for denoting a range of code via 'SYM_*_START/END' annotations; see Documentation/asm-annotations.rst\n" . $herecurr);
+               }
+
 # check we are in a valid source file C or perl if not then ignore this hunk
                next if ($realfile !~ /\.(h|c|pl|dtsi|dts)$/);
 
--
Quoted 1 line

2.17.1

From an earlier conversation:

Quoted 3 lines

So basically, you can use an .L symbol *inside* a function or a code segment, you just can't use the .L symbol to contain the code using a SYM_*_START/END annotation pair.

Quoted 13 lines
Quoted 3 lines

So this check warns on all uses of the .L prefix
I think that might be incorrect.

Hey Dwaipayan,
I think you missed this:

Quoted 5 lines

- If the line contains ".L" prefixed symbol, give user a warning/check, so that they can ensure that the line is not inside START/END block. (As we may not be able to make sure about the same, if the START/END line is not in the patch; otherwise we could run a while loop)

Then again what percentage of users actually intended to use it in a local scope? That is actually a correct usage and checkpatch will keep complaining - there will be no way to remove the warning.

Quoted 5 lines

At best, I think, we could use $context_function, which should work for patches, but again, this will not work for files.

Do you have any suggestions?

Does $context_function work for .S files? Am not sure.> But again that will not help much.

Quoted 9 lines

The main concern is not to allow .L prefix within a SYM_*_START...SYM_*_END annotation pair.

That means something like this will be disallowed:

SYM_FUNC_START(memset)

    .L ... etc

SYM_FUNC_END(memset)

Yes, $context_function works inside .S files.
So, I think if it is inside one of the SYM_*_START contexts, it should work for us.

Quoted 5 lines

One possible way can be to extract the context after getting a SYM_*_START. Following which the lines could be checked for a .L preifx.

Quoted 1 line

But complexity wise I dont know if it would be worth it.

I think, we could do this for files.

But I am not sure about the complexity part.
Lukas, what do you think?

Thanks
Aditya
_______________________________________________
Linux-kernel-mentees mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees

#5 lore raw
Quoted 88 lines · Aditya
Quoted 72 lines · Dwaipayan Ray
Quoted 45 lines · Aditya
Quoted 43 lines · Dwaipayan Ray
Quoted 35 lines · Aditya Srivastava

Local symbols prefixed with '.L' do not emit symbol table entries, as they have special meaning for the assembler.

'.L' prefixed symbols can be used within a code region, but should be avoided for denoting a range of code via 'SYM_*_START/END' annotations.

Add a new check to emit warning on finding the usage of '.L' symbols in '.S' files.

---
 scripts/checkpatch.pl | 6 ++++++
 1 file changed, 6 insertions(+)
scripts/checkpatch.pl +6 -1
index 7030c4d6d126..87d96a039e64 100755
@@ -3590,6 +3590,12 @@ sub process {
                        }
                }
 
+# check for .L prefix local symbols in .S files
+               if ($realfile =~ /\.S$/ && $line =~ /\.L\S+/) {
+                       WARN("AVOID_L_PREFIX",
+                            "Avoid using '.L' prefixed local symbol names for denoting a range of code via 'SYM_*_START/END' annotations; see Documentation/asm-annotations.rst\n" . $herecurr);
+               }
+
 # check we are in a valid source file C or perl if not then ignore this hunk
                next if ($realfile !~ /\.(h|c|pl|dtsi|dts)$/);
 
--
Quoted 1 line

2.17.1

From an earlier conversation:

Quoted 3 lines

So basically, you can use an .L symbol *inside* a function or a code segment, you just can't use the .L symbol to contain the code using a SYM_*_START/END annotation pair.

Quoted 13 lines
Quoted 3 lines

So this check warns on all uses of the .L prefix
I think that might be incorrect.

Hey Dwaipayan,
I think you missed this:

Quoted 5 lines

- If the line contains ".L" prefixed symbol, give user a warning/check, so that they can ensure that the line is not inside START/END block. (As we may not be able to make sure about the same, if the START/END line is not in the patch; otherwise we could run a while loop)

Then again what percentage of users actually intended to use it in a local scope? That is actually a correct usage and checkpatch will keep complaining - there will be no way to remove the warning.

Quoted 5 lines

At best, I think, we could use $context_function, which should work for patches, but again, this will not work for files.

Do you have any suggestions?

Does $context_function work for .S files? Am not sure.> But again that will not help much.

Quoted 9 lines

The main concern is not to allow .L prefix within a SYM_*_START...SYM_*_END annotation pair.

That means something like this will be disallowed:

SYM_FUNC_START(memset)

    .L ... etc

SYM_FUNC_END(memset)

Yes, $context_function works inside .S files.
So, I think if it is inside one of the SYM_*_START contexts, it should work for us.

Quoted 8 lines
Quoted 5 lines

One possible way can be to extract the context after getting a SYM_*_START. Following which the lines could be checked for a .L preifx.

Quoted 1 line

But complexity wise I dont know if it would be worth it.

I think, we could do this for files.

Just run it on the current kernel source and find out how many cases would generally match.

If it is just a few hundred occurrences, use a simple rule, not a complex one that hardly works on patches.

Lukas
_______________________________________________
Linux-kernel-mentees mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees

#6 lore raw

PATCH 1/1 checkpatch: add warning for avoiding .L prefix symbols in assembly files

Local symbols prefixed with '.L' do not emit symbol table entries, as they have special meaning for the assembler.

'.L' prefixed symbols can be used within a code region, but should be avoided for denoting a range of code via 'SYM_*_START/END' annotations.

Add a new check to emit warning on finding the usage of '.L' symbols in '.S' files, if it lies within SYM_*_START/END annotation pair.

---
 scripts/checkpatch.pl | 22 ++++++++++++++++++++++
 1 file changed, 22 insertions(+)
scripts/checkpatch.pl +22 -0
index 7030c4d6d126..858b5def61e9 100755
@@ -2501,6 +2501,9 @@ sub process {
 
 	my $checklicenseline = 1;
 
+	# record SYM_*_START/END annotation pair count, for AVOID_L_PREFIX
+	my $sym_start_block = 0;
+
 	sanitise_line_reset();
 	my $line;
 	foreach my $rawline (@rawlines) {
@@ -3590,6 +3593,25 @@ sub process {
 			}
 		}
 
+# check for .L prefix local symbols in .S files
+		if ($realfile =~ /\.S$/) {
+			if ($line =~ /SYM_.*_START/ ||
+			    (defined $context_function && $context_function =~ /SYM_.*_START/)) {
+				$sym_start_block++;
+			}
+
+			if ($line=~ /\.L\S+/ &&		# line contains .L prefixed local symbol
+			    $sym_start_block > 0) {	# lies between SYM_*_START and SYM_*_END pair
+				WARN("AVOID_L_PREFIX",
+					"Avoid using '.L' prefixed local symbol names for denoting a range of code via 'SYM_*_START/END' annotations; see Documentation/asm-annotations.rst\n" . $herecurr);
+			}
+
+			if ($line =~ /SYM_.*_END/ ||
+			    (defined $context_function && $context_function =~ /SYM_.*_END/)) {
+				$sym_start_block--;
+			}
+		}
+
 # check we are in a valid source file C or perl if not then ignore this hunk
 		next if ($realfile !~ /\.(h|c|pl|dtsi|dts)$/);
 
Signature · 6 lines
2.17.1

_______________________________________________
Linux-kernel-mentees mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees
#7 lore raw
Quoted 8 lines · Aditya Srivastava

Local symbols prefixed with '.L' do not emit symbol table entries, as they have special meaning for the assembler.

'.L' prefixed symbols can be used within a code region, but should be avoided for denoting a range of code via 'SYM_*_START/END' annotations.

Add a new check to emit warning on finding the usage of '.L' symbols

to emit a warning

Quoted 3 lines

in '.S' files, if it lies within SYM_*_START/END annotation pair.

Hmm, that is not an email?

Did you test running it on the patch that introduced the bug initially which then led to the overall discussion I pointed out to you?

Lukas

Quoted 47 lines
---
 scripts/checkpatch.pl | 22 ++++++++++++++++++++++
 1 file changed, 22 insertions(+)
scripts/checkpatch.pl +22 -1
index 7030c4d6d126..858b5def61e9 100755
@@ -2501,6 +2501,9 @@ sub process {
 
        my $checklicenseline = 1;
 
+       # record SYM_*_START/END annotation pair count, for AVOID_L_PREFIX
+       my $sym_start_block = 0;
+
        sanitise_line_reset();
        my $line;
        foreach my $rawline (@rawlines) {
@@ -3590,6 +3593,25 @@ sub process {
                        }
                }
 
+# check for .L prefix local symbols in .S files
+               if ($realfile =~ /\.S$/) {
+                       if ($line =~ /SYM_.*_START/ ||
+                           (defined $context_function && $context_function =~ /SYM_.*_START/)) {
+                               $sym_start_block++;
+                       }
+
+                       if ($line=~ /\.L\S+/ &&         # line contains .L prefixed local symbol
+                           $sym_start_block > 0) {     # lies between SYM_*_START and SYM_*_END pair
+                               WARN("AVOID_L_PREFIX",
+                                       "Avoid using '.L' prefixed local symbol names for denoting a range of code via 'SYM_*_START/END' annotations; see Documentation/asm-annotations.rst\n" . $herecurr);
+                       }
+
+                       if ($line =~ /SYM_.*_END/ ||
+                           (defined $context_function && $context_function =~ /SYM_.*_END/)) {
+                               $sym_start_block--;
+                       }
+               }
+
 # check we are in a valid source file C or perl if not then ignore this hunk
                next if ($realfile !~ /\.(h|c|pl|dtsi|dts)$/);
 
--
Quoted 2 lines

2.17.1

_______________________________________________
Linux-kernel-mentees mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees

author
#8 lore raw
Quoted 5 lines · Lukas Bulwahn
Quoted 4 lines · Aditya Srivastava

Local symbols prefixed with '.L' do not emit symbol table entries, as they have special meaning for the assembler.

Quoted 7 lines
Quoted 4 lines

'.L' prefixed symbols can be used within a code region, but should be avoided for denoting a range of code via 'SYM_*_START/END' annotations.

Add a new check to emit warning on finding the usage of '.L' symbols

to emit a warning

Okay

Quoted 6 lines
Quoted 3 lines

in '.S' files, if it lies within SYM_*_START/END annotation pair.

Hmm, that is not an email?

Oops, I'll fix it.

Quoted 3 lines

Did you test running it on the patch that introduced the bug initially which then led to the overall discussion I pointed out to you?

Hi Lukas
So, the patch led to the initial discussion was probably this:
https://groups.google.com/g/clang-built-linux/c/1C6YoJKBsQQ/m/a8IS1NjGAgAJ

This patch is related to changes made in tools/objtool. So, we probably cannot test this patch for AVOID_L_PREFIX warning.

I'll walk you through the discussion:

Because of the above changes in objtool, [PATCH] x86/entry: use STB_GLOBAL for register restoring thunk was proposed
(https://groups.google.com/g/clang-built-linux/c/-drkmLgu-cU/m/qWnKkZWFBgAJ)

It was later decided that the changes can be instead made to .L prefix local symbols here for avoiding the objtool warning:
https://groups.google.com/g/clang-built-linux/c/-drkmLgu-cU/m/MtjkJK6LCgAJ

And for standardizing this practice, the suggestion for checkpatch rule was made here:
https://groups.google.com/g/clang-built-linux/c/-drkmLgu-cU/m/4staOlf-CgAJ

However, I have tested the patch on arch/x86/ files and also the patch proposed here fixing for one of those files.

As expected, I got no warnings for the patch fixing the warnings for thunk_64.S file, and some warnings for files where the prefix was used.

Thanks
Aditya
_______________________________________________
Linux-kernel-mentees mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees

#9 lore raw

PATCH 1/1 checkpatch: add warning for avoiding .L prefix symbols in assembly files

Local symbols prefixed with '.L' do not emit symbol table entries, as they have special meaning for the assembler.

'.L' prefixed symbols can be used within a code region, but should be avoided for denoting a range of code via 'SYM_*_START/END' annotations.

Add a new check to emit a warning on finding the usage of '.L' symbols in '.S' files, if it lies within SYM_*_START/END annotation pair.

---
 scripts/checkpatch.pl | 22 ++++++++++++++++++++++
 1 file changed, 22 insertions(+)
scripts/checkpatch.pl +22 -0
index 7030c4d6d126..858b5def61e9 100755
@@ -2501,6 +2501,9 @@ sub process {
 
 	my $checklicenseline = 1;
 
+	# record SYM_*_START/END annotation pair count, for AVOID_L_PREFIX
+	my $sym_start_block = 0;
+
 	sanitise_line_reset();
 	my $line;
 	foreach my $rawline (@rawlines) {
@@ -3590,6 +3593,25 @@ sub process {
 			}
 		}
 
+# check for .L prefix local symbols in .S files
+		if ($realfile =~ /\.S$/) {
+			if ($line =~ /SYM_.*_START/ ||
+			    (defined $context_function && $context_function =~ /SYM_.*_START/)) {
+				$sym_start_block++;
+			}
+
+			if ($line=~ /\.L\S+/ &&		# line contains .L prefixed local symbol
+			    $sym_start_block > 0) {	# lies between SYM_*_START and SYM_*_END pair
+				WARN("AVOID_L_PREFIX",
+					"Avoid using '.L' prefixed local symbol names for denoting a range of code via 'SYM_*_START/END' annotations; see Documentation/asm-annotations.rst\n" . $herecurr);
+			}
+
+			if ($line =~ /SYM_.*_END/ ||
+			    (defined $context_function && $context_function =~ /SYM_.*_END/)) {
+				$sym_start_block--;
+			}
+		}
+
 # check we are in a valid source file C or perl if not then ignore this hunk
 		next if ($realfile !~ /\.(h|c|pl|dtsi|dts)$/);
 
Signature · 6 lines
2.17.1

_______________________________________________
Linux-kernel-mentees mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees
#10 lore raw
Quoted 7 lines · Aditya Srivastava

Local symbols prefixed with '.L' do not emit symbol table entries, as they have special meaning for the assembler.

'.L' prefixed symbols can be used within a code region, but should be avoided for denoting a range of code via 'SYM_*_START/END' annotations.

Quoted 7 lines

Add a new check to emit a warning on finding the usage of '.L' symbols in '.S' files, if it lies within SYM_*_START/END annotation pair.

---

Okay, send it out to the initial discussion group (with the standard CCs for mentees and checkpatch) and lkml. Then we see.

Lukas
_______________________________________________
Linux-kernel-mentees mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees