mirror of
https://github.com/torvalds/linux.git
synced 2024-11-10 06:01:57 +00:00
a660deb0f1
Endianness is currently detected on compile-time, but we can defer this until run-time. This change avoids re-executing scripts/mod/mk_elfconfig even if modpost in the linux-headers package needs to be rebuilt for a foreign architecture. Signed-off-by: Masahiro Yamada <masahiroy@kernel.org> Reviewed-by: Nicolas Schier <nicolas@fjasle.eu>
33 lines
604 B
C
33 lines
604 B
C
// SPDX-License-Identifier: GPL-2.0
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
#include <elf.h>
|
|
|
|
int
|
|
main(int argc, char **argv)
|
|
{
|
|
unsigned char ei[EI_NIDENT];
|
|
|
|
if (fread(ei, 1, EI_NIDENT, stdin) != EI_NIDENT) {
|
|
fprintf(stderr, "Error: input truncated\n");
|
|
return 1;
|
|
}
|
|
if (memcmp(ei, ELFMAG, SELFMAG) != 0) {
|
|
fprintf(stderr, "Error: not ELF\n");
|
|
return 1;
|
|
}
|
|
switch (ei[EI_CLASS]) {
|
|
case ELFCLASS32:
|
|
printf("#define KERNEL_ELFCLASS ELFCLASS32\n");
|
|
break;
|
|
case ELFCLASS64:
|
|
printf("#define KERNEL_ELFCLASS ELFCLASS64\n");
|
|
break;
|
|
default:
|
|
exit(1);
|
|
}
|
|
|
|
return 0;
|
|
}
|