Some argument for including CRC support in the linker. ============ The AUTOSAR organisation publishes requirement for developing code for the Automotive industry. Protecting your code with a CRC is mandatory, and the chosen algorithm is CRC64 ECMA. https://www.autosar.org/fileadmin/standards/classic/19-11/AUTOSAR_SWS_CRCLibrary.pdf Large companies like Texas Instruments put hardware into their microcontrollers for safetly critical operations liḱe the TMS570LC4375. https://www.ti.com/lit/pdf/spnu563 This is a big thing in embedded (non-linux/windows control) so I think that it is safe to say that people will be interested in simplifying their development by creating the CRC inside the linker. ============ That it is important also for Aviation is shown in this presentation: https://users.ece.cmu.edu/~koopman/pubs/KoopmanCRCWebinar9May2012.pdf ============ TÜV are very important in "Functional Safety". https://www.tuvsud.com/en/services/functional-safety/top-misunderstandings-about-functional-safety "Some integrity/diagnostic measures are performed at each startup of the system (e.g. RAM test, *Flash CRC check*, output tests, etc.). *These tests are very important*, as they are e.g. used for argumentation on diagnostic measures, or for fault detection time (test interval) in the safety analysis. However, sometime the operation condition can change (new project, new requirements, etc.). Systems which were regularly powered-down, stay powered-up for longer time. For example, modern rail systems are nowadays often continuously powered-on, without re-start every morning. In such cases the intended diagnostic measures will not become effective. If needed by the safety analysis, regular re-start shall be therefore explicitly specified in the safety manual, operator documentation, etc. You cannot get a Functional Safety device qualified, if the firmware is not protected by a CRC. The Microcontroller will run the bootloader, which will first perform a CRC check on itself, and then before an application image is started, the CRC check will pass. ============ So there is a significant part of the embedded industry that relies on CRC calculations for ensuring that their systems are not broken. What is important here is the "Hamming distance" which measures the quality of detection. The width of the CRC needs to grow as the program size grows. Best Regards Ulf Samuelsson Den 2023-02-15 kl. 21:07, skrev Ulf Samuelsson via Binutils: > CRC calculation in the linker > >> Actually -- there might be a way to do this: A linker plugin.  The >> linker already >> has the architecture to support plugins, and you could create a new >> one which would >> scan the text section, compute a CRC and then insert the value into a >> header in the >> linked image... > > There is a CRC library available from a guy named Lammert Bies > > This is released under an MIT license. > > /* >  * Library: libcrc >  * File:    src/crc64.c >  * Author:  Lammert Bies >  * >  * This file is licensed under the MIT License as stated below >  * >  * Copyright (c) 2016 Lammert Bies >  * >  * Permission is hereby granted, free of charge, to any person > obtaining a copy >  * of this software and associated documentation files (the > "Software"), to deal >  * in the Software without restriction, including without limitation > the rights >  * to use, copy, modify, merge, publish, distribute, sublicense, > and/or sell >  * copies of the Software, and to permit persons to whom the Software is >  * furnished to do so, subject to the following conditions: >  * >  * The above copyright notice and this permission notice shall be > included in all >  * copies or substantial portions of the Software. >  * >  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, > EXPRESS OR >  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF > MERCHANTABILITY, >  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT > SHALL THE >  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER >  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, > ARISING FROM, >  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER > DEALINGS IN THE >  * SOFTWARE. >  * >  * Description >  * ----------- >  * The source file src/crc64.c contains the routines which are needed to >  * calculate a 64 bit CRC value of a sequence of bytes. >  */ > > > The library supports a variety of CRC algorithms, but only 64-bit CRC > is needed here. > > The two enclosed files are (with minor modifications) all that are > needed. > > When you encounter a CRC, you generate a table based on a polynom.. > > ECMA:    0x42F0E1EBA9EA3693ull > ISO:        0xD800000000000000ull > custom: > > > | CRC64 ISO ' (' mustbe_exp ',' mustbe_exp ')' >           { >                      init_crc64_tab(0xD800000000000000ull) >                      ecc_start = $4; >                      ecc_end  = $6; >           } > > | CRC64 ECMA ' (' mustbe_exp ',' mustbe_exp ')' >           { >                      init_crc64_tab(0x42F0E1EBA9EA3693ull); >                      ecc_start = $4; >                      ecc_end  = $6; >           } > | CRC64 POLY '[' mustbe_exp ']' '(' mustbe_exp ',' mustbe_exp ')' >           { >                      init_crc64_tab($4); >                      ecc_start = $7; >                      ecc_end  = $9; >           } > > When it is time to calculate the CRC you either call crc_64 or crc_64_inv > on the area you specified in the CRC64 directive. > > The question is if a plugin is the right way or just add it to the > normal build. > > The code is well known, and very unlikely to change. > >> Cheers >>   Nick >> >>