macOS 11: tcc -run
using dyld shared cache
This commit is contained in:
parent
f6fb4d0cf1
commit
33fa3a4d41
2 changed files with 34 additions and 2 deletions
13
libtcc.c
13
libtcc.c
|
@ -979,6 +979,10 @@ static int tcc_glob_so(TCCState *s1, const char *pattern, char *buf, int size)
|
||||||
}
|
}
|
||||||
#endif
|
#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)
|
ST_FUNC int tcc_add_file_internal(TCCState *s1, const char *filename, int flags)
|
||||||
{
|
{
|
||||||
int fd, ret = -1;
|
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:
|
case AFF_BINTYPE_DYN:
|
||||||
if (s1->output_type == TCC_OUTPUT_MEMORY) {
|
if (s1->output_type == TCC_OUTPUT_MEMORY) {
|
||||||
#ifdef TCC_IS_NATIVE
|
#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) {
|
if (dl) {
|
||||||
tcc_add_dllref(s1, filename)->handle = dl;
|
tcc_add_dllref(s1, soname)->handle = dl;
|
||||||
ret = 0;
|
ret = 0;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
23
tccmacho.c
23
tccmacho.c
|
@ -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_tramplespace if(*pos==' ') tbd_parse_trample
|
||||||
#define tbd_parse_trample *pos++=0
|
#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)
|
ST_FUNC int macho_load_tbd(TCCState* s1, int fd, const char* filename, int lev)
|
||||||
{
|
{
|
||||||
char* soname;
|
char* soname;
|
||||||
|
|
Loading…
Add table
Reference in a new issue