mirror of
https://github.com/tbsdtv/linux_media.git
synced 2025-07-23 20:51:03 +02:00
x86/tools/relocs: Mark die() with the printf function attr format
Mark die() as a function which accepts printf-style arguments so that the compiler can typecheck them against the supplied format string. Use the C99 inttypes.h format specifiers as relocs.c gets built for both 32- and 64-bit. Original version of the patch by Greg Kroah-Hartman <gregkh@linuxfoundation.org> Signed-off-by: Borislav Petkov <bp@suse.de> Reviewed-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> Link: http://lkml.kernel.org/r/YNnb6Q4QHtNYC049@zn.tnic
This commit is contained in:
@@ -26,6 +26,9 @@ static struct relocs relocs32;
|
|||||||
#if ELF_BITS == 64
|
#if ELF_BITS == 64
|
||||||
static struct relocs relocs32neg;
|
static struct relocs relocs32neg;
|
||||||
static struct relocs relocs64;
|
static struct relocs relocs64;
|
||||||
|
#define FMT PRIu64
|
||||||
|
#else
|
||||||
|
#define FMT PRIu32
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
struct section {
|
struct section {
|
||||||
@@ -389,7 +392,7 @@ static void read_ehdr(FILE *fp)
|
|||||||
Elf_Shdr shdr;
|
Elf_Shdr shdr;
|
||||||
|
|
||||||
if (fseek(fp, ehdr.e_shoff, SEEK_SET) < 0)
|
if (fseek(fp, ehdr.e_shoff, SEEK_SET) < 0)
|
||||||
die("Seek to %d failed: %s\n", ehdr.e_shoff, strerror(errno));
|
die("Seek to %" FMT " failed: %s\n", ehdr.e_shoff, strerror(errno));
|
||||||
|
|
||||||
if (fread(&shdr, sizeof(shdr), 1, fp) != 1)
|
if (fread(&shdr, sizeof(shdr), 1, fp) != 1)
|
||||||
die("Cannot read initial ELF section header: %s\n", strerror(errno));
|
die("Cannot read initial ELF section header: %s\n", strerror(errno));
|
||||||
@@ -412,17 +415,17 @@ static void read_shdrs(FILE *fp)
|
|||||||
|
|
||||||
secs = calloc(shnum, sizeof(struct section));
|
secs = calloc(shnum, sizeof(struct section));
|
||||||
if (!secs) {
|
if (!secs) {
|
||||||
die("Unable to allocate %d section headers\n",
|
die("Unable to allocate %ld section headers\n",
|
||||||
shnum);
|
shnum);
|
||||||
}
|
}
|
||||||
if (fseek(fp, ehdr.e_shoff, SEEK_SET) < 0) {
|
if (fseek(fp, ehdr.e_shoff, SEEK_SET) < 0) {
|
||||||
die("Seek to %d failed: %s\n",
|
die("Seek to %" FMT " failed: %s\n",
|
||||||
ehdr.e_shoff, strerror(errno));
|
ehdr.e_shoff, strerror(errno));
|
||||||
}
|
}
|
||||||
for (i = 0; i < shnum; i++) {
|
for (i = 0; i < shnum; i++) {
|
||||||
struct section *sec = &secs[i];
|
struct section *sec = &secs[i];
|
||||||
if (fread(&shdr, sizeof(shdr), 1, fp) != 1)
|
if (fread(&shdr, sizeof(shdr), 1, fp) != 1)
|
||||||
die("Cannot read ELF section headers %d/%d: %s\n",
|
die("Cannot read ELF section headers %d/%ld: %s\n",
|
||||||
i, shnum, strerror(errno));
|
i, shnum, strerror(errno));
|
||||||
sec->shdr.sh_name = elf_word_to_cpu(shdr.sh_name);
|
sec->shdr.sh_name = elf_word_to_cpu(shdr.sh_name);
|
||||||
sec->shdr.sh_type = elf_word_to_cpu(shdr.sh_type);
|
sec->shdr.sh_type = elf_word_to_cpu(shdr.sh_type);
|
||||||
@@ -450,12 +453,12 @@ static void read_strtabs(FILE *fp)
|
|||||||
}
|
}
|
||||||
sec->strtab = malloc(sec->shdr.sh_size);
|
sec->strtab = malloc(sec->shdr.sh_size);
|
||||||
if (!sec->strtab) {
|
if (!sec->strtab) {
|
||||||
die("malloc of %d bytes for strtab failed\n",
|
die("malloc of %" FMT " bytes for strtab failed\n",
|
||||||
sec->shdr.sh_size);
|
sec->shdr.sh_size);
|
||||||
}
|
}
|
||||||
if (fseek(fp, sec->shdr.sh_offset, SEEK_SET) < 0) {
|
if (fseek(fp, sec->shdr.sh_offset, SEEK_SET) < 0) {
|
||||||
die("Seek to %d failed: %s\n",
|
die("Seek to %" FMT " failed: %s\n",
|
||||||
sec->shdr.sh_offset, strerror(errno));
|
sec->shdr.sh_offset, strerror(errno));
|
||||||
}
|
}
|
||||||
if (fread(sec->strtab, 1, sec->shdr.sh_size, fp)
|
if (fread(sec->strtab, 1, sec->shdr.sh_size, fp)
|
||||||
!= sec->shdr.sh_size) {
|
!= sec->shdr.sh_size) {
|
||||||
@@ -475,12 +478,12 @@ static void read_symtabs(FILE *fp)
|
|||||||
}
|
}
|
||||||
sec->symtab = malloc(sec->shdr.sh_size);
|
sec->symtab = malloc(sec->shdr.sh_size);
|
||||||
if (!sec->symtab) {
|
if (!sec->symtab) {
|
||||||
die("malloc of %d bytes for symtab failed\n",
|
die("malloc of %" FMT " bytes for symtab failed\n",
|
||||||
sec->shdr.sh_size);
|
sec->shdr.sh_size);
|
||||||
}
|
}
|
||||||
if (fseek(fp, sec->shdr.sh_offset, SEEK_SET) < 0) {
|
if (fseek(fp, sec->shdr.sh_offset, SEEK_SET) < 0) {
|
||||||
die("Seek to %d failed: %s\n",
|
die("Seek to %" FMT " failed: %s\n",
|
||||||
sec->shdr.sh_offset, strerror(errno));
|
sec->shdr.sh_offset, strerror(errno));
|
||||||
}
|
}
|
||||||
if (fread(sec->symtab, 1, sec->shdr.sh_size, fp)
|
if (fread(sec->symtab, 1, sec->shdr.sh_size, fp)
|
||||||
!= sec->shdr.sh_size) {
|
!= sec->shdr.sh_size) {
|
||||||
@@ -508,12 +511,12 @@ static void read_relocs(FILE *fp)
|
|||||||
}
|
}
|
||||||
sec->reltab = malloc(sec->shdr.sh_size);
|
sec->reltab = malloc(sec->shdr.sh_size);
|
||||||
if (!sec->reltab) {
|
if (!sec->reltab) {
|
||||||
die("malloc of %d bytes for relocs failed\n",
|
die("malloc of %" FMT " bytes for relocs failed\n",
|
||||||
sec->shdr.sh_size);
|
sec->shdr.sh_size);
|
||||||
}
|
}
|
||||||
if (fseek(fp, sec->shdr.sh_offset, SEEK_SET) < 0) {
|
if (fseek(fp, sec->shdr.sh_offset, SEEK_SET) < 0) {
|
||||||
die("Seek to %d failed: %s\n",
|
die("Seek to %" FMT " failed: %s\n",
|
||||||
sec->shdr.sh_offset, strerror(errno));
|
sec->shdr.sh_offset, strerror(errno));
|
||||||
}
|
}
|
||||||
if (fread(sec->reltab, 1, sec->shdr.sh_size, fp)
|
if (fread(sec->reltab, 1, sec->shdr.sh_size, fp)
|
||||||
!= sec->shdr.sh_size) {
|
!= sec->shdr.sh_size) {
|
||||||
|
@@ -17,6 +17,7 @@
|
|||||||
#include <regex.h>
|
#include <regex.h>
|
||||||
#include <tools/le_byteshift.h>
|
#include <tools/le_byteshift.h>
|
||||||
|
|
||||||
|
__attribute__((__format__(printf, 1, 2)))
|
||||||
void die(char *fmt, ...) __attribute__((noreturn));
|
void die(char *fmt, ...) __attribute__((noreturn));
|
||||||
|
|
||||||
#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
|
#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
|
||||||
|
Reference in New Issue
Block a user