Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!cornell!uw-beaver!uw-june!uw-entropy!dataio!bright From: bright@Data-IO.COM (Walter Bright) Newsgroups: comp.lang.c Subject: Re: Question about linking files Message-ID: <1915@dataio.Data-IO.COM> Date: 29 Mar 89 19:49:18 GMT References: <18980@iuvax.cs.indiana.edu> Reply-To: bright@dataio.Data-IO.COM (Walter Bright) Distribution: na Organization: Data I/O Corporation; Redmond, WA Lines: 44 In article <18980@iuvax.cs.indiana.edu> bobmon@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.