[vox-tech] behind the scenes of static

Micah Cowan vox-tech@lists.lugod.org
Fri, 26 Jul 2002 19:04:07 -0700


Peter Jay Salzman writes:
 > > Declaring global variables and functions as "static" keeps the scope of
 > > the variable/function to the file.  I'm no compiler writer, but this could
 > > be done simply by compiling the file, then removing the static symbol
 > > names.  If that's how things are done, this would be a task done by the
 > > compiler, not the linker.
 > 
 > i see what your saying, but it just seems like a more suitable task for
 > the linker.  the process of (resolving or) removing symbol names after
 > compilation just seems like more in the realm of linking.

Yeah, but the linker has no way of knowing what was declared as
"extern" or "static" unless the compiler signals it. AFA GNU
implementations are concerned, both types of symbols actually make it
into the resulting ELF; but they are marked differently. This is
because the linker still needs to map references to the static objects
to some memory space (this is only necessary for dynamically loaded
objects, AFAIK); it will resolve internal links only when referred to
internally (duh), and will resolve external links for whoever wants
'em.

-Micah