lddigest 32-bit support and gcc-4 compile errors
authorAlan Modra <amodra@gmail.com>
Wed, 8 Mar 2023 10:56:52 +0000 (21:26 +1030)
committerAlan Modra <amodra@gmail.com>
Thu, 9 Mar 2023 05:32:57 +0000 (16:02 +1030)
* ld.texi: Revert 2023-03-08 commit 9a534b9f8e3d.
* testsuite/ld-scripts/crc64-poly.d: Likewise.
* testsuite/ld-scripts/crc64-poly.t: Likewise.
* lddigest.c: Formatting.
(get_uint64_t): New function.
(lang_add_digest): Take etree_type* args.  Replace "illegal" with
"invalid" in error message.
* lddigest.h (lang_add_digest): Update prototype.
* lddigest_tab.c (algorithms): Work around gcc-4 errors.
* ldgram.y (polynome): Adjust lang_add_digest call.
* testsuite/ld-scripts/crc64-poly-size.d: Update expected error.

ld/ld.texi
ld/lddigest.c
ld/lddigest.h
ld/lddigest_tab.c
ld/ldgram.y
ld/testsuite/ld-scripts/crc64-poly-size.d
ld/testsuite/ld-scripts/crc64-poly.d
ld/testsuite/ld-scripts/crc64-poly.t

index 207ac98126bc3a113b9a0c7baf3fac01229b3b88..c21d849fe243b59b0e8df9dc017d949f91dc57a4 100644 (file)
@@ -5581,10 +5581,6 @@ The parameters are explained in detail in
 
 Some of the predefined polynomes are the same, but differs in the other
 parameters.
-
-Note - the generation of 64-bit polynomes on 32-bit hosts for 32-bit
-targets is not supported.
-
 @page
 The 32-bit <polynome> command defines the following global symbols.
 
