1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57#include <linux/moduleloader.h>
58#include <linux/elf.h>
59#include <linux/vmalloc.h>
60#include <linux/fs.h>
61#include <linux/string.h>
62#include <linux/kernel.h>
63#include <linux/bug.h>
64
65#include <asm/unwind.h>
66
67#if 0
68#define DEBUGP printk
69#else
70#define DEBUGP(fmt...)
71#endif
72
73#define RELOC_REACHABLE(val, bits) \
74 (( ( !((val) & (1<<((bits)-1))) && ((val)>>(bits)) != 0 ) || \
75 ( ((val) & (1<<((bits)-1))) && ((val)>>(bits)) != (((__typeof__(val))(~0))>>((bits)+2)))) ? \
76 0 : 1)
77
78#define CHECK_RELOC(val, bits) \
79 if (!RELOC_REACHABLE(val, bits)) { \
80 printk(KERN_ERR "module %s relocation of symbol %s is out of range (0x%lx in %d bits)\n", \
81 me->name, strtab + sym->st_name, (unsigned long)val, bits); \
82 return -ENOEXEC; \
83 }
84
85
86
87
88
89
90
91
92
93
94#define MAX_GOTS 4095
95
96
97
98static inline int in_init(struct module *me, void *loc)
99{
100 return (loc >= me->module_init &&
101 loc <= (me->module_init + me->init_size));
102}
103
104static inline int in_core(struct module *me, void *loc)
105{
106 return (loc >= me->module_core &&
107 loc <= (me->module_core + me->core_size));
108}
109
110static inline int in_local(struct module *me, void *loc)
111{
112 return in_init(me, loc) || in_core(me, loc);
113}
114
115#ifndef CONFIG_64BIT
116struct got_entry {
117 Elf32_Addr addr;
118};
119
120struct stub_entry {
121 Elf32_Word insns[2];
122};
123#else
124struct got_entry {
125 Elf64_Addr addr;
126};
127
128struct stub_entry {
129 Elf64_Word insns[4];
130};
131#endif
132
133
134#define rnd(x) (((x)+0x1000)&~0x1fff)
135
136#define fsel(v,a) ((v)+(a))
137
138#define lsel(v,a) (((v)+(a))>>11)
139
140#define rsel(v,a) (((v)+(a))&0x7ff)
141
142#define lrsel(v,a) (((v)+rnd(a))>>11)
143
144#define rrsel(v,a) ((((v)+rnd(a))&0x7ff)+((a)-rnd(a)))
145
146#define mask(x,sz) ((x) & ~((1<<(sz))-1))
147
148
149
150
151
152static inline int sign_unext(int x, int len)
153{
154 int len_ones;
155
156 len_ones = (1 << len) - 1;
157 return x & len_ones;
158}
159
160static inline int low_sign_unext(int x, int len)
161{
162 int sign, temp;
163
164 sign = (x >> (len-1)) & 1;
165 temp = sign_unext(x, len-1);
166 return (temp << 1) | sign;
167}
168
169static inline int reassemble_14(int as14)
170{
171 return (((as14 & 0x1fff) << 1) |
172 ((as14 & 0x2000) >> 13));
173}
174
175static inline int reassemble_16a(int as16)
176{
177 int s, t;
178
179
180 t = (as16 << 1) & 0xffff;
181 s = (as16 & 0x8000);
182 return (t ^ s ^ (s >> 1)) | (s >> 15);
183}
184
185
186static inline int reassemble_17(int as17)
187{
188 return (((as17 & 0x10000) >> 16) |
189 ((as17 & 0x0f800) << 5) |
190 ((as17 & 0x00400) >> 8) |
191 ((as17 & 0x003ff) << 3));
192}
193
194static inline int reassemble_21(int as21)
195{
196 return (((as21 & 0x100000) >> 20) |
197 ((as21 & 0x0ffe00) >> 8) |
198 ((as21 & 0x000180) << 7) |
199 ((as21 & 0x00007c) << 14) |
200 ((as21 & 0x000003) << 12));
201}
202
203static inline int reassemble_22(int as22)
204{
205 return (((as22 & 0x200000) >> 21) |
206 ((as22 & 0x1f0000) << 5) |
207 ((as22 & 0x00f800) << 5) |
208 ((as22 & 0x000400) >> 8) |
209 ((as22 & 0x0003ff) << 3));
210}
211
212void *module_alloc(unsigned long size)
213{
214 if (size == 0)
215 return NULL;
216 return vmalloc(size);
217}
218
219#ifndef CONFIG_64BIT
220static inline unsigned long count_gots(const Elf_Rela *rela, unsigned long n)
221{
222 return 0;
223}
224
225static inline unsigned long count_fdescs(const Elf_Rela *rela, unsigned long n)
226{
227 return 0;
228}
229
230static inline unsigned long count_stubs(const Elf_Rela *rela, unsigned long n)
231{
232 unsigned long cnt = 0;
233
234 for (; n > 0; n--, rela++)
235 {
236 switch (ELF32_R_TYPE(rela->r_info)) {
237 case R_PARISC_PCREL17F:
238 case R_PARISC_PCREL22F:
239 cnt++;
240 }
241 }
242
243 return cnt;
244}
245#else
246static inline unsigned long count_gots(const Elf_Rela *rela, unsigned long n)
247{
248 unsigned long cnt = 0;
249
250 for (; n > 0; n--, rela++)
251 {
252 switch (ELF64_R_TYPE(rela->r_info)) {
253 case R_PARISC_LTOFF21L:
254 case R_PARISC_LTOFF14R:
255 case R_PARISC_PCREL22F:
256 cnt++;
257 }
258 }
259
260 return cnt;
261}
262
263static inline unsigned long count_fdescs(const Elf_Rela *rela, unsigned long n)
264{
265 unsigned long cnt = 0;
266
267 for (; n > 0; n--, rela++)
268 {
269 switch (ELF64_R_TYPE(rela->r_info)) {
270 case R_PARISC_FPTR64:
271 cnt++;
272 }
273 }
274
275 return cnt;
276}
277
278static inline unsigned long count_stubs(const Elf_Rela *rela, unsigned long n)
279{
280 unsigned long cnt = 0;
281
282 for (; n > 0; n--, rela++)
283 {
284 switch (ELF64_R_TYPE(rela->r_info)) {
285 case R_PARISC_PCREL22F:
286 cnt++;
287 }
288 }
289
290 return cnt;
291}
292#endif
293
294
295
296void module_free(struct module *mod, void *module_region)
297{
298 kfree(mod->arch.section);
299 mod->arch.section = NULL;
300
301 vfree(module_region);
302}
303
304
305unsigned int arch_mod_section_prepend(struct module *mod,
306 unsigned int section)
307{
308
309
310 return (mod->arch.section[section].stub_entries + 1)
311 * sizeof(struct stub_entry);
312}
313
314#define CONST
315int module_frob_arch_sections(CONST Elf_Ehdr *hdr,
316 CONST Elf_Shdr *sechdrs,
317 CONST char *secstrings,
318 struct module *me)
319{
320 unsigned long gots = 0, fdescs = 0, len;
321 unsigned int i;
322
323 len = hdr->e_shnum * sizeof(me->arch.section[0]);
324 me->arch.section = kzalloc(len, GFP_KERNEL);
325 if (!me->arch.section)
326 return -ENOMEM;
327
328 for (i = 1; i < hdr->e_shnum; i++) {
329 const Elf_Rela *rels = (void *)sechdrs[i].sh_addr;
330 unsigned long nrels = sechdrs[i].sh_size / sizeof(*rels);
331 unsigned int count, s;
332
333 if (strncmp(secstrings + sechdrs[i].sh_name,
334 ".PARISC.unwind", 14) == 0)
335 me->arch.unwind_section = i;
336
337 if (sechdrs[i].sh_type != SHT_RELA)
338 continue;
339
340
341
342
343
344
345 gots += count_gots(rels, nrels);
346 fdescs += count_fdescs(rels, nrels);
347
348
349
350
351 count = count_stubs(rels, nrels);
352 if (!count)
353 continue;
354
355
356
357 s = sechdrs[i].sh_info;
358
359
360 WARN_ON(me->arch.section[s].stub_entries);
361
362
363 me->arch.section[s].stub_entries += count;
364 }
365
366
367 me->core_size = ALIGN(me->core_size, 16);
368 me->arch.got_offset = me->core_size;
369 me->core_size += gots * sizeof(struct got_entry);
370
371 me->core_size = ALIGN(me->core_size, 16);
372 me->arch.fdesc_offset = me->core_size;
373 me->core_size += fdescs * sizeof(Elf_Fdesc);
374
375 me->arch.got_max = gots;
376 me->arch.fdesc_max = fdescs;
377
378 return 0;
379}
380
381#ifdef CONFIG_64BIT
382static Elf64_Word get_got(struct module *me, unsigned long value, long addend)
383{
384 unsigned int i;
385 struct got_entry *got;
386
387 value += addend;
388
389 BUG_ON(value == 0);
390
391 got = me->module_core + me->arch.got_offset;
392 for (i = 0; got[i].addr; i++)
393 if (got[i].addr == value)
394 goto out;
395
396 BUG_ON(++me->arch.got_count > me->arch.got_max);
397
398 got[i].addr = value;
399 out:
400 DEBUGP("GOT ENTRY %d[%x] val %lx\n", i, i*sizeof(struct got_entry),
401 value);
402 return i * sizeof(struct got_entry);
403}
404#endif
405
406#ifdef CONFIG_64BIT
407static Elf_Addr get_fdesc(struct module *me, unsigned long value)
408{
409 Elf_Fdesc *fdesc = me->module_core + me->arch.fdesc_offset;
410
411 if (!value) {
412 printk(KERN_ERR "%s: zero OPD requested!\n", me->name);
413 return 0;
414 }
415
416
417 while (fdesc->addr) {
418 if (fdesc->addr == value)
419 return (Elf_Addr)fdesc;
420 fdesc++;
421 }
422
423 BUG_ON(++me->arch.fdesc_count > me->arch.fdesc_max);
424
425
426 fdesc->addr = value;
427 fdesc->gp = (Elf_Addr)me->module_core + me->arch.got_offset;
428 return (Elf_Addr)fdesc;
429}
430#endif
431
432enum elf_stub_type {
433 ELF_STUB_GOT,
434 ELF_STUB_MILLI,
435 ELF_STUB_DIRECT,
436};
437
438static Elf_Addr get_stub(struct module *me, unsigned long value, long addend,
439 enum elf_stub_type stub_type, Elf_Addr loc0, unsigned int targetsec)
440{
441 struct stub_entry *stub;
442 int __maybe_unused d;
443
444
445 if (!me->arch.section[targetsec].stub_offset) {
446 loc0 -= (me->arch.section[targetsec].stub_entries + 1) *
447 sizeof(struct stub_entry);
448
449 loc0 = ALIGN(loc0, sizeof(struct stub_entry));
450 me->arch.section[targetsec].stub_offset = loc0;
451 }
452
453
454 stub = (void *) me->arch.section[targetsec].stub_offset;
455 me->arch.section[targetsec].stub_offset += sizeof(struct stub_entry);
456
457
458 BUG_ON(0 == me->arch.section[targetsec].stub_entries--);
459
460
461#ifndef CONFIG_64BIT
462
463
464
465
466
467
468 stub->insns[0] = 0x20200000;
469 stub->insns[1] = 0xe0202002;
470
471 stub->insns[0] |= reassemble_21(lrsel(value, addend));
472 stub->insns[1] |= reassemble_17(rrsel(value, addend) / 4);
473
474#else
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494 switch (stub_type) {
495 case ELF_STUB_GOT:
496 d = get_got(me, value, addend);
497 if (d <= 15) {
498
499 stub->insns[0] = 0x0f6010db;
500 stub->insns[0] |= low_sign_unext(d, 5) << 16;
501 } else {
502
503 stub->insns[0] = 0x537b0000;
504 stub->insns[0] |= reassemble_16a(d);
505 }
506 stub->insns[1] = 0x53610020;
507 stub->insns[2] = 0xe820d000;
508 stub->insns[3] = 0x537b0030;
509 break;
510 case ELF_STUB_MILLI:
511 stub->insns[0] = 0x20200000;
512 stub->insns[1] = 0x34210000;
513 stub->insns[2] = 0x50210020;
514 stub->insns[3] = 0xe820d002;
515
516 stub->insns[0] |= reassemble_21(lrsel(value, addend));
517 stub->insns[1] |= reassemble_14(rrsel(value, addend));
518 break;
519 case ELF_STUB_DIRECT:
520 stub->insns[0] = 0x20200000;
521 stub->insns[1] = 0x34210000;
522 stub->insns[2] = 0xe820d002;
523
524 stub->insns[0] |= reassemble_21(lrsel(value, addend));
525 stub->insns[1] |= reassemble_14(rrsel(value, addend));
526 break;
527 }
528
529#endif
530
531 return (Elf_Addr)stub;
532}
533
534int apply_relocate(Elf_Shdr *sechdrs,
535 const char *strtab,
536 unsigned int symindex,
537 unsigned int relsec,
538 struct module *me)
539{
540
541 printk(KERN_ERR "module %s: RELOCATION unsupported\n",
542 me->name);
543 return -ENOEXEC;
544}
545
546#ifndef CONFIG_64BIT
547int apply_relocate_add(Elf_Shdr *sechdrs,
548 const char *strtab,
549 unsigned int symindex,
550 unsigned int relsec,
551 struct module *me)
552{
553 int i;
554 Elf32_Rela *rel = (void *)sechdrs[relsec].sh_addr;
555 Elf32_Sym *sym;
556 Elf32_Word *loc;
557 Elf32_Addr val;
558 Elf32_Sword addend;
559 Elf32_Addr dot;
560 Elf_Addr loc0;
561 unsigned int targetsec = sechdrs[relsec].sh_info;
562
563 register unsigned long dp asm ("r27");
564
565 DEBUGP("Applying relocate section %u to %u\n", relsec,
566 targetsec);
567 for (i = 0; i < sechdrs[relsec].sh_size / sizeof(*rel); i++) {
568
569 loc = (void *)sechdrs[targetsec].sh_addr
570 + rel[i].r_offset;
571
572 loc0 = sechdrs[targetsec].sh_addr;
573
574 sym = (Elf32_Sym *)sechdrs[symindex].sh_addr
575 + ELF32_R_SYM(rel[i].r_info);
576 if (!sym->st_value) {
577 printk(KERN_WARNING "%s: Unknown symbol %s\n",
578 me->name, strtab + sym->st_name);
579 return -ENOENT;
580 }
581
582 dot = (Elf32_Addr)loc & ~0x03;
583
584 val = sym->st_value;
585 addend = rel[i].r_addend;
586
587#if 0
588#define r(t) ELF32_R_TYPE(rel[i].r_info)==t ? #t :
589 DEBUGP("Symbol %s loc 0x%x val 0x%x addend 0x%x: %s\n",
590 strtab + sym->st_name,
591 (uint32_t)loc, val, addend,
592 r(R_PARISC_PLABEL32)
593 r(R_PARISC_DIR32)
594 r(R_PARISC_DIR21L)
595 r(R_PARISC_DIR14R)
596 r(R_PARISC_SEGREL32)
597 r(R_PARISC_DPREL21L)
598 r(R_PARISC_DPREL14R)
599 r(R_PARISC_PCREL17F)
600 r(R_PARISC_PCREL22F)
601 "UNKNOWN");
602#undef r
603#endif
604
605 switch (ELF32_R_TYPE(rel[i].r_info)) {
606 case R_PARISC_PLABEL32:
607
608
609 *loc = fsel(val, addend);
610 break;
611 case R_PARISC_DIR32:
612
613 *loc = fsel(val, addend);
614 break;
615 case R_PARISC_DIR21L:
616
617 val = lrsel(val, addend);
618 *loc = mask(*loc, 21) | reassemble_21(val);
619 break;
620 case R_PARISC_DIR14R:
621
622 val = rrsel(val, addend);
623 *loc = mask(*loc, 14) | reassemble_14(val);
624 break;
625 case R_PARISC_SEGREL32:
626
627
628
629
630 *loc = fsel(val, addend);
631 break;
632 case R_PARISC_DPREL21L:
633
634 val = lrsel(val - dp, addend);
635 *loc = mask(*loc, 21) | reassemble_21(val);
636 break;
637 case R_PARISC_DPREL14R:
638
639 val = rrsel(val - dp, addend);
640 *loc = mask(*loc, 14) | reassemble_14(val);
641 break;
642 case R_PARISC_PCREL17F:
643
644
645 val += addend;
646 val = (val - dot - 8)/4;
647 if (!RELOC_REACHABLE(val, 17)) {
648
649
650 val = get_stub(me, sym->st_value, addend,
651 ELF_STUB_DIRECT, loc0, targetsec);
652 val = (val - dot - 8)/4;
653 CHECK_RELOC(val, 17);
654 }
655 *loc = (*loc & ~0x1f1ffd) | reassemble_17(val);
656 break;
657 case R_PARISC_PCREL22F:
658
659
660 val += addend;
661 val = (val - dot - 8)/4;
662 if (!RELOC_REACHABLE(val, 22)) {
663
664
665 val = get_stub(me, sym->st_value, addend,
666 ELF_STUB_DIRECT, loc0, targetsec);
667 val = (val - dot - 8)/4;
668 CHECK_RELOC(val, 22);
669 }
670 *loc = (*loc & ~0x3ff1ffd) | reassemble_22(val);
671 break;
672
673 default:
674 printk(KERN_ERR "module %s: Unknown relocation: %u\n",
675 me->name, ELF32_R_TYPE(rel[i].r_info));
676 return -ENOEXEC;
677 }
678 }
679
680 return 0;
681}
682
683#else
684int apply_relocate_add(Elf_Shdr *sechdrs,
685 const char *strtab,
686 unsigned int symindex,
687 unsigned int relsec,
688 struct module *me)
689{
690 int i;
691 Elf64_Rela *rel = (void *)sechdrs[relsec].sh_addr;
692 Elf64_Sym *sym;
693 Elf64_Word *loc;
694 Elf64_Xword *loc64;
695 Elf64_Addr val;
696 Elf64_Sxword addend;
697 Elf64_Addr dot;
698 Elf_Addr loc0;
699 unsigned int targetsec = sechdrs[relsec].sh_info;
700
701 DEBUGP("Applying relocate section %u to %u\n", relsec,
702 targetsec);
703 for (i = 0; i < sechdrs[relsec].sh_size / sizeof(*rel); i++) {
704
705 loc = (void *)sechdrs[targetsec].sh_addr
706 + rel[i].r_offset;
707
708 loc0 = sechdrs[targetsec].sh_addr;
709
710 sym = (Elf64_Sym *)sechdrs[symindex].sh_addr
711 + ELF64_R_SYM(rel[i].r_info);
712 if (!sym->st_value) {
713 printk(KERN_WARNING "%s: Unknown symbol %s\n",
714 me->name, strtab + sym->st_name);
715 return -ENOENT;
716 }
717
718 dot = (Elf64_Addr)loc & ~0x03;
719 loc64 = (Elf64_Xword *)loc;
720
721 val = sym->st_value;
722 addend = rel[i].r_addend;
723
724#if 0
725#define r(t) ELF64_R_TYPE(rel[i].r_info)==t ? #t :
726 printk("Symbol %s loc %p val 0x%Lx addend 0x%Lx: %s\n",
727 strtab + sym->st_name,
728 loc, val, addend,
729 r(R_PARISC_LTOFF14R)
730 r(R_PARISC_LTOFF21L)
731 r(R_PARISC_PCREL22F)
732 r(R_PARISC_DIR64)
733 r(R_PARISC_SEGREL32)
734 r(R_PARISC_FPTR64)
735 "UNKNOWN");
736#undef r
737#endif
738
739 switch (ELF64_R_TYPE(rel[i].r_info)) {
740 case R_PARISC_LTOFF21L:
741
742 val = get_got(me, val, addend);
743 DEBUGP("LTOFF21L Symbol %s loc %p val %lx\n",
744 strtab + sym->st_name,
745 loc, val);
746 val = lrsel(val, 0);
747 *loc = mask(*loc, 21) | reassemble_21(val);
748 break;
749 case R_PARISC_LTOFF14R:
750
751
752 val = get_got(me, val, addend);
753 val = rrsel(val, 0);
754 DEBUGP("LTOFF14R Symbol %s loc %p val %lx\n",
755 strtab + sym->st_name,
756 loc, val);
757 *loc = mask(*loc, 14) | reassemble_14(val);
758 break;
759 case R_PARISC_PCREL22F:
760
761 DEBUGP("PCREL22F Symbol %s loc %p val %lx\n",
762 strtab + sym->st_name,
763 loc, val);
764 val += addend;
765
766 if (in_local(me, (void *)val)) {
767
768
769
770
771 val = (val - dot - 8)/4;
772 if (!RELOC_REACHABLE(val, 22)) {
773
774
775 val = get_stub(me, sym->st_value,
776 addend, ELF_STUB_DIRECT,
777 loc0, targetsec);
778 } else {
779
780 val = sym->st_value;
781 val += addend;
782 }
783 } else {
784 val = sym->st_value;
785 if (strncmp(strtab + sym->st_name, "$$", 2)
786 == 0)
787 val = get_stub(me, val, addend, ELF_STUB_MILLI,
788 loc0, targetsec);
789 else
790 val = get_stub(me, val, addend, ELF_STUB_GOT,
791 loc0, targetsec);
792 }
793 DEBUGP("STUB FOR %s loc %lx, val %lx+%lx at %lx\n",
794 strtab + sym->st_name, loc, sym->st_value,
795 addend, val);
796 val = (val - dot - 8)/4;
797 CHECK_RELOC(val, 22);
798 *loc = (*loc & ~0x3ff1ffd) | reassemble_22(val);
799 break;
800 case R_PARISC_DIR64:
801
802 *loc64 = val + addend;
803 break;
804 case R_PARISC_SEGREL32:
805
806
807
808
809 *loc = fsel(val, addend);
810 break;
811 case R_PARISC_FPTR64:
812
813 if(in_local(me, (void *)(val + addend))) {
814 *loc64 = get_fdesc(me, val+addend);
815 DEBUGP("FDESC for %s at %p points to %lx\n",
816 strtab + sym->st_name, *loc64,
817 ((Elf_Fdesc *)*loc64)->addr);
818 } else {
819
820
821
822 DEBUGP("Non local FPTR64 Symbol %s loc %p val %lx\n",
823 strtab + sym->st_name,
824 loc, val);
825 *loc64 = val + addend;
826 }
827 break;
828
829 default:
830 printk(KERN_ERR "module %s: Unknown relocation: %Lu\n",
831 me->name, ELF64_R_TYPE(rel[i].r_info));
832 return -ENOEXEC;
833 }
834 }
835 return 0;
836}
837#endif
838
839static void
840register_unwind_table(struct module *me,
841 const Elf_Shdr *sechdrs)
842{
843 unsigned char *table, *end;
844 unsigned long gp;
845
846 if (!me->arch.unwind_section)
847 return;
848
849 table = (unsigned char *)sechdrs[me->arch.unwind_section].sh_addr;
850 end = table + sechdrs[me->arch.unwind_section].sh_size;
851 gp = (Elf_Addr)me->module_core + me->arch.got_offset;
852
853 DEBUGP("register_unwind_table(), sect = %d at 0x%p - 0x%p (gp=0x%lx)\n",
854 me->arch.unwind_section, table, end, gp);
855 me->arch.unwind = unwind_table_add(me->name, 0, gp, table, end);
856}
857
858static void
859deregister_unwind_table(struct module *me)
860{
861 if (me->arch.unwind)
862 unwind_table_remove(me->arch.unwind);
863}
864
865int module_finalize(const Elf_Ehdr *hdr,
866 const Elf_Shdr *sechdrs,
867 struct module *me)
868{
869 int i;
870 unsigned long nsyms;
871 const char *strtab = NULL;
872 Elf_Sym *newptr, *oldptr;
873 Elf_Shdr *symhdr = NULL;
874#ifdef DEBUG
875 Elf_Fdesc *entry;
876 u32 *addr;
877
878 entry = (Elf_Fdesc *)me->init;
879 printk("FINALIZE, ->init FPTR is %p, GP %lx ADDR %lx\n", entry,
880 entry->gp, entry->addr);
881 addr = (u32 *)entry->addr;
882 printk("INSNS: %x %x %x %x\n",
883 addr[0], addr[1], addr[2], addr[3]);
884 printk("got entries used %ld, gots max %ld\n"
885 "fdescs used %ld, fdescs max %ld\n",
886 me->arch.got_count, me->arch.got_max,
887 me->arch.fdesc_count, me->arch.fdesc_max);
888#endif
889
890 register_unwind_table(me, sechdrs);
891
892
893
894 for (i = 1; i < hdr->e_shnum; i++) {
895 if(sechdrs[i].sh_type == SHT_SYMTAB
896 && (sechdrs[i].sh_flags & SHF_ALLOC)) {
897 int strindex = sechdrs[i].sh_link;
898
899
900
901 symhdr = (Elf_Shdr *)&sechdrs[i];
902 strtab = (char *)sechdrs[strindex].sh_addr;
903 break;
904 }
905 }
906
907 DEBUGP("module %s: strtab %p, symhdr %p\n",
908 me->name, strtab, symhdr);
909
910 if(me->arch.got_count > MAX_GOTS) {
911 printk(KERN_ERR "%s: Global Offset Table overflow (used %ld, allowed %d)\n",
912 me->name, me->arch.got_count, MAX_GOTS);
913 return -EINVAL;
914 }
915
916 kfree(me->arch.section);
917 me->arch.section = NULL;
918
919
920 if(symhdr == NULL)
921 return 0;
922
923 oldptr = (void *)symhdr->sh_addr;
924 newptr = oldptr + 1;
925 nsyms = symhdr->sh_size / sizeof(Elf_Sym);
926 DEBUGP("OLD num_symtab %lu\n", nsyms);
927
928 for (i = 1; i < nsyms; i++) {
929 oldptr++;
930 if(strncmp(strtab + oldptr->st_name,
931 ".L", 2) == 0)
932 continue;
933
934 if(newptr != oldptr)
935 *newptr++ = *oldptr;
936 else
937 newptr++;
938
939 }
940 nsyms = newptr - (Elf_Sym *)symhdr->sh_addr;
941 DEBUGP("NEW num_symtab %lu\n", nsyms);
942 symhdr->sh_size = nsyms * sizeof(Elf_Sym);
943 return module_bug_finalize(hdr, sechdrs, me);
944}
945
946void module_arch_cleanup(struct module *mod)
947{
948 deregister_unwind_table(mod);
949 module_bug_cleanup(mod);
950}
951