2018-09-15 13:32:42 +08:00
|
|
|
/*
|
2021-03-08 18:19:04 +08:00
|
|
|
* Copyright (c) 2006-2021, RT-Thread Development Team
|
2018-09-15 13:32:42 +08:00
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
2021-03-08 18:19:04 +08:00
|
|
|
*
|
2018-09-15 13:32:42 +08:00
|
|
|
* Change Logs:
|
|
|
|
* Date Author Notes
|
|
|
|
* 2018/09/15 parai first version
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "../dlmodule.h"
|
|
|
|
#include "../dlelf.h"
|
|
|
|
|
2018-10-10 14:38:24 +08:00
|
|
|
#ifdef __i386__
|
2018-09-15 13:32:42 +08:00
|
|
|
|
2023-06-29 23:24:25 +08:00
|
|
|
#define DBG_TAG "kernel.module"
|
|
|
|
#ifdef RT_DEBUG_MODULE
|
|
|
|
#define DBG_LVL DBG_LOG
|
|
|
|
#else
|
|
|
|
#define DBG_LVL DBG_WARNING
|
|
|
|
#endif /* defined (RT_DEBUG_MODULE) */
|
|
|
|
#include <rtdbg.h>
|
|
|
|
|
2021-03-08 18:19:04 +08:00
|
|
|
#define R_X86_64_GLOB_DAT 6 /* Create GOT entry */
|
|
|
|
#define R_X86_64_JUMP_SLOT 7 /* Create PLT entry */
|
|
|
|
#define R_X86_64_RELATIVE 8 /* Adjust by program base */
|
2018-09-15 13:32:42 +08:00
|
|
|
int dlmodule_relocate(struct rt_dlmodule *module, Elf32_Rel *rel, Elf32_Addr sym_val)
|
|
|
|
{
|
|
|
|
Elf32_Addr *where, tmp;
|
|
|
|
Elf32_Sword addend, offset;
|
|
|
|
rt_uint32_t upper, lower, sign, j1, j2;
|
|
|
|
|
|
|
|
where = (Elf32_Addr *)((rt_uint8_t *)module->mem_space
|
|
|
|
+ rel->r_offset
|
|
|
|
- module->vstart_addr);
|
|
|
|
|
|
|
|
switch (ELF32_R_TYPE(rel->r_info))
|
|
|
|
{
|
|
|
|
case R_X86_64_GLOB_DAT:
|
|
|
|
case R_X86_64_JUMP_SLOT:
|
|
|
|
*where = (Elf32_Addr)sym_val;
|
|
|
|
|
2023-06-29 23:24:25 +08:00
|
|
|
LOG_D("R_X86_64_JUMP_SLOT: 0x%x -> 0x%x 0x%x",
|
|
|
|
(uint32_t)where, *where, sym_val);
|
2018-09-15 13:32:42 +08:00
|
|
|
break;
|
|
|
|
case R_X86_64_RELATIVE:
|
|
|
|
*where = (Elf32_Addr)sym_val + *where;
|
2023-06-29 23:24:25 +08:00
|
|
|
LOG_D("R_X86_64_RELATIVE: 0x%x -> 0x%x 0x%x",
|
|
|
|
(uint32_t)where, *where, sym_val);
|
2018-09-15 13:32:42 +08:00
|
|
|
break;
|
|
|
|
default:
|
2023-06-29 23:24:25 +08:00
|
|
|
LOG_D("X86ELF: invalid relocate TYPE %d", ELF32_R_TYPE(rel->r_info));
|
2018-09-15 13:32:42 +08:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
#endif
|