Re: [PATCH] arm64: asm: vdso: gettimeofday: export common variables

Arnd Bergmann
2021-10-11T12:48:17Z

On Mon, Oct 11, 2021 at 12:03 PM Will Deacon <will@kernel.org> wrote:
>
> On Thu, Oct 07, 2021 at 09:57:54PM +0200, Anders Roxell wrote:
> > When building the kernel with sparse enabled 'C=1' the following
> > warnings can be seen:
> >
> > arch/arm64/kernel/vdso/vgettimeofday.c:9:5: warning: symbol '__kernel_clock_gettime' was not declared. Should it be static?
> > arch/arm64/kernel/vdso/vgettimeofday.c:15:5: warning: symbol '__kernel_gettimeofday' was not declared. Should it be static?
> > arch/arm64/kernel/vdso/vgettimeofday.c:21:5: warning: symbol '__kernel_clock_getres' was not declared. Should it be static?
> >
> > Rework so the variables are exported, since these variables are
> > created and used in vdso/vgettimeofday.c, also used in vdso.lds.S.
>
> Hmm, these functions are part of the vDSO and shouldn't be called from the
> kernel, so I don't think it makes sense to add prototypes for them to a
> kernel header, to be honest.

It's a recurring problem, and I have recommended this method to Anders as
I don't see any of the alternatives as better.

The thing is that both sparse (with make C=1) and gcc/clang (with make W=1)
warn about missing prototypes, and this catches a lot of real bugs. I hope
that we can eventually get to the point of enabling the warning by default for
all files, but that means we need a declaration for each global function and
variable.

It's possible to work around this by adding a declaration just before the
function definition to shut up those warnings, but I think that's worse because
we should not encourage having declarations in .c files where they may
get out of sync with a definition in another file. It's also possible that some
of the tools will start warning about extern declarations in .c files for this
reason, so it would end up as double work to add them here and move them
later.

Arnd