POD

Frits van Bommel fvbommel at REMwOVExCAPSs.nl
Fri Dec 29 08:34:25 PST 2006


Aleksey S. Skidan wrote:
> But unfortunately D's structs are not POD
> types. They depend on TypeInfo. For ex.:
> 
> module blah;
> struct Foo{ int a; }
> static Foo bar = { 3; };
> 
> Then
> $ dmd -c blah.d
> $ objdump -t blah.o
> 
> And you'll see a section named like .gnu.linkonce.d.*__initZ that contains the
> bar. But this section contains a reference to TypeInfo object for the Foo.

So? That doesn't have anything to do with POD-ness.

[after removing the extra ; in the initializer]
Actually, I don't see any such thing in my object file:

--------------------

$ objdump -sr test.o	# show relocation records and section contents

test.o:     file format elf32-i386

RELOCATION RECORDS FOR [.text]: (none)

RELOCATION RECORDS FOR [.data]: (none)

RELOCATION RECORDS FOR [.gnu.linkonce.d._D19TypeInfo_S4blah3Foo6__initZ]:
OFFSET   TYPE              VALUE
00000000 R_386_32          _D15TypeInfo_Struct6__vtblZ
0000000c R_386_32          .rodata


Contents of section .data:
  0000 03000000                             ....
Contents of section .rodata:
  0000 626c6168 2e466f6f 00000000 00000000  blah.Foo........
Contents of section .gnu.linkonce.d._D19TypeInfo_S4blah3Foo6__initZ:
  0000 00000000 00000000 08000000 00000000  ................
  0010 04000000 00000000 00000000 00000000  ................
  0020 00000000 00000000                    ........

--------------------

I don't see any special section for 'bar' at all (unless you count 
.data, which happens to only contain 'bar', already initialized to 3).
The only references to TypeInfo I see are the TypeInfo for Foo (not bar) 
and a relocation record that fills in the vtable pointer for 
TypeInfo_Struct.
The TypeInfo is probably emitted in this object file to avoid having to 
potentially emit it everywhere it's used. If nothing actually uses it in 
this program, the linker should be able to throw it out. IIRC optlink 
does this automatically on Windows, but on Linux you need to pass 
-L--gc-sections to DMD to get ld to do this.



More information about the Digitalmars-d mailing list