From 41d8b2a5054975aa9042a2548a539568f0b4dad0 Mon Sep 17 00:00:00 2001 From: Yann MAGNIN Date: Wed, 1 Jun 2022 16:27:30 +0200 Subject: [PATCH] vxBoot - 1.2.4 : Fix relocation for non 4-aligned symbols' offset @fix <> CMakelist.txt : | dump project version <> loader/elf/rela : | fix exception when the relocalised symbols are not in a 4-aligned address --- CMakeLists.txt | 2 +- src/loader/elf/rela.c | 35 ++++++++++++++++++++++++----------- 2 files changed, 25 insertions(+), 12 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 1b50435..3022dd0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,5 +1,5 @@ cmake_minimum_required(VERSION 3.15) -project(vxBoot VERSION 1.2.3 LANGUAGES C) +project(vxBoot VERSION 1.2.4 LANGUAGES C) include(GenerateG1A) include(GenerateG3A) diff --git a/src/loader/elf/rela.c b/src/loader/elf/rela.c index b2397e8..dfcd1e6 100644 --- a/src/loader/elf/rela.c +++ b/src/loader/elf/rela.c @@ -65,7 +65,7 @@ static int loader_reloc_section( /* logs */ terminal_log( LOG_INFO, - " section '%s' with %d entries\n", + " > '%s' (%d)...", name, nb_rela ); @@ -85,7 +85,10 @@ static int loader_reloc_section( break; } if (type < 0) { - terminal_write("unable to relocalize symbols %d\n", i); + terminal_log( + LOG_ALERT, + "\nunable to relocalize symbols %d\n", i + ); return (-1); } @@ -104,7 +107,10 @@ static int loader_reloc_section( virtual address is set. So, for now, we just need to add the relocation offset to the content of the location. */ //val = kernel->elf.sym.tab[ELF32_R_SYM(rela[i].r_info)].st_value; - val = *(uintptr_t*)loc; + val = (((uint8_t*)loc)[0] << 24); + val |= (((uint8_t*)loc)[1] << 16); + val |= (((uint8_t*)loc)[2] << 8); + val |= (((uint8_t*)loc)[3] << 0); switch (table[type].id) { case R_SH_GOT32: @@ -113,14 +119,19 @@ static int loader_reloc_section( case R_SH_GOTOFF: break; case R_SH_DIR32: - //terminal_log( - // LOG_DEBUG, - // " %08x %-8s %08x\n", - // rela[i].r_offset, - // table[type].name, - // val - //); - *(uintptr_t *)loc = voff + val; + terminal_log( + LOG_DEBUG, + " %08x %-8s %08x %d %d", + rela[i].r_offset, + table[type].name, + val, + rela[i].r_addend, type + ); + val += voff; + ((uint8_t *)loc)[0] = (val & 0xff000000) >> 24; + ((uint8_t *)loc)[1] = (val & 0x00ff0000) >> 16; + ((uint8_t *)loc)[2] = (val & 0x0000ff00) >> 8; + ((uint8_t *)loc)[3] = (val & 0x000000ff) >> 0; break; default: terminal_log( @@ -131,6 +142,8 @@ static int loader_reloc_section( return (-1); } } + + terminal_log(LOG_INFO, "OK\n"); return (0); }