From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id cR8bHil8smoNxzIAWB0awg (envelope-from ) for ; Tue, 22 Sep 2026 09:01:29 -0400 Authentication-Results: simark.ca; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20251104 header.b=QuBHR19e; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id 756AD1E06B; Tue, 22 Sep 2026 09:01:29 -0400 (EDT) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-25) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-2.4 required=5.0 tests=ARC_SIGNED,ARC_VALID,BAYES_00, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED,RCVD_IN_VALIDITY_CERTIFIED_BLOCKED, RCVD_IN_VALIDITY_RPBL_BLOCKED,RCVD_IN_VALIDITY_SAFE_BLOCKED autolearn=ham autolearn_force=no version=4.0.1 Received: from vm01.sourceware.org (vm01.sourceware.org [38.145.34.32]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange x25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPS id 0AD521E01F for ; Tue, 22 Sep 2026 09:01:28 -0400 (EDT) Received: from vm01.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 990AF4B99F67 for ; Tue, 22 Sep 2026 13:01:27 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 990AF4B99F67 Authentication-Results: sourceware.org; dkim=pass (2048-bit key, unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20251104 header.b=QuBHR19e Received: from mail-yx2-x10.google.com (mail-yx2-x10.google.com [IPv6:2607:f8b0:4864:41::10]) by sourceware.org (Postfix) with ESMTPS id 0BC504B99F4A for ; Tue, 22 Sep 2026 13:00:54 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 0BC504B99F4A Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 0BC504B99F4A Authentication-Results: sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:41::10 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1790082055; cv=none; b=BM+aQvgAhMlrupk/0eQImSAoTI66wQ4mTBBaWW/q1zhXe4y/r6Na/9cuCAlNIdWMx17VYnG5BEM4iDWu+9e1ZULvLFYauWc0KFyZkv0pRcQLLmfv81OnOXggT1/SFrLeWJzUaI5xXeuem6fMNpfGvA0WN3Do7ZczmcfnS7semSc= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1790082055; c=relaxed/simple; bh=kuVoCZhGMF5WOM2O8HRRci+shUFrbabTEkIH97V9LLE=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=TN3TbXgbIBXan25p7FRXILsdHtvVwcXHLu1Lo7wL1Ztlndx7MKfwF9l7BmeFyT6MHnFrYDNrFaELOQr9W/j4RqJ0kPAfcKWJQgm9rak2GGJMYUk7gkNNRkmR6oqxmGjDEzQBd61hbvHFtz/TBiBHVWVT0n6yBECEszKuocWKw7s= ARC-Authentication-Results: i=1; sourceware.org; dkim=pass (2048-bit key, unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20251104 header.b=QuBHR19e DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 0BC504B99F4A Received: by mail-yx2-x10.google.com with SMTP id 956f58d0204a3-66e4aac92dbso3431108d50.2 for ; Tue, 22 Sep 2026 06:00:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1790082054; x=1790686854; darn=sourceware.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to:content-type; bh=tSwr+p7vXuM3Nvr/JYh+SBQ4Mg+RGNJJ/y3IxrORFE4=; b=QuBHR19eOQFpoG9zsxkWdlVUYrAkBd3veUowxlEjdskEr8p1cQRTjW0tTEl3aGPzfN LKXz74QR5igi80VSnN1jxh4flYMR12ph02ak+Dua9fxI0hv6oNo8uG5jsCJjdAZAzV9O 2Z2bHUQZ64V+gIZ5nFufONxEu072v1rdiPkEapLsJ1oV6L8TlkgkjQtzHPYOfjQcPqHe gywGcdM/QA6a89dfNt3BTk04GMG6OT3ZiWsLLfqmcnIgRubhKQ7UTkmv/fQGi5vPYAtv mdQObXGTi7A5ourUUDaQeu+xDqtAyFOVDoh9u0/O2FxzFvNgubcPrSwGJVzcZa3MYUNq 8WWg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1790082054; x=1790686854; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=tSwr+p7vXuM3Nvr/JYh+SBQ4Mg+RGNJJ/y3IxrORFE4=; b=TCsQUtxL9qeyln1mgbApe6kSmF3Hye66UESBIZ3Pno+Gn1VilARXph50Yggpj1Jeo3 KVTX2BeuJpOwhJB8+CtBKwqCTOPHcSA2A9VwcC8vZdkkutnOKStxhd3Gg3t9vnKzw5lu f0O0pqXpjDP6A5f6L27/PhoTRzNa2hT6nDmLDhHc1k2ZF58Qe7+UdE+KmnLGGGjCiKSz fWGQ3FRwj8l8PgnV41pKD9aA3W4jGxEddvqjPHviCcMlurBV9g98HqUB0e0y4CxQd2rF LEkCyKcuBhPkF9+Cvp8in/zAQ4MSNzN1kvVVmd8Tv5/fyye81dvk3AE1iVpnWPkN06As LMYg== X-Gm-Message-State: AFuF++mIlsHpXxP0at3NFwmwvHtQdw3n6xJvHItPEbcU4USCgVo7DyFy h2MNYRpBvLshPR+uNKPtQViXLnWRbcesLgXjWMlopFxG3v2Nqo1AOLg3 X-Gm-Gg: AYBFou3PdIrehsBHxNXwAIVdhDPi/k3wr7RIaqzZVBPyJ+/2KnBFCmZtCldLQ7khGvj CnCrAwpuh41/bQCxK6Zpb1M5LoPrNIKwOVIPRRLMvB5si5GGT8juigQee+9UIyd2yHtdRT7+tGo d3SokYD+Pr3OrxVB/CyVgk7hV2KwuAxMyIgORbqFBuTcjT40gYrrNHUkEVXWAdgpx/T9Ts0r5CN N3Ru869b71+1k254/N2dhEkpIiTAFBZ810w8d/NBhE//iIu8EbQfXzIclB3FoFGhuLQKbQDMxGX v1LHTpf0fFMVYWcoAmHDn7Lw8siNiz2l66DCLwecfoH4pSHTPmIUuG/fpPgXihvzvNA9Lq/tKiY nYleJWqvUgbZTp0209YQ1TZSEZt+DETBH5NU59J/Mv/NCa6OEqUyOwPt7yFJfrjeO7n18YPk1Js gdJbJ9cfB21PCIDO5M3n3EquUQ3F4KDtGh8inDvhoIMyS63CGtDyrxm54nLNbO8fuNVfWk4q31O mQU1lWDwtMPDSVwxCzLzyMO3Zmryy3IU0Toeg== X-Received: by 2002:a05:690e:4850:b0:66f:c1be:a656 with SMTP id 956f58d0204a3-6717fdbf1fcmr3062106d50.72.1790082053746; Tue, 22 Sep 2026 06:00:53 -0700 (PDT) Received: from dhcp-9-123-8-113.bl1-in.ibm.com ([129.41.58.1]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-914023b2a81sm15494246d6.3.2026.09.22.06.00.50 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Tue, 22 Sep 2026 06:00:53 -0700 (PDT) From: Aditya Vidyadhar Kamath To: ulrich.weigand@de.ibm.com, simon.marchi@polymtl.ca, tom@tromey.com Cc: gdb-patches@sourceware.org, Aditya.Kamath1@ibm.com, sangamesh.swamy@in.ibm.com, Aditya Vidyadhar Kamath Subject: [PATCH v3 3/3] Add test cases for all TLS support in AIX Date: Tue, 22 Sep 2026 18:30:28 +0530 Message-ID: <20260922130027.65068-2-akamath996@gmail.com> X-Mailer: git-send-email 2.43.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gdb-patches-bounces~public-inbox=simark.ca@sourceware.org From: Aditya Vidyadhar Kamath This patch adds test cases to all the 4 types of TLS variables in a shared library on AIX. which is 1: local-exec 2: initial-exec 3: global-dynamic 4: local-dynamic le_var1 and le_var2 are local-exec in the main executable. gd_var1 and gd_var2 are initial exec if the compiler chose R_TLS_IE via compiler options otherwise is global dynamic. gd_var1, gd_var2 are global dynamic. ld_only_var is local dynamic since it is used in the shared library only and not in main executable. [See: powerpc-aix-tls-main.c] This test prints all of them and checks if we can access them in AIX. When we run this on AIX we get, gmake check RUNTESTFLAGS='gdb.arch/powerpc-aix-tls.exp CC_FOR_TARGET="/opt/freeware/bin/gcc" CXX_FOR_TARGET="/opt/freeware/bin/g++" CXXFLAGS_FOR_TARGET="-O0 -w -g -gdwarf -maix64" CFLAGS_FOR_TARGET="-O0 -w -g -gd warf -maix64"' Running target unix Using /opt/freeware/share/dejagnu/baseboards/unix.exp as board description file for target. Using /opt/freeware/share/dejagnu/config/unix.exp as generic interface file for target. Using /current_gdb/binutils-gdb/gdb/testsuite/config/unix.exp as tool-and-target-specific interface file. Running /current_gdb/binutils-gdb/gdb/testsuite/gdb.arch/powerpc-aix-tls.exp ... === gdb Summary === //# of expected passes 12 --- gdb/testsuite/gdb.arch/powerpc-aix-tls-lib.c | 66 +++++++ gdb/testsuite/gdb.arch/powerpc-aix-tls-main.c | 69 ++++++++ gdb/testsuite/gdb.arch/powerpc-aix-tls.exp | 163 ++++++++++++++++++ 3 files changed, 298 insertions(+) create mode 100644 gdb/testsuite/gdb.arch/powerpc-aix-tls-lib.c create mode 100644 gdb/testsuite/gdb.arch/powerpc-aix-tls-main.c create mode 100644 gdb/testsuite/gdb.arch/powerpc-aix-tls.exp diff --git a/gdb/testsuite/gdb.arch/powerpc-aix-tls-lib.c b/gdb/testsuite/gdb.arch/powerpc-aix-tls-lib.c new file mode 100644 index 00000000000..3f34d2e570b --- /dev/null +++ b/gdb/testsuite/gdb.arch/powerpc-aix-tls-lib.c @@ -0,0 +1,66 @@ +/* Copyright (C) 2026 Free Software Foundation, Inc. + + This file is part of GDB. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . */ + +/* Global-dynamic TLS variables exported from this shared library. + The main executable accesses these (R_TLS + R_TLSM relocs), which means + the TOC slots will be emitted in the main executable's .loader section. + Within this library the compiler may use local-dynamic or initial-exec + depending on flags, but the main exe always uses global-dynamic for + cross-module symbols. */ + +/* gd_var1 and gd_var2 are exported TLS variables that the main executable + imports via global-dynamic. They are also accessed here via local-dynamic + so that R_TLS_LD + R_TLSML relocs appear in this library's .loader. */ +__thread int gd_var1 = 10; +__thread int gd_var2 = 20; + +/* ld_only_var is a local-dynamic variable that is ONLY accessed from within + this shared library (never referenced in the main executable). This + exercises the access-dependency limitation: GDB must be able to resolve it + even though there is no R_TLS/R_TLSM slot for it in the main exe's loader + section. */ +__thread int ld_only_var = 30; + +/* Access gd_var1, gd_var2 and ld_only_var from within the library so that + the compiler emits R_TLS_LD / R_TLSML relocs into this .so's .loader + section. Force local-dynamic model explicitly. */ +int +lib_set_tls_vars (int a, int b, int c) +{ + gd_var1 = a; + gd_var2 = b; + ld_only_var = c; + return gd_var1 + gd_var2 + ld_only_var; +} + +int +lib_get_gd_var1 (void) +{ + return gd_var1; +} + +int +lib_get_gd_var2 (void) +{ + return gd_var2; +} + +int +lib_get_ld_only (void) +{ + return ld_only_var; +} diff --git a/gdb/testsuite/gdb.arch/powerpc-aix-tls-main.c b/gdb/testsuite/gdb.arch/powerpc-aix-tls-main.c new file mode 100644 index 00000000000..1a8a5561e71 --- /dev/null +++ b/gdb/testsuite/gdb.arch/powerpc-aix-tls-main.c @@ -0,0 +1,69 @@ +/* Copyright (C) 2026 Free Software Foundation, Inc. + + This file is part of GDB. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . */ + +/* This test exercises all four XCOFF TLS models on 64-bit AIX: + - local-exec (variables in the main executable, TP-relative offset) + - initial-exec (R_TLS_IE in which the compiler uses this for extern __thread + variables in the main exe when linked without -brtl) + - global-dynamic (R_TLS + R_TLSM in which cross-module access to variables + in a shared library) + - local-dynamic (R_TLS_LD + R_TLSML The within-module access inside the + shared library; also exercises the access-dependency + case for ld_only_var which is never accessed here) */ + +/* local-exec TLS variables: defined in the main executable. */ +__thread int le_var1 = 100; +__thread int le_var2 = 200; + +/* Declaration of TLS variables from the shared library. + The compiler uses global-dynamic model for these cross-module accesses, + emitting R_TLS + R_TLSM pairs in the .loader section. */ +extern __thread int gd_var1; +extern __thread int gd_var2; +/* ld_only_var is intentionally NOT declared here we only look it up via + GDB's symbol lookup to exercise the access-dependency fallback. This + is an edge case. */ + +extern int lib_set_tls_vars (int, int, int); +extern int lib_get_gd_var1 (void); +extern int lib_get_gd_var2 (void); +extern int lib_get_ld_only (void); + +volatile int sink; + +int +main (void) +{ + /* Set local-exec variables to known values. */ + le_var1 = 11; + le_var2 = 22; + + /* Access cross-module globals -- forces R_TLS + R_TLSM into the main + executable's .loader section for gd_var1 and gd_var2. */ + gd_var1 = 33; + gd_var2 = 44; + + /* Call into the library so the library-side TLS is initialised. This + also exercises the local-dynamic model inside the shared library (the + compiler will use R_TLS_LD for within-module accesses to gd_var1, + gd_var2, and ld_only_var inside the .so). */ + lib_set_tls_vars (33, 44, 55); + + sink = le_var1 + le_var2 + gd_var1 + gd_var2; /* breakpoint here */ + + return sink; +} diff --git a/gdb/testsuite/gdb.arch/powerpc-aix-tls.exp b/gdb/testsuite/gdb.arch/powerpc-aix-tls.exp new file mode 100644 index 00000000000..e4a4829647d --- /dev/null +++ b/gdb/testsuite/gdb.arch/powerpc-aix-tls.exp @@ -0,0 +1,163 @@ +# Copyright (C) 2026 Free Software Foundation, Inc. +# +# This file is part of GDB. +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +# Test GDB TLS variable access on 64-bit AIX (XCOFF) covering all four +# TLS models: +# +# 1. local-exec [le_var1, le_var2 variables defined in the main executable] +# GDB reads the XCOFF symbol value directly as a TP-relative offset. +# +# 2. initial-exec [gd_var1, gd_var2 accessed from the main executable] +# If the compiler chose R_TLS_IE for cross-module accesses +# GDB reads the TOC slot and adds it to TP. +# +# 3. global-dynamic [gd_var1, gd_var2 via R_TLS + R_TLSM] +# GDB reads the module-id from the R_TLSM slot, looks up +# thread_vector[mod_id] to find the TLS block base, and adds the per-variable +# offset from the R_TLS slot. +# +# 4. local-dynamic [ld_only_var which is only accessed from inside the .so of this test case] +# GDB reads the module-id from the R_TLSML slot in the .so, looks +# up thread_vector[mod_id], and adds the within-module offset from R_TLS_LD. +# ld_only_var is never referenced in the main executable, so there +# is no per-variable TOC slot for it in the main executbale; So GDB must use +# the access-dependency fallback path which is rs6000_aix_compute_tls_address (). + +require {istarget "powerpc*-*-aix*"} + +# This test requires 64-bit AIX binaries. Check that the compiler +# accepts -maix64 before doing anything else. +set test_src [standard_output_file "aix64-probe.c"] +set test_bin [standard_output_file "aix64-probe"] +set f [open $test_src w] +puts $f "int main(void){return 0;}" +close $f +if { [gdb_compile $test_src $test_bin executable \ + {additional_flags=-maix64}] != "" } { + unsupported "compiler does not support -maix64" + return +} + +standard_testfile powerpc-aix-tls-main.c +set srcfile_lib powerpc-aix-tls-lib.c +set binfile_lib [standard_output_file powerpc-aix-tls-lib.so] + +# Build shared library. +# On AIX with GCC the standard gdb_compile_shlib helper appends +# "-Wl,-soname," which the AIX linker treats as an input file name, +# causing a COFF mismatch error. Do the two-step compile+link manually: +# first compile the .c to a -fPIC object, then link it into a .so. +# -maix64 forces 64-bit mode throughout. +set lib_obj [standard_output_file powerpc-aix-tls-lib.c.o] +if { [gdb_compile "${srcdir}/${subdir}/${srcfile_lib}" \ + "${lib_obj}" \ + object \ + {debug additional_flags=-fPIC \ + additional_flags=-maix64}] != "" } { + unsupported "failed to compile shared library object" + return +} +if { [gdb_compile "${lib_obj}" \ + "${binfile_lib}" \ + executable \ + {debug additional_flags=-maix64 \ + additional_flags=-shared \ + additional_flags=-Wl,-bexpall \ + additional_flags=-lpthread}] != "" } { + unsupported "failed to link shared library" + return +} + +# Build main executable linked against the shared library. +# Pass the .so directly on the link line; on AIX with GCC shared libraries +# are named as regular file arguments rather than via -l flags. +if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" \ + "${binfile}" \ + executable \ + [list debug \ + additional_flags=-maix64 \ + additional_flags=${binfile_lib} \ + additional_flags=-lpthread]] != "" } { + unsupported "failed to compile test executable" + return +} + +# Helper: assert that printing VAR_EXPR from the inferior gives EXPECTED. +proc check_tls_var { var_expr expected test_name } { + gdb_test "print $var_expr" "= $expected" $test_name +} + +clean_restart ${testfile} +gdb_load_shlib ${binfile_lib} + +if {![runto_main]} { + return +} + +# Set breakpoint at the labelled line in main. +set bp_line [gdb_get_line_number "breakpoint here" \ + "${srcdir}/${subdir}/${srcfile}"] +gdb_breakpoint $bp_line +gdb_continue_to_breakpoint "run to breakpoint" + +# local-exec testing +# le_var1 and le_var2 are defined in the main executable. At this point +# they have been set to 11 and 22 respectively. +with_test_prefix "local-exec" { + check_tls_var le_var1 11 "le_var1 == 11" + check_tls_var le_var2 22 "le_var2 == 22" + + gdb_test "info address le_var1" \ + "Symbol \"le_var1\" is a thread-local variable.*" \ + "info address le_var1" +} + +# initial-exec / global-dynamic testing +# gd_var1 and gd_var2 are defined in the shared library and accessed +# from the main executable. Depending on the compiler's TLS dialect +# the main exe will use either R_TLS_IE = initial-exec or R_TLS+R_TLSM +# global-dynamic. Both must produce the correct values 33 and 44. +with_test_prefix "gd-from-main" { + check_tls_var gd_var1 33 "gd_var1 == 33" + check_tls_var gd_var2 44 "gd_var2 == 44" + + gdb_test "info address gd_var1" \ + "Symbol \"gd_var1\" is a thread-local variable.*" \ + "info address gd_var1" +} + +# local-dynamic testing +# ld_only_var is accessed solely from within the shared library using +# local-dynamic model R_TLS_LD + R_TLSML. lib_set_tls_vars set it to +# 55. Because ld_only_var is not referenced in the main executable there +# is no per-variable TOC slot for it in the main exe's .loader section; +# The fallback code must be used here which is rs6000_aix_compute_tls_address () +with_test_prefix "local-dynamic" { + check_tls_var ld_only_var 55 "ld_only_var == 55" + + gdb_test "info address ld_only_var" \ + "Symbol \"ld_only_var\" is a thread-local variable.*" \ + "info address ld_only_var" +} + +# Library-side local-dynamic - verify via library accessor +# Cross-check by calling the library function that reads the same variable. +with_test_prefix "lib-accessor" { + gdb_test "print lib_get_gd_var1()" "= 33" "lib_get_gd_var1" + gdb_test "print lib_get_gd_var2()" "= 44" "lib_get_gd_var2" + gdb_test "print lib_get_ld_only()" "= 55" "lib_get_ld_only" +} -- 2.51.2