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

Walter Bright walter at digitalmars.com
Sun Nov 7 18:05:10 PST 2010


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?
>
>   


More information about the dmd-internals mailing list