1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
|
#include <stdio.h>
#include <stdlib.h>
typedef int (*myfunc_type)();
static int mydata[10] = { 44 };
static void dtor() {
puts("side module atexit ..");
}
__attribute__((constructor)) static void ctor() {
puts("side module ctor");
atexit(dtor);
}
static int myfunc() {
return 43;
}
// Exposing the address of `mydata` in this way forces it to
// be present in the .data segment with its address calculated
// relative the `__memory_base` at which the DSO is loaded.
int* side_data_address() {
return mydata;
}
// Exposing the address of `mydata` in this way forces it to
// be present in static table region on the DSO and its
// address will be calculated relative to the `__table_base`
// at which the DSO is loaded.
myfunc_type side_func_address() {
return &myfunc;
}
|