我有以下代码,其中正在加载的共享库以预编译二进制文件的形式传递。它是用linaro工具链编译的。
gbm_create_device(int fd)
{
struct gbm_device *gbm = NULL;
void *module;
const struct gbm_backend *backend = NULL
module = dlopen("/usr/lib/gbm/gbm_pvr.so", RTLD_NOW | RTLD_GLOBAL);
backend = dlsym(module, "gbm_backend");
gbm = backend->create_device(fd);
gbm->surface_create(gbm, width, height, format, flags);
}
struct gbm_device {
/* Hack to make a gbm_device detectable by its first element. */
struct gbm_device *(*dummy)(int);
int fd;
const char *name;
unsigned int refcount;
struct stat stat;
...
void (*bo_destroy)(struct gbm_bo *bo);
struct gbm_surface *(*surface_create)(struct gbm_device *gbm,
uint32_t width, uint32_t height,
uint32_t format, uint32_t flags);
struct gbm_bo *(*surface_lock_front_buffer)(struct gbm_surface *surface);
...
};代码通常正常工作。但是,当我添加以下定义时,gbm->surface_create(...)跳转到共享库中的错误内存位置。为什么?在我看来,这一点在官方GNU页面看来并不明显。
#define _LARGEFILE_SOURCE
#define _LARGEFILE64_SOURCE
#define _FILE_OFFSET_BITS=64 其他信息:
我使用gdb检查gbm->surface_create(.)之后的第一步
没有这些定义:
0xb6beb5d0 in ?? () from /usr/lib/gbm/gbm_pvr.so
...
// Correct behavior定义如下:
0xb6c414a4 in ?? () from /usr/lib/gbm/gbm_pvr.so
...
// Segmentation fault发布于 2017-11-13 20:18:58
struct gbm_device包含一个struct stat stat;成员。
struct stat根据_LARGEFILE_SOURCE更改大小。它包含32位或64位的成员off_t st_size;等.
不使用_LARGEFILE_SOURCE编译的二进制文件中的结构和用_LARGEFILE_SOURCE编译的代码中的结构不兼容ABI。
函数指针位于结构的该成员之后;更改该成员的大小将更改以下成员的明显偏移量,这就是如何使用错误的函数指针值。
https://stackoverflow.com/questions/47271935
复制相似问题