From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from NAM11-DM6-obe.outbound.protection.outlook.com (mail-dm6nam11olkn2066.outbound.protection.outlook.com [40.92.19.66]) by sourceware.org (Postfix) with ESMTPS id 95FB43858D20 for ; Wed, 1 May 2024 05:07:55 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 95FB43858D20 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=maskray.me Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=maskray.me ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 95FB43858D20 Authentication-Results: server2.sourceware.org; arc=pass smtp.remote-ip=40.92.19.66 ARC-Seal: i=2; a=rsa-sha256; d=sourceware.org; s=key; t=1714540077; cv=pass; b=UqTki9qrEKAb0sCeBQewl9wuiCawLYP0rbWKNc10qYHbW1Q9IWaupPeK20smEirasBXLNZ1u9CYShE830FarBp7LV8ysNgnEQ+t+OqyVrhm/9642cY42DBeqhkjHH4B6S2drbmZMtSkcM07mZgyq0JROlRVgZ+HmzWcTG3kHx8s= ARC-Message-Signature: i=2; a=rsa-sha256; d=sourceware.org; s=key; t=1714540077; c=relaxed/simple; bh=xFw55JBmedT2u2Xanq1dYWBnxdN4Al0+Sm8kdPhD8O8=; h=From:Date:Message-ID:Subject:To:MIME-Version; b=qdF9FjcivY6Ify2byAZlqtEkG3sOLHjSvf1EiRTV87Wl6VPriTAW17pXTdI9HCMQdDNtLPknpqfxu2UxFuS2fAMeYLiYZ7QMtK98uzq9t+XX0524P2VQzXlpjdKLuoidVTTxq/wBxBOaU4OztE8jBJPjg3Vakn3a3u9iUukxiQE= ARC-Authentication-Results: i=2; server2.sourceware.org ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=TVKgxl18dUXakJR1Sq++opiNYmQ7yKfgDEr53kHAXshmwzkROwGdu1KBCwAwVpaxftGtYxoddD6+JjT7K4LKP6JIpu5vDGyfattVH1svU/75HSVU2xFhJ44RnarFseWlX7rof1cy0XGGU3Fdek6rPj/0Y8DAhXJty/h2wFK2X2csaTQGfZrw7dUxBQ0CJUY7Hzxk0O2Q8I1hnpGaO1L0AMOtlvOdqWLRI437l7DrHacF5X+2bLZ0ntp9SU4iy7JZoP91UZqGNl3jj84gnnOPwVd9j2t5NHOLREpfeNA1gGubmyLylC2UyfrLY+Lx467C0ja4losy5yMhDAldvQSwsA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=7eUvxYdHdvrdFZ71OFhT2JmHyJQL+RA8YFjXKXTXFvw=; b=IHcvMAKoe1B8tumcMKTvd4KfjxPSbtkAR7Xn1ijO++nzDKv9FkBg1XbHNURCLlSs1qk6I+wvQSM4yuvpw1t5DFfzaULavP0ExXhRJuJm6W8Q1W9XROAzBXESOPsJmZeMoaXTfIgsjQv7db599zshl0tksOf+zI3kova8DUQS28S31xDcIRPq47jQvcRG24vMZLEXGYc0WLGGm1KyH0i77v1fd2S2Tm5iJmiDLRdfYZW9rfS8ZRNVBePqhmx+UPHba4fgKbIQk+q9T+hP66VENLGfif7JZyVlf2WifvRT3izC8a/7tHZtufpdo9kQPIITUK1ed10IexB4ZWakQ/Xctw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none Received: from DS7PR12MB5765.namprd12.prod.outlook.com (2603:10b6:8:74::19) by SN7PR12MB7810.namprd12.prod.outlook.com (2603:10b6:806:34c::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7519.34; Wed, 1 May 2024 05:07:53 +0000 Received: from DS7PR12MB5765.namprd12.prod.outlook.com ([fe80::3f49:9f92:3fcd:e374]) by DS7PR12MB5765.namprd12.prod.outlook.com ([fe80::3f49:9f92:3fcd:e374%3]) with mapi id 15.20.7519.031; Wed, 1 May 2024 05:07:53 +0000 X-Forwarded-Encrypted: i=1; AJvYcCWcQSDlCnAzGIqnPXbw5KA0Gowj8v6wxeKl1X5otL9CMGCXqyqL0fBSK/skwgRhTA0Ic5W1o4RfXu0gwHLPdsTOXDxbya0vng== X-Gm-Message-State: AOJu0Yz5BmOAOLTSvsUrh5Ono73P9Zg2z+XgI65hm4aMr670pFbVFTQF KkMBmSLU0FIzk2G1QzPtlzbZR1P+fhOhxZh99CAPbXM7EnSTlkIpjahim8YP6Rv/OuCLNjI006N F34+VnZrVjU1tQa3NA2+r22rJ8Ns= X-Google-Smtp-Source: AGHT+IG4I+TZGRPsTBkj9HKc203e8XdnCpeYJAQoovmosq8aRgAChJp2lWZ+XhcdEN+jnEhgEeUABd/CkLM2Ux9fxO8= X-Received: by 2002:a05:6122:30a5:b0:4da:a9d8:f719 with SMTP id cd37-20020a05612230a500b004daa9d8f719mr2000463vkb.4.1714540071861; Tue, 30 Apr 2024 22:07:51 -0700 (PDT) References: In-Reply-To: From: Fangrui Song Date: Tue, 30 Apr 2024 22:07:41 -0700 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [RFC] ANY linker script syntax for non-contiguous regions To: Daniel Thornburgh Cc: Roland McGrath , binutils@sourceware.org, Christophe Lyon , Nick Clifton Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-TMN: [aAjC3NSS1NLm/n7b2QC+BU7oBWiLff6K] X-ClientProxiedBy: BN9PR03CA0055.namprd03.prod.outlook.com (2603:10b6:408:fb::30) To DS7PR12MB5765.namprd12.prod.outlook.com (2603:10b6:8:74::19) X-Microsoft-Original-Message-ID: MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DS7PR12MB5765:EE_|SN7PR12MB7810:EE_ X-MS-Office365-Filtering-Correlation-Id: bb23d1f2-0738-461a-7119-08dc699ca7b2 X-Microsoft-Antispam: BCL:0;ARA:14566002|461199019|1602099003|3412199016|440099019; X-Microsoft-Antispam-Message-Info: vz/kFXiU9I1qbfwyzNwqy+vUeBqZNSSfZCTBErEhdwpleTeiIfqGph1J5PYQnK1ZBrjXxj++BIrOa7gdoZWRSNDcCsopEF+EiYFOoKfbg5HxNfydoJ+1xmGODs4/7nNjC0qnLglppOqCOhSpr3MJBaOD3axqti17hIk1ZEpuOG5JlAICeBPSRTlEkDPmOLav41KIDu/ZiMVydT/YN7iPPjrfNrE/avkr3ICycp/EZGon97kl+o2JArNTbDghxndZrFg/NTxvhKfTNPQVoTDXasMO0Oi30PSt3tVUArz7IUHpLLQc7SurVq2lyIVrYzV9VlcVjKCKqzLLsvOW9TeZBfBcXAE3XPxcVa67vDmZwYyGHZvYdID+GGYr+rVIH2dAL7GC/6ZBFoe3J+1FV1OJEIaXMakOWwu130ybZWq7LFrpcrCnvdHSOLL1hP1Ha821kUliqnYm3/o8Fm4XkCwMv9nQWol7Cobr4oEdscdZqKBrjx/ijl8YPWjthxOAMLbrDTW7H2rwoNcLBFEsO2tPJGlF24IKMAb9KT0dUkqVbkNYxQHh6n4TPCKJEXda6+tJxaEQDYPAeW6X6huUtKCAhKzZBqCuJg00tBXGI+4eKNmqZzoWwEPyfBvhBJcaTobgZ50ZWKauLFnKMgMJSZdG4D9J5SvTE634SkAby39+Vi+jeEOMfXNud2WU+mlHg+fD2QnZ75dbvYzhX+Uqa5qybQ== X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?B?TXVJQXhPSnZUaVJ4a0JTNVFXQmhTczZwV2lKYzNsbkVDd2NPZnZSZmh6QkdW?= =?utf-8?B?Vmc1N2ZZK3hsWnRHNGZ3NVg5eVpMRkxsRW41ejRaU0FOS1hWbXpLVzRzN1dE?= =?utf-8?B?NFlEVmtrSzA0TGV0MjNKTEROd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9pQXBhajVPei9jRXBPQUpXaldnQ0N3NHUyUW4wUm9qOTJFTnhIeW9x?= =?utf-8?B?cnpCVVpJU204WWU5N3VYYm9lZUNpVjQvRjhISlVSbTNTc1p4YjdmSWFSYXdt?= =?utf-8?B?Vm8rRW5jRENBcnlGY05vZnBHMENXZTV5M283RWxQaFJYaHNuLzhBRk54ZEVM?= =?utf-8?B?ZW8yTEU0dDdVa1l0Q3JweE5tODlKb0lMWmw3emFtNzhiRzFRMUtmRnFxQmt4?= =?utf-8?B?UzN4MDViWUdKbFYzNnNEaEROWTc5Nm5vcmdLWnIwdjZMYm5BR0FZbTdrWDBO?= =?utf-8?B?T3MxTm9seXRSS0dUWHozOTYxWkQyRlVpQWZLMXRyazJFN2hCYjVCeC9TVXV3?= =?utf-8?B?Z1lNYUQ4SGljRXVtaGdmYmJZTjN5NTIzeCsrdFVSZVpoOW5pUVJvMTd0K3M5?= =?utf-8?B?cE55dGZKT1Z3NTFZazRUMC9Dc2VYd2RnK1NDUEEyMnZzSlptMkhDT2IzeXZ6?= =?utf-8?B?VEVaRVREbktpTU5vK01yaXU1eEpFTG0yeXZSUjc2L2M4OWlOQUJPZ0RnbTVX?= =?utf-8?B?YzFQYlp6cWEzbS84K0F6U0xZWDh0NFFNT0xQWW11SzgxaDhGRWY4MnlpSWxS?= =?utf-8?B?cEs0NlJiL3R1TTNsaUN1L2VhNU9hU1E9PQ==?= X-OriginatorOrg: sct-15-20-4755-11-msonline-outlook-71ea3.templateTenant X-MS-Exchange-CrossTenant-Network-Message-Id: bb23d1f2-0738-461a-7119-08dc699ca7b2 X-MS-Exchange-CrossTenant-AuthSource: DS7PR12MB5765.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 01 May 2024 05:07:53.2000 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-CrossTenant-RMS-PersistedConsumerOrg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN7PR12MB7810 X-Spam-Status: No, score=-2.7 required=5.0 tests=BAYES_00,KAM_DMARC_STATUS,KAM_INFOUSMEBIZ,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_PASS,SPF_PASS,TXREP autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: On Wed, Feb 7, 2024 at 3:23=E2=80=AFPM Daniel Thornburgh wrote: > > One more tack on: maybe just CLASS instead of SECTION_CLASS for the name.= .. it's only legal within SECTIONS {}, and none of the other things within = contain the word SECTION. > > On Wed, Feb 7, 2024 at 2:36=E2=80=AFPM Daniel Thornburgh wrote: >> >> This is interesting; I hadn't thought of breaking out tagging into its o= wn construct. I do like the name SECTION_CLASS; it makes it clear that elem= ents from that section could be placed there, and the only plausible meanin= g for multiple references to the same class would be to allow them to spill= . >> >> This also slightly increases the power of regular matching, since you co= uld catch a group of sections earlier in a linker script and place them lat= er, perhaps to avoid a broad wildcard needed for output sections that shoul= d appear earlier in a memory region. >> >> E.g. >> ``` >> SECTIONS { >> SECTION_CLASS(specific) { *(.specific) } >> .first_output { *(*) } >m1 >> .second_output { SECTION_CLASS(specific) } >m1 >> } >> ``` >> >> On the down side, it would make it harder to port existing linker script= s. To spill a wildcard match inside an output section with strong ordering = requirements, you would need to define classes for anything that precedes i= t. >> >> Without spilling: >> ``` >> SECTIONS { >> .foo { >> *(.foo.first.*) >> . =3D . < 0xc000 ? 0xc000 : .; /* or something similarly horrible = */ >> *(.foo.second.*) >> >> /* Excludes .foo.first.* and .foo.second.* by virtue of ordering */ >> *(.foo.*) >> }>m1 >> } >> ``` >> >> With spilling: >> ```SECTIONS { >> /* A whole collection now needs to be broken out of the output section= to preserve its semantics */ >> SECTION_CLASS(foo_first) { *(.foo.first.*) } >> SECTION_CLASS(foo_second) { *(.foo.second.*) } >> /* If only this section class were defined, then it would unintentiona= lly capture .foo.first and .foo.second */ >> SECTION_CLASS(foo_rest) { *(.foo.*) } >> >> .foo { >> SECTION_CLASS(foo_first) >> . =3D . < 0xc000 ? 0xc000 : .; >> SECTION_CLASS(foo_second) >> SECTION_CLASS(foo_rest) >> }>m1 >> .foo_alt { >> /* foo_rest is the only desirable spill, but it forces sweeping cha= nges to the linker script */ >> SECTION_CLASS(foo_rest) >> }>m2 >> } >> ``` >> >> Progressive enhancement of existing scripts is essential for this to be = useful in practice. As far as I can see, since linker script semantics are = so imperative, that requires section classes to be nameable in the same pla= ce as existing wildcards. That being said, as mentioned earlier, naming out= side output sections also adds power, so it might be useful too, but it see= ms like it would need to be judged on merit of the extra power added. >> >> On Tue, Feb 6, 2024 at 4:33=E2=80=AFPM Roland McGrath wrote: >>> >>> ``` >>> SECTIONS { >>> >>> >>> >>> /* New syntax that is not an output section clause: */ >>> SECTION_CLASS(class1) { *(.input2) } >>> >>> /* Output section clause referring to SECTION_CLASS: */ >>> .output2 { >>> *(.input3) /* normal section wildcard */ >>> >>> SECTION_CLASS(class1) /* reference to previously defined class */ >>> >>> *(.input4) /* normal section wildcard */ >>> } >>> .output4 { >>> /* reference to remainder not in .output[23], sorting applied to th= em */ >>> SORT_BY_NAME(SECTION_CLASS(class1)) >>> } >>> } >>> ``` >>> >>> Where they do appear, they can appear inside the SORT_* to have that >>> sorting applied to the subset. I'm not sure it's actually meaningful t= o >>> select a subset and then sort within that subset, so perhaps it would b= e >>> better to only support the SORT_* modifiers in the usual way on the inp= ut >>> section wildcards in the defining `SECTION_CLASS` clause, and then ever= y >>> reference has to always just draw in order from that sorted list. >> >> >> I would expect SECTION_CLASS uses in output sections to be referentially= transparent with the exception of the packing behavior and the ordering of= section "consumption". They should broadly behave as if the named wildcard= s had actually appeared in order in the corresponding location; that should= allow providing a set of allowed and disallowed SORT_x family specificatio= ns to match the current behavior. That would support using SECTION_CLASS to= break out an existing wildcard to run it earlier, since it would provide s= ome assurance that this wouldn't change the behavior beyond that which was = intended. The "CLASS" syntax is useful. I've filed a feature request: https://sourceware.org/bugzilla/show_bug.cgi?id=3D31688 ("ld: Add CLASS to allow separate section matching and referring")