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

Patchset VIII
Memory in testsuite reduced to 16kB ROM and 4 kB RAM
All situated in the first 64 KB.

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


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

* [PATCH v8 01/11] DIGEST: LICENSING
  2023-03-01 17:43 [PATCH v8 0/11 Add support for CRC64 generation in linker binutils
@ 2023-03-01 17:43 ` binutils
  2023-03-01 17:43 ` [PATCH v8 02/11] DIGEST: NEWS binutils
                   ` (10 subsequent siblings)
  11 siblings, 0 replies; 16+ messages in thread
From: binutils @ 2023-03-01 17:43 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] 16+ messages in thread

* [PATCH v8 02/11] DIGEST: NEWS
  2023-03-01 17:43 [PATCH v8 0/11 Add support for CRC64 generation in linker binutils
  2023-03-01 17:43 ` [PATCH v8 01/11] DIGEST: LICENSING binutils
@ 2023-03-01 17:43 ` binutils
  2023-03-01 17:43 ` [PATCH v8 03/11] DIGEST: Documentation binutils
                   ` (9 subsequent siblings)
  11 siblings, 0 replies; 16+ messages in thread
From: binutils @ 2023-03-01 17:43 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] 16+ messages in thread

* [PATCH v8 03/11] DIGEST: Documentation
  2023-03-01 17:43 [PATCH v8 0/11 Add support for CRC64 generation in linker binutils
  2023-03-01 17:43 ` [PATCH v8 01/11] DIGEST: LICENSING binutils
  2023-03-01 17:43 ` [PATCH v8 02/11] DIGEST: NEWS binutils
@ 2023-03-01 17:43 ` binutils
  2023-03-01 17:43 ` [PATCH v8 04/11] DIGEST: testsuite binutils
                   ` (8 subsequent siblings)
  11 siblings, 0 replies; 16+ messages in thread
From: binutils @ 2023-03-01 17:43 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] 16+ messages in thread

* [PATCH v8 04/11] DIGEST: testsuite
  2023-03-01 17:43 [PATCH v8 0/11 Add support for CRC64 generation in linker binutils
                   ` (2 preceding siblings ...)
  2023-03-01 17:43 ` [PATCH v8 03/11] DIGEST: Documentation binutils
@ 2023-03-01 17:43 ` binutils
  2023-03-01 17:43 ` [PATCH v8 05/11] DIGEST: ldlex.l binutils
                   ` (7 subsequent siblings)
  11 siblings, 0 replies; 16+ messages in thread
From: binutils @ 2023-03-01 17:43 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..bfc5adeb38a
--- /dev/null
+++ b/ld/testsuite/ld-scripts/crc32-poly.t
@@ -0,0 +1,42 @@
+MEMORY {
+  rom : ORIGIN = 0x000000, LENGTH = 0x4000
+  ram : ORIGIN = 0x008000, LENGTH = 0x1000
+}
+
+_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 (0x008000) { *(.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..fcd10c3990b
--- /dev/null
+++ b/ld/testsuite/ld-scripts/crc32.t
@@ -0,0 +1,41 @@
+MEMORY {
+  rom : ORIGIN = 0x000000, LENGTH = 0x4000
+  ram : ORIGIN = 0x008000, LENGTH = 0x1000
+}
+
+_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 (0x008000) { *(.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..26ddf5cc9ca
--- /dev/null
+++ b/ld/testsuite/ld-scripts/crc64-ecma.t
@@ -0,0 +1,44 @@
+MEMORY {
+  rom : ORIGIN = 0x000000, LENGTH = 0x4000
+  ram : ORIGIN = 0x008000, LENGTH = 0x1000
+}
+
+_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 (0x008000) { *(.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..59fe597901d
--- /dev/null
+++ b/ld/testsuite/ld-scripts/crc64-iso.t
@@ -0,0 +1,43 @@
+MEMORY {
+  rom : ORIGIN = 0x000000, LENGTH = 0x4000
+  ram : ORIGIN = 0x008000, LENGTH = 0x1000
+}
+
+_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 (0x008000) { *(.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..22cc37ca304
--- /dev/null
+++ b/ld/testsuite/ld-scripts/crc64-iso_be.t
@@ -0,0 +1,43 @@
+MEMORY {
+  rom : ORIGIN = 0x000000, LENGTH = 0x4000
+  ram : ORIGIN = 0x008000, LENGTH = 0x1000
+}
+
+_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 (0x008000) { *(.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..a2df26f17ab
--- /dev/null
+++ b/ld/testsuite/ld-scripts/crc64-poly.t
@@ -0,0 +1,43 @@
+MEMORY {
+  rom : ORIGIN = 0x000000, LENGTH = 0x4000
+  ram : ORIGIN = 0x008000, LENGTH = 0x1000
+}
+
+_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 (0x008000) { *(.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] 16+ messages in thread

* [PATCH v8 05/11] DIGEST: ldlex.l
  2023-03-01 17:43 [PATCH v8 0/11 Add support for CRC64 generation in linker binutils
                   ` (3 preceding siblings ...)
  2023-03-01 17:43 ` [PATCH v8 04/11] DIGEST: testsuite binutils
@ 2023-03-01 17:43 ` binutils
  2023-03-01 17:43 ` [PATCH v8 06/11] DIGEST: ldgram.y binutils
                   ` (6 subsequent siblings)
  11 siblings, 0 replies; 16+ messages in thread
From: binutils @ 2023-03-01 17:43 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] 16+ messages in thread

* [PATCH v8 06/11] DIGEST: ldgram.y
  2023-03-01 17:43 [PATCH v8 0/11 Add support for CRC64 generation in linker binutils
                   ` (4 preceding siblings ...)
  2023-03-01 17:43 ` [PATCH v8 05/11] DIGEST: ldlex.l binutils
@ 2023-03-01 17:43 ` binutils
  2023-03-01 17:43 ` [PATCH v8 07/11] DIGEST: ldmain.c binutils
                   ` (5 subsequent siblings)
  11 siblings, 0 replies; 16+ messages in thread
From: binutils @ 2023-03-01 17:43 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] 16+ messages in thread

* [PATCH v8 07/11] DIGEST: ldmain.c
  2023-03-01 17:43 [PATCH v8 0/11 Add support for CRC64 generation in linker binutils
                   ` (5 preceding siblings ...)
  2023-03-01 17:43 ` [PATCH v8 06/11] DIGEST: ldgram.y binutils
@ 2023-03-01 17:43 ` binutils
  2023-03-01 17:43 ` [PATCH v8 08/11] DIGEST: ldlang.*: add timestamp binutils
                   ` (4 subsequent siblings)
  11 siblings, 0 replies; 16+ messages in thread
From: binutils @ 2023-03-01 17:43 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] 16+ messages in thread

