Topic: Diagnosing violations of the ODR
Author: Jonathan de Boyne Pollard <J.deBoynePollard@tesco.net>
Date: 1999/10/08 Raw View
James.Kanze@dresdner-bank.com wrote:
> David R Tribble <david@tribble.com> wrote:
> > Thus the following is valid (but unverifiable) C code, but invalid
> > C++ code:
> >
> > // foo.c
> > inline int func(int i) { return i*2; }
> >
> > // bar.c
> > typedef int i_type;
> > inline i_type func(i_type i) { return (i*2); }
>
> [...] At least a conforming implementation in C++ can signal
> the errors.
>
> Signal[l]ing them in this case is not as hard as it would seem.
> Generally speaking, it would suffice if the compiler generated a
> 32 bit hashcode for anything covered by the ODR, and put this in
> the object file. The linker then verifies that all of the
> hashcodes are the same.
Another way that some C++ compilers solve this problem is to use linker
features that allow segments from in multiple object files to be overlaid on
top of one another. DOS, Win16, Win32, and OS/2 linkers support a combine
type of "common". Code that is generated by an extern inline function, for
example, is emitted into an object file segment with a "common" combine type
attached to it, and the linker combines all such code into a single instance
in the resulting executable. I'm glossing over the details here, but
effectively all of the copies are overlaid on top of one another at link time.
I don't know offhand whether or not those linkers are smart enough to analyse
the various segment contents to ensure that the data (i.e. the object code
bytes) being overlaid are the same in all cases, but it is certainly not
impossible for them to do so.
This is, of course, equivalent to your scheme, with the exception that "actual
generated object code" has been substituted for "32 bit hashcode".
Compilation, in this regard, is just another hashing function. (-:
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html ]