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>
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
28 * We are not doing SEGREL32 handling correctly. According to the ABI, we
29 * should do a value offset, like this:
30 * if (in_init(me, (void *)val))
31 * val -= (uint32_t)me->module_init;
33 * val -= (uint32_t)me->module_core;
34 * However, SEGREL32 is used only for PARISC unwind entries, and we want
35 * those entries to have an absolute address, and not just an offset.
37 * The unwind table mechanism has the ability to specify an offset for
38 * the unwind table; however, because we split off the init functions into
39 * a different piece of memory, it is not possible to do this using a
40 * single offset. Instead, we use the above hack for now.
43 #include <linux/moduleloader.h>
44 #include <linux/elf.h>
45 #include <linux/vmalloc.h>
47 #include <linux/string.h>
48 #include <linux/kernel.h>
49 #include <linux/bug.h>
50 #include <linux/uaccess.h>
52 #include <asm/sections.h>
53 #include <asm/unwind.h>
58 #define DEBUGP(fmt...)
61 #define CHECK_RELOC(val, bits) \
62 if ( ( !((val) & (1<<((bits)-1))) && ((val)>>(bits)) != 0 ) || \
63 ( ((val) & (1<<((bits)-1))) && ((val)>>(bits)) != (((__typeof__(val))(~0))>>((bits)+2)))) { \
64 printk(KERN_ERR "module %s relocation of symbol %s is out of range (0x%lx in %d bits)\n", \
65 me->name, strtab + sym->st_name, (unsigned long)val, bits); \
69 /* Maximum number of GOT entries. We use a long displacement ldd from
70 * the bottom of the table, which has a maximum signed displacement of
71 * 0x3fff; however, since we're only going forward, this becomes
72 * 0x1fff, and thus, since each GOT entry is 8 bytes long we can have
73 * at most 1023 entries */
76 /* three functions to determine where in the module core
77 * or init pieces the location is */
78 static inline int in_init(struct module
*me
, void *loc
)
80 return (loc
>= me
->module_init
&&
81 loc
<= (me
->module_init
+ me
->init_size
));
84 static inline int in_core(struct module
*me
, void *loc
)
86 return (loc
>= me
->module_core
&&
87 loc
<= (me
->module_core
+ me
->core_size
));
90 static inline int in_local(struct module
*me
, void *loc
)
92 return in_init(me
, loc
) || in_core(me
, loc
);
95 static inline int in_local_section(struct module
*me
, void *loc
, void *dot
)
97 return (in_init(me
, loc
) && in_init(me
, dot
)) ||
98 (in_core(me
, loc
) && in_core(me
, dot
));
107 #define Elf_Fdesc Elf32_Fdesc
110 Elf32_Word insns
[2]; /* each stub entry has two insns */
117 #define Elf_Fdesc Elf64_Fdesc
120 Elf64_Word insns
[4]; /* each stub entry has four insns */
124 /* Field selection types defined by hppa */
125 #define rnd(x) (((x)+0x1000)&~0x1fff)
126 /* fsel: full 32 bits */
127 #define fsel(v,a) ((v)+(a))
128 /* lsel: select left 21 bits */
129 #define lsel(v,a) (((v)+(a))>>11)
130 /* rsel: select right 11 bits */
131 #define rsel(v,a) (((v)+(a))&0x7ff)
132 /* lrsel with rounding of addend to nearest 8k */
133 #define lrsel(v,a) (((v)+rnd(a))>>11)
134 /* rrsel with rounding of addend to nearest 8k */
135 #define rrsel(v,a) ((((v)+rnd(a))&0x7ff)+((a)-rnd(a)))
137 #define mask(x,sz) ((x) & ~((1<<(sz))-1))
140 /* The reassemble_* functions prepare an immediate value for
141 insertion into an opcode. pa-risc uses all sorts of weird bitfields
142 in the instruction to hold the value. */
143 static inline int reassemble_14(int as14
)
145 return (((as14
& 0x1fff) << 1) |
146 ((as14
& 0x2000) >> 13));
149 static inline int reassemble_17(int as17
)
151 return (((as17
& 0x10000) >> 16) |
152 ((as17
& 0x0f800) << 5) |
153 ((as17
& 0x00400) >> 8) |
154 ((as17
& 0x003ff) << 3));
157 static inline int reassemble_21(int as21
)
159 return (((as21
& 0x100000) >> 20) |
160 ((as21
& 0x0ffe00) >> 8) |
161 ((as21
& 0x000180) << 7) |
162 ((as21
& 0x00007c) << 14) |
163 ((as21
& 0x000003) << 12));
166 static inline int reassemble_22(int as22
)
168 return (((as22
& 0x200000) >> 21) |
169 ((as22
& 0x1f0000) << 5) |
170 ((as22
& 0x00f800) << 5) |
171 ((as22
& 0x000400) >> 8) |
172 ((as22
& 0x0003ff) << 3));
175 void *module_alloc(unsigned long size
)
179 return vmalloc(size
);
183 static inline unsigned long count_gots(const Elf_Rela
*rela
, unsigned long n
)
188 static inline unsigned long count_fdescs(const Elf_Rela
*rela
, unsigned long n
)
193 static inline unsigned long count_stubs(const Elf_Rela
*rela
, unsigned long n
)
195 unsigned long cnt
= 0;
197 for (; n
> 0; n
--, rela
++)
199 switch (ELF32_R_TYPE(rela
->r_info
)) {
200 case R_PARISC_PCREL17F
:
201 case R_PARISC_PCREL22F
:
209 static inline unsigned long count_gots(const Elf_Rela
*rela
, unsigned long n
)
211 unsigned long cnt
= 0;
213 for (; n
> 0; n
--, rela
++)
215 switch (ELF64_R_TYPE(rela
->r_info
)) {
216 case R_PARISC_LTOFF21L
:
217 case R_PARISC_LTOFF14R
:
218 case R_PARISC_PCREL22F
:
226 static inline unsigned long count_fdescs(const Elf_Rela
*rela
, unsigned long n
)
228 unsigned long cnt
= 0;
230 for (; n
> 0; n
--, rela
++)
232 switch (ELF64_R_TYPE(rela
->r_info
)) {
233 case R_PARISC_FPTR64
:
241 static inline unsigned long count_stubs(const Elf_Rela
*rela
, unsigned long n
)
243 unsigned long cnt
= 0;
245 for (; n
> 0; n
--, rela
++)
247 switch (ELF64_R_TYPE(rela
->r_info
)) {
248 case R_PARISC_PCREL22F
:
258 /* Free memory returned from module_alloc */
259 void module_free(struct module
*mod
, void *module_region
)
261 vfree(module_region
);
262 /* FIXME: If module_region == mod->init_region, trim exception
267 int module_frob_arch_sections(CONST Elf_Ehdr
*hdr
,
268 CONST Elf_Shdr
*sechdrs
,
269 CONST
char *secstrings
,
272 unsigned long gots
= 0, fdescs
= 0, stubs
= 0, init_stubs
= 0;
275 for (i
= 1; i
< hdr
->e_shnum
; i
++) {
276 const Elf_Rela
*rels
= (void *)hdr
+ sechdrs
[i
].sh_offset
;
277 unsigned long nrels
= sechdrs
[i
].sh_size
/ sizeof(*rels
);
279 if (strncmp(secstrings
+ sechdrs
[i
].sh_name
,
280 ".PARISC.unwind", 14) == 0)
281 me
->arch
.unwind_section
= i
;
283 if (sechdrs
[i
].sh_type
!= SHT_RELA
)
286 /* some of these are not relevant for 32-bit/64-bit
287 * we leave them here to make the code common. the
288 * compiler will do its thing and optimize out the
289 * stuff we don't need
291 gots
+= count_gots(rels
, nrels
);
292 fdescs
+= count_fdescs(rels
, nrels
);
293 if(strncmp(secstrings
+ sechdrs
[i
].sh_name
,
294 ".rela.init", 10) == 0)
295 init_stubs
+= count_stubs(rels
, nrels
);
297 stubs
+= count_stubs(rels
, nrels
);
300 /* align things a bit */
301 me
->core_size
= ALIGN(me
->core_size
, 16);
302 me
->arch
.got_offset
= me
->core_size
;
303 me
->core_size
+= gots
* sizeof(struct got_entry
);
305 me
->core_size
= ALIGN(me
->core_size
, 16);
306 me
->arch
.fdesc_offset
= me
->core_size
;
307 me
->core_size
+= fdescs
* sizeof(Elf_Fdesc
);
309 me
->core_size
= ALIGN(me
->core_size
, 16);
310 me
->arch
.stub_offset
= me
->core_size
;
311 me
->core_size
+= stubs
* sizeof(struct stub_entry
);
313 me
->init_size
= ALIGN(me
->init_size
, 16);
314 me
->arch
.init_stub_offset
= me
->init_size
;
315 me
->init_size
+= init_stubs
* sizeof(struct stub_entry
);
317 me
->arch
.got_max
= gots
;
318 me
->arch
.fdesc_max
= fdescs
;
319 me
->arch
.stub_max
= stubs
;
320 me
->arch
.init_stub_max
= init_stubs
;
326 static Elf64_Word
get_got(struct module
*me
, unsigned long value
, long addend
)
329 struct got_entry
*got
;
335 got
= me
->module_core
+ me
->arch
.got_offset
;
336 for (i
= 0; got
[i
].addr
; i
++)
337 if (got
[i
].addr
== value
)
340 BUG_ON(++me
->arch
.got_count
> me
->arch
.got_max
);
344 DEBUGP("GOT ENTRY %d[%x] val %lx\n", i
, i
*sizeof(struct got_entry
),
346 return i
* sizeof(struct got_entry
);
348 #endif /* CONFIG_64BIT */
351 static Elf_Addr
get_fdesc(struct module
*me
, unsigned long value
)
353 Elf_Fdesc
*fdesc
= me
->module_core
+ me
->arch
.fdesc_offset
;
356 printk(KERN_ERR
"%s: zero OPD requested!\n", me
->name
);
360 /* Look for existing fdesc entry. */
361 while (fdesc
->addr
) {
362 if (fdesc
->addr
== value
)
363 return (Elf_Addr
)fdesc
;
367 BUG_ON(++me
->arch
.fdesc_count
> me
->arch
.fdesc_max
);
371 fdesc
->gp
= (Elf_Addr
)me
->module_core
+ me
->arch
.got_offset
;
372 return (Elf_Addr
)fdesc
;
374 #endif /* CONFIG_64BIT */
382 static Elf_Addr
get_stub(struct module
*me
, unsigned long value
, long addend
,
383 enum elf_stub_type stub_type
, int init_section
)
386 struct stub_entry
*stub
;
389 i
= me
->arch
.init_stub_count
++;
390 BUG_ON(me
->arch
.init_stub_count
> me
->arch
.init_stub_max
);
391 stub
= me
->module_init
+ me
->arch
.init_stub_offset
+
392 i
* sizeof(struct stub_entry
);
394 i
= me
->arch
.stub_count
++;
395 BUG_ON(me
->arch
.stub_count
> me
->arch
.stub_max
);
396 stub
= me
->module_core
+ me
->arch
.stub_offset
+
397 i
* sizeof(struct stub_entry
);
401 /* for 32-bit the stub looks like this:
403 * be,n R'XXX(%sr4,%r1)
405 //value = *(unsigned long *)((value + addend) & ~3); /* why? */
407 stub
->insns
[0] = 0x20200000; /* ldil L'XXX,%r1 */
408 stub
->insns
[1] = 0xe0202002; /* be,n R'XXX(%sr4,%r1) */
410 stub
->insns
[0] |= reassemble_21(lrsel(value
, addend
));
411 stub
->insns
[1] |= reassemble_17(rrsel(value
, addend
) / 4);
414 /* for 64-bit we have three kinds of stubs:
415 * for normal function calls:
427 * for direct branches (jumps between different section of the
435 stub
->insns
[0] = 0x537b0000; /* ldd 0(%dp),%dp */
436 stub
->insns
[1] = 0x53610020; /* ldd 10(%dp),%r1 */
437 stub
->insns
[2] = 0xe820d000; /* bve (%r1) */
438 stub
->insns
[3] = 0x537b0030; /* ldd 18(%dp),%dp */
440 stub
->insns
[0] |= reassemble_14(get_got(me
, value
, addend
) & 0x3fff);
443 stub
->insns
[0] = 0x20200000; /* ldil 0,%r1 */
444 stub
->insns
[1] = 0x34210000; /* ldo 0(%r1), %r1 */
445 stub
->insns
[2] = 0x50210020; /* ldd 10(%r1),%r1 */
446 stub
->insns
[3] = 0xe820d002; /* bve,n (%r1) */
448 stub
->insns
[0] |= reassemble_21(lrsel(value
, addend
));
449 stub
->insns
[1] |= reassemble_14(rrsel(value
, addend
));
451 case ELF_STUB_DIRECT
:
452 stub
->insns
[0] = 0x20200000; /* ldil 0,%r1 */
453 stub
->insns
[1] = 0x34210000; /* ldo 0(%r1), %r1 */
454 stub
->insns
[2] = 0xe820d002; /* bve,n (%r1) */
456 stub
->insns
[0] |= reassemble_21(lrsel(value
, addend
));
457 stub
->insns
[1] |= reassemble_14(rrsel(value
, addend
));
463 return (Elf_Addr
)stub
;
466 int apply_relocate(Elf_Shdr
*sechdrs
,
468 unsigned int symindex
,
472 /* parisc should not need this ... */
473 printk(KERN_ERR
"module %s: RELOCATION unsupported\n",
479 int apply_relocate_add(Elf_Shdr
*sechdrs
,
481 unsigned int symindex
,
486 Elf32_Rela
*rel
= (void *)sechdrs
[relsec
].sh_addr
;
492 //unsigned long dp = (unsigned long)$global$;
493 register unsigned long dp
asm ("r27");
495 DEBUGP("Applying relocate section %u to %u\n", relsec
,
496 sechdrs
[relsec
].sh_info
);
497 for (i
= 0; i
< sechdrs
[relsec
].sh_size
/ sizeof(*rel
); i
++) {
498 /* This is where to make the change */
499 loc
= (void *)sechdrs
[sechdrs
[relsec
].sh_info
].sh_addr
501 /* This is the symbol it is referring to */
502 sym
= (Elf32_Sym
*)sechdrs
[symindex
].sh_addr
503 + ELF32_R_SYM(rel
[i
].r_info
);
504 if (!sym
->st_value
) {
505 printk(KERN_WARNING
"%s: Unknown symbol %s\n",
506 me
->name
, strtab
+ sym
->st_name
);
509 //dot = (sechdrs[relsec].sh_addr + rel->r_offset) & ~0x03;
510 dot
= (Elf32_Addr
)loc
& ~0x03;
513 addend
= rel
[i
].r_addend
;
516 #define r(t) ELF32_R_TYPE(rel[i].r_info)==t ? #t :
517 DEBUGP("Symbol %s loc 0x%x val 0x%x addend 0x%x: %s\n",
518 strtab
+ sym
->st_name
,
519 (uint32_t)loc
, val
, addend
,
533 switch (ELF32_R_TYPE(rel
[i
].r_info
)) {
534 case R_PARISC_PLABEL32
:
535 /* 32-bit function address */
536 /* no function descriptors... */
537 *loc
= fsel(val
, addend
);
540 /* direct 32-bit ref */
541 *loc
= fsel(val
, addend
);
543 case R_PARISC_DIR21L
:
544 /* left 21 bits of effective address */
545 val
= lrsel(val
, addend
);
546 *loc
= mask(*loc
, 21) | reassemble_21(val
);
548 case R_PARISC_DIR14R
:
549 /* right 14 bits of effective address */
550 val
= rrsel(val
, addend
);
551 *loc
= mask(*loc
, 14) | reassemble_14(val
);
553 case R_PARISC_SEGREL32
:
554 /* 32-bit segment relative address */
555 /* See note about special handling of SEGREL32 at
556 * the beginning of this file.
558 *loc
= fsel(val
, addend
);
560 case R_PARISC_DPREL21L
:
561 /* left 21 bit of relative address */
562 val
= lrsel(val
- dp
, addend
);
563 *loc
= mask(*loc
, 21) | reassemble_21(val
);
565 case R_PARISC_DPREL14R
:
566 /* right 14 bit of relative address */
567 val
= rrsel(val
- dp
, addend
);
568 *loc
= mask(*loc
, 14) | reassemble_14(val
);
570 case R_PARISC_PCREL17F
:
571 /* 17-bit PC relative address */
572 val
= get_stub(me
, val
, addend
, ELF_STUB_GOT
, in_init(me
, loc
));
573 val
= (val
- dot
- 8)/4;
575 *loc
= (*loc
& ~0x1f1ffd) | reassemble_17(val
);
577 case R_PARISC_PCREL22F
:
578 /* 22-bit PC relative address; only defined for pa20 */
579 val
= get_stub(me
, val
, addend
, ELF_STUB_GOT
, in_init(me
, loc
));
580 DEBUGP("STUB FOR %s loc %lx+%lx at %lx\n",
581 strtab
+ sym
->st_name
, (unsigned long)loc
, addend
,
583 val
= (val
- dot
- 8)/4;
584 CHECK_RELOC(val
, 22);
585 *loc
= (*loc
& ~0x3ff1ffd) | reassemble_22(val
);
589 printk(KERN_ERR
"module %s: Unknown relocation: %u\n",
590 me
->name
, ELF32_R_TYPE(rel
[i
].r_info
));
599 int apply_relocate_add(Elf_Shdr
*sechdrs
,
601 unsigned int symindex
,
606 Elf64_Rela
*rel
= (void *)sechdrs
[relsec
].sh_addr
;
614 DEBUGP("Applying relocate section %u to %u\n", relsec
,
615 sechdrs
[relsec
].sh_info
);
616 for (i
= 0; i
< sechdrs
[relsec
].sh_size
/ sizeof(*rel
); i
++) {
617 /* This is where to make the change */
618 loc
= (void *)sechdrs
[sechdrs
[relsec
].sh_info
].sh_addr
620 /* This is the symbol it is referring to */
621 sym
= (Elf64_Sym
*)sechdrs
[symindex
].sh_addr
622 + ELF64_R_SYM(rel
[i
].r_info
);
623 if (!sym
->st_value
) {
624 printk(KERN_WARNING
"%s: Unknown symbol %s\n",
625 me
->name
, strtab
+ sym
->st_name
);
628 //dot = (sechdrs[relsec].sh_addr + rel->r_offset) & ~0x03;
629 dot
= (Elf64_Addr
)loc
& ~0x03;
630 loc64
= (Elf64_Xword
*)loc
;
633 addend
= rel
[i
].r_addend
;
636 #define r(t) ELF64_R_TYPE(rel[i].r_info)==t ? #t :
637 printk("Symbol %s loc %p val 0x%Lx addend 0x%Lx: %s\n",
638 strtab
+ sym
->st_name
,
650 switch (ELF64_R_TYPE(rel
[i
].r_info
)) {
651 case R_PARISC_LTOFF21L
:
652 /* LT-relative; left 21 bits */
653 val
= get_got(me
, val
, addend
);
654 DEBUGP("LTOFF21L Symbol %s loc %p val %lx\n",
655 strtab
+ sym
->st_name
,
658 *loc
= mask(*loc
, 21) | reassemble_21(val
);
660 case R_PARISC_LTOFF14R
:
661 /* L(ltoff(val+addend)) */
662 /* LT-relative; right 14 bits */
663 val
= get_got(me
, val
, addend
);
665 DEBUGP("LTOFF14R Symbol %s loc %p val %lx\n",
666 strtab
+ sym
->st_name
,
668 *loc
= mask(*loc
, 14) | reassemble_14(val
);
670 case R_PARISC_PCREL22F
:
671 /* PC-relative; 22 bits */
672 DEBUGP("PCREL22F Symbol %s loc %p val %lx\n",
673 strtab
+ sym
->st_name
,
675 /* can we reach it locally? */
676 if(!in_local_section(me
, (void *)val
, (void *)dot
)) {
678 if (in_local(me
, (void *)val
))
679 /* this is the case where the
680 * symbol is local to the
681 * module, but in a different
682 * section, so stub the jump
683 * in case it's more than 22
685 val
= get_stub(me
, val
, addend
, ELF_STUB_DIRECT
,
687 else if (strncmp(strtab
+ sym
->st_name
, "$$", 2)
689 val
= get_stub(me
, val
, addend
, ELF_STUB_MILLI
,
692 val
= get_stub(me
, val
, addend
, ELF_STUB_GOT
,
695 DEBUGP("STUB FOR %s loc %lx, val %lx+%lx at %lx\n",
696 strtab
+ sym
->st_name
, loc
, sym
->st_value
,
698 /* FIXME: local symbols work as long as the
699 * core and init pieces aren't separated too
700 * far. If this is ever broken, you will trip
701 * the check below. The way to fix it would
702 * be to generate local stubs to go between init
704 if((Elf64_Sxword
)(val
- dot
- 8) > 0x800000 -1 ||
705 (Elf64_Sxword
)(val
- dot
- 8) < -0x800000) {
706 printk(KERN_ERR
"Module %s, symbol %s is out of range for PCREL22F relocation\n",
707 me
->name
, strtab
+ sym
->st_name
);
710 val
= (val
- dot
- 8)/4;
711 *loc
= (*loc
& ~0x3ff1ffd) | reassemble_22(val
);
714 /* 64-bit effective address */
715 *loc64
= val
+ addend
;
717 case R_PARISC_SEGREL32
:
718 /* 32-bit segment relative address */
719 /* See note about special handling of SEGREL32 at
720 * the beginning of this file.
722 *loc
= fsel(val
, addend
);
724 case R_PARISC_FPTR64
:
725 /* 64-bit function address */
726 if(in_local(me
, (void *)(val
+ addend
))) {
727 *loc64
= get_fdesc(me
, val
+addend
);
728 DEBUGP("FDESC for %s at %p points to %lx\n",
729 strtab
+ sym
->st_name
, *loc64
,
730 ((Elf_Fdesc
*)*loc64
)->addr
);
732 /* if the symbol is not local to this
733 * module then val+addend is a pointer
734 * to the function descriptor */
735 DEBUGP("Non local FPTR64 Symbol %s loc %p val %lx\n",
736 strtab
+ sym
->st_name
,
738 *loc64
= val
+ addend
;
743 printk(KERN_ERR
"module %s: Unknown relocation: %Lu\n",
744 me
->name
, ELF64_R_TYPE(rel
[i
].r_info
));
753 register_unwind_table(struct module
*me
,
754 const Elf_Shdr
*sechdrs
)
756 unsigned char *table
, *end
;
759 if (!me
->arch
.unwind_section
)
762 table
= (unsigned char *)sechdrs
[me
->arch
.unwind_section
].sh_addr
;
763 end
= table
+ sechdrs
[me
->arch
.unwind_section
].sh_size
;
764 gp
= (Elf_Addr
)me
->module_core
+ me
->arch
.got_offset
;
766 DEBUGP("register_unwind_table(), sect = %d at 0x%p - 0x%p (gp=0x%lx)\n",
767 me
->arch
.unwind_section
, table
, end
, gp
);
768 me
->arch
.unwind
= unwind_table_add(me
->name
, 0, gp
, table
, end
);
772 deregister_unwind_table(struct module
*me
)
775 unwind_table_remove(me
->arch
.unwind
);
778 int module_finalize(const Elf_Ehdr
*hdr
,
779 const Elf_Shdr
*sechdrs
,
784 const char *strtab
= NULL
;
785 Elf_Sym
*newptr
, *oldptr
;
786 Elf_Shdr
*symhdr
= NULL
;
791 entry
= (Elf_Fdesc
*)me
->init
;
792 printk("FINALIZE, ->init FPTR is %p, GP %lx ADDR %lx\n", entry
,
793 entry
->gp
, entry
->addr
);
794 addr
= (u32
*)entry
->addr
;
795 printk("INSNS: %x %x %x %x\n",
796 addr
[0], addr
[1], addr
[2], addr
[3]);
797 printk("stubs used %ld, stubs max %ld\n"
798 "init_stubs used %ld, init stubs max %ld\n"
799 "got entries used %ld, gots max %ld\n"
800 "fdescs used %ld, fdescs max %ld\n",
801 me
->arch
.stub_count
, me
->arch
.stub_max
,
802 me
->arch
.init_stub_count
, me
->arch
.init_stub_max
,
803 me
->arch
.got_count
, me
->arch
.got_max
,
804 me
->arch
.fdesc_count
, me
->arch
.fdesc_max
);
807 register_unwind_table(me
, sechdrs
);
809 /* haven't filled in me->symtab yet, so have to find it
811 for (i
= 1; i
< hdr
->e_shnum
; i
++) {
812 if(sechdrs
[i
].sh_type
== SHT_SYMTAB
813 && (sechdrs
[i
].sh_type
& SHF_ALLOC
)) {
814 int strindex
= sechdrs
[i
].sh_link
;
816 * The cast is to drop the const from
817 * the sechdrs pointer */
818 symhdr
= (Elf_Shdr
*)&sechdrs
[i
];
819 strtab
= (char *)sechdrs
[strindex
].sh_addr
;
824 DEBUGP("module %s: strtab %p, symhdr %p\n",
825 me
->name
, strtab
, symhdr
);
827 if(me
->arch
.got_count
> MAX_GOTS
) {
828 printk(KERN_ERR
"%s: Global Offset Table overflow (used %ld, allowed %d)\n",
829 me
->name
, me
->arch
.got_count
, MAX_GOTS
);
833 /* no symbol table */
837 oldptr
= (void *)symhdr
->sh_addr
;
838 newptr
= oldptr
+ 1; /* we start counting at 1 */
839 nsyms
= symhdr
->sh_size
/ sizeof(Elf_Sym
);
840 DEBUGP("OLD num_symtab %lu\n", nsyms
);
842 for (i
= 1; i
< nsyms
; i
++) {
843 oldptr
++; /* note, count starts at 1 so preincrement */
844 if(strncmp(strtab
+ oldptr
->st_name
,
854 nsyms
= newptr
- (Elf_Sym
*)symhdr
->sh_addr
;
855 DEBUGP("NEW num_symtab %lu\n", nsyms
);
856 symhdr
->sh_size
= nsyms
* sizeof(Elf_Sym
);
857 return module_bug_finalize(hdr
, sechdrs
, me
);
860 void module_arch_cleanup(struct module
*mod
)
862 deregister_unwind_table(mod
);
863 module_bug_cleanup(mod
);
867 void *dereference_function_descriptor(void *ptr
)
869 Elf64_Fdesc
*desc
= ptr
;
872 if (!probe_kernel_address(&desc
->addr
, p
))