public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
* [PATCH v5 0/10 Add support for CRC64 generation in linker
@ 2023-02-22 16:15 binutils
  2023-02-22 16:16 ` [PATCH v5 01/10] TIMESTAMP: ldlang: process binutils
                   ` (10 more replies)
  0 siblings, 11 replies; 12+ messages in thread
From: binutils @ 2023-02-22 16:15 UTC (permalink / raw)
  To: binutils; +Cc: nickc

Fifth patchset.

+* The linker script has a new command to insert a timestamp
+  TIMESTAMP
+  inserts the current time (seconds since Epoch) as a 64-bit value
+
+* The linker script syntax has new commands for debugging a linker script
+  DEBUG ON  turns on debugging
+  DEBUG OFF turns off debugging
+
+* The linker script syntax has new commands for handling CRC-32/64 calculations
+  on the '.text' section
+  It uses code from https://www.libcrc.org/
+
+  DIGEST "CRC32"              (start, end)
+  DIGEST "CRC64-ECMA"         (start, end)
+  DIGEST "CRC64-ISO"          (start, end)
+  DIGEST "CRC64-WE"           (start, end)
+  DIGEST POLY (size, polynome)(start, end)
+  DIGEST POLYI(size, polynome)(start, end) (inversion during CRC calculation)
+  DIGEST TABLE
+  DIGEST SECTION "<section>

ran indent on the new files.

The *.d files in the testsuite was edited to 
reduce size and to remove all '(' characters.
The new linker can link using the testsuite/ld-script/*.t
linker files, but they do not pass the 'make check-ld'
test.

Fourth patchset.
Get rid of binaries in testsuite.

Here is the third patchset for introducing CRC64 generation.
This has focused on supporting maintainability of the feature.
In order to do so, CRC32 generation has been introduced to
detect issues when extending the linker with another algoritm
for checking integrity of the image.
This will simplify adding other algorithms like SHA algoritms
in the future.

In addition, the TIMESTAMP command is used to store the current time
in seconds since Epoch is stored in the image.

The main routine for calculating CRCs has been broken down
in subroutines which allow other algorithms.

An algorithm typically needs
<type> *init_<algo>_tab( <type> poly )
<type> calc_<algo>_inv( const unsigned char *input_str, size_t num_bytes );
<type> calc_<algo>    ( const unsigned char *input_str, size_t num_bytes );
void lang_add_<algo>_syndrome(bool invert, bfd_vma poly)
void lang_add_<algo>_table(void)

The common functions are:
* bool get_text_section_contents(void)
  This reads the '.text' section and its contents
  Pointers are stored in the global variables
  asection *text_section
  char     *text_contents
* bool set_crc_checksum(bfd_vma crc, bfd_vma addr, bfd_vma size)
  Stores the CRC at the index addr. The size of the CRC in bytes is specified.
  Storing something larger that 64-bit is not supported here.
* bool symbol_lookup(char *name, bfd_vma *val)
  Gets the value of a symbol into 'val'. Returns false if not found.

To add CRC32 support means adding the following commands
* CRC32 CRC32                    '(' crc_start ',' crc_end ')'
* CRC32 POLY  '[' mustbe_exp ']' '(' crc_start ',' crc_end ')'
* CRC32 POLYI '[' mustbe_exp ']' '(' crc_start ',' crc_end ')'

================
Here is the second patchset for introducing CRC64 generation in the linker
This is mainly looking at indentation and whitespace errors.
The patches applies cleanly without whitespace error
except for the last patch which contains the testsuite.
When the contents of .text is printed out, sometimes
the last byte of a line in the CRC table is a space.
This is reported as a whitespace error.

Supports the following new linker commands:
* CRC64 ECMA                     '(' crc_start ',' crc_end ')'
* CRC64 ISO                      '(' crc_start ',' crc_end ')'
* CRC64 POLY  '[' mustbe_exp ']' '(' crc_start ',' crc_end ')'
* CRC64 POLYI '[' mustbe_exp ']' '(' crc_start ',' crc_end ')'
* CRC64 TABLE

ECMA  == 0x42F0E1EBA9EA3693
ISO   == 0xD800000000000000
POLY  == Allows your own polynome
POLYI == Allows your own polynome, with inversion during calc

The CRC is calculated from crc_start to crc_end (not included)

The "CRC64 <polynome> command
* Allows specifying the polynom (ECMA(default), ISO or your own)
* Allows for inversion in the CRC calculation (CRC64-WE)
* Allows specifying the area that should be checked.
* reserves room for the CRC (8 bytes)
* Declares a symbol ___CRC64___ for the address of the CRC.
* Declares a symbol ___CRC64_START___ for the first address of the checked area
* Declares a symbol ___CRC64_END___ for the first address after the checked area

The symbols names are declared in "checksum.h".
If the names are unsuitable, it is easy to change.

The CRC TABLE command
  This is used to speed up the CRC calculation.
* Creates a 2kB table which speeds up the CRC calculation
* Can insert the 2kB table into the .text section at current location.
* Declares a symbol ___CRC64_TABLE___ if the table is inserted.

Comments on the code:

The process of calculation involves:
* Check if CRC is requested
* Validation of CRC prerequisites
* get .text section
* get .text section contents
* calculate CRC over the area
* insert the CRC in the correct location
====================================

This version also supports the
* DEBUG ON
* DEBUG OFF
turning on/off yydebug
I find it useful for debugging the build, but it can easly be removed.

This patch contains a lot of debug output, that is enabled by
#define DEBUG_CRC 1
This should be removed in the final version.

The ld.texi stuff needs some more work. Not very experienced with that.

Added an entry in NEWS

Added 4 test cases for the different CRC64 polynome commands.
All testcases generate a CRC table.

The code is using the libcrc released under an MIT license found in
* https://www.libcrc.org/
* https://github.com/lammertb/libcrc/tree/v2.0
Author:  Lammert Bies
A license for libcrc is added to the patch.

[PATCH v5 01/10] TIMESTAMP: ldlang: process
[PATCH v5 02/10] DIGEST: NEWS
[PATCH v5 03/10] DIGEST: ld.texi
[PATCH v5 04/10] LIBCRC: license
[PATCH v5 05/10] DIGEST: ldlex.l
[PATCH v5 06/10] DIGEST: ldgram.y
[PATCH v5 07/10] DIGEST: Makefile.am: add new files
[PATCH v5 08/10] DIGEST: CRC-32/64 algorithms
[PATCH v5 09/10] DIGEST: ldmain.c: add CRC calculation
[PATCH v5 10/10] DIGEST: testsuite


^ permalink raw reply	[flat|nested] 12+ messages in thread

* [PATCH v5 01/10] TIMESTAMP: ldlang: process
  2023-02-22 16:15 [PATCH v5 0/10 Add support for CRC64 generation in linker binutils
@ 2023-02-22 16:16 ` binutils
  2023-02-22 16:16 ` [PATCH v5 02/10] DIGEST: NEWS binutils
                   ` (9 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: binutils @ 2023-02-22 16:16 UTC (permalink / raw)
  To: binutils; +Cc: nickc, Ulf Samuelsson

From: Ulf Samuelsson <ulf@emagii.com>

Signed-off-by: Ulf Samuelsson <ulf@emagii.com>
---
 ld/ldlang.c | 8 ++++++++
 ld/ldlang.h | 2 ++
 2 files changed, 10 insertions(+)

diff --git a/ld/ldlang.c b/ld/ldlang.c
index 2852a4222d3..3ec89c6793b 100644
--- a/ld/ldlang.c
+++ b/ld/ldlang.c
@@ -20,6 +20,7 @@
 
 #include "sysdep.h"
 #include <limits.h>
+#include <time.h>
 #include "bfd.h"
 #include "libiberty.h"
 #include "filenames.h"
@@ -8481,6 +8482,13 @@ lang_add_string (size_t size, const char *s)
   free (string);
 }
 
+/* Store the time of linking in the image */
+void
+lang_add_timestamp (void)
+{
+  lang_add_data (QUAD, exp_intop ((bfd_vma) time (0)));
+}
+
 /* Create a new reloc statement.  RELOC is the BFD relocation type to
    generate.  HOWTO is the corresponding howto structure (we could
    look this up, but the caller has already done so).  SECTION is the
diff --git a/ld/ldlang.h b/ld/ldlang.h
index 2300fa5b2a3..ef785ae5cad 100644
--- a/ld/ldlang.h
+++ b/ld/ldlang.h
@@ -649,6 +649,8 @@ extern void lang_add_data
 extern bfd_vma charcount(const char *s);
 extern void lang_add_string
   (size_t, const char *s);
+extern void lang_add_timestamp
+  (void);
 extern void lang_add_reloc
   (bfd_reloc_code_real_type, reloc_howto_type *, asection *, const char *,
    union etree_union *);
-- 
2.34.1


^ permalink raw reply	[flat|nested] 12+ messages in thread

* [PATCH v5 02/10] DIGEST: NEWS
  2023-02-22 16:15 [PATCH v5 0/10 Add support for CRC64 generation in linker binutils
  2023-02-22 16:16 ` [PATCH v5 01/10] TIMESTAMP: ldlang: process binutils
@ 2023-02-22 16:16 ` binutils
  2023-02-22 16:16 ` [PATCH v5 03/10] DIGEST: ld.texi binutils
                   ` (8 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: binutils @ 2023-02-22 16:16 UTC (permalink / raw)
  To: binutils; +Cc: nickc, Ulf Samuelsson

From: Ulf Samuelsson <ulf@emagii.com>

Add info on
DEBUG [ON|OFF]
TIMESTAMP
DIGEST commands

Signed-off-by: Ulf Samuelsson <ulf@emagii.com>
---
 ld/NEWS | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 54 insertions(+)

diff --git a/ld/NEWS b/ld/NEWS
index 4b91f2c3b0a..774ccc732ae 100644
--- a/ld/NEWS
+++ b/ld/NEWS
@@ -1,5 +1,59 @@
 -*- text -*-
 
+* The linker script has a new command to insert a timestamp
+  TIMESTAMP
+  inserts the current time (seconds since Epoch) as a 64-bit value
+
+* The linker script syntax has new commands for debugging a linker script
+  DEBUG ON  turns on debugging
+  DEBUG OFF turns off debugging
+
+* The linker script syntax has new commands for handling CRC-32/64 calculations
+  on the '.text' section
+  It uses code from https://www.libcrc.org/
+
+  DIGEST "CRC32"              (start, end)
+  DIGEST "CRC64-ECMA"         (start, end)
+  DIGEST "CRC64-ISO"          (start, end)
+  DIGEST "CRC64-WE"           (start, end)
+  DIGEST POLY (size, polynome)(start, end)
+  DIGEST POLYI(size, polynome)(start, end) (inversion during CRC calculation)
+  DIGEST TABLE
+  DIGEST SECTION "<section>
+
+  The CRC32, CRC64-ECMA, CRC64-ISO, CRC64-WE, POLY and POLYI defines
+  the polynome to use and reserves space for the 32/64-bit CRC in the
+  '.text' section.
+  The user can do the CRC check in another section through the
+  DIGEST SECTION command.
+
+  The 32 bit DIGEST <polynome> command defines some global symbols.
+  ___CRC32___ is the address of the CRC64 checksum
+  ___CRC32_START___ is the address where CRC calculation starts
+  ___CRC32_END___ The CRC calculation ends before this address.
+
+  The 64-bit DIGEST <polynome> command defines some global symbols.
+  ___CRC64___ is the address of the CRC64 checksum
+  ___CRC64_START___ is the address where CRC calculation starts
+  ___CRC64_END___ The CRC calculation ends before this address.
+
+  All three symbols must refer to addresses in the selected section.
+  If they are defined at the end of the linking process, then
+  the CRC## will be calculated between
+
+    ___CRC##_START___ .. ___CRC##_END___ -1
+
+  and the result will be inserted at ___CRC##___.
+
+  ___CRC##___ must be outside the region where CRC is calculated
+
+  The DIGEST TABLE command generates a table for CRC generation.
+  A table is not neccessary, but will speed up the calculation and makes it
+  compatible with the CRC check routines at https://www.libcrc.org/
+  It defines the ___CRC##_TABLE___ symbol at the start of the table.
+  The user may choose to add this table to his code instead of using
+  the linker.
+
 * The linker script syntax has two new commands for inserting text into output
   sections:
     ASCII (<size>) "string"
-- 
2.34.1


^ permalink raw reply	[flat|nested] 12+ messages in thread

* [PATCH v5 03/10] DIGEST: ld.texi
  2023-02-22 16:15 [PATCH v5 0/10 Add support for CRC64 generation in linker binutils
  2023-02-22 16:16 ` [PATCH v5 01/10] TIMESTAMP: ldlang: process binutils
  2023-02-22 16:16 ` [PATCH v5 02/10] DIGEST: NEWS binutils
@ 2023-02-22 16:16 ` binutils
  2023-02-22 16:16 ` [PATCH v5 04/10] LIBCRC: license binutils
                   ` (7 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: binutils @ 2023-02-22 16:16 UTC (permalink / raw)
  To: binutils; +Cc: nickc, Ulf Samuelsson

From: Ulf Samuelsson <ulf@emagii.com>

Signed-off-by: Ulf Samuelsson <ulf@emagii.com>
---
 ld/ld.texi | 146 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 146 insertions(+)

diff --git a/ld/ld.texi b/ld/ld.texi
index 7802f0661b0..c321d383c0b 100644
--- a/ld/ld.texi
+++ b/ld/ld.texi
@@ -5394,6 +5394,152 @@ area:
   ASCIZ "This is 16 bytes"
 @end smallexample
 
+@cindex output section strings
+@kindex DIGEST "CRC64-ECMA"                              (@var{expression}, @var{expression})
+@kindex DIGEST "CRC64-WE"                                (@var{expression}, @var{expression})
+@kindex DIGEST "CRC64-ISO"                               (@var{expression}, @var{expression})
+@kindex DIGEST "CRC32"                                   (@var{expression}, @var{expression})
+@kindex DIGEST POLY  (@var{expression}, @var{expression})(@var{expression}, @var{expression})
+@kindex DIGEST POLYI (@var{expression}, @var{expression})(@var{expression}, @var{expression})
+
+You can calculate the CRC of a part of the '.text' section through the
+@code{DIGEST} command.
+The commands take a parameter for the @code{polynome} and then two more,
+specifying range of the checked area.  The end address is the first address
+past the checked area.
+
+There is one predefined 32-bit polynome
+
+@enumerate
+@item
+@code{CRC32} @code{0xEDB88320}
+@end enumerate
+
+There are three predefined 64-bit polynomes
+
+@enumerate
+@item
+@code{CRC64-ECMA}  @code{0x42F0E1EBA9EA3693}
+@item
+@code{CRC64-WE}    @code{0x42F0E1EBA9EA3693}
+@item
+@code{CRC64-ISO}   @code{0xD800000000000000}
+@end enumerate
+
+You can also select your own @code{polynome} using the @code{DIGEST POLY} or
+@code{DIGEST POLYI}. The @code{DIGEST POLYI} will invert the polynome before
+and after the calculation which is neccessary for the @code{CRC64-WE} algorithm
+
+The default 64-bit polynome is the @code{ECMA}
+
+The 32-bit <polynome> command defines some global symbols.
+
+@enumerate
+@item
+@code{___CRC32___}       address of the CRC32 checksum
+@item
+@code{___CRC32_START___} first address in the checked area.
+@item
+@code{___CRC32_END___}   first address past the checked area.
+@end enumerate
+
+The 64-bit <polynome> command defines some global symbols.
+
+@enumerate
+@item
+@code{___CRC64___}       address of the CRC64 checksum
+@item
+@code{___CRC64_START___} first address in the checked area.
+@item
+@code{___CRC64_END___}   first address past the checked area.
+@end enumerate
+
+Note: The generated CRC value must be stored outside the checked area.
+
+Example 1: This request a CRC check using the @code{ECMA} algorithm
+
+@smallexample
+  CRC = '.';
+  DIGEST "CRC64-ECMA" (START_CHECK,END_TEXT)
+  START_CHECK = '.';
+@end smallexample
+
+The user can retrieve the CRC value through the @code{CRC} label.
+
+Example 2: This request a CRC check using the @code{ISO} algorithm
+
+@smallexample
+  CRC = '.';
+  DIGEST "CRC64-ISO" (START_CHECK,END_TEXT)
+  START_CHECK = '.';
+@end smallexample
+
+The user can retrieve the CRC value through the @code{CRC} label.
+
+Example 3: This request a CRC check using a user defined @code{polynome}
+
+@smallexample
+  CRC = '.';
+  DIGEST POLY (64, 0xDEADBEEFDEADBEEF) (START_CHECK,END_TEXT)
+  START_CHECK = '.';
+@end smallexample
+
+The user can retrieve the CRC value through the @code{CRC} label.
+
+Example 4: This request a CRC check using a user defined @code{polynome}
+  The @code{polynome} is inverted before use, and teh result is inverted.
+
+@smallexample
+  CRC DIGEST POLYI (64, 0xDEADBEEFDEADBEEF) (START_CHECK,END_TEXT)
+  START_CHECK = '.';
+@end smallexample
+
+Example 5: This request a CRC check using the @code{CRC32} polynome
+
+@smallexample
+  CRC = '.';
+  DIGEST "CRC32" (START_CHECK,END_TEXT)
+  START_CHECK = '.';
+@end smallexample
+
+The user can retrieve the CRC value through the @code{CRC} label.
+
+@cindex output section strings
+@kindex DIGEST TABLE
+
+The @code{DIGEST TABLE} command creates a 1 or 2 kByte table for a table-driven
+CRC calculation.  This speeds up the CRC calculation over a non-table-driver
+version since you can handle 8 bits at a time, instead of 1 bit.
+
+The table generated is for the @code{polynome} selected using a 
+@code{DIGEST <polynome>} command.
+
+The command will define a symbol base on the size of the polynome
+
+@enumerate
+@item
+@code{___CRC32_TABLE___}       address of the CRC32 table, or
+@item
+@code{___CRC64_TABLE___}       address of the CRC64 table
+@end enumerate
+
+
+Example 1: Generate a 1 kB table
+           (assuming a previous @code{DIGEST "CRC32"} command
+
+@smallexample
+  mytable = '.';
+  DIGEST TABLE
+@end smallexample
+
+The user can declare @code{extern uint32_t *mytable;} in his code to use it.
+
+@cindex output section strings
+@kindex TIMESTAMP
+
+The @code{TIMESTAMP} command creates 64-bit integer with the number of seconds
+since Epoch (1970-01-01 00:00)
+
 @kindex FILL(@var{expression})
 @cindex holes, filling
 @cindex unspecified memory
-- 
2.34.1


^ permalink raw reply	[flat|nested] 12+ messages in thread

* [PATCH v5 04/10] LIBCRC: license
  2023-02-22 16:15 [PATCH v5 0/10 Add support for CRC64 generation in linker binutils
                   ` (2 preceding siblings ...)
  2023-02-22 16:16 ` [PATCH v5 03/10] DIGEST: ld.texi binutils
@ 2023-02-22 16:16 ` binutils
  2023-02-22 16:16 ` [PATCH v5 05/10] DIGEST: ldlex.l binutils
                   ` (6 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: binutils @ 2023-02-22 16:16 UTC (permalink / raw)
  To: binutils; +Cc: nickc, Ulf Samuelsson

From: Ulf Samuelsson <ulf@emagii.com>

Signed-off-by: Ulf Samuelsson <ulf@emagii.com>
---
 COPYING.LIBCRC | 45 +++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 45 insertions(+)
 create mode 100755 COPYING.LIBCRC

diff --git a/COPYING.LIBCRC b/COPYING.LIBCRC
new file mode 100755
index 00000000000..e8b7226ab89
--- /dev/null
+++ b/COPYING.LIBCRC
@@ -0,0 +1,45 @@
+The GNU linker contains CRC routines that are used to implement the
+DIGEST CRC32/64 commands in the output section.
+
+The CRC routines are extracted from LIBCRC available at
+* https://www.libcrc.org/
+* https://github.com/lammertb/libcrc/tree/v2.0
+
+The license file from libcrc is below.
+================================================================================
+/*
+ * 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.
+ */
+================================================================================
+NOTE: The user could/(should) extract the CRC calculation routines
+      and add to their program.
+      The linker can add the table, but not the calculation routines.
-- 
2.34.1


^ permalink raw reply	[flat|nested] 12+ messages in thread

* [PATCH v5 05/10] DIGEST: ldlex.l
  2023-02-22 16:15 [PATCH v5 0/10 Add support for CRC64 generation in linker binutils
                   ` (3 preceding siblings ...)
  2023-02-22 16:16 ` [PATCH v5 04/10] LIBCRC: license binutils
@ 2023-02-22 16:16 ` binutils
  2023-02-22 16:16 ` [PATCH v5 06/10] DIGEST: ldgram.y binutils
                   ` (5 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: binutils @ 2023-02-22 16:16 UTC (permalink / raw)
  To: binutils; +Cc: nickc, Ulf Samuelsson

From: Ulf Samuelsson <ulf@emagii.com>

Symbols for the following commands:

DIGEST "NAME"                 (start, end)
DIGEST POLY  (size, polynome) (start, end)
DIGEST POLYI (size, polynome) (start, end)
DIGEST TABLE
DIGEST SECTION "NAME"
TIMESTAMP
DEBUG ON
DEBUG OFF

Signed-off-by: Ulf Samuelsson <ulf@emagii.com>
---
 ld/ldlex.l | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/ld/ldlex.l b/ld/ldlex.l
index 910e7ea3b8b..420caee177c 100644
--- a/ld/ldlex.l
+++ b/ld/ldlex.l
@@ -298,6 +298,15 @@ V_IDENTIFIER [*?.$_a-zA-Z\[\]\-\!\^\\]([*?.$_a-zA-Z0-9\[\]\-\!\^\\]|::)*
 <SCRIPT>"AFTER"				{ RTOKEN(AFTER); }
 <SCRIPT>"BEFORE"			{ RTOKEN(BEFORE); }
 <WILD>"FILL"				{ RTOKEN(FILL); }
+<WILD>"DIGEST"				{ RTOKEN(DIGEST); }
+<WILD>"POLY"				{ RTOKEN(POLY); }
+<WILD>"POLYI"				{ RTOKEN(POLYI); }
+<WILD>"SECTION"				{ RTOKEN(SECTION); }
+<WILD>"TABLE"				{ RTOKEN(TABLE); }
+<WILD>"TIMESTAMP"			{ RTOKEN(TIMESTAMP); }
+<WILD>"DEBUG"				{ RTOKEN(DEBUG); }
+<WILD>"ON"				{ RTOKEN(ON); }
+<WILD>"OFF"				{ RTOKEN(OFF); }
 <SCRIPT>"STARTUP"			{ RTOKEN(STARTUP); }
 <SCRIPT>"OUTPUT_FORMAT"			{ RTOKEN(OUTPUT_FORMAT); }
 <SCRIPT>"OUTPUT_ARCH"			{ RTOKEN(OUTPUT_ARCH); }
-- 
2.34.1


^ permalink raw reply	[flat|nested] 12+ messages in thread

* [PATCH v5 06/10] DIGEST: ldgram.y
  2023-02-22 16:15 [PATCH v5 0/10 Add support for CRC64 generation in linker binutils
                   ` (4 preceding siblings ...)
  2023-02-22 16:16 ` [PATCH v5 05/10] DIGEST: ldlex.l binutils
@ 2023-02-22 16:16 ` binutils
  2023-02-22 16:16 ` [PATCH v5 07/10] DIGEST: Makefile.am: add new files binutils
                   ` (4 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: binutils @ 2023-02-22 16:16 UTC (permalink / raw)
  To: binutils; +Cc: nickc, Ulf Samuelsson

From: Ulf Samuelsson <ulf@emagii.com>

Parse the following commands

DIGEST "NAME"                 (start, end)
DIGEST POLY  (size, polynome) (start, end)
DIGEST POLYI (size, polynome) (start, end)
DIGEST TABLE
DIGEST SECTION "NAME"
TIMESTAMP
DEBUG ON
DEBUG OFF

Signed-off-by: Ulf Samuelsson <ulf@emagii.com>
---
 ld/ldgram.y | 48 +++++++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 47 insertions(+), 1 deletion(-)

diff --git a/ld/ldgram.y b/ld/ldgram.y
index faffeec94b8..2d752e52b6d 100644
--- a/ld/ldgram.y
+++ b/ld/ldgram.y
@@ -41,6 +41,7 @@
 #include "mri.h"
 #include "ldctor.h"
 #include "ldlex.h"
+#include "lddigest.h"
 
 #ifndef YYDEBUG
 #define YYDEBUG 1
@@ -130,6 +131,9 @@ static int error_index;
 %token DATA_SEGMENT_ALIGN DATA_SEGMENT_RELRO_END DATA_SEGMENT_END
 %token SORT_BY_NAME SORT_BY_ALIGNMENT SORT_NONE
 %token SORT_BY_INIT_PRIORITY
+%token DIGEST POLY POLYI TABLE SECTION
+%token TIMESTAMP
+%token DEBUG ON OFF
 %token '{' '}'
 %token SIZEOF_HEADERS OUTPUT_FORMAT FORCE_COMMON_ALLOCATION OUTPUT_ARCH
 %token INHIBIT_COMMON_ALLOCATION FORCE_GROUP_ALLOCATION
@@ -668,7 +672,7 @@ statement:
 		{
 		  lang_add_data ((int) $1, $3);
 		}
-        | ASCII '(' mustbe_exp ')' NAME
+	| ASCII '(' mustbe_exp ')' NAME
 		{
 		  /* 'value' is a memory leak, do we care?  */
 		  etree_type *value = $3;
@@ -682,6 +686,25 @@ statement:
 		{
 		  lang_add_fill ($3);
 		}
+	| DIGEST polynome '(' mustbe_exp ',' mustbe_exp ')'
+		{
+		  lang_add_assignment (exp_assign (CRC_ADDRESS, exp_nameop (NAME,"."), false));
+		  lang_add_assignment (exp_assign (CRC_START, $4, false));
+		  lang_add_assignment (exp_assign (CRC_END,   $6, false));
+		}
+	| DIGEST TABLE
+		{
+		  lang_add_assignment (exp_assign (CRC_TABLE, exp_nameop (NAME,"."), false));
+		  lang_add_digest_table ();
+		}
+	| DIGEST SECTION NAME
+		{
+		  lang_set_digest_section ($3);
+		}
+	| TIMESTAMP
+		{
+		  lang_add_timestamp ();
+		}
 	| ASSERT_K
 		{ ldlex_expression (); }
 	  '(' exp ',' NAME ')' separator
@@ -689,13 +712,36 @@ statement:
 		  ldlex_popstate ();
 		  lang_add_assignment (exp_assert ($4, $6));
 		}
+	| DEBUG ON
+		{
+		  yydebug = 1;
+		}
+	| DEBUG OFF
+		{
+		  yydebug = 0;
+		}
 	| INCLUDE filename
 		{
 		  ldfile_open_command_file ($2);
 		}
+
 	  statement_list_opt END
 	;
 
+polynome:
+	NAME
+		{
+		  lang_set_digest($1);
+		}
+	| POLY '(' mustbe_exp ',' mustbe_exp ')'
+		{
+		  lang_add_digest (false, $3->value.value, $5->value.value);
+		}
+	| POLYI '(' mustbe_exp ',' mustbe_exp ')'
+		{
+		  lang_add_digest (true,  $3->value.value, $5->value.value);
+		}
+
 statement_list:
 		statement_list statement
 	|	statement
-- 
2.34.1


^ permalink raw reply	[flat|nested] 12+ messages in thread

* [PATCH v5 07/10] DIGEST: Makefile.am: add new files
  2023-02-22 16:15 [PATCH v5 0/10 Add support for CRC64 generation in linker binutils
                   ` (5 preceding siblings ...)
  2023-02-22 16:16 ` [PATCH v5 06/10] DIGEST: ldgram.y binutils
@ 2023-02-22 16:16 ` binutils
  2023-02-22 16:16 ` [PATCH v5 08/10] DIGEST: CRC-32/64 algorithms binutils
                   ` (3 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: binutils @ 2023-02-22 16:16 UTC (permalink / raw)
  To: binutils; +Cc: nickc, Ulf Samuelsson

From: Ulf Samuelsson <ulf@emagii.com>

* lddigest.c
* lddigest.h
* ldcrc32.c
* ldcrc64.c

added to the build

Signed-off-by: Ulf Samuelsson <ulf@emagii.com>
---
 ld/Makefile.am |  9 +++++++--
 ld/Makefile.in | 15 ++++++++++++---
 2 files changed, 19 insertions(+), 5 deletions(-)

diff --git a/ld/Makefile.am b/ld/Makefile.am
index 760225c5b88..f778324d3db 100644
--- a/ld/Makefile.am
+++ b/ld/Makefile.am
@@ -479,13 +479,15 @@ CFILES = ldctor.c ldemul.c ldexp.c ldfile.c ldlang.c \
 	ldmain.c ldmisc.c ldver.c ldwrite.c lexsup.c \
 	mri.c ldcref.c pe-dll.c pep-dll.c ldlex-wrapper.c \
 	plugin.c ldbuildid.c ldelf.c ldelfgen.c \
-	pdb.c
+	pdb.c \
+	lddigest.c ldcrc32.c ldcrc64.c
 
 HFILES = ld.h ldctor.h ldemul.h ldexp.h ldfile.h \
 	ldlang.h ldlex.h ldmain.h ldmisc.h ldver.h \
 	ldwrite.h mri.h deffile.h pe-dll.h pep-dll.h \
 	elf-hints-local.h plugin.h ldbuildid.h ldelf.h ldelfgen.h \
-	pdb.h
+	pdb.h \
+	lddigest.h
 
 GENERATED_CFILES = ldgram.c ldlex.c deffilep.c
 GENERATED_HFILES = ldgram.h ldemul-list.h deffilep.h
@@ -495,6 +497,7 @@ GENERATED_HFILES = ldgram.h ldemul-list.h deffilep.h
 BUILT_SOURCES = $(GENERATED_HFILES)
 
 OFILES = ldgram.@OBJEXT@ ldlex-wrapper.@OBJEXT@ lexsup.@OBJEXT@ ldlang.@OBJEXT@ \
+	lddigest.@OBJEXT@ ldcrc32.@OBJEXT@ ldcrc64.@OBJEXT@ \
 	mri.@OBJEXT@ ldctor.@OBJEXT@ ldmain.@OBJEXT@ plugin.@OBJEXT@ \
 	ldwrite.@OBJEXT@ ldexp.@OBJEXT@  ldemul.@OBJEXT@ ldver.@OBJEXT@ ldmisc.@OBJEXT@ \
 	ldfile.@OBJEXT@ ldcref.@OBJEXT@ ${EMULATION_OFILES} ${EMUL_EXTRA_OFILES} \
@@ -962,8 +965,10 @@ EXTRA_ld_new_SOURCES = deffilep.y ldlex.l
 EXTRA_ld_new_SOURCES += ldelf.c ldelfgen.c pdb.c pep-dll.c pe-dll.c
 
 ld_new_SOURCES = ldgram.y ldlex-wrapper.c lexsup.c ldlang.c mri.c ldctor.c ldmain.c \
+	lddigest.c ldcrc32.c ldcrc64.c \
 	ldwrite.c ldexp.c ldemul.c ldver.c ldmisc.c ldfile.c ldcref.c plugin.c \
 	ldbuildid.c
+
 ld_new_DEPENDENCIES = $(EMULATION_OFILES) $(EMUL_EXTRA_OFILES) \
 		      $(BFDLIB) $(LIBCTF) $(LIBIBERTY) $(LIBINTL_DEP) $(JANSSON_LIBS)
 ld_new_LDADD = $(EMULATION_OFILES) $(EMUL_EXTRA_OFILES) $(BFDLIB) $(LIBCTF) \
diff --git a/ld/Makefile.in b/ld/Makefile.in
index d4dddf2f629..d3bab6c0d4a 100644
--- a/ld/Makefile.in
+++ b/ld/Makefile.in
@@ -209,7 +209,8 @@ libldtestplug4_la_LINK = $(LIBTOOL) $(AM_V_lt) --tag=CC \
 PROGRAMS = $(bin_PROGRAMS)
 am_ld_new_OBJECTS = ldgram.$(OBJEXT) ldlex-wrapper.$(OBJEXT) \
 	lexsup.$(OBJEXT) ldlang.$(OBJEXT) mri.$(OBJEXT) \
-	ldctor.$(OBJEXT) ldmain.$(OBJEXT) ldwrite.$(OBJEXT) \
+	ldctor.$(OBJEXT) ldmain.$(OBJEXT) lddigest.$(OBJEXT) \
+	ldcrc32.$(OBJEXT) ldcrc64.$(OBJEXT) ldwrite.$(OBJEXT) \
 	ldexp.$(OBJEXT) ldemul.$(OBJEXT) ldver.$(OBJEXT) \
 	ldmisc.$(OBJEXT) ldfile.$(OBJEXT) ldcref.$(OBJEXT) \
 	plugin.$(OBJEXT) ldbuildid.$(OBJEXT)
@@ -533,6 +534,7 @@ pdfdir = @pdfdir@
 prefix = @prefix@
 program_transform_name = @program_transform_name@
 psdir = @psdir@
+runstatedir = @runstatedir@
 sbindir = @sbindir@
 sharedstatedir = @sharedstatedir@
 srcdir = @srcdir@
@@ -978,13 +980,15 @@ CFILES = ldctor.c ldemul.c ldexp.c ldfile.c ldlang.c \
 	ldmain.c ldmisc.c ldver.c ldwrite.c lexsup.c \
 	mri.c ldcref.c pe-dll.c pep-dll.c ldlex-wrapper.c \
 	plugin.c ldbuildid.c ldelf.c ldelfgen.c \
-	pdb.c
+	pdb.c \
+	lddigest.c ldcrc32.c ldcrc64.c
 
 HFILES = ld.h ldctor.h ldemul.h ldexp.h ldfile.h \
 	ldlang.h ldlex.h ldmain.h ldmisc.h ldver.h \
 	ldwrite.h mri.h deffile.h pe-dll.h pep-dll.h \
 	elf-hints-local.h plugin.h ldbuildid.h ldelf.h ldelfgen.h \
-	pdb.h
+	pdb.h \
+	lddigest.h
 
 GENERATED_CFILES = ldgram.c ldlex.c deffilep.c
 GENERATED_HFILES = ldgram.h ldemul-list.h deffilep.h
@@ -993,6 +997,7 @@ GENERATED_HFILES = ldgram.h ldemul-list.h deffilep.h
 # tracking will not cause them to be built beforehand.
 BUILT_SOURCES = $(GENERATED_HFILES)
 OFILES = ldgram.@OBJEXT@ ldlex-wrapper.@OBJEXT@ lexsup.@OBJEXT@ ldlang.@OBJEXT@ \
+	lddigest.@OBJEXT@ ldcrc32.@OBJEXT@ ldcrc64.@OBJEXT@ \
 	mri.@OBJEXT@ ldctor.@OBJEXT@ ldmain.@OBJEXT@ plugin.@OBJEXT@ \
 	ldwrite.@OBJEXT@ ldexp.@OBJEXT@  ldemul.@OBJEXT@ ldver.@OBJEXT@ ldmisc.@OBJEXT@ \
 	ldfile.@OBJEXT@ ldcref.@OBJEXT@ ${EMULATION_OFILES} ${EMUL_EXTRA_OFILES} \
@@ -1014,6 +1019,7 @@ EXTRA_ld_new_SOURCES = deffilep.y ldlex.l ldelf.c ldelfgen.c pdb.c \
 	pep-dll.c pe-dll.c $(ALL_EMULATION_SOURCES) \
 	$(ALL_64_EMULATION_SOURCES)
 ld_new_SOURCES = ldgram.y ldlex-wrapper.c lexsup.c ldlang.c mri.c ldctor.c ldmain.c \
+	lddigest.c ldcrc32.c ldcrc64.c \
 	ldwrite.c ldexp.c ldemul.c ldver.c ldmisc.c ldfile.c ldcref.c plugin.c \
 	ldbuildid.c
 
@@ -1560,8 +1566,11 @@ distclean-compile:
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ez8001.Po@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ez8002.Po@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ldbuildid.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ldcrc32.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ldcrc64.Po@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ldcref.Po@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ldctor.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/lddigest.Po@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ldelf.Po@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ldelfgen.Po@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ldemul.Po@am__quote@
-- 
2.34.1


^ permalink raw reply	[flat|nested] 12+ messages in thread

* [PATCH v5 08/10] DIGEST: CRC-32/64 algorithms
  2023-02-22 16:15 [PATCH v5 0/10 Add support for CRC64 generation in linker binutils
                   ` (6 preceding siblings ...)
  2023-02-22 16:16 ` [PATCH v5 07/10] DIGEST: Makefile.am: add new files binutils
@ 2023-02-22 16:16 ` binutils
  2023-02-22 16:16 ` [PATCH v5 09/10] DIGEST: ldmain.c: add CRC calculation binutils
                   ` (2 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: binutils @ 2023-02-22 16:16 UTC (permalink / raw)
  To: binutils; +Cc: nickc, Ulf Samuelsson

From: Ulf Samuelsson <ulf@emagii.com>

Creation of CRC tables
Calculations of CRC
Functions to add data into the output section

Signed-off-by: Ulf Samuelsson <ulf@emagii.com>
---
 ld/ldcrc32.c  | 138 ++++++++++++
 ld/ldcrc64.c  | 131 ++++++++++++
 ld/lddigest.c | 575 ++++++++++++++++++++++++++++++++++++++++++++++++++
 ld/lddigest.h |  97 +++++++++
 4 files changed, 941 insertions(+)
 create mode 100644 ld/ldcrc32.c
 create mode 100644 ld/ldcrc64.c
 create mode 100644 ld/lddigest.c
 create mode 100755 ld/lddigest.h

diff --git a/ld/ldcrc32.c b/ld/ldcrc32.c
new file mode 100644
index 00000000000..67a85e89d1b
--- /dev/null
+++ b/ld/ldcrc32.c
@@ -0,0 +1,138 @@
+/*
+ * Library: libcrc
+ * 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.
+ *
+ */
+
+#include "sysdep.h"
+#include "bfd.h"
+#include "lddigest.h"
+
+/* ============ CRC-32 LIBCRC functions ======================================*/
+
+/*
+ * void init_crc32_tab( void );
+ *
+ * For optimal speed, the CRC32 calculation uses a table with pre-calculated
+ * bit patterns which are used in the XOR operations in the program.
+ * init_crc32_tab is copyright (c) 2016 Lammert Bies
+ */
+uint32_t *
+init_crc32_tab (uint32_t poly)
+{
+  uint32_t i;
+  uint32_t j;
+  uint32_t crc;
+  uint32_t *crc_tab;
+
+  crc_tab = malloc (256 * sizeof (uint32_t));
+  if (crc_tab == NULL)
+    return NULL;
+
+  for (i = 0; i < 256; i++)
+    {
+
+      crc = i;
+
+      for (j = 0; j < 8; j++)
+	{
+
+	  if (crc & 0x00000001L)
+	    {
+	      crc = (crc >> 1) ^ poly;
+	    }
+	  else
+	    {
+	      crc = crc >> 1;
+	    }
+	}
+
+      crc_tab[i] = crc;
+    }
+  return crc_tab;
+}				/* init_crc32_tab */
+
+/*
+ * uint32_t calc_crc32_inv( const unsigned char *input_str, size_t num_bytes );
+ *
+ * The function calc_crc32_inv() calculates in one pass the common 32 bit CRC value for
+ * a byte string that is passed to the function together with a parameter
+ * indicating the length.
+ */
+
+uint32_t
+calc_crc32_inv (const unsigned char *input_str, size_t num_bytes)
+{
+  uint32_t crc;
+  const unsigned char *ptr;
+  size_t a;
+
+  crc = CRC_START_32_INV;
+  ptr = input_str;
+
+  if (ptr != NULL)
+    {
+      for (a = 0; a < num_bytes; a++)
+	{
+	  crc = (crc >> 8) ^
+	    crc32_tab[(crc ^ (uint32_t) * ptr++) & 0x000000FFul];
+	}
+    }
+
+  return (crc ^ 0xFFFFFFFFul);
+
+}				/* calc_crc32_inv */
+
+/*
+ * uint32_t calc_crc32( const unsigned char *input_str, size_t num_bytes );
+ *
+ * The function calc_crc32() calculates in one pass the common 32 bit CRC value for
+ * a byte string that is passed to the function together with a parameter
+ * indicating the length.
+ */
+uint32_t
+calc_crc32 (const unsigned char *input_str, size_t num_bytes)
+{
+  uint32_t crc;
+  const unsigned char *ptr;
+  size_t a;
+  if (crc_invert)
+    return calc_crc32_inv (input_str, num_bytes);
+
+  crc = 0;
+  ptr = input_str;
+
+  if (ptr != NULL)
+    {
+      for (a = 0; a < num_bytes; a++)
+	{
+	  crc = (crc >> 8) ^
+	    crc32_tab[(crc ^ (uint32_t) * ptr++) & 0x000000FFul];
+	}
+    }
+
+  return (crc);
+
+}				/* calc_crc32 */
diff --git a/ld/ldcrc64.c b/ld/ldcrc64.c
new file mode 100644
index 00000000000..4c2bc89a78d
--- /dev/null
+++ b/ld/ldcrc64.c
@@ -0,0 +1,131 @@
+/*
+ * Library: libcrc
+ * 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.
+ *
+ */
+
+#include "sysdep.h"
+#include "bfd.h"
+#include "lddigest.h"
+
+/* ============ CRC-64 LIBCRC functions ======================================*/
+
+/*
+ * bfd_vma *init_crc64_tab( bfd_vma poly ) ;
+ *
+ * For optimal speed, the CRC64 calculation uses a table with pre-calculated
+ * bit patterns which are used in the XOR operations in the program.
+ * init_crc64_tab is copyright (c) 2016 Lammert Bies
+ */
+bfd_vma *
+init_crc64_tab (bfd_vma poly)
+{
+  bfd_vma i;
+  bfd_vma j;
+  bfd_vma c;
+  bfd_vma crc;
+  bfd_vma *crc_tab;
+
+  crc_tab = malloc (256 * sizeof (bfd_vma));
+  if (crc_tab == NULL)
+    return NULL;
+
+  for (i = 0; i < 256; i++)
+    {
+      crc = 0;
+      c = i << 56;
+      for (j = 0; j < 8; j++)
+	{
+	  if ((crc ^ c) & 0x8000000000000000ull)
+	    crc = (crc << 1) ^ poly;
+	  else
+	    crc = crc << 1;
+	  c = c << 1;
+	}
+      crc_tab[i] = crc;
+    }
+  return crc_tab;
+
+}				/* init_crc64_tab */
+
+/*
+ * The function calc_crc64_inv() calculates in one pass the CRC64 64 bit CRC
+ * value for a byte string that is passed to the function together with a
+ * parameter indicating the length.
+ * This is used for CRC64-WE
+ * calc_crc64_inv is copyright (c) 2016 Lammert Bies
+ */
+bfd_vma
+calc_crc64_inv (const unsigned char *input_str, size_t num_bytes)
+{
+  bfd_vma crc;
+  const unsigned char *ptr;
+  size_t a;
+
+  crc = CRC_START_64_INV;
+  ptr = input_str;
+
+  if (ptr != NULL)
+    {
+      for (a = 0; a < num_bytes; a++)
+	{
+	  crc = (crc << 8) ^
+	    crc64_tab[((crc >> 56) ^ (bfd_vma) * ptr++) &
+		      0x00000000000000FFull];
+	}
+    }
+  return crc ^ 0xFFFFFFFFFFFFFFFFull;
+}				/* calc_crc64_inv */
+
+/*
+ * bfd_vma calc_crc64( const unsigned char *input_str, size_t num_bytes );
+ *
+ * The function calc_crc64() calculates in one pass the 64 bit CRC value
+ * for a byte string that is passed to the function together with a
+ * parameter indicating the length.
+ * This is used for CRC64-ECMA and CRC64-ISO
+ * calc_crc64 is copyright (c) 2016 Lammert Bies
+ */
+bfd_vma
+calc_crc64 (const unsigned char *input_str, size_t num_bytes)
+{
+  bfd_vma crc;
+  const unsigned char *ptr;
+  size_t a;
+  if (crc_invert)
+    return calc_crc64_inv (input_str, num_bytes);
+  crc = CRC_START_64;
+  ptr = input_str;
+  if (ptr != NULL)
+    {
+      for (a = 0; a < num_bytes; a++)
+	{
+	  crc = (crc << 8) ^
+	    crc64_tab[((crc >> 56) ^ (bfd_vma) * ptr++) &
+		      0x00000000000000FFull];
+	}
+    }
+  return crc;
+}				/* calc_crc64 */
diff --git a/ld/lddigest.c b/ld/lddigest.c
new file mode 100644
index 00000000000..bed71a54cd1
--- /dev/null
+++ b/ld/lddigest.c
@@ -0,0 +1,575 @@
+/* Linker command language support.
+   Copyright (C) 1991-2023 Free Software Foundation, Inc.
+
+   This file is part of the GNU Binutils.
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program; if not, write to the Free Software
+   Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
+   MA 02110-1301, USA.  */
+
+#define	DEBUG_CRC	0
+
+#include "sysdep.h"
+#include "bfd.h"
+#include "safe-ctype.h"
+#include "obstack.h"
+#include "bfdlink.h"
+#include "ctf-api.h"
+
+#include "ld.h"
+#include "ldmain.h"
+#include "ldexp.h"
+#include "ldlang.h"
+#include <ldgram.h>
+#include "ldlex.h"
+#include "ldmisc.h"
+#include "lddigest.h"
+
+/* CRC calculation on output section */
+asection *text_section;
+unsigned char *text_contents = NULL;
+
+algo_t crc_algo = no_algo;
+bfd_vma crc_size = 0;		/* Size of syndrome */
+bool crc_invert = false;
+
+bfd_vma crc64_poly = CRC_POLY_64;	/* Default Polynome is CRC64 ECMA */
+bfd_vma *crc64_tab = NULL;
+
+uint32_t crc32_poly = CRC_POLY_32;	/* Default Polynome is CRC-32 */
+uint32_t *crc32_tab = NULL;
+
+char *CRC_ADDRESS = NULL;
+char *CRC_START = NULL;
+char *CRC_END = NULL;
+char *CRC_TABLE = NULL;
+
+const char *digest_section = ".text";
+
+/* ============ CRC-32 public functions ======================================*/
+
+void
+lang_add_crc32_syndrome (bool invert, bfd_vma poly)
+{
+  unsigned int poly32 = (unsigned int) (poly & 0xFFFFFFFF);
+#if (DEBUG_CRC == 1)
+  printf ("%s: invert=%d, poly=0x%08ul\n", __FUNCTION__, invert, poly32);
+#endif
+  if (crc_algo == no_algo)	/* We only allow one CRC64 <polynom> */
+    {
+      crc_algo = crc_algo_32;
+      crc_size = sizeof (uint32_t);
+      crc_invert = invert;
+      crc32_poly = poly32;	/* Set the polynom */
+      CRC_ADDRESS = CRC32_ADDRESS;
+      CRC_START = CRC32_START;
+      CRC_END = CRC32_END;
+      CRC_TABLE = CRC32_TABLE;
+
+#if (DEBUG_CRC == 1)
+      printf ("Adding Syndrome: 0x%08lx\n", poly);
+#endif
+      lang_add_data (LONG, exp_intop (0));	/* Reserve room for the ECC value */
+      crc32_tab = init_crc32_tab (crc32_poly);
+      if (crc32_tab == NULL)
+	{
+	  einfo (_("%F%P: can not allocate memory for CRC table: %E\n"));
+	  return;
+	}
+    }
+  else
+    {
+      einfo (_("%P:%pS: warning: Only the first CRC polynome is used\n"),
+	     NULL);
+    }
+}
+
+void
+lang_add_crc32_table (void)
+{
+  uint32_t *crc32_table = crc32_tab;	/* Use a precomputed, if it exists */
+  bool local_table = false;
+  if (crc32_table == NULL)
+    {				/* No luck, create a table */
+      crc32_table = init_crc32_tab (crc32_poly);
+      if (crc32_table == NULL)
+	{
+	  einfo (_("%F%P: can not allocate memory for CRC table: %E\n"));
+	  return;
+	}
+      local_table = true;
+    }
+  for (bfd_vma i = 0; i < 256; i++)
+    {
+      lang_add_data (LONG, exp_intop (crc32_table[i]));
+    }
+  if (local_table)
+    free (crc32_table);
+}
+
+/* ============ CRC-64 public functions ======================================*/
+
+void
+lang_add_crc64_syndrome (bool invert, bfd_vma poly)
+{
+#if (DEBUG_CRC == 1)
+  printf ("%s: invert=%d poly=0x%016lu\n", __FUNCTION__, invert, poly);
+#endif
+  if (crc_algo == no_algo)	/* We only allow one CRC64 <polynom> */
+    {
+      crc_algo = crc_algo_64;
+      crc_size = sizeof (bfd_vma);
+      crc_invert = invert;
+      crc64_poly = poly;	/* Set the polynom */
+      CRC_ADDRESS = CRC64_ADDRESS;
+      CRC_START = CRC64_START;
+      CRC_END = CRC64_END;
+      CRC_TABLE = CRC64_TABLE;
+
+#if (DEBUG_CRC == 1)
+      printf ("Adding Syndrome: 0x%016lu\n", poly);
+#endif
+      lang_add_data (QUAD, exp_intop (0));	/* Reserve room for the ECC value */
+      crc64_tab = init_crc64_tab (crc64_poly);
+      if (crc64_tab == NULL)
+	{
+	  einfo (_("%F%P: can not allocate memory for CRC table: %E\n"));
+	  return;
+	}
+    }
+  else
+    {
+      einfo (_("%P:%pS: warning: Only the first CRC polynome is used\n"),
+	     NULL);
+    }
+}
+
+void
+lang_add_crc64_table (void)
+{
+  bfd_vma *crc64_table = crc64_tab;	/* Use a precomputed, if it exists */
+  bool local_table = false;
+  if (crc64_table == NULL)
+    {				/* No luck, create a table */
+#if (DEBUG_CRC == 1)
+      printf ("%s: Init CRC64 Tab\n", __FUNCTION__);
+#endif
+      crc64_table = init_crc64_tab (crc64_poly);
+#if (DEBUG_CRC == 1)
+      printf ("%s: Init CRC64 Tab DONE\n", __FUNCTION__);
+#endif
+      if (crc64_table == NULL)
+	{
+	  einfo (_("%F%P: can not allocate memory for CRC table: %E\n"));
+	  return;
+	}
+      local_table = true;
+    }
+#if (DEBUG_CRC == 1)
+  printf ("%s: Adding to table\n", __FUNCTION__);
+#endif
+  for (bfd_vma i = 0; i < 256; i++)
+    {
+      lang_add_data (QUAD, exp_intop (crc64_table[i]));
+    }
+  if (local_table)
+    free (crc64_table);
+}
+
+/* ============ DIGEST COMMON functions ======================================*/
+
+void
+lang_add_digest (bool invert, bfd_vma size, bfd_vma poly)
+{
+  if (crc_algo != no_algo)	/* We only allow one CRC <polynom> */
+    {
+      einfo (_("%P:%pS: warning: Only the first CRC polynome is used\n"),
+	     NULL);
+      return;
+    }
+
+  if (size == 32)
+    {
+      lang_add_crc32_syndrome (invert, poly);
+    }
+  else if (size == 64)
+    {
+      lang_add_crc64_syndrome (invert, poly);
+    }
+  else
+    {
+      einfo (_("%F%P: Illegal Size in DIGEST: %E\n"));
+      return;
+    }
+}
+
+bool
+lang_set_digest (char *digest)
+{
+#if (DEBUG_CRC == 1)
+  printf ("%s: DIGEST=%s\n", __FUNCTION__, digest);
+#endif
+  if (crc_algo != no_algo)	/* We only allow one CRC <polynom> */
+    {
+      einfo (_("%P:%pS: warning: Only the first CRC polynome is used\n"),
+	     NULL);
+      return false;
+    }
+
+  if (!strcmp (digest, "CRC64-ECMA"))
+    {
+      lang_add_crc64_syndrome (false, CRC_POLY_64);
+    }
+  else if (!strcmp (digest, "CRC64-WE"))
+    {
+      lang_add_crc64_syndrome (true, CRC_POLY_64);
+    }
+  else if (!strcmp (digest, "CRC64-ISO"))
+    {
+      lang_add_crc64_syndrome (false, CRC_POLY_64_ISO);
+    }
+  else if (!strcmp (digest, "CRC32"))
+    {
+      lang_add_crc32_syndrome (true, CRC_POLY_32);
+    }
+  else
+    {
+      einfo (_("%F%P: Unknown DIGEST: %E\n"));
+      return false;
+    }
+  return true;
+}
+
+void
+lang_add_digest_table (void)
+{
+#if (DEBUG_CRC == 1)
+  printf ("%s: size=%d\n", __FUNCTION__, (int) crc_algo);
+#endif
+  if (crc_algo == crc_algo_32)
+    {
+      lang_add_crc32_table ();
+    }
+  else if (crc_algo == crc_algo_64)
+    {
+      lang_add_crc64_table ();
+    }
+#if (DEBUG_CRC == 1)
+  printf ("%s: END\n", __FUNCTION__);
+#endif
+}
+
+void
+lang_set_digest_section (char *section)
+{
+#if (DEBUG_CRC == 1)
+  printf ("%s: size=%d\n", __FUNCTION__, (int) crc_algo);
+#endif
+  digest_section = section;
+}
+
+/* ============ Access functions for inserting checksum in text section=======*/
+static bool
+get_text_section_contents (void)
+{
+  /*
+   * Get the '.text' section
+   * Is there a risk that CRC needs to be calculated on more than .text?
+   * We do not support that...
+   */
+  text_section =
+    bfd_get_section_by_name (link_info.output_bfd, digest_section);
+  if (text_section == NULL)
+    {
+      einfo (_("%P:%pS: Cannot retrieve '.text' section for CRC calc\n"),
+	     NULL);
+      return false;
+    }
+
+  /* Get the contents of the '.text' area so we can calculate the CRC */
+  if (!bfd_malloc_and_get_section (link_info.output_bfd,
+				   text_section->output_section,
+				   (bfd_byte **) & text_contents))
+    {
+      einfo (_("%P:%pS: warning: '.text' section contents unavailable\n"
+	       "CRC generation aborted\n"), NULL);
+      return false;
+    }
+
+#if (DEBUG_CRC == 1)
+  printf ("%s: [0x%08lx .. 0x%08lx]\n",
+	  text_section->name,
+	  text_section->lma, text_section->lma + text_section->size - 1);
+#endif
+  return true;
+}
+
+/* Set variable in the '.text' area */
+static bool
+set_crc_checksum (bfd_vma crc, bfd_vma addr, bfd_vma size)
+{
+  if (!bfd_set_section_contents (link_info.output_bfd,
+				 text_section->output_section,
+				 &crc, addr, size))
+    {
+      einfo (_("%P:%pS: warning: updating CRC failed\n"
+	       "CRC generation aborted\n"), NULL);
+      return false;
+    }
+  return true;
+}
+
+static bool
+symbol_lookup (char *name, bfd_vma * val)
+{
+  struct bfd_link_hash_entry *h;
+  *val = 0ull;
+  h = bfd_link_hash_lookup (link_info.hash, name, false, false, true);
+  if (h != NULL)
+    {
+      if (((h->type == bfd_link_hash_defined) ||
+	   (h->type == bfd_link_hash_defweak)) &&
+	  (h->u.def.section->output_section != NULL))
+	{
+	  *val = (h->u.def.value
+		  + bfd_section_vma (h->u.def.section->output_section)
+		  + h->u.def.section->output_offset);
+	  return true;
+	}
+    }
+  return false;
+}
+
+/* ============ CRC DEBUG functions ==========================================*/
+
+#if (DEBUG_CRC == 1)
+static void
+debug_hex (char *prompt, unsigned char *section, bfd_vma address, bfd_vma sz)
+{
+  bfd_vma *vma_section = (bfd_vma *) section;
+  bfd_vma size = (sz) / sizeof (bfd_vma);
+  printf ("%s:\n", prompt);
+  for (bfd_vma i = 0; i < size; i += 8)
+    {
+      printf ("0x%08lx: 0x%016lx 0x%016lx 0x%016lx 0x%016lx\n",
+	      address + (i * sizeof (bfd_vma)),
+	      vma_section[i + 0],
+	      vma_section[i + 1], vma_section[i + 2], vma_section[i + 3]);
+    }
+}
+
+static void
+debug_crc_header (char *prompt)
+{
+  debug_hex (prompt, text_contents, text_section->vma, 64);
+}
+
+static void
+debug_crc_update (bfd_vma crc, bfd_vma crc_addr)
+{
+  printf ("CRC [0x%016lx] update at 0x%08lx succeeded\n", crc, crc_addr);
+}
+
+static void
+debug_full_textsection (void)
+{
+
+  /* In order to see the updated content, we have to fetch it again */
+
+  if (!get_text_section_contents ())
+    {
+      debug_crc_header ("After CRC");
+      debug_hex ("Full Section After CRC",
+		 text_contents, text_section->vma, text_section->size);
+      free (text_contents);
+    }
+}
+#else
+#define	debug_hex(p,s,a,sz)
+#define debug_crc_header(p)
+#define debug_crc_update(c, a)
+#define debug_full_textsection()
+#endif
+
+/* ============ CRC common functions =========================================*/
+/*
+ * Multiplexing function for calculating CRC with different algorithms
+ * 'crc_algo'
+ */
+static bfd_vma
+calculate_crc (const unsigned char *input_str, size_t num_bytes)
+{
+  if (crc_algo == crc_algo_64)
+    {
+      if (crc64_tab != NULL)
+	{
+	  return calc_crc64 (input_str, num_bytes);
+	}
+    }
+  else if (crc_algo == crc_algo_32)
+    {
+      if (crc32_tab != NULL)
+	{
+	  return calc_crc32 (input_str, num_bytes);
+	}
+    }
+  /* This should never happen */
+  return 0;
+}
+
+static bool
+invalid_crc_parameters (bfd_vma crc_addr,
+			bfd_vma crc_area_start, bfd_vma crc_area_end)
+{
+  bool crc_in_section;
+  /* Get limits of '.text' section */
+  bfd_vma text_start = text_section->lma;
+  bfd_vma text_end = text_section->lma + text_section->size;
+
+  /* All three symbols must be inside the '.text' section */
+  crc_in_section =
+    ((text_start <= crc_addr) && (crc_addr <= text_end)) &&
+    ((text_start <= crc_area_start) && (crc_area_start <= text_end)) &&
+    ((text_start <= crc_area_end) && (crc_area_end <= text_end));
+
+  if (!crc_in_section)
+    {
+      einfo (_("%P:%pS: warning: CRC area outside the '.text' section\n"
+	       "CRC generation aborted\n"), NULL);
+      /*
+       * Maybe we should printout the text section start and end
+       * as well as the boundaries of the CRC check area.
+       */
+      return true;
+    }
+
+  /*
+   * CRC checksum must be outside the checked area
+   * We must check that they do not overlap in the beginning
+   */
+  {
+    bool crc_valid = false;
+    if (crc_addr < crc_area_start)
+      {
+	if ((crc_addr + crc_size) <= crc_area_start)
+	  {
+	    crc_valid = true;
+	  }
+      }
+    else if (crc_addr >= crc_area_end)
+      {
+	crc_valid = true;
+      }
+    if (!crc_valid)
+      {
+	einfo (_("%P:%pS: warning: CRC located inside checked area\n"
+		 "CRC generation aborted\n"), NULL);
+	return true;
+      }
+  }
+  return false;
+}
+
+void
+lang_generate_crc (void)
+{
+#if (DEBUG_CRC == 1)
+  printf ("%s\n", __FUNCTION__);
+#endif
+  bfd_vma crc_addr, crc_area_start, crc_area_end;
+  bfd_vma crc;
+  bool can_do_crc;
+
+  /* Return immediately, if CRC is not requested */
+  if (crc_algo == no_algo)
+    return;
+
+  if (!get_text_section_contents ())
+    {
+      /* Error messages inside check */
+      return;
+    }
+  /*
+   * These symbols must be present, for CRC to be generated
+   * They should all have been defined in a CRC## <syndrome> statement
+   * If they are not defined, then there is an internal error.
+   * Should we consider using symbols which cannot be parsed by the linker?
+   * I.E. CRC-64 is never an identifier
+   */
+  can_do_crc = symbol_lookup (CRC_ADDRESS, &crc_addr) &&
+    symbol_lookup (CRC_START, &crc_area_start) &&
+    symbol_lookup (CRC_END, &crc_area_end);
+
+  if (!can_do_crc)
+    {
+      einfo (_("%P:%pS: Internal Error - __CRC#___ symbols not defined\n"
+	       "CRC generation aborted\n"), NULL);
+      return;
+    }
+
+  /* Check that the addresses make sense */
+  if (invalid_crc_parameters (crc_addr, crc_area_start, crc_area_end))
+    {
+      /* Error messages inside check */
+      return;
+    }
+
+  /* Calculate and set the CRC */
+  {
+    /*
+     * The '.text' area does not neccessarily start at 0x00000000,
+     * so we have to shift the indices.
+     */
+    bfd_vma _crc_addr = crc_addr - text_section->vma;
+    bfd_vma _crc_area_start = crc_area_start - text_section->vma;
+    bfd_vma _crc_area_end = crc_area_end - text_section->vma;
+
+
+    /* This is the CRC calculation which we worked so hard for */
+    debug_crc_header ("Before CRC");
+    crc = calculate_crc (&text_contents[_crc_area_start],
+			 _crc_area_end - _crc_area_start);
+
+
+    /*
+     * The contents of the '.text' section are no longer needed.
+     * It is a copy of the section contents, and will therefore be stale
+     * after we updated the section with the CRC checksum.
+     * Remove it before we set the CRC checksum, to simplify the code logic.
+     */
+    free (text_contents);
+    if (set_crc_checksum (crc, _crc_addr, crc_size))
+      {
+	debug_crc_update (crc, crc_addr);
+      }
+  }
+
+  debug_full_textsection ();
+}
+
+/* ============ END CRC common functions =====================================*/
+
+void
+lang_generate_digest (void)
+{
+  /* Return immediately, if CRC is not requested */
+  if (crc_algo == no_algo)
+    return;
+
+  /* Handle 32/64-bit CRCs */
+  if ((crc_algo == crc_algo_32) || (crc_algo == crc_algo_32))
+    {
+      lang_generate_crc ();
+    }
+}
diff --git a/ld/lddigest.h b/ld/lddigest.h
new file mode 100755
index 00000000000..ffd65df4785
--- /dev/null
+++ b/ld/lddigest.h
@@ -0,0 +1,97 @@
+/*
+ * Library: libcrc
+ * 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.
+ *
+ */
+
+#ifndef LDDIGEST_H
+#define LDDIGEST_H
+
+#include <stddef.h>
+#include <stdint.h>
+
+#define	CRC_POLY_64		0x42F0E1EBA9EA3693ull
+#define	CRC_POLY_64_ISO		0xD800000000000000ull
+#define	CRC_START_64		0x0000000000000000ull
+#define	CRC_START_64_INV	0xFFFFFFFFFFFFFFFFull
+
+#define	CRC64_ADDRESS		"___CRC64___"
+#define	CRC64_START		"___CRC64_START___"
+#define	CRC64_END		"___CRC64_END___"
+#define	CRC64_TABLE		"___CRC64_TABLE___"
+
+#define	CRC_POLY_32		0xEDB88320ul
+#define	CRC_START_32_INV	0xFFFFFFFFul
+
+#define	CRC32_ADDRESS		"___CRC32___"
+#define	CRC32_START		"___CRC32_START___"
+#define	CRC32_END		"___CRC32_END___"
+#define	CRC32_TABLE		"___CRC32_TABLE___"
+
+typedef enum algorithm
+{
+  no_algo = 0,
+  sha_algo_1 = 1,
+  crc_algo_32 = 4,
+  crc_algo_64 = 8,
+  sha_algo_256 = 256,
+  sha_algo_512
+} algo_t;
+
+
+
+extern char *CRC_ADDRESS;
+extern char *CRC_START;
+extern char *CRC_END;
+extern char *CRC_TABLE;
+extern uint32_t *crc32_tab;
+extern bfd_vma *crc64_tab;
+extern bool crc_invert;
+
+extern void lang_add_crc32_syndrome (bool invert, bfd_vma poly);
+extern void lang_add_crc32_table (void);
+extern void lang_add_crc64_syndrome (bool invert, bfd_vma poly);
+extern void lang_add_crc64_table (void);
+
+extern void lang_add_digest (bool invert, bfd_vma size, bfd_vma polynome);
+extern bool lang_set_digest (char *digest);
+extern void lang_add_digest_table (void);
+extern void lang_generate_crc (void);
+extern void lang_generate_digest (void);
+extern void lang_set_digest_section (char *section);
+
+/* CRC-32 */
+extern uint32_t *init_crc32_tab (uint32_t poly);
+extern uint32_t calc_crc32_inv
+  (const unsigned char *input_str, size_t num_bytes);
+extern uint32_t calc_crc32 (const unsigned char *input_str, size_t num_bytes);
+
+/* CR-64 */
+extern bfd_vma *init_crc64_tab (bfd_vma poly);
+extern bfd_vma calc_crc64_inv
+  (const unsigned char *input_str, size_t num_bytes);
+extern bfd_vma calc_crc64 (const unsigned char *input_str, size_t num_bytes);
+
+#endif /* LDDIGEST_H */
-- 
2.34.1


^ permalink raw reply	[flat|nested] 12+ messages in thread

* [PATCH v5 09/10] DIGEST: ldmain.c: add CRC calculation
  2023-02-22 16:15 [PATCH v5 0/10 Add support for CRC64 generation in linker binutils
                   ` (7 preceding siblings ...)
  2023-02-22 16:16 ` [PATCH v5 08/10] DIGEST: CRC-32/64 algorithms binutils
@ 2023-02-22 16:16 ` binutils
  2023-02-22 16:16 ` [PATCH v5 10/10] DIGEST: testsuite binutils
  2023-02-22 18:23 ` [PATCH v5 0/10 Add support for CRC64 generation in linker Ulf Samuelsson
  10 siblings, 0 replies; 12+ messages in thread
From: binutils @ 2023-02-22 16:16 UTC (permalink / raw)
  To: binutils; +Cc: nickc, Ulf Samuelsson

From: Ulf Samuelsson <ulf@emagii.com>

Signed-off-by: Ulf Samuelsson <ulf@emagii.com>
---
 ld/ldmain.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/ld/ldmain.c b/ld/ldmain.c
index 25cc89b72f9..6bd17c87469 100644
--- a/ld/ldmain.c
+++ b/ld/ldmain.c
@@ -34,6 +34,7 @@
 #include "ldwrite.h"
 #include "ldexp.h"
 #include "ldlang.h"
+#include "lddigest.h"
 #include <ldgram.h>
 #include "ldlex.h"
 #include "ldfile.h"
@@ -527,6 +528,7 @@ main (int argc, char **argv)
 
   ldwrite ();
 
+  lang_generate_digest();		/* Calculate and store CRC on request */
   if (config.map_file != NULL)
     lang_map ();
   if (command_line.cref)
-- 
2.34.1


^ permalink raw reply	[flat|nested] 12+ messages in thread

* [PATCH v5 10/10] DIGEST: testsuite
  2023-02-22 16:15 [PATCH v5 0/10 Add support for CRC64 generation in linker binutils
                   ` (8 preceding siblings ...)
  2023-02-22 16:16 ` [PATCH v5 09/10] DIGEST: ldmain.c: add CRC calculation binutils
@ 2023-02-22 16:16 ` binutils
  2023-02-22 18:23 ` [PATCH v5 0/10 Add support for CRC64 generation in linker Ulf Samuelsson
  10 siblings, 0 replies; 12+ messages in thread
From: binutils @ 2023-02-22 16:16 UTC (permalink / raw)
  To: binutils; +Cc: nickc, Ulf Samuelsson

From: Ulf Samuelsson <ulf@emagii.com>

All these examples link, but fails in the make check-ld

Signed-off-by: Ulf Samuelsson <ulf@emagii.com>
---
 ld/testsuite/ld-scripts/crc32-poly.d  | 46 ++++++++++++++++++++++++++
 ld/testsuite/ld-scripts/crc32-poly.s  |  9 +++++
 ld/testsuite/ld-scripts/crc32-poly.t  | 38 ++++++++++++++++++++++
 ld/testsuite/ld-scripts/crc32-polyi.d | 45 +++++++++++++++++++++++++
 ld/testsuite/ld-scripts/crc32-polyi.s |  9 +++++
 ld/testsuite/ld-scripts/crc32-polyi.t | 38 ++++++++++++++++++++++
 ld/testsuite/ld-scripts/crc32.d       | 37 +++++++++++++++++++++
 ld/testsuite/ld-scripts/crc32.s       |  9 +++++
 ld/testsuite/ld-scripts/crc32.t       | 39 ++++++++++++++++++++++
 ld/testsuite/ld-scripts/crc64-ecma.d  | 47 +++++++++++++++++++++++++++
 ld/testsuite/ld-scripts/crc64-ecma.s  |  9 +++++
 ld/testsuite/ld-scripts/crc64-ecma.t  | 40 +++++++++++++++++++++++
 ld/testsuite/ld-scripts/crc64-iso.d   | 47 +++++++++++++++++++++++++++
 ld/testsuite/ld-scripts/crc64-iso.s   |  9 +++++
 ld/testsuite/ld-scripts/crc64-iso.t   | 40 +++++++++++++++++++++++
 ld/testsuite/ld-scripts/crc64-poly.d  | 46 ++++++++++++++++++++++++++
 ld/testsuite/ld-scripts/crc64-poly.s  |  9 +++++
 ld/testsuite/ld-scripts/crc64-poly.t  | 40 +++++++++++++++++++++++
 ld/testsuite/ld-scripts/crc64-polyi.d | 47 +++++++++++++++++++++++++++
 ld/testsuite/ld-scripts/crc64-polyi.s |  9 +++++
 ld/testsuite/ld-scripts/crc64-polyi.t | 40 +++++++++++++++++++++++
 ld/testsuite/ld-scripts/script.exp    |  8 +++++
 22 files changed, 661 insertions(+)
 create mode 100644 ld/testsuite/ld-scripts/crc32-poly.d
 create mode 100644 ld/testsuite/ld-scripts/crc32-poly.s
 create mode 100644 ld/testsuite/ld-scripts/crc32-poly.t
 create mode 100644 ld/testsuite/ld-scripts/crc32-polyi.d
 create mode 100644 ld/testsuite/ld-scripts/crc32-polyi.s
 create mode 100644 ld/testsuite/ld-scripts/crc32-polyi.t
 create mode 100644 ld/testsuite/ld-scripts/crc32.d
 create mode 100644 ld/testsuite/ld-scripts/crc32.s
 create mode 100644 ld/testsuite/ld-scripts/crc32.t
 create mode 100644 ld/testsuite/ld-scripts/crc64-ecma.d
 create mode 100644 ld/testsuite/ld-scripts/crc64-ecma.s
 create mode 100644 ld/testsuite/ld-scripts/crc64-ecma.t
 create mode 100644 ld/testsuite/ld-scripts/crc64-iso.d
 create mode 100644 ld/testsuite/ld-scripts/crc64-iso.s
 create mode 100644 ld/testsuite/ld-scripts/crc64-iso.t
 create mode 100644 ld/testsuite/ld-scripts/crc64-poly.d
 create mode 100644 ld/testsuite/ld-scripts/crc64-poly.s
 create mode 100644 ld/testsuite/ld-scripts/crc64-poly.t
 create mode 100644 ld/testsuite/ld-scripts/crc64-polyi.d
 create mode 100644 ld/testsuite/ld-scripts/crc64-polyi.s
 create mode 100644 ld/testsuite/ld-scripts/crc64-polyi.t

diff --git a/ld/testsuite/ld-scripts/crc32-poly.d b/ld/testsuite/ld-scripts/crc32-poly.d
new file mode 100644
index 00000000000..70fb231e116
--- /dev/null
+++ b/ld/testsuite/ld-scripts/crc32-poly.d
@@ -0,0 +1,46 @@
+#source: crc32-poly.s
+#ld: -T crc32-poly.t
+#objdump: -s -j .text
+#notarget: [is_aout_format]
+#xfail: tic4x-*-* tic54x-*-*
+
+.*:     file format .*
+
+Contents of section .text:
+ 1100 434f4445 deadbeef 712c8793 0c110000  CODE....q,......
+ 1110 10240000 04130000 deadbeef 434f4445  .$..........CODE
+ 1120 434f4445 0c110000 ffffffff ffffffff  CODE............
+ 1130 ffffffff ffffffff ffffffff ffffffff  .*
+ 1140 ffffffff ffffffff ffffffff ffffffff  .*
+ 1150 ffffffff ffffffff ffffffff ffffffff  .*
+ 1160 ffffffff ffffffff ffffffff ffffffff  .*
+ 1170 ffffffff ffffffff ffffffff ffffffff  .*
+ 1180 ffffffff ffffffff ffffffff ffffffff  .*
+#...
+ 1f90 ffffffff ffffffff ffffffff ffffffff  .*
+ 1fa0 ffffffff ffffffff ffffffff ffffffff  .*
+ 1fb0 ffffffff ffffffff ffffffff ffffffff  .*
+ 1fc0 ffffffff ffffffff ffffffff ffffffff  .*
+ 1fd0 ffffffff ffffffff ffffffff ffffffff  .*
+ 1fe0 ffffffff ffffffff ffffffff ffffffff  .*
+ 1ff0 ffffffff ffffffff 434f4445 deadbeef  ........CODE....
+ 2000 00000000 d23cc1eb 7b04d96a a9381881  .....<..{..j.8..
+ 2010 f608b2d5 2434733e 8d0c6bbf 5f30aa54  ....$4s>..k._0.T
+ 2020 336c3f16 e150fefd 4868e67c 9a542797  3l?..P..Hh.|.T'.
+ 2030 c5648dc3 17584c28 be6054a9 6c5c9542  .d...XL..`T.l\.B
+ 2040 66d87e2c b4e4bfc7 1ddca746 cfe066ad  f.~,.......F..f.
+ 2050 90d0ccf9 42ec0d12 ebd41593 39e8d478  ....B.......9..x
+ 2060 55b4413a 878880d1 2eb09850 fc8c59bb  U.A:.......P..Y.
+ 2070 a3bcf3ef 71803204 d8b82a85 0a84eb6e  ....q.2...*....n
+ 2080 ccb0fd58 1e8c3cb3 b7b42432 6588e5d9  ...X..<...$2e...
+#...
+ 2380 bb6fab37 69536adc c06b725d 1257b3b6  .o.7iSj..kr].W..
+ 2390 4d6719e2 9f5bd809 3663c088 e45f0163  Mg...[..6c..._.c
+ 23a0 88039421 5a3f55ca f3074d4b 213b8ca0  ...!Z?U...MK!;..
+ 23b0 7e0b26f4 ac37e71f 050fff9e d7333e75  ~.&..7.......3>u
+ 23c0 ddb7d51b 0f8b14f0 a6b30c71 748fcd9a  ...........qt...
+ 23d0 2bbf67ce f983a625 50bbbea4 82877f4f  +.g....%P......O
+ 23e0 eedbea0d 3ce72be6 95df3367 47e3f28c  ....<.+...3gG...
+ 23f0 18d358d8 caef9933 63d781b2 b1eb4059  ..X....3c.....@Y
+ 2400 434f4445 deadbeef 00000000 00000000  CODE............
+#pass
diff --git a/ld/testsuite/ld-scripts/crc32-poly.s b/ld/testsuite/ld-scripts/crc32-poly.s
new file mode 100644
index 00000000000..704b492ae61
--- /dev/null
+++ b/ld/testsuite/ld-scripts/crc32-poly.s
@@ -0,0 +1,9 @@
+    .extern ecc_start
+	.section .text
+main:
+	.long 0x45444F43
+	.long ecc_start
+	.section .data
+	.long 0x9abcdef0
+	.section .bss
+	.long 0
diff --git a/ld/testsuite/ld-scripts/crc32-poly.t b/ld/testsuite/ld-scripts/crc32-poly.t
new file mode 100644
index 00000000000..35224c2cff8
--- /dev/null
+++ b/ld/testsuite/ld-scripts/crc32-poly.t
@@ -0,0 +1,38 @@
+MEMORY {
+  rom : ORIGIN = 0x000000, LENGTH = 0x400000
+  ram : ORIGIN = 0x400000, LENGTH = 0x10000
+}
+
+_start = 0x000000;
+SECTIONS
+{
+  . = 0x1000 + SIZEOF_HEADERS;
+  .text ALIGN (0x100) :
+
+    {
+      FILL(0xFF)
+      QUAD(0xEFBEADDE45444F43);
+      crc32 = .;
+      DIGEST POLY(32, 0xDEADBEEF)(ecc_start , ecc_end)
+      ecc_start = .;
+      LONG(ecc_start)
+      LONG(ecc_end);
+      LONG(ecc_end - ecc_start);
+      QUAD(0x45444F43EFBEADDE);
+      entry = .;
+      *(.text)
+      . = ALIGN(0x100);
+      BYTE(1)
+      . = ALIGN(4096) - 8;
+      QUAD(0xEFBEADDE45444F43);
+      DIGEST TABLE
+      QUAD(0xEFBEADDE45444F43);
+      QUAD(0);
+      ecc_end = .;
+    } > rom
+
+  .data : AT (0x400000) { *(.data) } >ram /* NO default AT>rom */
+  . = ALIGN(0x20);
+  .bss : { *(.bss) } >ram /* NO default AT>rom */
+  /DISCARD/ : { *(*) }
+}
diff --git a/ld/testsuite/ld-scripts/crc32-polyi.d b/ld/testsuite/ld-scripts/crc32-polyi.d
new file mode 100644
index 00000000000..e3b224caeda
--- /dev/null
+++ b/ld/testsuite/ld-scripts/crc32-polyi.d
@@ -0,0 +1,45 @@
+#source: crc32-polyi.s
+#ld: -T crc32-polyi.t
+#objdump: -s -j .text
+#notarget: [is_aout_format]
+#xfail: tic4x-*-* tic54x-*-*
+
+.*:     file format .*
+
+Contents of section .text:
+ 1100 434f4445 deadbeef 8d51a265 0c110000  CODE.....Q.e....
+ 1110 10240000 04130000 deadbeef 434f4445  .$..........CODE
+ 1120 434f4445 0c110000 ffffffff ffffffff  CODE............
+ 1130 ffffffff ffffffff ffffffff ffffffff  .*
+ 1140 ffffffff ffffffff ffffffff ffffffff  .*
+ 1150 ffffffff ffffffff ffffffff ffffffff  .*
+ 1160 ffffffff ffffffff ffffffff ffffffff  .*
+ 1170 ffffffff ffffffff ffffffff ffffffff  .*
+#...
+ 1f80 ffffffff ffffffff ffffffff ffffffff  .*
+ 1f90 ffffffff ffffffff ffffffff ffffffff  .*
+ 1fa0 ffffffff ffffffff ffffffff ffffffff  .*
+ 1fb0 ffffffff ffffffff ffffffff ffffffff  .*
+ 1fc0 ffffffff ffffffff ffffffff ffffffff  .*
+ 1fd0 ffffffff ffffffff ffffffff ffffffff  .*
+ 1fe0 ffffffff ffffffff ffffffff ffffffff  .*
+ 1ff0 ffffffff ffffffff 434f4445 deadbeef  ........CODE....
+ 2000 00000000 96300777 2c610eee ba510999  .....0.w,a...Q..
+ 2010 19c46d07 8ff46a70 35a563e9 a395649e  ..m...jp5.c...d.
+ 2020 3288db0e a4b8dc79 1ee9d5e0 88d9d297  2......y........
+ 2030 2b4cb609 bd7cb17e 072db8e7 911dbf90  +L...|.~.-......
+ 2040 6410b71d f220b06a 4871b9f3 de41be84  d.... .jHq...A..
+ 2050 7dd4da1a ebe4dd6d 51b5d4f4 c785d383  }......mQ.......
+ 2060 56986c13 c0a86b64 7af962fd ecc9658a  V.l...kdz.b...e.
+ 2070 4f5c0114 d96c0663 633d0ffa f50d088d  O\...l.cc=......
+ 2080 c8206e3b 5e10694c e44160d5 727167a2  . n;^.iL.A`.rqg.
+#...
+ 2390 612667a7 f71660d0 4d476949 db776e3e  a&g...`.MGiI.wn>
+ 23a0 4a6ad1ae dc5ad6d9 660bdf40 f03bd837  Jj...Z..f..@.;.7
+ 23b0 53aebca9 c59ebbde 7fcfb247 e9ffb530  S..........G...0
+ 23c0 1cf2bdbd 8ac2baca 3093b353 a6a3b424  ........0..S...$
+ 23d0 0536d0ba 9306d7cd 2957de54 bf67d923  .6......)W.T.g.#
+ 23e0 2e7a66b3 b84a61c4 021b685d 942b6f2a  .zf..Ja...h].+o*
+ 23f0 37be0bb4 a18e0cc3 1bdf055a 8def022d  7..........Z...-
+ 2400 434f4445 deadbeef 00000000 00000000  CODE............
+ #pass
diff --git a/ld/testsuite/ld-scripts/crc32-polyi.s b/ld/testsuite/ld-scripts/crc32-polyi.s
new file mode 100644
index 00000000000..704b492ae61
--- /dev/null
+++ b/ld/testsuite/ld-scripts/crc32-polyi.s
@@ -0,0 +1,9 @@
+    .extern ecc_start
+	.section .text
+main:
+	.long 0x45444F43
+	.long ecc_start
+	.section .data
+	.long 0x9abcdef0
+	.section .bss
+	.long 0
diff --git a/ld/testsuite/ld-scripts/crc32-polyi.t b/ld/testsuite/ld-scripts/crc32-polyi.t
new file mode 100644
index 00000000000..5a7e25a4a9f
--- /dev/null
+++ b/ld/testsuite/ld-scripts/crc32-polyi.t
@@ -0,0 +1,38 @@
+MEMORY {
+  rom : ORIGIN = 0x000000, LENGTH = 0x400000
+  ram : ORIGIN = 0x400000, LENGTH = 0x10000
+}
+
+_start = 0x000000;
+SECTIONS
+{
+  . = 0x1000 + SIZEOF_HEADERS;
+  .text ALIGN (0x100) :
+
+    {
+      FILL(0xFF)
+      QUAD(0xEFBEADDE45444F43);
+      crc32 = .;
+      DIGEST POLYI(32,0xEDB88320)(ecc_start , ecc_end)
+      ecc_start = .;
+      LONG(ecc_start)
+      LONG(ecc_end);
+      LONG(ecc_end - ecc_start);
+      QUAD(0x45444F43EFBEADDE);
+      entry = .;
+      *(.text)
+      . = ALIGN(0x100);
+      BYTE(1)
+      . = ALIGN(4096) - 8;
+      QUAD(0xEFBEADDE45444F43);
+      DIGEST TABLE
+      QUAD(0xEFBEADDE45444F43);
+      QUAD(0);
+      ecc_end = .;
+    } > rom
+
+  .data : AT (0x400000) { *(.data) } >ram /* NO default AT>rom */
+  . = ALIGN(0x20);
+  .bss : { *(.bss) } >ram /* NO default AT>rom */
+  /DISCARD/ : { *(*) }
+}
diff --git a/ld/testsuite/ld-scripts/crc32.d b/ld/testsuite/ld-scripts/crc32.d
new file mode 100644
index 00000000000..4bfba79ef03
--- /dev/null
+++ b/ld/testsuite/ld-scripts/crc32.d
@@ -0,0 +1,37 @@
+#source: crc32.s
+#ld: -T crc32.t
+#objdump: -s -j .text
+#notarget: [is_aout_format]
+#xfail: tic4x-*-* tic54x-*-*
+
+.*:     file format .*
+
+Contents of section .text:
+ 1100 434f4445 deadbeef 8d51a265 0c110000  CODE.....Q.e....
+ 1110 10240000 04130000 deadbeef 434f4445  .$..........CODE
+ 1120 434f4445 0c110000 ffffffff ffffffff  CODE............
+ 1130 ffffffff ffffffff ffffffff ffffffff  .*
+ 1140 ffffffff ffffffff ffffffff ffffffff  .*
+ 1150 ffffffff ffffffff ffffffff ffffffff  .*
+#...
+ 1fe0 ffffffff ffffffff ffffffff ffffffff  .*
+ 1ff0 ffffffff ffffffff 434f4445 deadbeef  ........CODE....
+ 2000 00000000 96300777 2c610eee ba510999  .....0.w,a...Q..
+ 2010 19c46d07 8ff46a70 35a563e9 a395649e  ..m...jp5.c...d.
+ 2020 3288db0e a4b8dc79 1ee9d5e0 88d9d297  2......y........
+ 2030 2b4cb609 bd7cb17e 072db8e7 911dbf90  +L...|.~.-......
+ 2040 6410b71d f220b06a 4871b9f3 de41be84  d.... .jHq...A..
+ 2050 7dd4da1a ebe4dd6d 51b5d4f4 c785d383  }......mQ.......
+ 2060 56986c13 c0a86b64 7af962fd ecc9658a  V.l...kdz.b...e.
+ 2070 4f5c0114 d96c0663 633d0ffa f50d088d  O\...l.cc=......
+ 2080 c8206e3b 5e10694c e44160d5 727167a2  . n;^.iL.A`.rqg.
+#...
+ 2390 612667a7 f71660d0 4d476949 db776e3e  a&g...`.MGiI.wn>
+ 23a0 4a6ad1ae dc5ad6d9 660bdf40 f03bd837  Jj...Z..f..@.;.7
+ 23b0 53aebca9 c59ebbde 7fcfb247 e9ffb530  S..........G...0
+ 23c0 1cf2bdbd 8ac2baca 3093b353 a6a3b424  ........0..S...$
+ 23d0 0536d0ba 9306d7cd 2957de54 bf67d923  .6......)W.T.g.#
+ 23e0 2e7a66b3 b84a61c4 021b685d 942b6f2a  .zf..Ja...h].+o*
+ 23f0 37be0bb4 a18e0cc3 1bdf055a 8def022d  7..........Z...-
+ 2400 434f4445 deadbeef 00000000 00000000  CODE............
+#pass
diff --git a/ld/testsuite/ld-scripts/crc32.s b/ld/testsuite/ld-scripts/crc32.s
new file mode 100644
index 00000000000..704b492ae61
--- /dev/null
+++ b/ld/testsuite/ld-scripts/crc32.s
@@ -0,0 +1,9 @@
+    .extern ecc_start
+	.section .text
+main:
+	.long 0x45444F43
+	.long ecc_start
+	.section .data
+	.long 0x9abcdef0
+	.section .bss
+	.long 0
diff --git a/ld/testsuite/ld-scripts/crc32.t b/ld/testsuite/ld-scripts/crc32.t
new file mode 100644
index 00000000000..51c8f7c834e
--- /dev/null
+++ b/ld/testsuite/ld-scripts/crc32.t
@@ -0,0 +1,39 @@
+MEMORY {
+  rom : ORIGIN = 0x000000, LENGTH = 0x400000
+  ram : ORIGIN = 0x400000, LENGTH = 0x10000
+}
+
+_start = 0x000000;
+SECTIONS
+{
+  . = 0x1000 + SIZEOF_HEADERS;
+  .text ALIGN (0x100) :
+
+    {
+      FILL(0xFF)
+      QUAD(0xEFBEADDE45444F43);
+      crc32 = .;
+      DIGEST "CRC32" (ecc_start , ecc_end)
+      ecc_start = .;
+      LONG(ecc_start)
+      LONG(ecc_end);
+      LONG(ecc_end - ecc_start);
+      QUAD(0x45444F43EFBEADDE);
+      entry = .;
+      *(.text)
+      . = ALIGN(0x100);
+      BYTE(1)
+      . = ALIGN(4096) - 8;
+      QUAD(0xEFBEADDE45444F43);
+      DIGEST TABLE
+      QUAD(0xEFBEADDE45444F43);
+      QUAD(0);
+      ecc_end = .;
+
+    } > rom
+
+  .data : AT (0x400000) { *(.data) } >ram /* NO default AT>rom */
+  . = ALIGN(0x20);
+  .bss : { *(.bss) } >ram /* NO default AT>rom */
+  /DISCARD/ : { *(*) }
+}
diff --git a/ld/testsuite/ld-scripts/crc64-ecma.d b/ld/testsuite/ld-scripts/crc64-ecma.d
new file mode 100644
index 00000000000..a8d197c3323
--- /dev/null
+++ b/ld/testsuite/ld-scripts/crc64-ecma.d
@@ -0,0 +1,47 @@
+#source: crc-ecma.s
+#ld: -T crc-ecma.t
+#objdump: -s -j .text
+#notarget: [is_aout_format]
+#xfail: tic4x-*-* tic54x-*-*
+
+.*:     file format .*
+
+Contents of section .text:
+ 1100 434f4445 deadbeef d89e4425 b46db823  CODE......D%.m.#
+ 1110 10110000 00000000 10280000 00000000  .*
+ 1120 00170000 00000000 deadbeef 434f4445  ............CODE
+ 1130 434f4445 10110000 ffffffff ffffffff  CODE............
+ 1140 ffffffff ffffffff ffffffff ffffffff  .*
+ 1150 ffffffff ffffffff ffffffff ffffffff  .*
+ 1160 ffffffff ffffffff ffffffff ffffffff  .*
+ 1170 ffffffff ffffffff ffffffff ffffffff  .*
+ 1180 ffffffff ffffffff ffffffff ffffffff  .*
+#...
+ 1f80 ffffffff ffffffff ffffffff ffffffff  .*
+ 1f90 ffffffff ffffffff ffffffff ffffffff  .*
+ 1fa0 ffffffff ffffffff ffffffff ffffffff  .*
+ 1fb0 ffffffff ffffffff ffffffff ffffffff  .*
+ 1fc0 ffffffff ffffffff ffffffff ffffffff  .*
+ 1fd0 ffffffff ffffffff ffffffff ffffffff  .*
+ 1fe0 ffffffff ffffffff ffffffff ffffffff  .*
+ 1ff0 ffffffff ffffffff 434f4445 deadbeef  ........CODE....
+ 2000 00000000 00000000 9336eaa9 ebe1f042  .........6.....B
+ 2010 266dd453 d7c3e185 b55b3efa 3c2211c7  &m.S.....[>.<"..
+ 2020 dfec420e 45663349 4cdaa8a7 ae87c30b  ..B.Ef3IL.......
+ 2030 f981965d 92a5d2cc 6ab77cf4 7944228e  ...]....j.|.yD".
+ 2040 bed9851c 8acc6692 2def6fb5 612d96d0  ......f.-.o.a-..
+ 2050 98b4514f 5d0f8717 0b82bbe6 b6ee7755  ..QO].........wU
+ 2060 6135c712 cfaa55db f2032dbb 244ba599  a5....U...-.$K..
+ 2070 47581341 1869b45e d46ef9e8 f388441c  GX.A.i.^.n....D.
+ 2080 ef85e190 ff783d66 7cb30b39 1499cd24  .....x=f|..9...$
+#...
+ 2780 d3db7c26 d56eb886 40ed968f 3e8f48c4  ..|&.n..@...>.H.
+ 2790 f5b6a875 02ad5903 668042dc e94ca941  ...u..Y.f.B..L.A
+ 27a0 0c373e28 90088bcf 9f01d481 7be97b8d  .7>.........{.{.
+ 27b0 2a5aea7b 47cb6a4a b96c00d2 ac2a9a08  *Z.{G.jJ.l...*..
+ 27c0 6d02f93a 5fa2de14 fe341393 b4432e56  m..:_....4...C.V
+ 27d0 4b6f2d69 88613f91 d859c7c0 6380cfd3  Ko-i.a?..Y..c...
+ 27e0 b2eebb34 1ac4ed5d 21d8519d f1251d1f  ...4...]!.Q..%..
+ 27f0 94836f67 cd070cd8 07b585ce 26e6fc9a  ..og........&...
+ 2800 434f4445 deadbeef 00000000 00000000  CODE............
+#pass
diff --git a/ld/testsuite/ld-scripts/crc64-ecma.s b/ld/testsuite/ld-scripts/crc64-ecma.s
new file mode 100644
index 00000000000..704b492ae61
--- /dev/null
+++ b/ld/testsuite/ld-scripts/crc64-ecma.s
@@ -0,0 +1,9 @@
+    .extern ecc_start
+	.section .text
+main:
+	.long 0x45444F43
+	.long ecc_start
+	.section .data
+	.long 0x9abcdef0
+	.section .bss
+	.long 0
diff --git a/ld/testsuite/ld-scripts/crc64-ecma.t b/ld/testsuite/ld-scripts/crc64-ecma.t
new file mode 100644
index 00000000000..be50d102c2b
--- /dev/null
+++ b/ld/testsuite/ld-scripts/crc64-ecma.t
@@ -0,0 +1,40 @@
+MEMORY {
+  rom : ORIGIN = 0x000000, LENGTH = 0x400000
+  ram : ORIGIN = 0x400000, LENGTH = 0x10000
+}
+
+_start = 0x000000;
+SECTIONS
+{
+  . = 0x1000 + SIZEOF_HEADERS;
+  .text ALIGN (0x100) :
+
+    {
+      FILL(0xFF)
+      QUAD(0xEFBEADDE45444F43);
+      crc64 = .;
+      DEBUG ON
+      DIGEST "CRC64-ECMA" (ecc_start , ecc_end)
+      DEBUG OFF
+      ecc_start = .;
+      QUAD(ecc_start)
+      QUAD(ecc_end);
+      QUAD(ecc_end - ecc_start);
+      QUAD(0x45444F43EFBEADDE);
+      entry = .;
+      *(.text)
+      . = ALIGN(0x100);
+      BYTE(1)
+      . = ALIGN(4096) - 8;
+      QUAD(0xEFBEADDE45444F43);
+      DIGEST TABLE
+      QUAD(0xEFBEADDE45444F43);
+      QUAD(0);
+      ecc_end = .;
+    } > rom
+
+  .data : AT (0x400000) { *(.data) } >ram /* NO default AT>rom */
+  . = ALIGN(0x20);
+  .bss : { *(.bss) } >ram /* NO default AT>rom */
+  /DISCARD/ : { *(*) }
+}
diff --git a/ld/testsuite/ld-scripts/crc64-iso.d b/ld/testsuite/ld-scripts/crc64-iso.d
new file mode 100644
index 00000000000..1c4cae43295
--- /dev/null
+++ b/ld/testsuite/ld-scripts/crc64-iso.d
@@ -0,0 +1,47 @@
+#source: crc-iso.s
+#ld: -T crc-iso.t
+#objdump: -s -j .text
+#notarget: [is_aout_format]
+#xfail: tic4x-*-* tic54x-*-*
+
+.*:     file format .*
+
+Contents of section .text:
+ 1100 434f4445 deadbeef 00000000 000000a8  CODE............
+ 1110 10110000 00000000 10280000 00000000  .*
+ 1120 00170000 00000000 deadbeef 434f4445  ............CODE
+ 1130 434f4445 10110000 ffffffff ffffffff  CODE............
+ 1140 ffffffff ffffffff ffffffff ffffffff  .*
+ 1150 ffffffff ffffffff ffffffff ffffffff  .*
+ 1160 ffffffff ffffffff ffffffff ffffffff  .*
+ 1170 ffffffff ffffffff ffffffff ffffffff  .*
+ 1180 ffffffff ffffffff ffffffff ffffffff  .*
+#...
+ 1f80 ffffffff ffffffff ffffffff ffffffff  .*
+ 1f90 ffffffff ffffffff ffffffff ffffffff  .*
+ 1fa0 ffffffff ffffffff ffffffff ffffffff  .*
+ 1fb0 ffffffff ffffffff ffffffff ffffffff  .*
+ 1fc0 ffffffff ffffffff ffffffff ffffffff  .*
+ 1fd0 ffffffff ffffffff ffffffff ffffffff  .*
+ 1fe0 ffffffff ffffffff ffffffff ffffffff  .*
+ 1ff0 ffffffff ffffffff 434f4445 deadbeef  ........CODE....
+ 2000 00000000 00000000 00000000 000000d8  .*
+ 2010 00000000 00000068 00000000 000000b0  .......h........
+ 2020 00000000 000000d0 00000000 00000008  .*
+ 2030 00000000 000000b8 00000000 00000060  ...............`
+ 2040 00000000 00000078 00000000 000000a0  .......x........
+ 2050 00000000 00000010 00000000 000000c8  .*
+ 2060 00000000 000000a8 00000000 00000070  ...............p
+ 2070 00000000 000000c0 00000000 00000018  .*
+ 2080 00000000 000000f0 00000000 00000028  .*
+#...
+ 2780 00000000 00000058 00000000 00000080  .......X........
+ 2790 00000000 00000030 00000000 000000e8  .......0........
+ 27a0 00000000 00000088 00000000 00000050  ...............P
+ 27b0 00000000 000000e0 00000000 00000038  ...............8
+ 27c0 00000000 00000020 00000000 000000f8  ....... ........
+ 27d0 00000000 00000048 00000000 00000090  .......H........
+ 27e0 00000000 000000f0 00000000 00000028  .*
+ 27f0 00000000 00000098 00000000 00000040  ...............@
+ 2800 434f4445 deadbeef 00000000 00000000  CODE............
+#pass
diff --git a/ld/testsuite/ld-scripts/crc64-iso.s b/ld/testsuite/ld-scripts/crc64-iso.s
new file mode 100644
index 00000000000..704b492ae61
--- /dev/null
+++ b/ld/testsuite/ld-scripts/crc64-iso.s
@@ -0,0 +1,9 @@
+    .extern ecc_start
+	.section .text
+main:
+	.long 0x45444F43
+	.long ecc_start
+	.section .data
+	.long 0x9abcdef0
+	.section .bss
+	.long 0
diff --git a/ld/testsuite/ld-scripts/crc64-iso.t b/ld/testsuite/ld-scripts/crc64-iso.t
new file mode 100644
index 00000000000..8f5b85a37e7
--- /dev/null
+++ b/ld/testsuite/ld-scripts/crc64-iso.t
@@ -0,0 +1,40 @@
+MEMORY {
+  rom : ORIGIN = 0x000000, LENGTH = 0x400000
+  ram : ORIGIN = 0x400000, LENGTH = 0x10000
+}
+
+_start = 0x000000;
+SECTIONS
+{
+  . = 0x1000 + SIZEOF_HEADERS;
+  .text ALIGN (0x100) :
+
+    {
+      FILL(0xFF)
+      QUAD(0xEFBEADDE45444F43);
+      crc64 = .;
+      DEBUG OFF
+      DIGEST "CRC64-ISO" (ecc_start , ecc_end)
+      DEBUG OFF
+      ecc_start = .;
+      QUAD(ecc_start)
+      QUAD(ecc_end);
+      QUAD(ecc_end - ecc_start);
+      QUAD(0x45444F43EFBEADDE);
+      entry = .;
+      *(.text)
+      . = ALIGN(0x100);
+      BYTE(1)
+      . = ALIGN(4096) - 8;
+      QUAD(0xEFBEADDE45444F43);
+      DIGEST TABLE
+      QUAD(0xEFBEADDE45444F43);
+      QUAD(0);
+      ecc_end = .;
+    } > rom
+
+  .data : AT (0x400000) { *(.data) } >ram /* NO default AT>rom */
+  . = ALIGN(0x20);
+  .bss : { *(.bss) } >ram /* NO default AT>rom */
+  /DISCARD/ : { *(*) }
+}
diff --git a/ld/testsuite/ld-scripts/crc64-poly.d b/ld/testsuite/ld-scripts/crc64-poly.d
new file mode 100644
index 00000000000..221d61fec4a
--- /dev/null
+++ b/ld/testsuite/ld-scripts/crc64-poly.d
@@ -0,0 +1,46 @@
+#source: crc-poly.s
+#ld: -T crc-poly.t
+#objdump: -s -j .text
+#notarget: [is_aout_format]
+#xfail: tic4x-*-* tic54x-*-*
+
+.*:     file format .*
+
+Contents of section .text:
+ 1100 434f4445 deadbeef 5da495a3 927272b3  CODE....]....rr.
+ 1110 10110000 00000000 10280000 00000000  ................
+ 1120 00170000 00000000 deadbeef 434f4445  ............CODE
+ 1130 434f4445 10110000 ffffffff ffffffff  CODE............
+ 1140 ffffffff ffffffff ffffffff ffffffff  .*
+ 1150 ffffffff ffffffff ffffffff ffffffff  .*
+ 1160 ffffffff ffffffff ffffffff ffffffff  .*
+ 1170 ffffffff ffffffff ffffffff ffffffff  .*
+ 1180 ffffffff ffffffff ffffffff ffffffff  .*
+#...
+ 1f90 ffffffff ffffffff ffffffff ffffffff  .*
+ 1fa0 ffffffff ffffffff ffffffff ffffffff  .*
+ 1fb0 ffffffff ffffffff ffffffff ffffffff  .*
+ 1fc0 ffffffff ffffffff ffffffff ffffffff  .*
+ 1fd0 ffffffff ffffffff ffffffff ffffffff  .*
+ 1fe0 ffffffff ffffffff ffffffff ffffffff  .*
+ 1ff0 ffffffff ffffffff 434f4445 deadbeef  ........CODE....
+ 2000 00000000 00000000 efbeadde efbeadde  .*
+ 2010 31c3f663 30c3f663 de7d5bbd df7d5bbd  1..c0..c.}[..}[.
+ 2020 6286edc7 6086edc7 8d384019 8f384019  b...`....8@..8@.
+ 2030 53451ba4 50451ba4 bcfbb67a bffbb67a  SE..PE.....z...z
+ 2040 2bb27651 2eb27651 c40cdb8f c10cdb8f  +.vQ..vQ........
+ 2050 1a718032 1e718032 f5cf2dec f1cf2dec  .q.2.q.2..-...-.
+ 2060 49349b96 4e349b96 a68a3648 a18a3648  I4..N4....6H..6H
+ 2070 78f76df5 7ef76df5 9749c02b 9149c02b  x.m.~.m..I.+.I.+
+ 2080 5664eda2 5c64eda2 b9da407c b3da407c  Vd..\d....@|..@|
+#...
+ 2780 415af2df 225af2df aee45f01 cde45f01  AZ.."Z...._..._.
+ 2790 709904bc 129904bc 9f27a962 fd27a962  p........'.b.'.b
+ 27a0 23dc1f18 42dc1f18 cc62b2c6 ad62b2c6  #...B....b...b..
+ 27b0 121fe97b 721fe97b fda144a5 9da144a5  ...{r..{..D...D.
+ 27c0 6ae8848e 0ce8848e 85562950 e3562950  j........V.P.V.P
+ 27d0 5b2b72ed 3c2b72ed b495df33 d395df33  [+r.<+r....3...3
+ 27e0 086e6949 6c6e6949 e7d0c497 83d0c497  .niIlniI........
+ 27f0 39ad9f2a 5cad9f2a d61332f4 b31332f4  9..*\..*..2...2.
+ 2800 434f4445 deadbeef 00000000 00000000  CODE............
+#pass
diff --git a/ld/testsuite/ld-scripts/crc64-poly.s b/ld/testsuite/ld-scripts/crc64-poly.s
new file mode 100644
index 00000000000..704b492ae61
--- /dev/null
+++ b/ld/testsuite/ld-scripts/crc64-poly.s
@@ -0,0 +1,9 @@
+    .extern ecc_start
+	.section .text
+main:
+	.long 0x45444F43
+	.long ecc_start
+	.section .data
+	.long 0x9abcdef0
+	.section .bss
+	.long 0
diff --git a/ld/testsuite/ld-scripts/crc64-poly.t b/ld/testsuite/ld-scripts/crc64-poly.t
new file mode 100644
index 00000000000..035e79a26cf
--- /dev/null
+++ b/ld/testsuite/ld-scripts/crc64-poly.t
@@ -0,0 +1,40 @@
+MEMORY {
+  rom : ORIGIN = 0x000000, LENGTH = 0x400000
+  ram : ORIGIN = 0x400000, LENGTH = 0x10000
+}
+
+_start = 0x000000;
+SECTIONS
+{
+  . = 0x1000 + SIZEOF_HEADERS;
+  .text ALIGN (0x100) :
+
+    {
+      FILL(0xFF)
+      QUAD(0xEFBEADDE45444F43);
+      crc64 = .;
+      DEBUG ON
+      DIGEST POLY(64,0xDEADBEEFDEADBEEF)(ecc_start , ecc_end)
+      DEBUG OFF
+      ecc_start = .;
+      QUAD(ecc_start)
+      QUAD(ecc_end);
+      QUAD(ecc_end - ecc_start);
+      QUAD(0x45444F43EFBEADDE);
+      entry = .;
+      *(.text)
+      . = ALIGN(0x100);
+      BYTE(1)
+      . = ALIGN(4096) - 8;
+      QUAD(0xEFBEADDE45444F43);
+      DIGEST TABLE
+      QUAD(0xEFBEADDE45444F43);
+      QUAD(0);
+      ecc_end = .;
+    } > rom
+
+  .data : AT (0x400000) { *(.data) } >ram /* NO default AT>rom */
+  . = ALIGN(0x20);
+  .bss : { *(.bss) } >ram /* NO default AT>rom */
+  /DISCARD/ : { *(*) }
+}
diff --git a/ld/testsuite/ld-scripts/crc64-polyi.d b/ld/testsuite/ld-scripts/crc64-polyi.d
new file mode 100644
index 00000000000..7cbb2703d05
--- /dev/null
+++ b/ld/testsuite/ld-scripts/crc64-polyi.d
@@ -0,0 +1,47 @@
+#source: crc-polyi.s
+#ld: -T crc-polyi.t
+#objdump: -s -j .text
+#notarget: [is_aout_format]
+#xfail: tic4x-*-* tic54x-*-*
+
+.*:     file format .*
+
+Contents of section .text:
+ 1100 434f4445 deadbeef b7f7857f d0d5802a  CODE...........*
+ 1110 10110000 00000000 10280000 00000000  .*
+ 1120 00170000 00000000 deadbeef 434f4445  ............CODE
+ 1130 434f4445 10110000 ffffffff ffffffff  CODE............
+ 1140 ffffffff ffffffff ffffffff ffffffff  .*
+ 1150 ffffffff ffffffff ffffffff ffffffff  .*
+ 1160 ffffffff ffffffff ffffffff ffffffff  .*
+ 1170 ffffffff ffffffff ffffffff ffffffff  .*
+ 1180 ffffffff ffffffff ffffffff ffffffff  .*
+#...
+ 1f80 ffffffff ffffffff ffffffff ffffffff  .*
+ 1f90 ffffffff ffffffff ffffffff ffffffff  .*
+ 1fa0 ffffffff ffffffff ffffffff ffffffff  .*
+ 1fb0 ffffffff ffffffff ffffffff ffffffff  .*
+ 1fc0 ffffffff ffffffff ffffffff ffffffff  .*
+ 1fd0 ffffffff ffffffff ffffffff ffffffff  .*
+ 1fe0 ffffffff ffffffff ffffffff ffffffff  .*
+ 1ff0 ffffffff ffffffff 434f4445 deadbeef  ........CODE....
+ 2000 00000000 00000000 efbeadde efbeadde  .*
+ 2010 31c3f663 30c3f663 de7d5bbd df7d5bbd  1..c0..c.}[..}[.
+ 2020 6286edc7 6086edc7 8d384019 8f384019  b...`....8@..8@.
+ 2030 53451ba4 50451ba4 bcfbb67a bffbb67a  SE..PE.....z...z
+ 2040 2bb27651 2eb27651 c40cdb8f c10cdb8f  +.vQ..vQ........
+ 2050 1a718032 1e718032 f5cf2dec f1cf2dec  .q.2.q.2..-...-.
+ 2060 49349b96 4e349b96 a68a3648 a18a3648  I4..N4....6H..6H
+ 2070 78f76df5 7ef76df5 9749c02b 9149c02b  x.m.~.m..I.+.I.+
+ 2080 5664eda2 5c64eda2 b9da407c b3da407c  Vd..\d....@|..@|
+#...
+ 2780 415af2df 225af2df aee45f01 cde45f01  AZ.."Z...._..._.
+ 2790 709904bc 129904bc 9f27a962 fd27a962  p........'.b.'.b
+ 27a0 23dc1f18 42dc1f18 cc62b2c6 ad62b2c6  #...B....b...b..
+ 27b0 121fe97b 721fe97b fda144a5 9da144a5  ...{r..{..D...D.
+ 27c0 6ae8848e 0ce8848e 85562950 e3562950  j........V)P.V)P
+ 27d0 5b2b72ed 3c2b72ed b495df33 d395df33  [+r.<+r....3...3
+ 27e0 086e6949 6c6e6949 e7d0c497 83d0c497  .niIlniI........
+ 27f0 39ad9f2a 5cad9f2a d61332f4 b31332f4  9..*\..*..2...2.
+ 2800 434f4445 deadbeef 00000000 00000000  CODE............
+ #pass
diff --git a/ld/testsuite/ld-scripts/crc64-polyi.s b/ld/testsuite/ld-scripts/crc64-polyi.s
new file mode 100644
index 00000000000..704b492ae61
--- /dev/null
+++ b/ld/testsuite/ld-scripts/crc64-polyi.s
@@ -0,0 +1,9 @@
+    .extern ecc_start
+	.section .text
+main:
+	.long 0x45444F43
+	.long ecc_start
+	.section .data
+	.long 0x9abcdef0
+	.section .bss
+	.long 0
diff --git a/ld/testsuite/ld-scripts/crc64-polyi.t b/ld/testsuite/ld-scripts/crc64-polyi.t
new file mode 100644
index 00000000000..eefa3c63e68
--- /dev/null
+++ b/ld/testsuite/ld-scripts/crc64-polyi.t
@@ -0,0 +1,40 @@
+MEMORY {
+  rom : ORIGIN = 0x000000, LENGTH = 0x400000
+  ram : ORIGIN = 0x400000, LENGTH = 0x10000
+}
+
+_start = 0x000000;
+SECTIONS
+{
+  . = 0x1000 + SIZEOF_HEADERS;
+  .text ALIGN (0x100) :
+
+    {
+      FILL(0xFF)
+      QUAD(0xEFBEADDE45444F43);
+      crc64 = .;
+      DEBUG OFF
+      DIGEST POLYI(64, 0xDEADBEEFDEADBEEF)(ecc_start , ecc_end)
+      DEBUG OFF
+      ecc_start = .;
+      QUAD(ecc_start)
+      QUAD(ecc_end);
+      QUAD(ecc_end - ecc_start);
+      QUAD(0x45444F43EFBEADDE);
+      entry = .;
+      *(.text)
+      . = ALIGN(0x100);
+      BYTE(1)
+      . = ALIGN(4096) - 8;
+      QUAD(0xEFBEADDE45444F43);
+      DIGEST TABLE
+      QUAD(0xEFBEADDE45444F43);
+      QUAD(0);
+      ecc_end = .;
+    } > rom
+
+  .data : AT (0x400000) { *(.data) } >ram /* NO default AT>rom */
+  . = ALIGN(0x20);
+  .bss : { *(.bss) } >ram /* NO default AT>rom */
+  /DISCARD/ : { *(*) }
+}
diff --git a/ld/testsuite/ld-scripts/script.exp b/ld/testsuite/ld-scripts/script.exp
index 56e12da8e61..9d606ff9008 100644
--- a/ld/testsuite/ld-scripts/script.exp
+++ b/ld/testsuite/ld-scripts/script.exp
@@ -229,6 +229,14 @@ foreach test_script $test_script_list {
 
 run_dump_test "asciz"
 run_dump_test "ascii"
+run_dump_test "crc64-ecma"
+run_dump_test "crc64-iso"
+run_dump_test "crc64-poly"
+run_dump_test "crc64-polyi"
+run_dump_test "crc32"
+run_dump_test "crc32-poly"
+run_dump_test "crc32-polyi"
+
 run_dump_test "align-with-input"
 run_dump_test "pr20302"
 run_dump_test "output-section-types"
-- 
2.34.1


^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH v5 0/10 Add support for CRC64 generation in linker
  2023-02-22 16:15 [PATCH v5 0/10 Add support for CRC64 generation in linker binutils
                   ` (9 preceding siblings ...)
  2023-02-22 16:16 ` [PATCH v5 10/10] DIGEST: testsuite binutils
@ 2023-02-22 18:23 ` Ulf Samuelsson
  10 siblings, 0 replies; 12+ messages in thread
From: Ulf Samuelsson @ 2023-02-22 18:23 UTC (permalink / raw)
  To: binutils; +Cc: nickc

Discovered two bugs (which I fixed locally) so any review should be for 
general concepts.

I will modify the tests so that the CRCs will be computed
on known test data.

As an example:
The CRC64-ECMA run over the 9 characters in the string "123456789"
should generate 0x6C40DF5F0B497347.

So the revised test for CRC64-ECMA will calculate over this string
and store the result, which means that most of the test data
can be ignored.

Here I store the CRC at 0x1120, and the expected value in 0x1110.

      5     1100 434f4445 deadbeef 00000000 00000000 CODE............
      6     1110 4773490b 5fdf406c 00000000 00000000 GsI._.@l........
      7     1120 4773490b 5fdf406c 00000000 00000000 GsI._.@l........
      8     1130 31323334 35363738 3900ffff ffffffff 123456789.......

They match, so this seems to work.

Best Regards

Ulf Samuelsson


On 2023-02-22 17:15, Ulf Samuelsson via Binutils wrote:
> Fifth patchset.
>
> +* The linker script has a new command to insert a timestamp
> +  TIMESTAMP
> +  inserts the current time (seconds since Epoch) as a 64-bit value
> +
> +* The linker script syntax has new commands for debugging a linker script
> +  DEBUG ON  turns on debugging
> +  DEBUG OFF turns off debugging
> +
> +* The linker script syntax has new commands for handling CRC-32/64 calculations
> +  on the '.text' section
> +  It uses code from https://www.libcrc.org/
> +
> +  DIGEST "CRC32"              (start, end)
> +  DIGEST "CRC64-ECMA"         (start, end)
> +  DIGEST "CRC64-ISO"          (start, end)
> +  DIGEST "CRC64-WE"           (start, end)
> +  DIGEST POLY (size, polynome)(start, end)
> +  DIGEST POLYI(size, polynome)(start, end) (inversion during CRC calculation)
> +  DIGEST TABLE
> +  DIGEST SECTION "<section>
>
> ran indent on the new files.
>
> The *.d files in the testsuite was edited to
> reduce size and to remove all '(' characters.
> The new linker can link using the testsuite/ld-script/*.t
> linker files, but they do not pass the 'make check-ld'
> test.
>
> Fourth patchset.
> Get rid of binaries in testsuite.
>
> Here is the third patchset for introducing CRC64 generation.
> This has focused on supporting maintainability of the feature.
> In order to do so, CRC32 generation has been introduced to
> detect issues when extending the linker with another algoritm
> for checking integrity of the image.
> This will simplify adding other algorithms like SHA algoritms
> in the future.
>
> In addition, the TIMESTAMP command is used to store the current time
> in seconds since Epoch is stored in the image.
>
> The main routine for calculating CRCs has been broken down
> in subroutines which allow other algorithms.
>
> An algorithm typically needs
> <type> *init_<algo>_tab( <type> poly )
> <type> calc_<algo>_inv( const unsigned char *input_str, size_t num_bytes );
> <type> calc_<algo>    ( const unsigned char *input_str, size_t num_bytes );
> void lang_add_<algo>_syndrome(bool invert, bfd_vma poly)
> void lang_add_<algo>_table(void)
>
> The common functions are:
> * bool get_text_section_contents(void)
>    This reads the '.text' section and its contents
>    Pointers are stored in the global variables
>    asection *text_section
>    char     *text_contents
> * bool set_crc_checksum(bfd_vma crc, bfd_vma addr, bfd_vma size)
>    Stores the CRC at the index addr. The size of the CRC in bytes is specified.
>    Storing something larger that 64-bit is not supported here.
> * bool symbol_lookup(char *name, bfd_vma *val)
>    Gets the value of a symbol into 'val'. Returns false if not found.
>
> To add CRC32 support means adding the following commands
> * CRC32 CRC32                    '(' crc_start ',' crc_end ')'
> * CRC32 POLY  '[' mustbe_exp ']' '(' crc_start ',' crc_end ')'
> * CRC32 POLYI '[' mustbe_exp ']' '(' crc_start ',' crc_end ')'
>
> ================
> Here is the second patchset for introducing CRC64 generation in the linker
> This is mainly looking at indentation and whitespace errors.
> The patches applies cleanly without whitespace error
> except for the last patch which contains the testsuite.
> When the contents of .text is printed out, sometimes
> the last byte of a line in the CRC table is a space.
> This is reported as a whitespace error.
>
> Supports the following new linker commands:
> * CRC64 ECMA                     '(' crc_start ',' crc_end ')'
> * CRC64 ISO                      '(' crc_start ',' crc_end ')'
> * CRC64 POLY  '[' mustbe_exp ']' '(' crc_start ',' crc_end ')'
> * CRC64 POLYI '[' mustbe_exp ']' '(' crc_start ',' crc_end ')'
> * CRC64 TABLE
>
> ECMA  == 0x42F0E1EBA9EA3693
> ISO   == 0xD800000000000000
> POLY  == Allows your own polynome
> POLYI == Allows your own polynome, with inversion during calc
>
> The CRC is calculated from crc_start to crc_end (not included)
>
> The "CRC64 <polynome> command
> * Allows specifying the polynom (ECMA(default), ISO or your own)
> * Allows for inversion in the CRC calculation (CRC64-WE)
> * Allows specifying the area that should be checked.
> * reserves room for the CRC (8 bytes)
> * Declares a symbol ___CRC64___ for the address of the CRC.
> * Declares a symbol ___CRC64_START___ for the first address of the checked area
> * Declares a symbol ___CRC64_END___ for the first address after the checked area
>
> The symbols names are declared in "checksum.h".
> If the names are unsuitable, it is easy to change.
>
> The CRC TABLE command
>    This is used to speed up the CRC calculation.
> * Creates a 2kB table which speeds up the CRC calculation
> * Can insert the 2kB table into the .text section at current location.
> * Declares a symbol ___CRC64_TABLE___ if the table is inserted.
>
> Comments on the code:
>
> The process of calculation involves:
> * Check if CRC is requested
> * Validation of CRC prerequisites
> * get .text section
> * get .text section contents
> * calculate CRC over the area
> * insert the CRC in the correct location
> ====================================
>
> This version also supports the
> * DEBUG ON
> * DEBUG OFF
> turning on/off yydebug
> I find it useful for debugging the build, but it can easly be removed.
>
> This patch contains a lot of debug output, that is enabled by
> #define DEBUG_CRC 1
> This should be removed in the final version.
>
> The ld.texi stuff needs some more work. Not very experienced with that.
>
> Added an entry in NEWS
>
> Added 4 test cases for the different CRC64 polynome commands.
> All testcases generate a CRC table.
>
> The code is using the libcrc released under an MIT license found in
> * https://www.libcrc.org/
> * https://github.com/lammertb/libcrc/tree/v2.0
> Author:  Lammert Bies
> A license for libcrc is added to the patch.
>
> [PATCH v5 01/10] TIMESTAMP: ldlang: process
> [PATCH v5 02/10] DIGEST: NEWS
> [PATCH v5 03/10] DIGEST: ld.texi
> [PATCH v5 04/10] LIBCRC: license
> [PATCH v5 05/10] DIGEST: ldlex.l
> [PATCH v5 06/10] DIGEST: ldgram.y
> [PATCH v5 07/10] DIGEST: Makefile.am: add new files
> [PATCH v5 08/10] DIGEST: CRC-32/64 algorithms
> [PATCH v5 09/10] DIGEST: ldmain.c: add CRC calculation
> [PATCH v5 10/10] DIGEST: testsuite
>

^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2023-02-22 18:24 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-02-22 16:15 [PATCH v5 0/10 Add support for CRC64 generation in linker binutils
2023-02-22 16:16 ` [PATCH v5 01/10] TIMESTAMP: ldlang: process binutils
2023-02-22 16:16 ` [PATCH v5 02/10] DIGEST: NEWS binutils
2023-02-22 16:16 ` [PATCH v5 03/10] DIGEST: ld.texi binutils
2023-02-22 16:16 ` [PATCH v5 04/10] LIBCRC: license binutils
2023-02-22 16:16 ` [PATCH v5 05/10] DIGEST: ldlex.l binutils
2023-02-22 16:16 ` [PATCH v5 06/10] DIGEST: ldgram.y binutils
2023-02-22 16:16 ` [PATCH v5 07/10] DIGEST: Makefile.am: add new files binutils
2023-02-22 16:16 ` [PATCH v5 08/10] DIGEST: CRC-32/64 algorithms binutils
2023-02-22 16:16 ` [PATCH v5 09/10] DIGEST: ldmain.c: add CRC calculation binutils
2023-02-22 16:16 ` [PATCH v5 10/10] DIGEST: testsuite binutils
2023-02-22 18:23 ` [PATCH v5 0/10 Add support for CRC64 generation in linker Ulf Samuelsson

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).