1# Copyright 2006-2024 Free Software Foundation, Inc. 2 3# This program is free software; you can redistribute it and/or modify 4# it under the terms of the GNU General Public License as published by 5# the Free Software Foundation; either version 3 of the License, or 6# (at your option) any later version. 7# 8# This program is distributed in the hope that it will be useful, 9# but WITHOUT ANY WARRANTY; without even the implied warranty of 10# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11# GNU General Public License for more details. 12# 13# You should have received a copy of the GNU General Public License 14# along with this program. If not, see <http://www.gnu.org/licenses/>. 15 16# This test creates a shared library and a main program which uses 17# that library, extracts the debug info of the library to a separate 18# file, and then tests that a symbol from the shared library is 19# accessible using both absolute and relative settings of 20# LD_LIBRARY_PATH. 21 22# This test needs to change the environment in which the test program 23# is run, specifically the setting of LD_LIBRARY_PATH. GDB can adjust 24# this setting for both native and extended-remote targets, but not 25# for targets to which GDB connects after the program has already 26# started. Therefore, this test won't work for targets which use 27# "target remote". 28require !use_gdb_stub 29require {have_compile_flag -std=c11} 30 31set testfile tls-sepdebug 32set srcmainfile ${testfile}-main.c 33set srcsharedfile ${testfile}-shared.c 34 35set binmainfile [standard_output_file ${testfile}-main] 36set binsharedbase ${testfile}-shared.so 37set binsharedfile [standard_output_file ${binsharedbase}] 38 39# Build the shared library, but use explicit -soname; otherwise the 40# full path to the library would get encoded into ${binmainfile} 41# making LD_LIBRARY_PATH tests useless. 42# 43# The compile flag -std=c11 is required because the test case uses 44# 'thread_local' to indicate thread local storage. This is available 45# as a macro starting in C11 and became a C-language keyword in C23. 46if { [build_executable "build library" ${binsharedfile} ${srcsharedfile} \ 47 {debug shlib additional_flags=-std=c11}] == -1 } { 48 untested "Couldn't compile test library" 49 return -1 50} 51 52# Strip debug information from $binsharedfile, placing it in 53# ${binsharedfile}.debug. Also add a .gnu_debuglink in the former, 54# pointing to the latter. 55gdb_gnu_strip_debug ${binsharedfile} 56 57# Build main program, but do not use `shlib=' since that would 58# automatically add -rpath for gcc. 59if { [gdb_compile_pthreads \ 60 "${srcdir}/${subdir}/${srcmainfile} ${binsharedfile}" \ 61 "${binmainfile}" executable [list debug additional_flags=-std=c11]] \ 62 != "" } { 63 untested "Couldn't compile test program" 64 return -1 65} 66 67set absdir [file dirname [standard_output_file ${binsharedbase}]] 68 69foreach ld_library_path [list $absdir [relative_filename [pwd] $absdir]] \ 70 name { absolute relative } { 71 with_test_prefix $name { 72 73 # Restart, but defer loading until after setting LD_LIBRARY_PATH. 74 clean_restart 75 76 gdb_test_no_output "set env LD_LIBRARY_PATH=$ld_library_path" \ 77 "set env LD_LIBRARY_PATH" 78 79 gdb_load ${binmainfile} 80 81 if ![runto_main] { 82 return 83 } 84 85 # Print a thread local variable from the shared library to be certain 86 # that its symbols were loaded from the separate debuginfo file. 87 gdb_test "print var" \ 88 "\\\$1 = 42" \ 89 "print TLS variable from a shared library with separate debug info file" 90 } 91} 92