public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
* [PATCH v7 0/11 Add support for CRC64 generation in linker
@ 2023-03-01 15:45 binutils
  2023-03-01 15:45 ` [PATCH v7 01/11] DIGEST: LICENSING binutils
                   ` (6 more replies)
  0 siblings, 7 replies; 8+ messages in thread
From: binutils @ 2023-03-01 15:45 UTC (permalink / raw)
  To: binutils; +Cc: nickc

Patchset VII

Rebased against master
Fixed whitespace errors
Run indent on CRC files
Moved license to ld directory and renamed to COPYING.<website>
Added comments to COPYING.www.sunshine2k.de explaining what it is.

Patchset six
Commands changes so you always get little endian
but can override this in the linker command file.

  DIGEST "<label>[.BE]" "CRC32"              (start, end)
  DIGEST "<label>[.BE]" "CRC64-ECMA"         (start, end)
  DIGEST "<label>[.BE]" "CRC64-GO-ISO"       (start, end)
  DIGEST "<label>[.BE]" "CRC64-GO-ISO-R"     (start, end)
  DIGEST "<label>[.BE]" "CRC64-WE"           (start, end)
  DIGEST "<label>[.BE]" "CRC64-XZ"           (start, end)
  DIGEST "<label>[.BE]"  POLY (<params>)     (start, end)
  DIGEST TABLE "<label>[.BE]"
  DIGEST SECTION "<section>"

Each command has a label, which gets defined (not include ".BE")

It has been built natively as well as with the following setup
to configure.

  --target=x86_64-pc-linux-gnu
  --target=x86_64-w64-mingw32
  --target=aarch64-linux-gnu
  --target=powerpc64-linux-gnu
  --target=mips-elf
  --enable-targets=all --enable-64-bit-bfd 

A testsuite for all predefined algorithms are added.
The testsuite calculates the CRC for the "123456789"
string which is common.
The expected checksum value is provided.
The check ensures that a table is generated, but does not
check the binary contents of the table.
It is indirectly checked by using the same table for the
algorithm

The "DIGEST POLY" commands are checked by using
the the "CRC32" and "CRC64-ECMA" polynomes and parameters.

There is an online calculator at
http://www.sunshine2k.de/coding/javascript/crc/crc_js.html

There are no testsuites for the DEBUG ON|OFF, TIMESTAMP and
"DIGEST SECTION" commands yet.

The testsuite will fail if "DEBUG ON" is executed due to
verbose output.

The TIMESTAMP output varies with time and is difficult to test.

The DIGEST SECTION command is not tested, because this
need a little extra discussion.
I have not seen any other suitable sections being generated.

Since the information at http://www.sunshine2k.de/ has
been very useful, their license (MIT) is added.

Code examples for the CRC check routines that needs to be in the
user source is added to the documentation with copyright statements.
Should they be there, or is it enough to have the license
in the source code?

The Makefile.in is manually generated since I had a HDD crash
and upgraded to a new disk and installed Ubuntu 22.04.
The autotools are upgraded to 2.71. The build system
did not like this, so I installed 2.69.
This changes a lot more than the autotools-2.69 in Ubuntu 18.04
so I resorted to manual edit of Makefile.in.

Maybe someone should run autotools and generate this automatically
instead of applying the the manual edit.

Added instructions to build ldint.pdf which is not buildable today.

The system has only been tested on a PC == little endian.
I do not have a big endian host, but maybe someone could
test it on such a host.

The way endianess is implemented, it is easy for the user
to supply a workaround by specifying another endianess.



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 v7 01/11] DIGEST: LICENSING
[PATCH v7 02/11] DIGEST: NEWS
[PATCH v7 03/11] DIGEST: Documentation
[PATCH v7 04/11] DIGEST: testsuite
[PATCH v7 05/11] DIGEST: ldlex.l
[PATCH v7 06/11] DIGEST: ldgram.y
[PATCH v7 07/11] DIGEST: ldmain.c
[PATCH v7 08/11] DIGEST: ldlang.*: add timestamp
[PATCH v7 09/11] DIGEST: calculation
[PATCH v7 10/11] DIGEST: Makefile.*
[PATCH v7 11/11] Build ldint


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

