-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathREADME.save
More file actions
186 lines (182 loc) · 9.67 KB
/
README.save
File metadata and controls
186 lines (182 loc) · 9.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
g++ --std=c++11 -fPIC -fvisibility=hidden -c fooapi/foo.cpp -o fooapi/foo.o
g++ -fPIC -fvisibility=hidden -shared -Wl,-soname,libfoo.so.1.0.0 -o lib/libfoo.so.1.0.0 fooapi/foo.o
ldd lib/libfoo.so.1.0.0
linux-vdso.so.1 => (0x00007ffe0e12c000)
libstdc++.so.6 => /lib64/libstdc++.so.6 (0x00007fcf7f9dc000)
libm.so.6 => /lib64/libm.so.6 (0x00007fcf7f6da000)
libgcc_s.so.1 => /lib64/libgcc_s.so.1 (0x00007fcf7f4c4000)
libc.so.6 => /lib64/libc.so.6 (0x00007fcf7f0f7000)
/lib64/ld-linux-x86-64.so.2 (0x00007fcf7fee7000)
g++ --std=c++11 -fPIC -fvisibility=hidden -c fooapir2/foo.cpp -o fooapir2/foo.o
g++ -fPIC -fvisibility=hidden -shared -Wl,-soname,libfoo.so.1.0.2 -o lib/libfoo.so.1.0.2 fooapir2/foo.o
ldd lib/libfoo.so.1.0.*
lib/libfoo.so.1.0.0:
linux-vdso.so.1 => (0x00007fffc7d5d000)
libstdc++.so.6 => /lib64/libstdc++.so.6 (0x00007f467a3fc000)
libm.so.6 => /lib64/libm.so.6 (0x00007f467a0fa000)
libgcc_s.so.1 => /lib64/libgcc_s.so.1 (0x00007f4679ee4000)
libc.so.6 => /lib64/libc.so.6 (0x00007f4679b17000)
/lib64/ld-linux-x86-64.so.2 (0x00007f467a907000)
lib/libfoo.so.1.0.2:
linux-vdso.so.1 => (0x00007ffcc05fd000)
libstdc++.so.6 => /lib64/libstdc++.so.6 (0x00007f7968bfe000)
libm.so.6 => /lib64/libm.so.6 (0x00007f79688fc000)
libgcc_s.so.1 => /lib64/libgcc_s.so.1 (0x00007f79686e6000)
libc.so.6 => /lib64/libc.so.6 (0x00007f7968319000)
/lib64/ld-linux-x86-64.so.2 (0x00007f7969109000)
cd lib; ln -s libfoo.so.1.0.0 libfoo.so.1; ln -s libfoo.so.1 libfoo.so; cd ..
total 40
lrwxrwxrwx. 1 amd amd 11 Sep 4 11:30 libfoo.so -> libfoo.so.1
lrwxrwxrwx. 1 amd amd 15 Sep 4 11:30 libfoo.so.1 -> libfoo.so.1.0.0
-rwxrwxr-x. 1 amd amd 20120 Sep 4 11:16 libfoo.so.1.0.0
-rwxrwxr-x. 1 amd amd 20120 Sep 4 11:23 libfoo.so.1.0.2
g++ --std=c++11 -Ifooapi -fPIC -fvisibility=hidden -c barapi/bar.cpp -o barapi/bar.o
g++ -fPIC -fvisibility=hidden -shared -Wl,-soname,libbar.so.1.0.0 -o lib/libbar.so.1.0.0 barapi/bar.o
cd lib; ln -s libbar.so.1.0.0 libbar.so.1; ln -s libbar.so.1 libbar.so; cd ..
total 60
lrwxrwxrwx. 1 amd amd 11 Sep 4 11:37 libbar.so -> libbar.so.1
lrwxrwxrwx. 1 amd amd 15 Sep 4 11:37 libbar.so.1 -> libbar.so.1.0.0
-rwxrwxr-x. 1 amd amd 20160 Sep 4 11:34 libbar.so.1.0.0
lrwxrwxrwx. 1 amd amd 11 Sep 4 11:30 libfoo.so -> libfoo.so.1
lrwxrwxrwx. 1 amd amd 15 Sep 4 11:30 libfoo.so.1 -> libfoo.so.1.0.0
-rwxrwxr-x. 1 amd amd 20120 Sep 4 11:16 libfoo.so.1.0.0
-rwxrwxr-x. 1 amd amd 20120 Sep 4 11:23 libfoo.so.1.0.2
g++ --std=c++11 -Ifooapi -Ibarapi main.cpp -o main -Llib -lfoo -lbar
LD_LIBRARY_PATH=lib ldd ./main
linux-vdso.so.1 => (0x00007ffca29e4000)
libfoo.so.1.0.0 => lib/libfoo.so.1.0.0 (0x00007f5a8572a000)
libbar.so.1.0.0 => lib/libbar.so.1.0.0 (0x00007f5a85526000)
libstdc++.so.6 => /lib64/libstdc++.so.6 (0x00007f5a8521f000)
libm.so.6 => /lib64/libm.so.6 (0x00007f5a84f1d000)
libgcc_s.so.1 => /lib64/libgcc_s.so.1 (0x00007f5a84d07000)
libc.so.6 => /lib64/libc.so.6 (0x00007f5a8493a000)
/lib64/ld-linux-x86-64.so.2 (0x00007f5a8592e000)
Make libbar depend on libfoo - recompile libbar and main app
g++ -fPIC -fvisibility=hidden -shared -Wl,-soname,libbar.so.1.0.0 -o lib/libbar.so.1.0.0 barapi/bar.o -Llib -lfoo
ldd lib/libbar.so
linux-vdso.so.1 => (0x00007ffc5db8e000)
libfoo.so.1.0.0 => not found
libstdc++.so.6 => /lib64/libstdc++.so.6 (0x00007f82064d2000)
libm.so.6 => /lib64/libm.so.6 (0x00007f82061d0000)
libgcc_s.so.1 => /lib64/libgcc_s.so.1 (0x00007f8205fba000)
libc.so.6 => /lib64/libc.so.6 (0x00007f8205bed000)
/lib64/ld-linux-x86-64.so.2 (0x00007f82069dd000)
LD_LIBRARY_PATH=lib ldd lib/libbar.so
linux-vdso.so.1 => (0x00007fff7f1f5000)
libfoo.so.1.0.0 => lib/libfoo.so.1.0.0 (0x00007f3566b82000)
libstdc++.so.6 => /lib64/libstdc++.so.6 (0x00007f356687b000)
libm.so.6 => /lib64/libm.so.6 (0x00007f3566579000)
libgcc_s.so.1 => /lib64/libgcc_s.so.1 (0x00007f3566363000)
libc.so.6 => /lib64/libc.so.6 (0x00007f3565f96000)
/lib64/ld-linux-x86-64.so.2 (0x00007f3566f8a000)
g++ --std=c++11 -Ifooapi -Ibarapi main.cpp -o main -Llib -lbar
/usr/bin/ld: warning: libfoo.so.1.0.0, needed by lib/libbar.so, not found (try using -rpath or -rpath-link)
/tmp/ccPtxeEW.o: In function `main':
main.cpp:(.text+0xa): undefined reference to `foo'
collect2: error: ld returned 1 exit status
Use rpath to the rescue - recompile libbar telling loader to look in for dep libs
g++ -fPIC -fvisibility=hidden -shared -Wl,-soname,libbar.so.1.0.0 -Wl,-rpath,$ORIGIN -o lib/libbar.so.1.0.0 barapi/bar.o -Llib -lfoo
Dynamic section at offset 0x2d98 contains 30 entries:
Tag Type Name/Value
0x0000000000000001 (NEEDED) Shared library: [libfoo.so.1.0.0]
0x0000000000000001 (NEEDED) Shared library: [libstdc++.so.6]
0x0000000000000001 (NEEDED) Shared library: [libm.so.6]
0x0000000000000001 (NEEDED) Shared library: [libgcc_s.so.1]
0x0000000000000001 (NEEDED) Shared library: [libc.so.6]
0x000000000000000e (SONAME) Library soname: [libbar.so.1.0.0]
0x000000000000000f (RPATH) Library rpath: [$ORIGIN]
0x000000000000000c (INIT) 0x1560
0x000000000000000d (FINI) 0x2010
0x0000000000000019 (INIT_ARRAY) 0x202d68
0x000000000000001b (INIT_ARRAYSZ) 16 (bytes)
0x000000000000001a (FINI_ARRAY) 0x202d78
0x000000000000001c (FINI_ARRAYSZ) 8 (bytes)
0x000000006ffffef5 (GNU_HASH) 0x1f0
0x0000000000000005 (STRTAB) 0x830
0x0000000000000006 (SYMTAB) 0x2a8
0x000000000000000a (STRSZ) 1790 (bytes)
0x000000000000000b (SYMENT) 24 (bytes)
0x0000000000000003 (PLTGOT) 0x203000
0x0000000000000002 (PLTRELSZ) 960 (bytes)
0x0000000000000014 (PLTREL) RELA
0x0000000000000017 (JMPREL) 0x11a0
0x0000000000000007 (RELA) 0x1038
0x0000000000000008 (RELASZ) 360 (bytes)
0x0000000000000009 (RELAENT) 24 (bytes)
0x000000006ffffffe (VERNEED) 0xfa8
0x000000006fffffff (VERNEEDNUM) 3
0x000000006ffffff0 (VERSYM) 0xf2e
0x000000006ffffff9 (RELACOUNT) 4
0x0000000000000000 (NULL) 0x0
readelf -d main
Dynamic section at offset 0xdd8 contains 29 entries:
Tag Type Name/Value
0x0000000000000001 (NEEDED) Shared library: [libbar.so.1.0.0]
0x0000000000000001 (NEEDED) Shared library: [libfoo.so.1.0.0]
0x0000000000000001 (NEEDED) Shared library: [libstdc++.so.6]
0x0000000000000001 (NEEDED) Shared library: [libm.so.6]
0x0000000000000001 (NEEDED) Shared library: [libgcc_s.so.1]
0x0000000000000001 (NEEDED) Shared library: [libc.so.6]
0x000000000000000c (INIT) 0x400500
0x000000000000000d (FINI) 0x4006f4
0x0000000000000019 (INIT_ARRAY) 0x600dc0
0x000000000000001b (INIT_ARRAYSZ) 8 (bytes)
0x000000000000001a (FINI_ARRAY) 0x600dc8
0x000000000000001c (FINI_ARRAYSZ) 8 (bytes)
0x000000006ffffef5 (GNU_HASH) 0x400298
0x0000000000000005 (STRTAB) 0x4003c0
0x0000000000000006 (SYMTAB) 0x4002d0
0x000000000000000a (STRSZ) 171 (bytes)
0x000000000000000b (SYMENT) 24 (bytes)
0x0000000000000015 (DEBUG) 0x0
0x0000000000000003 (PLTGOT) 0x601000
0x0000000000000002 (PLTRELSZ) 72 (bytes)
0x0000000000000014 (PLTREL) RELA
0x0000000000000017 (JMPREL) 0x4004b8
0x0000000000000007 (RELA) 0x4004a0
0x0000000000000008 (RELASZ) 24 (bytes)
0x0000000000000009 (RELAENT) 24 (bytes)
0x000000006ffffffe (VERNEED) 0x400480
0x000000006fffffff (VERNEEDNUM) 1
0x000000006ffffff0 (VERSYM) 0x40046c
0x0000000000000000 (NULL) 0x0
g++ --std=c++11 -Ifooapi -Ibarapi main.cpp -o main -Llib -lbar -lfoo
ldd main
linux-vdso.so.1 => (0x00007ffc4efc7000)
libbar.so.1.0.0 => not found
libfoo.so.1.0.0 => not found
libstdc++.so.6 => /lib64/libstdc++.so.6 (0x00007fb8a221f000)
libm.so.6 => /lib64/libm.so.6 (0x00007fb8a1f1d000)
libgcc_s.so.1 => /lib64/libgcc_s.so.1 (0x00007fb8a1d07000)
libc.so.6 => /lib64/libc.so.6 (0x00007fb8a193a000)
/lib64/ld-linux-x86-64.so.2 (0x00007fb8a2526000)
LD_LIBRARY_PATH=lib ./main
foo doimpl 10 version 1 foo
foo doimpl 20 version 1 foo
bar doimpl 20 version 1 bar
Upgrade libfoo
cd lib; rm libfoo.so.1; rm libfoo.so; ln -s libfoo.so.1.0.2 libfoo.so.1; ln -s libfoo.so.1 libfoo.so; cd ..
total 60
lrwxrwxrwx. 1 amd amd 11 Sep 4 11:37 libbar.so -> libbar.so.1
lrwxrwxrwx. 1 amd amd 15 Sep 4 11:37 libbar.so.1 -> libbar.so.1.0.0
-rwxrwxr-x. 1 amd amd 20160 Sep 4 11:47 libbar.so.1.0.0
lrwxrwxrwx. 1 amd amd 11 Sep 4 13:06 libfoo.so -> libfoo.so.1
lrwxrwxrwx. 1 amd amd 15 Sep 4 13:06 libfoo.so.1 -> libfoo.so.1.0.2
-rwxrwxr-x. 1 amd amd 20120 Sep 4 11:16 libfoo.so.1.0.0
-rwxrwxr-x. 1 amd amd 20120 Sep 4 11:23 libfoo.so.1.0.2
LD_LIBRARY_PATH=lib ./main
foo doimpl 10 version 1 foo
foo doimpl 20 version 1 foo
bar doimpl 20 version 1 bar
main app works as libfoo.so.1.0.0 - old version still exists
mv lib/libfoo.so.1.0.0 lib/hide_libfoo.so.1.0.0
total 60
-rwxrwxr-x. 1 amd amd 20120 Sep 4 11:16 hide_libfoo.so.1.0.0
lrwxrwxrwx. 1 amd amd 11 Sep 4 11:37 libbar.so -> libbar.so.1
lrwxrwxrwx. 1 amd amd 15 Sep 4 11:37 libbar.so.1 -> libbar.so.1.0.0
-rwxrwxr-x. 1 amd amd 20160 Sep 4 11:47 libbar.so.1.0.0
lrwxrwxrwx. 1 amd amd 11 Sep 4 13:06 libfoo.so -> libfoo.so.1
lrwxrwxrwx. 1 amd amd 15 Sep 4 13:06 libfoo.so.1 -> libfoo.so.1.0.2
-rwxrwxr-x. 1 amd amd 20120 Sep 4 11:23 libfoo.so.1.0.2
LD_LIBRARY_PATH=lib ./main
./main: error while loading shared libraries: libfoo.so.1.0.0: cannot open shared object file: No such file or directory