From: Alan Modra Date: Wed, 8 Mar 2023 10:56:52 +0000 (+1030) Subject: lddigest 32-bit support and gcc-4 compile errors X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=bf0e35375461ef2a17e2872e7f5c1446a5924b64;p=binutils-gdb.git lddigest 32-bit support and gcc-4 compile errors * 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. --- diff --git a/ld/ld.texi b/ld/ld.texi index 207ac98126b..c21d849fe24 100644 --- a/ld/ld.texi +++ b/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 command defines the following global symbols. diff --git a/ld/lddigest.c b/ld/lddigest.c index a2d7460e56a..bd742020354 100644 --- a/ld/lddigest.c +++ b/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 */ { @@ -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) diff --git a/ld/lddigest.h b/ld/lddigest.h index a1eeb022d00..8f2889f1846 100755 --- a/ld/lddigest.h +++ b/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 diff --git a/ld/lddigest_tab.c b/ld/lddigest_tab.c index 4f5db10c997..b286a3c0161 100644 --- a/ld/lddigest_tab.c +++ b/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, diff --git a/ld/ldgram.y b/ld/ldgram.y index 54bf8e0f908..93aff6eeb76 100644 --- a/ld/ldgram.y +++ b/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; } diff --git a/ld/testsuite/ld-scripts/crc64-poly-size.d b/ld/testsuite/ld-scripts/crc64-poly-size.d index 6a3651cbff5..1c7b3c46881 100644 --- a/ld/testsuite/ld-scripts/crc64-poly-size.d +++ b/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-*-* diff --git a/ld/testsuite/ld-scripts/crc64-poly.d b/ld/testsuite/ld-scripts/crc64-poly.d index a1e6eb8f150..b54ac47e448 100644 --- a/ld/testsuite/ld-scripts/crc64-poly.d +++ b/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............ diff --git a/ld/testsuite/ld-scripts/crc64-poly.t b/ld/testsuite/ld-scripts/crc64-poly.t index 00a21557827..fb357caedf9 100644 --- a/ld/testsuite/ld-scripts/crc64-poly.t +++ b/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"