Skip to content

Commit 3f63ac8

Browse files
committed
LoongArch: Adjust module loader for 32BIT/64BIT
Adjust module loader for both 32BIT and 64BIT, including: change the s64 type to long, change the u64 type to unsigned long, change the plt entry definition and handling, etc. Reviewed-by: Arnd Bergmann <arnd@arndb.de> Signed-off-by: Jiaxun Yang <jiaxun.yang@flygoat.com> Signed-off-by: Huacai Chen <chenhuacai@loongson.cn>
1 parent ced7814 commit 3f63ac8

4 files changed

Lines changed: 163 additions & 55 deletions

File tree

arch/loongarch/include/asm/module.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,10 @@ struct got_entry {
3838

3939
struct plt_entry {
4040
u32 inst_lu12iw;
41+
#ifdef CONFIG_64BIT
4142
u32 inst_lu32id;
4243
u32 inst_lu52id;
44+
#endif
4345
u32 inst_jirl;
4446
};
4547

@@ -57,6 +59,14 @@ static inline struct got_entry emit_got_entry(Elf_Addr val)
5759

5860
static inline struct plt_entry emit_plt_entry(unsigned long val)
5961
{
62+
#ifdef CONFIG_32BIT
63+
u32 lu12iw, jirl;
64+
65+
lu12iw = larch_insn_gen_lu12iw(LOONGARCH_GPR_T1, ADDR_IMM(val, LU12IW));
66+
jirl = larch_insn_gen_jirl(0, LOONGARCH_GPR_T1, ADDR_IMM(val, ORI));
67+
68+
return (struct plt_entry) { lu12iw, jirl };
69+
#else
6070
u32 lu12iw, lu32id, lu52id, jirl;
6171

6272
lu12iw = larch_insn_gen_lu12iw(LOONGARCH_GPR_T1, ADDR_IMM(val, LU12IW));
@@ -65,6 +75,7 @@ static inline struct plt_entry emit_plt_entry(unsigned long val)
6575
jirl = larch_insn_gen_jirl(0, LOONGARCH_GPR_T1, ADDR_IMM(val, ORI));
6676

6777
return (struct plt_entry) { lu12iw, lu32id, lu52id, jirl };
78+
#endif
6879
}
6980

7081
static inline struct plt_idx_entry emit_plt_idx_entry(unsigned long val)

arch/loongarch/include/asm/percpu.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
* the loading address of main kernel image, but far from where the modules are
1414
* loaded. Tell the compiler this fact when using explicit relocs.
1515
*/
16-
#if defined(MODULE) && defined(CONFIG_AS_HAS_EXPLICIT_RELOCS)
16+
#if defined(MODULE) && defined(CONFIG_AS_HAS_EXPLICIT_RELOCS) && defined(CONFIG_64BIT)
1717
# if __has_attribute(model)
1818
# define PER_CPU_ATTRIBUTES __attribute__((model("extreme")))
1919
# else

arch/loongarch/kernel/module-sections.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ static void count_max_entries(Elf_Rela *relas, int num,
9393
(*plts)++;
9494
break;
9595
case R_LARCH_GOT_PC_HI20:
96+
case R_LARCH_GOT_PCADD_HI20:
9697
(*gots)++;
9798
break;
9899
default:

0 commit comments

Comments
 (0)