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

Michel Fortin michel.fortin at michelf.com
Sun Nov 7 16:50:31 PST 2010


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?

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





More information about the dmd-internals mailing list