Remove the previous logic to link a named file with a loader script by using tcc_add_dll instead. Hence, all files can be linked, not only files ending in .so/.def.
Unified · Split
| @@ -2846,40 +2846,6 @@ static int ld_next(TCCState *s1, char *name, int name_size) · 2845 unmodified lines | |||
| 2846 | return c; | 2846 | return c; |
| 2847 | } | 2847 | } |
| 2848 | 2848 | ||
| 2849 | /* | ||
| 2850 | * Extract the library name from the file name | ||
| 2851 | * Return 0 if the file isn't a library | ||
| 2852 | * | ||
| 2853 | * /!\ No test on filename capacity, be careful | ||
| 2854 | */ | ||
| 2855 | static int filename_to_libname(TCCState *s1, const char filename[], char libname[]) | ||
| 2856 | { | ||
| 2857 | char *ext; | ||
| 2858 | int libprefix; | ||
| 2859 | |||
| 2860 | /* already converted to library name */ | ||
| 2861 | if (libname[0] != '\0') | ||
| 2862 | return 1; | ||
| 2863 | ext = tcc_fileextension(filename); | ||
| 2864 | if (*ext == '\0') | ||
| 2865 | return 0; | ||
| 2866 | libprefix = !strncmp(filename, "lib", 3); | ||
| 2867 | if (!s1->static_link) { | ||
| 2868 | if (libprefix && (!strcmp(ext, ".so"))) { | ||
| 2869 | size_t len = ext - filename - 3; | ||
| 2870 | pstrncpy(libname, filename + 3, len); | ||
| 2871 | return 1; | ||
| 2872 | } | ||
| 2873 | } else { | ||
| 2874 | if (libprefix && (!strcmp(ext, ".a"))) { | ||
| 2875 | size_t len = ext - filename - 3; | ||
| 2876 | pstrncpy(libname, filename + 3, len); | ||
| 2877 | return 1; | ||
| 2878 | } | ||
| 2879 | } | ||
| 2880 | return 0; | ||
| 2881 | } | ||
| 2882 | |||
| 2883 | /* | 2849 | /* |
| 2884 | * Extract the file name from the library name | 2850 | * Extract the file name from the library name |
| 2885 | * | 2851 | * |
| @@ -2894,15 +2860,13 @@ static void libname_to_filename(TCCState *s1, const char libname[], char filenam · 8 unmodified lines | |||
| 2894 | } | 2860 | } |
| 2895 | } | 2861 | } |
| 2896 | 2862 | ||
| 2897 | static int ld_add_file(TCCState *s1, const char filename[], char libname[]) | 2863 | static int ld_add_file(TCCState *s1, const char filename[]) |
| 2898 | { | 2864 | { |
| 2899 | int ret; | 2865 | int ret; |
| 2900 | 2866 | ||
| 2901 | ret = tcc_add_file_internal(s1, filename, 0); | 2867 | ret = tcc_add_file_internal(s1, filename, 0); |
| 2902 | if (ret) { | 2868 | if (ret) |
| 2903 | if (filename_to_libname(s1, filename, libname)) | 2869 | ret = tcc_add_dll(s1, filename, 0); |
| 2904 | ret = tcc_add_library(s1, libname); | ||
| 2905 | } | ||
| 2906 | return ret; | 2870 | return ret; |
| 2907 | } | 2871 | } |
| 2908 | 2872 | ||
| @@ -2948,7 +2912,7 @@ static int ld_add_file_list(TCCState *s1, const char *cmd, int as_needed) · 39 unmodified lines | |||
| 2948 | tcc_error_noabort("filename expected"); | 2912 | tcc_error_noabort("filename expected"); |
| 2949 | ret = -1; | 2913 | ret = -1; |
| 2950 | goto lib_parse_error; | 2914 | goto lib_parse_error; |
| 2951 | } | 2915 | } |
| 2952 | if (!strcmp(filename, "AS_NEEDED")) { | 2916 | if (!strcmp(filename, "AS_NEEDED")) { |
| 2953 | ret = ld_add_file_list(s1, cmd, 1); | 2917 | ret = ld_add_file_list(s1, cmd, 1); |
| 2954 | if (ret) | 2918 | if (ret) |
| @@ -2956,13 +2920,14 @@ static int ld_add_file_list(TCCState *s1, const char *cmd, int as_needed) · 1 unmodified line | |||
| 2956 | } else { | 2920 | } else { |
| 2957 | /* TODO: Implement AS_NEEDED support. Ignore it for now */ | 2921 | /* TODO: Implement AS_NEEDED support. Ignore it for now */ |
| 2958 | if (!as_needed) { | 2922 | if (!as_needed) { |
| 2959 | ret = ld_add_file(s1, filename, libname); | 2923 | ret = ld_add_file(s1, filename); |
| 2960 | if (ret) | 2924 | if (ret) |
| 2961 | goto lib_parse_error; | 2925 | goto lib_parse_error; |
| 2962 | if (group) { | 2926 | if (group) { |
| 2963 | /* Add the filename *and* the libname to avoid future conversions */ | 2927 | /* Add the filename *and* the libname to avoid future conversions */ |
| 2964 | dynarray_add((void ***) &libs, &nblibs, tcc_strdup(filename)); | 2928 | dynarray_add((void ***) &libs, &nblibs, tcc_strdup(filename)); |
| 2965 | dynarray_add((void ***) &libs, &nblibs, tcc_strdup(libname)); | 2929 | if (libname[0] != '\0') |
| 2930 | dynarray_add((void ***) &libs, &nblibs, tcc_strdup(libname)); | ||
| 2966 | } | 2931 | } |
| 2967 | } | 2932 | } |
| 2968 | } | 2933 | } |
| @@ -2975,8 +2940,8 @@ static int ld_add_file_list(TCCState *s1, const char *cmd, int as_needed) · 6 unmodified lines | |||
| 2975 | while (new_undef_syms()) { | 2940 | while (new_undef_syms()) { |
| 2976 | int i; | 2941 | int i; |
| 2977 | 2942 | ||
| 2978 | for (i = 0; i < nblibs; i += 2) | 2943 | for (i = 0; i < nblibs; i ++) |
| 2979 | ld_add_file(s1, libs[i], libs[i+1]); | 2944 | ld_add_file(s1, libs[i]); |
| 2980 | } | 2945 | } |
| 2981 | } | 2946 | } |
| 2982 | lib_parse_error: | 2947 | lib_parse_error: |