Is it safe to use 'is' to compare types?

H. S. Teoh via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Wed Mar 9 18:14:19 PST 2016


On Thu, Mar 10, 2016 at 01:33:41AM +0000, Yuxuan Shui via Digitalmars-d-learn wrote:
> On Wednesday, 9 March 2016 at 22:26:38 UTC, Ali Çehreli wrote:
> >On 03/09/2016 07:05 AM, Yuxuan Shui wrote:
> >
> >> Can we left TypeInfo symbol undefined in the shared libraries? i.e.
> >> D compiler will strip out TypeInfo definition when creating .so.
> >> (Alternatively, we can have TypeInfo always undefined in .o, and
> >> generate them in linking stage only when creating executables)
> >
> >That would require a linker that's aware of D but as far as I know,
> >all system languages use the system linker.
> >
> >Ali
> 
> Hmm, how about this:
> 
> During compilation, D generate undefined TypeInfo symbols, but it also
> embed type information in the object file (like what Rust does). And
> then, when dmd/ldc/gdc/whatever is called for linking executables, it
> will scan object files and generate another object file containing the
> TypeInfos, and link them together with the system linker. If the
> compiler is called for linking shared libraries, it doesn't.

You can't rely on invoking the compiler to link these objects, because
if you're using shared libraries, it will be the OS's dynamic linker
that will get invoked to resolve the references, and different versions
of shared libraries may have a different set of TypeInfo's, and the
compiler may not be able to generate the required TypeInfo's.

A better way is to use the OS linker's "weak symbol" feature, where a
symbol is allowed to be defined multiple times (with identical content),
and the linker (both dynamic and static) will choose the first
definition that it finds.


T

-- 
Маленькие детки - маленькие бедки.


More information about the Digitalmars-d-learn mailing list