我使用 Clang 3.3 编译了 MUSL C 库,并转储了生成的 LLVM IR 文件。我发现 FILE 结构
struct __FILE_s {
unsigned flags;
unsigned char *rpos, *rend;
int (*close)(FILE *);
unsigned char *wend, *wpos;
unsigned char *mustbezero_1;
unsigned char *wbase;
size_t (*read)(FILE *, unsigned char *, size_t);
size_t (*write)(FILE *, const unsigned char *, size_t);
off_t (*seek)(FILE *, off_t, int);
unsigned char *buf;
size_t buf_size;
FILE *prev, *next;
int fd;
int pipe_pid;
long lockcount;
short dummy3;
signed char mode;
signed char lbf;
int lock;
int waiters;
void *cookie;
off_t off;
char *getln_buf;
void *mustbezero_2;
unsigned char *shend;
off_t shlim, shcnt;
};
被编译为
%struct.__FILE_s = type { i32, i8*, i8*,
i32 (%struct.__FILE_s*)*, i8*, i8*, i8*, i8*,
i64 (%struct.__FILE_s*, i8*, i64)*,
i64 (%struct.__FILE_s*, i8*, i64)*,
i64 (%struct.__FILE_s*, i64, i32)*,
i8*, i64, %struct.__FILE_s*, %struct.__FILE_s*,
i32, i32, i64, i16, i8, i8, i32, i32, i8*,
i64, i8*, i8*, i8*, i64, i64 }
在一些 IR 文件中,但被编译为
%struct.__FILE_s = type { i32, i8*, i8*,
i32 (%struct.__FILE_s*)*, i8*, i8*, i8*, i8*,
i64 (%struct.__FILE_s*, i8*, i64)*,
{}*,
i64 (%struct.__FILE_s*, i64, i32)*,
i8*, i64, %struct.__FILE_s*, %struct.__FILE_s*,
i32, i32, i64, i16, i8, i8, i32, i32, i8*,
i64, i8*, i8*, i8*, i64, i64 }
在其他源文件中。这两个 IR 结构之间的唯一区别是第一种形式的函数指针类型字段被替换为 {}* 而不是其完整类型。谁能告诉我为什么会发生这种情况以及如何禁用 {}* 替换?