Re: strange linking problem
- From: glen herrmannsfeldt <gah@xxxxxxxxxxxxxxxx>
- Date: Thu, 28 Apr 2005 12:30:22 -0700
Richard E Maine wrote:
In article <1114703379.735008.294480@xxxxxxxxxxxxxxxxxxxxxxxxxxxx>, nicolasbock@xxxxxxxxx wrote:
(snip)
As far as I know, the linker goes through the object files and looks for unsatisfied references to functions and variables. Then it looks through the libraries and tries to satisfy those references by linking code from the libraries into the executable.
(snip)
I'll try. For procedures (both functions and subroutines), you are right, but variables are different. For a procedure, things are relatively simple (in this regard). The linker sees 2 kinds of things: there are references to a procedure and there is a separate thing is the procedure itself. If you have references with no corresponding procedure, that is an error.
There might also be a difference between initialized data (as in BLOCK DATA), and uninitialized data (COMMON not in BLOCK DATA).
For data, however, it is possible to have multiple references to a data area, with nothing that actually is uniquely the data area itself. This is typical of non-initialized data areas. All that the linker sees is that there should be a data area of a certain size and a certain name. If something defines the area, then fine, that definition gets used. But if nothing otherwise defines the data area, the linker will allocate an an appropriate chunk of memory. This is not an error, and indeed is quite typical for COMMON blocks.
and static external variables in other languages that don't have COMMON.
I forget all the right terminology, but the "references" that the linker sees for the variable "test" here are probably of this type, where you won't get an error for a lack of other definition. The linker doesn't tend to look in libraries for this kind of reference.
As far as I know, it was Fortran's COMMON that historically started that
type of reference. It is used for external variables in other languages. The OS/360 linkers have one called SD, used for functions
and subroutines, and one called CM used for COMMON. There is another
type used for ENTRY, but has most of the same properties as SD.
OS/360 also has a reference type called weak, where it will be resolved to point to an otherwise already loaded module, but won't cause it to be loaded from the library.
As alluded to by others, this used to be quite a widespread problem with COMMON in f77 and earlier days. Modules are less prone to the problem, but it can still happen (only when the modules have no referenced procedures).
For OS/360 (and successors) initialized data (from BLOCK DATA) is SD,
just as subroutines and functions are. This can cause some interesting
effects if you accidentally (or not) name COMMON the same as a subroutine. OS/360 also requires that the initialized data be at least as long as the uninitialized data block with the same name. That was
once a limitation on a trick for specifying array sizes at link time
for already compiled subroutines.
-- glen
.
- Follow-Ups:
- Re: strange linking problem
- From: Richard E Maine
- Re: strange linking problem
- References:
- strange linking problem
- From: nicolasbock
- Re: strange linking problem
- From: Richard E Maine
- Re: strange linking problem
- From: nicolasbock
- Re: strange linking problem
- From: Richard E Maine
- strange linking problem
- Prev by Date: Re: why doesn't this compile ?
- Next by Date: Re: compilation problem with module function interface definition
- Previous by thread: Re: strange linking problem
- Next by thread: Re: strange linking problem
- Index(es):
Relevant Pages
|