Code Bloat g++

Martin v. Loewis martin@loewis.home.cs.tu-berlin.de
Fri Feb 18 00:02:00 GMT 2000


> Can you give me a pointer as to how I could test this ? I.e. solaris
> ld doesnt remove duplicate instantiations ??
> 
> I tried compiling a simple program and then tried to link it using
> solaris ld and gnu ld, but got lot of errors..

Please try the attached tar file; the Makefile in it assumes that the
default installation uses GNU binutils.

You'll get a number of binary files, including a.o, a, and
a.gnu. Inspect them all with 'objdump --headers'. a.o results from
a.cc, and has a section

  1 .gnu.linkonce.t.f__H1Zi_v_v 0000001c  00000000  00000000  000000c0  2**2
                  CONTENTS, ALLOC, LOAD, READONLY, CODE, LINK_ONCE_DISCARD

b.o has a similar section. Unfortunately, /usr/ccs/bin/ld does not
support the LINK_ONCE_DISCARD flag (at least not on 2.5.1), so the
resulting binary has

 10 .gnu.linkonce.t.f__H1Zi_v_v 00000038  0001091c  0001091c  0000091c  2**2
                  CONTENTS, ALLOC, LOAD, READONLY, CODE, LINK_ONCE_DISCARD

which is twice the size of the original section, since ld was
concatenating both template instantiations.

The binary produced by GNU ld does not have such a section; GNU ld
merges the gnu.linkonce sections into the .text section.

Regards,
Martin

-------------- next part --------------
A non-text attachment was scrubbed...
Name: dupsection.tgz
Type: application/x-gzip
Size: 381 bytes
Desc: not available
URL: <https://gcc.gnu.org/pipermail/gcc/attachments/20000218/05d5fc1a/attachment.bin>


More information about the Gcc mailing list