~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/arch/hexagon/kernel/module.c

Version: ~ [ linux-6.12-rc7 ] ~ [ linux-6.11.7 ] ~ [ linux-6.10.14 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.60 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.116 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.171 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.229 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.285 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.323 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.336 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.4.302 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.12 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

Diff markup

Differences between /arch/hexagon/kernel/module.c (Version linux-6.12-rc7) and /arch/alpha/kernel/module.c (Version linux-5.12.19)


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

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

sflogo.php