mirror of
				https://github.com/torvalds/linux.git
				synced 2025-11-03 18:20:25 +02:00 
			
		
		
		
	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>
		
			
				
	
	
		
			32 lines
		
	
	
	
		
			604 B
		
	
	
	
		
			C
		
	
	
	
	
	
			
		
		
	
	
			32 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;
 | 
						|
}
 |