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 Some of the predefined polynomes are the same, but differs in the other
parameters. parameters.
Note - the generation of 64-bit polynomes on 32-bit hosts for 32-bit
targets is not supported.
@page @page
The 32-bit <polynome> command defines the following global symbols. 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 static void
lang_add_crc32_table (bool big_endian) 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; bool local_table = false;
if (crc32_table == NULL) if (crc32_table == NULL)
{ /* No luck, create a table */ {
/* No luck, create a table. */
crc32_table = init_crc32_tab (&algorithm); crc32_table = init_crc32_tab (&algorithm);
if (crc32_table == NULL) if (crc32_table == NULL)
{ {
@ -227,14 +229,42 @@ lang_add_crc64_table (bool big_endian)
/* ============ DIGEST COMMON functions ======================================*/ /* ============ 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 void
lang_add_digest (bfd_vma size, lang_add_digest (etree_type *size,
bfd_vma poly, etree_type *poly,
bfd_vma initial, etree_type *initial,
bfd_vma xor_val, etree_type *xor_val,
bfd_vma ireflect, etree_type *ireflect,
bfd_vma oreflect, etree_type *oreflect,
bfd_vma reciprocal) etree_type *reciprocal)
{ {
if (algorithm.crc_algo != no_algo) /* We only allow one CRC <polynom> */ if (algorithm.crc_algo != no_algo) /* We only allow one CRC <polynom> */
{ {
@ -242,40 +272,44 @@ lang_add_digest (bfd_vma size,
return; return;
} }
bool err = false;
algorithm.name = "CUSTOM"; algorithm.name = "CUSTOM";
algorithm.big_endian = digest_big_endian; 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_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); lang_add_crc64_syndrome (&algorithm);
} }
else if (size == 32) else if (algorithm.crc_size == 32)
{ {
algorithm.crc_algo = crc_algo_32; algorithm.crc_algo = crc_algo_32;
algorithm.crc_size = size; algorithm.poly.d32._0 = algorithm.poly.d64;
algorithm.poly.d32._0 = poly; /* Set the polynom */ algorithm.poly.d32._1 = 0;
algorithm.initial.d32._0 = initial; /* Set seed */ algorithm.initial.d32._0 = algorithm.initial.d64;
algorithm.xor_val.d32._0 = xor_val; /* final XOR value */ algorithm.initial.d32._1 = 0;
algorithm.ireflect = ireflect; algorithm.xor_val.d32._0 = algorithm.xor_val.d64;
algorithm.oreflect = oreflect; algorithm.xor_val.d32._1 = 0;
algorithm.crc_tab = NULL;
algorithm.reciprocal = reciprocal;
algorithm.expected.d32._0 = 0;
lang_add_crc32_syndrome (&algorithm); lang_add_crc32_syndrome (&algorithm);
} }
else else
{ {
einfo (_("%F%P: Illegal Size in DIGEST: %E\n")); einfo (_("%F%P: Invalid Size in DIGEST\n"));
return; return;
} }
} }
@ -675,7 +709,7 @@ set_crc64_checksum (uint64_t crc, bfd_vma addr)
} }
static bool 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; bool status;
if (size == 64) if (size == 64)

5
ld/lddigest.h

@ -173,8 +173,11 @@ extern void lang_add_crc64_syndrome
(algorithm_desc_t * ); (algorithm_desc_t * );
/* In lddigest.c */ /* In lddigest.c */
union etree_union;
extern void lang_add_digest 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 extern bool lang_set_digest
(char *); (char *);
extern void lang_add_digest_table extern void lang_add_digest_table

4
ld/lddigest_tab.c

@ -99,9 +99,9 @@ const algorithm_desc_t algorithms[MAXALGO+1] =
[CRC32] = [CRC32] =
{ {
crc_algo_32, 32, "CRC32", crc_algo_32, 32, "CRC32",
.poly.d32._0 = CRC_POLY_32, .poly.d32 = { CRC_POLY_32, 0 },
.initial.d64 = CRC_START_32_INV, .initial.d64 = CRC_START_32_INV,
.xor_val.d32._0 = CRC_END_32_INV, .xor_val.d32 = { CRC_END_32_INV, 0 },
.ireflect = true, .ireflect = true,
.oreflect = true, .oreflect = true,
.reciprocal = false, .reciprocal = false,

14
ld/ldgram.y

@ -747,13 +747,13 @@ polynome:
mustbe_exp ',' mustbe_exp ',' mustbe_exp ')' mustbe_exp ',' mustbe_exp ',' mustbe_exp ')'
{ {
lang_add_digest ( lang_add_digest (
$3->value.value, /* size */ $3, /* size */
$5->value.value, /* polynome */ $5, /* polynome */
$7->value.value, /* initial value */ $7, /* initial value */
$9->value.value, /* xor value */ $9, /* xor value */
$11->value.value, /* input reflected */ $11, /* input reflected */
$13->value.value, /* output reflected */ $13, /* output reflected */
$15->value.value /* reciprocal */ $15 /* reciprocal */
); );
polynome_valid = true; polynome_valid = true;
} }

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

@ -1,5 +1,5 @@
#source: crc64-poly-size.s #source: crc64-poly-size.s
#ld: -T crc64-poly-size.t #ld: -T crc64-poly-size.t
# error: .*: Illegal Size in DIGEST: .* # error: .*: Invalid Size in DIGEST
#target: [is_elf_format] [is_coff_format] #target: [is_elf_format] [is_coff_format]
#skip: tic4x-*-* tic54x-*-* #skip: tic4x-*-* tic54x-*-*

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

@ -9,7 +9,7 @@
Contents of section .text: Contents of section .text:
1200 434f4445 deadbeef 00000000 00000000 CODE............ 1200 434f4445 deadbeef 00000000 00000000 CODE............
1210 6c40df5f 0b497347 00000000 00000000 l@._.IsG........ 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 1230 00000000 00000000 deadbeef 434f4445 ............CODE
1240 31323334 35363738 3900ffff ffffffff 123456789....... 1240 31323334 35363738 3900ffff ffffffff 123456789.......
1250 434f4445 00000000 00000000 00000000 CODE............ 1250 434f4445 00000000 00000000 00000000 CODE............

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

@ -26,7 +26,7 @@ SECTIONS
QUAD(0x0); QUAD(0x0);
crc64 = .; 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); QUAD(0x0);
INCLUDE "end_tag.inc" INCLUDE "end_tag.inc"

Loading…
Cancel
Save