• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2019 The Android Open Source Project
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  *  * Redistributions of source code must retain the above copyright
9  *    notice, this list of conditions and the following disclaimer.
10  *  * Redistributions in binary form must reproduce the above copyright
11  *    notice, this list of conditions and the following disclaimer in
12  *    the documentation and/or other materials provided with the
13  *    distribution.
14  *
15  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
16  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
17  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
18  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
19  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
20  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
21  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
22  * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
23  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
24  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
25  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26  * SUCH DAMAGE.
27  */
28 
29 // This shared object test library is dlopen'ed by the main test executable.
30 
31 // Export a large TLS variable from a solib for testing dladdr and dlsym. The
32 // TLS symbol's value will appear to overlap almost everything else in the
33 // shared object, but dladdr must not return it.
34 __thread char large_tls_var[4 * 1024 * 1024];
35 
get_large_tls_var_addr()36 extern "C" char* get_large_tls_var_addr() {
37   return large_tls_var;
38 }
39 
40 // For testing dladdr, return an address that's part of the solib's .bss
41 // section, but does not have an entry in the dynsym table and whose
42 // solib-relative address appears to overlap with the large TLS variable.
get_local_addr()43 extern "C" void* get_local_addr() {
44   static char dummy[1024];
45   return &dummy[512];
46 }
47 
48 // This variable comes from libtest_elftls_shared_var.so, which is part of
49 // static TLS. Verify that a GD-model access can access the variable.
50 //
51 // Accessing the static TLS variable from an solib prevents the static linker
52 // from relaxing the GD access to IE and lets us test that __tls_get_addr and
53 // the tlsdesc resolver handle a static TLS variable.
54 extern "C" __thread int elftls_shared_var;
55 
bump_shared_var()56 extern "C" int bump_shared_var() {
57   return ++elftls_shared_var;
58 }
59 
60 // The static linker denotes the current module by omitting the symbol from
61 // the DTPMOD/TLSDESC relocations.
62 static __thread int local_var_1 = 15;
63 static __thread int local_var_2 = 25;
64 
bump_local_vars()65 extern "C" int bump_local_vars() {
66   return ++local_var_1 + ++local_var_2;
67 }
68 
69 __attribute__((weak)) extern "C" __thread int missing_weak_dyn_tls;
70 
missing_weak_dyn_tls_addr()71 extern "C" int* missing_weak_dyn_tls_addr() {
72   return &missing_weak_dyn_tls;
73 }
74