From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id WXd/CycSYmr2WSkAWB0awg (envelope-from ) for ; Thu, 23 Jul 2026 09:07:51 -0400 Authentication-Results: simark.ca; dkim=pass (2048-bit key; unprotected) header.d=palves.net header.i=@palves.net header.a=rsa-sha256 header.s=dreamhost header.b=kRq+xf6e; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id 29E0E1E09E; Thu, 23 Jul 2026 09:07:51 -0400 (EDT) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-25) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-5.4 required=5.0 tests=ARC_SIGNED,ARC_VALID,BAYES_00, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED 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 8E82E1E099 for ; Thu, 23 Jul 2026 09:07:50 -0400 (EDT) Received: from vm01.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 10A394BA79B0 for ; Thu, 23 Jul 2026 13:07:50 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 10A394BA79B0 Authentication-Results: sourceware.org; dkim=pass (2048-bit key, unprotected) header.d=palves.net header.i=@palves.net header.a=rsa-sha256 header.s=dreamhost header.b=kRq+xf6e Received: from green.apple.relay.mailchannels.net (green.apple.relay.mailchannels.net [23.83.208.77]) by sourceware.org (Postfix) with ESMTPS id 366D14BA7999 for ; Thu, 23 Jul 2026 13:04:37 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 366D14BA7999 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=palves.net Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=palves.net ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 366D14BA7999 Authentication-Results: sourceware.org; arc=none smtp.remote-ip=23.83.208.77 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1784811877; cv=none; b=xLa/XYwMDrb0cdrVO9aoHKqvm6C7vqL/4xZLn3+Vfd6Yyb6AKmvSqCMoGTi2AILpeaEbtWHWwDUvxi9h8KFTP81Wi/8GNVh7jFztsR/KpKPA2F0aydoPm8Qsq5FfmIgcaOFS9MshgCnCPf4YkaIbMBeAI15lpBH6Hj+Hk7lBnvw= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1784811877; c=relaxed/simple; bh=L6Box1sbm0G/G+vsmzsSwFDoqiPaWTHelPK/iRxMAUY=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=heZPrUM1gbXF3FvyEmB6A3j+1VS+K4BXQxTp7WYtY6fsv03ZW9x9gxKi74Lt7/ZdPr0jiXsazjbgn0XiUBUx1vnEsv0nNHIu7570YL7Cvt0SOSzNLxUGB1r2qH7btYWOZyF5TU9z22JrXzx/7Onrp6H05nDdNvPPzmsXtPjb1bk= ARC-Authentication-Results: i=1; sourceware.org; dkim=pass (2048-bit key, unprotected) header.d=palves.net header.i=@palves.net header.a=rsa-sha256 header.s=dreamhost header.b=kRq+xf6e DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 366D14BA7999 X-Sender-Id: dreamhost|x-authsender|pedro@palves.net Received: from relay.mailchannels.net (localhost [127.0.0.1]) by relay.mailchannels.net (Postfix) with ESMTP id 39FEE7E1BE6 for ; Thu, 23 Jul 2026 13:04:36 +0000 (UTC) Received: from pdx1-sub0-mail-a249.dreamhost.com (100-103-96-19.trex-nlb.outbound.svc.cluster.local [100.103.96.19]) (Authenticated sender: dreamhost) by relay.mailchannels.net (Postfix) with ESMTPA id E31887E1DB6 for ; Thu, 23 Jul 2026 13:04:35 +0000 (UTC) X-Sender-Id: dreamhost|x-authsender|pedro@palves.net X-MC-Relay: Good X-MailChannels-SenderId: dreamhost|x-authsender|pedro@palves.net X-MailChannels-Auth-Id: dreamhost X-Broad-Trail: 42fcdc070dcb93c9_1784811876145_2104262336 X-MC-Loop-Signature: 1784811876145:3087936356 X-MC-Ingress-Time: 1784811876145 Received: from pdx1-sub0-mail-a249.dreamhost.com (pop.dreamhost.com [64.90.62.162]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384) by 100.103.96.19 (trex/8.0.2); Thu, 23 Jul 2026 13:04:36 +0000 Received: from localhost (bl20-181-64.dsl.telepac.pt [2.81.181.64]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: pedro@palves.net) by pdx1-sub0-mail-a249.dreamhost.com (Postfix) with ESMTPSA id 4h5WYH2pxYz105D for ; Thu, 23 Jul 2026 06:04:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=palves.net; s=dreamhost; t=1784811875; bh=PvwwCzypb4GMYkCnxBfH0mVxL48sUzxGFGM/xuuMces=; h=From:To:Subject:Date:Content-Transfer-Encoding; b=kRq+xf6eD6eem0oI0YoVVwwEKD+cJqH4vi5imA3M7wwumVEgek/ha5f36iAhb3Kii 7S7fOJKPgr2Brvvc4MkZeUHI12jDE3EdaBKrr2C+IB5WYO1xoxKIGoagnrh7yLNBQQ 2+69jU4VaPdQ7iKbrNNTN/SM3q0BD/y3uBEk+P3D2B71aXVZmkSahYrUNqMZ2eoZO4 fCtg/LJdKnEpNNjhiRSoaeHH6BjxPdxnbbpUmexBw4VAFm4UN3hf7pQc/Fpr8xCGQh 3s7/DjR8p1DhjsVPVxBtymxW9uaXwKnwBQgU7pSjbD/8+5ocpY/VVn4U30YWlrwa/V 0h56gXe+rXHJQ== From: Pedro Alves To: gdb-patches@sourceware.org Subject: [PATCH 17/27] gdb.base/shreloc.exp: Test absolute symbols portably Date: Thu, 23 Jul 2026 14:01:08 +0100 Message-ID: <20260723130118.206735-18-pedro@palves.net> X-Mailer: git-send-email 2.54.0 In-Reply-To: <20260723130118.206735-1-pedro@palves.net> References: <20260723130118.206735-1-pedro@palves.net> 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 gdb.base/shreloc.exp checks that an absolute symbol -- one whose value is a plain constant, not tied to any section -- is not adjusted when the library it lives in is relocated at load time. It does this by looking at _minor_os_version__, an absolute symbol that GNU ld's PE emulation injects into every image. That symbol only exists with GNU ld, so the check is gated on cygwin/mingw and does not run anywhere else. Generalize the test by doing what the existing comment already suggests: include an absolute symbol via the assembler instead. This drops the last istarget check from the test, runs the absolute-symbol check on every target rather than just cygwin/mingw, and also covers windows-msvc, where _minor_os_version__ does not exist (lld-link does not emit it). While at it, convert the check to gdb_assert. Change-Id: Ife2cc8f59d9e121661c125e08be21b221db860c9 --- gdb/testsuite/gdb.base/shreloc.exp | 20 ++++++------------ gdb/testsuite/gdb.base/shreloc.h | 33 ++++++++++++++++++++++++++++++ gdb/testsuite/gdb.base/shreloc1.c | 2 ++ gdb/testsuite/gdb.base/shreloc2.c | 2 ++ 4 files changed, 43 insertions(+), 14 deletions(-) create mode 100644 gdb/testsuite/gdb.base/shreloc.h diff --git a/gdb/testsuite/gdb.base/shreloc.exp b/gdb/testsuite/gdb.base/shreloc.exp index 718b1ca81ad..6c884f23fad 100644 --- a/gdb/testsuite/gdb.base/shreloc.exp +++ b/gdb/testsuite/gdb.base/shreloc.exp @@ -224,17 +224,9 @@ if {[send_gdb_discard "maint print msymbols ${msymfile}"]} { } } -if {([istarget "*pc-cygwin"] || [istarget "*pc-mingw32"]) } { - # - # We know the names of some absolute symbols included in the - # portable-executable (DLL) format. Check that they didn't get - # relocated. - # - # A better approach would be include absolute symbols via the assembler. - # - if {[check_same "_minor_os_version__" "${msymfile}"]} { - pass "absolute symbols not relocated" - } else { - fail "absolute symbols not relocated" - } -} +# Both libraries define 'shreloc_abs_sym' as an absolute symbol with +# the same value (see shreloc.h). An absolute symbol is not tied to a +# section, so it must not be adjusted when the library is relocated. +# Check that its value is reported the same for both libraries. +gdb_assert {[check_same "shreloc_abs_sym" "${msymfile}"]} \ + "absolute symbols not relocated" diff --git a/gdb/testsuite/gdb.base/shreloc.h b/gdb/testsuite/gdb.base/shreloc.h new file mode 100644 index 00000000000..cc283a85ce3 --- /dev/null +++ b/gdb/testsuite/gdb.base/shreloc.h @@ -0,0 +1,33 @@ +/* Copyright 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 . */ + +#ifndef GDB_TESTSUITE_GDB_BASE_SHRELOC_H +#define GDB_TESTSUITE_GDB_BASE_SHRELOC_H + +/* An absolute symbol. Its value is a plain constant, not tied to any + section, so it must not be adjusted when the library is relocated + at load time. Included by both libraries so the test can confirm + that GDB reports the same value for both. + + The name is emitted literally without the target's user-label + prefix (e.g. a leading '_' on some formats). The test greps for + the exact name, so it must be identical on every target. This is + OK because the symbol is never referenced from C. */ +asm (".globl shreloc_abs_sym\n\t" + "shreloc_abs_sym = 0x4000"); + +#endif /* GDB_TESTSUITE_GDB_BASE_SHRELOC_H */ diff --git a/gdb/testsuite/gdb.base/shreloc1.c b/gdb/testsuite/gdb.base/shreloc1.c index 6a228f85853..848ffaab4d4 100644 --- a/gdb/testsuite/gdb.base/shreloc1.c +++ b/gdb/testsuite/gdb.base/shreloc1.c @@ -1,3 +1,5 @@ +#include "shreloc.h" + #if defined(_WIN32) || defined(__CYGWIN__) # define ATTRIBUTES __attribute((__dllexport__)) #else diff --git a/gdb/testsuite/gdb.base/shreloc2.c b/gdb/testsuite/gdb.base/shreloc2.c index 1a9b48bd13d..521c4094c80 100644 --- a/gdb/testsuite/gdb.base/shreloc2.c +++ b/gdb/testsuite/gdb.base/shreloc2.c @@ -1,3 +1,5 @@ +#include "shreloc.h" + #if defined(_WIN32) || defined(__CYGWIN__) # define ATTRIBUTES __attribute((__dllexport__)) #else -- 2.54.0