https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114217
--- Comment #5 from Akihiko Odaki <akihiko.odaki at daynix dot com> --- (In reply to Andrew Pinski from comment #4) > https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/ > include/asm-generic/unaligned.h?h=v6.7 > > is correct except it should not expose get_unaligned/put_unaligned since the > undefined code happens way before. > > The problem is with the btrfs code in btrfs_filldir: > ``` > static int btrfs_filldir(void *addr, int entries, struct dir_context *ctx) > { > while (entries--) { > struct dir_entry *entry = addr; /// THIS IS BROKEN and causes > the > -fsanitize=alignment error > char *name = (char *)(entry + 1); > > ctx->pos = get_unaligned(&entry->offset); > if (!dir_emit(ctx, name, get_unaligned(&entry->name_len), > get_unaligned(&entry->ino), > get_unaligned(&entry->type))) > return 1; > addr += sizeof(struct dir_entry) + > get_unaligned(&entry->name_len); > ctx->pos++; > } > return 0; > } > ``` > > Added comment on where the error comes from. The get_unaligned macro really > should not be used here. What should be used here is an unaligned version of > `struct dir_entry` instead. I understand the idea. What I don't get is that GCC still emits code for unaligned memory access in such a case. It is just a waste of performance if GCC doesn't provide a guarantee that the unaligned access is performed in such a case and is not optimal.