History

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

Sushant Pandurangi committed 5 years ago

Commit 33fa3a41 parent f6fb4d02 files · +34 −2Browse files

Unified · Split

2 files
  1. libtcc.c +11 −2
  2. tccmacho.c +23 −0
libtcc.c+11−2
@@ -979,6 +979,10 @@ static int tcc_glob_so(TCCState *s1, const char *pattern, char *buf, int size) · 978 unmodified lines
979979 }
980980 #endif
981981
982+#ifdef TCC_TARGET_MACHO
983+ST_FUNC const char* macho_tbd_soname(const char* filename);
984+#endif
985+
982986 ST_FUNC int tcc_add_file_internal(TCCState *s1, const char *filename, int flags)
983987 {
984988 int fd, ret = -1;
@@ -1029,9 +1033,14 @@ ST_FUNC int tcc_add_file_internal(TCCState *s1, const char *filename, int flags) · 44 unmodified lines
10291033 case AFF_BINTYPE_DYN:
10301034 if (s1->output_type == TCC_OUTPUT_MEMORY) {
10311035 #ifdef TCC_IS_NATIVE
1032− void *dl = dlopen(filename, RTLD_GLOBAL | RTLD_LAZY);
1036+ char* soname = filename;
1037+# ifdef TCC_TARGET_MACHO
1038+ if (!strcmp(tcc_fileextension(filename), ".tbd"))
1039+ soname = macho_tbd_soname(filename);
1040+# endif
1041+ void* dl = dlopen(soname, RTLD_GLOBAL | RTLD_LAZY);
10331042 if (dl) {
1034− tcc_add_dllref(s1, filename)->handle = dl;
1043+ tcc_add_dllref(s1, soname)->handle = dl;
10351044 ret = 0;
10361045 }
10371046 #endif
tccmacho.c+23−0
@@ -865,6 +865,29 @@ ST_FUNC int macho_add_dllref(TCCState* s1, int lev, const char* soname) · 864 unmodified lines
865865 #define tbd_parse_tramplespace if(*pos==' ') tbd_parse_trample
866866 #define tbd_parse_trample *pos++=0
867867
868+ST_FUNC const char* macho_tbd_soname(const char* filename) {
869+ char* soname;
870+ int fd = open(filename,O_RDONLY);
871+ if (fd<0) return filename;
872+ struct stat sb;
873+ fstat(fd,&sb);
874+ char* data = load_data(fd, 0, sb.st_size+1);
875+ data[sb.st_size]=0;
876+ char* pos = data;
877+
878+ if (!tbd_parse_movepast("install-name: ")) return filename;
879+ tbd_parse_skipws;
880+ tbd_parse_tramplequote;
881+ soname = pos;
882+ if (!tbd_parse_movetoany("\n \"'")) return filename;
883+ tbd_parse_trample;
884+ char* ret = tcc_mallocz(strlen(soname)+1);
885+ strcpy(ret, soname);
886+ // soname = strdup(soname);
887+ tcc_free(data);
888+ return ret;
889+}
890+
868891 ST_FUNC int macho_load_tbd(TCCState* s1, int fd, const char* filename, int lev)
869892 {
870893 char* soname;

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t