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

jacob@jacob.remcomp.fr (Jacob Navia)
22 Aug 1998 23:31:19 -0400

          From comp.compilers

Related articles
[2 earlier articles]
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)
Re: How do linkers deal with C++ duplicate code? mrs@kithrup.com (1998-08-22)
linkers, and a correction to my previous post jacob@jacob.remcomp.fr (1998-08-24)
Re: How do linkers deal with C++ duplicate code? bowdidge@watson.ibm.com (Robert Bowdidge) (1998-08-24)
Re: How do linkers deal with C++ duplicate code? joachim.durchholz@munich.netsurf.de (Joachim Durchholz) (1998-08-25)
[2 later articles]
| List of all articles for this month |

From: jacob@jacob.remcomp.fr (Jacob Navia)
Newsgroups: comp.compilers
Date: 22 Aug 1998 23:31:19 -0400
Organization: Compilers Central
References: 98-08-147
Keywords: linker, C++

Hi John.


As you may already know, I wrote a linker for lcc-win32. It is one of
the fastest linkers for the windows world, featuring approx 7 to 8
times the speed of 'ld'. As I wrote it, I finally realized how C++
ignores duplicates: I cite from the MSDN chapter 'specifications',
section Portable executable and Common object format, chapter 5:
------------------------------------------------------begin quote
5.5.6. COMDAT Sections (Object Only)


The Selection field of the Section Definition auxiliary format is applicable
if the section is a COMDAT section: a section that can be defined by more than
one object file. (The flag IMAGE_SCN_LNK_COMDAT is set in the Section Flags
field of the section header.) The way that the linker resolves the multiple
definitions of COMDAT sections is determined by the Selection field.


The first symbol having the section value of the COMDAT section is the section
symbol This symbol has the name of the section, Value field equal to 0, the
section number of the COMDAT section in question, Type field equal to
IMAGE_SYM_TYPE_NULL, Class field equal to IMAGE_SYM_CLASS_STATIC, and one
auxiliary record. The second symbol is called "the COMDAT symbol" and is used
by the linker in conjunction with the Selection field.


Values for the Selection field are shown below.


Constant Value Description


IMAGE_COMDAT_SELECT_NODUPLICATES 1 The linker generates a warning if more
than one section defines the same
COMDAT symbol, but links in one of the
sections anyway.
IMAGE_COMDAT_SELECT_ANY 2 Any section defining the same COMDAT
symbol may be linked; the rest are
removed.
IMAGE_COMDAT_SELECT_SAME_SIZE 3 The linker chooses an arbitrary section
among the duplicate sections (having
same COMDAT symbol); however, all must
be the same size or the linker generates
a warning.
IMAGE_COMDAT_SELECT_EXACT_MATCH 4 All duplicate sections must match
exactly. One of them is linked. (This is
not currently implemented in the linker)


IMAGE_COMDAT_SELECT_ASSOCIATIVE 5 The section is linked if a certain other
COMDAT section is linked. This other
section is indicated by the Number
field of the auxiliary symbol record
for the section definition. Use of this
setting is useful for definitions that
have components in multiple sections
(for example, code in one and data in
another), but where all must be linked
together.
--------------------------------------------------------end quote


If any questions arise when you read this wonderful prose... please
feel free to pose them.


It would be nice if you would at least take a look at my linker, and
maybe even nicer if you would mention its existence in the book you
write.


It is the only linker in the world of windows where you can buy the sources...
--
Jacob Navia Logiciels/Informatique
41 rue Maurice Ravel Tel 01 48.23.51.44
93430 Villetaneuse Fax 01 48.23.95.39
France
--


Post a followup to this message

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