[pushed] Revert "gdb: change blockvector::contains() to handle blockvectors with "holes""
| Message ID | 20251223204828.2291977-1-jan.vrany@labware.com |
|---|---|
| State | New |
| Headers |
Return-Path: <gdb-patches-bounces~patchwork=sourceware.org@sourceware.org> X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from vm01.sourceware.org (localhost [127.0.0.1]) by sourceware.org (Postfix) with ESMTP id 67A004BA2E04 for <patchwork@sourceware.org>; Tue, 23 Dec 2025 20:49:26 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 67A004BA2E04 Authentication-Results: sourceware.org; dkim=pass (1024-bit key, unprotected) header.d=labware.com header.i=@labware.com header.a=rsa-sha256 header.s=mimecast20220511 header.b=atR/pvrY X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from us-smtp-delivery-114.mimecast.com (us-smtp-delivery-114.mimecast.com [170.10.133.114]) by sourceware.org (Postfix) with ESMTP id AD0764BA2E06 for <gdb-patches@sourceware.org>; Tue, 23 Dec 2025 20:48:49 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org AD0764BA2E06 Authentication-Results: sourceware.org; dmarc=pass (p=quarantine dis=none) header.from=labware.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=labware.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org AD0764BA2E06 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.133.114 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1766522929; cv=none; b=qRti6IsTLqh5nqggrVMRGwjWjdImYUfiqnsPMKoNyvEdsAcWsvyRV2/d6iqiH0v3EGuFSzu+3lrMA381h5NHdHnqhLgxedsyqbvl/S6EVCWqSzsP43tweoU98Na/ZCI+ounjSemUIoEz71gt8zQEGrrnr2mAFmrJ+EFyiYA9VtY= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1766522929; c=relaxed/simple; bh=pctAjP17NXvWeRX/IUanpVL8AhRuyDjTeFMaSXuEXr4=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=pJzEpwfaM32OBhsY30JOcinpOM83QVqJlNIcZRF45A1WEER46DvBFfDdl1IDwDwOea77bQT6srmv94tnD90OiPEVFNB6MTng7TsNdui4jkrxYtsSPGQq032tRjcgiq+rV8lxAdBHavwXEtBzbh+9I4GVY8LsaJb8KrtosbB1bpE= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org AD0764BA2E06 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=labware.com; s=mimecast20220511; t=1766522929; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=gk78f+abO6xeYgtUGPP225WOAVseFxuu8PPLI4vKvwM=; b=atR/pvrYj3Zx1ofdWof4ES2PC/kWMSjHGzNdiXW4zZh2jmFjuBc4RqjMBqamfXLoIk5N+O g85l0Vb9PxRUBGZ9gkmatd/adk0ydXXh73ZcIFq4ONppPt9sjQK4uCx9+qNiYrsb1ZbpEq NpLOGqwUYQtEsHV4XTmASUZlH3svLz8= Received: from CY3PR05CU001.outbound.protection.outlook.com (mail-westcentralusazon11023075.outbound.protection.outlook.com [40.93.201.75]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-592-WFx343fGPfu0RfIKMYGt0A-1; Tue, 23 Dec 2025 15:48:48 -0500 X-MC-Unique: WFx343fGPfu0RfIKMYGt0A-1 X-Mimecast-MFC-AGG-ID: WFx343fGPfu0RfIKMYGt0A_1766522927 Received: from SA1PR17MB5365.namprd17.prod.outlook.com (2603:10b6:806:1d8::11) by PH7PR17MB7199.namprd17.prod.outlook.com (2603:10b6:510:2e7::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9456.10; Tue, 23 Dec 2025 20:48:44 +0000 Received: from SA1PR17MB5365.namprd17.prod.outlook.com ([fe80::9a:538a:fa42:730e]) by SA1PR17MB5365.namprd17.prod.outlook.com ([fe80::9a:538a:fa42:730e%3]) with mapi id 15.20.9456.008; Tue, 23 Dec 2025 20:48:43 +0000 From: Jan Vrany <jan.vrany@labware.com> To: gdb-patches@sourceware.org CC: Jan Vrany <jan.vrany@labware.com>, tom@tromey.com, vries@gcc.gnu.org, thiago.bauermann@linaro.org, simon.marchi@efficios.com Subject: [pushed] Revert "gdb: change blockvector::contains() to handle blockvectors with "holes"" Date: Tue, 23 Dec 2025 20:48:28 +0000 Message-ID: <20251223204828.2291977-1-jan.vrany@labware.com> X-Mailer: git-send-email 2.51.0 X-ClientProxiedBy: LO6P123CA0004.GBRP123.PROD.OUTLOOK.COM (2603:10a6:600:338::11) To SA1PR17MB5365.namprd17.prod.outlook.com (2603:10b6:806:1d8::11) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SA1PR17MB5365:EE_|PH7PR17MB7199:EE_ X-MS-Office365-Filtering-Correlation-Id: 9b46d95d-2a7f-4746-5c70-08de4264a8df X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|366016|376014 X-Microsoft-Antispam-Message-Info: C067xkD4n//bjjMed86kj0khZxqH0onJ9IofSKiCTUlZeS4f8/A9W8wuN0voFO4GOPNb7JrmNfRpjF1pl45PmFZTt28+EclnsY6BtsdvrEARybmCtfuagOiJKSkjVaTjlVubDwirybP1nWIo/hRosnjOJ3VxTxwXWswXA4qd01OGl4TsfDF9O40s8ZB6HFPBZOHFcy0WffHsTD4O7gebVtsOFLqb13k6TDAGWOv2ZhqUOiNSMRoGtDDhoOQpvxziXmRVWfix8mQTZO6SrLJaH7elp2Lzl3tNL6PxT45LlPw/YM7/2InvDmsb6a+tsIJcn9RVTexhVt/lWGB2LQ7GPIBBCRD6t+LhdkSnVejxJ05yiVuYQOFFgOpNEZfImyTSgV49kThJanneuJEf54m9yQUss4PqFRtorreWp1oFLaRpB7gltsPTsFsSX16WUdlcYl5JqZyElv3s84jtrY15oLBsIO9fCSL9PTKDfOIfNhe0w7KFvLRh2kWVRPrc51F9nsg8bd//r6msFX9G/6MFxC9+AwU801Y4IcNkzyYybxIOM1wStb9WqUpJ+KnWTJDD9gULgj7wGS/rnV/6qruSgrimxAOf8aCJuXcTZTBKQkivkP7zNQqKRPKhEe9OLNeshL0UKZ6g/hbyKZ478lUiTW0Uanb8eaKgSElYx7HAmSF5WOCVsAtP7Cdmph/IrC2Y/QA3t+hNvyBfgcw+lk9uuT/u6/jX1xpJO0T6JgPaWJKM4KqxJYe2WIEJZa+HaRCKJu8y33BUHgj+LjOUxQcTuSOa+ZqBd+c+wuj7eBTT3E0kGisKDU0h/nsnzOXmYr6iGRBxs3bbYUpZuwQ21ms1fVEzKbKtVMZaD6ZysPhjVmucqH5x2UrwDonGvkU5M7dXiTrJp67VExo8C1eurxlbNNodvQBNFEA+M1rIPjAQ/pTr4nSh+XN68rhZ1G3E2gVp5f7nfJAKHt3l9ws8HVHXXvtw6yofH8WIWbf6zsccFTAz/vkCG1nOHuEcxhzQA2bwV/3IlEWGYHnHF0e6GAfLXrrp1DfDDo9j0lhctrlS1vaTuAL1q7PAo6NUh2BLlHjvXav4TuE4YrsO5twyABAVPMAGfGyHC7JVDZ+gY4AmqgwC2llYea47eNPxelSA0vVESq0kMOjY68b3Y0FVAZ8si80sCClYOwAPepbWlaFrChNG/RzKOP8PVLZmsHRsuRcWoZi6BfJY6Zwsg19iOI4am+0BdTX1C8pnVZM0foMaM4z7QCQobzkFbkhV2bN+ZgNdf9e5Hscx1HLnT68i3F9IA9TEU3qJiUUw/TxpwVpLzrR+a/BWb71Eq/hV02uVNCggZqVuNFQTRcJhhNeB1JiTxAMGL4x/JenXzxra4cnpXUsPwVLul23HYCDh688iYTK6H7dr2JqS65p2Wj28s7iMx2FjJXhT+1D8f9HsWAhfGxdEIHKG8LbFw6ZFfEGnWOBYN9eliu/vh6ucppxZu4qsSA== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:SA1PR17MB5365.namprd17.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230040)(1800799024)(366016)(376014); DIR:OUT; SFP:1102 X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: Jgviu9bmslscofh6UAxJ3Rfsr7D0qBCmqMsdIT2+xG9lYt77LligZLK8zXFyeeoCRx2UjqpK0CIOA8hzsSql27NNYOj8ixJ+8EIjg5+0/JR/eb8yYeHHV0W7OLOSpa0HCXhe3huft8g+HcFtCxA6+rMYyyOoYdNJ29cVqhqnNDKCz2hFIgb8JPvMrRj0rDR9zi6i3lWMUeUCvZJsoHzG0+62HUJceanp6kjsXrXfom1HIzxJVjPiS4Pt08YZsvWKFvm4aSWRGFqY8StOTtXxSsFzdf2BoiE4AWrl4Ahhs7sHsYjkTREPKqvzlbad/YmQHXiLwI91r8Yox0o8PWEHgJeSTtF/wWs3LmqNfNy2gXovgoF10v4OzawCn+dWPOykAHBezN3MliVklToF63m9cm+RpTF5bhpcz/kKhO26orh2G01FYrirHozZWH8+dsYRP+ymHwVhq+LHhDfAx740tT+xhdrdqM1TdU4ZahkIWUVFRY4CUWBuBneri1W7GDxPqFZk/YScElSaxZdlYaKhtl9QfTBQY7w1snmU8AgOXTQjGp8/lqx4qP3gHPGhTEMKgfmhKCWnqLwWRELl7uXcSRcXrl1YSXcjQBoM6+z5NqjkGnb1sBjTkj8u0U5iozJso+EpQS+g875m8kJerk9VZ4wLlmo3zjaqXXZGcj4nwSHtQ3njYx95RDs526MgqtjQMLS2v9aXLXjeXnn7hePtNH4UAxDCHouSIeeHcO9oOtU8qqKRFkKjFGCIAVVtPnANRAC0SYhnrMjaUov5lT+slMlZM/oLmf6R3vZcPQIqd/wgipLzNrrY4xDyPwDP2Lj4ZHernFuLcQUZRU3Fdxo/LI2GJl0EXPZ1JQzt5DwcfxdKvVuzTp2nSYFCY1v9r0NyOsNOrpsyBEOYxWYalTcsCg9uplb2B508QEWnckCgn0k44waIGpYI72XqbNsL3+YoYrZmWd7NJVglM7iQYUDsly2T346I6Lxht6VktJxSS8FUDNYKrX3M1sn9bWs2zAaRndJG3nm95d1f2iym5/V7oIjyQwwPeXlCtAG+b2oXDFizIIxhOIM/2BfkL7+QJMzQnF7XgrwJtb536+8FDccdwbuK1guxjtTYEilBP/uxwN6YLQP92D7ttrjGPacA+Q9a25d4w6nL/8DsrDzvfN6gegyrmLegYCN8Hyi7JH5C0ftEEbo1uvH9CYWIfDHTIvuswcehC28tRWtdoDrHRL7sqx3jgcRiIp2YCjVAUQXI1zp5YVaDBKBSU+jkljt9Z0WYiHst4G8myDuPTVea3HQgGQiVmBH3mvtwDUQtnp6gbM5VUKBSvhTqOYX13xiEKeMznUhCCES3kgRmdzUuijD8Gn6bkJRqZuwk3S/3w5YfQMufgrL7Au/N21MKsP36feW0uvk6XUi4LXsu7XhFA313RCfTdL+gzEt/J7Nmtyp+WYU4HjbS0t4OTztYNE7X41Qs36hfmmXVcRt13jTrqlCkUyx6dhNI4N8r1I3tVl1KEadhcr4FjMjIIfs6zUYAyQUnXfjQD4ylmg/2Tl9cH5CW4Iwu3dsXf1okvd/I12dtJWG0RGr+sk2ZLLOYv5guD8ololU4nwxZ1ogFVsWies+ebqoaDkgGXyOeGtLQaEb8LZ2FREglsVilgoRGlxnC4DY41Y1GX4h+FX7SyXX3WLjkUQolQvG3mGxorgpjNY/Qxcof2enVyS5w6RxUugTsysj1kBmg9CPaQG+TOHrPT/WcXg== X-OriginatorOrg: labware.com X-MS-Exchange-CrossTenant-Network-Message-Id: 9b46d95d-2a7f-4746-5c70-08de4264a8df X-MS-Exchange-CrossTenant-AuthSource: SA1PR17MB5365.namprd17.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 23 Dec 2025 20:48:43.4215 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: b5db0322-1aa0-4c0a-859c-ad0f96966f4c X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: C3pZ4Ly40YUH+OYdCdtvIASSJdDEghjhwWKfF40SYy8MGxEWmi3+s324dsGB5RH7gXmMIynGDUD0Lkk+jGo6zA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH7PR17MB7199 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: -39EBcgP29zCZvowggFXc9nDFeII91rUi9ZNkmGQ2TA_1766522927 X-Mimecast-Originator: labware.com Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=WINDOWS-1252 X-Spam-Status: No, score=-13.7 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_BLOCKED, RCVD_IN_MSPIKE_H5, RCVD_IN_MSPIKE_WL, RCVD_IN_VALIDITY_RPBL_BLOCKED, RCVD_IN_VALIDITY_SAFE_BLOCKED, SPF_HELO_PASS, SPF_PASS, TXREP, URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on sourceware.org X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gdb-patches mailing list <gdb-patches.sourceware.org> List-Unsubscribe: <https://sourceware.org/mailman/options/gdb-patches>, <mailto:gdb-patches-request@sourceware.org?subject=unsubscribe> List-Archive: <https://sourceware.org/pipermail/gdb-patches/> List-Post: <mailto:gdb-patches@sourceware.org> List-Help: <mailto:gdb-patches-request@sourceware.org?subject=help> List-Subscribe: <https://sourceware.org/mailman/listinfo/gdb-patches>, <mailto:gdb-patches-request@sourceware.org?subject=subscribe> Errors-To: gdb-patches-bounces~patchwork=sourceware.org@sourceware.org |
| Series |
[pushed] Revert "gdb: change blockvector::contains() to handle blockvectors with "holes""
|
|
Commit Message
Jan Vrany
Dec. 23, 2025, 8:48 p.m. UTC
This reverts commit cc1fc6af4150b19f9c4c70d0463ff498703fb637, since it
causes a number of regressions that seem not to be easily fixable.
The problem lies in existence of "freestanding" code, a code that is
part of a CU but does not have any block associated with it. Consider
following program:
__asm__(
".type foo,@function \n"
"foo: \n"
" mov %rdi, %rax \n"
" ret \n"
);
static int foo(int i);
int main(int argc, char **argv) {
return foo(argc);
}
When compiled, the foo function has no block of itself:
Blockvector:
no map
block #000, object at 0x55978957b510, 1 symbols in 0x1129..0x1148
int main(int, char **); block object 0x55978957b380, 0x112d..0x1148 section .text
block #001, object at 0x55978957b470 under 0x55978957b510, 2 symbols in 0x1129..0x1148
typedef int int;
typedef char char;
block #002, object at 0x55978957b380 under 0x55978957b470, 2 symbols in 0x112d..0x1148, function main
int argc; computed at runtime
char **argv; computed at runtime
In this case lookup(0x1129) returns static block and, because of the
change in cc1fc6af4, contains(0x1129) which is wrong.
Such "freestanding" code is perhaps not common but it does exist,
especially in system code. In fact the regressions were at least in part
caused by such "freestanding" code in glibc (libc_sigaction.c).
The whole idea of commit cc1fc6af4 was to handle "holes" in CUs, a case
where one CU spans over multiple disjoint regions, possibly interleaved
with other CUs. Consider somewhat extreme case with two CUs:
/* hole-1.c */
int give_me_zero ();
int
main ()
{
return give_me_zero ();
}
/* hole-2.c */
int __attribute__ ((section (".text_give_me_one"))) __attribute__((noinline))
baz () { return 42; }
__asm__(
".section .text_give_me_one,\"ax\",@progbits\n"
".type foo,@function \n"
"foo: \n"
" mov %rdi, %rax \n"
" ret \n"
" nop \n"
" nop \n"
" nop \n"
);
int __attribute__ ((section (".text_give_me_one"))) __attribute__((noinline))
give_me_one ()
{
return 1;
}
__asm__(
".section .text_give_me_zero,\"ax\",@progbits\n"
"bar: \n"
" jmp give_me_one \n"
" nop \n"
" nop \n"
" nop \n"
);
int __attribute__ ((section (".text_give_me_zero")))
give_me_zero ()
{
extern int bar();
return give_me_one() - 1;
}
This when compiled with a carefully crafted linker script to force code
at certain positions, creates following layout:
0x080000..0x080007 # "freestanding" bar from hole-2.c
0x080008..0x080016 # give_me_zero() from hole-2.c
0x080109..0x080114 # main from hole-1.c
0xf00000..0xf0000b # baz() from hole-2.c
0xf0000b..0xf00011 # "freestanding" foo from hole-2.
0xf0000b..0xf0001c # gice_me_one() from hole-2.
The block vector for hole-1.c looks:
Blockvector:
no map
block #000, object at 0x555a5d85fb90, 1 symbols in 0x80109..0x80114
int main(void); block object 0x555a5d85faa0, 0x80109..0x80114 section .text
block #001, object at 0x555a5d85faf0 under 0x555a5d85fb90, 1 symbols in 0x80109..0x80114
typedef int int;
block #002, object at 0x555a5d85faa0 under 0x555a5d85faf0, 0 symbols in 0x80109..0x80114, function main
And for hole-2.c:
Blockvector:
map
0x0 -> 0x0
0x80008 -> 0x555a5d85ff50
0x80016 -> 0x0
0xf00000 -> 0x555a5d860280
0xf0000b -> 0x0
0xf00012 -> 0x555a5d860110
0xf0001d -> 0x0
block #000, object at 0x555a5d8603b0, 3 symbols in 0x80008..0xf0001d
int give_me_zero(void); block object 0x555a5d85ff50, 0x80008..0x80016 section .text
int give_me_one(void); block object 0x555a5d860110, 0xf00012..0xf0001d section .text
int baz(void); block object 0x555a5d860280, 0xf00000..0xf0000b section .text
block #001, object at 0x555a5d8602d0 under 0x555a5d8603b0, 1 symbols in 0x80008..0xf0001d
typedef int int;
block #002, object at 0x555a5d85ff50 under 0x555a5d8602d0, 0 symbols in 0x80008..0x80016, function give_me_zero
block #003, object at 0x555a5d860280 under 0x555a5d8602d0, 0 symbols in 0xf00000..0xf0000b, function baz
block #004, object at 0x555a5d860110 under 0x555a5d8602d0, 0 symbols in 0xf00012..0xf0001d, function give_me_one
Note that despite the fact "freestanding" bar belongs to hole-2.c, the
corresponding CU's global and static blocks start at 0x80008! Looking
at DWARF for the second program, it looks like that the compiler (GCC 15)
did not record the presence of "freestanding" code:
<0><71>: Abbrev Number: 1 (DW_TAG_compile_unit)
<72> DW_AT_producer : (indirect string, offset: 0): GNU C23 15.2.0 -mtune=generic -march=x86-64 -g -fasynchronous-unwind-tables
<76> DW_AT_language : 29 (C11)
<77> Unknown AT value: 90: 3
<78> Unknown AT value: 91: 0x31647
<7c> DW_AT_name : (indirect line string, offset: 0x2d): hole-2.c
<80> DW_AT_comp_dir : (indirect line string, offset: 0): test_programs
<84> DW_AT_ranges : 0xc
<88> DW_AT_low_pc : 0
<90> DW_AT_stmt_list : 0x51
and corresponding part of .debug_aranges:
Length: 76
Version: 2
Offset into .debug_info: 0x65
Pointer Size: 8
Segment Size: 0
Address Length
0000000000f00000 000000000000000b
0000000000f00012 000000000000000b
0000000000080008 000000000000000e
0000000000000000 0000000000000000
Thiago suggested to use minsymbols to tell whether or a CU contains
given address. I do not think this would work reliably as minsymbols do
no know to which CU they belong. In slightly more complicated case of
interleaved CUs it does not seem to be possible to tell for sure to which
one a given minsymbol belongs.
Moreover, Tom suggested that the comment in find_compunit_symtab_for_pc_sect
(which led to cc1fc6af4) may be outdated [2].
Given all that, I'm just reverting the change.
[1]: https://sourceware.org/bugzilla/show_bug.cgi?id=33679#c13
[2]: https://inbox.sourceware.org/gdb-patches/87cy6xzd3j.fsf@tromey.com/
Approved-By: Tom Tromey <tom@tromey.com>
Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=33679
---
gdb/block-selftests.c | 15 ++++++++++-----
gdb/block.c | 29 +----------------------------
2 files changed, 11 insertions(+), 33 deletions(-)
Comments
On 12/23/25 9:48 PM, Jan Vrany wrote: > This reverts commit cc1fc6af4150b19f9c4c70d0463ff498703fb637, since it > causes a number of regressions that seem not to be easily fixable. Hi, $subject says "pushed", but AFAICT this hasn't been pushed. Thanks, - Tom > The problem lies in existence of "freestanding" code, a code that is > part of a CU but does not have any block associated with it. Consider > following program: > > __asm__( > ".type foo,@function \n" > "foo: \n" > " mov %rdi, %rax \n" > " ret \n" > ); > > static int foo(int i); > > int main(int argc, char **argv) { > return foo(argc); > } > > When compiled, the foo function has no block of itself: > > Blockvector: > > no map > > block #000, object at 0x55978957b510, 1 symbols in 0x1129..0x1148 > int main(int, char **); block object 0x55978957b380, 0x112d..0x1148 section .text > block #001, object at 0x55978957b470 under 0x55978957b510, 2 symbols in 0x1129..0x1148 > typedef int int; > typedef char char; > block #002, object at 0x55978957b380 under 0x55978957b470, 2 symbols in 0x112d..0x1148, function main > int argc; computed at runtime > char **argv; computed at runtime > > In this case lookup(0x1129) returns static block and, because of the > change in cc1fc6af4, contains(0x1129) which is wrong. > > Such "freestanding" code is perhaps not common but it does exist, > especially in system code. In fact the regressions were at least in part > caused by such "freestanding" code in glibc (libc_sigaction.c). > > The whole idea of commit cc1fc6af4 was to handle "holes" in CUs, a case > where one CU spans over multiple disjoint regions, possibly interleaved > with other CUs. Consider somewhat extreme case with two CUs: > > /* hole-1.c */ > int give_me_zero (); > > int > main () > { > return give_me_zero (); > } > > /* hole-2.c */ > int __attribute__ ((section (".text_give_me_one"))) __attribute__((noinline)) > baz () { return 42; } > > __asm__( > ".section .text_give_me_one,\"ax\",@progbits\n" > ".type foo,@function \n" > "foo: \n" > " mov %rdi, %rax \n" > " ret \n" > " nop \n" > " nop \n" > " nop \n" > ); > int __attribute__ ((section (".text_give_me_one"))) __attribute__((noinline)) > give_me_one () > { > return 1; > } > > __asm__( > ".section .text_give_me_zero,\"ax\",@progbits\n" > "bar: \n" > " jmp give_me_one \n" > " nop \n" > " nop \n" > " nop \n" > ); > int __attribute__ ((section (".text_give_me_zero"))) > give_me_zero () > { > extern int bar(); > return give_me_one() - 1; > } > > This when compiled with a carefully crafted linker script to force code > at certain positions, creates following layout: > > 0x080000..0x080007 # "freestanding" bar from hole-2.c > 0x080008..0x080016 # give_me_zero() from hole-2.c > 0x080109..0x080114 # main from hole-1.c > 0xf00000..0xf0000b # baz() from hole-2.c > 0xf0000b..0xf00011 # "freestanding" foo from hole-2. > 0xf0000b..0xf0001c # gice_me_one() from hole-2. > > The block vector for hole-1.c looks: > > Blockvector: > > no map > > block #000, object at 0x555a5d85fb90, 1 symbols in 0x80109..0x80114 > int main(void); block object 0x555a5d85faa0, 0x80109..0x80114 section .text > block #001, object at 0x555a5d85faf0 under 0x555a5d85fb90, 1 symbols in 0x80109..0x80114 > typedef int int; > block #002, object at 0x555a5d85faa0 under 0x555a5d85faf0, 0 symbols in 0x80109..0x80114, function main > > And for hole-2.c: > > Blockvector: > > map > 0x0 -> 0x0 > 0x80008 -> 0x555a5d85ff50 > 0x80016 -> 0x0 > 0xf00000 -> 0x555a5d860280 > 0xf0000b -> 0x0 > 0xf00012 -> 0x555a5d860110 > 0xf0001d -> 0x0 > > block #000, object at 0x555a5d8603b0, 3 symbols in 0x80008..0xf0001d > int give_me_zero(void); block object 0x555a5d85ff50, 0x80008..0x80016 section .text > int give_me_one(void); block object 0x555a5d860110, 0xf00012..0xf0001d section .text > int baz(void); block object 0x555a5d860280, 0xf00000..0xf0000b section .text > block #001, object at 0x555a5d8602d0 under 0x555a5d8603b0, 1 symbols in 0x80008..0xf0001d > typedef int int; > block #002, object at 0x555a5d85ff50 under 0x555a5d8602d0, 0 symbols in 0x80008..0x80016, function give_me_zero > block #003, object at 0x555a5d860280 under 0x555a5d8602d0, 0 symbols in 0xf00000..0xf0000b, function baz > block #004, object at 0x555a5d860110 under 0x555a5d8602d0, 0 symbols in 0xf00012..0xf0001d, function give_me_one > > Note that despite the fact "freestanding" bar belongs to hole-2.c, the > corresponding CU's global and static blocks start at 0x80008! Looking > at DWARF for the second program, it looks like that the compiler (GCC 15) > did not record the presence of "freestanding" code: > > <0><71>: Abbrev Number: 1 (DW_TAG_compile_unit) > <72> DW_AT_producer : (indirect string, offset: 0): GNU C23 15.2.0 -mtune=generic -march=x86-64 -g -fasynchronous-unwind-tables > <76> DW_AT_language : 29 (C11) > <77> Unknown AT value: 90: 3 > <78> Unknown AT value: 91: 0x31647 > <7c> DW_AT_name : (indirect line string, offset: 0x2d): hole-2.c > <80> DW_AT_comp_dir : (indirect line string, offset: 0): test_programs > <84> DW_AT_ranges : 0xc > <88> DW_AT_low_pc : 0 > <90> DW_AT_stmt_list : 0x51 > > and corresponding part of .debug_aranges: > > Length: 76 > Version: 2 > Offset into .debug_info: 0x65 > Pointer Size: 8 > Segment Size: 0 > > Address Length > 0000000000f00000 000000000000000b > 0000000000f00012 000000000000000b > 0000000000080008 000000000000000e > 0000000000000000 0000000000000000 > > Thiago suggested to use minsymbols to tell whether or a CU contains > given address. I do not think this would work reliably as minsymbols do > no know to which CU they belong. In slightly more complicated case of > interleaved CUs it does not seem to be possible to tell for sure to which > one a given minsymbol belongs. > > Moreover, Tom suggested that the comment in find_compunit_symtab_for_pc_sect > (which led to cc1fc6af4) may be outdated [2]. > > Given all that, I'm just reverting the change. > > [1]: https://sourceware.org/bugzilla/show_bug.cgi?id=33679#c13 > [2]: https://inbox.sourceware.org/gdb-patches/87cy6xzd3j.fsf@tromey.com/ > > Approved-By: Tom Tromey <tom@tromey.com> > Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=33679 > --- > gdb/block-selftests.c | 15 ++++++++++----- > gdb/block.c | 29 +---------------------------- > 2 files changed, 11 insertions(+), 33 deletions(-) > > diff --git a/gdb/block-selftests.c b/gdb/block-selftests.c > index f5883f18660..19e2a6d8db3 100644 > --- a/gdb/block-selftests.c > +++ b/gdb/block-selftests.c > @@ -100,13 +100,18 @@ test_blockvector_lookup_contains () > SELF_CHECK (bv->contains (0x1500) == true); > > /* Test address falling into a "hole". If BV has an address map, > - lookup () returns nullptr. If not, lookup () return static block. > - contains() returns false in both cases. */ > + lookup () returns nullptr and contains (). returns false. If not, > + lookup () return static block and contains() returns true. */ > if (with_map) > - SELF_CHECK (bv->lookup (0x2500) == nullptr); > + { > + SELF_CHECK (bv->lookup (0x2500) == nullptr); > + SELF_CHECK (bv->contains (0x2500) == false); > + } > else > - SELF_CHECK (bv->lookup (0x2500) == bv->block (STATIC_BLOCK)); > - SELF_CHECK (bv->contains (0x2500) == false); > + { > + SELF_CHECK (bv->lookup (0x2500) == bv->block (STATIC_BLOCK)); > + SELF_CHECK (bv->contains (0x2500) == true); > + } > > /* Test address falling into a block above the "hole". */ > SELF_CHECK (bv->lookup (0x3500) == bv->block (3)); > diff --git a/gdb/block.c b/gdb/block.c > index 3d2c51cc554..e21580bcf63 100644 > --- a/gdb/block.c > +++ b/gdb/block.c > @@ -864,34 +864,7 @@ blockvector::lookup (CORE_ADDR addr) const > bool > blockvector::contains (CORE_ADDR addr) const > { > - auto b = lookup (addr); > - if (b == nullptr) > - return false; > - > - /* Handle the case that the blockvector has no address map but still has > - "holes". For example, consider the following blockvector: > - > - B0 0x1000 - 0x4000 (global block) > - B1 0x1000 - 0x4000 (static block) > - B3 0x1000 - 0x2000 > - (hole) > - B4 0x3000 - 0x4000 > - > - In this case, the above blockvector does not contain address 0x2500 but > - lookup (0x2500) would return the blockvector's static block. > - > - So here we check if the returned block is a static block and if yes, still > - return false. However, if the blockvector contains no blocks other than > - the global and static blocks and ADDR falls into the static block, > - conservatively return true. > - > - See comment in find_compunit_symtab_for_pc_sect, symtab.c. > - > - Also, note that if the blockvector in the above example would contain > - an address map, then lookup (0x2500) would return NULL instead of > - the static block. > - */ > - return b != static_block () || num_blocks () == 2; > + return lookup (addr) != nullptr; > } > > /* See block.h. */
On Wed, 2025-12-24 at 14:34 +0100, Tom de Vries wrote: > On 12/23/25 9:48 PM, Jan Vrany wrote: > > This reverts commit cc1fc6af4150b19f9c4c70d0463ff498703fb637, since it > > causes a number of regressions that seem not to be easily fixable. > Hi, > > $subject says "pushed", but AFAICT this hasn't been pushed. > Fixed. Sorry, I should not have been doing things last-minute :-( Jan > Thanks, > - Tom > > > > The problem lies in existence of "freestanding" code, a code that is > > part of a CU but does not have any block associated with it. Consider > > following program: > > > > __asm__( > > ".type foo,@function \n" > > "foo: \n" > > " mov %rdi, %rax \n" > > " ret \n" > > ); > > > > static int foo(int i); > > > > int main(int argc, char **argv) { > > return foo(argc); > > } > > > > When compiled, the foo function has no block of itself: > > > > Blockvector: > > > > no map > > > > block #000, object at 0x55978957b510, 1 symbols in 0x1129..0x1148 > > int main(int, char **); block object 0x55978957b380, 0x112d..0x1148 section .text > > block #001, object at 0x55978957b470 under 0x55978957b510, 2 symbols in 0x1129..0x1148 > > typedef int int; > > typedef char char; > > block #002, object at 0x55978957b380 under 0x55978957b470, 2 symbols in 0x112d..0x1148, function main > > int argc; computed at runtime > > char **argv; computed at runtime > > > > In this case lookup(0x1129) returns static block and, because of the > > change in cc1fc6af4, contains(0x1129) which is wrong. > > > > Such "freestanding" code is perhaps not common but it does exist, > > especially in system code. In fact the regressions were at least in part > > caused by such "freestanding" code in glibc (libc_sigaction.c). > > > > The whole idea of commit cc1fc6af4 was to handle "holes" in CUs, a case > > where one CU spans over multiple disjoint regions, possibly interleaved > > with other CUs. Consider somewhat extreme case with two CUs: > > > > /* hole-1.c */ > > int give_me_zero (); > > > > int > > main () > > { > > return give_me_zero (); > > } > > > > /* hole-2.c */ > > int __attribute__ ((section (".text_give_me_one"))) __attribute__((noinline)) > > baz () { return 42; } > > > > __asm__( > > ".section .text_give_me_one,\"ax\",@progbits\n" > > ".type foo,@function \n" > > "foo: \n" > > " mov %rdi, %rax \n" > > " ret \n" > > " nop \n" > > " nop \n" > > " nop \n" > > ); > > int __attribute__ ((section (".text_give_me_one"))) __attribute__((noinline)) > > give_me_one () > > { > > return 1; > > } > > > > __asm__( > > ".section .text_give_me_zero,\"ax\",@progbits\n" > > "bar: \n" > > " jmp give_me_one \n" > > " nop \n" > > " nop \n" > > " nop \n" > > ); > > int __attribute__ ((section (".text_give_me_zero"))) > > give_me_zero () > > { > > extern int bar(); > > return give_me_one() - 1; > > } > > > > This when compiled with a carefully crafted linker script to force code > > at certain positions, creates following layout: > > > > 0x080000..0x080007 # "freestanding" bar from hole-2.c > > 0x080008..0x080016 # give_me_zero() from hole-2.c > > 0x080109..0x080114 # main from hole-1.c > > 0xf00000..0xf0000b # baz() from hole-2.c > > 0xf0000b..0xf00011 # "freestanding" foo from hole-2. > > 0xf0000b..0xf0001c # gice_me_one() from hole-2. > > > > The block vector for hole-1.c looks: > > > > Blockvector: > > > > no map > > > > block #000, object at 0x555a5d85fb90, 1 symbols in 0x80109..0x80114 > > int main(void); block object 0x555a5d85faa0, 0x80109..0x80114 section .text > > block #001, object at 0x555a5d85faf0 under 0x555a5d85fb90, 1 symbols in 0x80109..0x80114 > > typedef int int; > > block #002, object at 0x555a5d85faa0 under 0x555a5d85faf0, 0 symbols in 0x80109..0x80114, function main > > > > And for hole-2.c: > > > > Blockvector: > > > > map > > 0x0 -> 0x0 > > 0x80008 -> 0x555a5d85ff50 > > 0x80016 -> 0x0 > > 0xf00000 -> 0x555a5d860280 > > 0xf0000b -> 0x0 > > 0xf00012 -> 0x555a5d860110 > > 0xf0001d -> 0x0 > > > > block #000, object at 0x555a5d8603b0, 3 symbols in 0x80008..0xf0001d > > int give_me_zero(void); block object 0x555a5d85ff50, 0x80008..0x80016 section .text > > int give_me_one(void); block object 0x555a5d860110, 0xf00012..0xf0001d section .text > > int baz(void); block object 0x555a5d860280, 0xf00000..0xf0000b section .text > > block #001, object at 0x555a5d8602d0 under 0x555a5d8603b0, 1 symbols in 0x80008..0xf0001d > > typedef int int; > > block #002, object at 0x555a5d85ff50 under 0x555a5d8602d0, 0 symbols in 0x80008..0x80016, function give_me_zero > > block #003, object at 0x555a5d860280 under 0x555a5d8602d0, 0 symbols in 0xf00000..0xf0000b, function baz > > block #004, object at 0x555a5d860110 under 0x555a5d8602d0, 0 symbols in 0xf00012..0xf0001d, function give_me_one > > > > Note that despite the fact "freestanding" bar belongs to hole-2.c, the > > corresponding CU's global and static blocks start at 0x80008! Looking > > at DWARF for the second program, it looks like that the compiler (GCC 15) > > did not record the presence of "freestanding" code: > > > > <0><71>: Abbrev Number: 1 (DW_TAG_compile_unit) > > <72> DW_AT_producer : (indirect string, offset: 0): GNU C23 15.2.0 -mtune=generic -march=x86-64 -g -fasynchronous-unwind-tables > > <76> DW_AT_language : 29 (C11) > > <77> Unknown AT value: 90: 3 > > <78> Unknown AT value: 91: 0x31647 > > <7c> DW_AT_name : (indirect line string, offset: 0x2d): hole-2.c > > <80> DW_AT_comp_dir : (indirect line string, offset: 0): test_programs > > <84> DW_AT_ranges : 0xc > > <88> DW_AT_low_pc : 0 > > <90> DW_AT_stmt_list : 0x51 > > > > and corresponding part of .debug_aranges: > > > > Length: 76 > > Version: 2 > > Offset into .debug_info: 0x65 > > Pointer Size: 8 > > Segment Size: 0 > > > > Address Length > > 0000000000f00000 000000000000000b > > 0000000000f00012 000000000000000b > > 0000000000080008 000000000000000e > > 0000000000000000 0000000000000000 > > > > Thiago suggested to use minsymbols to tell whether or a CU contains > > given address. I do not think this would work reliably as minsymbols do > > no know to which CU they belong. In slightly more complicated case of > > interleaved CUs it does not seem to be possible to tell for sure to which > > one a given minsymbol belongs. > > > > Moreover, Tom suggested that the comment in find_compunit_symtab_for_pc_sect > > (which led to cc1fc6af4) may be outdated [2]. > > > > Given all that, I'm just reverting the change. > > > > [1]: https://sourceware.org/bugzilla/show_bug.cgi?id=33679#c13 > > [2]: https://inbox.sourceware.org/gdb-patches/87cy6xzd3j.fsf@tromey.com > > > > Approved-By: Tom Tromey <tom@tromey.com> > > Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=33679 > > --- > > gdb/block-selftests.c | 15 ++++++++++----- > > gdb/block.c | 29 +---------------------------- > > 2 files changed, 11 insertions(+), 33 deletions(-) > > > > diff --git a/gdb/block-selftests.c b/gdb/block-selftests.c > > index f5883f18660..19e2a6d8db3 100644 > > --- a/gdb/block-selftests.c > > +++ b/gdb/block-selftests.c > > @@ -100,13 +100,18 @@ test_blockvector_lookup_contains () > > SELF_CHECK (bv->contains (0x1500) == true); > > > > /* Test address falling into a "hole". If BV has an address map, > > - lookup () returns nullptr. If not, lookup () return static block. > > - contains() returns false in both cases. */ > > + lookup () returns nullptr and contains (). returns false. If not, > > + lookup () return static block and contains() returns true. */ > > if (with_map) > > - SELF_CHECK (bv->lookup (0x2500) == nullptr); > > + { > > + SELF_CHECK (bv->lookup (0x2500) == nullptr); > > + SELF_CHECK (bv->contains (0x2500) == false); > > + } > > else > > - SELF_CHECK (bv->lookup (0x2500) == bv->block (STATIC_BLOCK)); > > - SELF_CHECK (bv->contains (0x2500) == false); > > + { > > + SELF_CHECK (bv->lookup (0x2500) == bv->block (STATIC_BLOCK)); > > + SELF_CHECK (bv->contains (0x2500) == true); > > + } > > > > /* Test address falling into a block above the "hole". */ > > SELF_CHECK (bv->lookup (0x3500) == bv->block (3)); > > diff --git a/gdb/block.c b/gdb/block.c > > index 3d2c51cc554..e21580bcf63 100644 > > --- a/gdb/block.c > > +++ b/gdb/block.c > > @@ -864,34 +864,7 @@ blockvector::lookup (CORE_ADDR addr) const > > bool > > blockvector::contains (CORE_ADDR addr) const > > { > > - auto b = lookup (addr); > > - if (b == nullptr) > > - return false; > > - > > - /* Handle the case that the blockvector has no address map but still has > > - "holes". For example, consider the following blockvector: > > - > > - B0 0x1000 - 0x4000 (global block) > > - B1 0x1000 - 0x4000 (static block) > > - B3 0x1000 - 0x2000 > > - (hole) > > - B4 0x3000 - 0x4000 > > - > > - In this case, the above blockvector does not contain address 0x2500 but > > - lookup (0x2500) would return the blockvector's static block. > > - > > - So here we check if the returned block is a static block and if yes, still > > - return false. However, if the blockvector contains no blocks other than > > - the global and static blocks and ADDR falls into the static block, > > - conservatively return true. > > - > > - See comment in find_compunit_symtab_for_pc_sect, symtab.c. > > - > > - Also, note that if the blockvector in the above example would contain > > - an address map, then lookup (0x2500) would return NULL instead of > > - the static block. > > - */ > > - return b != static_block () || num_blocks () == 2; > > + return lookup (addr) != nullptr; > > } > > > > /* See block.h. */
diff --git a/gdb/block-selftests.c b/gdb/block-selftests.c index f5883f18660..19e2a6d8db3 100644 --- a/gdb/block-selftests.c +++ b/gdb/block-selftests.c @@ -100,13 +100,18 @@ test_blockvector_lookup_contains () SELF_CHECK (bv->contains (0x1500) == true); /* Test address falling into a "hole". If BV has an address map, - lookup () returns nullptr. If not, lookup () return static block. - contains() returns false in both cases. */ + lookup () returns nullptr and contains (). returns false. If not, + lookup () return static block and contains() returns true. */ if (with_map) - SELF_CHECK (bv->lookup (0x2500) == nullptr); + { + SELF_CHECK (bv->lookup (0x2500) == nullptr); + SELF_CHECK (bv->contains (0x2500) == false); + } else - SELF_CHECK (bv->lookup (0x2500) == bv->block (STATIC_BLOCK)); - SELF_CHECK (bv->contains (0x2500) == false); + { + SELF_CHECK (bv->lookup (0x2500) == bv->block (STATIC_BLOCK)); + SELF_CHECK (bv->contains (0x2500) == true); + } /* Test address falling into a block above the "hole". */ SELF_CHECK (bv->lookup (0x3500) == bv->block (3)); diff --git a/gdb/block.c b/gdb/block.c index 3d2c51cc554..e21580bcf63 100644 --- a/gdb/block.c +++ b/gdb/block.c @@ -864,34 +864,7 @@ blockvector::lookup (CORE_ADDR addr) const bool blockvector::contains (CORE_ADDR addr) const { - auto b = lookup (addr); - if (b == nullptr) - return false; - - /* Handle the case that the blockvector has no address map but still has - "holes". For example, consider the following blockvector: - - B0 0x1000 - 0x4000 (global block) - B1 0x1000 - 0x4000 (static block) - B3 0x1000 - 0x2000 - (hole) - B4 0x3000 - 0x4000 - - In this case, the above blockvector does not contain address 0x2500 but - lookup (0x2500) would return the blockvector's static block. - - So here we check if the returned block is a static block and if yes, still - return false. However, if the blockvector contains no blocks other than - the global and static blocks and ADDR falls into the static block, - conservatively return true. - - See comment in find_compunit_symtab_for_pc_sect, symtab.c. - - Also, note that if the blockvector in the above example would contain - an address map, then lookup (0x2500) would return NULL instead of - the static block. - */ - return b != static_block () || num_blocks () == 2; + return lookup (addr) != nullptr; } /* See block.h. */