January 12, 2016
On Tuesday, 12 January 2016 at 05:44:56 UTC, Dan Olson wrote:
> kinke <noone@nowhere.com> writes:
>
>> On Saturday, 9 January 2016 at 20:07:34 UTC, Dan Olson wrote:
>>> Just re-reading and it looks like alignments in your example are too big for a 4-byte type, assuming var is an int.  .align only needs to be 2 here.
>>
>> This is probably due to https://github.com/kinke/ldc/commit/a39997d326f0d3da353d8b9f27ffd559e6fcc5d7.
>
> I haven't carefully read the commit yet.  Is the extra alignment intended for all vars declarations?

For all globals, yes. There's a std.conv unittest casting a global (I don't remember the original type) to an object (class) reference iirc, leading to an error or crash if the chunk isn't aligned. I just assumed DMD assumes such an alignment for globals...
January 12, 2016
kink <noone@nowhere.com> writes:

> On Tuesday, 12 January 2016 at 05:44:56 UTC, Dan Olson wrote:
>> kinke <noone@nowhere.com> writes:
>>
>>> On Saturday, 9 January 2016 at 20:07:34 UTC, Dan Olson wrote:
>>>> Just re-reading and it looks like alignments in your example are too big for a 4-byte type, assuming var is an int.  .align only needs to be 2 here.
>>>
>>> This is probably due to https://github.com/kinke/ldc/commit/a39997d326f0d3da353d8b9f27ffd559e6fcc5d7.
>>
>> I haven't carefully read the commit yet.  Is the extra alignment intended for all vars declarations?
>
> For all globals, yes. There's a std.conv unittest casting a global (I don't remember the original type) to an object (class) reference iirc, leading to an error or crash if the chunk isn't aligned. I just assumed DMD assumes such an alignment for globals...

I think LDC is over aligning.  It is ok functionally but my gut says it should be fixed eventually to match DMD.

I did a test on OS X x86_64 and DMD seems to align global vars based on type size, maybe rounding up to next power of 2.  I haven't looked at the code yet.  DMD is more aligned than C or C++ but less than LDC.

$ cat tls.d
extern(C):
__gshared byte a;

__gshared byte[1] x1_1;
__gshared byte[1] x1_2;
__gshared byte[2] x2;
__gshared byte[1] x1_3;
__gshared byte[1] x1_4;
__gshared byte[1] x1_5;
__gshared byte[4] x4;
__gshared byte[1] x1_6;
__gshared byte[7] x7;
__gshared byte[7] x7_1;

void main() {}

$ dmd tls.d
$ nm -n tls
(snip)
0000000100001010 B _a
0000000100001011 B _x1_1
0000000100001012 B _x1_2
0000000100001014 B _x2
0000000100001016 B _x1_3
0000000100001017 B _x1_4
0000000100001018 B _x1_5
000000010000101c B _x4
0000000100001020 B _x1_6
0000000100001028 B _x7
0000000100001030 B _x7_1

compared to LDC

000000010004c1c0 S _a
000000010004c1c8 S _x1_1
000000010004c1d0 S _x1_2
000000010004c1d8 S _x2
000000010004c1e0 S _x1_3
000000010004c1e8 S _x1_4
000000010004c1f0 S _x1_5
000000010004c1f8 S _x4
000000010004c200 S _x1_6
000000010004c208 S _x7
000000010004c210 S _x7_1

C just puts all these bytes together without any special alignment.
1 2
Next ›   Last »