This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug c/59958] New: alpha does not deal with non-aligned returns from malloc() when doing byte wise access


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=59958

            Bug ID: 59958
           Summary: alpha does not deal with non-aligned returns from
                    malloc() when doing byte wise access
           Product: gcc
           Version: 4.8.3
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: martin at netbsd dot org

Created attachment 31962
  --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=31962&action=edit
generated assembler code (cc -O2 -S test.c)

On NetBSD/alpha a call to malloc requesting a two byte allocation may return a
pointer that is only 2-byte algined. We believe this to be within the C std
spec (as alignemnt is good enough for all complete objects fitting in the
allocated space).

However, gcc seems to assume return values from malloc to have higher
alignment.

This test program:

--8<--
#include <stdio.h>
#include <stdlib.h>

int main(int argc, char **argv)
{
        char *p;
        size_t i;

        for (i = 0; i < 24; i++) {
                p = malloc(2);
                printf("got %p\n", p);
                p[0] = 'A'; p[1] = 0;
                printf("stored string: %s\n", p);
        }

        return 0;
}
-->8--

shows the problem:

[..]
got 0x3fffdc02238
stored string: A
got 0x3fffdc0223a
pid 600 (a.out): unaligned access: va=0x3fffdc0223a pc=0x120000bc4
ra=0x120000bbc sp=0x1ffffdb08 op=ldl
pid 600 (a.out): unaligned access: va=0x3fffdc0223a pc=0x120000be4
ra=0x120000bbc sp=0x1ffffdb08 op=stl
stored string: A
got 0x3fffdc0223c
stored string: A
got 0x3fffdc0223e
pid 600 (a.out): unaligned access: va=0x3fffdc0223e pc=0x120000bc4
ra=0x120000bbc sp=0x1ffffdb08 op=ldl
pid 600 (a.out): unaligned access: va=0x3fffdc0223e pc=0x120000be4
ra=0x120000bbc sp=0x1ffffdb08 op=stl
stored string: A
got 0x3fffdc02240
[..]


This might be more of a problem with target alpha and the byte access code,
compiling the test program with -mbwx does help (but not all alpha CPUs support
that).

gcc version used:

> cc -v
Using built-in specs.
COLLECT_GCC=cc
Target: alpha--netbsd
Configured with: /usr/src7/tools/gcc/../../external/gpl3/gcc/dist/configure
--target=alpha--netbsd --enable-long-long --enable-threads
--with-bugurl=http://www.NetBSD.org/Misc/send-pr.html --with-pkgversion='NetBSD
nb1 20120916' --with-system-zlib --enable-__cxa_atexit
--with-mpc-lib=/var/obj/mknative/alpha/usr/src7/external/lgpl3/mpc/lib/libmpc
--with-mpfr-lib=/var/obj/mknative/alpha/usr/src7/external/lgpl3/mpfr/lib/libmpfr
--with-gmp-lib=/var/obj/mknative/alpha/usr/src7/external/lgpl3/gmp/lib/libgmp
--with-mpc-include=/usr/src7/external/lgpl3/mpc/dist/src
--with-mpfr-include=/usr/src7/external/lgpl3/mpfr/dist/src
--with-gmp-include=/usr/src7/external/lgpl3/gmp/lib/libgmp/arch/alpha
--enable-tls --disable-multilib --disable-symvers --disable-libstdcxx-pch
--build=x86_64-unknown-netbsd6.0. --host=alpha--netbsd
--with-sysroot=/var/obj/mknative/alpha/usr/src7/destdir.alpha
Thread model: posix
gcc version 4.8.3 (NetBSD nb1 20131213)


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]