unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Ahmed Khanzada <me@enzu.ru>
To: 46111@debbugs.gnu.org, me@enzu.ru
Subject: bug#46111: Reverting fns.c hash function due to OpenBSD/SPARC64 compile breaking
Date: Mon, 25 Jan 2021 22:57:18 -0800	[thread overview]
Message-ID: <CADAEaRXRH7obfoRWbQOWwQd8B9Mov3JMnRgjuzaLp1GwzD+krw@mail.gmail.com> (raw)
In-Reply-To: <87sg6oyzi6.wl-me@enzu.ru>

[-- Attachment #1: Type: text/plain, Size: 3452 bytes --]

Not sure if the patch attached correctly. Trying again.

On Mon, Jan 25, 2021 at 10:37 PM Ahmed Khanzada <me@enzu.ru> wrote:
>
> I'm not an expert on C, OpenBSD, or SPARC64, but I did notice
> emacs-current was not compiling.
>
> During a gmake, bootstrap-emacs would get a SIGBUS and fail. Running
> gdb led me to the hash_string function where it seemed to be failing.
>
> Reverting the hash_string function to a previous version seems to have
> fixed the issue.
>
> If I had to guess, it may have something to do with SPARC64 alignment.
>
> I don't have an updated AMD64 OpenBSD box running at the moment, but if you
> would like me to test there, I could find a way.
>
> I understand that reverting this function might not be the best way
> forward, but wrote a patch just in case that reverts hash_string to an
> earlier version that compiles on OpenBSD/SPARC64.
>
> I am already signed all my GNU contributor docs.
>
> --[[text/plain; type=patch; name="0001-Reverting-hash_string-function-due-to-problem-on-Ope.patch"
> Content-Disposition: attachment; filename="0001-Reverting-hasattach filh_string-function-due-to-problem-on-Ope.patch"][base64]]
> RnJvbSBkOTM4NzQ1Y2U1NjA1OGJlMjQwNzhlYzUyZDk3Mzk4Njk3ZGI0Yjc2IE1vbiBTZXAgMTcg
> MDA6MDA6MDAgMjAwMQpGcm9tOiBBaG1lZCBLaGFuemFkYSA8bWVAZW56dS5ydT4KRGF0ZTogTW9u
> LCAyNSBKYW4gMjAyMSAyMToxNjo0OCAtMDgwMApTdWJqZWN0OiBbUEFUQ0hdIFJldmVydGluZyBo
> YXNoX3N0cmluZyBm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KQorICBj
> aGFyIGNvbnN0ICpwID0gcHRyOworICBjaGFyIGNvbnN0ICplbmQgPSBwICsgbGVuOworICB1bnNp
> Z25lZCBjaGFyIGM7CisgIEVNQUNTX1VJTlQgaGFzaCA9IDA7CisKKyAgd2hpbGUgKHAgIT0gZW5k
> KQogICAgIHsKLSAgICAgIEVNQUNTX1VJTlQgYyA9ICpwOwotICAgICAgcCArPSBzdGVwOworICAg
> ICAgYyA9ICpwKys7CiAgICAgICBoYXNoID0gc3hoYXNoX2NvbWJpbmUgKGhhc2gsIGMpOwogICAg
> IH0KLSAgaWYgKHAgPCBlbmQpCi0gICAgeyAvKiBBIGZldyBsYXN0IGJ5dGVzIHJlbWFpbiAoc21h
> bGxlciB0aGFuIGFuIEVNQUNTX1VJTlQpLiAgKi8KLSAgICAgIC8qIEZJWE1FOiBXZSBjb3VsZCBk
> byB0aGlzIHdpdGhvdXQgYSBsb29wLCBidXQgaXQnZCByZXF1aXJlCi0gICAgICAgICBlbmRpYW4t
> ZGVwZW5kZW50IGNvZGUgOi0oICAqLwotICAgICAgY2hhciBjb25zdCAqcDEgPSAoY2hhciBjb25z
> dCAqKXA7Ci0gICAgICBjaGFyIGNvbnN0ICplbmQxID0gKGNoYXIgY29uc3QgKillbmQ7Ci0gICAg
> ICBkbwotICAgICAgICB7Ci0gICAgICAgICAgdW5zaWduZWQgY2hhciBjID0gKnAxKys7Ci0gICAg
> ICAgICAgaGFzaCA9IHN4aGFzaF9jb21iaW5lIChoYXNoLCBjKTsKLSAgICAgICAgfQotICAgICAg
> d2hpbGUgKHAxIDwgZW5kMSk7Ci0gICAgfQogCiAgIHJldHVybiBoYXNoOwogfQotLSAKMi4yOC4w
> Cgo=

[-- Attachment #2: 0001-Reverting-hash_string-function-due-to-problem-on-Ope.patch --]
[-- Type: application/octet-stream, Size: 1655 bytes --]

From d938745ce56058be24078ec52d97398697db4b76 Mon Sep 17 00:00:00 2001
From: Ahmed Khanzada <me@enzu.ru>
Date: Mon, 25 Jan 2021 21:16:48 -0800
Subject: [PATCH] Reverting hash_string function due to problem on
 OpenBSD/SPARC64

---
 src/fns.c | 32 +++++++-------------------------
 1 file changed, 7 insertions(+), 25 deletions(-)

diff --git a/src/fns.c b/src/fns.c
index 7ab2e8f1a0..0127fe3f48 100644
--- a/src/fns.c
+++ b/src/fns.c
@@ -4599,34 +4599,16 @@ #define SXHASH_MAX_LEN   7
 EMACS_UINT
 hash_string (char const *ptr, ptrdiff_t len)
 {
-  EMACS_UINT const *p   = (EMACS_UINT const *) ptr;
-  EMACS_UINT const *end = (EMACS_UINT const *) (ptr + len);
-  EMACS_UINT hash = len;
-  /* At most 8 steps.  We could reuse SXHASH_MAX_LEN, of course,
-   * but dividing by 8 is cheaper.  */
-  ptrdiff_t step = 1 + ((end - p) >> 3);
-
-  /* Beware: `end` might be unaligned, so `p < end` is not always the same
-   * as `p <= end - 1`.  */
-  while (p <= end - 1)
+  char const *p = ptr;
+  char const *end = p + len;
+  unsigned char c;
+  EMACS_UINT hash = 0;
+
+  while (p != end)
     {
-      EMACS_UINT c = *p;
-      p += step;
+      c = *p++;
       hash = sxhash_combine (hash, c);
     }
-  if (p < end)
-    { /* A few last bytes remain (smaller than an EMACS_UINT).  */
-      /* FIXME: We could do this without a loop, but it'd require
-         endian-dependent code :-(  */
-      char const *p1 = (char const *)p;
-      char const *end1 = (char const *)end;
-      do
-        {
-          unsigned char c = *p1++;
-          hash = sxhash_combine (hash, c);
-        }
-      while (p1 < end1);
-    }
 
   return hash;
 }
-- 
2.28.0


  reply	other threads:[~2021-01-26  6:57 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-01-26  6:37 bug#46111: Reverting fns.c hash function due to OpenBSD/SPARC64 compile breaking Ahmed Khanzada
2021-01-26  6:57 ` Ahmed Khanzada [this message]
2021-01-26 11:15   ` Eli Zaretskii
2021-01-28  4:06     ` Ahmed Khanzada
2021-01-28 13:58       ` Eli Zaretskii
2021-01-28 15:09       ` Stefan Monnier
2021-01-28 15:19         ` Eli Zaretskii
2021-01-28 15:44           ` Stefan Monnier
2021-01-28 15:52             ` Stefan Monnier
2021-01-28 16:17               ` Stefan Monnier
2021-01-28 16:22                 ` Andreas Schwab
2021-01-28 17:22                 ` Eli Zaretskii
2021-01-28 17:30                   ` Stefan Monnier
2021-01-28 16:04             ` Andreas Schwab
2021-01-28 16:14               ` Stefan Monnier
2021-01-26  9:36 ` Philipp Stephani
2021-01-26 11:12   ` Eli Zaretskii
2021-01-26 11:17     ` Andreas Schwab
2021-01-26 11:43       ` Eli Zaretskii
2021-01-26 11:49         ` Andreas Schwab
2021-01-26 15:36           ` Eli Zaretskii
2021-01-27  7:42       ` Richard Stallman
2021-01-27  8:24         ` Andreas Schwab

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

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CADAEaRXRH7obfoRWbQOWwQd8B9Mov3JMnRgjuzaLp1GwzD+krw@mail.gmail.com \
    --to=me@enzu.ru \
    --cc=46111@debbugs.gnu.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.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

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).