Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) // SPDX-License-Identifier: GPL-2.0-or-later
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) /*  Kernel module help for Alpha.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)     Copyright (C) 2002 Richard Henderson.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6) #include <linux/moduleloader.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7) #include <linux/elf.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8) #include <linux/vmalloc.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9) #include <linux/fs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) #include <linux/string.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) #if 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) #define DEBUGP printk
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) #define DEBUGP(fmt...)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) /* Allocate the GOT at the end of the core sections.  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) struct got_entry {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) 	struct got_entry *next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) 	Elf64_Sxword r_addend;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) 	int got_offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) static inline void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) process_reloc_for_got(Elf64_Rela *rela,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) 		      struct got_entry *chains, Elf64_Xword *poffset)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) 	unsigned long r_sym = ELF64_R_SYM (rela->r_info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) 	unsigned long r_type = ELF64_R_TYPE (rela->r_info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) 	Elf64_Sxword r_addend = rela->r_addend;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) 	struct got_entry *g;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) 	if (r_type != R_ALPHA_LITERAL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) 	for (g = chains + r_sym; g ; g = g->next)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 		if (g->r_addend == r_addend) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 			if (g->got_offset == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) 				g->got_offset = *poffset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 				*poffset += 8;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 			goto found_entry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 	g = kmalloc (sizeof (*g), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 	g->next = chains[r_sym].next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 	g->r_addend = r_addend;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 	g->got_offset = *poffset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 	*poffset += 8;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 	chains[r_sym].next = g;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56)  found_entry:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 	/* Trick: most of the ELF64_R_TYPE field is unused.  There are
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 	   42 valid relocation types, and a 32-bit field.  Co-opt the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 	   bits above 256 to store the got offset for this reloc.  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 	rela->r_info |= g->got_offset << 8;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) module_frob_arch_sections(Elf64_Ehdr *hdr, Elf64_Shdr *sechdrs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 			  char *secstrings, struct module *me)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 	struct got_entry *chains;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 	Elf64_Rela *rela;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 	Elf64_Shdr *esechdrs, *symtab, *s, *got;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 	unsigned long nsyms, nrela, i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 	esechdrs = sechdrs + hdr->e_shnum;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 	symtab = got = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 	/* Find out how large the symbol table is.  Allocate one got_entry
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 	   head per symbol.  Normally this will be enough, but not always.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 	   We'll chain different offsets for the symbol down each head.  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 	for (s = sechdrs; s < esechdrs; ++s)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 		if (s->sh_type == SHT_SYMTAB)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 			symtab = s;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 		else if (!strcmp(".got", secstrings + s->sh_name)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 			got = s;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 			me->arch.gotsecindex = s - sechdrs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 	if (!symtab) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 		printk(KERN_ERR "module %s: no symbol table\n", me->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 		return -ENOEXEC;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 	if (!got) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 		printk(KERN_ERR "module %s: no got section\n", me->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 		return -ENOEXEC;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 	nsyms = symtab->sh_size / sizeof(Elf64_Sym);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 	chains = kcalloc(nsyms, sizeof(struct got_entry), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 	if (!chains) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 		printk(KERN_ERR
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 		       "module %s: no memory for symbol chain buffer\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 		       me->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 	got->sh_size = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 	got->sh_addralign = 8;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 	got->sh_type = SHT_NOBITS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 	/* Examine all LITERAL relocations to find out what GOT entries
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 	   are required.  This sizes the GOT section as well.  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 	for (s = sechdrs; s < esechdrs; ++s)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 		if (s->sh_type == SHT_RELA) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 			nrela = s->sh_size / sizeof(Elf64_Rela);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 			rela = (void *)hdr + s->sh_offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 			for (i = 0; i < nrela; ++i)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 				process_reloc_for_got(rela+i, chains,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 						      &got->sh_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 	/* Free the memory we allocated.  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 	for (i = 0; i < nsyms; ++i) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 		struct got_entry *g, *n;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 		for (g = chains[i].next; g ; g = n) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 			n = g->next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 			kfree(g);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 	kfree(chains);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) apply_relocate_add(Elf64_Shdr *sechdrs, const char *strtab,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 		   unsigned int symindex, unsigned int relsec,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 		   struct module *me)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 	Elf64_Rela *rela = (void *)sechdrs[relsec].sh_addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 	unsigned long i, n = sechdrs[relsec].sh_size / sizeof(*rela);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 	Elf64_Sym *symtab, *sym;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 	void *base, *location;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 	unsigned long got, gp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 	DEBUGP("Applying relocate section %u to %u\n", relsec,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 	       sechdrs[relsec].sh_info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 	base = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 	symtab = (Elf64_Sym *)sechdrs[symindex].sh_addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 	/* The small sections were sorted to the end of the segment.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 	   The following should definitely cover them.  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 	gp = (u64)me->core_layout.base + me->core_layout.size - 0x8000;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 	got = sechdrs[me->arch.gotsecindex].sh_addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 	for (i = 0; i < n; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 		unsigned long r_sym = ELF64_R_SYM (rela[i].r_info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 		unsigned long r_type = ELF64_R_TYPE (rela[i].r_info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 		unsigned long r_got_offset = r_type >> 8;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 		unsigned long value, hi, lo;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 		r_type &= 0xff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 		/* This is where to make the change.  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 		location = base + rela[i].r_offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 		/* This is the symbol it is referring to.  Note that all
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 		   unresolved symbols have been resolved.  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 		sym = symtab + r_sym;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 		value = sym->st_value + rela[i].r_addend;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 		switch (r_type) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 		case R_ALPHA_NONE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 		case R_ALPHA_REFLONG:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 			*(u32 *)location = value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 		case R_ALPHA_REFQUAD:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 			/* BUG() can produce misaligned relocations. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 			((u32 *)location)[0] = value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) 			((u32 *)location)[1] = value >> 32;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 		case R_ALPHA_GPREL32:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) 			value -= gp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 			if ((int)value != value)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) 				goto reloc_overflow;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) 			*(u32 *)location = value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) 		case R_ALPHA_LITERAL:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 			hi = got + r_got_offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 			lo = hi - gp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 			if ((short)lo != lo)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 				goto reloc_overflow;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) 			*(u16 *)location = lo;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 			*(u64 *)hi = value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) 		case R_ALPHA_LITUSE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) 		case R_ALPHA_GPDISP:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 			value = gp - (u64)location;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) 			lo = (short)value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) 			hi = (int)(value - lo);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) 			if (hi + lo != value)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) 				goto reloc_overflow;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 			*(u16 *)location = hi >> 16;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) 			*(u16 *)(location + rela[i].r_addend) = lo;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) 		case R_ALPHA_BRSGP:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) 			/* BRSGP is only allowed to bind to local symbols.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) 			   If the section is undef, this means that the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) 			   value was resolved from somewhere else.  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) 			if (sym->st_shndx == SHN_UNDEF)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) 				goto reloc_overflow;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) 			if ((sym->st_other & STO_ALPHA_STD_GPLOAD) ==
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) 			    STO_ALPHA_STD_GPLOAD)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) 				/* Omit the prologue. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) 				value += 8;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) 			fallthrough;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) 		case R_ALPHA_BRADDR:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) 			value -= (u64)location + 4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) 			if (value & 3)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) 				goto reloc_overflow;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) 			value = (long)value >> 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) 			if (value + (1<<21) >= 1<<22)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) 				goto reloc_overflow;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) 			value &= 0x1fffff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 			value |= *(u32 *)location & ~0x1fffff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) 			*(u32 *)location = value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 		case R_ALPHA_HINT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 		case R_ALPHA_SREL32:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) 			value -= (u64)location;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) 			if ((int)value != value)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) 				goto reloc_overflow;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) 			*(u32 *)location = value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) 		case R_ALPHA_SREL64:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) 			value -= (u64)location;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) 			*(u64 *)location = value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) 		case R_ALPHA_GPRELHIGH:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) 			value = (long)(value - gp + 0x8000) >> 16;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) 			if ((short) value != value)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) 				goto reloc_overflow;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) 			*(u16 *)location = value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) 		case R_ALPHA_GPRELLOW:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) 			value -= gp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) 			*(u16 *)location = value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) 		case R_ALPHA_GPREL16:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) 			value -= gp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) 			if ((short) value != value)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) 				goto reloc_overflow;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) 			*(u16 *)location = value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) 		default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) 			printk(KERN_ERR "module %s: Unknown relocation: %lu\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) 			       me->name, r_type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) 			return -ENOEXEC;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) 		reloc_overflow:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) 			if (ELF64_ST_TYPE (sym->st_info) == STT_SECTION)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) 			  printk(KERN_ERR
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) 			         "module %s: Relocation (type %lu) overflow vs section %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) 			         me->name, r_type, sym->st_shndx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) 			else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) 			  printk(KERN_ERR
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) 			         "module %s: Relocation (type %lu) overflow vs %s\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) 			         me->name, r_type, strtab + sym->st_name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) 			return -ENOEXEC;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) }