| Ryan Prichard | 06d2d79 | 2019-01-23 23:19:19 -0800 | [diff] [blame] | 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 | // This variable comes from libtest_elftls_shared_var.so, which is part of | 
|  | 31 | // static TLS. Verify that a GD-model access can access the variable. | 
|  | 32 | // | 
|  | 33 | // Accessing the static TLS variable from an solib prevents the static linker | 
|  | 34 | // from relaxing the GD access to IE and lets us test that __tls_get_addr and | 
|  | 35 | // the tlsdesc resolver handle a static TLS variable. | 
|  | 36 | extern "C" __thread int elftls_shared_var; | 
|  | 37 |  | 
|  | 38 | extern "C" int bump_shared_var() { | 
|  | 39 | return ++elftls_shared_var; | 
|  | 40 | } | 
|  | 41 |  | 
|  | 42 | // The static linker denotes the current module by omitting the symbol from | 
|  | 43 | // the DTPMOD/TLSDESC relocations. | 
|  | 44 | static __thread int local_var_1 = 15; | 
|  | 45 | static __thread int local_var_2 = 25; | 
|  | 46 |  | 
|  | 47 | extern "C" int bump_local_vars() { | 
|  | 48 | return ++local_var_1 + ++local_var_2; | 
|  | 49 | } | 
|  | 50 |  | 
|  | 51 | __attribute__((weak)) extern "C" __thread int missing_weak_dyn_tls; | 
|  | 52 |  | 
|  | 53 | extern "C" int* missing_weak_dyn_tls_addr() { | 
|  | 54 | return &missing_weak_dyn_tls; | 
|  | 55 | } |