From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from NAM10-MW2-obe.outbound.protection.outlook.com (mail-mw2nam10olkn2106.outbound.protection.outlook.com [40.92.42.106]) by sourceware.org (Postfix) with ESMTPS id 10D093858D35 for ; Mon, 6 Mar 2023 07:50:39 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 10D093858D35 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-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=LL9lexRnrK+n3jWlDboZSEtZV6gQrJmc7QHcQZcGfKd2v093QQVSE6sCRilqlOih6qJI71/8BqxlS/mLJ+AbBrX4+R1onqApj9/XVUUtNPcm2jqtXn+brpVoSVRtvnEtEnDppCkoRiVwMwjoNiLCgdaUQMtjsaHNAQ7gNF9SUTZ/fHMB3L6Sj3u9EBP9JJXkScX4IcJIUpfM1CRWjWNAeBNLaJqcYszpAfrw2QKhArkDPZewfeQQ25MY4lHPXBXSkwEM96kc5yYvlZsuD4vjJbfHJd0FLfPuNHYwvByT+Z6oRYGssYaVUbPve7xJzqalOuhdxOP1ixKTbkxN3g6LIA== 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=/SFhRW6Zgu8c3pUthWxF78yAc9RWrD+AT1EFWIb11Dk=; b=jSQyHIcQh7zRrCQ/ZRxQ7YbXss+i3YMVjgAtNrCnRf7GxCeQNX0aG1+aWkiw97MI3YuPMU6oNqBLMZaLQWtgYI35+Y4rBi0jpBlohqba77R40Mawn++GgrxdCDCEMNSHHt5FiEuLK17TXMyLq33vogJZPJ9UzpuwmRWGzE0QMA5Uks4H7UqTvoJx21k4dHhL6ezmrd7mJmpYov3Ai1QI0mcUl8YnKDj/8c6+oBtahVASz8aKgIGbJYbVSOgJPqtnBX3oU37ai4uyUpH4lw2pPBXUcD2lzHpGkr0c8SJl7KF8WB/9e+mquEnjvAQEPbmbXbGTf0MqhGwgbeu3dwGHRg== 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 PH8PR12MB7424.namprd12.prod.outlook.com (2603:10b6:510:228::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6156.28; Mon, 6 Mar 2023 07:50:36 +0000 Received: from DS7PR12MB5765.namprd12.prod.outlook.com ([fe80::b084:b37b:f2a8:78d9]) by DS7PR12MB5765.namprd12.prod.outlook.com ([fe80::b084:b37b:f2a8:78d9%2]) with mapi id 15.20.6156.028; Mon, 6 Mar 2023 07:50:36 +0000 X-Gm-Message-State: AO0yUKWkHsQwodikNeuiR1NhRZC/eBtBLZhaLfYYAas40jNdeobm5pvN KHuO/52ee0sQUNBgawwC+V/Vm/rgJfSFj6TD5MU= X-Google-Smtp-Source: AK7set+E8pyZZXuweUqmv7bWJu9hOqoIjAfB21bAr+knqH9Fu8DLSvXQONNXWGpAGQ76hNZwdv0dpPrX3gkdRcFtz2E= X-Received: by 2002:a63:7556:0:b0:503:7bbc:243c with SMTP id f22-20020a637556000000b005037bbc243cmr3452205pgn.2.1678089032618; Sun, 05 Mar 2023 23:50:32 -0800 (PST) References: <20230216204006.1977-1-binutils@emagii.com> <8c80d58c-8c43-90c9-9d0b-9a5de91c16ed@emagii.com> <328005c0-a162-764e-47ba-036dce0ecbe4@redhat.com> <8c16e149-2117-56e1-61bf-a499f05a8fb9@emagii.com> In-Reply-To: <8c16e149-2117-56e1-61bf-a499f05a8fb9@emagii.com> From: Fangrui Song Date: Sun, 5 Mar 2023 23:50:21 -0800 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [RFC v0 0/1] Add support for CRC64 generation in linker To: Ulf Samuelsson Cc: Nick Clifton , binutils@sourceware.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-TMN: [JmSXLgxRfVAmCnwyaA39nj6hz6wEOV8i] X-ClientProxiedBy: MW4PR02CA0002.namprd02.prod.outlook.com (2603:10b6:303:16d::10) 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_|PH8PR12MB7424:EE_ X-MS-Office365-Filtering-Correlation-Id: e7eeda3b-8b95-4c60-1451-08db1e1778da X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 7mjuQaCYkBslIaNhIBOMA3DHgMDmpx0roKDzg315hMfCL0l+YFZvX5bBXAwrj7MBYmvZ4348Gm6lKqaiU9oU9UGvauKcx+GnAgfUqbokCBZUimGkRs5SZph/c8FHBjvHP+XNLHTpc51H7BTEiZaVCSw2Z86CXWwe4CoJZ97QMt3PP98kxjQuzNfDVOFDmDBeq5tF1GKSqL7Oa3iuIqoIyDEz7HiqboqyejP3vV52OsXzc2R0SP+KOTWsrxD+kiw/kZYYTPMiEwklkCOYUMgqmIEL0raTk7c28oypt5nbSVGdFXpr95CzsUmc9YG+wkDbZ7U0otUrOggirDdH2vmyThbJ8OPCFpCanVeWLruIeO0z6IAHz9874LoMCArsyCyhfGM3l9ylNp+tj/3hLs3Ckjmkg+6tWGezurBN918WhwQxRD6AitjTC76HNGNUGMn1ZcnrmlWUR0y//LWw8qe2JqNOIRXyUexakKwGe524TfVAur7LxWC8Y4qCtfUUAchCDlYcPOxqCr4BcedkmhG/x1plPbFEA98cyqXxSZq3QYTMj/NlJ4K+bBbuBqHBroImaph/JALHMBPo1l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dZ?= =?utf-8?Q?ezTWZG4JBH8QxslQSkNn?= X-OriginatorOrg: sct-15-20-4755-11-msonline-outlook-71ea3.templateTenant X-MS-Exchange-CrossTenant-Network-Message-Id: e7eeda3b-8b95-4c60-1451-08db1e1778da X-MS-Exchange-CrossTenant-AuthSource: DS7PR12MB5765.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 06 Mar 2023 07:50:36.7445 (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: PH8PR12MB7424 X-Spam-Status: No, score=-3.1 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 Fri, Feb 17, 2023 at 4:03=E2=80=AFAM Ulf Samuelsson wrote: > > > Den 2023-02-17 kl. 12:11, skrev Nick Clifton: > > Hi Ulf, > > > >>> Hi Ulf, can you state why a built-in support of ld is needed? If you > >>> want to embed a checksum, you can use Output Section Data to reserve = a > >>> few bytes in the output, then use a post-link tool to compute the > >>> checksum and rewrite the reserved bytes. > > > >> In my experience, the post link tools usually work on the binary data > >> and not the ELF file. > > > > The objcopy program can do most of this for you though. For example: > > > > % objcopy --dump-section .text=3Dcontents-of-text a.out > > % crc32 contents-of-text > crc32-of-text > > % objcopy --add-section .crc32=3Dcrc32-of-text a.out > > % readelf -x.crc32 a.out > > Hex dump of section '.crc32': > > 0x00000000 32323064 37636339 0a 220d7cc9. > > > > In this example the crc32 is stored as ascii text, but I am sure that > > you can find a version of the crc32 program that generates binary outpu= t. > > The crc32 generates a 32-bit CRC. Modern microcontrollers require a > 64-bit CRC. > > The second problem is: where is the .crc32 section and its contents? > The program needs to access the contents, but it is already linked. > The typical use is a header in front of the program, and the header > is part of the ".text" area. > Can you explain how this would work? > > > > > > >> Another thing is that the post-link tools I have seen are typically > >> poorly maintained. > > > > ...and so you want to move that maintainership burden onto us, yes ? > > The problem with the post-link tools is that they are hard wired to work = on > special use cased. > Example of problems > > * CRC is fixed to be at a certain address > > * CRC table is fixed to be at a certain address. > > * Works on binaries and not on ELF files > > * You have to have one postprocessor for each file format. Hi Ulf, I think a natural question from other binutils contributors is: why is the CRC-64 feature so special that it deserves several keywords dedicated for it in the linker script language. You can place placeholder content into the CRC-64 section (say, it is .crc64), compute its value with a post-link program, then update the content with objcopy --update-section .crc64=3D.... exe If objcopy --update-section somehow doesn't achieve your goal, it may be worth a feature request or bug, since the operation is generic and useful for a large number of users, not just your CRC-64 customers. > None of these problems affect the linker since it is agnostic on the > file format > as long as there is a ".text" section. > > The CRC calculation has been stable on www.libcrc.com for 7 years. > There is no reason for the CRC calculation to change. > The only chance I can see is a different polynom, but that is already > supported. > > The biggest problem is of course that it slows down the debugging > because you cannot download from an ELF file - it lacks the CRC. I am unsure how a linker script extension is more convenient than using the existing functionality plus a CRC64 calculator and objcopy. The linker script extension appears to add a lot of code to the linker script language, which is already quite challenging to maintain. If you distribute such object files with CRC64, I don't think it harms debuggability. > > > > > >> Adding a post-link step seems like a kludge if the linker can provide > >> the CRC inside the ELF file. > > > > But it also keeps things simple. No new code in the linker =3D no new > > bugs in the linker. Solving a problem using existing tools =3D no need > > for new versions of the linker when the already existing versions will > > work just fine. > > The problem is that the existing versions *barely* work. > Every company have to write their own solution. > It does not support source level debugging. > > Supporting it in the linker makes for a much cleaner solution. > > > > > Cheers > > Nick > > > Best Regards > > Ulf Samuelsson > >