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

TOMOYO Linux Cross Reference
Linux/arch/csky/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/csky/kernel/module.c (Version linux-6.12-rc7) and /arch/alpha/kernel/module.c (Version linux-4.16.18)


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

~ [ 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