mk_elfconfig.c 604 B

1234567891011121314151617181920212223242526272829303132
  1. // SPDX-License-Identifier: GPL-2.0
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4. #include <string.h>
  5. #include <elf.h>
  6. int
  7. main(int argc, char **argv)
  8. {
  9. unsigned char ei[EI_NIDENT];
  10. if (fread(ei, 1, EI_NIDENT, stdin) != EI_NIDENT) {
  11. fprintf(stderr, "Error: input truncated\n");
  12. return 1;
  13. }
  14. if (memcmp(ei, ELFMAG, SELFMAG) != 0) {
  15. fprintf(stderr, "Error: not ELF\n");
  16. return 1;
  17. }
  18. switch (ei[EI_CLASS]) {
  19. case ELFCLASS32:
  20. printf("#define KERNEL_ELFCLASS ELFCLASS32\n");
  21. break;
  22. case ELFCLASS64:
  23. printf("#define KERNEL_ELFCLASS ELFCLASS64\n");
  24. break;
  25. default:
  26. exit(1);
  27. }
  28. return 0;
  29. }