annotate dynload/README.txt @ 570:3155ccc33cae

- test/dynload_plain: simplify makefile based build by deducing default c lib to test with from a simple helper build
author Tassilo Philipp
date Sun, 04 Sep 2022 15:57:28 +0200
parents 3e629dc19168
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
1 dynload / abstraction to run-time shared library services:
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
2
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
3 - loading/unloading into the current process
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
4 - symbol lookup
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
5 - enumerating symbol tables
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
6 - elf: support for DT_GNU_HASH
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
7
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
8
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
9 Todo:
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
10 - a.out format
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
11 - support for different kind of symbols
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
12 (exports,imports,sections,constants...)
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
13
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
14 Notes on windows pe format:
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
15
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
16 File Extension: dll
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
17
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
18 Implementation:
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
19
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
20 1. Access to internals
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
21 The handle returned by LoadLibrary() is a pointer to the PE header
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
22 (which is a DOS header).
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
23
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
24
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
25 Notes on elf:
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
26
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
27 File Extension: so
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
28 Variants: Two core classes are defined Elf 32- and 64-bit.
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
29 Only one model is compiled in the library (the current run-time format).
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
30
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
31 Dynamic symbol table:
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
32
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
33 Symbol table layout:
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
34 1. Index 0 in any symbol table is used to represent undefined symbols.
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
35 As such, the first entry in a symbol table (index 0) is always completely
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
36 zeroed (type STT_NOTYPE), and is not used.
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
37
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
38 2. If the file contains any local symbols, the second entry (index 1)
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
39 the symbol table will be a STT_FILE symbol giving the name of the file.
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
40
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
41 3. Section symbols.
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
42
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
43 4. Register symbols.
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
44
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
45 5. Global symbols that have been reduced to local scope via a mapfile.
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
46
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
47 6. For each input file that supplied local symbols, a STT_FILE symbol
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
48 giving the name of the input file is put in the symbol table,
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
49 followed by the symbols in question.
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
50
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
51 7. The global symbols immediately follow the local symbols in the
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
52 symbol table. Local and global symbols are always kept separate
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
53 in this manner, and cannot be mixed together.
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
54
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
55
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
56 Dynamic symbol table handling seem to be different among platforms.
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
57 Due to System V ABI, one get access to the dynamic symbol table through
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
58 the DT_HASH entry in "DYNAMIC" Program Header.
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
59
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
60 It does not work on x86 on a x86_64 linux 2.6 machine.
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
61
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
62 A closer look to the binaries in /usr/lib32 revealed, there are differences:
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
63
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
64 differences
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
65 - elf32 has 21 sections
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
66 - elf64 has (21 + 2) sections
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
67 ".hash"
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
68 ".eh_frame_hdr"
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
69 - elf64 has ".rela.*"
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
70 while elf32 has ".rel.*"
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
71
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
72 in common:
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
73 - both have a ".gnu.hash" section
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
74
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
75
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
76 the ".gnu.hash"
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
77
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
78
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
79 Idea: "GNU hash" method ([3])
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
80
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
81
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
82 Symbol Versioning:
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
83
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
84
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
85
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
86 OS supported prelinking:
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
87
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
88 linux has prelink
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
89 irix has quickstart
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
90 solaris has crle
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
91
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
92 sparc uses STT_REGISTER:
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
93 STT_REGISTER is
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
94 The Sparc architecture has a concept known as a "register symbol". These
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
95 symbols are used to validate symbol/register usage, and can also be
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
96 used to initialize global registers. Other architectures don't use these.
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
97
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
98
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
99
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
100
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
101
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
102
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
103
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
104 References:
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
105 [1] Levin, R. John: Linkers & Loader
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
106 [2] System V ABI
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
107 [3] The cost of elf symbol hashing: http://blogs.sun.com/ali/entry/the_cost_of_elf_symbol
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
108 [4] GNU Hash ELF Section: http://blogs.sun.com/ali/entry/gnu_hash_elf_sections
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
109 [5] http://refspecs.freestandards.org/LSB_3.2.0/LSB-Core-generic/LSB-Core-generic/symversion.html
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
110 [6] elf: http://greek0.net/elf.html
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
111 [7] System V ABI Application Binary Interface - Draft 17 - December 2003 (SCO) :
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
112 http://sco.com/developers/gabi/latest/contents.html
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
113