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>
51 #include <asm/unwind.h>
56 #define DEBUGP(fmt...)
59 #define CHECK_RELOC(val, bits) \
60 if ( ( !((val) & (1<<((bits)-1))) && ((val)>>(bits)) != 0 ) || \
61 ( ((val) & (1<<((bits)-1))) && ((val)>>(bits)) != (((__typeof__(val))(~0))>>((bits)+2)))) { \
62 printk(KERN_ERR "module %s relocation of symbol %s is out of range (0x%lx in %d bits)\n", \
63 me->name, strtab + sym->st_name, (unsigned long)val, bits); \
67 /* Maximum number of GOT entries. We use a long displacement ldd from
68 * the bottom of the table, which has a maximum signed displacement of
69 * 0x3fff; however, since we're only going forward, this becomes
70 * 0x1fff, and thus, since each GOT entry is 8 bytes long we can have
71 * at most 1023 entries */
74 /* three functions to determine where in the module core
75 * or init pieces the location is */
76 static inline int in_init(struct module
*me
, void *loc
)
78 return (loc
>= me
->module_init
&&
79 loc
<= (me
->module_init
+ me
->init_size
));
82 static inline int in_core(struct module
*me
, void *loc
)
84 return (loc
>= me
->module_core
&&
85 loc
<= (me
->module_core
+ me
->core_size
));
88 static inline int in_local(struct module
*me
, void *loc
)
90 return in_init(me
, loc
) || in_core(me
, loc
);
93 static inline int in_local_section(struct module
*me
, void *loc
, void *dot
)
95 return (in_init(me
, loc
) && in_init(me
, dot
)) ||
96 (in_core(me
, loc
) && in_core(me
, dot
));
105 #define Elf_Fdesc Elf32_Fdesc
108 Elf32_Word insns
[2]; /* each stub entry has two insns */
115 #define Elf_Fdesc Elf64_Fdesc
118 Elf64_Word insns
[4]; /* each stub entry has four insns */
122 /* Field selection types defined by hppa */
123 #define rnd(x) (((x)+0x1000)&~0x1fff)
124 /* fsel: full 32 bits */
125 #define fsel(v,a) ((v)+(a))
126 /* lsel: select left 21 bits */
127 #define lsel(v,a) (((v)+(a))>>11)
128 /* rsel: select right 11 bits */
129 #define rsel(v,a) (((v)+(a))&0x7ff)
130 /* lrsel with rounding of addend to nearest 8k */
131 #define lrsel(v,a) (((v)+rnd(a))>>11)
132 /* rrsel with rounding of addend to nearest 8k */
133 #define rrsel(v,a) ((((v)+rnd(a))&0x7ff)+((a)-rnd(a)))
135 #define mask(x,sz) ((x) & ~((1<<(sz))-1))
138 /* The reassemble_* functions prepare an immediate value for
139 insertion into an opcode. pa-risc uses all sorts of weird bitfields
140 in the instruction to hold the value. */
141 static inline int reassemble_14(int as14
)
143 return (((as14
& 0x1fff) << 1) |
144 ((as14
& 0x2000) >> 13));
147 static inline int reassemble_17(int as17
)
149 return (((as17
& 0x10000) >> 16) |
150 ((as17
& 0x0f800) << 5) |
151 ((as17
& 0x00400) >> 8) |
152 ((as17
& 0x003ff) << 3));
155 static inline int reassemble_21(int as21
)
157 return (((as21
& 0x100000) >> 20) |
158 ((as21
& 0x0ffe00) >> 8) |
159 ((as21
& 0x000180) << 7) |
160 ((as21
& 0x00007c) << 14) |
161 ((as21
& 0x000003) << 12));
164 static inline int reassemble_22(int as22
)
166 return (((as22
& 0x200000) >> 21) |
167 ((as22
& 0x1f0000) << 5) |
168 ((as22
& 0x00f800) << 5) |
169 ((as22
& 0x000400) >> 8) |
170 ((as22
& 0x0003ff) << 3));
173 void *module_alloc(unsigned long size
)
177 return vmalloc(size
);
181 static inline unsigned long count_gots(const Elf_Rela
*rela
, unsigned long n
)
186 static inline unsigned long count_fdescs(const Elf_Rela
*rela
, unsigned long n
)
191 static inline unsigned long count_stubs(const Elf_Rela
*rela
, unsigned long n
)
193 unsigned long cnt
= 0;
195 for (; n
> 0; n
--, rela
++)
197 switch (ELF32_R_TYPE(rela
->r_info
)) {
198 case R_PARISC_PCREL17F
:
199 case R_PARISC_PCREL22F
:
207 static inline unsigned long count_gots(const Elf_Rela
*rela
, unsigned long n
)
209 unsigned long cnt
= 0;
211 for (; n
> 0; n
--, rela
++)
213 switch (ELF64_R_TYPE(rela
->r_info
)) {
214 case R_PARISC_LTOFF21L
:
215 case R_PARISC_LTOFF14R
:
216 case R_PARISC_PCREL22F
:
224 static inline unsigned long count_fdescs(const Elf_Rela
*rela
, unsigned long n
)
226 unsigned long cnt
= 0;
228 for (; n
> 0; n
--, rela
++)
230 switch (ELF64_R_TYPE(rela
->r_info
)) {
231 case R_PARISC_FPTR64
:
239 static inline unsigned long count_stubs(const Elf_Rela
*rela
, unsigned long n
)
241 unsigned long cnt
= 0;
243 for (; n
> 0; n
--, rela
++)
245 switch (ELF64_R_TYPE(rela
->r_info
)) {
246 case R_PARISC_PCREL22F
:
256 /* Free memory returned from module_alloc */
257 void module_free(struct module
*mod
, void *module_region
)
259 vfree(module_region
);
260 /* FIXME: If module_region == mod->init_region, trim exception
265 int module_frob_arch_sections(CONST Elf_Ehdr
*hdr
,
266 CONST Elf_Shdr
*sechdrs
,
267 CONST
char *secstrings
,
270 unsigned long gots
= 0, fdescs
= 0, stubs
= 0, init_stubs
= 0;
273 for (i
= 1; i
< hdr
->e_shnum
; i
++) {
274 const Elf_Rela
*rels
= (void *)hdr
+ sechdrs
[i
].sh_offset
;
275 unsigned long nrels
= sechdrs
[i
].sh_size
/ sizeof(*rels
);
277 if (strncmp(secstrings
+ sechdrs
[i
].sh_name
,
278 ".PARISC.unwind", 14) == 0)
279 me
->arch
.unwind_section
= i
;
281 if (sechdrs
[i
].sh_type
!= SHT_RELA
)
284 /* some of these are not relevant for 32-bit/64-bit
285 * we leave them here to make the code common. the
286 * compiler will do its thing and optimize out the
287 * stuff we don't need
289 gots
+= count_gots(rels
, nrels
);
290 fdescs
+= count_fdescs(rels
, nrels
);
291 if(strncmp(secstrings
+ sechdrs
[i
].sh_name
,
292 ".rela.init", 10) == 0)
293 init_stubs
+= count_stubs(rels
, nrels
);
295 stubs
+= count_stubs(rels
, nrels
);
298 /* align things a bit */
299 me
->core_size
= ALIGN(me
->core_size
, 16);
300 me
->arch
.got_offset
= me
->core_size
;
301 me
->core_size
+= gots
* sizeof(struct got_entry
);
303 me
->core_size
= ALIGN(me
->core_size
, 16);
304 me
->arch
.fdesc_offset
= me
->core_size
;
305 me
->core_size
+= fdescs
* sizeof(Elf_Fdesc
);
307 me
->core_size
= ALIGN(me
->core_size
, 16);
308 me
->arch
.stub_offset
= me
->core_size
;
309 me
->core_size
+= stubs
* sizeof(struct stub_entry
);
311 me
->init_size
= ALIGN(me
->init_size
, 16);
312 me
->arch
.init_stub_offset
= me
->init_size
;
313 me
->init_size
+= init_stubs
* sizeof(struct stub_entry
);
315 me
->arch
.got_max
= gots
;
316 me
->arch
.fdesc_max
= fdescs
;
317 me
->arch
.stub_max
= stubs
;
318 me
->arch
.init_stub_max
= init_stubs
;
324 static Elf64_Word
get_got(struct module
*me
, unsigned long value
, long addend
)
327 struct got_entry
*got
;
333 got
= me
->module_core
+ me
->arch
.got_offset
;
334 for (i
= 0; got
[i
].addr
; i
++)
335 if (got
[i
].addr
== value
)
338 BUG_ON(++me
->arch
.got_count
> me
->arch
.got_max
);
342 DEBUGP("GOT ENTRY %d[%x] val %lx\n", i
, i
*sizeof(struct got_entry
),
344 return i
* sizeof(struct got_entry
);
346 #endif /* CONFIG_64BIT */
349 static Elf_Addr
get_fdesc(struct module
*me
, unsigned long value
)
351 Elf_Fdesc
*fdesc
= me
->module_core
+ me
->arch
.fdesc_offset
;
354 printk(KERN_ERR
"%s: zero OPD requested!\n", me
->name
);
358 /* Look for existing fdesc entry. */
359 while (fdesc
->addr
) {
360 if (fdesc
->addr
== value
)
361 return (Elf_Addr
)fdesc
;
365 BUG_ON(++me
->arch
.fdesc_count
> me
->arch
.fdesc_max
);
369 fdesc
->gp
= (Elf_Addr
)me
->module_core
+ me
->arch
.got_offset
;
370 return (Elf_Addr
)fdesc
;
372 #endif /* CONFIG_64BIT */
380 static Elf_Addr
get_stub(struct module
*me
, unsigned long value
, long addend
,
381 enum elf_stub_type stub_type
, int init_section
)
384 struct stub_entry
*stub
;
387 i
= me
->arch
.init_stub_count
++;
388 BUG_ON(me
->arch
.init_stub_count
> me
->arch
.init_stub_max
);
389 stub
= me
->module_init
+ me
->arch
.init_stub_offset
+
390 i
* sizeof(struct stub_entry
);
392 i
= me
->arch
.stub_count
++;
393 BUG_ON(me
->arch
.stub_count
> me
->arch
.stub_max
);
394 stub
= me
->module_core
+ me
->arch
.stub_offset
+
395 i
* sizeof(struct stub_entry
);
399 /* for 32-bit the stub looks like this:
401 * be,n R'XXX(%sr4,%r1)
403 //value = *(unsigned long *)((value + addend) & ~3); /* why? */
405 stub
->insns
[0] = 0x20200000; /* ldil L'XXX,%r1 */
406 stub
->insns
[1] = 0xe0202002; /* be,n R'XXX(%sr4,%r1) */
408 stub
->insns
[0] |= reassemble_21(lrsel(value
, addend
));
409 stub
->insns
[1] |= reassemble_17(rrsel(value
, addend
) / 4);
412 /* for 64-bit we have three kinds of stubs:
413 * for normal function calls:
425 * for direct branches (jumps between different section of the
433 stub
->insns
[0] = 0x537b0000; /* ldd 0(%dp),%dp */
434 stub
->insns
[1] = 0x53610020; /* ldd 10(%dp),%r1 */
435 stub
->insns
[2] = 0xe820d000; /* bve (%r1) */
436 stub
->insns
[3] = 0x537b0030; /* ldd 18(%dp),%dp */
438 stub
->insns
[0] |= reassemble_14(get_got(me
, value
, addend
) & 0x3fff);
441 stub
->insns
[0] = 0x20200000; /* ldil 0,%r1 */
442 stub
->insns
[1] = 0x34210000; /* ldo 0(%r1), %r1 */
443 stub
->insns
[2] = 0x50210020; /* ldd 10(%r1),%r1 */
444 stub
->insns
[3] = 0xe820d002; /* bve,n (%r1) */
446 stub
->insns
[0] |= reassemble_21(lrsel(value
, addend
));
447 stub
->insns
[1] |= reassemble_14(rrsel(value
, addend
));
449 case ELF_STUB_DIRECT
:
450 stub
->insns
[0] = 0x20200000; /* ldil 0,%r1 */
451 stub
->insns
[1] = 0x34210000; /* ldo 0(%r1), %r1 */
452 stub
->insns
[2] = 0xe820d002; /* bve,n (%r1) */
454 stub
->insns
[0] |= reassemble_21(lrsel(value
, addend
));
455 stub
->insns
[1] |= reassemble_14(rrsel(value
, addend
));
461 return (Elf_Addr
)stub
;
464 int apply_relocate(Elf_Shdr
*sechdrs
,
466 unsigned int symindex
,
470 /* parisc should not need this ... */
471 printk(KERN_ERR
"module %s: RELOCATION unsupported\n",
477 int apply_relocate_add(Elf_Shdr
*sechdrs
,
479 unsigned int symindex
,
484 Elf32_Rela
*rel
= (void *)sechdrs
[relsec
].sh_addr
;
490 //unsigned long dp = (unsigned long)$global$;
491 register unsigned long dp
asm ("r27");
493 DEBUGP("Applying relocate section %u to %u\n", relsec
,
494 sechdrs
[relsec
].sh_info
);
495 for (i
= 0; i
< sechdrs
[relsec
].sh_size
/ sizeof(*rel
); i
++) {
496 /* This is where to make the change */
497 loc
= (void *)sechdrs
[sechdrs
[relsec
].sh_info
].sh_addr
499 /* This is the symbol it is referring to */
500 sym
= (Elf32_Sym
*)sechdrs
[symindex
].sh_addr
501 + ELF32_R_SYM(rel
[i
].r_info
);
502 if (!sym
->st_value
) {
503 printk(KERN_WARNING
"%s: Unknown symbol %s\n",
504 me
->name
, strtab
+ sym
->st_name
);
507 //dot = (sechdrs[relsec].sh_addr + rel->r_offset) & ~0x03;
508 dot
= (Elf32_Addr
)loc
& ~0x03;
511 addend
= rel
[i
].r_addend
;
514 #define r(t) ELF32_R_TYPE(rel[i].r_info)==t ? #t :
515 DEBUGP("Symbol %s loc 0x%x val 0x%x addend 0x%x: %s\n",
516 strtab
+ sym
->st_name
,
517 (uint32_t)loc
, val
, addend
,
531 switch (ELF32_R_TYPE(rel
[i
].r_info
)) {
532 case R_PARISC_PLABEL32
:
533 /* 32-bit function address */
534 /* no function descriptors... */
535 *loc
= fsel(val
, addend
);
538 /* direct 32-bit ref */
539 *loc
= fsel(val
, addend
);
541 case R_PARISC_DIR21L
:
542 /* left 21 bits of effective address */
543 val
= lrsel(val
, addend
);
544 *loc
= mask(*loc
, 21) | reassemble_21(val
);
546 case R_PARISC_DIR14R
:
547 /* right 14 bits of effective address */
548 val
= rrsel(val
, addend
);
549 *loc
= mask(*loc
, 14) | reassemble_14(val
);
551 case R_PARISC_SEGREL32
:
552 /* 32-bit segment relative address */
553 /* See note about special handling of SEGREL32 at
554 * the beginning of this file.
556 *loc
= fsel(val
, addend
);
558 case R_PARISC_DPREL21L
:
559 /* left 21 bit of relative address */
560 val
= lrsel(val
- dp
, addend
);
561 *loc
= mask(*loc
, 21) | reassemble_21(val
);
563 case R_PARISC_DPREL14R
:
564 /* right 14 bit of relative address */
565 val
= rrsel(val
- dp
, addend
);
566 *loc
= mask(*loc
, 14) | reassemble_14(val
);
568 case R_PARISC_PCREL17F
:
569 /* 17-bit PC relative address */
570 val
= get_stub(me
, val
, addend
, ELF_STUB_GOT
, in_init(me
, loc
));
571 val
= (val
- dot
- 8)/4;
573 *loc
= (*loc
& ~0x1f1ffd) | reassemble_17(val
);
575 case R_PARISC_PCREL22F
:
576 /* 22-bit PC relative address; only defined for pa20 */
577 val
= get_stub(me
, val
, addend
, ELF_STUB_GOT
, in_init(me
, loc
));
578 DEBUGP("STUB FOR %s loc %lx+%lx at %lx\n",
579 strtab
+ sym
->st_name
, (unsigned long)loc
, addend
,
581 val
= (val
- dot
- 8)/4;
582 CHECK_RELOC(val
, 22);
583 *loc
= (*loc
& ~0x3ff1ffd) | reassemble_22(val
);
587 printk(KERN_ERR
"module %s: Unknown relocation: %u\n",
588 me
->name
, ELF32_R_TYPE(rel
[i
].r_info
));
597 int apply_relocate_add(Elf_Shdr
*sechdrs
,
599 unsigned int symindex
,
604 Elf64_Rela
*rel
= (void *)sechdrs
[relsec
].sh_addr
;
612 DEBUGP("Applying relocate section %u to %u\n", relsec
,
613 sechdrs
[relsec
].sh_info
);
614 for (i
= 0; i
< sechdrs
[relsec
].sh_size
/ sizeof(*rel
); i
++) {
615 /* This is where to make the change */
616 loc
= (void *)sechdrs
[sechdrs
[relsec
].sh_info
].sh_addr
618 /* This is the symbol it is referring to */
619 sym
= (Elf64_Sym
*)sechdrs
[symindex
].sh_addr
620 + ELF64_R_SYM(rel
[i
].r_info
);
621 if (!sym
->st_value
) {
622 printk(KERN_WARNING
"%s: Unknown symbol %s\n",
623 me
->name
, strtab
+ sym
->st_name
);
626 //dot = (sechdrs[relsec].sh_addr + rel->r_offset) & ~0x03;
627 dot
= (Elf64_Addr
)loc
& ~0x03;
628 loc64
= (Elf64_Xword
*)loc
;
631 addend
= rel
[i
].r_addend
;
634 #define r(t) ELF64_R_TYPE(rel[i].r_info)==t ? #t :
635 printk("Symbol %s loc %p val 0x%Lx addend 0x%Lx: %s\n",
636 strtab
+ sym
->st_name
,
648 switch (ELF64_R_TYPE(rel
[i
].r_info
)) {
649 case R_PARISC_LTOFF21L
:
650 /* LT-relative; left 21 bits */
651 val
= get_got(me
, val
, addend
);
652 DEBUGP("LTOFF21L Symbol %s loc %p val %lx\n",
653 strtab
+ sym
->st_name
,
656 *loc
= mask(*loc
, 21) | reassemble_21(val
);
658 case R_PARISC_LTOFF14R
:
659 /* L(ltoff(val+addend)) */
660 /* LT-relative; right 14 bits */
661 val
= get_got(me
, val
, addend
);
663 DEBUGP("LTOFF14R Symbol %s loc %p val %lx\n",
664 strtab
+ sym
->st_name
,
666 *loc
= mask(*loc
, 14) | reassemble_14(val
);
668 case R_PARISC_PCREL22F
:
669 /* PC-relative; 22 bits */
670 DEBUGP("PCREL22F Symbol %s loc %p val %lx\n",
671 strtab
+ sym
->st_name
,
673 /* can we reach it locally? */
674 if(!in_local_section(me
, (void *)val
, (void *)dot
)) {
676 if (in_local(me
, (void *)val
))
677 /* this is the case where the
678 * symbol is local to the
679 * module, but in a different
680 * section, so stub the jump
681 * in case it's more than 22
683 val
= get_stub(me
, val
, addend
, ELF_STUB_DIRECT
,
685 else if (strncmp(strtab
+ sym
->st_name
, "$$", 2)
687 val
= get_stub(me
, val
, addend
, ELF_STUB_MILLI
,
690 val
= get_stub(me
, val
, addend
, ELF_STUB_GOT
,
693 DEBUGP("STUB FOR %s loc %lx, val %lx+%lx at %lx\n",
694 strtab
+ sym
->st_name
, loc
, sym
->st_value
,
696 /* FIXME: local symbols work as long as the
697 * core and init pieces aren't separated too
698 * far. If this is ever broken, you will trip
699 * the check below. The way to fix it would
700 * be to generate local stubs to go between init
702 if((Elf64_Sxword
)(val
- dot
- 8) > 0x800000 -1 ||
703 (Elf64_Sxword
)(val
- dot
- 8) < -0x800000) {
704 printk(KERN_ERR
"Module %s, symbol %s is out of range for PCREL22F relocation\n",
705 me
->name
, strtab
+ sym
->st_name
);
708 val
= (val
- dot
- 8)/4;
709 *loc
= (*loc
& ~0x3ff1ffd) | reassemble_22(val
);
712 /* 64-bit effective address */
713 *loc64
= val
+ addend
;
715 case R_PARISC_SEGREL32
:
716 /* 32-bit segment relative address */
717 /* See note about special handling of SEGREL32 at
718 * the beginning of this file.
720 *loc
= fsel(val
, addend
);
722 case R_PARISC_FPTR64
:
723 /* 64-bit function address */
724 if(in_local(me
, (void *)(val
+ addend
))) {
725 *loc64
= get_fdesc(me
, val
+addend
);
726 DEBUGP("FDESC for %s at %p points to %lx\n",
727 strtab
+ sym
->st_name
, *loc64
,
728 ((Elf_Fdesc
*)*loc64
)->addr
);
730 /* if the symbol is not local to this
731 * module then val+addend is a pointer
732 * to the function descriptor */
733 DEBUGP("Non local FPTR64 Symbol %s loc %p val %lx\n",
734 strtab
+ sym
->st_name
,
736 *loc64
= val
+ addend
;
741 printk(KERN_ERR
"module %s: Unknown relocation: %Lu\n",
742 me
->name
, ELF64_R_TYPE(rel
[i
].r_info
));
751 register_unwind_table(struct module
*me
,
752 const Elf_Shdr
*sechdrs
)
754 unsigned char *table
, *end
;
757 if (!me
->arch
.unwind_section
)
760 table
= (unsigned char *)sechdrs
[me
->arch
.unwind_section
].sh_addr
;
761 end
= table
+ sechdrs
[me
->arch
.unwind_section
].sh_size
;
762 gp
= (Elf_Addr
)me
->module_core
+ me
->arch
.got_offset
;
764 DEBUGP("register_unwind_table(), sect = %d at 0x%p - 0x%p (gp=0x%lx)\n",
765 me
->arch
.unwind_section
, table
, end
, gp
);
766 me
->arch
.unwind
= unwind_table_add(me
->name
, 0, gp
, table
, end
);
770 deregister_unwind_table(struct module
*me
)
773 unwind_table_remove(me
->arch
.unwind
);
776 int module_finalize(const Elf_Ehdr
*hdr
,
777 const Elf_Shdr
*sechdrs
,
782 const char *strtab
= NULL
;
783 Elf_Sym
*newptr
, *oldptr
;
784 Elf_Shdr
*symhdr
= NULL
;
789 entry
= (Elf_Fdesc
*)me
->init
;
790 printk("FINALIZE, ->init FPTR is %p, GP %lx ADDR %lx\n", entry
,
791 entry
->gp
, entry
->addr
);
792 addr
= (u32
*)entry
->addr
;
793 printk("INSNS: %x %x %x %x\n",
794 addr
[0], addr
[1], addr
[2], addr
[3]);
795 printk("stubs used %ld, stubs max %ld\n"
796 "init_stubs used %ld, init stubs max %ld\n"
797 "got entries used %ld, gots max %ld\n"
798 "fdescs used %ld, fdescs max %ld\n",
799 me
->arch
.stub_count
, me
->arch
.stub_max
,
800 me
->arch
.init_stub_count
, me
->arch
.init_stub_max
,
801 me
->arch
.got_count
, me
->arch
.got_max
,
802 me
->arch
.fdesc_count
, me
->arch
.fdesc_max
);
805 register_unwind_table(me
, sechdrs
);
807 /* haven't filled in me->symtab yet, so have to find it
809 for (i
= 1; i
< hdr
->e_shnum
; i
++) {
810 if(sechdrs
[i
].sh_type
== SHT_SYMTAB
811 && (sechdrs
[i
].sh_type
& SHF_ALLOC
)) {
812 int strindex
= sechdrs
[i
].sh_link
;
814 * The cast is to drop the const from
815 * the sechdrs pointer */
816 symhdr
= (Elf_Shdr
*)&sechdrs
[i
];
817 strtab
= (char *)sechdrs
[strindex
].sh_addr
;
822 DEBUGP("module %s: strtab %p, symhdr %p\n",
823 me
->name
, strtab
, symhdr
);
825 if(me
->arch
.got_count
> MAX_GOTS
) {
826 printk(KERN_ERR
"%s: Global Offset Table overflow (used %ld, allowed %d)\n",
827 me
->name
, me
->arch
.got_count
, MAX_GOTS
);
831 /* no symbol table */
835 oldptr
= (void *)symhdr
->sh_addr
;
836 newptr
= oldptr
+ 1; /* we start counting at 1 */
837 nsyms
= symhdr
->sh_size
/ sizeof(Elf_Sym
);
838 DEBUGP("OLD num_symtab %lu\n", nsyms
);
840 for (i
= 1; i
< nsyms
; i
++) {
841 oldptr
++; /* note, count starts at 1 so preincrement */
842 if(strncmp(strtab
+ oldptr
->st_name
,
852 nsyms
= newptr
- (Elf_Sym
*)symhdr
->sh_addr
;
853 DEBUGP("NEW num_symtab %lu\n", nsyms
);
854 symhdr
->sh_size
= nsyms
* sizeof(Elf_Sym
);
855 return module_bug_finalize(hdr
, sechdrs
, me
);
858 void module_arch_cleanup(struct module
*mod
)
860 deregister_unwind_table(mod
);
861 module_bug_cleanup(mod
);