]>
Commit | Line | Data |
---|---|---|
30a4e827 MT |
1 | # |
2 | # Patch provided by Ulrich Drepper in BZ#919562. | |
3 | # | |
4 | # Patch has not been sent upstream. | |
5 | # | |
6 | # 2013-03-08 Ulrich Drepper <drepper@gmail.com> | |
7 | # | |
8 | # * elf/rtld.c (dl_main): Correctly determine when the application | |
9 | # required DSOs with TLS and bump the generation counter in that | |
10 | # case. The current condition does not account for an audit | |
11 | # module using TLS. | |
12 | # * elf/dl-tls.c (_dl_count_modids): New function. | |
13 | # (_dl_allocate_tls_init): Add assertion to check TLS | |
14 | # generation. | |
15 | # * sysdeps/generic/ldsodefs.h: Declare _dl_count_modids. | |
16 | # * elf/Makefile: Add rules to build and run tst-audit9. | |
17 | # * elf/tst-audit9.c: New file. | |
18 | # * elf/tst-auditmod9a.c: New file. | |
19 | # * elf/tst-auditmod9b.c: New file. | |
20 | # | |
21 | diff -urN glibc-2.12-2-gc4ccff1.orig/elf/dl-tls.c glibc-2.12-2-gc4ccff1/elf/dl-tls.c | |
22 | --- glibc-2.12-2-gc4ccff1.orig/elf/dl-tls.c 2013-04-24 16:06:10.410756438 -0400 | |
23 | +++ glibc-2.12-2-gc4ccff1/elf/dl-tls.c 2013-04-24 16:06:49.092604707 -0400 | |
24 | @@ -109,6 +109,28 @@ | |
25 | } | |
26 | ||
27 | ||
28 | +size_t | |
29 | +internal_function | |
30 | +_dl_count_modids (void) | |
31 | +{ | |
32 | + if (! __builtin_expect (GL(dl_tls_dtv_gaps), true)) | |
33 | + return GL(dl_tls_max_dtv_idx); | |
34 | + | |
35 | + size_t n = 0; | |
36 | + struct dtv_slotinfo_list *runp = GL(dl_tls_dtv_slotinfo_list); | |
37 | + while (runp != NULL) | |
38 | + { | |
39 | + for (size_t i = 0; i < runp->len; ++i) | |
40 | + if (runp->slotinfo[i].map != NULL) | |
41 | + ++n; | |
42 | + | |
43 | + runp = runp->next; | |
44 | + } | |
45 | + | |
46 | + return n; | |
47 | +} | |
48 | + | |
49 | + | |
50 | #ifdef SHARED | |
51 | void | |
52 | internal_function | |
53 | @@ -411,6 +433,7 @@ | |
54 | ||
55 | /* Keep track of the maximum generation number. This might | |
56 | not be the generation counter. */ | |
57 | + assert (listp->slotinfo[cnt].gen <= GL(dl_tls_generation)); | |
58 | maxgen = MAX (maxgen, listp->slotinfo[cnt].gen); | |
59 | ||
60 | if (map->l_tls_offset == NO_TLS_OFFSET | |
61 | diff -urN glibc-2.12-2-gc4ccff1.orig/elf/Makefile glibc-2.12-2-gc4ccff1/elf/Makefile | |
62 | --- glibc-2.12-2-gc4ccff1.orig/elf/Makefile 2013-04-24 16:06:10.408756448 -0400 | |
63 | +++ glibc-2.12-2-gc4ccff1/elf/Makefile 2013-04-24 16:07:29.475457962 -0400 | |
64 | @@ -97,6 +97,8 @@ | |
65 | tst-audit6.c tst-auditmod6a.c tst-auditmod6b.c \ | |
66 | tst-auditmod6c.c \ | |
67 | tst-audit7.c tst-auditmod7a.c tst-auditmod7b.c \ | |
68 | + tst-audit9.c \ | |
69 | + tst-auditmod9a.c tst-auditmod9b.c \ | |
70 | order2mod1.c order2mod2.c order2mod3.c order2mod4.c \ | |
71 | tst-stackguard1.c tst-stackguard1-static.c \ | |
72 | tst-array5.c tst-array5-static.c tst-array5dep.c \ | |
73 | @@ -198,7 +200,7 @@ | |
74 | tst-dlmodcount tst-dlopenrpath tst-deep1 \ | |
75 | tst-dlmopen1 tst-dlmopen2 tst-dlmopen3 \ | |
76 | unload3 unload4 unload5 unload6 unload7 unload8 tst-global1 order2 \ | |
77 | - tst-audit1 tst-audit2 \ | |
78 | + tst-audit1 tst-audit2 tst-audit9 \ | |
79 | tst-stackguard1 tst-addr1 tst-thrlock \ | |
80 | tst-unique1 tst-unique2 | |
81 | # reldep9 | |
82 | @@ -251,7 +253,8 @@ | |
83 | unload8mod1 unload8mod1x unload8mod2 unload8mod3 \ | |
84 | order2mod1 order2mod2 order2mod3 order2mod4 \ | |
85 | tst-unique1mod1 tst-unique1mod2 \ | |
86 | - tst-unique2mod1 tst-unique2mod2 | |
87 | + tst-unique2mod1 tst-unique2mod2 \ | |
88 | + tst-auditmod9a tst-auditmod9b | |
89 | ifeq (yes,$(have-initfini-array)) | |
90 | modules-names += tst-array2dep tst-array5dep | |
91 | endif | |
92 | @@ -574,6 +577,8 @@ | |
93 | ifuncmod1.so-no-z-defs = yes | |
94 | ifuncmod5.so-no-z-defs = yes | |
95 | ifuncmod6.so-no-z-defs = yes | |
96 | +tst-auditmod9a.so-no-z-defs = yes | |
97 | +tst-auditmod9b.so-no-z-defs = yes | |
98 | ||
99 | ifeq ($(build-shared),yes) | |
100 | # Build all the modules even when not actually running test programs. | |
101 | @@ -1015,6 +1020,10 @@ | |
102 | $(objpfx)tst-audit7.out: $(objpfx)tst-auditmod7b.so | |
103 | tst-audit7-ENV = LD_AUDIT=$(objpfx)tst-auditmod7b.so | |
104 | ||
105 | +$(objpfx)tst-audit9: $(libdl) | |
106 | +$(objpfx)tst-audit9.out: $(objpfx)tst-auditmod9a.so $(objpfx)tst-auditmod9b.so | |
107 | +tst-audit9-ENV = LD_AUDIT=$(objpfx)tst-auditmod9a.so | |
108 | + | |
109 | $(objpfx)tst-global1: $(libdl) | |
110 | $(objpfx)tst-global1.out: $(objpfx)testobj6.so $(objpfx)testobj2.so | |
111 | ||
112 | diff -urN glibc-2.12-2-gc4ccff1.orig/elf/rtld.c glibc-2.12-2-gc4ccff1/elf/rtld.c | |
113 | --- glibc-2.12-2-gc4ccff1.orig/elf/rtld.c 2013-04-24 16:06:10.410756438 -0400 | |
114 | +++ glibc-2.12-2-gc4ccff1/elf/rtld.c 2013-04-24 16:06:49.096604693 -0400 | |
115 | @@ -1637,6 +1637,10 @@ | |
116 | } | |
117 | } | |
118 | ||
119 | + /* Keep track of the currently loaded modules to count how many | |
120 | + non-audit modules which use TLS are loaded. */ | |
121 | + size_t count_modids = _dl_count_modids (); | |
122 | + | |
123 | /* Set up debugging before the debugger is notified for the first time. */ | |
124 | #ifdef ELF_MACHINE_DEBUG_SETUP | |
125 | /* Some machines (e.g. MIPS) don't use DT_DEBUG in this way. */ | |
126 | @@ -2281,7 +2285,8 @@ | |
127 | # define NONTLS_INIT_TP do { } while (0) | |
128 | #endif | |
129 | ||
130 | - if (!was_tls_init_tp_called && GL(dl_tls_max_dtv_idx) > 0) | |
131 | + if ((!was_tls_init_tp_called && GL(dl_tls_max_dtv_idx) > 0) | |
132 | + || count_modids != _dl_count_modids ()) | |
133 | ++GL(dl_tls_generation); | |
134 | ||
135 | /* Now that we have completed relocation, the initializer data | |
136 | diff -urN glibc-2.12-2-gc4ccff1.orig/elf/tst-audit9.c glibc-2.12-2-gc4ccff1/elf/tst-audit9.c | |
137 | --- glibc-2.12-2-gc4ccff1.orig/elf/tst-audit9.c 1969-12-31 19:00:00.000000000 -0500 | |
138 | +++ glibc-2.12-2-gc4ccff1/elf/tst-audit9.c 2013-04-24 16:06:49.096604693 -0400 | |
139 | @@ -0,0 +1,8 @@ | |
140 | +#include <dlfcn.h> | |
141 | + | |
142 | +int main(void) | |
143 | +{ | |
144 | + void *h = dlopen("$ORIGIN/tst-auditmod9b.so", RTLD_LAZY); | |
145 | + int (*fp)(void) = dlsym(h, "f"); | |
146 | + return fp() - 1; | |
147 | +} | |
148 | diff -urN glibc-2.12-2-gc4ccff1.orig/elf/tst-auditmod9a.c glibc-2.12-2-gc4ccff1/elf/tst-auditmod9a.c | |
149 | --- glibc-2.12-2-gc4ccff1.orig/elf/tst-auditmod9a.c 1969-12-31 19:00:00.000000000 -0500 | |
150 | +++ glibc-2.12-2-gc4ccff1/elf/tst-auditmod9a.c 2013-04-24 16:06:49.097604689 -0400 | |
151 | @@ -0,0 +1,16 @@ | |
152 | +#include <stdint.h> | |
153 | + | |
154 | +__thread int var; | |
155 | + | |
156 | +unsigned int | |
157 | +la_version (unsigned int v) | |
158 | +{ | |
159 | + return v; | |
160 | +} | |
161 | + | |
162 | +void | |
163 | +la_activity (uintptr_t *cookie, unsigned int flag) | |
164 | +{ | |
165 | + ++var; | |
166 | +} | |
167 | + | |
168 | diff -urN glibc-2.12-2-gc4ccff1.orig/elf/tst-auditmod9b.c glibc-2.12-2-gc4ccff1/elf/tst-auditmod9b.c | |
169 | --- glibc-2.12-2-gc4ccff1.orig/elf/tst-auditmod9b.c 1969-12-31 19:00:00.000000000 -0500 | |
170 | +++ glibc-2.12-2-gc4ccff1/elf/tst-auditmod9b.c 2013-04-24 16:06:49.097604689 -0400 | |
171 | @@ -0,0 +1,6 @@ | |
172 | +__thread int a; | |
173 | + | |
174 | +int f(void) | |
175 | +{ | |
176 | + return ++a; | |
177 | +} | |
178 | diff -urN glibc-2.12-2-gc4ccff1.orig/sysdeps/generic/ldsodefs.h glibc-2.12-2-gc4ccff1/sysdeps/generic/ldsodefs.h | |
179 | --- glibc-2.12-2-gc4ccff1.orig/sysdeps/generic/ldsodefs.h 2013-04-24 16:06:10.545755798 -0400 | |
180 | +++ glibc-2.12-2-gc4ccff1/sysdeps/generic/ldsodefs.h 2013-04-24 16:06:49.098604686 -0400 | |
181 | @@ -1031,6 +1031,9 @@ | |
182 | /* Determine next available module ID. */ | |
183 | extern size_t _dl_next_tls_modid (void) internal_function attribute_hidden; | |
184 | ||
185 | +/* Count the modules with TLS segments. */ | |
186 | +extern size_t _dl_count_modids (void) internal_function attribute_hidden; | |
187 | + | |
188 | /* Calculate offset of the TLS blocks in the static TLS block. */ | |
189 | extern void _dl_determine_tlsoffset (void) internal_function attribute_hidden; | |
190 |