| @@ -1,14 +1,14 @@ | | | @@ -1,14 +1,14 @@ |
1 | .\" $NetBSD: link.5,v 1.24 2017/07/03 21:30:59 wiz Exp $ | | 1 | .\" $NetBSD: link.5,v 1.25 2022/12/29 22:41:36 gutteridge Exp $ |
2 | .\" | | 2 | .\" |
3 | .\" Copyright (c) 1996 The NetBSD Foundation, Inc. | | 3 | .\" Copyright (c) 1996 The NetBSD Foundation, Inc. |
4 | .\" All rights reserved. | | 4 | .\" All rights reserved. |
5 | .\" | | 5 | .\" |
6 | .\" This code is derived from software contributed to The NetBSD Foundation | | 6 | .\" This code is derived from software contributed to The NetBSD Foundation |
7 | .\" by Paul Kranenburg. | | 7 | .\" by Paul Kranenburg. |
8 | .\" | | 8 | .\" |
9 | .\" Redistribution and use in source and binary forms, with or without | | 9 | .\" Redistribution and use in source and binary forms, with or without |
10 | .\" modification, are permitted provided that the following conditions | | 10 | .\" modification, are permitted provided that the following conditions |
11 | .\" are met: | | 11 | .\" are met: |
12 | .\" 1. Redistributions of source code must retain the above copyright | | 12 | .\" 1. Redistributions of source code must retain the above copyright |
13 | .\" notice, this list of conditions and the following disclaimer. | | 13 | .\" notice, this list of conditions and the following disclaimer. |
14 | .\" 2. Redistributions in binary form must reproduce the above copyright | | 14 | .\" 2. Redistributions in binary form must reproduce the above copyright |
| @@ -66,50 +66,50 @@ Several utilities cooperate to ensure th | | | @@ -66,50 +66,50 @@ Several utilities cooperate to ensure th |
66 | ready to run can complete successfully in a way that optimizes the use | | 66 | ready to run can complete successfully in a way that optimizes the use |
67 | of system resources. | | 67 | of system resources. |
68 | The compiler emits PIC code from which shared libraries can be built by | | 68 | The compiler emits PIC code from which shared libraries can be built by |
69 | .Xr ld 1 . | | 69 | .Xr ld 1 . |
70 | The compiler also includes size information of any initialized data items | | 70 | The compiler also includes size information of any initialized data items |
71 | through the .size assembler directive. | | 71 | through the .size assembler directive. |
72 | .Pp | | 72 | .Pp |
73 | PIC code differs from conventional code in that it accesses data | | 73 | PIC code differs from conventional code in that it accesses data |
74 | variables through an indirection table, the Global Offset Table, | | 74 | variables through an indirection table, the Global Offset Table, |
75 | by convention accessible by the reserved name | | 75 | by convention accessible by the reserved name |
76 | .Em _GLOBAL_OFFSET_TABLE_ . | | 76 | .Em _GLOBAL_OFFSET_TABLE_ . |
77 | The exact mechanism used for this is machine dependent, usually a machine | | 77 | The exact mechanism used for this is machine dependent, usually a machine |
78 | register is reserved for the purpose. | | 78 | register is reserved for the purpose. |
79 | The rational behind this construct is to generate code that is | | 79 | The rationale behind this construct is to generate code that is |
80 | independent of the actual load address. | | 80 | independent of the actual load address. |
81 | Only the values contained in the Global Offset Table may need | | 81 | Only the values contained in the Global Offset Table may need |
82 | updating at run-time depending on the load addresses of the various | | 82 | updating at run-time depending on the load addresses of the various |
83 | shared objects in the address space. | | 83 | shared objects in the address space. |
84 | .Pp | | 84 | .Pp |
85 | Likewise, procedure calls to globally defined functions are redirected | | 85 | Likewise, procedure calls to globally defined functions are redirected |
86 | through the Procedure Linkage Table (PLT) residing in the data | | 86 | through the Procedure Linkage Table (PLT) residing in the data |
87 | segment of the core image. | | 87 | segment of the core image. |
88 | Again, this is done to avoid run-time modifications to the text segment. | | 88 | Again, this is done to avoid run-time modifications to the text segment. |
89 | .Pp | | 89 | .Pp |
90 | The linker-editor allocates the Global Offset Table and Procedure | | 90 | The linker-editor allocates the Global Offset Table and Procedure |
91 | Linkage Table when combining PIC object files into an image suitable | | 91 | Linkage Table when combining PIC object files into an image suitable |
92 | for mapping into the process address space. | | 92 | for mapping into the process address space. |
93 | It also collects all symbols that may be needed by the run-time | | 93 | It also collects all symbols that may be needed by the run-time |
94 | link-editor and stores these along with the image's text and data bits. | | 94 | link-editor and stores these along with the image's text and data bits. |
95 | Another reserved symbol, | | 95 | Another reserved symbol, |
96 | .Em _DYNAMIC | | 96 | .Em _DYNAMIC |
97 | is used to indicate the presence of the run-time linker structures. | | 97 | is used to indicate the presence of the run-time linker structures. |
98 | Whenever | | 98 | Whenever |
99 | .Em _DYNAMIC | | 99 | .Em _DYNAMIC |
100 | is relocated to 0, there is no need to invoke the run-time link-editor. | | 100 | is relocated to 0, there is no need to invoke the run-time link-editor. |
101 | If this symbol is non-zero, it points at a data structure from | | 101 | If this symbol is non-zero, it points at a data structure from |
102 | which the location of the necessary relocation- and symbol information | | 102 | which the location of the necessary relocation and symbol information |
103 | can be derived. | | 103 | can be derived. |
104 | This is most notably used by the start-up module, | | 104 | This is most notably used by the start-up module, |
105 | .Em crt0 . | | 105 | .Em crt0 . |
106 | The _DYNAMIC structure is conventionally located at the start of the data | | 106 | The _DYNAMIC structure is conventionally located at the start of the data |
107 | segment of the image to which it pertains. | | 107 | segment of the image to which it pertains. |
108 | .Sh DATA STRUCTURES | | 108 | .Sh DATA STRUCTURES |
109 | The data structures supporting dynamic linking and run-time relocation | | 109 | The data structures supporting dynamic linking and run-time relocation |
110 | reside both in the text and data segments of the image they apply to. | | 110 | reside both in the text and data segments of the image they apply to. |
111 | The text segments contain read-only data such as symbols descriptions and | | 111 | The text segments contain read-only data such as symbols descriptions and |
112 | names, while the data segments contain the tables that need to be modified by | | 112 | names, while the data segments contain the tables that need to be modified by |
113 | during the relocation process. | | 113 | during the relocation process. |
114 | .Pp | | 114 | .Pp |
115 | The _DYNAMIC symbol references a | | 115 | The _DYNAMIC symbol references a |
| @@ -370,27 +370,27 @@ struct rrs_hash { | | | @@ -370,27 +370,27 @@ struct rrs_hash { |
370 | .It Fa rh_symbolnum | | 370 | .It Fa rh_symbolnum |
371 | The index of the symbol in the shared object's symbol table (as given by the | | 371 | The index of the symbol in the shared object's symbol table (as given by the |
372 | .Fa ld_symbols | | 372 | .Fa ld_symbols |
373 | field). | | 373 | field). |
374 | .It Fa rh_next | | 374 | .It Fa rh_next |
375 | In case of collisions, this field is the offset of the next entry in this | | 375 | In case of collisions, this field is the offset of the next entry in this |
376 | hash table bucket. | | 376 | hash table bucket. |
377 | It is zero for the last bucket element. | | 377 | It is zero for the last bucket element. |
378 | .El | | 378 | .El |
379 | The | | 379 | The |
380 | .Fa rt_symbol | | 380 | .Fa rt_symbol |
381 | structure is used to keep track of run-time allocated commons | | 381 | structure is used to keep track of run-time allocated commons |
382 | and data items copied from shared objects. | | 382 | and data items copied from shared objects. |
383 | These items are kept on linked list and is exported through the | | 383 | These items are kept in a linked list which is exported through the |
384 | .Fa dd_cc | | 384 | .Fa dd_cc |
385 | field in the | | 385 | field in the |
386 | .Fa so_debug | | 386 | .Fa so_debug |
387 | structure (see below) for use by debuggers. | | 387 | structure (see below) for use by debuggers. |
388 | .Bd -literal -offset indent | | 388 | .Bd -literal -offset indent |
389 | struct rt_symbol { | | 389 | struct rt_symbol { |
390 | struct nzlist *rt_sp; | | 390 | struct nzlist *rt_sp; |
391 | struct rt_symbol *rt_next; | | 391 | struct rt_symbol *rt_next; |
392 | struct rt_symbol *rt_link; | | 392 | struct rt_symbol *rt_link; |
393 | void *rt_srcaddr; | | 393 | void *rt_srcaddr; |
394 | struct so_map *rt_smp; | | 394 | struct so_map *rt_smp; |
395 | }; | | 395 | }; |
396 | .Ed | | 396 | .Ed |