Skip to content

Commit 9a6a511

Browse files
RISC-V: Fix the rv32i kernel build
These patches for building 32-bit RISC-V kernel. - Fix the compile errors and warnings on RV32I. - Fix some incompatible problem on RV32I. - Add format.h for compatible of print format. The fixed width integer types format for Elf_Addr will move to generic header by another patch. For now, there are some warning about unexpected argument of type on RV32I. Change in v1: - Fix some error in v1 - Remove implementation of fixed width integer types format for Elf_Addr.
2 parents 1db9b80 + 7df8500 commit 9a6a511

File tree

4 files changed

+21
-13
lines changed

4 files changed

+21
-13
lines changed

arch/riscv/Kconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ config ARCH_RV32I
107107
select GENERIC_LIB_ASHLDI3
108108
select GENERIC_LIB_ASHRDI3
109109
select GENERIC_LIB_LSHRDI3
110+
select GENERIC_LIB_UCMPDI2
110111

111112
config ARCH_RV64I
112113
bool "RV64I"

arch/riscv/include/uapi/asm/elf.h

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,13 @@ typedef struct user_regs_struct elf_gregset_t;
2121

2222
typedef union __riscv_fp_state elf_fpregset_t;
2323

24-
#define ELF_RISCV_R_SYM(r_info) ((r_info) >> 32)
25-
#define ELF_RISCV_R_TYPE(r_info) ((r_info) & 0xffffffff)
24+
#if __riscv_xlen == 64
25+
#define ELF_RISCV_R_SYM(r_info) ELF64_R_SYM(r_info)
26+
#define ELF_RISCV_R_TYPE(r_info) ELF64_R_TYPE(r_info)
27+
#else
28+
#define ELF_RISCV_R_SYM(r_info) ELF32_R_SYM(r_info)
29+
#define ELF_RISCV_R_TYPE(r_info) ELF32_R_TYPE(r_info)
30+
#endif
2631