* [PATCH v8 08/11] DIGEST: ldlang.*: add timestamp
  2023-03-01 17:43 [PATCH v8 0/11 Add support for CRC64 generation in linker binutils
                   ` (6 preceding siblings ...)
  2023-03-01 17:43 ` [PATCH v8 07/11] DIGEST: ldmain.c binutils
@ 2023-03-01 17:43 ` binutils
  2023-03-01 17:43 ` [PATCH v8 09/11] DIGEST: calculation binutils
                   ` (3 subsequent siblings)
  11 siblings, 0 replies; 16+ messages in thread
From: binutils @ 2023-03-01 17:43 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 295de015da9..77917027f83 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"
@@ -8520,6 +8521,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] 16+ messages in thread

* [PATCH v8 09/11] DIGEST: calculation
  2023-03-01 17:43 [PATCH v8 0/11 Add support for CRC64 generation in linker binutils
                   ` (7 preceding siblings ...)
  2023-03-01 17:43 ` [PATCH v8 08/11] DIGEST: ldlang.*: add timestamp binutils
@ 2023-03-01 17:43 ` binutils
  2023-03-01 17:43 ` [PATCH v8 10/11] DIGEST: Makefile.* binutils
                   ` (2 subsequent siblings)
  11 siblings, 0 replies; 16+ messages in thread
From: binutils @ 2023-03-01 17:43 UTC (permalink / raw)
  To: binutils; +Cc: nickc, Ulf Samuelsson

From: Ulf Samuelsson <ulf@emagii.com>

Signed-off-by: Ulf Samuelsson <ulf@emagii.com>
---
 ld/ldcrc32.c      | 179 +++++++++++
 ld/ldcrc64.c      | 180 +++++++++++
 ld/lddigest.c     | 760 ++++++++++++++++++++++++++++++++++++++++++++++
 ld/lddigest.h     | 172 +++++++++++
 ld/lddigest_tab.c | 147 +++++++++
 ld/ldreflect.c    |  99 ++++++
 ld/ldreflect.h    |  37 +++
 7 files changed, 1574 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
 create mode 100644 ld/lddigest_tab.c
 create mode 100644 ld/ldreflect.c
 create mode 100644 ld/ldreflect.h

diff --git a/ld/ldcrc32.c b/ld/ldcrc32.c
new file mode 100644
index 00000000000..8b7de1d6e72
--- /dev/null
+++ b/ld/ldcrc32.c
@@ -0,0 +1,179 @@
+/*
+ * Library: ldlibcrc
+ * Author:  Lammert Bies, Bastian Molkenthin, Ulf Samuelsson
+ *
+ * This file is licensed under the MIT License as stated below
+ *
+ * Copyright (c) 2016 Lammert Bies
+ * Copyright (c) 2013 Ulf Samuelsson (ulf@emagii.com)
+ *
+ * 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"
+#include "ldreflect.h"
+
+#define SHIFT(t)   ((sizeof(t)-1)*8)
+/* ============ CRC-32 LIBCRC functions ======================================*/
+
+/*
+ * void _init_crc32_tab (uint32_t *crc_tab,  uint32_t poly);
+ *
+ * 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
+ */
+static void
+_init_crc32_tab (uint32_t * crc_tab, uint32_t poly)
+{
+  uint32_t crc;
+  uint32_t shift = SHIFT (uint32_t);
+  for (uint32_t i = 0; i < 256; i++)
+    {
+      crc = i << shift;
+      for (uint32_t j = 0; j < 8; j++)
+	{
+	  if ((crc & 0x80000000u) != 0)
+	    {
+	      crc = (crc << 1) ^ poly;
+	    }
+	  else
+	    {
+	      crc = crc << 1;
+	    }
+	}
+      crc_tab[i] = crc;
+    }
+}				/* _init_crc32__tab */
+
+/*
+ * void _init_crc32_reciprocal_tab (uint32_t *crc_tab,  uint32_t poly);
+ *
+ * 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_reciprocal_tab is copyright (c) 2021 Bastian Molkenthin
+ */
+static void
+_init_crc32_reciprocal_tab (uint32_t * crc_tab, uint32_t poly)
+{
+  uint32_t crc;
+  uint32_t reflected_poly = reflect32 (poly);
+  for (uint32_t i = 0; i < 256; i++)
+    {
+      crc = i;
+      for (uint32_t j = 0; j < 8; j++)
+	{
+	  if (crc & 0x00000001U)
+	    {
+	      crc >>= 1;
+	      crc ^= reflected_poly;
+	    }
+	  else
+	    {
+	      crc = crc >> 1;
+	    }
+	}
+      crc_tab[i] = crc;
+    }
+}				/* _init_crc32_reciprocal_tab */
+
+/*
+ * 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.
+ * The table can be calculated in a normal or a reciprocal version.
+ * init_crc64_tab is copyright (c) 2023 Ulf Samuelsson
+ */
+uint32_t *
+init_crc32_tab (algorithm_desc_t * dsc)
+{
+  uint32_t *crc_tab = malloc (256 * sizeof (uint32_t));
+
+  if (crc_tab == NULL)
+    return NULL;
+
+  if (dsc->reciprocal)
+    {
+      _init_crc32_reciprocal_tab (crc_tab, dsc->poly.d32._0);
+    }
+  else
+    {
+      _init_crc32_tab (crc_tab, dsc->poly.d32._0);
+    }
+
+  return crc_tab;
+}				/* init_crc32_tab */
+
+/*
+ * uint32_t calc_crc32(algorithm_desc_t *dsc, 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.
+ * calc_crc32 is
+ *   copyright (c) 2016 Lammert Bies
+ *   copyright (c) 2021 Bastian Molkenthin
+ *   copyright (c) 2023 Ulf Samuelsson
+ */
+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.d32._0;
+
+  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.d32._0;
+  return crc;
+}				/* calc_crc32 */
diff --git a/ld/ldcrc64.c b/ld/ldcrc64.c
new file mode 100644
index 00000000000..c94ff21bdcb
--- /dev/null
+++ b/ld/ldcrc64.c
@@ -0,0 +1,180 @@
+/*
+ * Library: ldlibcrc
+ * Author:  Lammert Bies, Bastian Molkenthin, Ulf Samuelsson
+ *
+ * This file is licensed under the MIT License as stated below
+ *
+ * Copyright (c) 2016 Lammert Bies
+ * Copyright (c) 2021 Bastian Molkenthin
+ * Copyright (c) 2023 Ulf Samuelsson (ulf@emagii.com)
+ *
+ * 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"
+#include "ldreflect.h"
+
+#define SHIFT(t)   ((sizeof(t)-1)*8)
+/* ============ CRC-64 LIBCRC functions ======================================*/
+
+/*
+ * uint64_t *init_crc64_tab(algorithm_desc_t *dsc) ;
+ *
+ * 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
+ */
+static void
+_init_crc64_tab (uint64_t * crc_tab, uint64_t poly)
+{
+  uint64_t crc;
+  uint32_t shift = SHIFT (uint64_t);
+  for (uint64_t i = 0; i < 256; i++)
+    {
+      crc = i << shift;
+      for (uint64_t j = 0; j < 8; j++)
+	{
+	  if ((crc & 0x8000000000000000ull) != 0)
+	    {
+	      crc = (crc << 1) ^ poly;
+	    }
+	  else
+	    {
+	      crc = crc << 1;
+	    }
+	}
+      crc_tab[i] = crc;
+    }
+}				/* _init_crc64_tab */
+
+/*
+ * _init_crc64_reciprocal_tab (uint64_t *crc_tab,  uint64_t 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_reciprocal_tab is copyright (c) 2021 Bastian Molkenthin
+ */
+
+static void
+_init_crc64_reciprocal_tab (uint64_t * crc_tab, uint64_t poly)
+{
+  uint64_t crc;
+  uint64_t reflected_poly = reflect64 (poly);
+  for (uint64_t i = 0; i < 256; i++)
+    {
+      crc = i;
+      for (uint64_t j = 0; j < 8; j++)
+	{
+	  if ((crc & 0x0000000000000001ULL) != 0)
+	    {
+	      crc >>= 1;
+	      crc ^= reflected_poly;
+	    }
+	  else
+	    {
+	      crc >>= 1;
+	    }
+	}
+      crc_tab[i] = crc;
+    }
+}				/* _init_crc64_reciprocal_tab */
+
+/*
+ * uint64_t *init_crc64_tab(algorithm_desc_t *dsc) ;
+ *
+ * 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) 2023 Ulf Samuelsson
+ */
+uint64_t *
+init_crc64_tab (algorithm_desc_t * dsc)
+{
+  uint64_t *crc_tab = malloc (256 * sizeof (uint64_t));
+
+  if (crc_tab == NULL)
+    return NULL;
+
+  if (dsc->reciprocal)
+    {
+      _init_crc64_reciprocal_tab (crc_tab, dsc->poly.d64);
+    }
+  else
+    {
+      _init_crc64_tab (crc_tab, dsc->poly.d64);
+    }
+  return crc_tab;
+
+}				/* init_crc64_tab */
+
+/*
+ * uint64_t calc_crc64
+ *   (algorithm_desc_t *dsc, 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.
+ * calc_crc64 is
+ *   copyright (c) 2016 Lammert Bies
+ *   copyright (c) 2021 Bastian Molkenthin
+ *   copyright (c) 2023 Ulf Samuelsson
+ */
+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.d64;
+  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.d64;
+  return crc;
+}				/* calc_crc64 */
diff --git a/ld/lddigest.c b/ld/lddigest.c
new file mode 100644
index 00000000000..1c6ddc69a58
--- /dev/null
+++ b/ld/lddigest.c
@@ -0,0 +1,760 @@
+/* Linker command language support.
+   Copyright (C) 1991-2023 Ulf Samuelsson <ulf@emagii.com>
+
+   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;
+
+char *CRC_ADDRESS = NULL;
+char *CRC_START = NULL;
+char *CRC_END = NULL;
+char *CRC_TABLE = NULL;
+
+
+
+
+
+const char *digest_section = ".text";
+const char *digest_label = "___CRC_LABEL__";
+bool digest_big_endian = false;
+static bool
+big_endian_host (void)
+{
+  union
+  {
+    uint32_t i;
+    char c[4];
+  } e = { 0x01000000 };
+
+  return e.c[0];
+}
+
+#if     0
+static bool
+swap_endian (void)
+{
+  if (big_endian_host ())
+    {
+      return !link_info.big_endian;
+    }
+  else
+    {
+      return link_info.big_endian;
+    }
+}
+#endif
+
+/* ============ CRC-32 public functions ======================================*/
+
+void
+lang_add_crc32_syndrome (algorithm_desc_t * a)
+{
+  CRC_ADDRESS = CRC32_ADDRESS;
+  CRC_START = CRC32_START;
+  CRC_END = CRC32_END;
+  CRC_TABLE = CRC32_TABLE;
+
+  lang_add_data (LONG, exp_intop (0));	/* Reserve room for the ECC value */
+  a->crc_tab = init_crc32_tab (a);
+  if (a->crc_tab == NULL)
+    {
+      einfo (_("%F%P: can not allocate memory for CRC table: %E\n"));
+      return;
+    }
+}
+
+static void
+lang_add_crc32_table (bool big_endian)
+{
+  uint32_t *crc32_table = algorithm.crc_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 (&algorithm);
+      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++)
+    {
+      uint32_t elem = crc32_table[i];
+      if (big_endian)
+	{
+	  elem = __builtin_bswap32 (elem);
+	}
+      lang_add_data (LONG, exp_intop (elem));
+    }
+  if (local_table)
+    free (crc32_table);
+}
+
+/* ============ CRC-64 public functions ======================================*/
+
+void
+lang_add_crc64_syndrome (algorithm_desc_t * a)
+{
+  CRC_ADDRESS = CRC64_ADDRESS;
+  CRC_START = CRC64_START;
+  CRC_END = CRC64_END;
+  CRC_TABLE = CRC64_TABLE;
+  lang_add_data (QUAD, exp_intop (0));	/* Reserve room for the ECC value */
+  a->crc_tab = init_crc64_tab (a);
+  if (a->crc_tab == NULL)
+    {
+      einfo (_("%F%P: can not allocate memory for CRC table: %E\n"));
+      return;
+    }
+}
+
+#if (DEBUG_CRC == 1)
+static void
+print_hash64_table (algorithm_desc_t * a)
+{
+  uint64_t *crc_tab = a->crc_tab;
+  uint32_t i;
+  if (crc_tab == NULL)
+    {
+      printf ("%-20ssBad Table\n", a->name);
+      return;
+
+    }
+
+  i = 0;
+  printf ("%03d\t", i);
+  printf ("0x%016lx, ", crc_tab[i + 0]);
+  printf ("0x%016lx, ", crc_tab[i + 1]);
+  printf ("0x%016lx, ", crc_tab[i + 2]);
+  printf ("0x%016lx\n", crc_tab[i + 3]);
+  printf ("\t...\n");
+  i = 252;
+  printf ("%03d\t", i);
+  printf ("0x%016lx, ", crc_tab[i + 0]);
+  printf ("0x%016lx, ", crc_tab[i + 1]);
+  printf ("0x%016lx, ", crc_tab[i + 2]);
+  printf ("0x%016lx\n", crc_tab[i + 3]);
+  printf ("\n");
+}
+#else
+#define print_hash64_table(x)
+#endif
+
+static void
+lang_add_crc64_table (bool big_endian)
+{
+  bfd_vma *crc64_table = algorithm.crc_tab;	/* Use a precomputed, if it exists */
+  bool local_table = false;
+  if (crc64_table == NULL)
+    {				/* No luck, create a table */
+      crc64_table = init_crc64_tab (&algorithm);
+      if (crc64_table == NULL)
+	{
+	  einfo (_("%F%P: can not allocate memory for CRC table: %E\n"));
+	  return;
+	}
+      local_table = true;
+    }
+  print_hash64_table (&algorithm);
+  for (bfd_vma i = 0; i < 256; i++)
+    {
+      bfd_vma elem = crc64_table[i];
+      if (big_endian)
+	{
+	  elem = __builtin_bswap64 (elem);
+	}
+      if (link_info.big_endian)
+	{
+	  elem = __builtin_bswap64 (elem);
+	}
+
+      lang_add_data (QUAD, exp_intop (elem));
+    }
+  if (local_table)
+    free (crc64_table);
+}
+
+/* ============ DIGEST COMMON functions ======================================*/
+
+void
+lang_add_digest (bfd_vma size,
+		 bfd_vma poly,
+		 bfd_vma initial,
+		 bfd_vma xor_val,
+		 bfd_vma ireflect, bfd_vma oreflect, bfd_vma reciprocal)
+{
+  if (algorithm.crc_algo != no_algo)	/* We only allow one CRC <polynom> */
+    {
+      einfo (_("%P:%pS: warning: Only the first CRC polynome is used\n"),
+	     NULL);
+      return;
+    }
+
+  algorithm.name = "CUSTOM";
+  algorithm.big_endian = digest_big_endian;
+  if (size == 64)
+    {
+      algorithm.crc_algo = crc_algo_64;
+      algorithm.crc_size = size;
+      algorithm.poly.d64 = poly;	/* Set the polynom */
+      algorithm.initial.d64 = initial;	/* Set seed */
+      algorithm.xor_val.d64 = xor_val;	/* final XOR value */
+      algorithm.ireflect = ireflect;
+      algorithm.oreflect = oreflect;
+      algorithm.crc_tab = NULL;
+      algorithm.reciprocal = reciprocal;
+      algorithm.expected.d64 = 0;
+
+      lang_add_crc64_syndrome (&algorithm);
+    }
+  else if (size == 32)
+    {
+      algorithm.crc_algo = crc_algo_32;
+      algorithm.crc_size = size;
+      algorithm.poly.d32._0 = poly;	/* Set the polynom */
+      algorithm.initial.d32._0 = initial;	/* Set seed */
+      algorithm.xor_val.d32._0 = xor_val;	/* final XOR value */
+      algorithm.ireflect = ireflect;
+      algorithm.oreflect = oreflect;
+      algorithm.crc_tab = NULL;
+      algorithm.reciprocal = reciprocal;
+      algorithm.expected.d32._0 = 0;
+      lang_add_crc32_syndrome (&algorithm);
+    }
+  else
+    {
+      einfo (_("%F%P: Illegal Size in DIGEST: %E\n"));
+      return;
+    }
+}
+
+const char *
+lang_get_label (const char *label, bool *big_endian)
+{
+  char *newlabel;
+  const char *p = &label[1];
+  char c;
+  *big_endian = false;		/* unless told otherwise */
+  if (*label == '\0')
+    {
+      return "__CRC_LABEL__";
+    }
+  for (uint32_t i = 1; *p; i++)	/* ignore '.' in first character */
+    {
+      c = *p;
+      if (c == '.')
+	{
+	  newlabel = strndup (label, i);
+	  p++;
+	  if (strlen (p) == 2)
+	    {
+	      char c0 = *p++;
+	      char c1 = *p;
+	      bool be = ((c0 == 'B') || (c0 == 'b')) &
+		((c1 == 'E') || (c1 == 'e'));
+	      if (be)
+		{
+		  *big_endian = true;
+		}
+	    }
+	  return newlabel;
+	}
+      else
+	{
+	  p++;
+	}
+    }
+  return label;
+}
+
+bool
+lang_set_digest (char *digest)
+{
+  if (algorithm.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;
+    }
+
+  for (algo_t a = (algo_t) 0; algorithms[a].crc_algo != no_algo; a++)
+    {
+#if (DEBUG_CRC == 1)
+      printf ("Comparing \"%s\" with \"%s\": ", digest, algorithms[a].name);
+#endif
+      if (!strcmp (digest, algorithms[a].name))
+	{
+#if (DEBUG_CRC == 1)
+	  printf ("OK\n");
+#endif
+	  memcpy (&algorithm, &algorithms[a], sizeof (algorithm_desc_t));
+	  algorithm.big_endian = digest_big_endian;
+	  if (algorithm.crc_size == 64)
+	    {
+	      lang_add_crc64_syndrome (&algorithm);
+	    }
+	  else if (algorithm.crc_size == 32)
+	    {
+	      lang_add_crc32_syndrome (&algorithm);
+	    }
+
+	  return true;
+	}
+#if (DEBUG_CRC == 1)
+      else
+	{
+	  printf ("FAIL\n");
+	}
+#endif
+    }
+  einfo (_("%F%P: Unknown DIGEST: %E\n"));
+  return false;
+}
+
+void
+lang_add_digest_table (bool big_endian)
+{
+  if (algorithm.crc_algo == crc_algo_32)
+    {
+      lang_add_crc32_table (big_endian);
+    }
+  else if (algorithm.crc_algo == crc_algo_64)
+    {
+      lang_add_crc64_table (big_endian);
+    }
+}
+
+void
+lang_set_digest_section (char *section)
+{
+  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_crc32_checksum (uint32_t crc, bfd_vma addr)
+{
+  uint32_t real_crc = crc;
+  if (big_endian_host ())
+    {
+      if (algorithm.big_endian)
+	{
+	  /* We are OK */
+	}
+      else
+	{
+	  real_crc = __builtin_bswap32 (crc);
+	}
+    }
+  else
+    {
+      if (algorithm.big_endian)
+	{
+	  real_crc = __builtin_bswap32 (crc);
+	}
+      else
+	{
+	  /* We are OK */
+	}
+    }
+
+  return (bfd_set_section_contents (link_info.output_bfd,
+				    text_section->output_section,
+				    &real_crc, addr, sizeof (uint32_t)));
+}
+
+static bool
+set_crc64_checksum (uint64_t crc, bfd_vma addr)
+{
+  uint64_t real_crc = crc;
+  if (big_endian_host ())
+    {
+      if (algorithm.big_endian)
+	{
+	  /* We are OK */
+	}
+      else
+	{
+	  real_crc = __builtin_bswap64 (crc);
+	}
+    }
+  else
+    {
+      if (algorithm.big_endian)
+	{
+	  real_crc = __builtin_bswap64 (crc);
+	}
+      else
+	{
+	  /* We are OK */
+	}
+    }
+  /* True if OK */
+  return (bfd_set_section_contents (link_info.output_bfd,
+				    text_section->output_section,
+				    &real_crc, addr, sizeof (uint64_t)));
+}
+
+static bool
+set_crc_checksum (bfd_vma crc, bfd_vma addr, bfd_vma size)
+{
+  bool status;
+  if (size == 64)
+    {
+      status = set_crc64_checksum (crc, addr);
+    }
+  else
+    {
+      status = set_crc32_checksum ((uint32_t) crc, addr);
+    }
+  if (!status)
+    {
+      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);
+    }
+}
+
+
+static void
+print_crc64_algorithm (algorithm_desc_t * a, const unsigned char *crc_data,
+		       uint64_t crc)
+{
+  printf ("64:%-16s, data=\"%s\", ", a->name, crc_data);
+  printf ("poly=0x%016lx i=0x%1x xor=0x%1x .ir=%u .or=%u .rp=%u ",
+	  a->poly.d64,
+	  a->initial.d32._0 & 0xF,
+	  a->xor_val.d32._0 & 0xF, a->ireflect, a->oreflect, a->reciprocal);
+  printf ("checksum=0x%016lx, expected=0x%016lx\n", crc, a->expected.d64);
+}
+
+#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
+ * 'algorithm.crc_algo'
+ */
+static bfd_vma
+calculate_crc (const unsigned char *input_str, size_t num_bytes)
+{
+  if (algorithm.crc_algo == crc_algo_64)
+    {
+      if (algorithm.crc_tab != NULL)
+	{
+	  return calc_crc64 (&algorithm, input_str, num_bytes);
+	}
+    }
+  else if (algorithm.crc_algo == crc_algo_32)
+    {
+      if (algorithm.crc_tab != NULL)
+	{
+	  return calc_crc32 (&algorithm, 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 + (algorithm.crc_size / 8)) <= 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)
+{
+  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 (algorithm.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");
+
+    print_hash64_table (&algorithm);
+
+#if (DEBUG_CRC == 1)
+    crc = calculate_crc ((const unsigned char *) "123456789", 9);
+#else
+    crc = calculate_crc (&text_contents[_crc_area_start],
+			 _crc_area_end - _crc_area_start);
+#endif
+
+#if (DEBUG_CRC == 1)
+    printf ("size  = 0x%08u\n", (uint32_t) (_crc_area_end - _crc_area_start));
+    printf ("start = 0x%016lx\n", _crc_area_start);
+    printf ("end   = 0x%016lx\n", _crc_area_end);
+    printf ("crc   = 0x%016lx\n", crc);
+
+    print_crc64_algorithm (&algorithm, &text_contents[_crc_area_start], crc);
+#endif
+
+    /*
+     * 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, algorithm.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 (algorithm.crc_algo == no_algo)
+    return;
+
+  /* Handle 32/64-bit CRCs */
+  if ((algorithm.crc_algo == crc_algo_32)
+      || (algorithm.crc_algo == crc_algo_64))
+    {
+      lang_generate_crc ();
+    }
+}
diff --git a/ld/lddigest.h b/ld/lddigest.h
new file mode 100755
index 00000000000..a1f7933ad36
--- /dev/null
+++ b/ld/lddigest.h
@@ -0,0 +1,172 @@
+/*
+ * Library: libcrc
+ * Author:  Lammert Bies, Ulf Samuelsson
+ *
+ * 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>
+#include <stdbool.h>
+#include "bfd.h"
+
+#define	CRC_POLY_64_ECMA	0x42F0E1EBA9EA3693ull	/* Normal */
+#define	CRC_POLY_64_ECMA_EXP	0x6C40DF5F0B497347ull	/* CRC when testing "123456789" */
+#define	CRC_POLY_64_ECMA_R	0xC96C5795D7870F42ull	/* Reversed */
+
+#define	CRC_POLY_64_ISO		0x000000000000001Bull	/* Normal */
+#define	CRC_POLY_64_ISO_EXP	0xB90956C775A41001ull	/* CRC when testing "123456789" */
+#define	CRC_POLY_64_ISO_R	0xD800000000000000ull	/* Reversed */
+
+#define	CRC_POLY_64_WE		0x42F0E1EBA9EA3693ull	/* Normal */
+#define	CRC_POLY_64_WE_EXP	0x62EC59E3F1A4F00Aull	/* CRC when testing "123456789" */
+
+#define	CRC_POLY_64_XZ		0x42F0E1EBA9EA3693ull	/* Normal */
+#define	CRC_POLY_64_XZ_EXP	0x995DC9BBDF1939FAull	/* CRC when testing "123456789" */
+
+#define	CRC_START_64		0x0000000000000000ull
+#define	CRC_START_64_ECMA	0x0000000000000000ull
+#define	CRC_START_64_WE		0xFFFFFFFFFFFFFFFFull
+#define	CRC_START_64_INV	0xFFFFFFFFFFFFFFFFull
+#define	CRC_END_64		0x0000000000000000ull
+#define	CRC_END_64_INV		0xFFFFFFFFFFFFFFFFull
+
+#define	CRC_START_32		0xFFFFFFFFul
+#define	CRC_END_32		0xFFFFFFFFul
+
+#define	CRC64_ADDRESS		"___CRC64___"
+#define	CRC64_START		"___CRC64_START___"
+#define	CRC64_END		"___CRC64_END___"
+#define	CRC64_TABLE		"___CRC64_TABLE___"
+
+#define	CRC_POLY_32		0x04C11DB7ul	/* Normal */
+#define	CRC_POLY_32_R		0xEDB88320ul	/* Reversed */
+
+#define	CRC_START_32_INV	0xFFFFFFFFul
+#define	CRC_END_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;
+
+typedef struct
+{
+  uint8_t _0;
+  uint8_t _1;
+  uint8_t _2;
+  uint8_t _3;
+  uint8_t _4;
+  uint8_t _5;
+  uint8_t _6;
+  uint8_t _7;
+} uint8_ut;
+
+typedef struct
+{
+  uint16_t _0;
+  uint16_t _1;
+  uint16_t _2;
+  uint16_t _3;
+} uint16_ut;
+
+typedef struct
+{
+  uint32_t _0;
+  uint32_t _1;
+} uint32_ut;
+
+typedef union
+{
+  uint64_t d64;
+  uint32_ut d32;
+  uint16_ut d16;
+  uint8_ut d8;
+} int_t;
+
+typedef struct
+{
+  algo_t crc_algo;
+  uint32_t crc_size;
+  const char *name;
+  int_t poly;
+  int_t initial;
+  int_t xor_val;
+  bool ireflect;
+  bool oreflect;
+  bool reciprocal;
+  void *crc_tab;
+  int_t expected;
+  bool big_endian;
+} algorithm_desc_t;
+
+extern char *CRC_ADDRESS;
+extern char *CRC_START;
+extern char *CRC_END;
+extern char *CRC_TABLE;
+extern const algorithm_desc_t algorithms[];
+extern algorithm_desc_t algorithm;
+
+extern const char *digest_label;
+extern bool digest_big_endian;
+
+/* CRC-32 */
+extern uint32_t *init_crc32_tab (algorithm_desc_t * dsc);
+extern uint32_t calc_crc32
+  (algorithm_desc_t * dsc, const unsigned char *input_str, size_t num_bytes);
+extern void lang_add_crc32_syndrome (algorithm_desc_t * a);
+
+/* CR-64 */
+extern bfd_vma *init_crc64_tab (algorithm_desc_t * dsc);
+extern bfd_vma calc_crc64
+  (algorithm_desc_t * dsc, const unsigned char *input_str, size_t num_bytes);
+extern void lang_add_crc64_syndrome (algorithm_desc_t * a);
+
+extern void lang_add_digest (bfd_vma size,
+			     bfd_vma poly,
+			     bfd_vma initial,
+			     bfd_vma xor_val,
+			     bfd_vma ireflect,
+			     bfd_vma oreflect, bfd_vma reciprocal);
+extern bool lang_set_digest (char *digest);
+extern void lang_add_digest_table (bool big_endian);
+extern const char *lang_get_label (const char *label, bool *big_endian);
+extern void lang_generate_crc (void);
+extern void lang_generate_digest (void);
+extern void lang_set_digest_section (char *section);
+
+#endif /* LDDIGEST_H */
diff --git a/ld/lddigest_tab.c b/ld/lddigest_tab.c
new file mode 100644
index 00000000000..8752a4ed55f
--- /dev/null
+++ b/ld/lddigest_tab.c
@@ -0,0 +1,147 @@
+/* Linker command language support.
+   Copyright (C) 1991-2023 Ulf Samuelsson <ulf@emagii.com>
+
+   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.  */
+
+typedef enum
+{
+  CRC64_ECMA,
+  CRC64_WE,
+  CRC64_XZ,
+  CRC64_ISO,
+  CRC64_ISO_R,
+  CRC32,
+  MAXALGO
+} poly_t;
+
+#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"
+
+const algorithm_desc_t algorithms[] =
+{
+  [CRC64_ECMA] =
+	{
+		crc_algo_64, 64, "CRC64-ECMA",
+		.poly.d64 = CRC_POLY_64_ECMA,
+		.initial.d64 = CRC_START_64,
+		.xor_val.d64 = CRC_END_64,
+		.ireflect = false,
+		.oreflect = false,
+		.reciprocal = false,
+		.crc_tab = NULL,
+		.expected.d64 = 0x6c40df5f0b497347
+	},
+  [CRC64_WE] =
+	{
+		crc_algo_64, 64, "CRC64-WE",
+		.poly.d64 = CRC_POLY_64_WE,
+		.initial.d64 = CRC_START_64_INV,
+		.xor_val.d64 = CRC_END_64_INV,
+		.ireflect = false,
+		.oreflect = false,
+		.reciprocal = false,
+		.crc_tab = NULL,
+		.expected.d64 = 0x62ec59e3f1a4f00a
+	},
+  [CRC64_XZ] =
+	{
+		crc_algo_64, 64, "CRC64-XZ",
+		.poly.d64 = CRC_POLY_64_XZ,
+		.initial.d64 = CRC_START_64_INV,
+		.xor_val.d64 = CRC_END_64_INV,
+		.ireflect = true,
+		.oreflect = true,
+		.reciprocal = false,
+		.crc_tab = NULL,
+		.expected.d64 = 0x995dc9bbdf1939fa
+	},
+  [CRC64_ISO] =
+	{
+		crc_algo_64, 64, "CRC64-GO-ISO",
+		.poly.d64 = CRC_POLY_64_ISO,
+		.initial.d64 = CRC_START_64_INV,
+		.xor_val.d64 = CRC_END_64_INV,
+		.ireflect = true,
+		.oreflect = true,
+		.reciprocal = false,
+		.crc_tab = NULL,
+		.expected.d64 = 0xb90956c775a41001
+	},
+  [CRC64_ISO_R] =
+	{
+		crc_algo_64, 64, "CRC64-GO-ISO-R",
+		.poly.d64 = CRC_POLY_64_ISO,
+		.initial.d64 = CRC_START_64_INV,
+		.xor_val.d64 = CRC_END_64_INV,
+		.ireflect = false,
+		.oreflect = false,
+		.reciprocal = true,
+		.crc_tab = NULL,
+		.expected.d64 = 0xb90956c775a41001
+	},
+  [CRC32] =
+	{
+		crc_algo_32, 32, "CRC32",
+		.poly.d32._0 = CRC_POLY_32,
+		.initial.d64 = CRC_START_32_INV,
+		.xor_val.d32._0 = CRC_END_32_INV,
+		.ireflect = true,
+		.oreflect = true,
+		.reciprocal = false,
+		.crc_tab = NULL,
+		.expected.d64 = 0xCBF43926
+	},
+  [MAXALGO] =
+	{
+		no_algo, 0, "",
+		.poly.d64 = 0,
+		.initial.d64 = 0,
+		.xor_val.d64 = 0,
+		.ireflect = false,
+		.oreflect = false,
+		.reciprocal = false,
+		.crc_tab = NULL,
+		.expected.d64 = 0
+	}
+};
+
+algorithm_desc_t algorithm =
+{
+		no_algo, 0, "",
+		.poly.d64 = 0,
+		.initial.d64 = 0,
+		.xor_val.d64 = 0,
+		.ireflect = false,
+		.oreflect = false,
+		.reciprocal = false,
+		.crc_tab = NULL,
+		.expected.d64 = 0
+};
diff --git a/ld/ldreflect.c b/ld/ldreflect.c
new file mode 100644
index 00000000000..0601e2a8c1b
--- /dev/null
+++ b/ld/ldreflect.c
@@ -0,0 +1,99 @@
+/* Linker command language support.
+   Copyright (C) 1991-2023 Ulf Samuelsson <ulf@emagii.com>
+
+   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.  */
+
+#include <stdint.h>
+#include <stdlib.h>
+#include "ldreflect.h"
+
+uint8_t reflect_tab[256] = {
+  0x00, 0x80, 0x40, 0xC0, 0x20, 0xA0, 0x60, 0xE0,
+  0x10, 0x90, 0x50, 0xD0, 0x30, 0xB0, 0x70, 0xF0,
+  0x08, 0x88, 0x48, 0xC8, 0x28, 0xA8, 0x68, 0xE8,
+  0x18, 0x98, 0x58, 0xD8, 0x38, 0xB8, 0x78, 0xF8,
+  0x04, 0x84, 0x44, 0xC4, 0x24, 0xA4, 0x64, 0xE4,
+  0x14, 0x94, 0x54, 0xD4, 0x34, 0xB4, 0x74, 0xF4,
+  0x0C, 0x8C, 0x4C, 0xCC, 0x2C, 0xAC, 0x6C, 0xEC,
+  0x1C, 0x9C, 0x5C, 0xDC, 0x3C, 0xBC, 0x7C, 0xFC,
+  0x02, 0x82, 0x42, 0xC2, 0x22, 0xA2, 0x62, 0xE2,
+  0x12, 0x92, 0x52, 0xD2, 0x32, 0xB2, 0x72, 0xF2,
+  0x0A, 0x8A, 0x4A, 0xCA, 0x2A, 0xAA, 0x6A, 0xEA,
+  0x1A, 0x9A, 0x5A, 0xDA, 0x3A, 0xBA, 0x7A, 0xFA,
+  0x06, 0x86, 0x46, 0xC6, 0x26, 0xA6, 0x66, 0xE6,
+  0x16, 0x96, 0x56, 0xD6, 0x36, 0xB6, 0x76, 0xF6,
+  0x0E, 0x8E, 0x4E, 0xCE, 0x2E, 0xAE, 0x6E, 0xEE,
+  0x1E, 0x9E, 0x5E, 0xDE, 0x3E, 0xBE, 0x7E, 0xFE,
+  0x01, 0x81, 0x41, 0xC1, 0x21, 0xA1, 0x61, 0xE1,
+  0x11, 0x91, 0x51, 0xD1, 0x31, 0xB1, 0x71, 0xF1,
+  0x09, 0x89, 0x49, 0xC9, 0x29, 0xA9, 0x69, 0xE9,
+  0x19, 0x99, 0x59, 0xD9, 0x39, 0xB9, 0x79, 0xF9,
+  0x05, 0x85, 0x45, 0xC5, 0x25, 0xA5, 0x65, 0xE5,
+  0x15, 0x95, 0x55, 0xD5, 0x35, 0xB5, 0x75, 0xF5,
+  0x0D, 0x8D, 0x4D, 0xCD, 0x2D, 0xAD, 0x6D, 0xED,
+  0x1D, 0x9D, 0x5D, 0xDD, 0x3D, 0xBD, 0x7D, 0xFD,
+  0x03, 0x83, 0x43, 0xC3, 0x23, 0xA3, 0x63, 0xE3,
+  0x13, 0x93, 0x53, 0xD3, 0x33, 0xB3, 0x73, 0xF3,
+  0x0B, 0x8B, 0x4B, 0xCB, 0x2B, 0xAB, 0x6B, 0xEB,
+  0x1B, 0x9B, 0x5B, 0xDB, 0x3B, 0xBB, 0x7B, 0xFB,
+  0x07, 0x87, 0x47, 0xC7, 0x27, 0xA7, 0x67, 0xE7,
+  0x17, 0x97, 0x57, 0xD7, 0x37, 0xB7, 0x77, 0xF7,
+  0x0F, 0x8F, 0x4F, 0xCF, 0x2F, 0xAF, 0x6F, 0xEF,
+  0x1F, 0x9F, 0x5F, 0xDF, 0x3F, 0xBF, 0x7F, 0xFF
+};
+
+uint8_t
+reflect8 (uint8_t val)
+{
+  return reflect_tab[val];
+}
+
+uint16_t
+reflect16 (uint16_t val)
+{
+  uint16_t result;
+  result = ((uint16_t) reflect_tab[(val >> 0) & 0xFF]) << 8;
+  result |= ((uint16_t) reflect_tab[(val >> 8) & 0xFF]) << 0;
+  return result;
+}
+
+uint32_t
+reflect32 (uint32_t val)
+{
+  uint32_t result;
+  result = ((uint32_t) reflect_tab[(val >> 0) & 0xFF]) << 24;
+  result |= ((uint32_t) reflect_tab[(val >> 8) & 0xFF]) << 16;
+  result |= ((uint32_t) reflect_tab[(val >> 16) & 0xFF]) << 8;
+  result |= ((uint32_t) reflect_tab[(val >> 24) & 0xFF]) << 0;
+  return result;
+}
+
+uint64_t
+reflect64 (uint64_t val)
+{
+  uint64_t result;
+  result = ((uint64_t) reflect_tab[(val >> 0) & 0xFF]) << 56;
+  result |= ((uint64_t) reflect_tab[(val >> 8) & 0xFF]) << 48;
+  result |= ((uint64_t) reflect_tab[(val >> 16) & 0xFF]) << 40;
+  result |= ((uint64_t) reflect_tab[(val >> 24) & 0xFF]) << 32;
+  result |= ((uint64_t) reflect_tab[(val >> 32) & 0xFF]) << 24;
+  result |= ((uint64_t) reflect_tab[(val >> 40) & 0xFF]) << 16;
+  result |= ((uint64_t) reflect_tab[(val >> 48) & 0xFF]) << 8;
+  result |= ((uint64_t) reflect_tab[(val >> 56) & 0xFF]) << 0;
+  return result;
+}
diff --git a/ld/ldreflect.h b/ld/ldreflect.h
new file mode 100644
index 00000000000..a3f834d0acc
--- /dev/null
+++ b/ld/ldreflect.h
@@ -0,0 +1,37 @@
+/*
+ * File:    reflect.h
+ * Author:  Ulf Samuelsson <ulf@emagii.com>
+ *
+ * This file is licensed under the MIT License as stated below
+ *
+ * Copyright (c) 2013 Ulf Samuelsson (ulf@emagii.com)
+ *
+ * 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 REFLECT_H
+#define REFLECT_H
+
+uint8_t reflect8 (uint8_t val);
+uint16_t reflect16 (uint16_t val);
+uint32_t reflect32 (uint32_t val);
+uint64_t reflect64 (uint64_t val);
+
+#endif /* REFLECT_H */
-- 
2.34.1


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

* [PATCH v8 10/11] DIGEST: Makefile.*
  2023-03-01 17:43 [PATCH v8 0/11 Add support for CRC64 generation in linker binutils
                   ` (8 preceding siblings ...)
  2023-03-01 17:43 ` [PATCH v8 09/11] DIGEST: calculation binutils
@ 2023-03-01 17:43 ` binutils
  2023-03-01 17:43 ` [PATCH v8 11/11] Build ldint binutils
  2023-03-02 16:43 ` [PATCH v8 0/11 Add support for CRC64 generation in linker Nick Clifton
  11 siblings, 0 replies; 16+ messages in thread
From: binutils @ 2023-03-01 17:43 UTC (permalink / raw)
  To: binutils; +Cc: nickc, Ulf Samuelsson

From: Ulf Samuelsson <ulf@emagii.com>

The Makefile.in was generated using automake
after adding a few files.

When adding the ldreflect.* files, the autotools
versions were wrong.
After upgrading the host OS, autotools were upgraded to 2.71
reinstalling the desired 2.69 still generates a lot of changes.

Makefile.ini has therefore been manually edited.

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

diff --git a/ld/Makefile.am b/ld/Makefile.am
index 760225c5b88..813f19b354a 100644
--- a/ld/Makefile.am
+++ b/ld/Makefile.am
@@ -479,12 +479,14 @@ 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 \
+	lddigest.c lddigest_tab.c ldcrc32.c ldcrc64.c ldreflect.c \
 	pdb.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 \
+	lddigest.h ldreflect.h \
 	pdb.h
 
 GENERATED_CFILES = ldgram.c ldlex.c deffilep.c
@@ -495,6 +497,8 @@ 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@ lddigest_tab.@OBJEXT@ \
+	ldcrc32.@OBJEXT@ ldcrc64.@OBJEXT@ ldreflect.@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,6 +966,7 @@ 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 lddigest_tab.c ldcrc32.c ldcrc64.c ldreflect.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) \
diff --git a/ld/Makefile.in b/ld/Makefile.in
index d4dddf2f629..6ec916aa629 100644
--- a/ld/Makefile.in
+++ b/ld/Makefile.in
@@ -210,6 +210,8 @@ PROGRAMS = $(bin_PROGRAMS)
 am_ld_new_OBJECTS = ldgram.$(OBJEXT) ldlex-wrapper.$(OBJEXT) \
 	lexsup.$(OBJEXT) ldlang.$(OBJEXT) mri.$(OBJEXT) \
 	ldctor.$(OBJEXT) ldmain.$(OBJEXT) ldwrite.$(OBJEXT) \
+	lddigest.$(OBJEXT) lddigest_tab.$(OBJEXT) \
+	ldcrc32.$(OBJEXT) ldcrc64.$(OBJEXT) ldreflect.$(OBJEXT) \
 	ldexp.$(OBJEXT) ldemul.$(OBJEXT) ldver.$(OBJEXT) \
 	ldmisc.$(OBJEXT) ldfile.$(OBJEXT) ldcref.$(OBJEXT) \
 	plugin.$(OBJEXT) ldbuildid.$(OBJEXT)
@@ -533,6 +535,7 @@ pdfdir = @pdfdir@
 prefix = @prefix@
 program_transform_name = @program_transform_name@
 psdir = @psdir@
+runstatedir = @runstatedir@
 sbindir = @sbindir@
 sharedstatedir = @sharedstatedir@
 srcdir = @srcdir@
@@ -978,12 +981,14 @@ 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 \
+	lddigest.c lddigest_tab.c ldcrc32.c ldcrc64.c ldreflect.c \
 	pdb.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 \
+	lddigest.h ldreflect.h \
 	pdb.h
 
 GENERATED_CFILES = ldgram.c ldlex.c deffilep.c
@@ -993,6 +998,8 @@ 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@ lddigest_tab.@OBJEXT@ \
+	ldcrc32.@OBJEXT@ ldcrc64.@OBJEXT@ ldreflect.@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 +1021,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 lddigest_tab.c ldcrc32.c ldcrc64.c ldreflect.c \
 	ldwrite.c ldexp.c ldemul.c ldver.c ldmisc.c ldfile.c ldcref.c plugin.c \
 	ldbuildid.c
 
@@ -1560,8 +1568,12 @@ 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)/lddigest_tab.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@
@@ -1573,6 +1585,7 @@ distclean-compile:
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ldlex.Po@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ldmain.Po@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ldmisc.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ldreflect.Po@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ldver.Po@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ldwrite.Po@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/lexsup.Po@am__quote@
-- 
2.34.1


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

* [PATCH v8 11/11] Build ldint
  2023-03-01 17:43 [PATCH v8 0/11 Add support for CRC64 generation in linker binutils
                   ` (9 preceding siblings ...)
  2023-03-01 17:43 ` [PATCH v8 10/11] DIGEST: Makefile.* binutils
@ 2023-03-01 17:43 ` binutils
  2023-03-02 16:43 ` [PATCH v8 0/11 Add support for CRC64 generation in linker Nick Clifton
  11 siblings, 0 replies; 16+ messages in thread
From: binutils @ 2023-03-01 17:43 UTC (permalink / raw)
  To: binutils; +Cc: nickc, Ulf Samuelsson

From: Ulf Samuelsson <ulf@emagii.com>

Signed-off-by: Ulf Samuelsson <ulf@emagii.com>
---
 ld/Makefile.am | 16 +++++++++++++--
 ld/Makefile.in | 53 ++++++++++++++++++++++++++++++++++++++++++++------
 2 files changed, 61 insertions(+), 8 deletions(-)

diff --git a/ld/Makefile.am b/ld/Makefile.am
index 813f19b354a..00118f8da13 100644
--- a/ld/Makefile.am
+++ b/ld/Makefile.am
@@ -128,7 +128,7 @@ CXXFLAGS_FOR_TARGET = `echo $(CXXFLAGS) | sed -e 's/-fsanitize=[^ ]*//g'`
 
 transform = s/^ld-new$$/$(installed_linker)/;@program_transform_name@
 bin_PROGRAMS = ld-new
-info_TEXINFOS = ld.texi
+info_TEXINFOS = ld.texi ldint.texi
 ld_TEXINFOS = configdoc.texi
 noinst_TEXINFOS = ldint.texi
 man_MANS = ld.1
@@ -1060,7 +1060,19 @@ ld.1: $(srcdir)/ld.texi configdoc.texi
 		(rm -f $@.T$$$$ && exit 1)
 	$(AM_V_at)rm -f ld.pod
 
-MAINTAINERCLEANFILES = configdoc.texi ld.1
+# Build the man page from the texinfo file
+# The sed command removes the no-adjust Nroff command so that
+# the man output looks standard.
+ldint.1: $(srcdir)/ldint.texi configdoc.texi
+	$(AM_V_GEN)touch $@
+	$(AM_V_at)-$(TEXI2POD) $(MANCONF) < $(srcdir)/ldint.texi > ldint.pod
+	$(AM_V_at)-($(POD2MAN) ldint.pod | \
+		sed -e '/^.if n .na/d' > $@.T$$$$ && \
+		mv -f $@.T$$$$ $@) || \
+		(rm -f $@.T$$$$ && exit 1)
+	$(AM_V_at)rm -f ldint.pod
+
+MAINTAINERCLEANFILES = configdoc.texi ld.1 ldint.1
 
 # We want to reconfigure if configure.host or configure.tgt changes.
 # development.sh is used to determine -Werror default.
diff --git a/ld/Makefile.in b/ld/Makefile.in
index 6ec916aa629..7bf51bffa54 100644
--- a/ld/Makefile.in
+++ b/ld/Makefile.in
@@ -305,11 +305,11 @@ am__v_texidevnull_0 = > /dev/null
 am__v_texidevnull_1 = 
 INFO_DEPS = ld.info
 am__TEXINFO_TEX_DIR = $(srcdir)/../texinfo
-DVIS = ld.dvi
-PDFS = ld.pdf
-PSS = ld.ps
-HTMLS = ld.html
-TEXINFOS = ld.texi
+DVIS = ld.dvi ldint.dvi
+PDFS = ld.pdf ldint.pdf
+PSS = ld.ps ldint.ps
+HTMLS = ld.html ldint.html
+TEXINFOS = ld.texi ldint.texi
 TEXI2PDF = $(TEXI2DVI) --pdf --batch
 MAKEINFOHTML = $(MAKEINFO) --html
 AM_MAKEINFOHTMLFLAGS = $(AM_MAKEINFOFLAGS)
@@ -1682,18 +1682,48 @@ ld.info: ld.texi $(ld_TEXINFOS)
 	fi; \
 	rm -rf $$backupdir; exit $$rc
 
+ldint.info: ld.texi $(ld_TEXINFOS)
+	$(AM_V_MAKEINFO)restore=: && backupdir="$(am__leading_dot)am$$$$" && \
+	rm -rf $$backupdir && mkdir $$backupdir && \
+	if ($(MAKEINFO) --version) >/dev/null 2>&1; then \
+	  for f in $@ $@-[0-9] $@-[0-9][0-9] $(@:.info=).i[0-9] $(@:.info=).i[0-9][0-9]; do \
+	    if test -f $$f; then mv $$f $$backupdir; restore=mv; else :; fi; \
+	  done; \
+	else :; fi && \
+	if $(MAKEINFO) $(AM_MAKEINFOFLAGS) $(MAKEINFOFLAGS) -I $(srcdir) \
+	 -o $@ `test -f 'ldint.texi' || echo '$(srcdir)/'`ldint.texi; \
+	then \
+	  rc=0; \
+	else \
+	  rc=$$?; \
+	  $$restore $$backupdir/* `echo "./$@" | sed 's|[^/]*$$||'`; \
+	fi; \
+	rm -rf $$backupdir; exit $$rc
+
 ld.dvi: ld.texi $(ld_TEXINFOS) 
 	$(AM_V_TEXI2DVI)TEXINPUTS="$(am__TEXINFO_TEX_DIR)$(PATH_SEPARATOR)$$TEXINPUTS" \
 	MAKEINFO='$(MAKEINFO) $(AM_MAKEINFOFLAGS) $(MAKEINFOFLAGS) -I $(srcdir)' \
 	$(TEXI2DVI) $(AM_V_texinfo) --build-dir=$(@:.dvi=.t2d) -o $@ $(AM_V_texidevnull) \
 	`test -f 'ld.texi' || echo '$(srcdir)/'`ld.texi
 
-ld.pdf: ld.texi $(ld_TEXINFOS) 
+ldint.dvi: ldint.texi $(ld_TEXINFOS)
+	$(AM_V_TEXI2DVI)TEXINPUTS="$(am__TEXINFO_TEX_DIR)$(PATH_SEPARATOR)$$TEXINPUTS" \
+	MAKEINFO='$(MAKEINFO) $(AM_MAKEINFOFLAGS) $(MAKEINFOFLAGS) -I $(srcdir)' \
+	$(TEXI2DVI) $(AM_V_texinfo) --build-dir=$(@:.dvi=.t2d) -o $@ $(AM_V_texidevnull) \
+	`test -f 'ldint.texi' || echo '$(srcdir)/'`ldint.texi
+
+ld.pdf: ld.texi $(ld_TEXINFOS)
 	$(AM_V_TEXI2PDF)TEXINPUTS="$(am__TEXINFO_TEX_DIR)$(PATH_SEPARATOR)$$TEXINPUTS" \
 	MAKEINFO='$(MAKEINFO) $(AM_MAKEINFOFLAGS) $(MAKEINFOFLAGS) -I $(srcdir)' \
 	$(TEXI2PDF) $(AM_V_texinfo) --build-dir=$(@:.pdf=.t2p) -o $@ $(AM_V_texidevnull) \
 	`test -f 'ld.texi' || echo '$(srcdir)/'`ld.texi
 
+ldint.pdf: ldint.texi $(ld_TEXINFOS)
+	$(AM_V_TEXI2PDF)TEXINPUTS="$(am__TEXINFO_TEX_DIR)$(PATH_SEPARATOR)$$TEXINPUTS" \
+	MAKEINFO='$(MAKEINFO) $(AM_MAKEINFOFLAGS) $(MAKEINFOFLAGS) -I $(srcdir)' \
+	$(TEXI2PDF) $(AM_V_texinfo) --build-dir=$(@:.pdf=.t2p) -o $@ $(AM_V_texidevnull) \
+	`test -f 'ldint.texi' || echo '$(srcdir)/'`ldint.texi
+
 ld.html: ld.texi $(ld_TEXINFOS) 
 	$(AM_V_MAKEINFO)rm -rf $(@:.html=.htp)
 	$(AM_V_at)if $(MAKEINFOHTML) $(AM_MAKEINFOHTMLFLAGS) $(MAKEINFOFLAGS) -I $(srcdir) \
@@ -1703,6 +1733,17 @@ ld.html: ld.texi $(ld_TEXINFOS)
 	else \
 	  rm -rf $(@:.html=.htp); exit 1; \
 	fi
+
+ldint.html: ldint.texi $(ld_TEXINFOS)
+	$(AM_V_MAKEINFO)rm -rf $(@:.html=.htp)
+	$(AM_V_at)if $(MAKEINFOHTML) $(AM_MAKEINFOHTMLFLAGS) $(MAKEINFOFLAGS) -I $(srcdir) \
+	 -o $(@:.html=.htp) `test -f 'ldint.texi' || echo '$(srcdir)/'`ldint.texi; \
+	then \
+	  rm -rf $@ && mv $(@:.html=.htp) $@; \
+	else \
+	  rm -rf $(@:.html=.htp); exit 1; \
+	fi
+
 .dvi.ps:
 	$(AM_V_DVIPS)TEXINPUTS="$(am__TEXINFO_TEX_DIR)$(PATH_SEPARATOR)$$TEXINPUTS" \
 	$(DVIPS) $(AM_V_texinfo) -o $@ $<
-- 
2.34.1


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

* Re: [PATCH v8 0/11 Add support for CRC64 generation in linker
  2023-03-01 17:43 [PATCH v8 0/11 Add support for CRC64 generation in linker binutils
                   ` (10 preceding siblings ...)
  2023-03-01 17:43 ` [PATCH v8 11/11] Build ldint binutils
@ 2023-03-02 16:43 ` Nick Clifton
  2023-03-02 22:02   ` Ulf Samuelsson
  2023-03-03  7:28   ` Ulf Samuelsson
  11 siblings, 2 replies; 16+ messages in thread
From: Nick Clifton @ 2023-03-02 16:43 UTC (permalink / raw)
  To: binutils, binutils

Hi Ulf,

   The patch set is looking good so far.

   I have been running some experiments on misusing the DIGEST directive
   and found a few problems.  For example, if I want to have two digests
   in my binary:

      % ld foo.o -T test.t
     ld:test.t:19: warning: Only the first CRC polynome is used
     ld:crc.t:0: warning: updating CRC failed
     CRC generation aborted

   which would be fine, except for the fact that the link succeeds:

     % echo $?
     0

  (Hint: You can use %X in your message string when calling einfo() to set
   an error exit code...)

   Even better would be to allow an number of digests.  I still do not know
   why you want to have a limit of 1.


   I do not like using the DIGEST SECTION directive to specify the section
   for the digest.  This should be implied by the presence of the DIGEST
   directive itself.  For example:

     .data : { DIGEST ... }

   ought to create a digest in the .data section.  Furthermore it seems that
   the DIGEST SECTION directive does not work reliably:

     % cat test.t
     _start = 0x000000;
     SECTIONS
     {
       . = 0x1000 + SIZEOF_HEADERS;

       .foo ALIGN (CONSTANT (COMMONPAGESIZE)) :
        {
           foo_start = .;
           *(.foo)
           foo_end = .;
         }

         .data ALIGN (CONSTANT (COMMONPAGESIZE)) :
         {
           DIGEST SECTION ".foo"
           DIGEST "BE.BE.BE" POLY (64,a,b,c,d,e,f) (foo_start , foo_end)
           *(.data)
         }

        /DISCARD/ : { *(*) }
     }

     % ld -T test.t foo.o
     ld:test.t:0: warning: updating CRC failed
     CRC generation aborted


   Another issue - if the digest is unrecognised then the error message
   is not very helpful.  For example I tried:

      DIGEST "0.BE" "TCRC32" (___CRC32_START___ , text_end)

   and received the error message:

     ld: Unknown DIGEST: no error

   (There is no line number in the error message, nor does it repeat of the
   unrecognized name).

   Incidentally if a valid digest name is used in the above example a symbol
   with the name "0" is generated, which is not really allowed as symbol
   names should not start with a numeric value.  But that is probably being
   too pedantic.


   Oh - and here is a good one.  If the start symbol is beyond the end symbol
   the code triggers a segmentation fault:

     % cat test.t
     [...]
     .text ALIGN (CONSTANT (COMMONPAGESIZE)) :
       {
         DIGEST "BE.BE.BE" POLY (64,a,b,c,d,e,f) (text_end , text_start)
         text_start = .;
         *(.text)
         text_end = .;
       }
      [...]

     % ld foo.o -T test.t
     Segmentation fault (core dumped)


   I am not sure if the next one matters or not, but just in case: The
   checksum and crc table can be generated on unaligned boundaries if
   the code does not happen to be aligned.  For example:

     .text ALIGN (CONSTANT (COMMONPAGESIZE)) :
       {
         BYTE(0);
         DIGEST "BE.BE.BE" POLY (64,a,b,c,d,e,f) (text_start , text_end)
         text_start = .;
         *(.text)
         text_end = .;
       }


   If the new directives are used outside of an output section then they
   do not generate very helpful error messages.  For example:

     % cat test.t
     _start = 0x000000;
     SECTIONS
     {
       DEBUG ON
       /DISCARD/ : { *(*) }
     }

     % ld foo.o -T test.t
     ld:test.t:5: syntax error

   (Note the incorrect line number for the error).  This is probably a limitation
   of the grammar supported by bison however, so I would not be surprised if there
   is no easy way to fix it.


   On a related note - I think that there is a problem with the checksum
   generation.  Specifically using the ".BE" suffix to indicate that a
   big-endian checksum should be computed.  The problem is that some targets
   support both big-endian and little-endian output, selectable via a
   command line option, and so a static choice in a linker script is
   inappropriate.  May I suggest an alternative ?  Support both ".LE" and
   ".BE" suffixes, and if neither is specified then use whichever endian
   format has been selected by the command line.

Cheers
   Nick


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

* Re: [PATCH v8 0/11 Add support for CRC64 generation in linker
  2023-03-02 16:43 ` [PATCH v8 0/11 Add support for CRC64 generation in linker Nick Clifton
@ 2023-03-02 22:02   ` Ulf Samuelsson
  2023-03-03  7:28   ` Ulf Samuelsson
  1 sibling, 0 replies; 16+ messages in thread
From: Ulf Samuelsson @ 2023-03-02 22:02 UTC (permalink / raw)
  To: Nick Clifton, binutils


On 2023-03-02 17:43, Nick Clifton wrote:
> Hi Ulf,
>
>   The patch set is looking good so far.
>
>   I have been running some experiments on misusing the DIGEST directive
>   and found a few problems.  For example, if I want to have two digests
>   in my binary:
>
>      % ld foo.o -T test.t
>     ld:test.t:19: warning: Only the first CRC polynome is used
>     ld:crc.t:0: warning: updating CRC failed
>     CRC generation aborted
>
>   which would be fine, except for the fact that the link succeeds:
>
>     % echo $?
>     0
>
>  (Hint: You can use %X in your message string when calling einfo() to set
>   an error exit code...)
>
>   Even better would be to allow an number of digests.  I still do not 
> know
>   why you want to have a limit of 1.

I only see the DIGEST feature as useful for an embedded system executing 
from flash.
It would not be used for applications running linux - until linux starts 
to CRC check
the applications before they run.
Embedded Linux, typically compresses the kernel and encapsulates the the
compressed data in a header (U-Boot mkimage) is an example,
but that, I think is outside the scope of the linker.

In an embedded system you use the digest in two ways.

1. The bootloader will start by verifying its own contents.
     At reset, the ".data" and ".bss" sections of the bootloader are 
uninitialized.
     They will be initialized by the bootloader, from the ".text" section.
     The CRC check will be done before initialization so you cannot
     use this to check the ".data" or ".bss".

2. The bootloader will verify the real application before it is started.

     The application has a header containing the digest in a location 
known to the bootloader.
     The check should be of the *entire flash contents* except the 
digest itself.
     There is nothing else to check so having additional checks is 
meaningless.
     The bootloader cannot check the ".data" or ".bss" of the application
     because they are initialized by the application, and the bootloader 
will check
     before the application is started.
     The bootloader will again check the entire flash contents, leaving 
nothing else to check.

     If the application needs to do a selfcheck of the flash while running,
     it will use the same digest as the bootloader and check the same area.
     There is no need for a new digest for this.

     If the application needs to calculate CRC on other things, like 
communications,
     using another CRC algorithm, it can add the CRC routines and table 
in the
     application code. Doing it in the linker just adds complexity.

     That is why I suspect it does not make sense to support anything 
but ".text"
     and it does not make sense to have more than one digest.

=================================================

     I can see that it would be good to have a built in function inside 
the gcc compiler
     that would generate crc routines.

     I.E: Something like this:

     #pragma digest "CRC64-ECMA" "crc_ecma" using "crc_tab"

     #pragma digest_table "CRC64-ECMA" "crc_tab"

       extern uint64_t crc_ecma(char *s, uint32_t numbytes);

=================================================

The digest table is strictly not neccessary, but it is convenient and 
removes the risk

that the user uses a different table than the table used to generate the 
digest in the linker.

=============================================

If you try to use two digests in error, then you have two cases.

1. You add a second digest which is not used by the application.
     Then the link completes with a warning.
     Really not worrysome.

2. You add a second digest which is used by the application.

     DIGEST "digest1" "CRC64-ECMA"
     DIGEST "digest2" "CRC64-ISO"

     The application needs to refer to the digest and declares.
     extern uint64_t digest1;
     extern uint64_t digest2;

     uint64_t mycrc = digest2;

     The linker will not find "digest2" and will report that as an error;
     and then the warning message will be detected as the user looks at 
the log.

===============================================
>
>   I do not like using the DIGEST SECTION directive to specify the section
>   for the digest.  This should be implied by the presence of the DIGEST
>   directive itself.  For example:
>
>     .data : { DIGEST ... }

I did not manage to figure out which section I am in
when the digest command is executed, so I tool the easy way out.

As I said above, this is not going to happen in the real world
as you cannot use this to check the ".data" section in an proper setup.

I'd like to remove the function and only support ".text".

>
>   ought to create a digest in the .data section.  Furthermore it seems 
> that
>   the DIGEST SECTION directive does not work reliably:
>
>     % cat test.t
>     _start = 0x000000;
>     SECTIONS
>     {
>       . = 0x1000 + SIZEOF_HEADERS;
>
>       .foo ALIGN (CONSTANT (COMMONPAGESIZE)) :
>        {
>           foo_start = .;
>           *(.foo)
>           foo_end = .;
>         }
>
>         .data ALIGN (CONSTANT (COMMONPAGESIZE)) :
>         {
>           DIGEST SECTION ".foo"
>           DIGEST "BE.BE.BE" POLY (64,a,b,c,d,e,f) (foo_start , foo_end)
>           *(.data)
>         }
>
>        /DISCARD/ : { *(*) }
>     }
>
>     % ld -T test.t foo.o
>     ld:test.t:0: warning: updating CRC failed
>     CRC generation aborted
>
>
The digest, start and end needs to be in the same section.
You put the start and end in ".foo" and the digest in ".data".

I do a check that the digest and the start/end are in the selected
section, but I do not understand why there is no error message.

===============================================
> Another issue - if the digest is unrecognised then the error message
>   is not very helpful.  For example I tried:
>
>      DIGEST "0.BE" "TCRC32" (___CRC32_START___ , text_end)
>
>   and received the error message:
>
>     ld: Unknown DIGEST: no error
>
Will see if I can fix that.

> (There is no line number in the error message, nor does it repeat of the
>   unrecognized name).
>
>   Incidentally if a valid digest name is used in the above example a 
> symbol
>   with the name "0" is generated, which is not really allowed as symbol
>   names should not start with a numeric value.  But that is probably 
> being
>   too pedantic.

If the user tries to access the digest, he needs to declare a variable with
the name "0"

I.E:

uint64_t   0;

Good luck with that :-)

If I read the manual, I find this:

####################

3.10.3 Symbol Names
Unless quoted, symbol names start with a letter, underscore, or period 
and may include
letters, digits, underscores, periods, and hyphens. Unquoted symbol 
names must not conflict
with any keywords. You can specify a symbol which contains odd 
characters or has the
same name as a keyword by surrounding the symbol name in double quotes:

   "SECTION" = 9;

   "with a space" = "also with a space" + 10;

Since symbols can contain many non-alphabetic characters, it is safest 
to delimit symbols
with spaces. For example, ‘A-B’ is one symbol, whereas ‘A - B’ is an 
expression involving
subtraction.

####################

so "0" is actually a legal symbol in the linker.

Since '.' is also a legal character, I will change the endian character 
to '#'.

I.E:

    DIGEST "CRC#BE" "CRC64-ECMA"

===============================================
>   Oh - and here is a good one.  If the start symbol is beyond the end 
> symbol
>   the code triggers a segmentation fault:
>
>     % cat test.t
>     [...]
>     .text ALIGN (CONSTANT (COMMONPAGESIZE)) :
>       {
>         DIGEST "BE.BE.BE" POLY (64,a,b,c,d,e,f) (text_end , text_start)
>         text_start = .;
>         *(.text)
>         text_end = .;
>       }
>      [...]
>
>     % ld foo.o -T test.t
>     Segmentation fault (core dumped)
OK,  I verify the sanity of those variables, and that is a simple check 
which I will add.
>
>
>   I am not sure if the next one matters or not, but just in case: The
>   checksum and crc table can be generated on unaligned boundaries if
>   the code does not happen to be aligned.  For example:
>
>     .text ALIGN (CONSTANT (COMMONPAGESIZE)) :
>       {
>         BYTE(0);
>         DIGEST "BE.BE.BE" POLY (64,a,b,c,d,e,f) (text_start , text_end)
>         text_start = .;
>         *(.text)
>         text_end = .;
>       }

Since there are architectures which supports byte aligned instructions
it is up to the user to specify alignment in the linker file.
( I was raised with the Series 32000 which supported instruction lengths 
between 2..23 bytes )

If they need the alignment but fail in the linker file,
then this will result in a trap when testing.

================================================

>   If the new directives are used outside of an output section then they
>   do not generate very helpful error messages.  For example:
>
>     % cat test.t
>     _start = 0x000000;
>     SECTIONS
>     {
>       DEBUG ON
>       /DISCARD/ : { *(*) }
>     }
>
>     % ld foo.o -T test.t
>     ld:test.t:5: syntax error
>
>   (Note the incorrect line number for the error).  This is probably a 
> limitation
>   of the grammar supported by bison however, so I would not be 
> surprised if there
>   is no easy way to fix it.

That is part of the higher level parsing, so there is probably nothing I 
can do about that.

The line number problem is also high level parsing, so I think that 
should be reported as a bug.
I suspect you get the same problem if you replace the DEBUG with a QUAD 
directive in the same place.

================================================

>
>   On a related note - I think that there is a problem with the checksum
>   generation.  Specifically using the ".BE" suffix to indicate that a
>   big-endian checksum should be computed.  The problem is that some 
> targets
>   support both big-endian and little-endian output, selectable via a
>   command line option, and so a static choice in a linker script is
>   inappropriate.  May I suggest an alternative ?  Support both ".LE" and
>   ".BE" suffixes, and if neither is specified then use whichever endian
>   format has been selected by the command line.
>
I can have a look at that.

It will be small endian if nothing is specified in the label nor in the 
command line.


> Cheers
>   Nick
>

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

* Re: [PATCH v8 0/11 Add support for CRC64 generation in linker
  2023-03-02 16:43 ` [PATCH v8 0/11 Add support for CRC64 generation in linker Nick Clifton
  2023-03-02 22:02   ` Ulf Samuelsson
@ 2023-03-03  7:28   ` Ulf Samuelsson
  2023-03-03  9:47     ` Nick Clifton
  1 sibling, 1 reply; 16+ messages in thread
From: Ulf Samuelsson @ 2023-03-03  7:28 UTC (permalink / raw)
  To: Nick Clifton, binutils

Is there a way to run a test which is expected to fail,
to check that an error message is generated?

Best Regards
Ulf Samuelsson

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

* Re: [PATCH v8 0/11 Add support for CRC64 generation in linker
  2023-03-03  7:28   ` Ulf Samuelsson
@ 2023-03-03  9:47     ` Nick Clifton
  0 siblings, 0 replies; 16+ messages in thread
From: Nick Clifton @ 2023-03-03  9:47 UTC (permalink / raw)
  To: Ulf Samuelsson, binutils

Hi Ulf,

> Is there a way to run a test which is expected to fail,
> to check that an error message is generated?

Yes.  You can use the "error:" directive in the .d control file.
For example see ld/testsuite/ld-scripts/align2c.d.  (There are
lots more example of this in other files in the testuite).

If it helps there is also a "#warning:" directive to look for
warning messages.

Cheers
   Nick



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

end of thread, other threads:[~2023-03-03  9:47 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-03-01 17:43 [PATCH v8 0/11 Add support for CRC64 generation in linker binutils
2023-03-01 17:43 ` [PATCH v8 01/11] DIGEST: LICENSING binutils
2023-03-01 17:43 ` [PATCH v8 02/11] DIGEST: NEWS binutils
2023-03-01 17:43 ` [PATCH v8 03/11] DIGEST: Documentation binutils
2023-03-01 17:43 ` [PATCH v8 04/11] DIGEST: testsuite binutils
2023-03-01 17:43 ` [PATCH v8 05/11] DIGEST: ldlex.l binutils
2023-03-01 17:43 ` [PATCH v8 06/11] DIGEST: ldgram.y binutils
2023-03-01 17:43 ` [PATCH v8 07/11] DIGEST: ldmain.c binutils
2023-03-01 17:43 ` [PATCH v8 08/11] DIGEST: ldlang.*: add timestamp binutils
2023-03-01 17:43 ` [PATCH v8 09/11] DIGEST: calculation binutils
2023-03-01 17:43 ` [PATCH v8 10/11] DIGEST: Makefile.* binutils
2023-03-01 17:43 ` [PATCH v8 11/11] Build ldint binutils
2023-03-02 16:43 ` [PATCH v8 0/11 Add support for CRC64 generation in linker Nick Clifton
2023-03-02 22:02   ` Ulf Samuelsson
2023-03-03  7:28   ` Ulf Samuelsson
2023-03-03  9:47     ` Nick Clifton

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