Application written in C, and runs on Ubuntu 18.04.
This application links with couple of shared libraries, lets say shared_lib1_external.so,
and shared_lib1_internal.so.
I have this unique scenario where the shared_lib1_external is used initially(during application
startup), and so some of the globals get initialized in this shared_lib1_external.
But then after startup is completed, need to use shared_lib1_internal for subsequent usage.
Now this leaves us with shared_lib1_internal, which does not have the globals initialized correctly.
Just to clarify, when I say global symbols, I am only interested in getting global variables,
not global functions from the library.
For example:
int global_counter = 0;
int global_array[10];
Now after startup is done, I do have the option to use dlopen(to open shared_lib_external.so), and then use dlsym(shared_lib_external's handle, "global_symbol_name"), to fetch the global symbols.
But this can be tedious, since there are several globals, but more importantly, there are also static variables which are local to the library, but gets initialized during startup, and used during runtime. Now we cannot get static symbols through dlsym, which is another issue.
For example, static variables like below:
static int local_counter;
When I do an object dump:
objdump -t shared_lib1_internal.so,
both static and global symbols show up either in .bss (OR) in .data section, depending on whether variable is initialized or not.
So question is, is there a programmatic way to do the steps below in my C application:
After application startup is completed, the following steps to be executed by the C application:
Step1-> Retrieve the entire .bss and .data sections of shared_lib1_external.so, into application's memory.
Step2-> Copy-over the entire .bss and .data sections retrieved in Step1, to the corresponding
sections in shared_lib1_internal.so