public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
From: Lirong Yuan <yuanzi@google.com>
To: Szabolcs Nagy <szabolcs.nagy@arm.com>
Cc: "Carlos O'Donell" <carlos@redhat.com>,
	libc-alpha@sourceware.org,  Shu-Chun Weng <scw@google.com>
Subject: Re: [PATCH] locale: align _nl_C_LC_CTYPE_class and _nl_C_LC_CTYPE_class32 arrays to uint16_t and uint32_t respectively
Date: Tue, 16 Mar 2021 12:05:48 -0700	[thread overview]
Message-ID: <CADjx4CL4mbM=PzcOUkbBJoACY5fPG7hF9+y=Jmt7XrquNVF_wg@mail.gmail.com> (raw)
In-Reply-To: <20210316142816.GC4427@arm.com>

On Mon, Mar 15, 2021 at 6:45 PM Carlos O'Donell <carlos@redhat.com> wrote:

> My expectation is that normally aarch64 simply handles the unaligned load
> without any problems,
> but that it would be "better" if it were 16-bit aligned?
> Is this the *only* case of misaligned pointers?


Yes, this is the only case reported by UBSan.

> Signed-off-by: Lirong Yuan <yuanzi@google.com>
> We don't use DSOs in glibc, we assign copyright to the FSF, so this line
> would
> be normally removed, and you as the git author remains.


Thanks for the explanation! I will send an updated patch without
"Signed-off-by" if the current approach looks good. :)

On Tue, Mar 16, 2021 at 7:28 AM Szabolcs Nagy <szabolcs.nagy@arm.com> wrote:

> The 03/15/2021 21:44, Carlos O'Donell wrote:
> > On 3/15/21 2:42 PM, Lirong Yuan via Libc-alpha wrote:
> > > steps to reproduce the problem: compile a program that uses ctype
> functions such as “isspace” for aarch64 with UBSan flag
> “-fsanitize=undefined” and run it on x86_64 machines with qemu user mode
> emulation.
> >
> > Szabolcs,
> >
> > Do you have any input on this?
> >
> > > observed behavior: UndefinedBehaviorSanitizer reports
> misaligned-pointer-use in the program.
> >
> > Yes, the char array could be misaligned with respect to a 16-bit value,
> > and should be aligned to the type that is expected from the interface
> e.g.
>
> using char[] as uint16_t[] is aliasing violation. and in principle
> alignas on the definition does not fix this, but in practice that's
> the only abi visible aspect of the wrong type.
>

Alternatively, we can define _nl_C_LC_CTYPE_class and
_nl_C_LC_CTYPE_class32 arrays directly as uint16_t and uint32_t arrays,
like _nl_C_LC_CTYPE_toupper array:
https://code.woboq.org/userspace/glibc/locale/C-ctype.c.html#_nl_C_LC_CTYPE_toupper
Though the conversion may be error-prune and require more test cases...
It would seem that using alignas is an approach that's both technically
correct and less likely to cause havoc.


> i'm not sure why ubsanitizer cares about alignment specifically on
> aarch64, unaligned load should work.
>

Yes, the code works fine in practice on aarch64. The ubsan alignment is a
check for misaligned rather than unaligned. It's almost always worth fixing
since this can cause subtle and hard to track down failures that more often
manifest on other architectures.

Thanks,
Lirong

  reply	other threads:[~2021-03-16 19:06 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-03-15 18:42 Lirong Yuan
2021-03-16  1:44 ` Carlos O'Donell
2021-03-16 14:28   ` Szabolcs Nagy
2021-03-16 19:05     ` Lirong Yuan [this message]
2021-03-16 19:47       ` Adhemerval Zanella
2021-03-16 20:49         ` Andreas Schwab
2021-03-16 21:05         ` Carlos O'Donell
2021-03-17 11:34           ` Adhemerval Zanella
2021-03-19 18:31             ` Lirong Yuan
2021-03-30 17:33               ` Lirong Yuan

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CADjx4CL4mbM=PzcOUkbBJoACY5fPG7hF9+y=Jmt7XrquNVF_wg@mail.gmail.com' \
    --to=yuanzi@google.com \
    --cc=carlos@redhat.com \
    --cc=libc-alpha@sourceware.org \
    --cc=scw@google.com \
    --cc=szabolcs.nagy@arm.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).