lkml.org 
[lkml]   [2021]   [Jun]   [26]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
From
Date
SubjectRe: [PATCH 2/3] checkpatch: tweak extern in C warning
On Sat, Jun 26, 2021 at 12:46 PM Joe Perches <joe@perches.com> wrote:
>
> On Fri, 2021-06-25 at 21:40 -0600, Jim Cromie wrote:
> > The extern-in-C rule has one important exception: the symbol is
> > defined in/by the linker script. By convention, these almost always
> > contain: _start, _stop, _end. Suppress the warning on such symbols.
> []
> > diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
> > []
> > @@ -6910,7 +6910,8 @@ sub process {
> > $stat =~ /^.\s*extern\s+/)
> > {
> > WARN("AVOID_EXTERNS",
> > - "externs should be avoided in .c files\n" . $herecurr);
> > + "externs should be avoided in .c files\n($stat)\n" . $herecurr)
> > + unless $stat =~ /_start|_stop|_end/;
>
> nak.
>
> As far as I can tell, there's no reason these symbols
> should not be in .h files.
>

judging from the codebase, it has been a case-by-case decision,
with 8/10 of the linker-vars extern'd into C files, not headers.

[jimc@frodo wk-test]$ perl -ne '/(\w*_(?:start|stop|end)(?:_\w+))/ and
print "$1\n"' `find . -name \*.lds.h` > symbols
[jimc@frodo wk-test]$ wc symbols
99 99 2112 symbols
[jimc@frodo wk-test]$ grep -n -r --exclude-dir=builds/ -f symbols . |
grep -E '\.c:' | grep extern | wc
79 331 6402
[jimc@frodo wk-test]$ grep -n -r --exclude-dir=builds/ -f symbols . |
grep -E '\.h' | grep extern | wc
19 81 1581

8/10 cases dont expose these symbols in headers,
Makes sense to me, mostly theyre internal, and often double-underscored too.
2/10 are presumably in headers for specific reasons.


> besides that:
>
> output is single line, $stat should not be used and
> using unless is not desired.
>

could you clarify ?
style issues are easy, std if form...
$stat is already used, it must contain extern to get here.
checking it for a likely-linker-symbol seems fair.

\
 
 \ /
  Last update: 2021-06-27 05:48    [W:0.051 / U:0.272 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site