blob: df3ad75a6d3c836022ec96d260d42ca6f166bcf1 [file] [log] [blame]
Ryan Prichard06d2d792019-01-23 23:19:19 -08001/*
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.
Ryan Pricharde4d620b2019-04-01 17:42:14 -070030
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
36extern "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.
43extern "C" void* get_local_addr() {
Elliott Hughes68ae6ad2020-07-21 16:11:30 -070044 static char buf[1024];
45 return &buf[512];
Ryan Pricharde4d620b2019-04-01 17:42:14 -070046}
47
Ryan Prichard06d2d792019-01-23 23:19:19 -080048// 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.
54extern "C" __thread int elftls_shared_var;
55
56extern "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.
62static __thread int local_var_1 = 15;
63static __thread int local_var_2 = 25;
64
65extern "C" int bump_local_vars() {
66 return ++local_var_1 + ++local_var_2;
67}
68
Paul Kirth4d437782024-01-30 23:03:14 +000069extern "C" int get_local_var1() {
70 return local_var_1;
71}
72
73extern "C" int* get_local_var1_addr() {
74 return &local_var_1;
75}
76
77extern "C" int get_local_var2() {
78 return local_var_2;
79}
80
Ryan Prichard06d2d792019-01-23 23:19:19 -080081__attribute__((weak)) extern "C" __thread int missing_weak_dyn_tls;
82
83extern "C" int* missing_weak_dyn_tls_addr() {
84 return &missing_weak_dyn_tls;
85}