* [PATCH v3] selftests/vDSO: Explicit unsigned char conversion for elf_hash
@ 2024-05-01 18:06 Edward Liaw
2024-05-01 19:54 ` Justin Stitt
0 siblings, 1 reply; 8+ messages in thread
From: Edward Liaw @ 2024-05-01 18:06 UTC (permalink / raw
To: linux-kernel, Shuah Khan, Nathan Chancellor, Nick Desaulniers,
Bill Wendling, Justin Stitt, H. Peter Anvin, Andy Lutomirski
Cc: linux-kselftest, kernel-team, Edward Liaw, llvm
Fixes clang compilation warnings by adding explicit unsigned conversion:
parse_vdso.c:206:22: warning: passing 'const char *' to parameter of
type 'const unsigned char *' converts between pointers to integer types
where one is of the unique plain 'char' type and the other is not
[-Wpointer-sign]
ver_hash = elf_hash(version);
^~~~~~~
parse_vdso.c:59:52: note: passing argument to parameter 'name' here
static unsigned long elf_hash(const unsigned char *name)
^
parse_vdso.c:207:46: warning: passing 'const char *' to parameter of
type 'const unsigned char *' converts between pointers to integer types
where one is of the unique plain 'char' type and the other is not
[-Wpointer-sign]
ELF(Word) chain = vdso_info.bucket[elf_hash(name) % vdso_info.nbucket];
^~~~
parse_vdso.c:59:52: note: passing argument to parameter 'name' here
static unsigned long elf_hash(const unsigned char *name)
Fixes: 98eedc3a9dbf ("Document the vDSO and add a reference parser")
Signed-off-by: Edward Liaw <edliaw@google.com>
---
v2: update commit message with correct compiler warning
v3: fix checkpatch errors and indentation
---
tools/testing/selftests/vDSO/parse_vdso.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/tools/testing/selftests/vDSO/parse_vdso.c b/tools/testing/selftests/vDSO/parse_vdso.c
index 413f75620a35..9e29ff0657ea 100644
--- a/tools/testing/selftests/vDSO/parse_vdso.c
+++ b/tools/testing/selftests/vDSO/parse_vdso.c
@@ -203,8 +203,9 @@ void *vdso_sym(const char *version, const char *name)
if (!vdso_info.valid)
return 0;
- ver_hash = elf_hash(version);
- ELF(Word) chain = vdso_info.bucket[elf_hash(name) % vdso_info.nbucket];
+ ver_hash = elf_hash((const unsigned char *)version);
+ ELF(Word) chain = vdso_info.bucket[
+ elf_hash((const unsigned char *)name) % vdso_info.nbucket];
for (; chain != STN_UNDEF; chain = vdso_info.chain[chain]) {
ELF(Sym) *sym = &vdso_info.symtab[chain];
--
2.45.0.rc0.197.gbae5840b3b-goog
^ permalink raw reply related [flat|nested] 8+ messages in thread
* Re: [PATCH v3] selftests/vDSO: Explicit unsigned char conversion for elf_hash
2024-05-01 18:06 [PATCH v3] selftests/vDSO: Explicit unsigned char conversion for elf_hash Edward Liaw
@ 2024-05-01 19:54 ` Justin Stitt
2024-05-01 20:21 ` Edward Liaw
2024-05-05 13:20 ` David Laight
0 siblings, 2 replies; 8+ messages in thread
From: Justin Stitt @ 2024-05-01 19:54 UTC (permalink / raw
To: Edward Liaw
Cc: linux-kernel, Shuah Khan, Nathan Chancellor, Nick Desaulniers,
Bill Wendling, H. Peter Anvin, Andy Lutomirski, linux-kselftest,
kernel-team, llvm
Hi,
On Wed, May 01, 2024 at 06:06:18PM +0000, Edward Liaw wrote:
> Fixes clang compilation warnings by adding explicit unsigned conversion:
>
> parse_vdso.c:206:22: warning: passing 'const char *' to parameter of
> type 'const unsigned char *' converts between pointers to integer types
> where one is of the unique plain 'char' type and the other is not
> [-Wpointer-sign]
> ver_hash = elf_hash(version);
> ^~~~~~~
> parse_vdso.c:59:52: note: passing argument to parameter 'name' here
> static unsigned long elf_hash(const unsigned char *name)
> ^
> parse_vdso.c:207:46: warning: passing 'const char *' to parameter of
> type 'const unsigned char *' converts between pointers to integer types
> where one is of the unique plain 'char' type and the other is not
> [-Wpointer-sign]
> ELF(Word) chain = vdso_info.bucket[elf_hash(name) % vdso_info.nbucket];
> ^~~~
> parse_vdso.c:59:52: note: passing argument to parameter 'name' here
> static unsigned long elf_hash(const unsigned char *name)
>
> Fixes: 98eedc3a9dbf ("Document the vDSO and add a reference parser")
> Signed-off-by: Edward Liaw <edliaw@google.com>
> ---
> v2: update commit message with correct compiler warning
> v3: fix checkpatch errors and indentation
> ---
> tools/testing/selftests/vDSO/parse_vdso.c | 5 +++--
> 1 file changed, 3 insertions(+), 2 deletions(-)
>
> diff --git a/tools/testing/selftests/vDSO/parse_vdso.c b/tools/testing/selftests/vDSO/parse_vdso.c
> index 413f75620a35..9e29ff0657ea 100644
> --- a/tools/testing/selftests/vDSO/parse_vdso.c
> +++ b/tools/testing/selftests/vDSO/parse_vdso.c
> @@ -203,8 +203,9 @@ void *vdso_sym(const char *version, const char *name)
Is it possible to just change the types of the parameters of vdso_sym()
or does that trigger even more warnings on the callsites of vdso_sym()?
Either way, this looks ok to me.
Acked-by: Justin Stitt <justinstitt@google.com>
> if (!vdso_info.valid)
> return 0;
>
> - ver_hash = elf_hash(version);
> - ELF(Word) chain = vdso_info.bucket[elf_hash(name) % vdso_info.nbucket];
> + ver_hash = elf_hash((const unsigned char *)version);
> + ELF(Word) chain = vdso_info.bucket[
> + elf_hash((const unsigned char *)name) % vdso_info.nbucket];
>
> for (; chain != STN_UNDEF; chain = vdso_info.chain[chain]) {
> ELF(Sym) *sym = &vdso_info.symtab[chain];
> --
> 2.45.0.rc0.197.gbae5840b3b-goog
>
Thanks
Justin
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH v3] selftests/vDSO: Explicit unsigned char conversion for elf_hash
2024-05-01 19:54 ` Justin Stitt
@ 2024-05-01 20:21 ` Edward Liaw
2024-05-05 13:20 ` David Laight
1 sibling, 0 replies; 8+ messages in thread
From: Edward Liaw @ 2024-05-01 20:21 UTC (permalink / raw
To: Justin Stitt
Cc: linux-kernel, Shuah Khan, Nathan Chancellor, Nick Desaulniers,
Bill Wendling, H. Peter Anvin, Andy Lutomirski, linux-kselftest,
kernel-team, llvm
On Wed, May 1, 2024 at 12:54 PM Justin Stitt <justinstitt@google.com> wrote:
>
> Hi,
>
> On Wed, May 01, 2024 at 06:06:18PM +0000, Edward Liaw wrote:
> > Fixes clang compilation warnings by adding explicit unsigned conversion:
> >
> > parse_vdso.c:206:22: warning: passing 'const char *' to parameter of
> > type 'const unsigned char *' converts between pointers to integer types
> > where one is of the unique plain 'char' type and the other is not
> > [-Wpointer-sign]
> > ver_hash = elf_hash(version);
> > ^~~~~~~
> > parse_vdso.c:59:52: note: passing argument to parameter 'name' here
> > static unsigned long elf_hash(const unsigned char *name)
> > ^
> > parse_vdso.c:207:46: warning: passing 'const char *' to parameter of
> > type 'const unsigned char *' converts between pointers to integer types
> > where one is of the unique plain 'char' type and the other is not
> > [-Wpointer-sign]
> > ELF(Word) chain = vdso_info.bucket[elf_hash(name) % vdso_info.nbucket];
> > ^~~~
> > parse_vdso.c:59:52: note: passing argument to parameter 'name' here
> > static unsigned long elf_hash(const unsigned char *name)
> >
> > Fixes: 98eedc3a9dbf ("Document the vDSO and add a reference parser")
> > Signed-off-by: Edward Liaw <edliaw@google.com>
>
> > ---
> > v2: update commit message with correct compiler warning
> > v3: fix checkpatch errors and indentation
> > ---
> > tools/testing/selftests/vDSO/parse_vdso.c | 5 +++--
> > 1 file changed, 3 insertions(+), 2 deletions(-)
> >
> > diff --git a/tools/testing/selftests/vDSO/parse_vdso.c b/tools/testing/selftests/vDSO/parse_vdso.c
> > index 413f75620a35..9e29ff0657ea 100644
> > --- a/tools/testing/selftests/vDSO/parse_vdso.c
> > +++ b/tools/testing/selftests/vDSO/parse_vdso.c
> > @@ -203,8 +203,9 @@ void *vdso_sym(const char *version, const char *name)
>
> Is it possible to just change the types of the parameters of vdso_sym()
> or does that trigger even more warnings on the callsites of vdso_sym()?
It does trigger more warnings on the callsites unfortunately.
>
> Either way, this looks ok to me.
>
> Acked-by: Justin Stitt <justinstitt@google.com>
>
> > if (!vdso_info.valid)
> > return 0;
> >
> > - ver_hash = elf_hash(version);
> > - ELF(Word) chain = vdso_info.bucket[elf_hash(name) % vdso_info.nbucket];
> > + ver_hash = elf_hash((const unsigned char *)version);
> > + ELF(Word) chain = vdso_info.bucket[
> > + elf_hash((const unsigned char *)name) % vdso_info.nbucket];
> >
> > for (; chain != STN_UNDEF; chain = vdso_info.chain[chain]) {
> > ELF(Sym) *sym = &vdso_info.symtab[chain];
> > --
> > 2.45.0.rc0.197.gbae5840b3b-goog
> >
>
> Thanks
> Justin
^ permalink raw reply [flat|nested] 8+ messages in thread
* RE: [PATCH v3] selftests/vDSO: Explicit unsigned char conversion for elf_hash
2024-05-01 19:54 ` Justin Stitt
2024-05-01 20:21 ` Edward Liaw
@ 2024-05-05 13:20 ` David Laight
2024-05-06 17:16 ` Justin Stitt
1 sibling, 1 reply; 8+ messages in thread
From: David Laight @ 2024-05-05 13:20 UTC (permalink / raw
To: 'Justin Stitt', Edward Liaw
Cc: linux-kernel@vger.kernel.org, Shuah Khan, Nathan Chancellor,
Nick Desaulniers, Bill Wendling, H. Peter Anvin, Andy Lutomirski,
linux-kselftest@vger.kernel.org, kernel-team@android.com,
llvm@lists.linux.dev
From: Justin Stitt
> Sent: 01 May 2024 20:55
...
> > static unsigned long elf_hash(const unsigned char *name)
...
> Is it possible to just change the types of the parameters of vdso_sym()
> or does that trigger even more warnings on the callsites of vdso_sym()?
Isn't the problem the definition of elf_hash()?
A '\0' terminated string really ought to be 'char *' not 'unsigned char *'.
David
-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
Registration No: 1397386 (Wales)
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH v3] selftests/vDSO: Explicit unsigned char conversion for elf_hash
2024-05-05 13:20 ` David Laight
@ 2024-05-06 17:16 ` Justin Stitt
2024-05-06 17:34 ` Edward Liaw
0 siblings, 1 reply; 8+ messages in thread
From: Justin Stitt @ 2024-05-06 17:16 UTC (permalink / raw
To: David Laight
Cc: Edward Liaw, linux-kernel@vger.kernel.org, Shuah Khan,
Nathan Chancellor, Nick Desaulniers, Bill Wendling,
H. Peter Anvin, Andy Lutomirski, linux-kselftest@vger.kernel.org,
kernel-team@android.com, llvm@lists.linux.dev
On Sun, May 5, 2024 at 6:21 AM David Laight <David.Laight@aculab.com> wrote:
>
> From: Justin Stitt
> > Sent: 01 May 2024 20:55
> ...
> > > static unsigned long elf_hash(const unsigned char *name)
> ...
> > Is it possible to just change the types of the parameters of vdso_sym()
> > or does that trigger even more warnings on the callsites of vdso_sym()?
>
> Isn't the problem the definition of elf_hash()?
> A '\0' terminated string really ought to be 'char *' not 'unsigned char *'.
Right, although note this comment just about its definition:
/* Straight from the ELF specification. */
static unsigned long elf_hash(const unsigned char *name)
{
which indeed matches [1]
[1]: https://man.freebsd.org/cgi/man.cgi?query=elf_hash&sektion=3&apropos=0&manpath=FreeBSD+7.1-RELEASE
>
> David
>
> -
> Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
> Registration No: 1397386 (Wales)
>
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH v3] selftests/vDSO: Explicit unsigned char conversion for elf_hash
2024-05-06 17:16 ` Justin Stitt
@ 2024-05-06 17:34 ` Edward Liaw
2024-05-06 19:31 ` David Laight
0 siblings, 1 reply; 8+ messages in thread
From: Edward Liaw @ 2024-05-06 17:34 UTC (permalink / raw
To: Justin Stitt
Cc: David Laight, linux-kernel@vger.kernel.org, Shuah Khan,
Nathan Chancellor, Nick Desaulniers, Bill Wendling,
H. Peter Anvin, Andy Lutomirski, linux-kselftest@vger.kernel.org,
kernel-team@android.com, llvm@lists.linux.dev
On Mon, May 6, 2024 at 10:16 AM Justin Stitt <justinstitt@google.com> wrote:
>
> On Sun, May 5, 2024 at 6:21 AM David Laight <David.Laight@aculab.com> wrote:
> >
> > From: Justin Stitt
> > > Sent: 01 May 2024 20:55
> > ...
> > > > static unsigned long elf_hash(const unsigned char *name)
> > ...
> > > Is it possible to just change the types of the parameters of vdso_sym()
> > > or does that trigger even more warnings on the callsites of vdso_sym()?
> >
> > Isn't the problem the definition of elf_hash()?
> > A '\0' terminated string really ought to be 'char *' not 'unsigned char *'.
>
> Right, although note this comment just about its definition:
>
> /* Straight from the ELF specification. */
> static unsigned long elf_hash(const unsigned char *name)
> {
>
> which indeed matches [1]
>
> [1]: https://man.freebsd.org/cgi/man.cgi?query=elf_hash&sektion=3&apropos=0&manpath=FreeBSD+7.1-RELEASE
How about I move the type cast into elf_hash, like libelf does
https://sourceforge.net/p/elftoolchain/code/HEAD/tree/trunk/libelf/elf_hash.c#l47
diff --git a/tools/testing/selftests/vDSO/parse_vdso.c
b/tools/testing/selftests/vDSO/parse_vdso.c
index 413f75620a35..33db8abd7d59 100644
--- a/tools/testing/selftests/vDSO/parse_vdso.c
+++ b/tools/testing/selftests/vDSO/parse_vdso.c
@@ -56,12 +56,15 @@ static struct vdso_info
} vdso_info;
/* Straight from the ELF specification. */
-static unsigned long elf_hash(const unsigned char *name)
+static unsigned long elf_hash(const char *name)
{
unsigned long h = 0, g;
- while (*name)
+ const unsigned char *s;
+
+ s = (const unsigned char *) name;
+ while (*s)
{
- h = (h << 4) + *name++;
+ h = (h << 4) + *s++;
if (g = h & 0xf0000000)
h ^= g >> 24;
h &= ~g;
>
> >
> > David
> >
> > -
> > Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
> > Registration No: 1397386 (Wales)
> >
^ permalink raw reply related [flat|nested] 8+ messages in thread
* RE: [PATCH v3] selftests/vDSO: Explicit unsigned char conversion for elf_hash
2024-05-06 17:34 ` Edward Liaw
@ 2024-05-06 19:31 ` David Laight
2024-05-06 23:10 ` Edward Liaw
0 siblings, 1 reply; 8+ messages in thread
From: David Laight @ 2024-05-06 19:31 UTC (permalink / raw
To: 'Edward Liaw', Justin Stitt
Cc: linux-kernel@vger.kernel.org, Shuah Khan, Nathan Chancellor,
Nick Desaulniers, Bill Wendling, H. Peter Anvin, Andy Lutomirski,
linux-kselftest@vger.kernel.org, kernel-team@android.com,
llvm@lists.linux.dev
From: Edward Liaw
> Sent: 06 May 2024 18:34
>
> On Mon, May 6, 2024 at 10:16 AM Justin Stitt <justinstitt@google.com> wrote:
> >
> > On Sun, May 5, 2024 at 6:21 AM David Laight <David.Laight@aculab.com> wrote:
> > >
> > > From: Justin Stitt
> > > > Sent: 01 May 2024 20:55
> > > ...
> > > > > static unsigned long elf_hash(const unsigned char *name)
> > > ...
> > > > Is it possible to just change the types of the parameters of vdso_sym()
> > > > or does that trigger even more warnings on the callsites of vdso_sym()?
> > >
> > > Isn't the problem the definition of elf_hash()?
> > > A '\0' terminated string really ought to be 'char *' not 'unsigned char *'.
> >
> > Right, although note this comment just about its definition:
> >
> > /* Straight from the ELF specification. */
> > static unsigned long elf_hash(const unsigned char *name)
> > {
> >
> > which indeed matches [1]
> >
> > [1]: https://man.freebsd.org/cgi/man.cgi?query=elf_hash&sektion=3&apropos=0&manpath=FreeBSD+7.1-
> RELEASE
>
> How about I move the type cast into elf_hash, like libelf does
> https://sourceforge.net/p/elftoolchain/code/HEAD/tree/trunk/libelf/elf_hash.c#l47
>
> diff --git a/tools/testing/selftests/vDSO/parse_vdso.c
> b/tools/testing/selftests/vDSO/parse_vdso.c
> index 413f75620a35..33db8abd7d59 100644
> --- a/tools/testing/selftests/vDSO/parse_vdso.c
> +++ b/tools/testing/selftests/vDSO/parse_vdso.c
> @@ -56,12 +56,15 @@ static struct vdso_info
> } vdso_info;
>
> /* Straight from the ELF specification. */
> -static unsigned long elf_hash(const unsigned char *name)
> +static unsigned long elf_hash(const char *name)
> {
> unsigned long h = 0, g;
> - while (*name)
> + const unsigned char *s;
> +
> + s = (const unsigned char *) name;
> + while (*s)
> {
> - h = (h << 4) + *name++;
> + h = (h << 4) + *s++;
> if (g = h & 0xf0000000)
> h ^= g >> 24;
> h &= ~g;
That makes a lot more sense.
David
-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
Registration No: 1397386 (Wales)
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH v3] selftests/vDSO: Explicit unsigned char conversion for elf_hash
2024-05-06 19:31 ` David Laight
@ 2024-05-06 23:10 ` Edward Liaw
0 siblings, 0 replies; 8+ messages in thread
From: Edward Liaw @ 2024-05-06 23:10 UTC (permalink / raw
To: David Laight
Cc: Justin Stitt, linux-kernel@vger.kernel.org, Shuah Khan,
Nathan Chancellor, Nick Desaulniers, Bill Wendling,
H. Peter Anvin, Andy Lutomirski, linux-kselftest@vger.kernel.org,
kernel-team@android.com, llvm@lists.linux.dev
On Mon, May 6, 2024 at 12:32 PM David Laight <David.Laight@aculab.com> wrote:
>
>
> That makes a lot more sense.
I sent v4 https://lore.kernel.org/all/20240506181951.1804451-1-edliaw@google.com/.
I updated the commit log to reflect the change but I'm not sure if I
did it right for the mailing list. Should I have added --in-reply-to
this thread?
Edward
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2024-05-06 23:10 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-05-01 18:06 [PATCH v3] selftests/vDSO: Explicit unsigned char conversion for elf_hash Edward Liaw
2024-05-01 19:54 ` Justin Stitt
2024-05-01 20:21 ` Edward Liaw
2024-05-05 13:20 ` David Laight
2024-05-06 17:16 ` Justin Stitt
2024-05-06 17:34 ` Edward Liaw
2024-05-06 19:31 ` David Laight
2024-05-06 23:10 ` Edward Liaw
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).