How to distinguish between movable and non-movable characters inside a .data.rel section

I am trying to create a simple linker for a barebone ARM application. Currently, the loader loading the module will simply add an offset to all the entries in the .got and .data.rel . This works fine in .got and for all characters that need to be moved inside .data.rel . It will be broken, although for all non-moving data, since they will also receive this offset.

Example:

 void some_function() { return; } struct a { void* fptr; int number; }; static struct a = { .fptr = some_function, .number = 0x1000, }; 

Here a.fptr will correctly address the actual location of the function, but a.number will incorrectly hold 0x1000 + offset instead of just 0x1000 .

How should I distinguish between the two? Am I enough to check the .symtab section and move only the addresses that are there? But what if the character is really at location 0x1000 ? Or does the linker address this problem (therefore, it will not put the function at 0x1000 )? Does .symtabs include all the characters that can be found inside .got and .data.rel ?

+4
source share
1 answer

I wrote the base ELF loader some time ago, and I remember that you only add offsets to the movement records marked as "R_ARM_ABS32".

Here you can find the code https://github.com/tangrs/ndless-elfloader/blob/master/elf/elf_load.c

I just linked my ELF files with -emit-relocs included. That way, the linker makes all the links, it just tells me what it did so that you can fix the bias at boot time.

+2
source

Source: https://habr.com/ru/post/1400589/


All Articles