From: David Laight <David.Laight@ACULAB.COM>
To: 'Edward Liaw' <edliaw@google.com>, Justin Stitt <justinstitt@google.com>
Cc: "linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
Shuah Khan <shuah@kernel.org>,
Nathan Chancellor <nathan@kernel.org>,
Nick Desaulniers <ndesaulniers@google.com>,
Bill Wendling <morbo@google.com>,
"H. Peter Anvin" <hpa@linux.intel.com>,
Andy Lutomirski <luto@mit.edu>,
"linux-kselftest@vger.kernel.org"
<linux-kselftest@vger.kernel.org>,
"kernel-team@android.com" <kernel-team@android.com>,
"llvm@lists.linux.dev" <llvm@lists.linux.dev>
Subject: RE: [PATCH v3] selftests/vDSO: Explicit unsigned char conversion for elf_hash
Date: Mon, 6 May 2024 19:31:36 +0000 [thread overview]
Message-ID: <7332ff979f3440bd8362d37d4d1f34b8@AcuMS.aculab.com> (raw)
In-Reply-To: <CAG4es9WYrN_tOV1Uxi_ytO2qDRRZW5_uN=2p3iCg=P0r3mM3Og@mail.gmail.com>
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)
next prev parent reply other threads:[~2024-05-06 19:32 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
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 [this message]
2024-05-06 23:10 ` Edward Liaw
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=7332ff979f3440bd8362d37d4d1f34b8@AcuMS.aculab.com \
--to=david.laight@aculab.com \
--cc=edliaw@google.com \
--cc=hpa@linux.intel.com \
--cc=justinstitt@google.com \
--cc=kernel-team@android.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=llvm@lists.linux.dev \
--cc=luto@mit.edu \
--cc=morbo@google.com \
--cc=nathan@kernel.org \
--cc=ndesaulniers@google.com \
--cc=shuah@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox