asm(".global _start; _start: b .");
struct lock {
unsigned int lk;
};
struct lock x;
unsigned char a;
unsigned short b;
struct lock y;
void centry ( void )
{
}
Gcc is just trying for alignment
Disassembly of section .text:
0000000000001000 <_start>:
1000: 14000000 b 1000 <_start>
1004: d503201f nop
0000000000001008 <centry>:
1008: d65f03c0 ret
Disassembly of section .bss:
0000000000002000 <b>:
...
0000000000002008 <x>:
...
0000000000002010 <y>:
2010: 00000000 .inst 0x00000000 ; undefined
0000000000002014 <a>:
2014: 00000000 .inst 0x00000000 ; undefined
you really shouldnt fight that if you can avoid it. if you are trying to point structures across compile domains then you are asking for trouble anyway.
asm(".global _start; _start: b .");
struct lock {
unsigned int lk;
};
struct lock x;
unsigned char a;
unsigned short b;
unsigned int c;
unsigned int d;
struct lock y;
unsigned int e;
void centry ( void )
{
}
that worked
Disassembly of section .text:
0000000000001000 <_start>:
1000: 14000000 b 1000 <_start>
1004: d503201f nop
0000000000001008 <centry>:
1008: d65f03c0 ret
Disassembly of section .bss:
0000000000002000 <b>:
...
0000000000002008 <x>:
2008: 00000000 .inst 0x00000000 ; undefined
000000000000200c <c>:
200c: 00000000 .inst 0x00000000 ; undefined
0000000000002010 <y>:
2010: 00000000 .inst 0x00000000 ; undefined
0000000000002014 <d>:
2014: 00000000 .inst 0x00000000 ; undefined
0000000000002018 <a>:
2018: 00000000 .inst 0x00000000 ; undefined
000000000000201c <e>:
201c: 00000000 .inst 0x00000000 ; undefined
I wouldnt rely on these settings or how they arrange things, you let the compiler set the alignment and packing on the structure so that it ideally doesnt create alignment faults or performance hits. Just asking for trouble if you start to mess with that, may take days or years for the trouble to hit but it will eventually.