Compiler bug

Here you can discuss ReactOS related topics.

Moderator: Moderator Team

Post Reply
hto
Developer
Posts: 2193
Joined: Sun Oct 01, 2006 3:43 pm

Compiler bug

Post by hto »

It seems that MinGW GCC-3.4.5 compiler disregards alignment attributes. It can lead (and I think actually leads) to bugs in ReactOS.

For example:

Code: Select all

#include <stdio.h>

#define ALIGNED(n)  __attribute__((aligned(n)))

typedef ALIGNED(16) struct
{
    int i;
} S;

int main(void)
{
    S s;
    printf("%p\n", &s); // I have 0022FF74
}

Karl
Posts: 19
Joined: Sun Jan 07, 2007 7:04 am

Post by Karl »

Are we still using GCC-3.4.5?

In all tests I've done, GCC-4.1.0 has compiled faster, and produced better code.

Christoph_vW
Developer
Posts: 48
Joined: Sun Sep 18, 2005 11:58 pm
Location: Germany
Contact:

Post by Christoph_vW »


hto
Developer
Posts: 2193
Joined: Sun Oct 01, 2006 3:43 pm

Post by hto »

This code works well:

Code: Select all

#include <stdio.h>

#define ALIGNED(n)  __attribute__((aligned(n)))

typedef struct
{
    int i ALIGNED(16);
} S;

int main(void)
{
    S s;
    printf("%p\n", &s); // 0022FF60
}
16-byte alignment should be used in ExfAcquirePushLockExclusive() and ExfAcquirePushLockShared(), EX_PUSH_LOCK_WAIT_BLOCK WaitBlock structure. Misalignment can cause crash / hang, I believe.
Andrew Pinski wrote: Actually this is just a missed diagnostic. The compiler cannot align the stack variables where the alignment is greater than stack alignment that the compiler can give for the stack.
I do not agree. Stack variable can be aligned even by hand.

GreatLord
Developer
Posts: 926
Joined: Tue Nov 30, 2004 10:26 am
Location: Sweden

Post by GreatLord »

we are thinking of slash gcc 3.4.x and go for 4.2.x for it seam align work in that.

the align are also broken in gcc 4.1.x for complex code. simple code as u show hto works in gcc 4.1.x but when the code start getting complex it break the align.

we are investing how this should be solv at irc channel

hto
Developer
Posts: 2193
Joined: Sun Oct 01, 2006 3:43 pm

Post by hto »

Simple, but ugly looking solution is:

VOID
FASTCALL
ExfAcquirePushLockShared(PEX_PUSH_LOCK PushLock)
{
char xxx[sizeof(EX_PUSH_LOCK_WAIT_BLOCK) + 16];

#define WaitBlock \
(*(PEX_PUSH_LOCK_WAIT_BLOCK)(((unsigned)buf + 12) & 0xfffffff0))

...

#undef WaitBlock
}

GreatLord
Developer
Posts: 926
Joined: Tue Nov 30, 2004 10:26 am
Location: Sweden

Post by GreatLord »

after long testing night with other devs. it seam the lates trunk of gcc 4.1.2 is working pretty good. and align is working there.

we will problare slash gcc 3.4.x as supported compiler and move to gcc 4.1.2 with in some days I think. we for see how it end.

it will be small fork of gcc 4.1.2 for offical gcc 4.1.2 can not build reactos we need some patcher for it that we are merge in by hand.

Karl
Posts: 19
Joined: Sun Jan 07, 2007 7:04 am

Post by Karl »

good, then we should have q better quality 0.3.1 :P

GreatLord
Developer
Posts: 926
Joined: Tue Nov 30, 2004 10:26 am
Location: Sweden

Post by GreatLord »

a new RosBE will be made
with gcc 4.1.2 and gcc 4.2 and alex intruduse a hack for gcc 3.4.x so align work in puch lock. it is only there we are using align now what I am aware. The new RosBe will problare be avail later today.


This issue are solv now.

Post Reply

Who is online

Users browsing this forum: Bing [Bot], DotBot [Crawler], Majestic-12 [Bot] and 1 guest