| .. | .. |
|---|
| 8 | 8 | #include <linux/elf.h> |
|---|
| 9 | 9 | #include <linux/kernel.h> |
|---|
| 10 | 10 | #include <linux/module.h> |
|---|
| 11 | +#include <linux/moduleloader.h> |
|---|
| 11 | 12 | |
|---|
| 12 | | -u64 module_emit_got_entry(struct module *mod, u64 val) |
|---|
| 13 | +unsigned long module_emit_got_entry(struct module *mod, unsigned long val) |
|---|
| 13 | 14 | { |
|---|
| 14 | 15 | struct mod_section *got_sec = &mod->arch.got; |
|---|
| 15 | 16 | int i = got_sec->num_entries; |
|---|
| 16 | 17 | struct got_entry *got = get_got_entry(val, got_sec); |
|---|
| 17 | 18 | |
|---|
| 18 | 19 | if (got) |
|---|
| 19 | | - return (u64)got; |
|---|
| 20 | + return (unsigned long)got; |
|---|
| 20 | 21 | |
|---|
| 21 | 22 | /* There is no duplicate entry, create a new one */ |
|---|
| 22 | 23 | got = (struct got_entry *)got_sec->shdr->sh_addr; |
|---|
| .. | .. |
|---|
| 25 | 26 | got_sec->num_entries++; |
|---|
| 26 | 27 | BUG_ON(got_sec->num_entries > got_sec->max_entries); |
|---|
| 27 | 28 | |
|---|
| 28 | | - return (u64)&got[i]; |
|---|
| 29 | + return (unsigned long)&got[i]; |
|---|
| 29 | 30 | } |
|---|
| 30 | 31 | |
|---|
| 31 | | -u64 module_emit_plt_entry(struct module *mod, u64 val) |
|---|
| 32 | +unsigned long module_emit_plt_entry(struct module *mod, unsigned long val) |
|---|
| 32 | 33 | { |
|---|
| 33 | 34 | struct mod_section *got_plt_sec = &mod->arch.got_plt; |
|---|
| 34 | 35 | struct got_entry *got_plt; |
|---|
| .. | .. |
|---|
| 37 | 38 | int i = plt_sec->num_entries; |
|---|
| 38 | 39 | |
|---|
| 39 | 40 | if (plt) |
|---|
| 40 | | - return (u64)plt; |
|---|
| 41 | + return (unsigned long)plt; |
|---|
| 41 | 42 | |
|---|
| 42 | 43 | /* There is no duplicate entry, create a new one */ |
|---|
| 43 | 44 | got_plt = (struct got_entry *)got_plt_sec->shdr->sh_addr; |
|---|
| 44 | 45 | got_plt[i] = emit_got_entry(val); |
|---|
| 45 | 46 | plt = (struct plt_entry *)plt_sec->shdr->sh_addr; |
|---|
| 46 | | - plt[i] = emit_plt_entry(val, (u64)&plt[i], (u64)&got_plt[i]); |
|---|
| 47 | + plt[i] = emit_plt_entry(val, |
|---|
| 48 | + (unsigned long)&plt[i], |
|---|
| 49 | + (unsigned long)&got_plt[i]); |
|---|
| 47 | 50 | |
|---|
| 48 | 51 | plt_sec->num_entries++; |
|---|
| 49 | 52 | got_plt_sec->num_entries++; |
|---|
| 50 | 53 | BUG_ON(plt_sec->num_entries > plt_sec->max_entries); |
|---|
| 51 | 54 | |
|---|
| 52 | | - return (u64)&plt[i]; |
|---|
| 55 | + return (unsigned long)&plt[i]; |
|---|
| 53 | 56 | } |
|---|
| 54 | 57 | |
|---|
| 55 | | -static int is_rela_equal(const Elf64_Rela *x, const Elf64_Rela *y) |
|---|
| 58 | +static int is_rela_equal(const Elf_Rela *x, const Elf_Rela *y) |
|---|
| 56 | 59 | { |
|---|
| 57 | 60 | return x->r_info == y->r_info && x->r_addend == y->r_addend; |
|---|
| 58 | 61 | } |
|---|
| 59 | 62 | |
|---|
| 60 | | -static bool duplicate_rela(const Elf64_Rela *rela, int idx) |
|---|
| 63 | +static bool duplicate_rela(const Elf_Rela *rela, int idx) |
|---|
| 61 | 64 | { |
|---|
| 62 | 65 | int i; |
|---|
| 63 | 66 | for (i = 0; i < idx; i++) { |
|---|
| .. | .. |
|---|
| 67 | 70 | return false; |
|---|
| 68 | 71 | } |
|---|
| 69 | 72 | |
|---|
| 70 | | -static void count_max_entries(Elf64_Rela *relas, int num, |
|---|
| 73 | +static void count_max_entries(Elf_Rela *relas, int num, |
|---|
| 71 | 74 | unsigned int *plts, unsigned int *gots) |
|---|
| 72 | 75 | { |
|---|
| 73 | 76 | unsigned int type, i; |
|---|
| 74 | 77 | |
|---|
| 75 | 78 | for (i = 0; i < num; i++) { |
|---|
| 76 | | - type = ELF64_R_TYPE(relas[i].r_info); |
|---|
| 79 | + type = ELF_RISCV_R_TYPE(relas[i].r_info); |
|---|
| 77 | 80 | if (type == R_RISCV_CALL_PLT) { |
|---|
| 78 | 81 | if (!duplicate_rela(relas, i)) |
|---|
| 79 | 82 | (*plts)++; |
|---|
| .. | .. |
|---|
| 118 | 121 | |
|---|
| 119 | 122 | /* Calculate the maxinum number of entries */ |
|---|
| 120 | 123 | for (i = 0; i < ehdr->e_shnum; i++) { |
|---|
| 121 | | - Elf64_Rela *relas = (void *)ehdr + sechdrs[i].sh_offset; |
|---|
| 122 | | - int num_rela = sechdrs[i].sh_size / sizeof(Elf64_Rela); |
|---|
| 123 | | - Elf64_Shdr *dst_sec = sechdrs + sechdrs[i].sh_info; |
|---|
| 124 | + Elf_Rela *relas = (void *)ehdr + sechdrs[i].sh_offset; |
|---|
| 125 | + int num_rela = sechdrs[i].sh_size / sizeof(Elf_Rela); |
|---|
| 126 | + Elf_Shdr *dst_sec = sechdrs + sechdrs[i].sh_info; |
|---|
| 124 | 127 | |
|---|
| 125 | 128 | if (sechdrs[i].sh_type != SHT_RELA) |
|---|
| 126 | 129 | continue; |
|---|