Browse Source

lddigest 32-bit support and gcc-4 compile errors

* ld.texi: Revert 2023-03-08 commit 9a534b9f8e.
	* 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.
users/aburgess/try-core-file-pid0
Alan Modra 3 years ago
parent
commit
bf0e353754
  1. 4
      ld/ld.texi
  2. 98
      ld/lddigest.c
  3. 5
      ld/lddigest.h
  4. 4
      ld/lddigest_tab.c
  5. 14
      ld/ldgram.y
  6. 2
      ld/testsuite/ld-scripts/crc64-poly-size.d
  7. 2
      ld/testsuite/ld-scripts/crc64-poly.d
  8. 2
      ld/testsuite/ld-scripts/crc64-poly.t

4
ld/ld.texi

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

98
ld/lddigest.c

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

5
ld/lddigest.h

@ -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

4
ld/lddigest_tab.c

@ -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,

14
ld/ldgram.y

@ -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;
}

2
ld/testsuite/ld-scripts/crc64-poly-size.d

@ -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-*-*

2
ld/testsuite/ld-scripts/crc64-poly.d

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

2
ld/testsuite/ld-scripts/crc64-poly.t

@ -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"

Loading…
Cancel
Save