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, 0, NUMA_NO_NODE,
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
301void module_arch_freeing_init(struct module *mod)
302{
303 kfree(mod->arch.section);
304 mod->arch.section = NULL;
305}
306
307
308unsigned int arch_mod_section_prepend(struct module *mod,
309 unsigned int section)
310{
311
312
313 return (mod->arch.section[section].stub_entries + 1)
314 * sizeof(struct stub_entry);
315}
316
317#define CONST
318int module_frob_arch_sections(CONST Elf_Ehdr *hdr,
319 CONST Elf_Shdr *sechdrs,
320 CONST char *secstrings,
321 struct module *me)
322{
323 unsigned long gots = 0, fdescs = 0, len;
324 unsigned int i;
325
326 len = hdr->e_shnum * sizeof(me->arch.section[0]);
327 me->arch.section = kzalloc(len, GFP_KERNEL);
328 if (!me->arch.section)
329 return -ENOMEM;
330
331 for (i = 1; i < hdr->e_shnum; i++) {
332 const Elf_Rela *rels = (void *)sechdrs[i].sh_addr;
333 unsigned long nrels = sechdrs[i].sh_size / sizeof(*rels);
334 unsigned int count, s;
335
336 if (strncmp(secstrings + sechdrs[i].sh_name,
337 ".PARISC.unwind", 14) == 0)
338 me->arch.unwind_section = i;
339
340 if (sechdrs[i].sh_type != SHT_RELA)
341 continue;
342
343
344
345
346
347
348 gots += count_gots(rels, nrels);
349 fdescs += count_fdescs(rels, nrels);
350
351
352
353
354 count = count_stubs(rels, nrels);
355 if (!count)
356 continue;
357
358
359
360 s = sechdrs[i].sh_info;
361
362
363 WARN_ON(me->arch.section[s].stub_entries);
364
365
366 me->arch.section[s].stub_entries += count;
367 }
368
369
370 me->core_size = ALIGN(me->core_size, 16);
371 me->arch.got_offset = me->core_size;
372 me->core_size += gots * sizeof(struct got_entry);
373
374 me->core_size = ALIGN(me->core_size, 16);
375 me->arch.fdesc_offset = me->core_size;
376 me->core_size += fdescs * sizeof(Elf_Fdesc);
377
378 me->arch.got_max = gots;
379 me->arch.fdesc_max = fdescs;
380
381 return 0;
382}
383
384#ifdef CONFIG_64BIT
385static Elf64_Word get_got(struct module *me, unsigned long value, long addend)
386{
387 unsigned int i;
388 struct got_entry *got;
389
390 value += addend;
391
392 BUG_ON(value == 0);
393
394 got = me->module_core + me->arch.got_offset;
395 for (i = 0; got[i].addr; i++)
396 if (got[i].addr == value)
397 goto out;
398
399 BUG_ON(++me->arch.got_count > me->arch.got_max);
400
401 got[i].addr = value;
402 out:
403 DEBUGP("GOT ENTRY %d[%x] val %lx\n", i, i*sizeof(struct got_entry),
404 value);
405 return i * sizeof(struct got_entry);
406}
407#endif
408
409#ifdef CONFIG_64BIT
410static Elf_Addr get_fdesc(struct module *me, unsigned long value)
411{
412 Elf_Fdesc *fdesc = me->module_core + me->arch.fdesc_offset;
413
414 if (!value) {
415 printk(KERN_ERR "%s: zero OPD requested!\n", me->name);
416 return 0;
417 }
418
419
420 while (fdesc->addr) {
421 if (fdesc->addr == value)
422 return (Elf_Addr)fdesc;
423 fdesc++;
424 }
425
426 BUG_ON(++me->arch.fdesc_count > me->arch.fdesc_max);
427
428
429 fdesc->addr = value;
430 fdesc->gp = (Elf_Addr)me->module_core + me->arch.got_offset;
431 return (Elf_Addr)fdesc;
432}
433#endif
434
435enum elf_stub_type {
436 ELF_STUB_GOT,
437 ELF_STUB_MILLI,
438 ELF_STUB_DIRECT,
439};
440
441static Elf_Addr get_stub(struct module *me, unsigned long value, long addend,
442 enum elf_stub_type stub_type, Elf_Addr loc0, unsigned int targetsec)
443{
444 struct stub_entry *stub;
445 int __maybe_unused d;
446
447
448 if (!me->arch.section[targetsec].stub_offset) {
449 loc0 -= (me->arch.section[targetsec].stub_entries + 1) *
450 sizeof(struct stub_entry);
451
452 loc0 = ALIGN(loc0, sizeof(struct stub_entry));
453 me->arch.section[targetsec].stub_offset = loc0;
454 }
455
456
457 stub = (void *) me->arch.section[targetsec].stub_offset;
458 me->arch.section[targetsec].stub_offset += sizeof(struct stub_entry);
459
460
461 BUG_ON(0 == me->arch.section[targetsec].stub_entries--);
462
463
464#ifndef CONFIG_64BIT
465
466
467
468
469
470
471 stub->insns[0] = 0x20200000;
472 stub->insns[1] = 0xe0202002;
473
474 stub->insns[0] |= reassemble_21(lrsel(value, addend));
475 stub->insns[1] |= reassemble_17(rrsel(value, addend) / 4);
476
477#else
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497 switch (stub_type) {
498 case ELF_STUB_GOT:
499 d = get_got(me, value, addend);
500 if (d <= 15) {
501
502 stub->insns[0] = 0x0f6010db;
503 stub->insns[0] |= low_sign_unext(d, 5) << 16;
504 } else {
505
506 stub->insns[0] = 0x537b0000;
507 stub->insns[0] |= reassemble_16a(d);
508 }
509 stub->insns[1] = 0x53610020;
510 stub->insns[2] = 0xe820d000;
511 stub->insns[3] = 0x537b0030;
512 break;
513 case ELF_STUB_MILLI:
514 stub->insns[0] = 0x20200000;
515 stub->insns[1] = 0x34210000;
516 stub->insns[2] = 0x50210020;
517 stub->insns[3] = 0xe820d002;
518
519 stub->insns[0] |= reassemble_21(lrsel(value, addend));
520 stub->insns[1] |= reassemble_14(rrsel(value, addend));
521 break;
522 case ELF_STUB_DIRECT:
523 stub->insns[0] = 0x20200000;
524 stub->insns[1] = 0x34210000;
525 stub->insns[2] = 0xe820d002;
526
527 stub->insns[0] |= reassemble_21(lrsel(value, addend));
528 stub->insns[1] |= reassemble_14(rrsel(value, addend));
529 break;
530 }
531
532#endif
533
534 return (Elf_Addr)stub;
535}
536
537#ifndef CONFIG_64BIT
538int apply_relocate_add(Elf_Shdr *sechdrs,
539 const char *strtab,
540 unsigned int symindex,
541 unsigned int relsec,
542 struct module *me)
543{
544 int i;
545 Elf32_Rela *rel = (void *)sechdrs[relsec].sh_addr;
546 Elf32_Sym *sym;
547 Elf32_Word *loc;
548 Elf32_Addr val;
549 Elf32_Sword addend;
550 Elf32_Addr dot;
551 Elf_Addr loc0;
552 unsigned int targetsec = sechdrs[relsec].sh_info;
553
554 register unsigned long dp asm ("r27");
555
556 DEBUGP("Applying relocate section %u to %u\n", relsec,
557 targetsec);
558 for (i = 0; i < sechdrs[relsec].sh_size / sizeof(*rel); i++) {
559
560 loc = (void *)sechdrs[targetsec].sh_addr
561 + rel[i].r_offset;
562
563 loc0 = sechdrs[targetsec].sh_addr;
564
565 sym = (Elf32_Sym *)sechdrs[symindex].sh_addr
566 + ELF32_R_SYM(rel[i].r_info);
567 if (!sym->st_value) {
568 printk(KERN_WARNING "%s: Unknown symbol %s\n",
569 me->name, strtab + sym->st_name);
570 return -ENOENT;
571 }
572
573 dot = (Elf32_Addr)loc & ~0x03;
574
575 val = sym->st_value;
576 addend = rel[i].r_addend;
577
578#if 0
579#define r(t) ELF32_R_TYPE(rel[i].r_info)==t ? #t :
580 DEBUGP("Symbol %s loc 0x%x val 0x%x addend 0x%x: %s\n",
581 strtab + sym->st_name,
582 (uint32_t)loc, val, addend,
583 r(R_PARISC_PLABEL32)
584 r(R_PARISC_DIR32)
585 r(R_PARISC_DIR21L)
586 r(R_PARISC_DIR14R)
587 r(R_PARISC_SEGREL32)
588 r(R_PARISC_DPREL21L)
589 r(R_PARISC_DPREL14R)
590 r(R_PARISC_PCREL17F)
591 r(R_PARISC_PCREL22F)
592 "UNKNOWN");
593#undef r
594#endif
595
596 switch (ELF32_R_TYPE(rel[i].r_info)) {
597 case R_PARISC_PLABEL32:
598
599
600 *loc = fsel(val, addend);
601 break;
602 case R_PARISC_DIR32:
603
604 *loc = fsel(val, addend);
605 break;
606 case R_PARISC_DIR21L:
607
608 val = lrsel(val, addend);
609 *loc = mask(*loc, 21) | reassemble_21(val);
610 break;
611 case R_PARISC_DIR14R:
612
613 val = rrsel(val, addend);
614 *loc = mask(*loc, 14) | reassemble_14(val);
615 break;
616 case R_PARISC_SEGREL32:
617
618
619
620
621 *loc = fsel(val, addend);
622 break;
623 case R_PARISC_DPREL21L:
624
625 val = lrsel(val - dp, addend);
626 *loc = mask(*loc, 21) | reassemble_21(val);
627 break;
628 case R_PARISC_DPREL14R:
629
630 val = rrsel(val - dp, addend);
631 *loc = mask(*loc, 14) | reassemble_14(val);
632 break;
633 case R_PARISC_PCREL17F:
634
635
636 val += addend;
637 val = (val - dot - 8)/4;
638 if (!RELOC_REACHABLE(val, 17)) {
639
640
641 val = get_stub(me, sym->st_value, addend,
642 ELF_STUB_DIRECT, loc0, targetsec);
643 val = (val - dot - 8)/4;
644 CHECK_RELOC(val, 17);
645 }
646 *loc = (*loc & ~0x1f1ffd) | reassemble_17(val);
647 break;
648 case R_PARISC_PCREL22F:
649
650
651 val += addend;
652 val = (val - dot - 8)/4;
653 if (!RELOC_REACHABLE(val, 22)) {
654
655
656 val = get_stub(me, sym->st_value, addend,
657 ELF_STUB_DIRECT, loc0, targetsec);
658 val = (val - dot - 8)/4;
659 CHECK_RELOC(val, 22);
660 }
661 *loc = (*loc & ~0x3ff1ffd) | reassemble_22(val);
662 break;
663
664 default:
665 printk(KERN_ERR "module %s: Unknown relocation: %u\n",
666 me->name, ELF32_R_TYPE(rel[i].r_info));
667 return -ENOEXEC;
668 }
669 }
670
671 return 0;
672}
673
674#else
675int apply_relocate_add(Elf_Shdr *sechdrs,
676 const char *strtab,
677 unsigned int symindex,
678 unsigned int relsec,
679 struct module *me)
680{
681 int i;
682 Elf64_Rela *rel = (void *)sechdrs[relsec].sh_addr;
683 Elf64_Sym *sym;
684 Elf64_Word *loc;
685 Elf64_Xword *loc64;
686 Elf64_Addr val;
687 Elf64_Sxword addend;
688 Elf64_Addr dot;
689 Elf_Addr loc0;
690 unsigned int targetsec = sechdrs[relsec].sh_info;
691
692 DEBUGP("Applying relocate section %u to %u\n", relsec,
693 targetsec);
694 for (i = 0; i < sechdrs[relsec].sh_size / sizeof(*rel); i++) {
695
696 loc = (void *)sechdrs[targetsec].sh_addr
697 + rel[i].r_offset;
698
699 loc0 = sechdrs[targetsec].sh_addr;
700
701 sym = (Elf64_Sym *)sechdrs[symindex].sh_addr
702 + ELF64_R_SYM(rel[i].r_info);
703 if (!sym->st_value) {
704 printk(KERN_WARNING "%s: Unknown symbol %s\n",
705 me->name, strtab + sym->st_name);
706 return -ENOENT;
707 }
708
709 dot = (Elf64_Addr)loc & ~0x03;
710 loc64 = (Elf64_Xword *)loc;
711
712 val = sym->st_value;
713 addend = rel[i].r_addend;
714
715#if 0
716#define r(t) ELF64_R_TYPE(rel[i].r_info)==t ? #t :
717 printk("Symbol %s loc %p val 0x%Lx addend 0x%Lx: %s\n",
718 strtab + sym->st_name,
719 loc, val, addend,
720 r(R_PARISC_LTOFF14R)
721 r(R_PARISC_LTOFF21L)
722 r(R_PARISC_PCREL22F)
723 r(R_PARISC_DIR64)
724 r(R_PARISC_SEGREL32)
725 r(R_PARISC_FPTR64)
726 "UNKNOWN");
727#undef r
728#endif
729
730 switch (ELF64_R_TYPE(rel[i].r_info)) {
731 case R_PARISC_LTOFF21L:
732
733 val = get_got(me, val, addend);
734 DEBUGP("LTOFF21L Symbol %s loc %p val %lx\n",
735 strtab + sym->st_name,
736 loc, val);
737 val = lrsel(val, 0);
738 *loc = mask(*loc, 21) | reassemble_21(val);
739 break;
740 case R_PARISC_LTOFF14R:
741
742
743 val = get_got(me, val, addend);
744 val = rrsel(val, 0);
745 DEBUGP("LTOFF14R Symbol %s loc %p val %lx\n",
746 strtab + sym->st_name,
747 loc, val);
748 *loc = mask(*loc, 14) | reassemble_14(val);
749 break;
750 case R_PARISC_PCREL22F:
751
752 DEBUGP("PCREL22F Symbol %s loc %p val %lx\n",
753 strtab + sym->st_name,
754 loc, val);
755 val += addend;
756
757 if (in_local(me, (void *)val)) {
758
759
760
761
762 val = (val - dot - 8)/4;
763 if (!RELOC_REACHABLE(val, 22)) {
764
765
766 val = get_stub(me, sym->st_value,
767 addend, ELF_STUB_DIRECT,
768 loc0, targetsec);
769 } else {
770
771 val = sym->st_value;
772 val += addend;
773 }
774 } else {
775 val = sym->st_value;
776 if (strncmp(strtab + sym->st_name, "$$", 2)
777 == 0)
778 val = get_stub(me, val, addend, ELF_STUB_MILLI,
779 loc0, targetsec);
780 else
781 val = get_stub(me, val, addend, ELF_STUB_GOT,
782 loc0, targetsec);
783 }
784 DEBUGP("STUB FOR %s loc %lx, val %lx+%lx at %lx\n",
785 strtab + sym->st_name, loc, sym->st_value,
786 addend, val);
787 val = (val - dot - 8)/4;
788 CHECK_RELOC(val, 22);
789 *loc = (*loc & ~0x3ff1ffd) | reassemble_22(val);
790 break;
791 case R_PARISC_DIR64:
792
793 *loc64 = val + addend;
794 break;
795 case R_PARISC_SEGREL32:
796
797
798
799
800 *loc = fsel(val, addend);
801 break;
802 case R_PARISC_FPTR64:
803
804 if(in_local(me, (void *)(val + addend))) {
805 *loc64 = get_fdesc(me, val+addend);
806 DEBUGP("FDESC for %s at %p points to %lx\n",
807 strtab + sym->st_name, *loc64,
808 ((Elf_Fdesc *)*loc64)->addr);
809 } else {
810
811
812
813 DEBUGP("Non local FPTR64 Symbol %s loc %p val %lx\n",
814 strtab + sym->st_name,
815 loc, val);
816 *loc64 = val + addend;
817 }
818 break;
819
820 default:
821 printk(KERN_ERR "module %s: Unknown relocation: %Lu\n",
822 me->name, ELF64_R_TYPE(rel[i].r_info));
823 return -ENOEXEC;
824 }
825 }
826 return 0;
827}
828#endif
829
830static void
831register_unwind_table(struct module *me,
832 const Elf_Shdr *sechdrs)
833{
834 unsigned char *table, *end;
835 unsigned long gp;
836
837 if (!me->arch.unwind_section)
838 return;
839
840 table = (unsigned char *)sechdrs[me->arch.unwind_section].sh_addr;
841 end = table + sechdrs[me->arch.unwind_section].sh_size;
842 gp = (Elf_Addr)me->module_core + me->arch.got_offset;
843
844 DEBUGP("register_unwind_table(), sect = %d at 0x%p - 0x%p (gp=0x%lx)\n",
845 me->arch.unwind_section, table, end, gp);
846 me->arch.unwind = unwind_table_add(me->name, 0, gp, table, end);
847}
848
849static void
850deregister_unwind_table(struct module *me)
851{
852 if (me->arch.unwind)
853 unwind_table_remove(me->arch.unwind);
854}
855
856int module_finalize(const Elf_Ehdr *hdr,
857 const Elf_Shdr *sechdrs,
858 struct module *me)
859{
860 int i;
861 unsigned long nsyms;
862 const char *strtab = NULL;
863 Elf_Sym *newptr, *oldptr;
864 Elf_Shdr *symhdr = NULL;
865#ifdef DEBUG
866 Elf_Fdesc *entry;
867 u32 *addr;
868
869 entry = (Elf_Fdesc *)me->init;
870 printk("FINALIZE, ->init FPTR is %p, GP %lx ADDR %lx\n", entry,
871 entry->gp, entry->addr);
872 addr = (u32 *)entry->addr;
873 printk("INSNS: %x %x %x %x\n",
874 addr[0], addr[1], addr[2], addr[3]);
875 printk("got entries used %ld, gots max %ld\n"
876 "fdescs used %ld, fdescs max %ld\n",
877 me->arch.got_count, me->arch.got_max,
878 me->arch.fdesc_count, me->arch.fdesc_max);
879#endif
880
881 register_unwind_table(me, sechdrs);
882
883
884
885 for (i = 1; i < hdr->e_shnum; i++) {
886 if(sechdrs[i].sh_type == SHT_SYMTAB
887 && (sechdrs[i].sh_flags & SHF_ALLOC)) {
888 int strindex = sechdrs[i].sh_link;
889
890
891
892 symhdr = (Elf_Shdr *)&sechdrs[i];
893 strtab = (char *)sechdrs[strindex].sh_addr;
894 break;
895 }
896 }
897
898 DEBUGP("module %s: strtab %p, symhdr %p\n",
899 me->name, strtab, symhdr);
900
901 if(me->arch.got_count > MAX_GOTS) {
902 printk(KERN_ERR "%s: Global Offset Table overflow (used %ld, allowed %d)\n",
903 me->name, me->arch.got_count, MAX_GOTS);
904 return -EINVAL;
905 }
906
907 kfree(me->arch.section);
908 me->arch.section = NULL;
909
910
911 if(symhdr == NULL)
912 return 0;
913
914 oldptr = (void *)symhdr->sh_addr;
915 newptr = oldptr + 1;
916 nsyms = symhdr->sh_size / sizeof(Elf_Sym);
917 DEBUGP("OLD num_symtab %lu\n", nsyms);
918
919 for (i = 1; i < nsyms; i++) {
920 oldptr++;
921 if(strncmp(strtab + oldptr->st_name,
922 ".L", 2) == 0)
923 continue;
924
925 if(newptr != oldptr)
926 *newptr++ = *oldptr;
927 else
928 newptr++;
929
930 }
931 nsyms = newptr - (Elf_Sym *)symhdr->sh_addr;
932 DEBUGP("NEW num_symtab %lu\n", nsyms);
933 symhdr->sh_size = nsyms * sizeof(Elf_Sym);
934 return 0;
935}
936
937void module_arch_cleanup(struct module *mod)
938{
939 deregister_unwind_table(mod);
940}
941