From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id 3jqiJWL3hWqy/zAAWB0awg (envelope-from ) for ; Wed, 19 Aug 2026 14:35:14 -0400 Authentication-Results: simark.ca; dkim=pass (2048-bit key; unprotected) header.d=ibm.com header.i=@ibm.com header.a=rsa-sha256 header.s=pp1 header.b=sqVbsPjN; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id 84DDA1E09B; Wed, 19 Aug 2026 14:35:14 -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.3 required=5.0 tests=ARC_SIGNED,ARC_VALID,BAYES_00, DKIM_SIGNED,DKIM_VALID,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 1E97C1E09B for ; Wed, 19 Aug 2026 14:35:13 -0400 (EDT) Received: from vm01.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 95E0D4BAE7E5 for ; Wed, 19 Aug 2026 18:35:12 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 95E0D4BAE7E5 Authentication-Results: sourceware.org; dkim=pass (2048-bit key, unprotected) header.d=ibm.com header.i=@ibm.com header.a=rsa-sha256 header.s=pp1 header.b=sqVbsPjN Received: from mx0b-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com [148.163.158.5]) by sourceware.org (Postfix) with ESMTPS id 42BEF4B9DB6F for ; Wed, 19 Aug 2026 18:34:48 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 42BEF4B9DB6F Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=linux.ibm.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=linux.ibm.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 42BEF4B9DB6F Authentication-Results: sourceware.org; arc=none smtp.remote-ip=148.163.158.5 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1787164488; cv=none; b=Jc3AbDm1oI38vX4sqL3b1v74ZNSOpXmcfimz9cHftmmiDXbggb0oqeCXwL1zdwJfZy4lWaIY7sxYNz2Ql6lgpFa8QPtU6i/APpOu32Ljx2oALV8P8T36QR3kf01aYvyqVljSax+LpstM9SiT0qEKpHD28lwiEuUPYLYN0PlDqKI= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1787164488; c=relaxed/simple; bh=F5ceLbBUgH/F1H/808ncVXUAYPvm9Z4sGEX73lqq99A=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=afVgYsftvsPAvHANOM3WloCYtZSWQdDAOJIfDQebSh7whKl9AnuxI8tQm9sMbKOuAo/kogZpsulWH+QkYQfQBXyRinlgRvdgovmHWsAtr9VaohJgG/SQ3VR+wU87DyhvV+EQxiXt8CVGq7rGoLaaFZr4E1FYcU9qdugqiMov20s= ARC-Authentication-Results: i=1; sourceware.org; dkim=pass (2048-bit key, unprotected) header.d=ibm.com header.i=@ibm.com header.a=rsa-sha256 header.s=pp1 header.b=sqVbsPjN DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 42BEF4B9DB6F Received: from pps.filterd (m0356516.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.18.1.11/8.18.1.11) with ESMTP id 67JI1ixg4100320 for ; Wed, 19 Aug 2026 18:34:47 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=cc :content-transfer-encoding:date:from:message-id:mime-version :subject:to; s=pp1; bh=U+tktv2CUEQGDMjSuZ6UW9mROGxQJJcxLgtzmmGcz vM=; b=sqVbsPjNohDDbmP4CN+8PPfUQww42Hi6pOQMG0D0ji7hvCvLpCf+X9bcV hgAJfWYtdr78ElYYOVgYZ+IenjSCd4n414FfMyKftIV58eqMWj0wQ/M371APK3LH 8JvGMtaazZbk/Gg5qhodu5mMysL6qEURDJiPr2yg7Yvkq0vBqOSUSr2kci9WGnlU j5LIWYpKIFnWLOAGAYeDWm1DBdeMTGleC9y9QHOomhyDNvOxdMLmmOqF65F6zeH9 /6EZIPrePmXb9alzkGd0lWdcclSz/+i30rSJxB4TKdbdYZiHpDaA5wMy3yjpNU8f UthWW8pYngbcjtNXXvWQ5bc+gUWWg== Received: from ppma22.wdc07v.mail.ibm.com (5c.69.3da9.ip4.static.sl-reverse.com [169.61.105.92]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 4g4yu45f0r-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Wed, 19 Aug 2026 18:34:47 +0000 (GMT) Received: from pps.filterd (ppma22.wdc07v.mail.ibm.com [127.0.0.1]) by ppma22.wdc07v.mail.ibm.com (8.18.1.7/8.18.1.7) with ESMTP id 67JIQQfK025588 for ; Wed, 19 Aug 2026 18:34:46 GMT Received: from smtprelay03.fra02v.mail.ibm.com ([9.218.2.224]) by ppma22.wdc07v.mail.ibm.com (PPS) with ESMTPS id 4g32twafmt-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Wed, 19 Aug 2026 18:34:46 +0000 (GMT) Received: from smtpav01.fra02v.mail.ibm.com (smtpav01.fra02v.mail.ibm.com [10.20.54.100]) by smtprelay03.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 67JIYcXt28180966 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 19 Aug 2026 18:34:38 GMT Received: from smtpav01.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 1EB462004B; Wed, 19 Aug 2026 18:34:38 +0000 (GMT) Received: from smtpav01.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 5706520043; Wed, 19 Aug 2026 18:34:37 +0000 (GMT) Received: from kubota.pok.stglabs.ibm.com (unknown [9.114.39.181]) by smtpav01.fra02v.mail.ibm.com (Postfix) with ESMTP; Wed, 19 Aug 2026 18:34:37 +0000 (GMT) From: Abhay Kandpal To: gdb-patches@sourceware.org Cc: Ulrich.Weigand@de.ibm.com, cel@linux.ibm.com, abhay.k@ibm.com, Abhay Kandpal Subject: [PATCH v2] PowerPC: fix external calls from modules built by the compile command Date: Wed, 19 Aug 2026 13:34:29 -0500 Message-ID: <20260819183429.3039030-1-abhay@linux.ibm.com> X-Mailer: git-send-email 2.52.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-TM-AS-GCONF: 00 X-Proofpoint-Spam-Info: AW1haW4tMjYwODE5MDE0MyBTYWx0ZWRfX0yDQOvaOG/Ds A7lH3Hxozb3Kx75RD5LprslACRGmJ7TE1ZjGucAzOgG9lVa5SUlHjymefqNdLQAfAwvo/PAng0z uM9+ST2hpLDRcEdgbvKdp/4TxqIy/4M= X-Proofpoint-GUID: eLpGXRPplygxhdA2kcsp1iqanva0xG5B X-Proofpoint-ORIG-GUID: eLpGXRPplygxhdA2kcsp1iqanva0xG5B X-Authority-Analysis: v=2.4 cv=RPmD2Yi+ c=1 sm=1 tr=0 ts=6a85f747 cx=c_pps a=5BHTudwdYE3Te8bg5FgnPg==:117 a=5BHTudwdYE3Te8bg5FgnPg==:17 a=Sv0fKeRqtYgA:10 a=VkNPw1HP01LnGYTKEx00:22 a=RnoormkPH1_aCDwRdu11:22 a=Y2IxJ9c9Rs8Kov3niI8_:22 a=VnNF1IyMAAAA:8 a=QQrMTcx7CB3ijN1mdTcA:9 X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYwODE5MDE0MyBTYWx0ZWRfX84x30sto+M0M j/1uUGI11uYxGKZCKSRZoCFUjMpV9mHPbJsyGc+ywTeZ5AuFSJ9yv4ZvUyAffo8CuKaA4ljtgqr eEh/h2Yd/oiOew/CDfi5+70f0snzOHelwgEQ/LtTDx6a2/IBgDhvItU//EXYt4dnt8ZC5E2N2w8 QX89jaezC+PfPQ9nRhyTND6HFcTZp9VFeXEPJKJ9i+7reZIt65hVsKu+H/jxLBS24oaY8qkT644 JfZVutcHc+3NjBM8zIf3n1xOQRx7vQSEzpEkAVGEye2jX7vioDv00JYjMv8pHSNFWbYNYyzcGqk JF9CPaamaT320BKS+Sk2DmfclAgzo0hT/738/i0/ng48fC6mJdL6J/usIiaFlwEortRTGN3i/NU BsrWzX+6o4UNTePfPA9ZKqvjnc5eNzgMcdJZ+4dLjcUx/uHzQY1e+HgAAueezKXrSkZD6MsYwOq IzY1HyQD7Ve+wFvLyKg== X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1176,Hydra:6.1.134,FMLib:17.12.100.49 definitions=2026-08-19_05,2026-08-19_02,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 clxscore=1015 phishscore=0 adultscore=0 spamscore=0 priorityscore=1501 bulkscore=0 impostorscore=0 malwarescore=0 lowpriorityscore=0 suspectscore=0 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2606150000 definitions=main-2608190143 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 A module built for the compile command is loaded into inferior memory without a linker, so it has no PLT. On ELFv2 the default code model still emits a direct bl for a call to another module, leaving r12 unset and the caller's TOC pointer unrestored, and the callee then derives a wrong r2 from a stale r12. gdb.compile/compile-setjmp.exp shows this: the injected code calls setjmp, whose global entry point computes r2 from a stale r12, and the first TOC-relative load segfaults. -mlongcall makes the call indirect, but on its own it reaches the target through a PLT entry, giving R_PPC64_PLT16_HA/LO_DS relocations that BFD's generic linker rejects. Adding -mno-pltseq resolves the call against the module's own TOC instead, via R_PPC64_TOC16_HA/LO_DS, which GDB already handles. GCC then emits the r2 save and restore around the call itself. Tested on powerpc64le-linux; the two compile-setjmp.exp failures now pass with no unexpected failures in the full testsuite. Suggested-by: Ulrich Weigand --- This patch is reg tested. gdb/ppc-linux-tdep.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/gdb/ppc-linux-tdep.c b/gdb/ppc-linux-tdep.c index 8a55ff5d4af..b468dbcb62c 100644 --- a/gdb/ppc-linux-tdep.c +++ b/gdb/ppc-linux-tdep.c @@ -2196,6 +2196,18 @@ rs6000_linux_adjust_frame_regnum (struct gdbarch *gdbarch, int num, return num; } +/* Implement gdbarch_gcc_target_options. A module built for the "compile" + command is loaded into inferior memory without a linker, so it has no + PLT. -mlongcall makes calls to other modules indirect, and -mno-pltseq + stops GCC reaching the target through a PLT entry; together they let the + call be resolved against the module's own TOC. */ + +static std::string +ppc64_gcc_target_options (struct gdbarch *gdbarch) +{ + return default_gcc_target_options (gdbarch) + " -mlongcall -mno-pltseq"; +} + static void ppc_linux_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch) @@ -2304,6 +2316,7 @@ ppc_linux_init_abi (struct gdbarch_info info, (gdbarch, ppc_elfv2_elf_make_msymbol_special); set_gdbarch_skip_entrypoint (gdbarch, ppc_elfv2_skip_entrypoint); + set_gdbarch_gcc_target_options (gdbarch, ppc64_gcc_target_options); } /* Shared library handling. */ -- 2.52.0