From: Richard Koch <n1gp@hotmail.com>
To: <crossgcc@sourceware.org>
Subject: Compiler Memory Alignment Issue
Date: Thu, 02 Feb 2012 18:15:00 -0000 [thread overview]
Message-ID: <SNT112-W20026C65DA2489BC8955CE87700@phx.gbl> (raw)
Hello List,
I'm seeing an alignment issue when I'm incrementing a pointer.
Using the program below I found that the cross compiler I built from
crosstools-ng-1.13.3, interprets the "*(ptr + 1)" as adding 1 BYTE to ptr. It should
know that ptr is declared as a pointer to an integer and interpret "*(ptr + 1)"
as adding 4 BYTES to ptr.
An older cross compiler from Technologics, crosstool-linux-gnueabi-2005q3-2, doesn't
exhibit this problem and interprets the pointer addition correctly. So does the
native gcc on the target. I would prefer to use crosstools-ng.
The target is a Technologics TS-7350 ARM920T (EP9302).
I'm wondering if there may be something I haven't set properly in the crosstool-ng's
configuration?
The configuration file I'm using can be seen here:
http://home.comcast.net/~n1gp/ct_config
PROGRAM:
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
int main()
{
unsigned char buffer[8], i;
int *ptr = (int *) buffer;
printf("size of int is: %d\n", sizeof(int));
memset(buffer, 0xff, sizeof buffer);
*(ptr + 1) = 0x1234;
for (i=0; i<(sizeof(buffer) +1); i++)
printf("buffer[%d]=%x\n", i, buffer[i]);
}
RESULTS WITH crosstool-linux-gnueabi-2005q3-2:
size of int is: 4
buffer[0]=ff
buffer[1]=ff
buffer[2]=ff
buffer[3]=ff
buffer[4]=34
buffer[5]=12
buffer[6]=0
buffer[7]=0
buffer[8]=0
RESULTS WITH crosstools-ng:
size of int is: 4
buffer[0]=ff
buffer[1]=34
buffer[2]=12
buffer[3]=0
buffer[4]=0
buffer[5]=ff
buffer[6]=ff
buffer[7]=ff
buffer[8]=8
Thanks,
Rick
--
For unsubscribe information see http://sourceware.org/lists.html#faq
next reply other threads:[~2012-02-02 18:15 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-02-02 18:15 Richard Koch [this message]
2012-02-02 23:09 ` Martin Guy
2012-02-02 23:26 ` Rod Nussbaumer
2012-02-03 9:52 ` Martin Guy
2012-02-03 10:16 ` Bob Dunlop
2012-02-03 13:21 ` Yann E. MORIN
2012-02-03 14:14 ` Johannes Stezenbach
2012-02-03 14:23 ` Yann E. MORIN
2012-02-03 20:41 ` Johannes Stezenbach
2012-02-03 15:13 ` Richard Koch
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=SNT112-W20026C65DA2489BC8955CE87700@phx.gbl \
--to=n1gp@hotmail.com \
--cc=crossgcc@sourceware.org \
/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).