git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: Unaligned accesses in sha1dc

From
Linus Torvalds <torvalds@linux-foundation.org>
Date
Jun 2, 2017, 21:53 UTC
Message-ID
<CA+55aFwL9LQfx8t7tixYgV+2w_=_dAABxk54_GLJoGod-w=mbw@mail.gmail.com>
In-Reply-To
<CANgJU+UzoaN3Urj=L4unMMtNwFm6G8LGxx19g49AR5R+76F2OA@mail.gmail.com>
On Fri, Jun 2, 2017 at 1:17 PM, demerphq <demerphq@gmail.com> wrote:
> Most hash function implementations have code like the following
> (extracted and reduced from hv_macro.h in perl.git [which only
> supports little-endian hash functions]):
Yes.

Please do *not* try to make things overly portable by adding random memcpy() functions.

Yes, many compilers will do ok with it, and generate the right code (single load from an unaligned address). But many won't. Gcc completely screws it up in older versions on ARM, for example.

Dereferencing an unaligned pointer may be "undefined" in some technical meaning, but it sure as hell isn't undefined in reality, and compilers that willfully do stupid things should not be catered to overly. Reality is a lot more important.

And I think gcc can be tweaked to use "movbe" on x86 with the right magic incantation (ie not just __builtin_bswap32(), but also the switch to enable the new instructions). So having code to detect gcc and using __builtin_bswap32() would indeed be a good thing.

                     Linus
Previous: Ævar Arnfjörð BjarmasonNext: Junio C Hamano
Message 23 of 28 in “Unaligned accesses in sha1dc”
  1. Andreas SchwabJun 1, 2017
  2. Junio C HamanoJun 1, 2017
  3. Andreas SchwabJun 1, 2017
  4. Junio C HamanoJun 1, 2017
  5. brian m. carlsonJun 1, 2017
  6. Andreas SchwabJun 1, 2017
  7. Lars SchneiderJun 1, 2017
  8. Junio C HamanoJun 1, 2017
  9. Andreas SchwabJun 1, 2017
  10. Martin ÅgrenJun 1, 2017
  11. Ævar Arnfjörð BjarmasonJun 1, 2017
  12. Martin ÅgrenJun 1, 2017
  13. Martin ÅgrenJun 1, 2017
  14. Junio C HamanoJun 2, 2017
  15. Ævar Arnfjörð BjarmasonJun 2, 2017
  16. Martin ÅgrenJun 2, 2017
  17. Ævar Arnfjörð BjarmasonJun 2, 2017
  18. Martin ÅgrenJun 2, 2017
  19. Ævar Arnfjörð BjarmasonJun 2, 2017
  20. demerphqJun 2, 2017
  21. demerphqJun 2, 2017
  22. Ævar Arnfjörð BjarmasonJun 2, 2017
  23. Linus TorvaldsJun 2, 2017
  24. Junio C HamanoJun 3, 2017
  25. Liam R. HowlettJun 2, 2017
  26. Ævar Arnfjörð BjarmasonJun 2, 2017
  27. Junio C HamanoJun 3, 2017
  28. Andreas SchwabJun 1, 2017

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.