When and how are the items in data.rel.ro section updated in Linux?

  Kiến thức lập trình

I’m rafactoring a 32bit application on 64bit embeded Linux. I’ll explain why I refacotr it first:
Currently there’s huge amount of global settings which are defined as global variables e.g., globalSetting_xxx in my application. The type of these variables are struct like:

struct SettingItem {
    char* desc;
    void** ramPtr;
    unsigned value;

All these variables are defined in one source file(say, setting.c), put to a used defined segment SEGM_SETTING_STRUCT, and then compiled and linked to the main application statically.
In this case a tiny modification in setting.c can lead to a compilation of whole app.
So I wanna pack the setting.c as libsetting.so, then it’s separated with main application.
Now the problem I am facing is, the addresses of the globalSetting_xxx are wrong.
I checked the map file(main.map) by main application, there’re section like this:

 *(.data.rel.ro .data.rel.ro.* .gnu.linkonce.d.rel.ro.*)
 .data.rel.ro   0x0000000080598410       0x20 d:/dev/toolchain/gcc-arm-11.2-2022.02-mingw-w64-i686-arm-none-linux-gnueabihf/bin/../arm-none-linux-gnueabihf/libc/usr/lib/crt1.o
                0x0000000080598410                globalSetting_A
                0x0000000080598410                globalSetting_B
                0x0000000080598410                globalSetting_C
                0x0000000080598410                globalSetting_D
                0x0000000080598410                globalSetting_...

and in the map file(setting.map) by libsetting.so, there’re section:

                0x00000000004f5f00   0x1bcec8 ./setting.o
                0x00000000004f5f00                globalSetting_A
                0x00000000004f5f38                globalSetting_B
                0x00000000004f5f70                globalSetting_C
                0x00000000004f5fa8                globalSetting_D
                0x00000000004f5fe0                globalSetting_....

I guess the 0x0000000080598410 in main.map is to be overwritten by dynamic loader during the loading phase.

I printed the starting address of SEGM_SETTING_STRUCT(I put a symbol just in front of SEGM_SETTING_STRUCT in the linker script for libsetting.so), it is something like 0xf70e5f00, but when I printed the address of &globalSetting_x, I got 0x80598410.
It seems the values(GOT? I guess.) in .data.rel.ro are not updated by loader.
Can anyone tell me the reason?
Tell me in the comment if you need any detailed information.