[dmd-internals] How to avoid 4-word padding for symbols?

Michel Fortin michel.fortin at michelf.com
Sun Nov 7 20:19:55 PST 2010


I hoped it wouldn't have to come to that. I'm a little surprised that symbols have to be 16-byte aligned.

But thanks for confirming what I'll have to do.


Le 2010-11-07 à 21:05, Walter Bright a écrit :

> Symbols are aligned when written out to the data segment.
> 
> To defeat the alignment, symbols that should be adjacent should be merged into one symbol.
> 
> Michel Fortin wrote:
>> It's probably a small thing that I'm missing, but I have a small problem where the code below causes undesired padding to be added between two symbols in the object file. This code writes 5 words to the object file:
>> 
>>    symbol = symbol_name(sname, SCstatic, type_fake(TYnptr));
>>    symbol->Sdt = dt;
>>    symbol->Sseg = objc_getsegment(SEGprotocol);
>>    outdata(symbol);
>> 
>> If you call it 2 times, it generates 5*2 + 3 padding bytes between the two (added dashes to show padding):
>> 
>> [25] 002d2 0034 000da6    0 0f94   2 10000000 00 00 __protocol __OBJC
>> 0000:   0  0  0  0  6  3  0  0  0  0  0  0  0  0  0  0   ................
>> 0010:   0  0  0  0 -0--0--0--0--0--0--0--0--0--0--0--0   ................
>> 0020:   0  0  0  0 36  3  0  0  0  0  0  0  0  0  0  0   ....6...........
>> 0030:   0  0  0  0                     ....            
>> This padding is causing a crash when starting the Objective-C runtime because it expects the two to be contiguous.
>> 
>> What needs to be changed to remove this padding?
>> 
>>  
> _______________________________________________
> dmd-internals mailing list
> dmd-internals at puremagic.com
> http://lists.puremagic.com/mailman/listinfo/dmd-internals

-- 
Michel Fortin
michel.fortin at michelf.com
http://michelf.com/





More information about the dmd-internals mailing list