index a2d7460e56a36da1a8da5d225512fd97262e2e1a..bd742020354cd3f2e146e5a0e30cf6f65fffae66 100644 (file)
@@ -103,10 +103,12 @@ lang_add_crc32_syndrome (algorithm_desc_t * a)
 static void
 lang_add_crc32_table (bool big_endian)
 {
-  uint32_t *crc32_table = algorithm.crc_tab;   /* Use a precomputed, if it exists */
+  /* Use a precomputed table, if one exists.  */
+  uint32_t *crc32_table = algorithm.crc_tab;
   bool local_table = false;
   if (crc32_table == NULL)
-    {                          /* No luck, create a table */
+    {
+      /* No luck, create a table.  */
       crc32_table = init_crc32_tab (&algorithm);
       if (crc32_table == NULL)
        {
@@ -227,14 +229,42 @@ lang_add_crc64_table (bool big_endian)
 
 /* ============ DIGEST COMMON functions ======================================*/
 
+static uint64_t
+get_uint64 (etree_type *tree, bool *err)
+{
+  if (tree != NULL)
+    {
+      exp_fold_tree_no_dot (tree);
+
+      if (expld.result.valid_p)
+       {
+         if (expld.result.str != NULL)
+           {
+             char *end;
+             uint64_t val = strtoull (expld.result.str, &end, 16);
+             if (!*end)
+               return val;
+           }
+         else
+           {
+             if (expld.result.section != NULL)
+               expld.result.value += expld.result.section->vma;
+             return expld.result.value;
+           }
+       }
+    }
+  *err = true;
+  return 0;
+}
+
 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)
+lang_add_digest (etree_type *size,
+                etree_type *poly,
+                etree_type *initial,
+                etree_type *xor_val,
+                etree_type *ireflect,
+                etree_type *oreflect,
+                etree_type *reciprocal)
 {
   if (algorithm.crc_algo != no_algo)   /* We only allow one CRC <polynom> */
     {
@@ -242,40 +272,44 @@ lang_add_digest (bfd_vma size,
       return;
     }
 
+  bool err = false;
   algorithm.name = "CUSTOM";
   algorithm.big_endian = digest_big_endian;
-  if (size == 64)
+  algorithm.crc_size = get_uint64 (size, &err);
+  algorithm.poly.d64 = get_uint64 (poly, &err);
+  algorithm.initial.d64 = get_uint64 (initial, &err);
+  algorithm.xor_val.d64 = get_uint64 (xor_val, &err);
+  algorithm.ireflect = get_uint64 (ireflect, &err);
+  algorithm.oreflect = get_uint64 (oreflect, &err);
+  algorithm.crc_tab = NULL;
+  algorithm.reciprocal = get_uint64 (reciprocal, &err);
+  algorithm.expected.d64 = 0;
+
+  if (err)
+    {
+      einfo (_("%F%P: Invalid DIGEST arg\n"));
+      return;
+    }
+
+  if (algorithm.crc_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)
+  else if (algorithm.crc_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;
+      algorithm.poly.d32._0 = algorithm.poly.d64;
+      algorithm.poly.d32._1 = 0;
+      algorithm.initial.d32._0 = algorithm.initial.d64;
+      algorithm.initial.d32._1 = 0;
+      algorithm.xor_val.d32._0 = algorithm.xor_val.d64;
+      algorithm.xor_val.d32._1 = 0;
       lang_add_crc32_syndrome (&algorithm);
     }
   else
     {
-      einfo (_("%F%P: Illegal Size in DIGEST: %E\n"));
+      einfo (_("%F%P: Invalid Size in DIGEST\n"));
       return;
     }
 }
@@ -675,7 +709,7 @@ set_crc64_checksum (uint64_t crc, bfd_vma addr)
 }
 
 static bool
-set_crc_checksum (uint64_t crc, bfd_vma addr, bfd_vma size)
+set_crc_checksum (uint64_t crc, bfd_vma addr, int size)
 {
   bool status;
   if (size == 64)
index a1eeb022d00ba66ca1d9fbcec954283ed469be86..8f2889f18462f6341e8e7e10717252174db575c9 100755 (executable)
@@ -173,8 +173,11 @@ extern void lang_add_crc64_syndrome
   (algorithm_desc_t * );
 
 /* In lddigest.c  */
+union etree_union;
 extern void lang_add_digest
-  (bfd_vma, bfd_vma, bfd_vma, bfd_vma, bfd_vma, bfd_vma, bfd_vma);
+  (union etree_union *, union etree_union *, union etree_union *,
+   union etree_union *, union etree_union *, union etree_union *,
+   union etree_union *);
 extern bool lang_set_digest
   (char *);
 extern void lang_add_digest_table
index 4f5db10c997dcccd97cfe88e78759855822e2864..b286a3c01618bef114b768c37c942934bbde115a 100644 (file)
@@ -99,9 +99,9 @@ const algorithm_desc_t algorithms[MAXALGO+1] =
   [CRC32] =
        {
                crc_algo_32, 32, "CRC32",
-               .poly.d32._0 = CRC_POLY_32,
+               .poly.d32 = { CRC_POLY_32, 0 },
                .initial.d64 = CRC_START_32_INV,
-               .xor_val.d32._0 = CRC_END_32_INV,
+               .xor_val.d32 = { CRC_END_32_INV, 0 },
                .ireflect = true,
                .oreflect = true,
                .reciprocal = false,
index 54bf8e0f908e46cda6867804b7e5ca36e1ee5186..93aff6eeb766b39040a2e0e11650e340765bc583 100644 (file)
@@ -747,13 +747,13 @@ polynome:
                   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           */
+                       $3,     /* size                 */
+                       $5,     /* polynome             */
+                       $7,     /* initial value        */
+                       $9,     /* xor     value        */
+                       $11,    /* input   reflected    */
+                       $13,    /* output  reflected    */
+                       $15     /* reciprocal           */
                        );
                  polynome_valid = true;
                }
index 6a3651cbff5e8908acacd4fe7f8e70af45c965be..1c7b3c468819bc4cae946ffca441a03a46186f70 100644 (file)
@@ -1,5 +1,5 @@
 #source: crc64-poly-size.s
 #ld: -T crc64-poly-size.t
-# error: .*: Illegal Size in DIGEST: .*
+# error: .*: Invalid Size in DIGEST
 #target: [is_elf_format] [is_coff_format]
 #skip: tic4x-*-* tic54x-*-*
index a1e6eb8f1506afb731e1527364a7c2c02f44dc2c..b54ac47e448fd02fd9c44b2cfbdbbb1a9de91023 100644 (file)
@@ -9,7 +9,7 @@
 Contents of section .text:
  1200 434f4445 deadbeef 00000000 00000000  CODE............
  1210 6c40df5f 0b497347 00000000 00000000  l@._.IsG........
- 1220 ee5e1ecd 02f31206 00000000 00000000  ................
+ 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............
index 00a21557827ee1cbffbec767d4ca0ee93f24e6dd..fb357caedf9dd89802649a936354a007ed44b442 100644 (file)
@@ -26,7 +26,7 @@ SECTIONS
       QUAD(0x0);
 
       crc64 = .;
-      DIGEST "_CRC64#BE" POLY(64,0xA9EA3693,0,0,0,0,0)(ecc_start , ecc_end)
+      DIGEST "_CRC64#BE" POLY(64,0x42F0E1EBA9EA3693,0,0,0,0,0)(ecc_start , ecc_end)
       QUAD(0x0);
 
       INCLUDE "end_tag.inc"