public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
From: Alan Modra <amodra@gmail.com>
To: Mark Harmstone <mark@harmstone.com>
Cc: binutils@sourceware.org, martin@martin.st
Subject: Re: [PATCH v4 2/2] ld: Add minimal pdb generation
Date: Wed, 12 Oct 2022 10:58:41 +1030	[thread overview]
Message-ID: <Y0YKOe6KJ78OeDxH@squeak.grove.modra.org> (raw)
In-Reply-To: <20221011175332.17156-2-mark@harmstone.com>

On Tue, Oct 11, 2022 at 06:53:32PM +0100, Mark Harmstone wrote:
> +/* Calculate the hash of a given string.  */
> +static uint32_t
> +calc_hash (const char *data, size_t len)
> +{
> +  uint32_t hash = 0;
> +
> +  while (len >= 4)
> +    {
> +      hash ^= *(uint32_t *) data;
> +      data += 4;
> +      len -= 4;
> +    }
> +
> +  if (len >= 2)
> +    {
> +      hash ^= *(uint16_t *) data;
> +      data += 2;
> +      len -= 2;
> +    }
> +
> +  if (len != 0)
> +    hash ^= *data;
> +
> +  hash |= 0x20202020;
> +  hash ^= (hash >> 11);
> +
> +  return hash ^ (hash >> 16);
> +}

I think the above code will calculate different hash values on
big-endian machines to little-endian.  Also, unless "data" is aligned
as for uint32_t you run the risk of alignment traps on machines with
strict alignment requirements.

-- 
Alan Modra
Australia Development Lab, IBM

  reply	other threads:[~2022-10-12  0:28 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-10-11 17:53 [PATCH v4 1/2] ld: Add --pdb option Mark Harmstone
2022-10-11 17:53 ` [PATCH v4 2/2] ld: Add minimal pdb generation Mark Harmstone
2022-10-12  0:28   ` Alan Modra [this message]
2022-10-12  0:31     ` Mark Harmstone
2022-10-11 19:06 ` [PATCH v4 1/2] ld: Add --pdb option Martin Storsjö

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=Y0YKOe6KJ78OeDxH@squeak.grove.modra.org \
    --to=amodra@gmail.com \
    --cc=binutils@sourceware.org \
    --cc=mark@harmstone.com \
    --cc=martin@martin.st \
    /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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).