mirror of
https://mirrors.bfsu.edu.cn/git/linux.git
synced 2024-12-05 18:14:07 +08:00
21532b9e5b
bin2c is used to create a valid C file out of a binary file where two symbols will be globally defined: <name> and <name>_size. <name> is passed as the first parameter of the host binary. Building using goto-cc reported that the purgatory binary code (the only current user of this utility) declares kexec_purgatory_size as 'size_t' where bin2c generate <name>_size to be 'int' so in a 64-bit host where sizeof(size_t) > sizeof(int) this type mismatch will always yield the wrong value for big-endian architectures while for little-endian it will be wrong if the object laid in memory directly after kexec_purgatory_size contains non-zero value at the time of reading. This commit changes <name>_size to be size_t instead. Note: Another way to fix the problem is to change the type of kexec_purgatory_size to be 'int' as there's this check in code: (kexec_purgatory_size <= 0) Signed-off-by: Michael Tautschnig <tautschn@amazon.com> Cc: Vivek Goyal <vgoyal@redhat.com> Acked-by: Dave Young <dyoung@redhat.com> Signed-off-by: Michal Marek <mmarek@suse.com>
37 lines
743 B
C
37 lines
743 B
C
/*
|
|
* Unloved program to convert a binary on stdin to a C include on stdout
|
|
*
|
|
* Jan 1999 Matt Mackall <mpm@selenic.com>
|
|
*
|
|
* This software may be used and distributed according to the terms
|
|
* of the GNU General Public License, incorporated herein by reference.
|
|
*/
|
|
|
|
#include <stdio.h>
|
|
|
|
int main(int argc, char *argv[])
|
|
{
|
|
int ch, total = 0;
|
|
|
|
if (argc > 1)
|
|
printf("const char %s[] %s=\n",
|
|
argv[1], argc > 2 ? argv[2] : "");
|
|
|
|
do {
|
|
printf("\t\"");
|
|
while ((ch = getchar()) != EOF) {
|
|
total++;
|
|
printf("\\x%02x", ch);
|
|
if (total % 16 == 0)
|
|
break;
|
|
}
|
|
printf("\"\n");
|
|
} while (ch != EOF);
|
|
|
|
if (argc > 1)
|
|
printf("\t;\n\n#include <linux/types.h>\n\nconst size_t %s_size = %d;\n",
|
|
argv[1], total);
|
|
|
|
return 0;
|
|
}
|