Unified · Split
| @@ -979,6 +979,10 @@ static int tcc_glob_so(TCCState *s1, const char *pattern, char *buf, int size) · 978 unmodified lines | ||
| 979 | 979 | } |
| 980 | 980 | #endif |
| 981 | 981 | |
| 982 | +#ifdef TCC_TARGET_MACHO | |
| 983 | +ST_FUNC const char* macho_tbd_soname(const char* filename); | |
| 984 | +#endif | |
| 985 | + | |
| 982 | 986 | ST_FUNC int tcc_add_file_internal(TCCState *s1, const char *filename, int flags) |
| 983 | 987 | { |
| 984 | 988 | 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 | ||
| 1029 | 1033 | case AFF_BINTYPE_DYN: |
| 1030 | 1034 | if (s1->output_type == TCC_OUTPUT_MEMORY) { |
| 1031 | 1035 | #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); | |
| 1033 | 1042 | if (dl) { |
| 1034 | − tcc_add_dllref(s1, filename)->handle = dl; | |
| 1043 | + tcc_add_dllref(s1, soname)->handle = dl; | |
| 1035 | 1044 | ret = 0; |
| 1036 | 1045 | } |
| 1037 | 1046 | #endif |
| @@ -865,6 +865,29 @@ ST_FUNC int macho_add_dllref(TCCState* s1, int lev, const char* soname) · 864 unmodified lines | ||
| 865 | 865 | #define tbd_parse_tramplespace if(*pos==' ') tbd_parse_trample |
| 866 | 866 | #define tbd_parse_trample *pos++=0 |
| 867 | 867 | |
| 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 | + | |
| 868 | 891 | ST_FUNC int macho_load_tbd(TCCState* s1, int fd, const char* filename, int lev) |
| 869 | 892 | { |
| 870 | 893 | char* soname; |