2

I have a data-conversion function in our ARM9 code which uses varargs. I've been using an arm-elf yagarto distribution from a couple of years ago, with no problems. Recently, we upgraded to the arm-eabi-none yagarto package from the yagarto site, and I'm finding that we now have problems with floating point values. What I eventually discovered is that doubles are being forced to 8-byte boundaries, and the existing varargs floating-point handler didn't expect to find gaps in the args.

I can manually check the pointer and force it up to an eight-byte boundary (in fact, I did that, and that fixed the issue entirely), but I'd like to know why this has suddenly started happening.

Is there a compiler switch that specifies data alignment on the stack, or in function calls, or something like that?? And why would it be defaulting to 8-byte boundaries on a 32-bit (4-byte) architecture??

I would appreciate any advice or insights that anyone could provide on these issues.

The code is simple:

    .....
    float floatValue = 10.0;
    int intValue = 10;
    char buffer[32];
    ...
    snprintf (buffer, 32, "%g", floatValue); /* Here we are getting junk value bcz of 8-byte*/
    snprintf (buffer, 32, "%lld", intValue); /* Here we are getting junk value bcz of 8-byte */
    ....

The version of GCC we were using is 4.7.1

Compiling options:

Toolchain compiling options:

    `mabi=aapcs-linux
    `mcpu=arm7tdmi/mcpu=arm946e-s`
    `mfloat-abi=softfp`

Application compiler option:

    `-mfloat-abi=softfp`
    `-mfpu=vfp`
    `-mstructure-size-boundary=8`
    `-fomit-frame-pointer`
    `-fshort-wchar`
    `-fno-short-enums`
Santhosh
  • 637
  • 1
  • 7
  • 19
  • What happens if you set abi to an older one? like via '-mabi=apcs-gnu' – auselen Oct 15 '12 at 07:38
  • Auselen - I want to use aapcs only and I think the problem is in strcture size boundary as it is hardcoded to 8 bit instead of passed one (GCC ARM EABI). – Santhosh Oct 15 '12 at 09:13
  • 1
    But that's what aapcs already dictates. Get a copy of **Procedure Call Standard for the ARM Architecture** and search for `A double-word aligned type will always start in an even-numbered core register, or at a double-word aligned address on the stack even if it is not the first member of an aggregate.` – auselen Oct 15 '12 at 10:57
  • Auselen - Thanks for your information. But i find acps-gnu removes EABI support and it will be supported on ARMV4 and older versions. We are currently using ARM9 version and it should be supported with EABI. I find there is an bug logged for the above bug in GCC as mentioned in the link http://gcc.gnu.org/bugzilla/show_bug.cgi?id=34281 but i don't know how it is finally fixed. – Santhosh Oct 16 '12 at 05:48
  • auselen - Updated the sample code. Could you please give some input over here? – Santhosh Oct 16 '12 at 09:21
  • The problem here i want to explain is if you try to print it as 64-bit data in sprintf, it is giving some junk string instead of the exact data. Also, I could not understand about running test case in bug report....? – Santhosh Oct 16 '12 at 10:46
  • I'm sure the problem will be there. In the link http://gcc.gnu.org/bugzilla/show_bug.cgi?id=34281 it is mentioned that if the last fixed argument in a va_arg function is 64 bits bad things happen. But for us it does not need to be of last argument, even if you try to print simple 64-bit value in double, we are getting incorrect string. – Santhosh Oct 16 '12 at 11:08
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/18112/discussion-between-santhosh-and-auselen) – Santhosh Oct 16 '12 at 14:25
  • Are you using the new library or any chance that you compile with new tool chain but using old libraries probably on target if shared or on host side if static? – auselen Oct 16 '12 at 21:14
  • I'm statically linking the archive library to the application and starting it. I was using dinkumware library function call snprintf(). When i used arm-elf everything was working fine.???? Still not able to fix it....:( – Santhosh Oct 17 '12 at 10:21
  • With which ABI that library is built with? Is it a full implementation or using varargs from another library? Are you building it yourself? – auselen Oct 17 '12 at 15:54

0 Answers0