* [PATCH v7 01/11] DIGEST: LICENSING
  2023-03-01 15:45 [PATCH v7 0/11 Add support for CRC64 generation in linker binutils
@ 2023-03-01 15:45 ` binutils
  2023-03-01 15:45 ` [PATCH v7 02/11] DIGEST: NEWS binutils
                   ` (5 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: binutils @ 2023-03-01 15:45 UTC (permalink / raw)
  To: binutils; +Cc: nickc, Ulf Samuelsson

From: Ulf Samuelsson <ulf@emagii.com>

Signed-off-by: Ulf Samuelsson <ulf@emagii.com>
---
 ld/COPYING.www.libcrc.org    | 45 ++++++++++++++++++++++++++++++++++++
 ld/COPYING.www.sunshine2k.de | 25 ++++++++++++++++++++
 2 files changed, 70 insertions(+)
 create mode 100755 ld/COPYING.www.libcrc.org
 create mode 100644 ld/COPYING.www.sunshine2k.de

diff --git a/ld/COPYING.www.libcrc.org b/ld/COPYING.www.libcrc.org
new file mode 100755
index 00000000000..e8b7226ab89
--- /dev/null
+++ b/ld/COPYING.www.libcrc.org
@@ -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.
diff --git a/ld/COPYING.www.sunshine2k.de b/ld/COPYING.www.sunshine2k.de
new file mode 100644
index 00000000000..636496fe047
--- /dev/null
+++ b/ld/COPYING.www.sunshine2k.de
@@ -0,0 +1,25 @@
+The ld.bfd linker contains code from the http://www.sunshine2k.de/ website
+This code is released under the license below
+================================================================================
+All content of this website is released under the MIT license as follows:
+
+Copyright (c) 2021 Bastian Molkenthin
+
+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.
+================================================================================
-- 
2.34.1


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

* [PATCH v7 02/11] DIGEST: NEWS
  2023-03-01 15:45 [PATCH v7 0/11 Add support for CRC64 generation in linker binutils
  2023-03-01 15:45 ` [PATCH v7 01/11] DIGEST: LICENSING binutils
@ 2023-03-01 15:45 ` binutils
  2023-03-01 15:45 ` [PATCH v7 03/11] DIGEST: Documentation binutils
                   ` (4 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: binutils @ 2023-03-01 15:45 UTC (permalink / raw)
  To: binutils; +Cc: nickc, Ulf Samuelsson

From: Ulf Samuelsson <ulf@emagii.com>

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

diff --git a/ld/NEWS b/ld/NEWS
index 4b91f2c3b0a..e245d3da4dc 100644
--- a/ld/NEWS
+++ b/ld/NEWS
@@ -1,5 +1,77 @@
 -*- 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 "<label>[.BE]" "CRC32"              (start, end)
+  DIGEST "<label>[.BE]" "CRC64-ECMA"         (start, end)
+  DIGEST "<label>[.BE]" "CRC64-GO-ISO"       (start, end)
+  DIGEST "<label>[.BE]" "CRC64-GO-ISO-R"     (start, end)
+  DIGEST "<label>[.BE]" "CRC64-WE"           (start, end)
+  DIGEST "<label>[.BE]" "CRC64-XZ"           (start, end)
+  DIGEST "<label>[.BE]"  POLY (<params>)     (start, end)
+  DIGEST TABLE "<label>[.BE]"
+  DIGEST SECTION "<section>"
+
+  The CRC32, CRC64-ECMA, CRC64-ISO, CRC64-WE and POLY defines
+  the polynome to use and reserves space for the 32/64-bit CRC in the
+  current section (default ".text"). It also defines a label "<label>".
+
+  When generating a custom polynome you have to supply parameters
+  in the  following order
+  * size            {32 | 64 }
+  * polynome
+  * initial         initial value of crc
+  * xor value       xor with this before returning result
+  * input reflect   bitreverse input data
+  * output reflect  bitreverse result
+  * reciprocal      bitreverse polynome
+
+  These terms are explained at
+  http://www.sunshine2k.de/articles/coding/crc/understanding_crc.html
+
+  The checksum is generated in little endian format, but this
+  can be overridden by adding a ".BE" modifier to the label string.
+  The generated label does not include the modifier.
+
+  The user can do the CRC check in another section through the
+  DIGEST SECTION command by specifying the name of the section.
+
+  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.
+  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"
@@ -41,16 +113,16 @@ Changes in 2.39:
   re-enabled via the --warn-rwx-segments option.
 
   New configure options can also control these new features:
-  
+
   --enable-warn-execstack=no
      will disable the warnings about creating an executable stack.
-     
+
   --enable-warn-execstack=yes
      will make --warn-execstack enabled by default.
-     
+
   --enable-warn-rwx-segments=no
      will make --no-warn-rwx-segments enabled by default.
-     
+
   --enable-default-execstack=no
      will stop the creation of an executable stack simply because an input file
      is missing a .note.GNU-stack section, even on architectures where this
-- 
2.34.1


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

* [PATCH v7 03/11] DIGEST: Documentation
  2023-03-01 15:45 [PATCH v7 0/11 Add support for CRC64 generation in linker binutils
  2023-03-01 15:45 ` [PATCH v7 01/11] DIGEST: LICENSING binutils
  2023-03-01 15:45 ` [PATCH v7 02/11] DIGEST: NEWS binutils
@ 2023-03-01 15:45 ` binutils
  2023-03-01 15:45 ` [PATCH v7 04/11] DIGEST: testsuite binutils
                   ` (3 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: binutils @ 2023-03-01 15:45 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 | 514 ++++++++++++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 510 insertions(+), 4 deletions(-)

diff --git a/ld/ld.texi b/ld/ld.texi
index 3367075cae8..fd992d4480c 100644
--- a/ld/ld.texi
+++ b/ld/ld.texi
@@ -5302,7 +5302,7 @@ __stop_SECNAME, where SECNAME is the name of the section.  These
 indicate the start address and end address of the output section
 respectively.  Note: most section names are not representable as
 C identifiers because they contain a @samp{.} character.
-
+@page
 @node Output Section Data
 @subsection Output Section Data
 @cindex data
@@ -5353,10 +5353,28 @@ whereas this will work:
 @smallexample
 SECTIONS @{@ .text : @{@ *(.text) ; LONG(1) @}@ .data : @{@ *(.data) @}@ @}@
 @end smallexample
-
+@page
 @cindex output section strings
 @kindex ASCII (@var{expression}) ``@var{string}''
 @kindex ASCIZ ``@var{string}''
+@code{ASCII strings}
+@sp 1
+@multitable @columnfractions .25 .20 .30 .20 .05
+@item
+ASCIZ
+@tab
+@tab
+"<string"
+@tab
+@item
+ASCII
+@tab
+(<size>)
+@tab
+"<string"
+@tab
+@end multitable
+@sp 1
 You can include a zero-terminated string in an output section by using
 @code{ASCIZ}.  The keyword is followed by a string which is stored at
 the current value of the location counter including adding a zero byte
@@ -5381,18 +5399,506 @@ it must be enclosed in double quotes.
 The string can have C escape characters like '\n', '\r', '\t' and
 octal numbers.  The '\"' escape is not supported.  Nor are escaped hex
 values.
-
+@sp 2
 Example 1: This is string of 16 characters and will create a 32 byte
 area:
 @smallexample
   ASCII (32) "This is 16 bytes"
 @end smallexample
-
+@sp 2
 Example 2: This is a string of 16 characters and will create a 17 byte
 area:
 @smallexample
   ASCIZ "This is 16 bytes"
 @end smallexample
+@page
+@cindex output section strings
+@kindex DIGEST "<label>[.BE]" "CRC64-ECMA"   (@var{expr}, @var{expr})
+@kindex DIGEST "<label>[.BE]" "CRC64-ISO"    (@var{expr}, @var{expr})
+@kindex DIGEST "<label>[.BE]" "CRC64-ISO-R"  (@var{expr}, @var{expr})
+@kindex DIGEST "<label>[.BE]" "CRC64-WE"     (@var{expr}, @var{expr})
+@kindex DIGEST "<label>[.BE]" "CRC64-XZ"     (@var{expr}, @var{expr})
+@kindex DIGEST "<label>[.BE]" "CRC32"        (@var{expr}, @var{expr})
+@kindex DIGEST "<label>[.BE]"  POLY (@var{<parms>}) (@var{expr}, @var{expr})
+
+@code{CRC Calculation}
+@sp 1
+@multitable @columnfractions .25 .20 .30 .20 .05
+@item
+DIGEST
+@tab
+"<label>[.BE]"
+@tab
+"CRC32"
+@tab
+(start, end)
+@item
+DIGEST
+@tab
+"<label>[.BE]"
+@tab
+"CRC64-ECMA"
+@tab
+(start, end)
+@item
+DIGEST
+@tab
+"<label>[.BE]"
+@tab
+"CRC64-GO-ISO"
+@tab
+(start, end)
+@item
+DIGEST
+@tab
+"<label>[.BE]"
+@tab
+"CRC64-GO-ISO-R"
+@tab
+(start, end)
+@item
+DIGEST
+@tab
+"<label>[.BE]"
+@tab
+"CRC64-WE"
+@tab
+(start, end)
+@item
+DIGEST
+@tab
+"<label>[.BE]"
+@tab
+"CRC64-XZ"
+@tab
+(start, end)
+@item
+DIGEST
+@tab
+"<label>[.BE]"
+@tab
+POLY (<params>)
+@tab
+(start, end)
+@item
+DIGEST TABLE
+@tab
+"<label>[.BE]"
+@tab
+@tab
+(start, end)
+@item
+DIGEST SECTION
+@tab
+"<section>"
+@tab
+@tab
+@end multitable
+
+You can calculate the CRC of a part of an output section through the
+@code{DIGEST} command. The default section is the @code{".text"} section.
+The commands take parameters for a label, a @code{polynome} and then two more,
+specifying range of the checked area.  The end address is the first address
+past the checked area.
+
+The checksum is generated in little endian format, but this
+can be overridden by adding a @code{.BE} modifier to the label string.
+The generated label does not include the modifier.
+@sp 1
+There is one predefined 32-bit polynome
+
+@multitable @columnfractions .3 .4 .4
+@item
+* @code{CRC32}
+@tab
+@code{0x04C11DB7}
+@tab
+@end multitable
+
+There are five predefined 64-bit polynomes
+
+@multitable @columnfractions .3 .4 .4
+@item
+* @code{CRC64-ECMA}
+@tab
+@code{0x42F0E1EBA9EA3693}
+@tab
+@item
+* @code{CRC64-ISO}
+@tab
+@code{0x000000000000001B}
+@tab
+@item
+* @code{CRC64-ISO-R}
+@tab
+@code{0xD800000000000000}
+@tab
+@item
+* @code{CRC64-WE}
+@tab
+@code{0x42F0E1EBA9EA3693}
+@tab
+@item
+* @code{CRC64-XZ}
+@tab
+@code{0x42F0E1EBA9EA3693}
+@tab
+@end multitable
+@sp 1
+You can also select your own @code{polynome} using the @code{DIGEST POLY}.
+
+It takes the following @code{parameters} separated by commas.
+
+@multitable @columnfractions .3 .7
+@item
+@code{size}
+@tab
+size of CRC (32 or 64)
+@item
+@code{polynome}
+@tab
+@item
+@code{initial}
+@tab
+initial value of crc before calculation
+@item
+@code{xor}
+@tab
+xor result before return
+@item
+@code{input reflect}
+@tab
+bitreverse input data
+@item
+@code{output reflect}
+@tab
+bitreverse result (before xor'ing)
+@item
+@code{reciprocal}
+@tab
+bitreverse polynome before generating table
+@end multitable
+
+The parameters are explained in detail in
+
+@code{http://www.sunshine2k.de/articles/coding/crc/understanding_crc.html}
+
+Some of the predefined polynomes are the same, but differs in the other
+parameters.
+@page
+The 32-bit <polynome> command defines the following global symbols.
+
+@multitable @columnfractions .3 .7
+@item
+@code{___CRC32___}
+@tab
+address of the CRC32 checksum
+@item
+@code{___CRC32_START___}
+@tab
+first address in the checked area.
+@item
+@code{___CRC32_END___}
+@tab
+first address past the checked area.
+@end multitable
+@sp 2
+The 64-bit <polynome> command defines the following global symbols.
+
+@multitable @columnfractions .3 .7
+@item
+@code{___CRC64___}
+@tab
+address of the CRC64 checksum
+@item
+@code{___CRC64_START___}
+@tab
+first address in the checked area.
+@item
+@code{___CRC64_END___}
+@tab
+first address past the checked area.
+@end multitable
+@sp 2
+Note: The generated CRC value must be stored outside the checked area.
+@sp 2
+Example 1: This request a CRC check using the @code{ECMA} algorithm
+
+@smallexample
+  DIGEST "C64" "CRC64-ECMA" (START_CHECK,END_TEXT)
+@end smallexample
+
+The user can retrieve the CRC value through the @code{C64} label.
+@sp 2
+Example 2: This request a CRC check using the @code{ISO} algorithm
+
+           The checksum is stored as big endian
+
+@smallexample
+  DIGEST "C64I.BE" "CRC64-ISO" (START_CHECK,END_TEXT)
+@end smallexample
+
+The user can retrieve the big endian CRC value through the @code{C64I} label.
+@sp 2
+Example 3: This request a CRC check using a user defined @code{polynome}
+
+           The setup is the "CRC32" algorithm
+
+@smallexample
+  DIGEST "CRC" POLY (32, 0x04C11DB7,~0,~0,1,1,0) (START_CHECK,END_TEXT)
+@end smallexample
+
+The user can retrieve the CRC value through the @code{CRC} label.
+@sp 2
+Example 4: This request a CRC check using the @code{CRC32} polynome
+
+@smallexample
+  DIGEST "C32.SE" (START_CHECK,END_TEXT)
+@end smallexample
+
+The user can retrieve the CRC value through the @code{C32} label.
+
+@page
+@cindex output section strings
+@kindex DIGEST TABLE "<label>[.BE]"
+@page
+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 the label supplied as a parameter.
+The table will be in small endian, unless the @code{.BE} extension is given
+to the label. It also defines a symbol based 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
+
+@sp 2
+Example 1: Generate a 1 kB table
+
+(assuming a previous @code{DIGEST "CRC32"} command)
+
+@smallexample
+  DIGEST TABLE "crc_tab32"
+@end smallexample
+
+The user must declare @code{extern uint32_t *crc_tab32;} in his code.
+@sp 2
+Example 2: Generate a 2 kB table in big endian format.
+
+(assuming a previous @code{DIGEST "CRC64-###"} command)
+
+@smallexample
+  DIGEST TABLE "crc_tab64.be"
+@end smallexample
+
+The user must declare @code{extern uint64_t *crc_tab64;} in his code.
+@sp 2
+The default section is the @code{".text"} section but the user can
+specify another section using the @code{DIGEST SECTION <section>} command.
+@sp 1
+Example 1: Calculate the CRC in a @code{".aux"} section.
+
+@smallexample
+  DIGEST SECTION ".aux"
+@end smallexample
+@sp 1
+The @code{DIGEST <polynome>} and @code{DIGEST TABLE} commands must be in
+the @code{".aux"} section.
+@page
+
+Using the tables:
+           The user must include CRC code in the application to test the CRC
+@sp 2
+
+@multitable @columnfractions .15 .85
+@item
+Example 1:
+@tab
+Calculating CRC-64
+@end multitable
+@sp 1
+@multitable @columnfractions .05 .95
+@item
+@tab
+Copyright (c) 2016 Lammert Bies
+@item
+@tab
+Copyright (c) 2021 Bastian Molkenthin
+@item
+@tab
+Copyright (c) 2023 Ulf Samuelsson
+@end multitable
+@sp 2
+@smallexample
+#define SHIFT(t)   ((sizeof(t)-1)*8)
+uint64_t calc_crc64
+  (algorithm_desc_t * dsc, const unsigned char *input_str, size_t num_bytes)
+@{
+  uint64_t crc;
+  const unsigned char *ptr;
+  uint64_t *crc_tab = dsc->crc_tab;
+  uint64_t index;
+
+  if ((ptr = input_str) == NULL)
+    return 0;
+
+  if (crc_tab == NULL)
+    return 0;
+
+
+  crc = dsc->initial;
+  if (dsc->reciprocal)
+    @{
+      for (uint32_t i = 0; i < num_bytes; i++)
+        @{
+          index = ((crc >> 0) ^ (uint64_t) * ptr++) & 0x00000000000000FFull;
+          crc = (crc >> 8) ^ crc_tab[index];
+        @}
+    @}
+  else
+    @{
+      uint32_t shift = SHIFT (uint64_t);
+      for (uint32_t i = 0; i < num_bytes; i++)
+        @{
+          const unsigned char c = *ptr++;
+          uint64_t rc = (uint64_t) (dsc->ireflect ? reflect8 (c) : c);
+          crc = (crc ^ (rc << shift));
+          index = (uint32_t) (crc >> shift);
+          crc = (crc << 8);
+          crc = (crc ^ (crc_tab[index]));
+        @}
+    @}
+  crc = (dsc->oreflect ? reflect64 (crc) : crc);
+  crc = crc ^ dsc->xor_val;
+  return crc;
+@}  /* calc_crc64 */
+@end smallexample
+@page
+@multitable @columnfractions .15 .85
+@item
+Example 2:
+@tab
+Calculating CRC-32
+@end multitable
+@sp 1
+@multitable @columnfractions .05 .95
+@item
+@tab
+Copyright (c) 2016 Lammert Bies
+@item
+@tab
+Copyright (c) 2021 Bastian Molkenthin
+@item
+@tab
+Copyright (c) 2023 Ulf Samuelsson
+@end multitable
+@sp 2
+@smallexample
+#define SHIFT(t)   ((sizeof(t)-1)*8)
+uint32_t
+calc_crc32 (algorithm_desc_t * dsc, const unsigned char *input_str,
+            size_t num_bytes)
+@{
+  uint32_t crc;
+  const unsigned char *ptr;
+  uint32_t index;
+  uint32_t *crc_tab = dsc->crc_tab;
+
+  if ((ptr = input_str) == NULL)
+    return 0;
+
+  if (crc_tab == NULL)
+    return 0;
+
+  crc = dsc->initial;
+
+  if (dsc->reciprocal)
+    @{
+      for (uint32_t i = 0; i < num_bytes; i++)
+        @{
+          index = ((crc >> 0) ^ (uint32_t) * ptr++) & 0x000000FFul;
+          crc = (crc >> 8) ^ crc_tab[index];
+        @}
+    @}
+  else
+    @{
+      uint32_t shift = SHIFT (uint32_t);
+      for (uint32_t i = 0; i < num_bytes; i++)
+        @{
+          const unsigned char c = *ptr++;
+          uint32_t rc = (uint32_t) (dsc->ireflect ? reflect8 (c) : c);
+          crc = (crc ^ (rc << shift));
+          index = (uint32_t) (crc >> shift);
+          crc = (crc << 8);
+          crc = (crc ^ (crc_tab[index]));
+        @}
+    @}
+  crc = (dsc->oreflect ? reflect32 (crc) : crc);
+  crc = crc ^ dsc->xor_val;
+  return crc;
+@} /* calc_crc32 */
+@end smallexample
+@page
+@multitable @columnfractions .15 .85
+@item
+Example 3:
+@tab
+Calculating CRC-32 using optimized routine
+@end multitable
+@sp 1
+@multitable @columnfractions .05 .95
+@item
+@tab
+Copyright (c) 2016 Lammert Bies
+@item
+@tab
+Copyright (c) 2021 Bastian Molkenthin
+@item
+@tab
+Copyright (c) 2023 Ulf Samuelsson
+@end multitable
+@sp 2
+@smallexample
+#define SHIFT(t)   ((sizeof(t)-1)*8)
+extern uint32_t *crc_tab;
+
+uint32_t
+calc_crc32 (const unsigned char *input_str, size_t num_bytes)
+@{
+  uint32_t crc;
+  const unsigned char *ptr;
+  uint32_t index;
+  uint32_t shift = SHIFT (uint32_t);
+
+  if ((ptr = input_str) == NULL)
+    return 0;
+
+  crc = 0xFFFFFFFF;
+  for (uint32_t i = 0; i < num_bytes; i++)
+    @{
+      const unsigned char c = *ptr++;
+      crc = (crc ^ (c << shift));
+      index = (uint32_t) (crc >> shift);
+      crc = (crc << 8);
+      crc = (crc ^ (crc_tab[index]));
+    @}
+  return crc ^ 0xFFFFFFFF;
+@} /* calc_crc32 */
+@end smallexample
+@page
+@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
-- 
2.34.1


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

* [PATCH v7 04/11] DIGEST: testsuite
  2023-03-01 15:45 [PATCH v7 0/11 Add support for CRC64 generation in linker binutils
                   ` (2 preceding siblings ...)
  2023-03-01 15:45 ` [PATCH v7 03/11] DIGEST: Documentation binutils
@ 2023-03-01 15:45 ` binutils
  2023-03-01 15:45 ` [PATCH v7 05/11] DIGEST: ldlex.l binutils
                   ` (2 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: binutils @ 2023-03-01 15:45 UTC (permalink / raw)
  To: binutils; +Cc: nickc, Ulf Samuelsson

From: Ulf Samuelsson <ulf@emagii.com>

Signed-off-by: Ulf Samuelsson <ulf@emagii.com>
---
 ld/testsuite/ld-scripts/begin_tag.inc       |  9 +++++
 ld/testsuite/ld-scripts/crc32-poly.d        | 24 +++++++++++
 ld/testsuite/ld-scripts/crc32-poly.s        | 21 ++++++++++
 ld/testsuite/ld-scripts/crc32-poly.t        | 42 ++++++++++++++++++++
 ld/testsuite/ld-scripts/crc32.d             | 24 +++++++++++
 ld/testsuite/ld-scripts/crc32.s             | 21 ++++++++++
 ld/testsuite/ld-scripts/crc32.t             | 41 +++++++++++++++++++
 ld/testsuite/ld-scripts/crc64-ecma.d        | 24 +++++++++++
 ld/testsuite/ld-scripts/crc64-ecma.s        | 21 ++++++++++
 ld/testsuite/ld-scripts/crc64-ecma.t        | 44 +++++++++++++++++++++
 ld/testsuite/ld-scripts/crc64-iso.d         | 24 +++++++++++
 ld/testsuite/ld-scripts/crc64-iso.s         | 21 ++++++++++
 ld/testsuite/ld-scripts/crc64-iso.t         | 43 ++++++++++++++++++++
 ld/testsuite/ld-scripts/crc64-iso_be.d      | 24 +++++++++++
 ld/testsuite/ld-scripts/crc64-iso_be.s      | 21 ++++++++++
 ld/testsuite/ld-scripts/crc64-iso_be.t      | 43 ++++++++++++++++++++
 ld/testsuite/ld-scripts/crc64-poly.d        | 24 +++++++++++
 ld/testsuite/ld-scripts/crc64-poly.s        | 21 ++++++++++
 ld/testsuite/ld-scripts/crc64-poly.t        | 43 ++++++++++++++++++++
 ld/testsuite/ld-scripts/crc_data.inc        |  9 +++++
 ld/testsuite/ld-scripts/digest_table.inc    |  6 +++
 ld/testsuite/ld-scripts/digest_table_be.inc |  6 +++
 ld/testsuite/ld-scripts/end_tag.inc         |  9 +++++
 ld/testsuite/ld-scripts/script.exp          |  7 ++++
 24 files changed, 572 insertions(+)
 create mode 100644 ld/testsuite/ld-scripts/begin_tag.inc
 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.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-iso_be.d
 create mode 100644 ld/testsuite/ld-scripts/crc64-iso_be.s
 create mode 100644 ld/testsuite/ld-scripts/crc64-iso_be.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/crc_data.inc
 create mode 100644 ld/testsuite/ld-scripts/digest_table.inc
 create mode 100644 ld/testsuite/ld-scripts/digest_table_be.inc
 create mode 100644 ld/testsuite/ld-scripts/end_tag.inc

diff --git a/ld/testsuite/ld-scripts/begin_tag.inc b/ld/testsuite/ld-scripts/begin_tag.inc
new file mode 100644
index 00000000000..ef395bbe717
--- /dev/null
+++ b/ld/testsuite/ld-scripts/begin_tag.inc
@@ -0,0 +1,9 @@
+      BYTE(0x43);
+      BYTE(0x4F);
+      BYTE(0x44);
+      BYTE(0x45);
+      BYTE(0xDE);
+      BYTE(0xAD);
+      BYTE(0xBE);
+      BYTE(0xEF);
+      QUAD(0);
diff --git a/ld/testsuite/ld-scripts/crc32-poly.d b/ld/testsuite/ld-scripts/crc32-poly.d
new file mode 100644
index 00000000000..028ef14460f
--- /dev/null
+++ b/ld/testsuite/ld-scripts/crc32-poly.d
@@ -0,0 +1,24 @@
+#source: crc32-poly.s
+#ld: -T crc32-poly.t
+#objdump: -s -j .text
+#target: [is_elf_format] [is_coff_format]
+#notarget: [is_aout_format]
+#xfail: tic4x-*-* tic54x-*-*
+
+.*:     file format .*
+
+Contents of section .text:
+ 1200 434f4445 deadbeef 00000000 00000000  CODE............
+ 1210 cbf43926 00000000 00000000 00000000  ..9&............
+ 1220 cbf43926 00000000 00000000 00000000  ..9&............
+ 1230 00000000 00000000 deadbeef 434f4445  ............CODE
+ 1240 31323334 35363738 3900ffff ffffffff  123456789.......
+ 1250 434f4445 00000000 00000000 00000000  CODE............
+ 1260 ffffffff ffffffff ffffffff ffffffff  .*
+#...
+ 17e0 434f4445 deadbeef 00000000 00000000  CODE............
+ 17f0 44494745 53542054 41424c45 00000000  DIGEST TABLE....
+#...
+ 1c00 454e4420 5441424c 45000000 00000000  END TABLE.......
+ 1c10 00000000 00000000 deadbeef 434f4445  ............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..e4ffb15af62
--- /dev/null
+++ b/ld/testsuite/ld-scripts/crc32-poly.s
@@ -0,0 +1,21 @@
+    .extern ecc_start
+	.section .text
+main:
+	.byte 0x43
+	.byte 0x4F
+	.byte 0x44
+	.byte 0x45
+    .long 0
+    .long 0
+    .long 0
+	.section .data
+    .byte 0xde
+    .byte 0xad
+    .byte 0xde
+    .byte 0xad
+    .byte 0xde
+    .byte 0xad
+    .byte 0xbe
+    .byte 0xef
+	.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..15acfa54500
--- /dev/null
+++ b/ld/testsuite/ld-scripts/crc32-poly.t
@@ -0,0 +1,42 @@
+MEMORY {
+  rom : ORIGIN = 0x000000, LENGTH = 0x400000
+  ram : ORIGIN = 0x400000, LENGTH = 0x10000
+}
+
+_start = 0x000000;
+SECTIONS
+{
+  . = 0x1000 + SIZEOF_HEADERS;
+  .text ALIGN (0x200) :
+
+    {
+      FILL(0xFF)
+      header = .;
+      INCLUDE "begin_tag.inc"
+
+      expected = .;
+      BYTE(0xCB);
+      BYTE(0xF4);
+      BYTE(0x39);
+      BYTE(0x26);
+      LONG(0x0);
+      QUAD(0x0);
+
+
+      crc32 = .;
+      DIGEST "_CRC32.BE" POLY(32, 0x04C11DB7, 0xFFFFFFFF,0xFFFFFFFF,1,1,0 )(ecc_start , ecc_end)
+      LONG(0);
+      QUAD(0);
+
+      INCLUDE "end_tag.inc"
+
+      INCLUDE "crc_data.inc"
+
+      INCLUDE "digest_table.inc"
+    } > 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..c154fb579f4
--- /dev/null
+++ b/ld/testsuite/ld-scripts/crc32.d
@@ -0,0 +1,24 @@
+#source: crc32.s
+#ld: -T crc32.t
+#objdump: -s -j .text
+#target: [is_elf_format] [is_coff_format]
+#notarget: [is_aout_format]
+#xfail: tic4x-*-* tic54x-*-*
+
+.*:     file format .*
+
+Contents of section .text:
+ 1200 434f4445 deadbeef 00000000 00000000  CODE............
+ 1210 cbf43926 00000000 00000000 00000000  ..9&............
+ 1220 cbf43926 00000000 00000000 00000000  ..9&............
+ 1230 00000000 00000000 deadbeef 434f4445  ............CODE
+ 1240 31323334 35363738 3900ffff ffffffff  123456789.......
+ 1250 434f4445 00000000 00000000 00000000  CODE............
+ 1260 ffffffff ffffffff ffffffff ffffffff  .*
+#...
+ 17e0 434f4445 deadbeef 00000000 00000000  CODE............
+ 17f0 44494745 53542054 41424c45 00000000  DIGEST TABLE....
+#...
+ 1c00 454e4420 5441424c 45000000 00000000  END TABLE.......
+ 1c10 00000000 00000000 deadbeef 434f4445  ............CODE
+#pass
diff --git a/ld/testsuite/ld-scripts/crc32.s b/ld/testsuite/ld-scripts/crc32.s
new file mode 100644
index 00000000000..e4ffb15af62
--- /dev/null
+++ b/ld/testsuite/ld-scripts/crc32.s
@@ -0,0 +1,21 @@
+    .extern ecc_start
+	.section .text
+main:
+	.byte 0x43
+	.byte 0x4F
+	.byte 0x44
+	.byte 0x45
+    .long 0
+    .long 0
+    .long 0
+	.section .data
+    .byte 0xde
+    .byte 0xad
+    .byte 0xde
+    .byte 0xad
+    .byte 0xde
+    .byte 0xad
+    .byte 0xbe
+    .byte 0xef
+	.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..4cfe74493b2
--- /dev/null
+++ b/ld/testsuite/ld-scripts/crc32.t
@@ -0,0 +1,41 @@
+MEMORY {
+  rom : ORIGIN = 0x000000, LENGTH = 0x400000
+  ram : ORIGIN = 0x400000, LENGTH = 0x10000
+}
+
+_start = 0x000000;
+SECTIONS
+{
+  . = 0x1000 + SIZEOF_HEADERS;
+  .text ALIGN (0x200) :
+
+    {
+      FILL(0xFF)
+      header = .;
+      INCLUDE "begin_tag.inc"
+
+      expected = .;
+      BYTE(0xCB);
+      BYTE(0xF4);
+      BYTE(0x39);
+      BYTE(0x26);
+      LONG(0x0);
+      QUAD(0x0);
+
+      crc32 = .;
+      DIGEST "_CRC32.BE" "CRC32" (ecc_start , ecc_end);
+      LONG(0);
+      QUAD(0);
+
+      INCLUDE "end_tag.inc"
+
+      INCLUDE "crc_data.inc"
+
+      INCLUDE "digest_table.inc"
+    } > 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..d30d6a7cd7e
--- /dev/null
+++ b/ld/testsuite/ld-scripts/crc64-ecma.d
@@ -0,0 +1,24 @@
+#source: crc64-ecma.s
+#ld: -T crc64-ecma.t
+#objdump: -s -j .text
+#target: [is_elf_format] [is_coff_format]
+#notarget: [is_aout_format]
+#xfail: tic4x-*-* tic54x-*-*
+
+.*:     file format .*
+
+Contents of section .text:
+ 1200 434f4445 deadbeef 00000000 00000000  CODE............
+ 1210 6c40df5f 0b497347 00000000 00000000  l@._.IsG........
+ 1220 6c40df5f 0b497347 00000000 00000000  l@._.IsG........
+ 1230 00000000 00000000 deadbeef 434f4445  ............CODE
+ 1240 31323334 35363738 3900ffff ffffffff  123456789.......
+ 1250 434f4445 00000000 00000000 00000000  CODE............
+ 1260 ffffffff ffffffff ffffffff ffffffff  .*
+#...
+ 17e0 434f4445 deadbeef 00000000 00000000  CODE............
+ 17f0 44494745 53542054 41424c45 00000000  DIGEST TABLE....
+#...
+ 2000 454e4420 5441424c 45000000 00000000  END TABLE.......
+ 2010 00000000 00000000 deadbeef 434f4445  ............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..e4ffb15af62
--- /dev/null
+++ b/ld/testsuite/ld-scripts/crc64-ecma.s
@@ -0,0 +1,21 @@
+    .extern ecc_start
+	.section .text
+main:
+	.byte 0x43
+	.byte 0x4F
+	.byte 0x44
+	.byte 0x45
+    .long 0
+    .long 0
+    .long 0
+	.section .data
+    .byte 0xde
+    .byte 0xad
+    .byte 0xde
+    .byte 0xad
+    .byte 0xde
+    .byte 0xad
+    .byte 0xbe
+    .byte 0xef
+	.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..5d63e2000ba
--- /dev/null
+++ b/ld/testsuite/ld-scripts/crc64-ecma.t
@@ -0,0 +1,44 @@
+MEMORY {
+  rom : ORIGIN = 0x000000, LENGTH = 0x400000
+  ram : ORIGIN = 0x400000, LENGTH = 0x10000
+}
+
+_start = 0x000000;
+SECTIONS
+{
+  . = 0x1000 + SIZEOF_HEADERS;
+  .text ALIGN (0x200) :
+
+    {
+      FILL(0xFF)
+      header = .;
+      INCLUDE "begin_tag.inc"
+
+      expected = .;
+      BYTE(0x6C);
+      BYTE(0x40);
+      BYTE(0xDF);
+      BYTE(0x5F);
+      BYTE(0x0B);
+      BYTE(0x49);
+      BYTE(0x73);
+      BYTE(0x47);
+
+      QUAD(0x0);
+
+      crc64 = .;
+      DIGEST "_CRC64.BE" "CRC64-ECMA" (ecc_start , ecc_end);
+      QUAD(0x0);
+
+      INCLUDE "end_tag.inc"
+
+      INCLUDE "crc_data.inc"
+
+      INCLUDE "digest_table.inc"
+    } > 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..12b9d319a61
--- /dev/null
+++ b/ld/testsuite/ld-scripts/crc64-iso.d
@@ -0,0 +1,24 @@
+#source: crc64-iso.s
+#ld: -T crc64-iso.t
+#objdump: -s -j .text
+#target: [is_elf_format] [is_coff_format]
+#notarget: [is_aout_format]
+#xfail: tic4x-*-* tic54x-*-*
+
+.*:     file format .*
+
+Contents of section .text:
+ 1200 434f4445 deadbeef 00000000 00000000  CODE............
+ 1210 b90956c7 75a41001 00000000 00000000  ..V.u...........
+ 1220 b90956c7 75a41001 00000000 00000000  ..V.u...........
+ 1230 00000000 00000000 deadbeef 434f4445  ............CODE
+ 1240 31323334 35363738 3900ffff ffffffff  123456789.......
+ 1250 434f4445 00000000 00000000 00000000  CODE............
+ 1260 ffffffff ffffffff ffffffff ffffffff  .*
+#...
+ 17e0 434f4445 deadbeef 00000000 00000000  CODE............
+ 17f0 44494745 53542054 41424c45 00000000  DIGEST TABLE....
+#...
+ 2000 454e4420 5441424c 45000000 00000000  END TABLE.......
+ 2010 00000000 00000000 deadbeef 434f4445  ............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..e4ffb15af62
--- /dev/null
+++ b/ld/testsuite/ld-scripts/crc64-iso.s
@@ -0,0 +1,21 @@
+    .extern ecc_start
+	.section .text
+main:
+	.byte 0x43
+	.byte 0x4F
+	.byte 0x44
+	.byte 0x45
+    .long 0
+    .long 0
+    .long 0
+	.section .data
+    .byte 0xde
+    .byte 0xad
+    .byte 0xde
+    .byte 0xad
+    .byte 0xde
+    .byte 0xad
+    .byte 0xbe
+    .byte 0xef
+	.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..18f0a2ce34b
--- /dev/null
+++ b/ld/testsuite/ld-scripts/crc64-iso.t
@@ -0,0 +1,43 @@
+MEMORY {
+  rom : ORIGIN = 0x000000, LENGTH = 0x400000
+  ram : ORIGIN = 0x400000, LENGTH = 0x10000
+}
+
+_start = 0x000000;
+SECTIONS
+{
+  . = 0x1000 + SIZEOF_HEADERS;
+  .text ALIGN (0x200) :
+
+    {
+      FILL(0xFF)
+      header = .;
+      INCLUDE "begin_tag.inc"
+
+      expected = .;
+      BYTE(0xb9);
+      BYTE(0x09);
+      BYTE(0x56);
+      BYTE(0xc7);
+      BYTE(0x75);
+      BYTE(0xa4);
+      BYTE(0x10);
+      BYTE(0x01);
+      QUAD(0x0);
+
+      crc64 = .;
+      DIGEST "_CRC64.BE" "CRC64-GO-ISO" (ecc_start , ecc_end)
+      QUAD(0x0);
+
+      INCLUDE "end_tag.inc"
+
+      INCLUDE "crc_data.inc"
+
+      INCLUDE "digest_table.inc"
+    } > 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_be.d b/ld/testsuite/ld-scripts/crc64-iso_be.d
new file mode 100644
index 00000000000..131116d4305
--- /dev/null
+++ b/ld/testsuite/ld-scripts/crc64-iso_be.d
@@ -0,0 +1,24 @@
+#source: crc64-iso_be.s
+#ld: -T crc64-iso_be.t
+#objdump: -s -j .text
+#target: [is_elf_format] [is_coff_format]
+#notarget: [is_aout_format]
+#xfail: tic4x-*-* tic54x-*-*
+
+.*:     file format .*
+
+Contents of section .text:
+ 1200 434f4445 deadbeef 00000000 00000000  CODE............
+ 1210 0110a475 c75609b9 00000000 00000000  ...u.V..........
+ 1220 0110a475 c75609b9 00000000 00000000  ...u.V..........
+ 1230 00000000 00000000 deadbeef 434f4445  ............CODE
+ 1240 31323334 35363738 3900ffff ffffffff  123456789.......
+ 1250 434f4445 00000000 00000000 00000000  CODE............
+ 1260 ffffffff ffffffff ffffffff ffffffff  .*
+#...
+ 17e0 434f4445 deadbeef 00000000 00000000  CODE............
+ 17f0 44494745 53542054 41424c45 00000000  DIGEST TABLE....
+#...
+ 2000 454e4420 5441424c 45000000 00000000  END TABLE.......
+ 2010 00000000 00000000 deadbeef 434f4445  ............CODE
+#pass
diff --git a/ld/testsuite/ld-scripts/crc64-iso_be.s b/ld/testsuite/ld-scripts/crc64-iso_be.s
new file mode 100644
index 00000000000..e4ffb15af62
--- /dev/null
+++ b/ld/testsuite/ld-scripts/crc64-iso_be.s
@@ -0,0 +1,21 @@
+    .extern ecc_start
+	.section .text
+main:
+	.byte 0x43
+	.byte 0x4F
+	.byte 0x44
+	.byte 0x45
+    .long 0
+    .long 0
+    .long 0
+	.section .data
+    .byte 0xde
+    .byte 0xad
+    .byte 0xde
+    .byte 0xad
+    .byte 0xde
+    .byte 0xad
+    .byte 0xbe
+    .byte 0xef
+	.section .bss
+	.long 0
diff --git a/ld/testsuite/ld-scripts/crc64-iso_be.t b/ld/testsuite/ld-scripts/crc64-iso_be.t
new file mode 100644
index 00000000000..5893b0f6948
--- /dev/null
+++ b/ld/testsuite/ld-scripts/crc64-iso_be.t
@@ -0,0 +1,43 @@
+MEMORY {
+  rom : ORIGIN = 0x000000, LENGTH = 0x400000
+  ram : ORIGIN = 0x400000, LENGTH = 0x10000
+}
+
+_start = 0x000000;
+SECTIONS
+{
+  . = 0x1000 + SIZEOF_HEADERS;
+  .text ALIGN (0x200) :
+
+    {
+      FILL(0xFF)
+      header = .;
+      INCLUDE "begin_tag.inc"
+
+      expected = .;
+      BYTE(0x01);
+      BYTE(0x10);
+      BYTE(0xa4);
+      BYTE(0x75);
+      BYTE(0xc7);
+      BYTE(0x56);
+      BYTE(0x09);
+      BYTE(0xb9);
+      QUAD(0x0);
+
+      crc64 = .;
+      DIGEST "_CRC64" "CRC64-GO-ISO" (ecc_start , ecc_end)
+      QUAD(0x0);
+
+      INCLUDE "end_tag.inc"
+
+      INCLUDE "crc_data.inc"
+
+      INCLUDE "digest_table_be.inc"
+    } > 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..d683d8b0058
--- /dev/null
+++ b/ld/testsuite/ld-scripts/crc64-poly.d
@@ -0,0 +1,24 @@
+#source: crc64-poly.s
+#ld: -T crc64-poly.t
+#objdump: -s -j .text
+#target: [is_elf_format] [is_coff_format]
+#notarget: [is_aout_format]
+#xfail: tic4x-*-* tic54x-*-*
+
+.*:     file format .*
+
+Contents of section .text:
+ 1200 434f4445 deadbeef 00000000 00000000  CODE............
+ 1210 6c40df5f 0b497347 00000000 00000000  l@._.IsG........
+ 1220 6c40df5f 0b497347 00000000 00000000  l@._.IsG........
+ 1230 00000000 00000000 deadbeef 434f4445  ............CODE
+ 1240 31323334 35363738 3900ffff ffffffff  123456789.......
+ 1250 434f4445 00000000 00000000 00000000  CODE............
+ 1260 ffffffff ffffffff ffffffff ffffffff  .*
+#...
+ 17e0 434f4445 deadbeef 00000000 00000000  CODE............
+ 17f0 44494745 53542054 41424c45 00000000  DIGEST TABLE....
+#...
+ 2000 454e4420 5441424c 45000000 00000000  END TABLE.......
+ 2010 00000000 00000000 deadbeef 434f4445  ............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..e4ffb15af62
--- /dev/null
+++ b/ld/testsuite/ld-scripts/crc64-poly.s
@@ -0,0 +1,21 @@
+    .extern ecc_start
+	.section .text
+main:
+	.byte 0x43
+	.byte 0x4F
+	.byte 0x44
+	.byte 0x45
+    .long 0
+    .long 0
+    .long 0
+	.section .data
+    .byte 0xde
+    .byte 0xad
+    .byte 0xde
+    .byte 0xad
+    .byte 0xde
+    .byte 0xad
+    .byte 0xbe
+    .byte 0xef
+	.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..6519b71c684
--- /dev/null
+++ b/ld/testsuite/ld-scripts/crc64-poly.t
@@ -0,0 +1,43 @@
+MEMORY {
+  rom : ORIGIN = 0x000000, LENGTH = 0x400000
+  ram : ORIGIN = 0x400000, LENGTH = 0x10000
+}
+
+_start = 0x000000;
+SECTIONS
+{
+  . = 0x1000 + SIZEOF_HEADERS;
+  .text ALIGN (0x200) :
+
+    {
+      FILL(0xFF)
+      header = .;
+      INCLUDE "begin_tag.inc"
+
+      expected = .;
+      BYTE(0x6C);
+      BYTE(0x40);
+      BYTE(0xDF);
+      BYTE(0x5F);
+      BYTE(0x0B);
+      BYTE(0x49);
+      BYTE(0x73);
+      BYTE(0x47);
+      QUAD(0x0);
+
+      crc64 = .;
+      DIGEST "_CRC64.BE" POLY(64,0x42F0E1EBA9EA3693,0,0,0,0,0)(ecc_start , ecc_end)
+      QUAD(0x0);
+
+      INCLUDE "end_tag.inc"
+
+      INCLUDE "crc_data.inc"
+
+      INCLUDE "digest_table.inc"
+    } > 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/crc_data.inc b/ld/testsuite/ld-scripts/crc_data.inc
new file mode 100644
index 00000000000..176a4689493
--- /dev/null
+++ b/ld/testsuite/ld-scripts/crc_data.inc
@@ -0,0 +1,9 @@
+      ecc_start = .;
+      ASCIZ "123456789"
+      ecc_end = . - 1;
+      . = ALIGN(0x10);
+
+      entry = .;
+      *(.text)
+      . = ALIGN(0x100);
+      BYTE(1);
diff --git a/ld/testsuite/ld-scripts/digest_table.inc b/ld/testsuite/ld-scripts/digest_table.inc
new file mode 100644
index 00000000000..fb40a4fa024
--- /dev/null
+++ b/ld/testsuite/ld-scripts/digest_table.inc
@@ -0,0 +1,6 @@
+      . = ALIGN(2048) - 32;
+      INCLUDE "begin_tag.inc"
+      ASCII (16) "DIGEST TABLE"
+      DIGEST TABLE "CRCTAB"
+      ASCII (16) "END TABLE"
+      INCLUDE "end_tag.inc"
diff --git a/ld/testsuite/ld-scripts/digest_table_be.inc b/ld/testsuite/ld-scripts/digest_table_be.inc
new file mode 100644
index 00000000000..eec712d9eff
--- /dev/null
+++ b/ld/testsuite/ld-scripts/digest_table_be.inc
@@ -0,0 +1,6 @@
+      . = ALIGN(2048) - 32;
+      INCLUDE "begin_tag.inc"
+      ASCII (16) "DIGEST TABLE"
+      DIGEST TABLE "CRCTAB.BE"
+      ASCII (16) "END TABLE"
+      INCLUDE "end_tag.inc"
diff --git a/ld/testsuite/ld-scripts/end_tag.inc b/ld/testsuite/ld-scripts/end_tag.inc
new file mode 100644
index 00000000000..4c80854b062
--- /dev/null
+++ b/ld/testsuite/ld-scripts/end_tag.inc
@@ -0,0 +1,9 @@
+      QUAD(0);
+      BYTE(0xDE);
+      BYTE(0xAD);
+      BYTE(0xBE);
+      BYTE(0xEF);
+      BYTE(0x43);
+      BYTE(0x4F);
+      BYTE(0x44);
+      BYTE(0x45);
diff --git a/ld/testsuite/ld-scripts/script.exp b/ld/testsuite/ld-scripts/script.exp
index 56e12da8e61..38cb0f9fe66 100644
--- a/ld/testsuite/ld-scripts/script.exp
+++ b/ld/testsuite/ld-scripts/script.exp
@@ -229,6 +229,13 @@ 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-iso_be"
+run_dump_test "crc64-poly"
+run_dump_test "crc32"
+run_dump_test "crc32-poly"
+
 run_dump_test "align-with-input"
 run_dump_test "pr20302"
 run_dump_test "output-section-types"
-- 
2.34.1


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

* [PATCH v7 05/11] DIGEST: ldlex.l
  2023-03-01 15:45 [PATCH v7 0/11 Add support for CRC64 generation in linker binutils
                   ` (3 preceding siblings ...)
  2023-03-01 15:45 ` [PATCH v7 04/11] DIGEST: testsuite binutils
@ 2023-03-01 15:45 ` binutils
  2023-03-01 15:45 ` [PATCH v7 06/11] DIGEST: ldgram.y binutils
  2023-03-01 15:45 ` [PATCH v7 07/11] DIGEST: ldmain.c binutils
  6 siblings, 0 replies; 8+ messages in thread
From: binutils @ 2023-03-01 15:45 UTC (permalink / raw)
  To: binutils; +Cc: nickc, Ulf Samuelsson

From: Ulf Samuelsson <ulf@emagii.com>

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

diff --git a/ld/ldlex.l b/ld/ldlex.l
index 910e7ea3b8b..219702e0a1f 100644
--- a/ld/ldlex.l
+++ b/ld/ldlex.l
@@ -298,6 +298,14 @@ 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>"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] 8+ messages in thread

* [PATCH v7 06/11] DIGEST: ldgram.y
  2023-03-01 15:45 [PATCH v7 0/11 Add support for CRC64 generation in linker binutils
                   ` (4 preceding siblings ...)
  2023-03-01 15:45 ` [PATCH v7 05/11] DIGEST: ldlex.l binutils
@ 2023-03-01 15:45 ` binutils
  2023-03-01 15:45 ` [PATCH v7 07/11] DIGEST: ldmain.c binutils
  6 siblings, 0 replies; 8+ messages in thread
From: binutils @ 2023-03-01 15:45 UTC (permalink / raw)
  To: binutils; +Cc: nickc, Ulf Samuelsson

From: Ulf Samuelsson <ulf@emagii.com>

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

diff --git a/ld/ldgram.y b/ld/ldgram.y
index faffeec94b8..fcc47712b11 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,32 @@ statement:
 		{
 		  lang_add_fill ($3);
 		}
+	| DIGEST NAME
+		{ /* CRC_ADDRESS is set in <polynome>, but polynome reserves space, so we use a temporary */
+		  digest_label = lang_get_label($2, &digest_big_endian);
+		  lang_add_assignment (exp_assign (digest_label, exp_nameop (NAME, "."), false));
+		}
+		polynome '(' mustbe_exp ',' mustbe_exp ')'
+		{
+		  lang_add_assignment (exp_assign (CRC_ADDRESS, exp_nameop (NAME, digest_label), false));
+		  lang_add_assignment (exp_assign (CRC_START, $6, false));
+		  lang_add_assignment (exp_assign (CRC_END,   $8, false));
+		}
+	| DIGEST TABLE NAME
+		{
+		  bool       big_endian;
+		  const char *label = lang_get_label($3, &big_endian);
+		  lang_add_assignment (exp_assign (label, exp_nameop (NAME,"."), false));
+		  lang_add_digest_table (big_endian);
+		}
+	| DIGEST SECTION NAME
+		{
+		  lang_set_digest_section ($3);
+		}
+	| TIMESTAMP
+		{
+		  lang_add_timestamp ();
+		}
 	| ASSERT_K
 		{ ldlex_expression (); }
 	  '(' exp ',' NAME ')' separator
@@ -689,13 +719,42 @@ 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 ',' mustbe_exp ',' mustbe_exp ','
+		   mustbe_exp ',' mustbe_exp ',' mustbe_exp ')'
+		{
+		  lang_add_digest (
+			$3->value.value,	/* size			*/
+			$5->value.value,	/* polynome		*/
+			$7->value.value,	/* initial value	*/
+			$9->value.value,	/* xor     value	*/
+			$11->value.value,	/* input   reflected	*/
+			$13->value.value,	/* output  reflected	*/
+			$15->value.value	/* reciprocal		*/
+			);
+		}
+
 statement_list:
 		statement_list statement
 	|	statement
-- 
2.34.1


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

* [PATCH v7 07/11] DIGEST: ldmain.c
  2023-03-01 15:45 [PATCH v7 0/11 Add support for CRC64 generation in linker binutils
                   ` (5 preceding siblings ...)
  2023-03-01 15:45 ` [PATCH v7 06/11] DIGEST: ldgram.y binutils
@ 2023-03-01 15:45 ` binutils
  6 siblings, 0 replies; 8+ messages in thread
From: binutils @ 2023-03-01 15:45 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] 8+ messages in thread

end of thread, other threads:[~2023-03-01 15:46 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-03-01 15:45 [PATCH v7 0/11 Add support for CRC64 generation in linker binutils
2023-03-01 15:45 ` [PATCH v7 01/11] DIGEST: LICENSING binutils
2023-03-01 15:45 ` [PATCH v7 02/11] DIGEST: NEWS binutils
2023-03-01 15:45 ` [PATCH v7 03/11] DIGEST: Documentation binutils
2023-03-01 15:45 ` [PATCH v7 04/11] DIGEST: testsuite binutils
2023-03-01 15:45 ` [PATCH v7 05/11] DIGEST: ldlex.l binutils
2023-03-01 15:45 ` [PATCH v7 06/11] DIGEST: ldgram.y binutils
2023-03-01 15:45 ` [PATCH v7 07/11] DIGEST: ldmain.c binutils

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).