1 /* Kernel dynamically loadable module help for PARISC.
3 * The best reference for this stuff is probably the Processor-
4 * Specific ELF Supplement for PA-RISC:
5 * http://ftp.parisc-linux.org/docs/arch/elf-pa-hp.pdf
7 * Linux/PA-RISC Project (http://www.parisc-linux.org/)
8 * Copyright (C) 2003 Randolph Chung <tausq at debian . org>
9 * Copyright (C) 2008 Helge Deller <deller@gmx.de>
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
29 * On 32bit (and sometimes 64bit) and with big kernel modules like xfs or
30 * ipv6 the relocation types R_PARISC_PCREL17F and R_PARISC_PCREL22F may
31 * fail to reach their PLT stub if we only create one big stub array for
32 * all sections at the beginning of the core or init section.
33 * Instead we now insert individual PLT stub entries directly in front of
34 * of the code sections where the stubs are actually called.
35 * This reduces the distance between the PCREL location and the stub entry
36 * so that the relocations can be fulfilled.
37 * While calculating the final layout of the kernel module in memory, the
38 * kernel module loader calls arch_mod_section_prepend() to request the
39 * to be reserved amount of memory in front of each individual section.
42 * We are not doing SEGREL32 handling correctly. According to the ABI, we
43 * should do a value offset, like this:
44 * if (in_init(me, (void *)val))
45 * val -= (uint32_t)me->module_init;
47 * val -= (uint32_t)me->module_core;
48 * However, SEGREL32 is used only for PARISC unwind entries, and we want
49 * those entries to have an absolute address, and not just an offset.
51 * The unwind table mechanism has the ability to specify an offset for
52 * the unwind table; however, because we split off the init functions into
53 * a different piece of memory, it is not possible to do this using a
54 * single offset. Instead, we use the above hack for now.
57 #include <linux/moduleloader.h>
58 #include <linux/elf.h>
59 #include <linux/vmalloc.h>
61 #include <linux/string.h>
62 #include <linux/kernel.h>
63 #include <linux/bug.h>
65 #include <linux/slab.h>
67 #include <asm/pgtable.h>
68 #include <asm/unwind.h>
73 #define DEBUGP(fmt...)
76 #define RELOC_REACHABLE(val, bits) \
77 (( ( !((val) & (1<<((bits)-1))) && ((val)>>(bits)) != 0 ) || \
78 ( ((val) & (1<<((bits)-1))) && ((val)>>(bits)) != (((__typeof__(val))(~0))>>((bits)+2)))) ? \
81 #define CHECK_RELOC(val, bits) \
82 if (!RELOC_REACHABLE(val, bits)) { \
83 printk(KERN_ERR "module %s relocation of symbol %s is out of range (0x%lx in %d bits)\n", \
84 me->name, strtab + sym->st_name, (unsigned long)val, bits); \
88 /* Maximum number of GOT entries. We use a long displacement ldd from
89 * the bottom of the table, which has a maximum signed displacement of
90 * 0x3fff; however, since we're only going forward, this becomes
91 * 0x1fff, and thus, since each GOT entry is 8 bytes long we can have
92 * at most 1023 entries.
93 * To overcome this 14bit displacement with some kernel modules, we'll
94 * use instead the unusal 16bit displacement method (see reassemble_16a)
95 * which gives us a maximum positive displacement of 0x7fff, and as such
96 * allows us to allocate up to 4095 GOT entries. */
99 /* three functions to determine where in the module core
100 * or init pieces the location is */
101 static inline int in_init(struct module
*me
, void *loc
)
103 return (loc
>= me
->module_init
&&
104 loc
<= (me
->module_init
+ me
->init_size
));
107 static inline int in_core(struct module
*me
, void *loc
)
109 return (loc
>= me
->module_core
&&
110 loc
<= (me
->module_core
+ me
->core_size
));
113 static inline int in_local(struct module
*me
, void *loc
)
115 return in_init(me
, loc
) || in_core(me
, loc
);
124 Elf32_Word insns
[2]; /* each stub entry has two insns */
132 Elf64_Word insns
[4]; /* each stub entry has four insns */
136 /* Field selection types defined by hppa */
137 #define rnd(x) (((x)+0x1000)&~0x1fff)
138 /* fsel: full 32 bits */
139 #define fsel(v,a) ((v)+(a))
140 /* lsel: select left 21 bits */
141 #define lsel(v,a) (((v)+(a))>>11)
142 /* rsel: select right 11 bits */
143 #define rsel(v,a) (((v)+(a))&0x7ff)
144 /* lrsel with rounding of addend to nearest 8k */
145 #define lrsel(v,a) (((v)+rnd(a))>>11)
146 /* rrsel with rounding of addend to nearest 8k */
147 #define rrsel(v,a) ((((v)+rnd(a))&0x7ff)+((a)-rnd(a)))
149 #define mask(x,sz) ((x) & ~((1<<(sz))-1))
152 /* The reassemble_* functions prepare an immediate value for
153 insertion into an opcode. pa-risc uses all sorts of weird bitfields
154 in the instruction to hold the value. */
155 static inline int sign_unext(int x
, int len
)
159 len_ones
= (1 << len
) - 1;
163 static inline int low_sign_unext(int x
, int len
)
167 sign
= (x
>> (len
-1)) & 1;
168 temp
= sign_unext(x
, len
-1);
169 return (temp
<< 1) | sign
;
172 static inline int reassemble_14(int as14
)
174 return (((as14
& 0x1fff) << 1) |
175 ((as14
& 0x2000) >> 13));
178 static inline int reassemble_16a(int as16
)
182 /* Unusual 16-bit encoding, for wide mode only. */
183 t
= (as16
<< 1) & 0xffff;
185 return (t
^ s
^ (s
>> 1)) | (s
>> 15);
189 static inline int reassemble_17(int as17
)
191 return (((as17
& 0x10000) >> 16) |
192 ((as17
& 0x0f800) << 5) |
193 ((as17
& 0x00400) >> 8) |
194 ((as17
& 0x003ff) << 3));
197 static inline int reassemble_21(int as21
)
199 return (((as21
& 0x100000) >> 20) |
200 ((as21
& 0x0ffe00) >> 8) |
201 ((as21
& 0x000180) << 7) |
202 ((as21
& 0x00007c) << 14) |
203 ((as21
& 0x000003) << 12));
206 static inline int reassemble_22(int as22
)
208 return (((as22
& 0x200000) >> 21) |
209 ((as22
& 0x1f0000) << 5) |
210 ((as22
& 0x00f800) << 5) |
211 ((as22
& 0x000400) >> 8) |
212 ((as22
& 0x0003ff) << 3));
215 void *module_alloc(unsigned long size
)
217 /* using RWX means less protection for modules, but it's
218 * easier than trying to map the text, data, init_text and
219 * init_data correctly */
220 return __vmalloc_node_range(size
, 1, VMALLOC_START
, VMALLOC_END
,
221 GFP_KERNEL
| __GFP_HIGHMEM
,
223 __builtin_return_address(0));
227 static inline unsigned long count_gots(const Elf_Rela
*rela
, unsigned long n
)
232 static inline unsigned long count_fdescs(const Elf_Rela
*rela
, unsigned long n
)
237 static inline unsigned long count_stubs(const Elf_Rela
*rela
, unsigned long n
)
239 unsigned long cnt
= 0;
241 for (; n
> 0; n
--, rela
++)
243 switch (ELF32_R_TYPE(rela
->r_info
)) {
244 case R_PARISC_PCREL17F
:
245 case R_PARISC_PCREL22F
:
253 static inline unsigned long count_gots(const Elf_Rela
*rela
, unsigned long n
)
255 unsigned long cnt
= 0;
257 for (; n
> 0; n
--, rela
++)
259 switch (ELF64_R_TYPE(rela
->r_info
)) {
260 case R_PARISC_LTOFF21L
:
261 case R_PARISC_LTOFF14R
:
262 case R_PARISC_PCREL22F
:
270 static inline unsigned long count_fdescs(const Elf_Rela
*rela
, unsigned long n
)
272 unsigned long cnt
= 0;
274 for (; n
> 0; n
--, rela
++)
276 switch (ELF64_R_TYPE(rela
->r_info
)) {
277 case R_PARISC_FPTR64
:
285 static inline unsigned long count_stubs(const Elf_Rela
*rela
, unsigned long n
)
287 unsigned long cnt
= 0;
289 for (; n
> 0; n
--, rela
++)
291 switch (ELF64_R_TYPE(rela
->r_info
)) {
292 case R_PARISC_PCREL22F
:
302 /* Free memory returned from module_alloc */
303 void module_free(struct module
*mod
, void *module_region
)
305 kfree(mod
->arch
.section
);
306 mod
->arch
.section
= NULL
;
308 vfree(module_region
);
311 /* Additional bytes needed in front of individual sections */
312 unsigned int arch_mod_section_prepend(struct module
*mod
,
313 unsigned int section
)
315 /* size needed for all stubs of this section (including
316 * one additional for correct alignment of the stubs) */
317 return (mod
->arch
.section
[section
].stub_entries
+ 1)
318 * sizeof(struct stub_entry
);
322 int module_frob_arch_sections(CONST Elf_Ehdr
*hdr
,
323 CONST Elf_Shdr
*sechdrs
,
324 CONST
char *secstrings
,
327 unsigned long gots
= 0, fdescs
= 0, len
;
330 len
= hdr
->e_shnum
* sizeof(me
->arch
.section
[0]);
331 me
->arch
.section
= kzalloc(len
, GFP_KERNEL
);
332 if (!me
->arch
.section
)
335 for (i
= 1; i
< hdr
->e_shnum
; i
++) {
336 const Elf_Rela
*rels
= (void *)sechdrs
[i
].sh_addr
;
337 unsigned long nrels
= sechdrs
[i
].sh_size
/ sizeof(*rels
);
338 unsigned int count
, s
;
340 if (strncmp(secstrings
+ sechdrs
[i
].sh_name
,
341 ".PARISC.unwind", 14) == 0)
342 me
->arch
.unwind_section
= i
;
344 if (sechdrs
[i
].sh_type
!= SHT_RELA
)
347 /* some of these are not relevant for 32-bit/64-bit
348 * we leave them here to make the code common. the
349 * compiler will do its thing and optimize out the
350 * stuff we don't need
352 gots
+= count_gots(rels
, nrels
);
353 fdescs
+= count_fdescs(rels
, nrels
);
355 /* XXX: By sorting the relocs and finding duplicate entries
356 * we could reduce the number of necessary stubs and save
358 count
= count_stubs(rels
, nrels
);
362 /* so we need relocation stubs. reserve necessary memory. */
363 /* sh_info gives the section for which we need to add stubs. */
364 s
= sechdrs
[i
].sh_info
;
366 /* each code section should only have one relocation section */
367 WARN_ON(me
->arch
.section
[s
].stub_entries
);
369 /* store number of stubs we need for this section */
370 me
->arch
.section
[s
].stub_entries
+= count
;
373 /* align things a bit */
374 me
->core_size
= ALIGN(me
->core_size
, 16);
375 me
->arch
.got_offset
= me
->core_size
;
376 me
->core_size
+= gots
* sizeof(struct got_entry
);
378 me
->core_size
= ALIGN(me
->core_size
, 16);
379 me
->arch
.fdesc_offset
= me
->core_size
;
380 me
->core_size
+= fdescs
* sizeof(Elf_Fdesc
);
382 me
->arch
.got_max
= gots
;
383 me
->arch
.fdesc_max
= fdescs
;
389 static Elf64_Word
get_got(struct module
*me
, unsigned long value
, long addend
)
392 struct got_entry
*got
;
398 got
= me
->module_core
+ me
->arch
.got_offset
;
399 for (i
= 0; got
[i
].addr
; i
++)
400 if (got
[i
].addr
== value
)
403 BUG_ON(++me
->arch
.got_count
> me
->arch
.got_max
);
407 DEBUGP("GOT ENTRY %d[%x] val %lx\n", i
, i
*sizeof(struct got_entry
),
409 return i
* sizeof(struct got_entry
);
411 #endif /* CONFIG_64BIT */
414 static Elf_Addr
get_fdesc(struct module
*me
, unsigned long value
)
416 Elf_Fdesc
*fdesc
= me
->module_core
+ me
->arch
.fdesc_offset
;
419 printk(KERN_ERR
"%s: zero OPD requested!\n", me
->name
);
423 /* Look for existing fdesc entry. */
424 while (fdesc
->addr
) {
425 if (fdesc
->addr
== value
)
426 return (Elf_Addr
)fdesc
;
430 BUG_ON(++me
->arch
.fdesc_count
> me
->arch
.fdesc_max
);
434 fdesc
->gp
= (Elf_Addr
)me
->module_core
+ me
->arch
.got_offset
;
435 return (Elf_Addr
)fdesc
;
437 #endif /* CONFIG_64BIT */
445 static Elf_Addr
get_stub(struct module
*me
, unsigned long value
, long addend
,
446 enum elf_stub_type stub_type
, Elf_Addr loc0
, unsigned int targetsec
)
448 struct stub_entry
*stub
;
449 int __maybe_unused d
;
451 /* initialize stub_offset to point in front of the section */
452 if (!me
->arch
.section
[targetsec
].stub_offset
) {
453 loc0
-= (me
->arch
.section
[targetsec
].stub_entries
+ 1) *
454 sizeof(struct stub_entry
);
455 /* get correct alignment for the stubs */
456 loc0
= ALIGN(loc0
, sizeof(struct stub_entry
));
457 me
->arch
.section
[targetsec
].stub_offset
= loc0
;
460 /* get address of stub entry */
461 stub
= (void *) me
->arch
.section
[targetsec
].stub_offset
;
462 me
->arch
.section
[targetsec
].stub_offset
+= sizeof(struct stub_entry
);
464 /* do not write outside available stub area */
465 BUG_ON(0 == me
->arch
.section
[targetsec
].stub_entries
--);
469 /* for 32-bit the stub looks like this:
471 * be,n R'XXX(%sr4,%r1)
473 //value = *(unsigned long *)((value + addend) & ~3); /* why? */
475 stub
->insns
[0] = 0x20200000; /* ldil L'XXX,%r1 */
476 stub
->insns
[1] = 0xe0202002; /* be,n R'XXX(%sr4,%r1) */
478 stub
->insns
[0] |= reassemble_21(lrsel(value
, addend
));
479 stub
->insns
[1] |= reassemble_17(rrsel(value
, addend
) / 4);
482 /* for 64-bit we have three kinds of stubs:
483 * for normal function calls:
495 * for direct branches (jumps between different section of the
503 d
= get_got(me
, value
, addend
);
506 stub
->insns
[0] = 0x0f6010db; /* ldd 0(%dp),%dp */
507 stub
->insns
[0] |= low_sign_unext(d
, 5) << 16;
510 stub
->insns
[0] = 0x537b0000; /* ldd 0(%dp),%dp */
511 stub
->insns
[0] |= reassemble_16a(d
);
513 stub
->insns
[1] = 0x53610020; /* ldd 10(%dp),%r1 */
514 stub
->insns
[2] = 0xe820d000; /* bve (%r1) */
515 stub
->insns
[3] = 0x537b0030; /* ldd 18(%dp),%dp */
518 stub
->insns
[0] = 0x20200000; /* ldil 0,%r1 */
519 stub
->insns
[1] = 0x34210000; /* ldo 0(%r1), %r1 */
520 stub
->insns
[2] = 0x50210020; /* ldd 10(%r1),%r1 */
521 stub
->insns
[3] = 0xe820d002; /* bve,n (%r1) */
523 stub
->insns
[0] |= reassemble_21(lrsel(value
, addend
));
524 stub
->insns
[1] |= reassemble_14(rrsel(value
, addend
));
526 case ELF_STUB_DIRECT
:
527 stub
->insns
[0] = 0x20200000; /* ldil 0,%r1 */
528 stub
->insns
[1] = 0x34210000; /* ldo 0(%r1), %r1 */
529 stub
->insns
[2] = 0xe820d002; /* bve,n (%r1) */
531 stub
->insns
[0] |= reassemble_21(lrsel(value
, addend
));
532 stub
->insns
[1] |= reassemble_14(rrsel(value
, addend
));
538 return (Elf_Addr
)stub
;
542 int apply_relocate_add(Elf_Shdr
*sechdrs
,
544 unsigned int symindex
,
549 Elf32_Rela
*rel
= (void *)sechdrs
[relsec
].sh_addr
;
556 unsigned int targetsec
= sechdrs
[relsec
].sh_info
;
557 //unsigned long dp = (unsigned long)$global$;
558 register unsigned long dp
asm ("r27");
560 DEBUGP("Applying relocate section %u to %u\n", relsec
,
562 for (i
= 0; i
< sechdrs
[relsec
].sh_size
/ sizeof(*rel
); i
++) {
563 /* This is where to make the change */
564 loc
= (void *)sechdrs
[targetsec
].sh_addr
566 /* This is the start of the target section */
567 loc0
= sechdrs
[targetsec
].sh_addr
;
568 /* This is the symbol it is referring to */
569 sym
= (Elf32_Sym
*)sechdrs
[symindex
].sh_addr
570 + ELF32_R_SYM(rel
[i
].r_info
);
571 if (!sym
->st_value
) {
572 printk(KERN_WARNING
"%s: Unknown symbol %s\n",
573 me
->name
, strtab
+ sym
->st_name
);
576 //dot = (sechdrs[relsec].sh_addr + rel->r_offset) & ~0x03;
577 dot
= (Elf32_Addr
)loc
& ~0x03;
580 addend
= rel
[i
].r_addend
;
583 #define r(t) ELF32_R_TYPE(rel[i].r_info)==t ? #t :
584 DEBUGP("Symbol %s loc 0x%x val 0x%x addend 0x%x: %s\n",
585 strtab
+ sym
->st_name
,
586 (uint32_t)loc
, val
, addend
,
600 switch (ELF32_R_TYPE(rel
[i
].r_info
)) {
601 case R_PARISC_PLABEL32
:
602 /* 32-bit function address */
603 /* no function descriptors... */
604 *loc
= fsel(val
, addend
);
607 /* direct 32-bit ref */
608 *loc
= fsel(val
, addend
);
610 case R_PARISC_DIR21L
:
611 /* left 21 bits of effective address */
612 val
= lrsel(val
, addend
);
613 *loc
= mask(*loc
, 21) | reassemble_21(val
);
615 case R_PARISC_DIR14R
:
616 /* right 14 bits of effective address */
617 val
= rrsel(val
, addend
);
618 *loc
= mask(*loc
, 14) | reassemble_14(val
);
620 case R_PARISC_SEGREL32
:
621 /* 32-bit segment relative address */
622 /* See note about special handling of SEGREL32 at
623 * the beginning of this file.
625 *loc
= fsel(val
, addend
);
627 case R_PARISC_DPREL21L
:
628 /* left 21 bit of relative address */
629 val
= lrsel(val
- dp
, addend
);
630 *loc
= mask(*loc
, 21) | reassemble_21(val
);
632 case R_PARISC_DPREL14R
:
633 /* right 14 bit of relative address */
634 val
= rrsel(val
- dp
, addend
);
635 *loc
= mask(*loc
, 14) | reassemble_14(val
);
637 case R_PARISC_PCREL17F
:
638 /* 17-bit PC relative address */
639 /* calculate direct call offset */
641 val
= (val
- dot
- 8)/4;
642 if (!RELOC_REACHABLE(val
, 17)) {
643 /* direct distance too far, create
644 * stub entry instead */
645 val
= get_stub(me
, sym
->st_value
, addend
,
646 ELF_STUB_DIRECT
, loc0
, targetsec
);
647 val
= (val
- dot
- 8)/4;
648 CHECK_RELOC(val
, 17);
650 *loc
= (*loc
& ~0x1f1ffd) | reassemble_17(val
);
652 case R_PARISC_PCREL22F
:
653 /* 22-bit PC relative address; only defined for pa20 */
654 /* calculate direct call offset */
656 val
= (val
- dot
- 8)/4;
657 if (!RELOC_REACHABLE(val
, 22)) {
658 /* direct distance too far, create
659 * stub entry instead */
660 val
= get_stub(me
, sym
->st_value
, addend
,
661 ELF_STUB_DIRECT
, loc0
, targetsec
);
662 val
= (val
- dot
- 8)/4;
663 CHECK_RELOC(val
, 22);
665 *loc
= (*loc
& ~0x3ff1ffd) | reassemble_22(val
);
669 printk(KERN_ERR
"module %s: Unknown relocation: %u\n",
670 me
->name
, ELF32_R_TYPE(rel
[i
].r_info
));
679 int apply_relocate_add(Elf_Shdr
*sechdrs
,
681 unsigned int symindex
,
686 Elf64_Rela
*rel
= (void *)sechdrs
[relsec
].sh_addr
;
694 unsigned int targetsec
= sechdrs
[relsec
].sh_info
;
696 DEBUGP("Applying relocate section %u to %u\n", relsec
,
698 for (i
= 0; i
< sechdrs
[relsec
].sh_size
/ sizeof(*rel
); i
++) {
699 /* This is where to make the change */
700 loc
= (void *)sechdrs
[targetsec
].sh_addr
702 /* This is the start of the target section */
703 loc0
= sechdrs
[targetsec
].sh_addr
;
704 /* This is the symbol it is referring to */
705 sym
= (Elf64_Sym
*)sechdrs
[symindex
].sh_addr
706 + ELF64_R_SYM(rel
[i
].r_info
);
707 if (!sym
->st_value
) {
708 printk(KERN_WARNING
"%s: Unknown symbol %s\n",
709 me
->name
, strtab
+ sym
->st_name
);
712 //dot = (sechdrs[relsec].sh_addr + rel->r_offset) & ~0x03;
713 dot
= (Elf64_Addr
)loc
& ~0x03;
714 loc64
= (Elf64_Xword
*)loc
;
717 addend
= rel
[i
].r_addend
;
720 #define r(t) ELF64_R_TYPE(rel[i].r_info)==t ? #t :
721 printk("Symbol %s loc %p val 0x%Lx addend 0x%Lx: %s\n",
722 strtab
+ sym
->st_name
,
734 switch (ELF64_R_TYPE(rel
[i
].r_info
)) {
735 case R_PARISC_LTOFF21L
:
736 /* LT-relative; left 21 bits */
737 val
= get_got(me
, val
, addend
);
738 DEBUGP("LTOFF21L Symbol %s loc %p val %lx\n",
739 strtab
+ sym
->st_name
,
742 *loc
= mask(*loc
, 21) | reassemble_21(val
);
744 case R_PARISC_LTOFF14R
:
745 /* L(ltoff(val+addend)) */
746 /* LT-relative; right 14 bits */
747 val
= get_got(me
, val
, addend
);
749 DEBUGP("LTOFF14R Symbol %s loc %p val %lx\n",
750 strtab
+ sym
->st_name
,
752 *loc
= mask(*loc
, 14) | reassemble_14(val
);
754 case R_PARISC_PCREL22F
:
755 /* PC-relative; 22 bits */
756 DEBUGP("PCREL22F Symbol %s loc %p val %lx\n",
757 strtab
+ sym
->st_name
,
760 /* can we reach it locally? */
761 if (in_local(me
, (void *)val
)) {
762 /* this is the case where the symbol is local
763 * to the module, but in a different section,
764 * so stub the jump in case it's more than 22
766 val
= (val
- dot
- 8)/4;
767 if (!RELOC_REACHABLE(val
, 22)) {
768 /* direct distance too far, create
769 * stub entry instead */
770 val
= get_stub(me
, sym
->st_value
,
771 addend
, ELF_STUB_DIRECT
,
774 /* Ok, we can reach it directly. */
780 if (strncmp(strtab
+ sym
->st_name
, "$$", 2)
782 val
= get_stub(me
, val
, addend
, ELF_STUB_MILLI
,
785 val
= get_stub(me
, val
, addend
, ELF_STUB_GOT
,
788 DEBUGP("STUB FOR %s loc %lx, val %lx+%lx at %lx\n",
789 strtab
+ sym
->st_name
, loc
, sym
->st_value
,
791 val
= (val
- dot
- 8)/4;
792 CHECK_RELOC(val
, 22);
793 *loc
= (*loc
& ~0x3ff1ffd) | reassemble_22(val
);
796 /* 64-bit effective address */
797 *loc64
= val
+ addend
;
799 case R_PARISC_SEGREL32
:
800 /* 32-bit segment relative address */
801 /* See note about special handling of SEGREL32 at
802 * the beginning of this file.
804 *loc
= fsel(val
, addend
);
806 case R_PARISC_FPTR64
:
807 /* 64-bit function address */
808 if(in_local(me
, (void *)(val
+ addend
))) {
809 *loc64
= get_fdesc(me
, val
+addend
);
810 DEBUGP("FDESC for %s at %p points to %lx\n",
811 strtab
+ sym
->st_name
, *loc64
,
812 ((Elf_Fdesc
*)*loc64
)->addr
);
814 /* if the symbol is not local to this
815 * module then val+addend is a pointer
816 * to the function descriptor */
817 DEBUGP("Non local FPTR64 Symbol %s loc %p val %lx\n",
818 strtab
+ sym
->st_name
,
820 *loc64
= val
+ addend
;
825 printk(KERN_ERR
"module %s: Unknown relocation: %Lu\n",
826 me
->name
, ELF64_R_TYPE(rel
[i
].r_info
));
835 register_unwind_table(struct module
*me
,
836 const Elf_Shdr
*sechdrs
)
838 unsigned char *table
, *end
;
841 if (!me
->arch
.unwind_section
)
844 table
= (unsigned char *)sechdrs
[me
->arch
.unwind_section
].sh_addr
;
845 end
= table
+ sechdrs
[me
->arch
.unwind_section
].sh_size
;
846 gp
= (Elf_Addr
)me
->module_core
+ me
->arch
.got_offset
;
848 DEBUGP("register_unwind_table(), sect = %d at 0x%p - 0x%p (gp=0x%lx)\n",
849 me
->arch
.unwind_section
, table
, end
, gp
);
850 me
->arch
.unwind
= unwind_table_add(me
->name
, 0, gp
, table
, end
);
854 deregister_unwind_table(struct module
*me
)
857 unwind_table_remove(me
->arch
.unwind
);
860 int module_finalize(const Elf_Ehdr
*hdr
,
861 const Elf_Shdr
*sechdrs
,
866 const char *strtab
= NULL
;
867 Elf_Sym
*newptr
, *oldptr
;
868 Elf_Shdr
*symhdr
= NULL
;
873 entry
= (Elf_Fdesc
*)me
->init
;
874 printk("FINALIZE, ->init FPTR is %p, GP %lx ADDR %lx\n", entry
,
875 entry
->gp
, entry
->addr
);
876 addr
= (u32
*)entry
->addr
;
877 printk("INSNS: %x %x %x %x\n",
878 addr
[0], addr
[1], addr
[2], addr
[3]);
879 printk("got entries used %ld, gots max %ld\n"
880 "fdescs used %ld, fdescs max %ld\n",
881 me
->arch
.got_count
, me
->arch
.got_max
,
882 me
->arch
.fdesc_count
, me
->arch
.fdesc_max
);
885 register_unwind_table(me
, sechdrs
);
887 /* haven't filled in me->symtab yet, so have to find it
889 for (i
= 1; i
< hdr
->e_shnum
; i
++) {
890 if(sechdrs
[i
].sh_type
== SHT_SYMTAB
891 && (sechdrs
[i
].sh_flags
& SHF_ALLOC
)) {
892 int strindex
= sechdrs
[i
].sh_link
;
894 * The cast is to drop the const from
895 * the sechdrs pointer */
896 symhdr
= (Elf_Shdr
*)&sechdrs
[i
];
897 strtab
= (char *)sechdrs
[strindex
].sh_addr
;
902 DEBUGP("module %s: strtab %p, symhdr %p\n",
903 me
->name
, strtab
, symhdr
);
905 if(me
->arch
.got_count
> MAX_GOTS
) {
906 printk(KERN_ERR
"%s: Global Offset Table overflow (used %ld, allowed %d)\n",
907 me
->name
, me
->arch
.got_count
, MAX_GOTS
);
911 kfree(me
->arch
.section
);
912 me
->arch
.section
= NULL
;
914 /* no symbol table */
918 oldptr
= (void *)symhdr
->sh_addr
;
919 newptr
= oldptr
+ 1; /* we start counting at 1 */
920 nsyms
= symhdr
->sh_size
/ sizeof(Elf_Sym
);
921 DEBUGP("OLD num_symtab %lu\n", nsyms
);
923 for (i
= 1; i
< nsyms
; i
++) {
924 oldptr
++; /* note, count starts at 1 so preincrement */
925 if(strncmp(strtab
+ oldptr
->st_name
,
935 nsyms
= newptr
- (Elf_Sym
*)symhdr
->sh_addr
;
936 DEBUGP("NEW num_symtab %lu\n", nsyms
);
937 symhdr
->sh_size
= nsyms
* sizeof(Elf_Sym
);
941 void module_arch_cleanup(struct module
*mod
)
943 deregister_unwind_table(mod
);