|
|
1.1 root 1:
2:
3: ld Command ld
4:
5:
6:
7:
8: Link relocatable object files
9:
10: lldd [_o_p_t_i_o_n ...] _f_i_l_e ...
11:
12: A compiler translates a file of source code into a relocatable
13: object. This relocatable object cannot be executed by itself,
14: for calls to routines stored in libraries have not yet been
15: resolved. ld combines, or links, relocatable object files with
16: routines stored in libraries produced by the archiver ar to con-
17: struct an executable file. For this reason, ld is sometimes
18: called a linker, a link editor, or a loader.
19:
20: ld scans its arguments in order and interprets each option as
21: described below. Each non-option argument is either a relocat-
22: able object file, produced by cc, as, or ld, or a library archive
23: produced by ar. It rejects all other arguments and prints a
24: diagnostic message.
25:
26: Each relocatable file argument is bound into the output file if
27: its machine type matches the machine type of the first file so
28: bound; if it does not, ld prints a diagnostic message. The sym-
29: bol table of the file is merged into the output symbol table and
30: the list of defined and undefined symbols updated appropriately.
31: If the file redefines a symbol defined in an earlier bound
32: module, the redefinition is reported and the link continues. The
33: last such redefinition determines the value that the symbol will
34: have in the output file, which may be acceptable but is probably
35: an error.
36:
37: Each library archive argument is searched only to resolve un-
38: defined references, i.e., if there are no undefined symbols, the
39: linker goes to the next argument immediately. The library is
40: searched from first module to last and any module that resolves
41: one or more undefined symbols is bound into the output exactly as
42: an explicitly named relocatable file is bound. The library is
43: searched repeatedly until an entire scan adds nothing to the ex-
44: ecutable file.
45:
46: The order of modules in a library is important in two respects:
47: it will affect the time required to search the library, and, if
48: more than one module resolves an undefined symbol, it can alter
49: the set of library modules bound into the output.
50:
51: A library will link faster if the undefined symbols in any given
52: library module are resolved by a library module that comes later
53: in the library. Thus, the low-level library modules, those with
54: no undefined symbols, should come at the end of the library,
55: whereas the higher-level modules, those with many undefined sym-
56: bols, should come at the beginning. The library module ran-
57: lib.sym, which is maintained by the ar s modifier, provides ld
58: with a compressed index to the symbols defined in the library.
59: But even with the index, the library will link much faster if the
60: modules occur in top-down rather than bottom-up order.
61:
62:
63:
64: COHERENT Lexicon Page 1
65:
66:
67:
68:
69: ld Command ld
70:
71:
72:
73: A library can be constructed to provide a type of ``conditional''
74: linking if alternate resolutions of undefined symbols are ar-
75: chived in a carefully thought-out order. For instance, libc.a
76: contains the modules
77:
78:
79: finit.o
80: exit.o
81: _finish.o
82:
83:
84: in precisely the order given, though some other modules may in-
85: tervene. finit.o contains most of the internals of the STDIO
86: library, exit.o contains the exit() function, and _finish.o con-
87: tains an empty version of _finish(), the function that exit()
88: calls to close STDIO streams before process termination. If a
89: program uses any STDIO routines, macros, or data, then finit.o
90: will be bound into the output with its version of finish(). If a
91: program uses no STDIO, then the ``dummy'' _finish.o will be bound
92: into the output because it is the first module that defines
93: _finish() that the linker encounters after exit.o adds the un-
94: defined reference. This saves approximately 3,000 bytes. To set
95: the order of routines within a library, use the archiver ar.
96:
97: The available options are as follows:
98:
99: -dd Define common regions even if relocation information is
100: retained. By default, ld leaves common areas undefined if
101: there are undefined symbols or if the -r option is
102: specified.
103:
104: -ee _e_n_t_r_y
105: Specify the entry point of the output module, either as a
106: symbol or as an absolute octal address.
107:
108: -kk[_s_y_s_t_e_m]
109: Bind the output as a kernel process or linkable driver. The
110: starting address depends on the target machine, and ld scans
111: the system link file symbol table for symbols that are cur-
112: rently undefined. system defaults to /coherent.
113:
114: -ll _n_a_m_e
115: An abbreviation for the library /lliibb/lliibb_n_a_m_e.aa or
116: /uussrr/lliibb/lliibb_n_a_m_e.aa if the first is not found.
117:
118: -mm This option tells ld to perform in-memory load if possible.
119: This requires more memory, but is faster than using a buffer
120: file.
121:
122: -nn Bind the output with separate shared and private segments,
123: and with each starting on a hardware segment boundary, so
124: that several processes can use a single copy of the shared
125: segment simultaneously.
126:
127:
128:
129:
130: COHERENT Lexicon Page 2
131:
132:
133:
134:
135: ld Command ld
136:
137:
138:
139: -oo _f_i_l_e
140: Write output to file (default, ll.oouutt.)
141:
142: -RR _v_a_l_u_e
143: Relocation base option. By default, ld links executeable
144: files to run at the user-base for the computer. In almost
145: all cases, the user-base is zero. If the -R option is used,
146: ld will link the executeable to run at value instead of at
147: zero. value can be set to any C-style constant, or to a
148: symbol name that ld can find in the object files and ar-
149: chives being linked; remember that a C-accessible symbol
150: must end with an underscore character `_'. This option is
151: used primarily to produce output files that can be burned
152: into ROM. These programs must make their own provisions for
153: relocating initialized data and other tasks.
154:
155: -rr Retain relocation information in the output, and issue no
156: diagnostic message for undefined symbols. By default ld
157: discards relocation information from the output if there are
158: no undefined symbols.
159:
160: -ss Strip the symbol table from the output. The same effect may
161: be obtained by using the command strip. The -s and -r op-
162: tions are mutually exclusive.
163:
164: -uu _s_y_m_b_o_l
165: Add symbol to the symbol table as a global reference, usu-
166: ally to force the linking of a particular library module.
167:
168: -XX Discard local compiler-generated symbols of the form `LL...'.
169:
170: -xx Discard all local symbols.
171:
172: ***** Files *****
173:
174: ll.oouutt -- Default output
175: /ccoohheerreenntt for -kk option
176: /lliibb/lliibb*.aa -- Libraries
177: /uussrr/lliibb/lliibb*.aa -- More libraries
178:
179: ***** See Also *****
180:
181: ar, ar.h, as, cc, commands, l.out.h, strip
182:
183: ***** Notes *****
184:
185: By default, COHERENT allocates two kilobytes of stack to a
186: process. This is sufficient for most processes. To change the
187: amount of stack used by a given executable program, use the com-
188: mand fixstack. See its Lexicon entry for details. If you are
189: linking a program by hand (that is, running ld independently from
190: the cc command), be sure to include the appropriate run-time
191: start-up routine with the ld command line; otherwise, the program
192: will not link correctly.
193:
194:
195:
196: COHERENT Lexicon Page 3
197:
198:
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.