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