Re: How do linkers deal with C++ duplicate code?

David L Moore <dlmoore@molalla.net>
22 Aug 1998 23:27:21 -0400

          From comp.compilers

Related articles
How do linkers deal with C++ duplicate code? johnl@iecc.com (John R Levine) (1998-08-20)
Re: How do linkers deal with C++ duplicate code? johnmce@world.std.com (1998-08-20)
Re: How do linkers deal with C++ duplicate code? stes@mundivia.es (David Stes) (1998-08-20)
Re: How do linkers deal with C++ duplicate code? urs@cs.ucsb.edu (Urs Hoelzle) (1998-08-20)
Re: How do linkers deal with C++ duplicate code? dlmoore@molalla.net (David L Moore) (1998-08-22)
Re: How do linkers deal with C++ duplicate code? dwight@pentasoft.com (1998-08-22)
Re: How do linkers deal with C++ duplicate code? stes@mundivia.es (David Stes) (1998-08-22)
Re: How do linkers deal with C++ duplicate code? saroj@bear.com (1998-08-22)
Re: How do linkers deal with C++ duplicate code? jacob@jacob.remcomp.fr (1998-08-22)
Re: How do linkers deal with C++ duplicate code? ian@cygnus.com (1998-08-22)
Re: How do linkers deal with C++ duplicate code? mrs@kithrup.com (1998-08-22)
[5 later articles]
| List of all articles for this month |

From: David L Moore <dlmoore@molalla.net>
Newsgroups: comp.compilers
Date: 22 Aug 1998 23:27:21 -0400
Organization: One World Internetworking, Inc.
References: 98-08-147
Keywords: linker, C++

John R Levine wrote:
>
> I'm finally back at work on my long threatened linker book. (Chapters
> should appear on my web site soon, for review and comment.)
>
> I'm trying to figure out how linkers deal with the unique problems of
> C++.


Unfortunately, the Unix linkers were originally less functional than
the linkers of propieratary machines, and they have not really caught
up.


One used to be able to define named sections containing code. All the
sections from all your objects with a given name would be combined by
the linker to be contiguous in memory. This allowed you to build up
tables across modules.


Now, if there is a way to define a symbol which gives the size of a
region, and another for the absolute start of a region, you can put
all your initializer's addresses in one such named section and iterate
through it. You may be able to generate a dummy begin and end section
if the linker has no way to define symbols to be the absolute first
and (last+1) addresses of a section, but will guarantee ordering of
sections.


Duplicate code could also be handled using sections, but I don't
remember if any linkers actually ever supported this. You simply have
a type of initialized common which throws away all but the first
initialization or (better) makes sure all initializations are
identical. Once again, because code is divided into sections with all
between section references being relocatable, this will work.


(Of course, the initializer idea does not work for programming
languages in which elaboration ordering is done in a sane fashion, but
for C++ it is fine)
[The latest GNU linker appears, in classic GNU fashion, to have every bell
and whistle anyone could possibly want. -John]




--


Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.