* [PATCH v1 0/1 Fix DIGEST build issues on 32-bit hosts
@ 2023-03-08 12:54 binutils
2023-03-08 12:54 ` [PATCH v1] DIGEST: Disable 64-bit CRC for 32-bit BFD binutils
0 siblings, 1 reply; 2+ messages in thread
From: binutils @ 2023-03-08 12:54 UTC (permalink / raw)
To: binutils; +Cc: nickc, mliska, schwab
Patchset 1
The DIGEST feature breaks builds on 32-bit hosts
since it was assumed that bfd_vma was always 64-bits.
When bfd_vma is 32-bit, all expression in the ldgram.y
expression calculator is 32-bit, making it impossible
or at least very difficult to support 64 bit digest.
This patchset disable the 64-bit functionality
on 32-bit hosts which does not explicitly
build with 64-bit BFDs
(I.E: makes sure that BFD64 is defined)
[PATCH v1] DIGEST: Disable 64-bit CRC for 32-bit BFD
^ permalink raw reply [flat|nested] 2+ messages in thread
* [PATCH v1] DIGEST: Disable 64-bit CRC for 32-bit BFD
2023-03-08 12:54 [PATCH v1 0/1 Fix DIGEST build issues on 32-bit hosts binutils
@ 2023-03-08 12:54 ` binutils
0 siblings, 0 replies; 2+ messages in thread
From: binutils @ 2023-03-08 12:54 UTC (permalink / raw)
To: binutils; +Cc: nickc, mliska, schwab, Ulf Samuelsson
From: Ulf Samuelsson <ulf@emagii.com>
When the binutils are built on a 32-bit host,the default is that the
bfd_vma type is 32-bit.
All the expression evaluations are also 32-bit which makes it very
difficult to support 64-bit operations.
All predefined 64-bit polynomes are removed and the "DIGEST POLY(64,..."
is disabled as well.
Signed-off-by: Ulf Samuelsson <ulf@emagii.com>
---
ld/NEWS | 3 +++
ld/ld.texi | 9 +++++--
ld/lddigest.c | 63 +++++++++++++++++++++++++----------------------
ld/lddigest.h | 7 ++++++
ld/lddigest_tab.c | 2 ++
5 files changed, 52 insertions(+), 32 deletions(-)
diff --git a/ld/NEWS b/ld/NEWS
index b79023ecb95..09ab3f15549 100644
--- a/ld/NEWS
+++ b/ld/NEWS
@@ -1,5 +1,8 @@
-*- text -*-
+* The DIGEST feature is broken when 32-bit BFDs are used.
+ Disable 64-bit CRCs when BFD64 is not defined.
+
* The linker script has a new command to insert a timestamp
TIMESTAMP
inserts the current time (seconds since Epoch) as a 64-bit value
diff --git a/ld/ld.texi b/ld/ld.texi
index c21d849fe24..60b5ff40a56 100644
--- a/ld/ld.texi
+++ b/ld/ld.texi
@@ -5511,7 +5511,9 @@ There is one predefined 32-bit polynome
@tab
@end multitable
-There are five predefined 64-bit polynomes
+There are five predefined 64-bit polynomes available on binutils builds
+on 64-bit hosts. They are not available when built on 32-bit hosts unless
+the build is configured with @code{--enable-64-bit-bfd}.
@multitable @columnfractions .3 .4 .4
@item
@@ -5575,11 +5577,14 @@ bitreverse result (before xor'ing)
bitreverse polynome before generating table
@end multitable
+Again, 64-bit polynomes are only available when binutils is built on
+a 64-bit host.
+
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
+Some of the predefined polynomes look the same, but differs in the other
parameters.
@page
The 32-bit <polynome> command defines the following global symbols.
diff --git a/ld/lddigest.c b/ld/lddigest.c
index d0bb4db73ab..ca450ed33d5 100644
--- a/ld/lddigest.c
+++ b/ld/lddigest.c
@@ -45,10 +45,6 @@ char *CRC_START = NULL;
char *CRC_END = NULL;
char *CRC_TABLE = NULL;
-
-
-
-
const char *digest_section = ".text";
const char *digest_label = "___CRC_LABEL__";
bool digest_big_endian = false;
@@ -129,7 +125,7 @@ lang_add_crc32_table (bool big_endian)
}
/* ============ CRC-64 public functions ======================================*/
-
+#if defined(ENABLE_CRC64)
void
lang_add_crc64_syndrome (algorithm_desc_t * a)
{
@@ -145,8 +141,9 @@ lang_add_crc64_syndrome (algorithm_desc_t * a)
return;
}
}
+#endif
-#if (DEBUG_CRC == 1)
+#if (DEBUG_CRC == 1) && defined(ENABLE_CRC64)
static void
print_hash64_table (algorithm_desc_t * a)
{
@@ -178,6 +175,7 @@ print_hash64_table (algorithm_desc_t * a)
#define print_hash64_table(x)
#endif
+#if defined(ENABLE_CRC64)
static void
lang_add_crc64_table (bool big_endian)
{
@@ -211,7 +209,7 @@ lang_add_crc64_table (bool big_endian)
if (local_table)
free (crc64_table);
}
-
+#endif
/* ============ DIGEST COMMON functions ======================================*/
void
@@ -229,35 +227,37 @@ lang_add_digest (bfd_vma size,
algorithm.name = "CUSTOM";
algorithm.big_endian = digest_big_endian;
- if (size == 64)
+ if (size == 32)
{
- algorithm.crc_algo = crc_algo_64;
+ algorithm.crc_algo = crc_algo_32;
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.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.d64 = 0;
-
- lang_add_crc64_syndrome (&algorithm);
+ algorithm.expected.d32._0 = 0;
+ lang_add_crc32_syndrome (&algorithm);
}
- else if (size == 32)
+#if defined(ENABLE_CRC64)
+ else if (size == 64)
{
- algorithm.crc_algo = crc_algo_32;
+ algorithm.crc_algo = crc_algo_64;
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.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.d32._0 = 0;
- lang_add_crc32_syndrome (&algorithm);
+ algorithm.expected.d64 = 0;
+
+ lang_add_crc64_syndrome (&algorithm);
}
+#endif
else
{
einfo (_("%F%P: Illegal Size in DIGEST: %E\n"));
@@ -389,15 +389,16 @@ lang_set_digest (char *digest)
#endif
memcpy (&algorithm, &algorithms[a], sizeof (algorithm_desc_t));
algorithm.big_endian = digest_big_endian;
- if (algorithm.crc_size == 64)
+ if (algorithm.crc_size == 32)
{
- lang_add_crc64_syndrome (&algorithm);
+ lang_add_crc32_syndrome (&algorithm);
}
- else if (algorithm.crc_size == 32)
+#if defined(ENABLE_CRC64)
+ else if (algorithm.crc_size == 64)
{
- lang_add_crc32_syndrome (&algorithm);
+ lang_add_crc64_syndrome (&algorithm);
}
-
+#endif
return true;
}
#if (DEBUG_CRC == 1)
@@ -418,15 +419,17 @@ lang_add_digest_table (bool big_endian)
{
lang_add_crc32_table (big_endian);
}
+#if defined(ENABLE_CRC64)
else if (algorithm.crc_algo == crc_algo_64)
{
lang_add_crc64_table (big_endian);
}
+#endif
}
/* ============ CRC DEBUG functions ==========================================*/
+#if (DEBUG_CRC == 1) && defined(ENABLE_CRC64)
-#if (DEBUG_CRC == 1)
static void
debug_hex (char *prompt, unsigned char *section, bfd_vma address, bfd_vma sz)
{
@@ -583,7 +586,7 @@ get_text_section_contents (void)
return false;
}
-#if (DEBUG_CRC == 1)
+#if (DEBUG_CRC == 1) && defined(ENABLE_CRC64)
print_section (text_section);
/*
printf ("%s: [0x%08lx .. 0x%08lx]\n",
@@ -849,7 +852,7 @@ lang_generate_crc (void)
_crc_area_end - _crc_area_start);
#endif
-#if (DEBUG_CRC == 1)
+#if (DEBUG_CRC == 1) && defined(ENABLE_CRC64)
printf ("size = 0x%08u\n", (uint32_t) (_crc_area_end - _crc_area_start));
printf ("start = 0x%016lx\n", _crc_area_start);
printf ("end = 0x%016lx\n", _crc_area_end);
diff --git a/ld/lddigest.h b/ld/lddigest.h
index 9f5e5f3fbda..7c3d3c0339b 100755
--- a/ld/lddigest.h
+++ b/ld/lddigest.h
@@ -34,6 +34,9 @@
#include <stdbool.h>
#include "bfd.h"
+#if defined(BFD64)
+#define ENABLE_CRC64 1
+
#define CRC_POLY_64_ECMA 0x42F0E1EBA9EA3693ull /* Normal */
#define CRC_POLY_64_ECMA_EXP 0x6C40DF5F0B497347ull /* CRC when testing "123456789" */
#define CRC_POLY_64_ECMA_R 0xC96C5795D7870F42ull /* Reversed */
@@ -55,6 +58,8 @@
#define CRC_END_64 0x0000000000000000ull
#define CRC_END_64_INV 0xFFFFFFFFFFFFFFFFull
+#endif
+
#define CRC_START_32 0xFFFFFFFFul
#define CRC_END_32 0xFFFFFFFFul
@@ -86,11 +91,13 @@ typedef enum algorithm
typedef enum
{
+#if defined(BFD64)
CRC64_ECMA,
CRC64_WE,
CRC64_XZ,
CRC64_ISO,
CRC64_ISO_R,
+#endif
CRC32,
MAXALGO
} poly_t;
diff --git a/ld/lddigest_tab.c b/ld/lddigest_tab.c
index 4f5db10c997..aaba3cf13d2 100644
--- a/ld/lddigest_tab.c
+++ b/ld/lddigest_tab.c
@@ -36,6 +36,7 @@
const algorithm_desc_t algorithms[MAXALGO+1] =
{
+#if defined(ENABLE_CRC64)
[CRC64_ECMA] =
{
crc_algo_64, 64, "CRC64-ECMA",
@@ -96,6 +97,7 @@ const algorithm_desc_t algorithms[MAXALGO+1] =
.crc_tab = NULL,
.expected.d64 = 0xb90956c775a41001
},
+#endif
[CRC32] =
{
crc_algo_32, 32, "CRC32",
--
2.34.1
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2023-03-08 12:55 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-03-08 12:54 [PATCH v1 0/1 Fix DIGEST build issues on 32-bit hosts binutils
2023-03-08 12:54 ` [PATCH v1] DIGEST: Disable 64-bit CRC for 32-bit BFD binutils
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).