Menu

#14 cmph will crash in ARM platform.

open
nobody
None
5
2020-08-17
2012-07-30
Jun Huang
No

There's so many code like the following one in cmph sources:
> register cmph_uint32 * ptr = (cmph_uint32 *)packed_mphf;
> register cmph_uint32 packed_cr_size = *ptr++;
packed_mphf is void*. In some ARM architecture, it needs the access be word aligned, and the code may be failed in some cases. You should read the value char by char or use marco like get_unalign in asm/unaligned.h in Linux.

Discussion

  • Fabiano C. Botelho

    Hi Jun,

    If you were to have a patch for this we would love to apply it.
    Thanks, Fabiano.

     
  • Sven Köhler

    Sven Köhler - 2020-08-17

    It is generally discouraged in C to cast pointers with small alignment requirements to pointers with bigger alignment requirements. To do so is generally considered a beginner's mistake.

    For that reason, it is generally recommended to properly align all data. Unaligned data (such as packed structs) can also decrease performance.

    There are compiler extensions to deal with unaligned access. Packed structs and GCC's aligned attribute can be used, for example. But that will not be portable, and still have an issue with the endianess of the data. Portable unaligned access will have to do the conversion from bytes to larger types by hand. That will likely kill performance.

     

    Last edit: Sven Köhler 2020-08-17

Log in to post a comment.

Monday.com Logo