Question about linking files

Walter Bright bright at Data-IO.COM
Thu Mar 30 05:49:18 AEST 1989


In article <18980 at iuvax.cs.indiana.edu> bobmon at iuvax.cs.indiana.edu (RAMontante) writes:
>The question was:  is such behavior (linking everything in the OBJ)
>necessary for some reason, or is it more likely to be a hack for
>speed/simplicity of compilation (or a bug)?

It is expected behavior, that if you specify a .OBJ file to the linker,
it'll link it in.

Suppose, for example, you create a C file that has only

	static char copyright[] = "Copyright (C) by XYZ Corp";

in it, and you want that string imbedded in the resulting EXE file.
This file would be compiled and then placed in the list of OBJs to be
linked together. If the linker ignored it, because it didn't satisfy any
unresolved externals, then that is a BUG.

The order that OBJs are specified to the linker is also important.

The purpose of library files is to link in only the object files necessary
to resolve any remaining undefined externals.

On a related issue, the structure of an OBJ file closely follows that of
an assembly language source file, i.e. it is *not* organized as a sequence
of functions. OBJ files are a sequence of bytes, with public and
external symbols. What the function boundaries are, or even if the bytes
represent code or data, is irrelevant to the format of the OBJ file.

Expecting object files to have more structure to them is nice for the
future, but for now and for compatibility with existing practice, it's
impractical.

This lack of structure in the OBJ file is a major obstacle when creating
a symbolic debugger. So everyone who does a symbolic debugger has invented
extensions to the format in order to add structure. Unfortunately, the
problems are:
1. This is only added if symbolic debug info is requested.
2. It adds quite a bit to the size of the file, slowing down linking.
3. Microsoft and Borland have decided to keep their formats secret, thus
   doing a major disservice to the community. (Let's here it for open
   standards!)

P.S. My comments apply to OBJ files on MS-DOS, I'm not familiar with
COFF.



More information about the Comp.lang.c mailing list