* [PATCH v7 01/11] DIGEST: LICENSING
2023-03-01 15:45 [PATCH v7 0/11 Add support for CRC64 generation in linker binutils
@ 2023-03-01 15:45 ` binutils
2023-03-01 15:45 ` [PATCH v7 02/11] DIGEST: NEWS binutils
` (5 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: binutils @ 2023-03-01 15:45 UTC (permalink / raw)
To: binutils; +Cc: nickc, Ulf Samuelsson
From: Ulf Samuelsson <ulf@emagii.com>
Signed-off-by: Ulf Samuelsson <ulf@emagii.com>
---
ld/COPYING.www.libcrc.org | 45 ++++++++++++++++++++++++++++++++++++
ld/COPYING.www.sunshine2k.de | 25 ++++++++++++++++++++
2 files changed, 70 insertions(+)
create mode 100755 ld/COPYING.www.libcrc.org
create mode 100644 ld/COPYING.www.sunshine2k.de
diff --git a/ld/COPYING.www.libcrc.org b/ld/COPYING.www.libcrc.org
new file mode 100755
index 00000000000..e8b7226ab89
--- /dev/null
+++ b/ld/COPYING.www.libcrc.org
@@ -0,0 +1,45 @@
+The GNU linker contains CRC routines that are used to implement the
+DIGEST CRC32/64 commands in the output section.
+
+The CRC routines are extracted from LIBCRC available at
+* https://www.libcrc.org/
+* https://github.com/lammertb/libcrc/tree/v2.0
+
+The license file from libcrc is below.
+================================================================================
+/*
+ * Library: libcrc
+ * File: src/crc64.c
+ * Author: Lammert Bies
+ *
+ * This file is licensed under the MIT License as stated below
+ *
+ * Copyright (c) 2016 Lammert Bies
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all
+ * copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ *
+ * Description
+ * -----------
+ * The source file src/crc64.c contains the routines which are needed to
+ * calculate a 64 bit CRC value of a sequence of bytes.
+ */
+================================================================================
+NOTE: The user could/(should) extract the CRC calculation routines
+ and add to their program.
+ The linker can add the table, but not the calculation routines.
diff --git a/ld/COPYING.www.sunshine2k.de b/ld/COPYING.www.sunshine2k.de
new file mode 100644
index 00000000000..636496fe047
--- /dev/null
+++ b/ld/COPYING.www.sunshine2k.de
@@ -0,0 +1,25 @@
+The ld.bfd linker contains code from the http://www.sunshine2k.de/ website
+This code is released under the license below
+================================================================================
+All content of this website is released under the MIT license as follows:
+
+Copyright (c) 2021 Bastian Molkenthin
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+THE SOFTWARE.
+================================================================================
--
2.34.1
^ permalink raw reply [flat|nested] 8+ messages in thread
* [PATCH v7 02/11] DIGEST: NEWS
2023-03-01 15:45 [PATCH v7 0/11 Add support for CRC64 generation in linker binutils
2023-03-01 15:45 ` [PATCH v7 01/11] DIGEST: LICENSING binutils
@ 2023-03-01 15:45 ` binutils
2023-03-01 15:45 ` [PATCH v7 03/11] DIGEST: Documentation binutils
` (4 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: binutils @ 2023-03-01 15:45 UTC (permalink / raw)
To: binutils; +Cc: nickc, Ulf Samuelsson
From: Ulf Samuelsson <ulf@emagii.com>
Signed-off-by: Ulf Samuelsson <ulf@emagii.com>
---
ld/NEWS | 80 ++++++++++++++++++++++++++++++++++++++++++++++++++++++---
1 file changed, 76 insertions(+), 4 deletions(-)
diff --git a/ld/NEWS b/ld/NEWS
index 4b91f2c3b0a..e245d3da4dc 100644
--- a/ld/NEWS
+++ b/ld/NEWS
@@ -1,5 +1,77 @@
-*- text -*-
+* The linker script has a new command to insert a timestamp
+ TIMESTAMP
+ inserts the current time (seconds since Epoch) as a 64-bit value
+
+* The linker script syntax has new commands for debugging a linker script
+ DEBUG ON turns on debugging
+ DEBUG OFF turns off debugging
+
+* The linker script syntax has new commands for handling CRC-32/64 calculations
+ on the '.text' section
+ It uses code from https://www.libcrc.org/
+
+ DIGEST "<label>[.BE]" "CRC32" (start, end)
+ DIGEST "<label>[.BE]" "CRC64-ECMA" (start, end)
+ DIGEST "<label>[.BE]" "CRC64-GO-ISO" (start, end)
+ DIGEST "<label>[.BE]" "CRC64-GO-ISO-R" (start, end)
+ DIGEST "<label>[.BE]" "CRC64-WE" (start, end)
+ DIGEST "<label>[.BE]" "CRC64-XZ" (start, end)
+ DIGEST "<label>[.BE]" POLY (<params>) (start, end)
+ DIGEST TABLE "<label>[.BE]"
+ DIGEST SECTION "<section>"
+
+ The CRC32, CRC64-ECMA, CRC64-ISO, CRC64-WE and POLY defines
+ the polynome to use and reserves space for the 32/64-bit CRC in the
+ current section (default ".text"). It also defines a label "<label>".
+
+ When generating a custom polynome you have to supply parameters
+ in the following order
+ * size {32 | 64 }
+ * polynome
+ * initial initial value of crc
+ * xor value xor with this before returning result
+ * input reflect bitreverse input data
+ * output reflect bitreverse result
+ * reciprocal bitreverse polynome
+
+ These terms are explained at
+ http://www.sunshine2k.de/articles/coding/crc/understanding_crc.html
+
+ The checksum is generated in little endian format, but this
+ can be overridden by adding a ".BE" modifier to the label string.
+ The generated label does not include the modifier.
+
+ The user can do the CRC check in another section through the
+ DIGEST SECTION command by specifying the name of the section.
+
+ The 32 bit DIGEST <polynome> command defines some global symbols.
+ ___CRC32___ is the address of the CRC64 checksum
+ ___CRC32_START___ is the address where CRC calculation starts
+ ___CRC32_END___ The CRC calculation ends before this address.
+
+ The 64-bit DIGEST <polynome> command defines some global symbols.
+ ___CRC64___ is the address of the CRC64 checksum
+ ___CRC64_START___ is the address where CRC calculation starts
+ ___CRC64_END___ The CRC calculation ends before this address.
+
+ All three symbols must refer to addresses in the selected section.
+ If they are defined at the end of the linking process, then
+ the CRC## will be calculated between
+
+ ___CRC##_START___ .. ___CRC##_END___ -1
+
+ and the result will be inserted at ___CRC##___.
+
+ ___CRC##___ must be outside the region where CRC is calculated
+
+ The DIGEST TABLE command generates a table for CRC generation.
+ A table is not neccessary, but will speed up the calculation.
+ It defines the ___CRC##_TABLE___ symbol at the start of the table.
+ The user may choose to add this table to his code instead of using
+ the linker.
+
* The linker script syntax has two new commands for inserting text into output
sections:
ASCII (<size>) "string"
@@ -41,16 +113,16 @@ Changes in 2.39:
re-enabled via the --warn-rwx-segments option.
New configure options can also control these new features:
-
+
--enable-warn-execstack=no
will disable the warnings about creating an executable stack.
-
+
--enable-warn-execstack=yes
will make --warn-execstack enabled by default.
-
+
--enable-warn-rwx-segments=no
will make --no-warn-rwx-segments enabled by default.
-
+
--enable-default-execstack=no
will stop the creation of an executable stack simply because an input file
is missing a .note.GNU-stack section, even on architectures where this
--
2.34.1
^ permalink raw reply [flat|nested] 8+ messages in thread
* [PATCH v7 03/11] DIGEST: Documentation
2023-03-01 15:45 [PATCH v7 0/11 Add support for CRC64 generation in linker binutils
2023-03-01 15:45 ` [PATCH v7 01/11] DIGEST: LICENSING binutils
2023-03-01 15:45 ` [PATCH v7 02/11] DIGEST: NEWS binutils
@ 2023-03-01 15:45 ` binutils
2023-03-01 15:45 ` [PATCH v7 04/11] DIGEST: testsuite binutils
` (3 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: binutils @ 2023-03-01 15:45 UTC (permalink / raw)
To: binutils; +Cc: nickc, Ulf Samuelsson
From: Ulf Samuelsson <ulf@emagii.com>
Signed-off-by: Ulf Samuelsson <ulf@emagii.com>
---
ld/ld.texi | 514 ++++++++++++++++++++++++++++++++++++++++++++++++++++-
1 file changed, 510 insertions(+), 4 deletions(-)
diff --git a/ld/ld.texi b/ld/ld.texi
index 3367075cae8..fd992d4480c 100644
--- a/ld/ld.texi
+++ b/ld/ld.texi
@@ -5302,7 +5302,7 @@ __stop_SECNAME, where SECNAME is the name of the section. These
indicate the start address and end address of the output section
respectively. Note: most section names are not representable as
C identifiers because they contain a @samp{.} character.
-
+@page
@node Output Section Data
@subsection Output Section Data
@cindex data
@@ -5353,10 +5353,28 @@ whereas this will work:
@smallexample
SECTIONS @{@ .text : @{@ *(.text) ; LONG(1) @}@ .data : @{@ *(.data) @}@ @}@
@end smallexample
-
+@page
@cindex output section strings
@kindex ASCII (@var{expression}) ``@var{string}''
@kindex ASCIZ ``@var{string}''
+@code{ASCII strings}
+@sp 1
+@multitable @columnfractions .25 .20 .30 .20 .05
+@item
+ASCIZ
+@tab
+@tab
+"<string"
+@tab
+@item
+ASCII
+@tab
+(<size>)
+@tab
+"<string"
+@tab
+@end multitable
+@sp 1
You can include a zero-terminated string in an output section by using
@code{ASCIZ}. The keyword is followed by a string which is stored at
the current value of the location counter including adding a zero byte
@@ -5381,18 +5399,506 @@ it must be enclosed in double quotes.
The string can have C escape characters like '\n', '\r', '\t' and
octal numbers. The '\"' escape is not supported. Nor are escaped hex
values.
-
+@sp 2
Example 1: This is string of 16 characters and will create a 32 byte
area:
@smallexample
ASCII (32) "This is 16 bytes"
@end smallexample
-
+@sp 2
Example 2: This is a string of 16 characters and will create a 17 byte
area:
@smallexample
ASCIZ "This is 16 bytes"
@end smallexample
+@page
+@cindex output section strings
+@kindex DIGEST "<label>[.BE]" "CRC64-ECMA" (@var{expr}, @var{expr})
+@kindex DIGEST "<label>[.BE]" "CRC64-ISO" (@var{expr}, @var{expr})
+@kindex DIGEST "<label>[.BE]" "CRC64-ISO-R" (@var{expr}, @var{expr})
+@kindex DIGEST "<label>[.BE]" "CRC64-WE" (@var{expr}, @var{expr})
+@kindex DIGEST "<label>[.BE]" "CRC64-XZ" (@var{expr}, @var{expr})
+@kindex DIGEST "<label>[.BE]" "CRC32" (@var{expr}, @var{expr})
+@kindex DIGEST "<label>[.BE]" POLY (@var{<parms>}) (@var{expr}, @var{expr})
+
+@code{CRC Calculation}
+@sp 1
+@multitable @columnfractions .25 .20 .30 .20 .05
+@item
+DIGEST
+@tab
+"<label>[.BE]"
+@tab
+"CRC32"
+@tab
+(start, end)
+@item
+DIGEST
+@tab
+"<label>[.BE]"
+@tab
+"CRC64-ECMA"
+@tab
+(start, end)
+@item
+DIGEST
+@tab
+"<label>[.BE]"
+@tab
+"CRC64-GO-ISO"
+@tab
+(start, end)
+@item
+DIGEST
+@tab
+"<label>[.BE]"
+@tab
+"CRC64-GO-ISO-R"
+@tab
+(start, end)
+@item
+DIGEST
+@tab
+"<label>[.BE]"
+@tab
+"CRC64-WE"
+@tab
+(start, end)
+@item
+DIGEST
+@tab
+"<label>[.BE]"
+@tab
+"CRC64-XZ"
+@tab
+(start, end)
+@item
+DIGEST
+@tab
+"<label>[.BE]"
+@tab
+POLY (<params>)
+@tab
+(start, end)
+@item
+DIGEST TABLE
+@tab
+"<label>[.BE]"
+@tab
+@tab
+(start, end)
+@item
+DIGEST SECTION
+@tab
+"<section>"
+@tab
+@tab
+@end multitable
+
+You can calculate the CRC of a part of an output section through the
+@code{DIGEST} command. The default section is the @code{".text"} section.
+The commands take parameters for a label, a @code{polynome} and then two more,
+specifying range of the checked area. The end address is the first address
+past the checked area.
+
+The checksum is generated in little endian format, but this
+can be overridden by adding a @code{.BE} modifier to the label string.
+The generated label does not include the modifier.
+@sp 1
+There is one predefined 32-bit polynome
+
+@multitable @columnfractions .3 .4 .4
+@item
+* @code{CRC32}
+@tab
+@code{0x04C11DB7}
+@tab
+@end multitable
+
+There are five predefined 64-bit polynomes
+
+@multitable @columnfractions .3 .4 .4
+@item
+* @code{CRC64-ECMA}
+@tab
+@code{0x42F0E1EBA9EA3693}
+@tab
+@item
+* @code{CRC64-ISO}
+@tab
+@code{0x000000000000001B}
+@tab
+@item
+* @code{CRC64-ISO-R}
+@tab
+@code{0xD800000000000000}
+@tab
+@item
+* @code{CRC64-WE}
+@tab
+@code{0x42F0E1EBA9EA3693}
+@tab
+@item
+* @code{CRC64-XZ}
+@tab
+@code{0x42F0E1EBA9EA3693}
+@tab
+@end multitable
+@sp 1
+You can also select your own @code{polynome} using the @code{DIGEST POLY}.
+
+It takes the following @code{parameters} separated by commas.
+
+@multitable @columnfractions .3 .7
+@item
+@code{size}
+@tab
+size of CRC (32 or 64)
+@item
+@code{polynome}
+@tab
+@item
+@code{initial}
+@tab
+initial value of crc before calculation
+@item
+@code{xor}
+@tab
+xor result before return
+@item
+@code{input reflect}
+@tab
+bitreverse input data
+@item
+@code{output reflect}
+@tab
+bitreverse result (before xor'ing)
+@item
+@code{reciprocal}
+@tab
+bitreverse polynome before generating table
+@end multitable
+
+The parameters are explained in detail in
+
+@code{http://www.sunshine2k.de/articles/coding/crc/understanding_crc.html}
+
+Some of the predefined polynomes are the same, but differs in the other
+parameters.
+@page
+The 32-bit <polynome> command defines the following global symbols.
+
+@multitable @columnfractions .3 .7
+@item
+@code{___CRC32___}
+@tab
+address of the CRC32 checksum
+@item
+@code{___CRC32_START___}
+@tab
+first address in the checked area.
+@item
+@code{___CRC32_END___}
+@tab
+first address past the checked area.
+@end multitable
+@sp 2
+The 64-bit <polynome> command defines the following global symbols.
+
+@multitable @columnfractions .3 .7
+@item
+@code{___CRC64___}
+@tab
+address of the CRC64 checksum
+@item
+@code{___CRC64_START___}
+@tab
+first address in the checked area.
+@item
+@code{___CRC64_END___}
+@tab
+first address past the checked area.
+@end multitable
+@sp 2
+Note: The generated CRC value must be stored outside the checked area.
+@sp 2
+Example 1: This request a CRC check using the @code{ECMA} algorithm
+
+@smallexample
+ DIGEST "C64" "CRC64-ECMA" (START_CHECK,END_TEXT)
+@end smallexample
+
+The user can retrieve the CRC value through the @code{C64} label.
+@sp 2
+Example 2: This request a CRC check using the @code{ISO} algorithm
+
+ The checksum is stored as big endian
+
+@smallexample
+ DIGEST "C64I.BE" "CRC64-ISO" (START_CHECK,END_TEXT)
+@end smallexample
+
+The user can retrieve the big endian CRC value through the @code{C64I} label.
+@sp 2
+Example 3: This request a CRC check using a user defined @code{polynome}
+
+ The setup is the "CRC32" algorithm
+
+@smallexample
+ DIGEST "CRC" POLY (32, 0x04C11DB7,~0,~0,1,1,0) (START_CHECK,END_TEXT)
+@end smallexample
+
+The user can retrieve the CRC value through the @code{CRC} label.
+@sp 2
+Example 4: This request a CRC check using the @code{CRC32} polynome
+
+@smallexample
+ DIGEST "C32.SE" (START_CHECK,END_TEXT)
+@end smallexample
+
+The user can retrieve the CRC value through the @code{C32} label.
+
+@page
+@cindex output section strings
+@kindex DIGEST TABLE "<label>[.BE]"
+@page
+The @code{DIGEST TABLE} command creates a 1 or 2 kByte table for a table-driven
+CRC calculation. This speeds up the CRC calculation over a non-table-driver
+version since you can handle 8 bits at a time, instead of 1 bit.
+
+The table generated is for the @code{polynome} selected using a
+@code{DIGEST <polynome>} command.
+
+The command will define the label supplied as a parameter.
+The table will be in small endian, unless the @code{.BE} extension is given
+to the label. It also defines a symbol based on the size of the polynome.
+
+@enumerate
+@item
+@code{___CRC32_TABLE___} address of the CRC32 table, or
+@item
+@code{___CRC64_TABLE___} address of the CRC64 table
+@end enumerate
+
+@sp 2
+Example 1: Generate a 1 kB table
+
+(assuming a previous @code{DIGEST "CRC32"} command)
+
+@smallexample
+ DIGEST TABLE "crc_tab32"
+@end smallexample
+
+The user must declare @code{extern uint32_t *crc_tab32;} in his code.
+@sp 2
+Example 2: Generate a 2 kB table in big endian format.
+
+(assuming a previous @code{DIGEST "CRC64-###"} command)
+
+@smallexample
+ DIGEST TABLE "crc_tab64.be"
+@end smallexample
+
+The user must declare @code{extern uint64_t *crc_tab64;} in his code.
+@sp 2
+The default section is the @code{".text"} section but the user can
+specify another section using the @code{DIGEST SECTION <section>} command.
+@sp 1
+Example 1: Calculate the CRC in a @code{".aux"} section.
+
+@smallexample
+ DIGEST SECTION ".aux"
+@end smallexample
+@sp 1
+The @code{DIGEST <polynome>} and @code{DIGEST TABLE} commands must be in
+the @code{".aux"} section.
+@page
+
+Using the tables:
+ The user must include CRC code in the application to test the CRC
+@sp 2
+
+@multitable @columnfractions .15 .85
+@item
+Example 1:
+@tab
+Calculating CRC-64
+@end multitable
+@sp 1
+@multitable @columnfractions .05 .95
+@item
+@tab
+Copyright (c) 2016 Lammert Bies
+@item
+@tab
+Copyright (c) 2021 Bastian Molkenthin
+@item
+@tab
+Copyright (c) 2023 Ulf Samuelsson
+@end multitable
+@sp 2
+@smallexample
+#define SHIFT(t) ((sizeof(t)-1)*8)
+uint64_t calc_crc64
+ (algorithm_desc_t * dsc, const unsigned char *input_str, size_t num_bytes)
+@{
+ uint64_t crc;
+ const unsigned char *ptr;
+ uint64_t *crc_tab = dsc->crc_tab;
+ uint64_t index;
+
+ if ((ptr = input_str) == NULL)
+ return 0;
+
+ if (crc_tab == NULL)
+ return 0;
+
+
+ crc = dsc->initial;
+ if (dsc->reciprocal)
+ @{
+ for (uint32_t i = 0; i < num_bytes; i++)
+ @{
+ index = ((crc >> 0) ^ (uint64_t) * ptr++) & 0x00000000000000FFull;
+ crc = (crc >> 8) ^ crc_tab[index];
+ @}
+ @}
+ else
+ @{
+ uint32_t shift = SHIFT (uint64_t);
+ for (uint32_t i = 0; i < num_bytes; i++)
+ @{
+ const unsigned char c = *ptr++;
+ uint64_t rc = (uint64_t) (dsc->ireflect ? reflect8 (c) : c);
+ crc = (crc ^ (rc << shift));
+ index = (uint32_t) (crc >> shift);
+ crc = (crc << 8);
+ crc = (crc ^ (crc_tab[index]));
+ @}
+ @}
+ crc = (dsc->oreflect ? reflect64 (crc) : crc);
+ crc = crc ^ dsc->xor_val;
+ return crc;
+@} /* calc_crc64 */
+@end smallexample
+@page
+@multitable @columnfractions .15 .85
+@item
+Example 2:
+@tab
+Calculating CRC-32
+@end multitable
+@sp 1
+@multitable @columnfractions .05 .95
+@item
+@tab
+Copyright (c) 2016 Lammert Bies
+@item
+@tab
+Copyright (c) 2021 Bastian Molkenthin
+@item
+@tab
+Copyright (c) 2023 Ulf Samuelsson
+@end multitable
+@sp 2
+@smallexample
+#define SHIFT(t) ((sizeof(t)-1)*8)
+uint32_t
+calc_crc32 (algorithm_desc_t * dsc, const unsigned char *input_str,
+ size_t num_bytes)
+@{
+ uint32_t crc;
+ const unsigned char *ptr;
+ uint32_t index;
+ uint32_t *crc_tab = dsc->crc_tab;
+
+ if ((ptr = input_str) == NULL)
+ return 0;
+
+ if (crc_tab == NULL)
+ return 0;
+
+ crc = dsc->initial;
+
+ if (dsc->reciprocal)
+ @{
+ for (uint32_t i = 0; i < num_bytes; i++)
+ @{
+ index = ((crc >> 0) ^ (uint32_t) * ptr++) & 0x000000FFul;
+ crc = (crc >> 8) ^ crc_tab[index];
+ @}
+ @}
+ else
+ @{
+ uint32_t shift = SHIFT (uint32_t);
+ for (uint32_t i = 0; i < num_bytes; i++)
+ @{
+ const unsigned char c = *ptr++;
+ uint32_t rc = (uint32_t) (dsc->ireflect ? reflect8 (c) : c);
+ crc = (crc ^ (rc << shift));
+ index = (uint32_t) (crc >> shift);
+ crc = (crc << 8);
+ crc = (crc ^ (crc_tab[index]));
+ @}
+ @}
+ crc = (dsc->oreflect ? reflect32 (crc) : crc);
+ crc = crc ^ dsc->xor_val;
+ return crc;
+@} /* calc_crc32 */
+@end smallexample
+@page
+@multitable @columnfractions .15 .85
+@item
+Example 3:
+@tab
+Calculating CRC-32 using optimized routine
+@end multitable
+@sp 1
+@multitable @columnfractions .05 .95
+@item
+@tab
+Copyright (c) 2016 Lammert Bies
+@item
+@tab
+Copyright (c) 2021 Bastian Molkenthin
+@item
+@tab
+Copyright (c) 2023 Ulf Samuelsson
+@end multitable
+@sp 2
+@smallexample
+#define SHIFT(t) ((sizeof(t)-1)*8)
+extern uint32_t *crc_tab;
+
+uint32_t
+calc_crc32 (const unsigned char *input_str, size_t num_bytes)
+@{
+ uint32_t crc;
+ const unsigned char *ptr;
+ uint32_t index;
+ uint32_t shift = SHIFT (uint32_t);
+
+ if ((ptr = input_str) == NULL)
+ return 0;
+
+ crc = 0xFFFFFFFF;
+ for (uint32_t i = 0; i < num_bytes; i++)
+ @{
+ const unsigned char c = *ptr++;
+ crc = (crc ^ (c << shift));
+ index = (uint32_t) (crc >> shift);
+ crc = (crc << 8);
+ crc = (crc ^ (crc_tab[index]));
+ @}
+ return crc ^ 0xFFFFFFFF;
+@} /* calc_crc32 */
+@end smallexample
+@page
+@cindex output section strings
+@kindex TIMESTAMP
+
+The @code{TIMESTAMP} command creates 64-bit integer with the number of seconds
+since Epoch (1970-01-01 00:00).
@kindex FILL(@var{expression})
@cindex holes, filling
--
2.34.1
^ permalink raw reply [flat|nested] 8+ messages in thread
* [PATCH v7 04/11] DIGEST: testsuite
2023-03-01 15:45 [PATCH v7 0/11 Add support for CRC64 generation in linker binutils
` (2 preceding siblings ...)
2023-03-01 15:45 ` [PATCH v7 03/11] DIGEST: Documentation binutils
@ 2023-03-01 15:45 ` binutils
2023-03-01 15:45 ` [PATCH v7 05/11] DIGEST: ldlex.l binutils
` (2 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: binutils @ 2023-03-01 15:45 UTC (permalink / raw)
To: binutils; +Cc: nickc, Ulf Samuelsson
From: Ulf Samuelsson <ulf@emagii.com>
Signed-off-by: Ulf Samuelsson <ulf@emagii.com>
---
ld/testsuite/ld-scripts/begin_tag.inc | 9 +++++
ld/testsuite/ld-scripts/crc32-poly.d | 24 +++++++++++
ld/testsuite/ld-scripts/crc32-poly.s | 21 ++++++++++
ld/testsuite/ld-scripts/crc32-poly.t | 42 ++++++++++++++++++++
ld/testsuite/ld-scripts/crc32.d | 24 +++++++++++
ld/testsuite/ld-scripts/crc32.s | 21 ++++++++++
ld/testsuite/ld-scripts/crc32.t | 41 +++++++++++++++++++
ld/testsuite/ld-scripts/crc64-ecma.d | 24 +++++++++++
ld/testsuite/ld-scripts/crc64-ecma.s | 21 ++++++++++
ld/testsuite/ld-scripts/crc64-ecma.t | 44 +++++++++++++++++++++
ld/testsuite/ld-scripts/crc64-iso.d | 24 +++++++++++
ld/testsuite/ld-scripts/crc64-iso.s | 21 ++++++++++
ld/testsuite/ld-scripts/crc64-iso.t | 43 ++++++++++++++++++++
ld/testsuite/ld-scripts/crc64-iso_be.d | 24 +++++++++++
ld/testsuite/ld-scripts/crc64-iso_be.s | 21 ++++++++++
ld/testsuite/ld-scripts/crc64-iso_be.t | 43 ++++++++++++++++++++
ld/testsuite/ld-scripts/crc64-poly.d | 24 +++++++++++
ld/testsuite/ld-scripts/crc64-poly.s | 21 ++++++++++
ld/testsuite/ld-scripts/crc64-poly.t | 43 ++++++++++++++++++++
ld/testsuite/ld-scripts/crc_data.inc | 9 +++++
ld/testsuite/ld-scripts/digest_table.inc | 6 +++
ld/testsuite/ld-scripts/digest_table_be.inc | 6 +++
ld/testsuite/ld-scripts/end_tag.inc | 9 +++++
ld/testsuite/ld-scripts/script.exp | 7 ++++
24 files changed, 572 insertions(+)
create mode 100644 ld/testsuite/ld-scripts/begin_tag.inc
create mode 100644 ld/testsuite/ld-scripts/crc32-poly.d
create mode 100644 ld/testsuite/ld-scripts/crc32-poly.s
create mode 100644 ld/testsuite/ld-scripts/crc32-poly.t
create mode 100644 ld/testsuite/ld-scripts/crc32.d
create mode 100644 ld/testsuite/ld-scripts/crc32.s
create mode 100644 ld/testsuite/ld-scripts/crc32.t
create mode 100644 ld/testsuite/ld-scripts/crc64-ecma.d
create mode 100644 ld/testsuite/ld-scripts/crc64-ecma.s
create mode 100644 ld/testsuite/ld-scripts/crc64-ecma.t
create mode 100644 ld/testsuite/ld-scripts/crc64-iso.d
create mode 100644 ld/testsuite/ld-scripts/crc64-iso.s
create mode 100644 ld/testsuite/ld-scripts/crc64-iso.t
create mode 100644 ld/testsuite/ld-scripts/crc64-iso_be.d
create mode 100644 ld/testsuite/ld-scripts/crc64-iso_be.s
create mode 100644 ld/testsuite/ld-scripts/crc64-iso_be.t
create mode 100644 ld/testsuite/ld-scripts/crc64-poly.d
create mode 100644 ld/testsuite/ld-scripts/crc64-poly.s
create mode 100644 ld/testsuite/ld-scripts/crc64-poly.t
create mode 100644 ld/testsuite/ld-scripts/crc_data.inc
create mode 100644 ld/testsuite/ld-scripts/digest_table.inc
create mode 100644 ld/testsuite/ld-scripts/digest_table_be.inc
create mode 100644 ld/testsuite/ld-scripts/end_tag.inc
diff --git a/ld/testsuite/ld-scripts/begin_tag.inc b/ld/testsuite/ld-scripts/begin_tag.inc
new file mode 100644
index 00000000000..ef395bbe717
--- /dev/null
+++ b/ld/testsuite/ld-scripts/begin_tag.inc
@@ -0,0 +1,9 @@
+ BYTE(0x43);
+ BYTE(0x4F);
+ BYTE(0x44);
+ BYTE(0x45);
+ BYTE(0xDE);
+ BYTE(0xAD);
+ BYTE(0xBE);
+ BYTE(0xEF);
+ QUAD(0);
diff --git a/ld/testsuite/ld-scripts/crc32-poly.d b/ld/testsuite/ld-scripts/crc32-poly.d
new file mode 100644
index 00000000000..028ef14460f
--- /dev/null
+++ b/ld/testsuite/ld-scripts/crc32-poly.d
@@ -0,0 +1,24 @@
+#source: crc32-poly.s
+#ld: -T crc32-poly.t
+#objdump: -s -j .text
+#target: [is_elf_format] [is_coff_format]
+#notarget: [is_aout_format]
+#xfail: tic4x-*-* tic54x-*-*
+
+.*: file format .*
+
+Contents of section .text:
+ 1200 434f4445 deadbeef 00000000 00000000 CODE............
+ 1210 cbf43926 00000000 00000000 00000000 ..9&............
+ 1220 cbf43926 00000000 00000000 00000000 ..9&............
+ 1230 00000000 00000000 deadbeef 434f4445 ............CODE
+ 1240 31323334 35363738 3900ffff ffffffff 123456789.......
+ 1250 434f4445 00000000 00000000 00000000 CODE............
+ 1260 ffffffff ffffffff ffffffff ffffffff .*
+#...
+ 17e0 434f4445 deadbeef 00000000 00000000 CODE............
+ 17f0 44494745 53542054 41424c45 00000000 DIGEST TABLE....
+#...
+ 1c00 454e4420 5441424c 45000000 00000000 END TABLE.......
+ 1c10 00000000 00000000 deadbeef 434f4445 ............CODE
+#pass
diff --git a/ld/testsuite/ld-scripts/crc32-poly.s b/ld/testsuite/ld-scripts/crc32-poly.s
new file mode 100644
index 00000000000..e4ffb15af62
--- /dev/null
+++ b/ld/testsuite/ld-scripts/crc32-poly.s
@@ -0,0 +1,21 @@
+ .extern ecc_start
+ .section .text
+main:
+ .byte 0x43
+ .byte 0x4F
+ .byte 0x44
+ .byte 0x45
+ .long 0
+ .long 0
+ .long 0
+ .section .data
+ .byte 0xde
+ .byte 0xad
+ .byte 0xde
+ .byte 0xad
+ .byte 0xde
+ .byte 0xad
+ .byte 0xbe
+ .byte 0xef
+ .section .bss
+ .long 0
diff --git a/ld/testsuite/ld-scripts/crc32-poly.t b/ld/testsuite/ld-scripts/crc32-poly.t
new file mode 100644
index 00000000000..15acfa54500
--- /dev/null
+++ b/ld/testsuite/ld-scripts/crc32-poly.t
@@ -0,0 +1,42 @@
+MEMORY {
+ rom : ORIGIN = 0x000000, LENGTH = 0x400000
+ ram : ORIGIN = 0x400000, LENGTH = 0x10000
+}
+
+_start = 0x000000;
+SECTIONS
+{
+ . = 0x1000 + SIZEOF_HEADERS;
+ .text ALIGN (0x200) :
+
+ {
+ FILL(0xFF)
+ header = .;
+ INCLUDE "begin_tag.inc"
+
+ expected = .;
+ BYTE(0xCB);
+ BYTE(0xF4);
+ BYTE(0x39);
+ BYTE(0x26);
+ LONG(0x0);
+ QUAD(0x0);
+
+
+ crc32 = .;
+ DIGEST "_CRC32.BE" POLY(32, 0x04C11DB7, 0xFFFFFFFF,0xFFFFFFFF,1,1,0 )(ecc_start , ecc_end)
+ LONG(0);
+ QUAD(0);
+
+ INCLUDE "end_tag.inc"
+
+ INCLUDE "crc_data.inc"
+
+ INCLUDE "digest_table.inc"
+ } > rom
+
+ .data : AT (0x400000) { *(.data) } >ram /* NO default AT>rom */
+ . = ALIGN(0x20);
+ .bss : { *(.bss) } >ram /* NO default AT>rom */
+ /DISCARD/ : { *(*) }
+}
diff --git a/ld/testsuite/ld-scripts/crc32.d b/ld/testsuite/ld-scripts/crc32.d
new file mode 100644
index 00000000000..c154fb579f4
--- /dev/null
+++ b/ld/testsuite/ld-scripts/crc32.d
@@ -0,0 +1,24 @@
+#source: crc32.s
+#ld: -T crc32.t
+#objdump: -s -j .text
+#target: [is_elf_format] [is_coff_format]
+#notarget: [is_aout_format]
+#xfail: tic4x-*-* tic54x-*-*
+
+.*: file format .*
+
+Contents of section .text:
+ 1200 434f4445 deadbeef 00000000 00000000 CODE............
+ 1210 cbf43926 00000000 00000000 00000000 ..9&............
+ 1220 cbf43926 00000000 00000000 00000000 ..9&............
+ 1230 00000000 00000000 deadbeef 434f4445 ............CODE
+ 1240 31323334 35363738 3900ffff ffffffff 123456789.......
+ 1250 434f4445 00000000 00000000 00000000 CODE............
+ 1260 ffffffff ffffffff ffffffff ffffffff .*
+#...
+ 17e0 434f4445 deadbeef 00000000 00000000 CODE............
+ 17f0 44494745 53542054 41424c45 00000000 DIGEST TABLE....
+#...
+ 1c00 454e4420 5441424c 45000000 00000000 END TABLE.......
+ 1c10 00000000 00000000 deadbeef 434f4445 ............CODE
+#pass
diff --git a/ld/testsuite/ld-scripts/crc32.s b/ld/testsuite/ld-scripts/crc32.s
new file mode 100644
index 00000000000..e4ffb15af62
--- /dev/null
+++ b/ld/testsuite/ld-scripts/crc32.s
@@ -0,0 +1,21 @@
+ .extern ecc_start
+ .section .text
+main:
+ .byte 0x43
+ .byte 0x4F
+ .byte 0x44
+ .byte 0x45
+ .long 0
+ .long 0
+ .long 0
+ .section .data
+ .byte 0xde
+ .byte 0xad
+ .byte 0xde
+ .byte 0xad
+ .byte 0xde
+ .byte 0xad
+ .byte 0xbe
+ .byte 0xef
+ .section .bss
+ .long 0
diff --git a/ld/testsuite/ld-scripts/crc32.t b/ld/testsuite/ld-scripts/crc32.t
new file mode 100644
index 00000000000..4cfe74493b2
--- /dev/null
+++ b/ld/testsuite/ld-scripts/crc32.t
@@ -0,0 +1,41 @@
+MEMORY {
+ rom : ORIGIN = 0x000000, LENGTH = 0x400000
+ ram : ORIGIN = 0x400000, LENGTH = 0x10000
+}
+
+_start = 0x000000;
+SECTIONS
+{
+ . = 0x1000 + SIZEOF_HEADERS;
+ .text ALIGN (0x200) :
+
+ {
+ FILL(0xFF)
+ header = .;
+ INCLUDE "begin_tag.inc"
+
+ expected = .;
+ BYTE(0xCB);
+ BYTE(0xF4);
+ BYTE(0x39);
+ BYTE(0x26);
+ LONG(0x0);
+ QUAD(0x0);
+
+ crc32 = .;
+ DIGEST "_CRC32.BE" "CRC32" (ecc_start , ecc_end);
+ LONG(0);
+ QUAD(0);
+
+ INCLUDE "end_tag.inc"
+
+ INCLUDE "crc_data.inc"
+
+ INCLUDE "digest_table.inc"
+ } > rom
+
+ .data : AT (0x400000) { *(.data) } >ram /* NO default AT>rom */
+ . = ALIGN(0x20);
+ .bss : { *(.bss) } >ram /* NO default AT>rom */
+ /DISCARD/ : { *(*) }
+}
diff --git a/ld/testsuite/ld-scripts/crc64-ecma.d b/ld/testsuite/ld-scripts/crc64-ecma.d
new file mode 100644
index 00000000000..d30d6a7cd7e
--- /dev/null
+++ b/ld/testsuite/ld-scripts/crc64-ecma.d
@@ -0,0 +1,24 @@
+#source: crc64-ecma.s
+#ld: -T crc64-ecma.t
+#objdump: -s -j .text
+#target: [is_elf_format] [is_coff_format]
+#notarget: [is_aout_format]
+#xfail: tic4x-*-* tic54x-*-*
+
+.*: file format .*
+
+Contents of section .text:
+ 1200 434f4445 deadbeef 00000000 00000000 CODE............
+ 1210 6c40df5f 0b497347 00000000 00000000 l@._.IsG........
+ 1220 6c40df5f 0b497347 00000000 00000000 l@._.IsG........
+ 1230 00000000 00000000 deadbeef 434f4445 ............CODE
+ 1240 31323334 35363738 3900ffff ffffffff 123456789.......
+ 1250 434f4445 00000000 00000000 00000000 CODE............
+ 1260 ffffffff ffffffff ffffffff ffffffff .*
+#...
+ 17e0 434f4445 deadbeef 00000000 00000000 CODE............
+ 17f0 44494745 53542054 41424c45 00000000 DIGEST TABLE....
+#...
+ 2000 454e4420 5441424c 45000000 00000000 END TABLE.......
+ 2010 00000000 00000000 deadbeef 434f4445 ............CODE
+#pass
diff --git a/ld/testsuite/ld-scripts/crc64-ecma.s b/ld/testsuite/ld-scripts/crc64-ecma.s
new file mode 100644
index 00000000000..e4ffb15af62
--- /dev/null
+++ b/ld/testsuite/ld-scripts/crc64-ecma.s
@@ -0,0 +1,21 @@
+ .extern ecc_start
+ .section .text
+main:
+ .byte 0x43
+ .byte 0x4F
+ .byte 0x44
+ .byte 0x45
+ .long 0
+ .long 0
+ .long 0
+ .section .data
+ .byte 0xde
+ .byte 0xad
+ .byte 0xde
+ .byte 0xad
+ .byte 0xde
+ .byte 0xad
+ .byte 0xbe
+ .byte 0xef
+ .section .bss
+ .long 0
diff --git a/ld/testsuite/ld-scripts/crc64-ecma.t b/ld/testsuite/ld-scripts/crc64-ecma.t
new file mode 100644
index 00000000000..5d63e2000ba
--- /dev/null
+++ b/ld/testsuite/ld-scripts/crc64-ecma.t
@@ -0,0 +1,44 @@
+MEMORY {
+ rom : ORIGIN = 0x000000, LENGTH = 0x400000
+ ram : ORIGIN = 0x400000, LENGTH = 0x10000
+}
+
+_start = 0x000000;
+SECTIONS
+{
+ . = 0x1000 + SIZEOF_HEADERS;
+ .text ALIGN (0x200) :
+
+ {
+ FILL(0xFF)
+ header = .;
+ INCLUDE "begin_tag.inc"
+
+ expected = .;
+ BYTE(0x6C);
+ BYTE(0x40);
+ BYTE(0xDF);
+ BYTE(0x5F);
+ BYTE(0x0B);
+ BYTE(0x49);
+ BYTE(0x73);
+ BYTE(0x47);
+
+ QUAD(0x0);
+
+ crc64 = .;
+ DIGEST "_CRC64.BE" "CRC64-ECMA" (ecc_start , ecc_end);
+ QUAD(0x0);
+
+ INCLUDE "end_tag.inc"
+
+ INCLUDE "crc_data.inc"
+
+ INCLUDE "digest_table.inc"
+ } > rom
+
+ .data : AT (0x400000) { *(.data) } >ram /* NO default AT>rom */
+ . = ALIGN(0x20);
+ .bss : { *(.bss) } >ram /* NO default AT>rom */
+ /DISCARD/ : { *(*) }
+}
diff --git a/ld/testsuite/ld-scripts/crc64-iso.d b/ld/testsuite/ld-scripts/crc64-iso.d
new file mode 100644
index 00000000000..12b9d319a61
--- /dev/null
+++ b/ld/testsuite/ld-scripts/crc64-iso.d
@@ -0,0 +1,24 @@
+#source: crc64-iso.s
+#ld: -T crc64-iso.t
+#objdump: -s -j .text
+#target: [is_elf_format] [is_coff_format]
+#notarget: [is_aout_format]
+#xfail: tic4x-*-* tic54x-*-*
+
+.*: file format .*
+
+Contents of section .text:
+ 1200 434f4445 deadbeef 00000000 00000000 CODE............
+ 1210 b90956c7 75a41001 00000000 00000000 ..V.u...........
+ 1220 b90956c7 75a41001 00000000 00000000 ..V.u...........
+ 1230 00000000 00000000 deadbeef 434f4445 ............CODE
+ 1240 31323334 35363738 3900ffff ffffffff 123456789.......
+ 1250 434f4445 00000000 00000000 00000000 CODE............
+ 1260 ffffffff ffffffff ffffffff ffffffff .*
+#...
+ 17e0 434f4445 deadbeef 00000000 00000000 CODE............
+ 17f0 44494745 53542054 41424c45 00000000 DIGEST TABLE....
+#...
+ 2000 454e4420 5441424c 45000000 00000000 END TABLE.......
+ 2010 00000000 00000000 deadbeef 434f4445 ............CODE
+#pass
diff --git a/ld/testsuite/ld-scripts/crc64-iso.s b/ld/testsuite/ld-scripts/crc64-iso.s
new file mode 100644
index 00000000000..e4ffb15af62
--- /dev/null
+++ b/ld/testsuite/ld-scripts/crc64-iso.s
@@ -0,0 +1,21 @@
+ .extern ecc_start
+ .section .text
+main:
+ .byte 0x43
+ .byte 0x4F
+ .byte 0x44
+ .byte 0x45
+ .long 0
+ .long 0
+ .long 0
+ .section .data
+ .byte 0xde
+ .byte 0xad
+ .byte 0xde
+ .byte 0xad
+ .byte 0xde
+ .byte 0xad
+ .byte 0xbe
+ .byte 0xef
+ .section .bss
+ .long 0
diff --git a/ld/testsuite/ld-scripts/crc64-iso.t b/ld/testsuite/ld-scripts/crc64-iso.t
new file mode 100644
index 00000000000..18f0a2ce34b
--- /dev/null
+++ b/ld/testsuite/ld-scripts/crc64-iso.t
@@ -0,0 +1,43 @@
+MEMORY {
+ rom : ORIGIN = 0x000000, LENGTH = 0x400000
+ ram : ORIGIN = 0x400000, LENGTH = 0x10000
+}
+
+_start = 0x000000;
+SECTIONS
+{
+ . = 0x1000 + SIZEOF_HEADERS;
+ .text ALIGN (0x200) :
+
+ {
+ FILL(0xFF)
+ header = .;
+ INCLUDE "begin_tag.inc"
+
+ expected = .;
+ BYTE(0xb9);
+ BYTE(0x09);
+ BYTE(0x56);
+ BYTE(0xc7);
+ BYTE(0x75);
+ BYTE(0xa4);
+ BYTE(0x10);
+ BYTE(0x01);
+ QUAD(0x0);
+
+ crc64 = .;
+ DIGEST "_CRC64.BE" "CRC64-GO-ISO" (ecc_start , ecc_end)
+ QUAD(0x0);
+
+ INCLUDE "end_tag.inc"
+
+ INCLUDE "crc_data.inc"
+
+ INCLUDE "digest_table.inc"
+ } > rom
+
+ .data : AT (0x400000) { *(.data) } >ram /* NO default AT>rom */
+ . = ALIGN(0x20);
+ .bss : { *(.bss) } >ram /* NO default AT>rom */
+ /DISCARD/ : { *(*) }
+}
diff --git a/ld/testsuite/ld-scripts/crc64-iso_be.d b/ld/testsuite/ld-scripts/crc64-iso_be.d
new file mode 100644
index 00000000000..131116d4305
--- /dev/null
+++ b/ld/testsuite/ld-scripts/crc64-iso_be.d
@@ -0,0 +1,24 @@
+#source: crc64-iso_be.s
+#ld: -T crc64-iso_be.t
+#objdump: -s -j .text
+#target: [is_elf_format] [is_coff_format]
+#notarget: [is_aout_format]
+#xfail: tic4x-*-* tic54x-*-*
+
+.*: file format .*
+
+Contents of section .text:
+ 1200 434f4445 deadbeef 00000000 00000000 CODE............
+ 1210 0110a475 c75609b9 00000000 00000000 ...u.V..........
+ 1220 0110a475 c75609b9 00000000 00000000 ...u.V..........
+ 1230 00000000 00000000 deadbeef 434f4445 ............CODE
+ 1240 31323334 35363738 3900ffff ffffffff 123456789.......
+ 1250 434f4445 00000000 00000000 00000000 CODE............
+ 1260 ffffffff ffffffff ffffffff ffffffff .*
+#...
+ 17e0 434f4445 deadbeef 00000000 00000000 CODE............
+ 17f0 44494745 53542054 41424c45 00000000 DIGEST TABLE....
+#...
+ 2000 454e4420 5441424c 45000000 00000000 END TABLE.......
+ 2010 00000000 00000000 deadbeef 434f4445 ............CODE
+#pass
diff --git a/ld/testsuite/ld-scripts/crc64-iso_be.s b/ld/testsuite/ld-scripts/crc64-iso_be.s
new file mode 100644
index 00000000000..e4ffb15af62
--- /dev/null
+++ b/ld/testsuite/ld-scripts/crc64-iso_be.s
@@ -0,0 +1,21 @@
+ .extern ecc_start
+ .section .text
+main:
+ .byte 0x43
+ .byte 0x4F
+ .byte 0x44
+ .byte 0x45
+ .long 0
+ .long 0
+ .long 0
+ .section .data
+ .byte 0xde
+ .byte 0xad
+ .byte 0xde
+ .byte 0xad
+ .byte 0xde
+ .byte 0xad
+ .byte 0xbe
+ .byte 0xef
+ .section .bss
+ .long 0
diff --git a/ld/testsuite/ld-scripts/crc64-iso_be.t b/ld/testsuite/ld-scripts/crc64-iso_be.t
new file mode 100644
index 00000000000..5893b0f6948
--- /dev/null
+++ b/ld/testsuite/ld-scripts/crc64-iso_be.t
@@ -0,0 +1,43 @@
+MEMORY {
+ rom : ORIGIN = 0x000000, LENGTH = 0x400000
+ ram : ORIGIN = 0x400000, LENGTH = 0x10000
+}
+
+_start = 0x000000;
+SECTIONS
+{
+ . = 0x1000 + SIZEOF_HEADERS;
+ .text ALIGN (0x200) :
+
+ {
+ FILL(0xFF)
+ header = .;
+ INCLUDE "begin_tag.inc"
+
+ expected = .;
+ BYTE(0x01);
+ BYTE(0x10);
+ BYTE(0xa4);
+ BYTE(0x75);
+ BYTE(0xc7);
+ BYTE(0x56);
+ BYTE(0x09);
+ BYTE(0xb9);
+ QUAD(0x0);
+
+ crc64 = .;
+ DIGEST "_CRC64" "CRC64-GO-ISO" (ecc_start , ecc_end)
+ QUAD(0x0);
+
+ INCLUDE "end_tag.inc"
+
+ INCLUDE "crc_data.inc"
+
+ INCLUDE "digest_table_be.inc"
+ } > rom
+
+ .data : AT (0x400000) { *(.data) } >ram /* NO default AT>rom */
+ . = ALIGN(0x20);
+ .bss : { *(.bss) } >ram /* NO default AT>rom */
+ /DISCARD/ : { *(*) }
+}
diff --git a/ld/testsuite/ld-scripts/crc64-poly.d b/ld/testsuite/ld-scripts/crc64-poly.d
new file mode 100644
index 00000000000..d683d8b0058
--- /dev/null
+++ b/ld/testsuite/ld-scripts/crc64-poly.d
@@ -0,0 +1,24 @@
+#source: crc64-poly.s
+#ld: -T crc64-poly.t
+#objdump: -s -j .text
+#target: [is_elf_format] [is_coff_format]
+#notarget: [is_aout_format]
+#xfail: tic4x-*-* tic54x-*-*
+
+.*: file format .*
+
+Contents of section .text:
+ 1200 434f4445 deadbeef 00000000 00000000 CODE............
+ 1210 6c40df5f 0b497347 00000000 00000000 l@._.IsG........
+ 1220 6c40df5f 0b497347 00000000 00000000 l@._.IsG........
+ 1230 00000000 00000000 deadbeef 434f4445 ............CODE
+ 1240 31323334 35363738 3900ffff ffffffff 123456789.......
+ 1250 434f4445 00000000 00000000 00000000 CODE............
+ 1260 ffffffff ffffffff ffffffff ffffffff .*
+#...
+ 17e0 434f4445 deadbeef 00000000 00000000 CODE............
+ 17f0 44494745 53542054 41424c45 00000000 DIGEST TABLE....
+#...
+ 2000 454e4420 5441424c 45000000 00000000 END TABLE.......
+ 2010 00000000 00000000 deadbeef 434f4445 ............CODE
+#pass
diff --git a/ld/testsuite/ld-scripts/crc64-poly.s b/ld/testsuite/ld-scripts/crc64-poly.s
new file mode 100644
index 00000000000..e4ffb15af62
--- /dev/null
+++ b/ld/testsuite/ld-scripts/crc64-poly.s
@@ -0,0 +1,21 @@
+ .extern ecc_start
+ .section .text
+main:
+ .byte 0x43
+ .byte 0x4F
+ .byte 0x44
+ .byte 0x45
+ .long 0
+ .long 0
+ .long 0
+ .section .data
+ .byte 0xde
+ .byte 0xad
+ .byte 0xde
+ .byte 0xad
+ .byte 0xde
+ .byte 0xad
+ .byte 0xbe
+ .byte 0xef
+ .section .bss
+ .long 0
diff --git a/ld/testsuite/ld-scripts/crc64-poly.t b/ld/testsuite/ld-scripts/crc64-poly.t
new file mode 100644
index 00000000000..6519b71c684
--- /dev/null
+++ b/ld/testsuite/ld-scripts/crc64-poly.t
@@ -0,0 +1,43 @@
+MEMORY {
+ rom : ORIGIN = 0x000000, LENGTH = 0x400000
+ ram : ORIGIN = 0x400000, LENGTH = 0x10000
+}
+
+_start = 0x000000;
+SECTIONS
+{
+ . = 0x1000 + SIZEOF_HEADERS;
+ .text ALIGN (0x200) :
+
+ {
+ FILL(0xFF)
+ header = .;
+ INCLUDE "begin_tag.inc"
+
+ expected = .;
+ BYTE(0x6C);
+ BYTE(0x40);
+ BYTE(0xDF);
+ BYTE(0x5F);
+ BYTE(0x0B);
+ BYTE(0x49);
+ BYTE(0x73);
+ BYTE(0x47);
+ QUAD(0x0);
+
+ crc64 = .;
+ DIGEST "_CRC64.BE" POLY(64,0x42F0E1EBA9EA3693,0,0,0,0,0)(ecc_start , ecc_end)
+ QUAD(0x0);
+
+ INCLUDE "end_tag.inc"
+
+ INCLUDE "crc_data.inc"
+
+ INCLUDE "digest_table.inc"
+ } > rom
+
+ .data : AT (0x400000) { *(.data) } >ram /* NO default AT>rom */
+ . = ALIGN(0x20);
+ .bss : { *(.bss) } >ram /* NO default AT>rom */
+ /DISCARD/ : { *(*) }
+}
diff --git a/ld/testsuite/ld-scripts/crc_data.inc b/ld/testsuite/ld-scripts/crc_data.inc
new file mode 100644
index 00000000000..176a4689493
--- /dev/null
+++ b/ld/testsuite/ld-scripts/crc_data.inc
@@ -0,0 +1,9 @@
+ ecc_start = .;
+ ASCIZ "123456789"
+ ecc_end = . - 1;
+ . = ALIGN(0x10);
+
+ entry = .;
+ *(.text)
+ . = ALIGN(0x100);
+ BYTE(1);
diff --git a/ld/testsuite/ld-scripts/digest_table.inc b/ld/testsuite/ld-scripts/digest_table.inc
new file mode 100644
index 00000000000..fb40a4fa024
--- /dev/null
+++ b/ld/testsuite/ld-scripts/digest_table.inc
@@ -0,0 +1,6 @@
+ . = ALIGN(2048) - 32;
+ INCLUDE "begin_tag.inc"
+ ASCII (16) "DIGEST TABLE"
+ DIGEST TABLE "CRCTAB"
+ ASCII (16) "END TABLE"
+ INCLUDE "end_tag.inc"
diff --git a/ld/testsuite/ld-scripts/digest_table_be.inc b/ld/testsuite/ld-scripts/digest_table_be.inc
new file mode 100644
index 00000000000..eec712d9eff
--- /dev/null
+++ b/ld/testsuite/ld-scripts/digest_table_be.inc
@@ -0,0 +1,6 @@
+ . = ALIGN(2048) - 32;
+ INCLUDE "begin_tag.inc"
+ ASCII (16) "DIGEST TABLE"
+ DIGEST TABLE "CRCTAB.BE"
+ ASCII (16) "END TABLE"
+ INCLUDE "end_tag.inc"
diff --git a/ld/testsuite/ld-scripts/end_tag.inc b/ld/testsuite/ld-scripts/end_tag.inc
new file mode 100644
index 00000000000..4c80854b062
--- /dev/null
+++ b/ld/testsuite/ld-scripts/end_tag.inc
@@ -0,0 +1,9 @@
+ QUAD(0);
+ BYTE(0xDE);
+ BYTE(0xAD);
+ BYTE(0xBE);
+ BYTE(0xEF);
+ BYTE(0x43);
+ BYTE(0x4F);
+ BYTE(0x44);
+ BYTE(0x45);
diff --git a/ld/testsuite/ld-scripts/script.exp b/ld/testsuite/ld-scripts/script.exp
index 56e12da8e61..38cb0f9fe66 100644
--- a/ld/testsuite/ld-scripts/script.exp
+++ b/ld/testsuite/ld-scripts/script.exp
@@ -229,6 +229,13 @@ foreach test_script $test_script_list {
run_dump_test "asciz"
run_dump_test "ascii"
+run_dump_test "crc64-ecma"
+run_dump_test "crc64-iso"
+run_dump_test "crc64-iso_be"
+run_dump_test "crc64-poly"
+run_dump_test "crc32"
+run_dump_test "crc32-poly"
+
run_dump_test "align-with-input"
run_dump_test "pr20302"
run_dump_test "output-section-types"
--
2.34.1
^ permalink raw reply [flat|nested] 8+ messages in thread
* [PATCH v7 05/11] DIGEST: ldlex.l
2023-03-01 15:45 [PATCH v7 0/11 Add support for CRC64 generation in linker binutils
` (3 preceding siblings ...)
2023-03-01 15:45 ` [PATCH v7 04/11] DIGEST: testsuite binutils
@ 2023-03-01 15:45 ` binutils
2023-03-01 15:45 ` [PATCH v7 06/11] DIGEST: ldgram.y binutils
2023-03-01 15:45 ` [PATCH v7 07/11] DIGEST: ldmain.c binutils
6 siblings, 0 replies; 8+ messages in thread
From: binutils @ 2023-03-01 15:45 UTC (permalink / raw)
To: binutils; +Cc: nickc, Ulf Samuelsson
From: Ulf Samuelsson <ulf@emagii.com>
Signed-off-by: Ulf Samuelsson <ulf@emagii.com>
---
ld/ldlex.l | 8 ++++++++
1 file changed, 8 insertions(+)
diff --git a/ld/ldlex.l b/ld/ldlex.l
index 910e7ea3b8b..219702e0a1f 100644
--- a/ld/ldlex.l
+++ b/ld/ldlex.l
@@ -298,6 +298,14 @@ V_IDENTIFIER [*?.$_a-zA-Z\[\]\-\!\^\\]([*?.$_a-zA-Z0-9\[\]\-\!\^\\]|::)*
<SCRIPT>"AFTER" { RTOKEN(AFTER); }
<SCRIPT>"BEFORE" { RTOKEN(BEFORE); }
<WILD>"FILL" { RTOKEN(FILL); }
+<WILD>"DIGEST" { RTOKEN(DIGEST); }
+<WILD>"POLY" { RTOKEN(POLY); }
+<WILD>"SECTION" { RTOKEN(SECTION); }
+<WILD>"TABLE" { RTOKEN(TABLE); }
+<WILD>"TIMESTAMP" { RTOKEN(TIMESTAMP); }
+<WILD>"DEBUG" { RTOKEN(DEBUG); }
+<WILD>"ON" { RTOKEN(ON); }
+<WILD>"OFF" { RTOKEN(OFF); }
<SCRIPT>"STARTUP" { RTOKEN(STARTUP); }
<SCRIPT>"OUTPUT_FORMAT" { RTOKEN(OUTPUT_FORMAT); }
<SCRIPT>"OUTPUT_ARCH" { RTOKEN(OUTPUT_ARCH); }
--
2.34.1
^ permalink raw reply [flat|nested] 8+ messages in thread
* [PATCH v7 06/11] DIGEST: ldgram.y
2023-03-01 15:45 [PATCH v7 0/11 Add support for CRC64 generation in linker binutils
` (4 preceding siblings ...)
2023-03-01 15:45 ` [PATCH v7 05/11] DIGEST: ldlex.l binutils
@ 2023-03-01 15:45 ` binutils
2023-03-01 15:45 ` [PATCH v7 07/11] DIGEST: ldmain.c binutils
6 siblings, 0 replies; 8+ messages in thread
From: binutils @ 2023-03-01 15:45 UTC (permalink / raw)
To: binutils; +Cc: nickc, Ulf Samuelsson
From: Ulf Samuelsson <ulf@emagii.com>
Signed-off-by: Ulf Samuelsson <ulf@emagii.com>
---
ld/ldgram.y | 61 ++++++++++++++++++++++++++++++++++++++++++++++++++++-
1 file changed, 60 insertions(+), 1 deletion(-)
diff --git a/ld/ldgram.y b/ld/ldgram.y
index faffeec94b8..fcc47712b11 100644
--- a/ld/ldgram.y
+++ b/ld/ldgram.y
@@ -41,6 +41,7 @@
#include "mri.h"
#include "ldctor.h"
#include "ldlex.h"
+#include "lddigest.h"
#ifndef YYDEBUG
#define YYDEBUG 1
@@ -130,6 +131,9 @@ static int error_index;
%token DATA_SEGMENT_ALIGN DATA_SEGMENT_RELRO_END DATA_SEGMENT_END
%token SORT_BY_NAME SORT_BY_ALIGNMENT SORT_NONE
%token SORT_BY_INIT_PRIORITY
+%token DIGEST POLY POLYI TABLE SECTION
+%token TIMESTAMP
+%token DEBUG ON OFF
%token '{' '}'
%token SIZEOF_HEADERS OUTPUT_FORMAT FORCE_COMMON_ALLOCATION OUTPUT_ARCH
%token INHIBIT_COMMON_ALLOCATION FORCE_GROUP_ALLOCATION
@@ -668,7 +672,7 @@ statement:
{
lang_add_data ((int) $1, $3);
}
- | ASCII '(' mustbe_exp ')' NAME
+ | ASCII '(' mustbe_exp ')' NAME
{
/* 'value' is a memory leak, do we care? */
etree_type *value = $3;
@@ -682,6 +686,32 @@ statement:
{
lang_add_fill ($3);
}
+ | DIGEST NAME
+ { /* CRC_ADDRESS is set in <polynome>, but polynome reserves space, so we use a temporary */
+ digest_label = lang_get_label($2, &digest_big_endian);
+ lang_add_assignment (exp_assign (digest_label, exp_nameop (NAME, "."), false));
+ }
+ polynome '(' mustbe_exp ',' mustbe_exp ')'
+ {
+ lang_add_assignment (exp_assign (CRC_ADDRESS, exp_nameop (NAME, digest_label), false));
+ lang_add_assignment (exp_assign (CRC_START, $6, false));
+ lang_add_assignment (exp_assign (CRC_END, $8, false));
+ }
+ | DIGEST TABLE NAME
+ {
+ bool big_endian;
+ const char *label = lang_get_label($3, &big_endian);
+ lang_add_assignment (exp_assign (label, exp_nameop (NAME,"."), false));
+ lang_add_digest_table (big_endian);
+ }
+ | DIGEST SECTION NAME
+ {
+ lang_set_digest_section ($3);
+ }
+ | TIMESTAMP
+ {
+ lang_add_timestamp ();
+ }
| ASSERT_K
{ ldlex_expression (); }
'(' exp ',' NAME ')' separator
@@ -689,13 +719,42 @@ statement:
ldlex_popstate ();
lang_add_assignment (exp_assert ($4, $6));
}
+ | DEBUG ON
+ {
+ yydebug = 1;
+ }
+ | DEBUG OFF
+ {
+ yydebug = 0;
+ }
| INCLUDE filename
{
ldfile_open_command_file ($2);
}
+
statement_list_opt END
;
+polynome:
+ NAME
+ {
+ lang_set_digest($1);
+ }
+ | POLY '(' mustbe_exp ','
+ mustbe_exp ',' mustbe_exp ',' mustbe_exp ','
+ mustbe_exp ',' mustbe_exp ',' mustbe_exp ')'
+ {
+ lang_add_digest (
+ $3->value.value, /* size */
+ $5->value.value, /* polynome */
+ $7->value.value, /* initial value */
+ $9->value.value, /* xor value */
+ $11->value.value, /* input reflected */
+ $13->value.value, /* output reflected */
+ $15->value.value /* reciprocal */
+ );
+ }
+
statement_list:
statement_list statement
| statement
--
2.34.1
^ permalink raw reply [flat|nested] 8+ messages in thread
* [PATCH v7 07/11] DIGEST: ldmain.c
2023-03-01 15:45 [PATCH v7 0/11 Add support for CRC64 generation in linker binutils
` (5 preceding siblings ...)
2023-03-01 15:45 ` [PATCH v7 06/11] DIGEST: ldgram.y binutils
@ 2023-03-01 15:45 ` binutils
6 siblings, 0 replies; 8+ messages in thread
From: binutils @ 2023-03-01 15:45 UTC (permalink / raw)
To: binutils; +Cc: nickc, Ulf Samuelsson
From: Ulf Samuelsson <ulf@emagii.com>
Signed-off-by: Ulf Samuelsson <ulf@emagii.com>
---
ld/ldmain.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/ld/ldmain.c b/ld/ldmain.c
index 25cc89b72f9..6bd17c87469 100644
--- a/ld/ldmain.c
+++ b/ld/ldmain.c
@@ -34,6 +34,7 @@
#include "ldwrite.h"
#include "ldexp.h"
#include "ldlang.h"
+#include "lddigest.h"
#include <ldgram.h>
#include "ldlex.h"
#include "ldfile.h"
@@ -527,6 +528,7 @@ main (int argc, char **argv)
ldwrite ();
+ lang_generate_digest(); /* Calculate and store CRC on request */
if (config.map_file != NULL)
lang_map ();
if (command_line.cref)
--
2.34.1
^ permalink raw reply [flat|nested] 8+ messages in thread