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