提交 33fa3a4d 编辑于 作者: Sushant Pandurangi's avatar Sushant Pandurangi
浏览文件

macOS 11: `tcc -run` using dyld shared cache

上级 f6fb4d0c
......@@ -979,6 +979,10 @@ static int tcc_glob_so(TCCState *s1, const char *pattern, char *buf, int size)
}
#endif
#ifdef TCC_TARGET_MACHO
ST_FUNC const char* macho_tbd_soname(const char* filename);
#endif
ST_FUNC int tcc_add_file_internal(TCCState *s1, const char *filename, int flags)
{
int fd, ret = -1;
......@@ -1029,9 +1033,14 @@ ST_FUNC int tcc_add_file_internal(TCCState *s1, const char *filename, int flags)
case AFF_BINTYPE_DYN:
if (s1->output_type == TCC_OUTPUT_MEMORY) {
#ifdef TCC_IS_NATIVE
void *dl = dlopen(filename, RTLD_GLOBAL | RTLD_LAZY);
char* soname = filename;
# ifdef TCC_TARGET_MACHO
if (!strcmp(tcc_fileextension(filename), ".tbd"))
soname = macho_tbd_soname(filename);
# endif
void* dl = dlopen(soname, RTLD_GLOBAL | RTLD_LAZY);
if (dl) {
tcc_add_dllref(s1, filename)->handle = dl;
tcc_add_dllref(s1, soname)->handle = dl;
ret = 0;
}
#endif
......
......@@ -865,6 +865,29 @@ ST_FUNC int macho_add_dllref(TCCState* s1, int lev, const char* soname)
#define tbd_parse_tramplespace if(*pos==' ') tbd_parse_trample
#define tbd_parse_trample *pos++=0
ST_FUNC const char* macho_tbd_soname(const char* filename) {
char* soname;
int fd = open(filename,O_RDONLY);
if (fd<0) return filename;
struct stat sb;
fstat(fd,&sb);
char* data = load_data(fd, 0, sb.st_size+1);
data[sb.st_size]=0;
char* pos = data;
if (!tbd_parse_movepast("install-name: ")) return filename;
tbd_parse_skipws;
tbd_parse_tramplequote;
soname = pos;
if (!tbd_parse_movetoany("\n \"'")) return filename;
tbd_parse_trample;
char* ret = tcc_mallocz(strlen(soname)+1);
strcpy(ret, soname);
// soname = strdup(soname);
tcc_free(data);
return ret;
}
ST_FUNC int macho_load_tbd(TCCState* s1, int fd, const char* filename, int lev)
{
char* soname;
......
Supports Markdown
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册