Skip to content

Commit a56fece

Browse files
committed
genksyms: use uint32_t instead of unsigned long for calculating CRC
Currently, 'unsigned long' is used for intermediate variables when calculating CRCs. The size of 'long' differs depending on the architecture: it is 32 bits on 32-bit architectures and 64 bits on 64-bit architectures. The CRC values generated by genksyms represent the compatibility of exported symbols. Therefore, reproducibility is important. In other words, we need to ensure that the output is the same when the kernel source is identical, regardless of whether genksyms is running on a 32-bit or 64-bit build machine. Fortunately, the output from genksyms is not affected by the build machine's architecture because only the lower 32 bits of the 'unsigned long' variables are used. To make it even clearer that the CRC calculation is independent of the build machine's architecture, this commit explicitly uses the fixed-width type, uint32_t. Signed-off-by: Masahiro Yamada <[email protected]>
1 parent 2759bd9 commit a56fece

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

scripts/genksyms/genksyms.c

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
#include <stdio.h>
1414
#include <string.h>
15+
#include <stdint.h>
1516
#include <stdlib.h>
1617
#include <unistd.h>
1718
#include <assert.h>
@@ -60,7 +61,7 @@ static void print_type_name(enum symbol_type type, const char *name);
6061

6162
/*----------------------------------------------------------------------*/
6263

63-
static const unsigned int crctab32[] = {
64+
static const uint32_t crctab32[] = {
6465
0x00000000U, 0x77073096U, 0xee0e612cU, 0x990951baU, 0x076dc419U,
6566
0x706af48fU, 0xe963a535U, 0x9e6495a3U, 0x0edb8832U, 0x79dcb8a4U,
6667
0xe0d5e91eU, 0x97d2d988U, 0x09b64c2bU, 0x7eb17cbdU, 0xe7b82d07U,
@@ -115,19 +116,19 @@ static const unsigned int crctab32[] = {
115116
0x2d02ef8dU
116117
};
117118

118-
static unsigned long partial_crc32_one(unsigned char c, unsigned long crc)
119+
static uint32_t partial_crc32_one(uint8_t c, uint32_t crc)
119120
{
120121
return crctab32[(crc ^ c) & 0xff] ^ (crc >> 8);
121122
}
122123

123-
static unsigned long partial_crc32(const char *s, unsigned long crc)
124+
static uint32_t partial_crc32(const char *s, uint32_t crc)
124125
{
125126
while (*s)
126127
crc = partial_crc32_one(*s++, crc);
127128
return crc;
128129
}
129130

130-
static unsigned long crc32(const char *s)
131+
static uint32_t crc32(const char *s)
131132
{
132133
return partial_crc32(s, 0xffffffff) ^ 0xffffffff;
133134
}
@@ -517,7 +518,7 @@ static void print_list(FILE * f, struct string_list *list)
517518
}
518519
}
519520

520-
static unsigned long expand_and_crc_sym(struct symbol *sym, unsigned long crc)
521+
static uint32_t expand_and_crc_sym(struct symbol *sym, uint32_t crc)
521522
{
522523
struct string_list *list = sym->defn;
523524
struct string_list **e, **b;
@@ -624,7 +625,7 @@ static unsigned long expand_and_crc_sym(struct symbol *sym, unsigned long crc)
624625
void export_symbol(const char *name)
625626
{
626627
struct symbol *sym;
627-
unsigned long crc;
628+
uint32_t crc;
628629
int has_changed = 0;
629630

630631
sym = find_symbol(name, SYM_NORMAL, 0);
@@ -672,7 +673,7 @@ void export_symbol(const char *name)
672673
if (flag_dump_defs)
673674
fputs(">\n", debugfile);
674675

675-
printf("#SYMVER %s 0x%08lx\n", name, crc);
676+
printf("#SYMVER %s 0x%08lx\n", name, (unsigned long)crc);
676677
}
677678

678679
/*----------------------------------------------------------------------*/

0 commit comments

Comments
 (0)