2732
/*
2833
* RISC-V relocation types

arch/riscv/kernel/module.c

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ static int apply_r_riscv_64_rela(struct module *me, u32 *location, Elf_Addr v)
3737
static int apply_r_riscv_branch_rela(struct module *me, u32 *location,
3838
Elf_Addr v)
3939
{
40-
s64 offset = (void *)v - (void *)location;
40+
ptrdiff_t offset = (void *)v - (void *)location;
4141
u32 imm12 = (offset & 0x1000) << (31 - 12);
4242
u32 imm11 = (offset & 0x800) >> (11 - 7);
4343
u32 imm10_5 = (offset & 0x7e0) << (30 - 10);
@@ -50,7 +50,7 @@ static int apply_r_riscv_branch_rela(struct module *me, u32 *location,
5050
static int apply_r_riscv_jal_rela(struct module *me, u32 *location,
5151
Elf_Addr v)
5252
{
53-
s64 offset = (void *)v - (void *)location;
53+
ptrdiff_t offset = (void *)v - (void *)location;
5454
u32 imm20 = (offset & 0x100000) << (31 - 20);
5555
u32 imm19_12 = (offset & 0xff000);
5656
u32 imm11 = (offset & 0x800) << (20 - 11);
@@ -63,7 +63,7 @@ static int apply_r_riscv_jal_rela(struct module *me, u32 *location,
6363
static int apply_r_riscv_rcv_branch_rela(struct module *me, u32 *location,
6464
Elf_Addr v)
6565
{
66-
s64 offset = (void *)v - (void *)location;
66+
ptrdiff_t offset = (void *)v - (void *)location;
6767
u16 imm8 = (offset & 0x100) << (12 - 8);
6868
u16 imm7_6 = (offset & 0xc0) >> (6 - 5);
6969
u16 imm5 = (offset & 0x20) >> (5 - 2);
@@ -78,7 +78,7 @@ static int apply_r_riscv_rcv_branch_rela(struct module *me, u32 *location,
7878
static int apply_r_riscv_rvc_jump_rela(struct module *me, u32 *location,
7979
Elf_Addr v)
8080
{
81-
s64 offset = (void *)v - (void *)location;
81+
ptrdiff_t offset = (void *)v - (void *)location;
8282
u16 imm11 = (offset & 0x800) << (12 - 11);
8383
u16 imm10 = (offset & 0x400) >> (10 - 8);
8484
u16 imm9_8 = (offset & 0x300) << (12 - 11);
@@ -96,7 +96,7 @@ static int apply_r_riscv_rvc_jump_rela(struct module *me, u32 *location,
9696
static int apply_r_riscv_pcrel_hi20_rela(struct module *me, u32 *location,
9797
Elf_Addr v)
9898
{
99-
s64 offset = (void *)v - (void *)location;
99+
ptrdiff_t offset = (void *)v - (void *)location;
100100
s32 hi20;
101101

102102
if (offset != (s32)offset) {
@@ -178,7 +178,7 @@ static int apply_r_riscv_lo12_s_rela(struct module *me, u32 *location,
178178
static int apply_r_riscv_got_hi20_rela(struct module *me, u32 *location,
179179
Elf_Addr v)
180180
{
181-
s64 offset = (void *)v - (void *)location;
181+
ptrdiff_t offset = (void *)v - (void *)location;
182182
s32 hi20;
183183

184184
/* Always emit the got entry */
@@ -200,7 +200,7 @@ static int apply_r_riscv_got_hi20_rela(struct module *me, u32 *location,
200200
static int apply_r_riscv_call_plt_rela(struct module *me, u32 *location,
201201
Elf_Addr v)
202202
{
203-
s64 offset = (void *)v - (void *)location;
203+
ptrdiff_t offset = (void *)v - (void *)location;
204204
s32 fill_v = offset;
205205
u32 hi20, lo12;
206206

@@ -227,7 +227,7 @@ static int apply_r_riscv_call_plt_rela(struct module *me, u32 *location,
227227
static int apply_r_riscv_call_rela(struct module *me, u32 *location,
228228
Elf_Addr v)
229229
{
230-
s64 offset = (void *)v - (void *)location;
230+
ptrdiff_t offset = (void *)v - (void *)location;
231231
s32 fill_v = offset;
232232
u32 hi20, lo12;
233233

@@ -347,7 +347,7 @@ int apply_relocate_add(Elf_Shdr *sechdrs, const char *strtab,
347347
unsigned int j;
348348

349349
for (j = 0; j < sechdrs[relsec].sh_size / sizeof(*rel); j++) {
350-
u64 hi20_loc =
350+
unsigned long hi20_loc =
351351
sechdrs[sechdrs[relsec].sh_info].sh_addr
352352
+ rel[j].r_offset;
353353
u32 hi20_type = ELF_RISCV_R_TYPE(rel[j].r_info);
@@ -360,12 +360,12 @@ int apply_relocate_add(Elf_Shdr *sechdrs, const char *strtab,
360360
Elf_Sym *hi20_sym =
361361
(Elf_Sym *)sechdrs[symindex].sh_addr
362362
+ ELF_RISCV_R_SYM(rel[j].r_info);
363-
u64 hi20_sym_val =
363+
unsigned long hi20_sym_val =
364364
hi20_sym->st_value
365365
+ rel[j].r_addend;
366366

367367
/* Calculate lo12 */
368-
u64 offset = hi20_sym_val - hi20_loc;
368+
size_t offset = hi20_sym_val - hi20_loc;
369369
if (IS_ENABLED(CONFIG_MODULE_SECTIONS)
370370
&& hi20_type == R_RISCV_GOT_HI20) {
371371
offset = module_emit_got_entry(

arch/riscv/mm/init.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,9 @@ static void __init zone_sizes_init(void)
2828
{
2929
unsigned long max_zone_pfns[MAX_NR_ZONES] = { 0, };
3030

31+
#ifdef CONFIG_ZONE_DMA32
3132
max_zone_pfns[ZONE_DMA32] = PFN_DOWN(min(4UL * SZ_1G, max_low_pfn));
33+
#endif
3234
max_zone_pfns[ZONE_NORMAL] = max_low_pfn;
3335

3436
free_area_init_nodes(max_zone_pfns);

0 commit comments

Comments
 (0)