From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from NAM04-DM6-obe.outbound.protection.outlook.com (mail-dm6nam04olkn2096.outbound.protection.outlook.com [40.92.45.96]) by sourceware.org (Postfix) with ESMTPS id B13CB3858D20 for ; Sat, 10 Feb 2024 06:40:37 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org B13CB3858D20 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 B13CB3858D20 Authentication-Results: server2.sourceware.org; arc=pass smtp.remote-ip=40.92.45.96 ARC-Seal: i=2; a=rsa-sha256; d=sourceware.org; s=key; t=1707547239; cv=pass; b=My7+sBpJuc2FcQrHjtywhI6vtEoglrRrMfFOJ1Q1FDaknTGibaoQyNTTgrJVtxpufe21y9L7T2ofLuQnZ9BoWCn8hD1iU7R4wF5jGFlES6/MtSiXnARepQDW3VPjOy59O5WHjmTwMjJZnD4fh34DZSHrxzu40qSnCItNh6Fk6sg= ARC-Message-Signature: i=2; a=rsa-sha256; d=sourceware.org; s=key; t=1707547239; c=relaxed/simple; bh=G5s+tP9U2NeWfuXeNpoQs0omZn1VkBT05c19P+V3gvY=; h=From:Date:Message-ID:Subject:To:MIME-Version; b=v4T/G9+KcHlqdcuPCcpp2eazTmsV4FCsL/UMtuedQ+/CaD0fz6HbgnLuHfVMtrrz2EmNPzBdcusmSmIYktVU1jKY70kv5G42VnSgpDDm8bmqz7c7a65m90EF0td2X2Oe48/if4sVOzAVH7lAGG3C0850c3RNdvcjnoiygw+2T70= ARC-Authentication-Results: i=2; server2.sourceware.org ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=anWbmR94U8bQoM6vOLebOHpTTA0fQYxykmYOclawzRpsDTkquwveEDSQ3uRQKx7vOww0Vt2kvntKfL3oM6dSrdBs3rBWJUS2a5YY/HFC3PYvcIjXXibWNbQrvY5t58dpYxnxQk0eEygfUQFJcI3Rhf6i11TCtNpZeKxmuQM2fiHOCzELcHxTCCwGMm9SnyU6nDnA7VAG/FCOoZk/KS9de7T/ylY9+H/r5+g7uRFoneg2pFijdilzZN8iqyhiuxsrbEUzBprSJIcQqtvqAgLdHh6r2/T83ezHspt36ABNRgp6TuTv9th7+OMNdZldD/WjJt+4bGuIBEnZsYpkCRvy8g== 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=+CKcq6h/Mi1KbY5XuTXgrFPRVMLSy6IUpyTbSdlUx9I=; b=aW2fEG6Z9zYY/4MniajOlyja8/vF2zcwRkovYGf37gFuv7UbzLXGeu2MUunF+pBYp1KCNppV1awc3o8KkrDtbWMr6cC21jV4HyN2Iz13EFHtK0snuJ7vsEpNwk2YMmOrxFvhUCJgh2HjdluZezFleaNI9i0NUJWLIdpBHPLLushj+aXHsyIVyERP7IxJPIn4UNcCvIm5SDH4Fyq4IaFaA53fNx4IkA2CrpAxr2Nu/3iLat6emLpXY2YTJMFGKGt0NdxAquBut3fA0jwe/+lLoHvArVZRyUC0W3Q1Xwdh9n6zOMV/Up+VNu1zryLWW/X3lDtjkEVzAaaQTRVkhNun6A== 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 DM4PR12MB5987.namprd12.prod.outlook.com (2603:10b6:8:6a::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7270.14; Sat, 10 Feb 2024 06:40:35 +0000 Received: from DS7PR12MB5765.namprd12.prod.outlook.com ([fe80::fa25:6d58:7ae9:9c0b]) by DS7PR12MB5765.namprd12.prod.outlook.com ([fe80::fa25:6d58:7ae9:9c0b%5]) with mapi id 15.20.7270.010; Sat, 10 Feb 2024 06:40:35 +0000 X-Forwarded-Encrypted: i=1; AJvYcCXdoixfJagl+ObJsy6Rqm8lrugn3hX9nEzuXvrsO16DjLP8cwDgH3/x5rsyf8nOzqEY9yBMR4UWtO+rYYd05pZOuc32nb/vqA== X-Gm-Message-State: AOJu0Yy81VbEP6uvlyjNaDkPsTT6U1ZeJPn7uTbyutK9amG4WsUOmam7 DgIDHdry7fjHNLAjXAYEQ/mihuQBRf2JeYkJBFkfiF6JA6zfoIT3GvePmUlc7bsPyKNbvP+fql0 GAMchy2vG0zhcGG60OYpwcYJtlPo= X-Google-Smtp-Source: AGHT+IExh8RREcQm480IEIA6n/q7C5VVOzUr+Bt1cOVXPD3RukYPt9ve4om+zzKXvDvhFFXJs3ouCxZ1YO/7puOM5OE= X-Received: by 2002:a05:6102:91:b0:46d:afa:f07 with SMTP id t17-20020a056102009100b0046d0afa0f07mr1365815vsp.10.1707546826581; Fri, 09 Feb 2024 22:33:46 -0800 (PST) References: In-Reply-To: From: Fangrui Song Date: Fri, 9 Feb 2024 22:33:35 -0800 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [RFC] ANY linker script syntax for non-contiguous regions To: Christophe Lyon Cc: Daniel Thornburgh , Roland McGrath , binutils@sourceware.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-TMN: [HAVMOGFSlZ+dnHFQ70W61ImjMH3ozQqr] X-ClientProxiedBy: BLAPR05CA0010.namprd05.prod.outlook.com (2603:10b6:208:36e::19) 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_|DM4PR12MB5987:EE_ X-MS-Office365-Filtering-Correlation-Id: b49127a5-64ab-4b6d-3d16-08dc2a032f4c X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: QBKOcV/c2r5mffNmryTGyPUZH5H/FC9a9gY1GhWa28uEnJrY+s/QC29rdkntcWcOBvh4gE9kV1bD12xA1hoSrihlIkjD+6LHYbSGMCSgK6FGCsZmBOKBjdeVoZlPN6zchKCWuCOhz4nsMTNvIdRJ1HLSMt9SrAHj6YR0hJ0c5CCZ0AH49RU0JdIzp39HA8mziZZP5OKDsAZdOoZqcyyvzIOOPXkrJe7GTyapJVAPB/8W+ZObULPu2Fmxm8Q0opd/V57EtvsR3VvDr/G3am8EBkyiG27l25sZQXDodq2mI12SRTlNk0Hl4HQ0KgxrDMCrCh/A1b89L7Dm60fAaC8Buo4mxPw3ZtRR/lYPJPb2MdKZwRhGq7ljpafKHHfU7jiP2PaXTfSbwXqHkaKcbZanbHniFENKff3nb6hvKlGOWTV9Ds0qud34Geygj7RgXY07eRr121ZhqIjv/SWL/D5BgpnPfbNvke05ZZ5LObLQl+/6v8zcg4bfvxJUbLwep3yexU7ZImDJwFpeNdgTYaXEnGXsSCrEOAe02d0rfqJi7K+ZQoUw+CoA4HDcMx8BumXl X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?B?NG5vN0ZxdzE4V0hjWlZLRVpXRDN5RzNuWHdEb3YwNWdjQXZtbDA1VWNZQUE0?= =?utf-8?B?M0ZHU1ZUcmJrWTUyWUo3bjVuZTEzQ2JHUVI3Y0N2UUN0a29WbUlnd0NyMHc3?= =?utf-8?B?T3JNNFJUOG1oaFdzWld3YjF6WmZtVWVJQmthZlFRLzZiWGt3NktkdElrY1Fm?= =?utf-8?B?UXViUm01eU1icTJxK2syVnIxRmNRc1Frdm5TVVdXVXlKQ3l0QmFtMmpoeERl?= =?utf-8?B?SEtVSUIzNjJkQ1dlbW5xOElUUStSOWVyVGkvZUFPelQ0eWpn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NmFEWHRzb2ty?= =?utf-8?B?QjY4aHFaaWN1YkwrQXBQUjB0cGFMMi9oT3pOYi9LYlJkTHB0MkpySHFKVmpU?= =?utf-8?B?SzFuVU5FQTNsME03QVlndnNQWDQ5SGpDQnlWc0k5WS8xcW9QUEJIdWNMSnhn?= =?utf-8?B?NGVYckVaWWVTdU9qSjVjbVVvRm1SdzRXS0U0YjVlc0xiV20wZnM0cEVCUUdM?= =?utf-8?B?UHhxR1ZrZmpuUVE4VnJYbEJGTnZ4ZGppREE1dWlLaEI4bDBqSXc1SXFwQ2JY?= =?utf-8?B?eStWdldJcVpNVHJoU2U5dTBPbkQveVpTUEc3MklKaCtxemJ2dm9EYzRrVFpw?= =?utf-8?B?OGVKanJtSDArZjFlaXpEN2QrTlhyVW9pMjhzaHlRODFnK01Qekl2bExrRnpo?= =?utf-8?B?TkkxVE1URHhSSmRvMkg0eHhwekxSbDJrVEhzTWozWmdxSEZZY3M5T3lmK2xj?= =?utf-8?B?bHNNTFdudDcxUVhTcnpmSnB6dVBUQkE9PQ==?= X-OriginatorOrg: sct-15-20-4755-11-msonline-outlook-5183d.templateTenant X-MS-Exchange-CrossTenant-Network-Message-Id: b49127a5-64ab-4b6d-3d16-08dc2a032f4c X-MS-Exchange-CrossTenant-AuthSource: DS7PR12MB5765.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 10 Feb 2024 06:40:34.9356 (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: DM4PR12MB5987 X-Spam-Status: No, score=-2.6 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,T_SCC_BODY_TEXT_LINE 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: +Christophe 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. >> >> -- >> >> Daniel Thornburgh | dthorn@google.com >> > > > -- > > Daniel Thornburgh | dthorn@google.com >