<div dir="ltr"><div>Here's the CL I submitted to our git respository:</div><div><br></div><div><a href="https://android-review.googlesource.com/#/c/200798/">https://android-review.googlesource.com/#/c/200798/</a><br></div><div><br></div><div>I think this is portable, but I've only verified that this works on gcc 4.9/current clang. </div><div><br></div><div>On a sort of related note, there is a typo in jemalloc/internal/ckh.h. The prototype for ckh_search, has the second parameter as seachkey instead of searchkey.</div><div><br></div><div>Christopher </div></div><div class="gmail_extra"><br><div class="gmail_quote">On Mon, Feb 1, 2016 at 3:51 PM, Christopher Ferris <span dir="ltr"><<a href="mailto:cferris@google.com" target="_blank">cferris@google.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">When I compiled the ckh unit test with a newer version of clang, it was crashing. I tracked the problem down to an implicit assumption that a value passed to chk_search is 4 byte aligned. Specifically, the code in test/unit/ckh.c, the test test_count_insert_search_remove, makes this call:<div><br></div><div><div><font face="monospace, monospace">  assert_true(ckh_search(&ckh, missing, NULL, NULL),</font></div><div><font face="monospace, monospace">      "Unexpected ckh_search() success");</font></div></div><div><br></div><div>The problem is that the definition of missing is:</div><div><br></div><div><font face="monospace, monospace">  char *missing = "A string not in the hash table.";</font></div><div><br></div><div>Which means missing is not guaranteed to be of any alignment.</div><div><br></div><div>I'm not sure on what platforms jemalloc needs to be compiled, so I think that something like this:</div><div><font face="monospace, monospace"><br></font></div><div><div><font face="monospace, monospace">  #define HASH_TABLE_STRING "A string not in the hash table."</font></div></div><div><font face="monospace, monospace">  union { char char_data[sizeof(HASH_TABLE_STRING)]; uint32_t uint_data; } missing;<br></font></div><div><div><font face="monospace, monospace">  memcpy(missing.char_data, HASH_TABLE_STRING, sizeof(HASH_TABLE_STRING));</font></div></div><div><font face="monospace, monospace">  .</font></div><div><font face="monospace, monospace">  .</font></div><div><font face="monospace, monospace">  .</font></div><div><div><font face="monospace, monospace">  assert_true(ckh_search(&ckh, missing.char_data, NULL, NULL),</font></div><div><font face="monospace, monospace">      "Unexpected ckh_search() success");</font></div></div><div><br></div><div>Would guarantee the needed alignment.</div><div><br></div><div>Does this seem reasonable?</div><span class="HOEnZb"><font color="#888888"><div><br></div><div>Christopher</div></font></span></div>
</blockquote></div><br></div>