public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Hans-Peter Nilsson <hans-peter.nilsson@axis.com>
To: michael.hope@linaro.org
Cc: gcc-patches@gcc.gnu.org, richard.earnshaw@arm.com
Subject: Re: [RFA:] Caveat for ARM in gcc-4.7/changes.html: unaligned accesses
Date: Fri, 08 Jun 2012 03:51:00 -0000	[thread overview]
Message-ID: <201206080320.q583KKY1017961@ignucius.se.axis.com> (raw)
In-Reply-To: <CANLjY-na+TDgzQL5nxkftc4jG3+Q-DCsvBTvnR0UxRL5kEr4PQ@mail.gmail.com>	(message from Michael Hope on Fri, 8 Jun 2012 04:42:30 +0200)

> From: Michael Hope <michael.hope@linaro.org>
> Date: Fri, 8 Jun 2012 04:42:30 +0200

> On 8 June 2012 12:15, Hans-Peter Nilsson <hans-peter.nilsson@axis.com> wrote:
> > The "some source
> > codes" was in the analyzed case a strcpy of a five-byte string
> > (busybox/libbb/procps.c:365 'strcpy(filename_tail, "stat");' of
> > some unknown busybox-version).
> >
> > An OS configured with unaligned accesses turned off (IIUC the
> > default for Linux/ARM), has the nice property that you easily
> > spot a certain class of bad codes.
> >
> > Ok to commit?
> 
> The wording is scarier than I'd like.  Userspace and the Linux kernel
> post 3.1 are fine.

So the default for ALIGNMENT_TRAP changed in >3.1?

>  Earlier kernels fail to start due to the kernel
> turning off the hardware support and an interaction of
> -fconserve-stack and -munaligned-access cause a char array to be
> unaligned on the stack.
> 
> I don't agree that unaligned access is a sign of wrong code.  It's
> very common when poking about in protocol buffers.  Using the hardware
> support is better than the multi-byte read plus OR that GCC used to
> do.

Totally disagree.  Code that e.g. casts unaligned char * to int *
and dereferences that, is crappy and unportable and fails
without OS-configury choice on some platforms, and is also
avoidable.  But hopefully that wasn't what you meant.

> Where else have you seen this?

I don't get the "else".  I've seen the unaligned accesses from
userland code as quoted above.  There were other (userland)
places in that build-tree that I'm not going to check, as this
was (again) GCC-generated code.  There were no other misaligned
accesses on that system; not from the kernel, not from userspace.

> > +    <li>On ARM, when compiling for ARMv6 (but not ARMv6-M), ARMv7-A,
> > +    ARMv7-R, or ARMv7-M
> 
> How about "ARMv6K and above"? or "ARMv6 and above, except for ARMv6-M"

I'll let an ARM maintainer sort out the names and color for the
toolshed; ARMv6K isn't an obvious improvement to me over the
names used in the patch introducing -munaligned-access.

> > the default of the new option
> > +    <code>-munaligned-accesses</code> is on, which for some source
> > +    codes generates code that accesses memory on unaligned adresses.
> > +    This will require the OS of those systems to enable such accesses
> > +    (controlled by CP15 register c1, refer to ARM documentation).
> 
> The CPU has an unaligned access trap which is off by default.  The
> kernel has to turn the trap on to cause the fault.

In arch/arm/Kconfig it looks for all purposes default "on" to me
(config ALIGNMENT_TRAP, 2.6.35): "default y if !ARCH_EBSA110"
where ARCH_EBSA110 seems to be for some "evaluation board from Digital".

brgds, H-P

  reply	other threads:[~2012-06-08  3:20 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-06-08  0:31 Hans-Peter Nilsson
2012-06-08  3:20 ` Michael Hope
2012-06-08  3:51   ` Hans-Peter Nilsson [this message]
2012-06-08  4:29     ` Michael Hope
2012-06-08  4:53       ` Hans-Peter Nilsson
2012-06-08  5:17         ` Hans-Peter Nilsson
2012-06-10 22:27           ` Michael Hope
2012-06-10 23:16             ` Hans-Peter Nilsson
2012-06-12 14:37               ` Hans-Peter Nilsson
2012-06-12 23:15                 ` Michael Hope
2012-06-13  2:19                   ` Hans-Peter Nilsson
2012-06-10 23:00 ` Gerald Pfeifer
2012-06-11  1:29   ` Hans-Peter Nilsson
2012-06-13 13:55     ` Hans-Peter Nilsson
2012-06-15  3:40       ` [RFA:] Caveat for ARM in gcc-4.7/changes.html: unaligned accesses, take 2 Hans-Peter Nilsson
2012-06-22  7:20         ` Ping: " Hans-Peter Nilsson
2012-06-29 13:35           ` Hans-Peter Nilsson
2012-07-08  1:10             ` Ping again: " Hans-Peter Nilsson
2012-12-29 17:36         ` Gerald Pfeifer

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=201206080320.q583KKY1017961@ignucius.se.axis.com \
    --to=hans-peter.nilsson@axis.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=michael.hope@linaro.org \
    --cc=richard.earnshaw@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).