Rebuild the dynamic library when typedef is changed

Suppose I have a C structure DynApiArg_t.

typedef struct DynApiArg_s {
    uint32_t m1;
    ...
    uint32_t mx;
} DynApiArg_t;

The pointer to this structure is passed as an argument to the say function

void DynLibApi(DynApiArg_t *arg)
{
     arg->m1 = 0;
     another_fn_in_the_lib(arg->mold); /* May crash here. (1) */
}

which is present in the dynamic library libdyn.so. This API is called from an executable using a dlopen/dlsymcall procedure .

If this dynamic library is updated to version 2, where it DynApiArg_tnow has a new member, say m2, as shown below:

typedef struct DynApiArg_s {
    uint32_t m1;
    OldMbr_t *mold;
    ...
    uint32_t mx;
    uint32_t m2;
    NewMbr *mnew;
} DynApiArg_t;

, API dlopen/dlsym, , API , , - . , 2 . mold, , .

typedef void (*fnPtr_t)(DynApiArg_t*);


void DynApiCaller(DynApiArg_t *arg)
{
     void *libhdl = dlopen("libdyn.so", RTLD_LAZY | RTLD_GLOBAL);
     fnPtr_t fptr = dlsym(libhdl, "DynLibApi");
     fnptr(arg); /* actual call to the dynamically loaded API (2) */
}

API fnptr , (2), / ( v1 lib, DynApiCaller ), (1), , , NULL.

?

, libs symliks , libsolid.so.4. -, , ? , , ?

+4

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


All Articles