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

Re: [PATCH 0/2] compiling with -fsanitize=undefined

From
Jeff King <peff@peff.net>
Date
Dec 29, 2015, 06:44 UTC
Message-ID
<20151229064435.GA31944@sigill.intra.peff.net>
In-Reply-To
<20151229063449.GA28755@sigill.intra.peff.net>
On Tue, Dec 29, 2015 at 01:34:49AM -0500, Jeff King wrote:
Show 10 quoted lines
>   2. We have some unaligned memory accesses that presumably work OK on
>      x86, but would blow up on ARM or other platforms (I didn't test).
> 
> The latter looks like it's in the untracked cache code (Duy and
> Christian cc'd). Running t7063 gets me this:
> 
> dir.c:2631:45: runtime error: member access within misaligned address 0x7f19806ff185 for type 'const struct ondisk_untracked_cache', which requires 4 byte alignment
> 0x7f19806ff185: note: pointer points here
>  31 33 29 00 00 00 00  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  00
>              ^

I took a brief look at fixing this, and it may actually be a false positive, as well (in a manner of speaking; if the compiler thinks it is undefined behavior, it may still be worth fixing so we don't fall prey to some optimizations-gone-wild).

The line in question is:
  load_sha1_stat(&uc->ss_info_exclude, &ouc->info_exclude_stat,
		 ouc->info_exclude_sha1);

where "ouc" is the on-disk data cast to a struct. So we definitely generate an unaligned pointer, but then we only access its contents via get_be32(), which handles alignment. So it might actually be OK. I dunno.

-Peff
Previous: Jeff King
Message 12 of 12 in “compiling with -fsanitize=undefined”
  1. 0/2 compiling with -fsanitize=undefinedJeff King, Dec 29, 2015
  2. 1/2 avoid shifting signed integers 31 bitsJeff King, Dec 29, 2015
  3. Junio C HamanoDec 30, 2015
  4. Jeff KingDec 30, 2015
  5. Duy NguyenDec 31, 2015
  6. Jeff KingDec 31, 2015
  7. Junio C HamanoJan 4, 2016
  8. Jeff KingJan 4, 2016
  9. 2/2 bswap: add NO_UNALIGNED_LOADS defineJeff King, Dec 29, 2015
  10. Eric SunshineDec 29, 2015
  11. Jeff KingDec 29, 2015
  12. Jeff KingDec 29, 2015

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.