[TUHS] About Unix header files

Perry E. Metzger perry at piermont.com
Thu Aug 23 01:46:30 AEST 2018


On Wed, 22 Aug 2018 11:29:40 -0400 Paul Winalski
<paul.winalski at gmail.com> wrote:
> On 8/22/18, Perry E. Metzger <perry at piermont.com> wrote:
> >
> > To my knowledge, object file formats still don't have information
> > about type signatures, and linkers still don't care about types.
> > This is actually a problem. It would probably prevent a lot of
> > errors if those things changed.
> 
> For a linker to enforce (or warn about) type and call signature
> matching, it would have to know the type and call semantics of each
> particular language,

Not necessarily. One could produce a language-independent way of
signaling what the type signatures are (perhaps with normalized
language-dependent strings) and the linker could just check that they
match.

I've seen several languages (like OCaml) hack around the lack of this
by providing an auxiliary file for a pre-link phase to check off
of. It would be nicer if the linker could just handle that.

And, as I noted, this would doubtless prevent a _lot_ of bugs.

One could simply decorate the symbols with a
(language, semi-opaque "type string") pair, and the linker could just
verify that they matched without understanding semantics.

> Not impossible, but a difficult and cumbersome problem, particularly
> as language and compiler implementation semantics vary over time.

As I noted, there are ways to get around that.

> C++ and other strongly-typed languages typically hack around the
> problem using name decoration.  Not elegant, but effective.

Name mangling for C++ is needed for another reason, too, which is that
a single "name" foo might be multiple different concrete functions
depending on what type it is invoked on.

> Has anyone experimented with building Unix using C++, to take
> advantage of strong typing?  My guess is no--it would be a Herculean
> task likely to introduce more bugs than it would fix.

C++ doesn't have strong typing in the modern sense. It also has some
small incompatibilities with C's syntax and semantics, sufficient that
you can't just (say) compile the Linux kernel with a C++ compiler and
have it work.

Perry
-- 
Perry E. Metzger		perry at piermont.com



More information about the TUHS mailing list