Changeset 535
- Timestamp:
- Aug 5, 2003, 9:46:37 PM (22 years ago)
- Location:
- trunk/src/emx/src/emxomf
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/emx/src/emxomf/emxomfld.c
-
Property cvs2svn:cvs-rev
changed from
1.20
to1.21
r534 r535 113 113 static FILE *response_file = NULL; 114 114 115 /* Force the use of a response file from the next put_arg(). */ 116 static int force_response_file = FALSE; 117 115 118 /* Weak alias object file. */ 116 119 static char weakobj_fname[_MAX_PATH]; 120 121 /* Weak definition file (modified def_fname). */ 122 static char weakdef_fname[_MAX_PATH]; 117 123 118 124 /* Non-zero if debugging information is to be omitted. Set by the -s … … 327 333 328 334 max_len = (response_file == NULL ? 110 : 52); 329 if (line_len + len + 1 > max_len) 335 if ( line_len + len + 1 > max_len 336 || (force_response_file && !response_file)) 330 337 { 331 338 … … 385 392 command_line[line_len++] = '@'; 386 393 strcpy (command_line+line_len, response_fname); 394 395 if (force_response_file) 396 force_response_file = FALSE; 387 397 } 388 398 else if (line_len != 0) … … 645 655 if ( !strnicmp(pOpt->name, "/I", 2) 646 656 || !strnicmp(pOpt->name, "-I", 2)) 647 fFlags |= WLDC_VERBOSE;657 fFlags = fFlags; /* Ignore - require opt_t. */ 648 658 else 649 659 if ( !strnicmp(pOpt->name, "/NOIN", 5) … … 704 714 /* generate weak aliases. */ 705 715 if (!rc) 706 rc = wldGenerateWeak obj (pwld, weakobj_fname);716 rc = wldGenerateWeakAliases (pwld, weakobj_fname, weakdef_fname); 707 717 if (!rc && weakobj_fname[0]) 708 718 add_name_list (&add_obj_fnames, weakobj_fname); 719 if (!rc && weakdef_fname[0]) 720 strcpy (def_fname, weakdef_fname); 709 721 710 722 /* cleanup the linker */ … … 740 752 line_len = 0; 741 753 response_flag = rsp; 754 force_response_file = FALSE; 742 755 } 743 756 … … 827 840 if (!(argi % 32)) 828 841 argv = xrealloc(argv, sizeof(argv[0]) * (argi + 32 + 1)); 829 argv[argi++] = xstrdup(psz);842 argv[argi++] = psz; 830 843 831 844 /* next */ … … 839 852 fprintf(stderr, "*** Return from %s is %d\n", pszwhat, rc); 840 853 854 free(argv); 841 855 return rc; 842 856 } … … 862 876 remove (weakobj_fname); 863 877 weakobj_fname[0] = '\0'; 878 } 879 if (weakdef_fname[0] != '\0') 880 { 881 remove (weakdef_fname); 882 weakdef_fname[0] = '\0'; 864 883 } 865 884 } … … 1259 1278 1260 1279 /* Put the object file names onto the command line. */ 1261 1280 1281 force_response_file = TRUE; /* link386 workaround. */ 1262 1282 put_args (obj_fnames, TRUE); 1263 1283 put_arg (",", FALSE, FALSE); -
Property cvs2svn:cvs-rev
changed from
-
trunk/src/emx/src/emxomf/weakld.c
-
Property cvs2svn:cvs-rev
changed from
1.12
to1.13
r534 r535 82 82 #include <string.h> 83 83 #include <sys/types.h> 84 #include <sys/time.h> 85 #include <sys/stat.h> 86 #include <process.h> 84 87 #include <sys/omflib.h> 85 88 #include <sys/moddef.h> … … 564 567 { 565 568 pLib->phFile = fopen(pLib->pszLibName, "rb"); 566 if ( pLib->phFile)569 if (!pLib->phFile) 567 570 libErr(pLib, "Failed to open library."); 568 571 } … … 576 579 static void libClose(PWLDLIB pLib) 577 580 { 578 if ( !pLib->phFile)581 if (pLib->phFile) 579 582 { 580 583 fclose(pLib->phFile); … … 2342 2345 { 2343 2346 void *pv = pObj; 2347 modClose(pObj); 2344 2348 pObj = pObj->pNext; 2345 2349 free(pv); … … 2348 2352 { 2349 2353 void *pv = pObj; 2354 modClose(pObj); 2350 2355 pObj = pObj->pNext; 2351 2356 free(pv); … … 2356 2361 { 2357 2362 void *pv = pLib; 2363 libClose(pLib); 2358 2364 pLib = pLib->pNext; 2359 2365 free(pv); … … 2411 2417 pWld->ppObjsAdd = &pMod->pNext; 2412 2418 rc = pass1ReadOMFMod(pWld, pMod, 0); 2419 modClose(pMod); 2413 2420 } 2414 2421 else if (OmfRec.chType == LIBHDR) … … 2435 2442 } 2436 2443 rc = pass1ReadOMFMod(pWld, pMod, 0); 2444 pMod->phFile = NULL; 2437 2445 if (rc) 2438 2446 break; … … 2447 2455 fread(&OmfRec, sizeof(OmfRec), 1, phFile); 2448 2456 } 2457 fclose(phFile); 2449 2458 } 2450 2459 else 2451 2460 { 2461 fclose(phFile); 2452 2462 fprintf(stderr, "weakld: invalid object file '%s'.\n", pszName); 2453 2463 rc = -1; … … 2826 2836 2827 2837 2838 2839 /** 2840 * Callback function for doing weak aliasing of a module definition file. 2841 * 2842 * @returns 0 on success. 2843 * @returns -1 to stop the parsing. 2844 * @param pMD Pointer to module definition file handle. 2845 * @param pStmt Statement we're processing. 2846 * @param eToken Token we're processing. 2847 * @param pvArg Pointer to file stream for the output file. 2848 * 2849 */ 2850 static int wldDefCallbackGenerateWeakAliases(struct _md *pMD, const _md_stmt *pStmt, _md_token eToken, void *pvArg) 2851 { 2852 unsigned fFlags; 2853 unsigned uOrdinal; 2854 unsigned cWords; 2855 PWLDSYM pSym; 2856 FILE * phFile = (PHFILE)pvArg; 2857 2858 switch (eToken) 2859 { 2860 /* 2861 * One export. 2862 */ 2863 case _MD_EXPORTS: 2864 fFlags = uOrdinal = cWords = 0; 2865 if (pStmt->export.flags & _MDEP_ORDINAL) 2866 uOrdinal = pStmt->export.ordinal; 2867 if (pStmt->export.flags & _MDEP_RESIDENTNAME) 2868 fFlags |= WLDSEF_NONRESIDENT; 2869 else if (pStmt->export.flags & _MDEP_NONAME) 2870 fFlags |= WLDSEF_NONAME; 2871 else 2872 fFlags |= WLDSEF_DEFAULT; 2873 if (pStmt->export.flags & _MDEP_NODATA) 2874 fFlags |= WLDSEF_NODATA; 2875 if (pStmt->export.flags & _MDEP_PWORDS) 2876 cWords = pStmt->export.pwords; 2877 pSym = symAddExport(pParam->pWld, pParam->pMod, 0, 2878 fFlags, cWords, 2879 pStmt->export.entryname, -1, 2880 pStmt->export.internalname, -1, 2881 uOrdinal); 2882 if (!pSym) 2883 { 2884 pParam->rc = -4; 2885 return -4; 2886 } 2887 break; 2888 2889 /* 2890 * Parse error. 2891 */ 2892 case _MD_parseerror: 2893 wldErr(pWld, "Parse error %d on line %d. (errorcode=%d stmt=%d)", 2894 _md_get_linenumber(pMD), pStmt->error.code, pStmt->error.stmt); 2895 pParam->rc = -2; 2896 break; 2897 2898 /* 2899 * Everything else is passed thru line by line. 2900 */ 2901 default: 2902 pMD-> 2903 break; 2904 } 2905 return 0; 2906 } 2907 2908 2909 /** 2910 * Generates an unique temporary file. 2911 * 2912 * @returns 0 on success. 2913 * @returns -1 on failure. 2914 * @param pWld Linker instance. 2915 * @param pszFile Where to put the filename. 2916 * @param pszPrefix Prefix. 2917 * @param pszSuffix Suffix. 2918 */ 2919 static int wldTempFile(PWLD pWld, char *pszFile, const char *pszPrefix, const char *pszSuffix) 2920 { 2921 struct stat s; 2922 unsigned c = 0; 2923 pid_t pid = getpid(); 2924 const char * pszTmp = getenv("TMP"); 2925 if (!pszTmp) pszTmp = getenv("TMPDIR"); 2926 if (!pszTmp) pszTmp = getenv("TEMP"); 2927 if (!pszTmp) pszTmp = "."; 2928 2929 do 2930 { 2931 struct timeval tv = {0,0}; 2932 if (c++ >= 200) 2933 return -1; 2934 gettimeofday(&tv, NULL); 2935 sprintf(pszFile, "%s\\%s%x%lx%d%lx%s", pszTmp, pszPrefix, pid, tv.tv_sec, c, tv.tv_usec, pszSuffix); 2936 } while (!stat(pszFile, &s)); 2937 2938 return 0; 2939 } 2940 2941 2828 2942 /** 2829 2943 * Generates a object file containing alias for resolving the weak … … 2834 2948 * @returns 0 on success. 2835 2949 * @returns some unexplainable randomly picked number on failure. 2836 * @param pWld Linker instance to destroy. 2837 * @param pszName Where to put the name of the generated object file. 2838 * This is an empty string if no weak symbols were found! 2839 */ 2840 int wldGenerateWeakobj(PWLD pWld, char *pszName) 2950 * @param pWld Linker instance. 2951 * @param pszObjName Where to put the name of the generated object file. 2952 * This is an empty string if no weak symbols were found! 2953 * @param pszDefName Where to put the name of the modified definition file. 2954 * This is an empty string if changes was required! 2955 */ 2956 int wldGenerateWeakAliases(PWLD pWld, char *pszObjName, char *pszDefName) 2841 2957 { 2842 2958 char * psz; … … 2844 2960 int rc; 2845 2961 2846 /* generate the file */ 2847 *pszName = '\0'; 2848 psz = _tempnam(NULL, "weako"); 2849 if (psz) 2850 { 2851 strcpy(pszName, psz); 2852 free(psz); 2853 } 2854 else 2855 tmpnam(pszName); 2856 strcat(pszName, "wk.obj"); 2857 WLDINFO(pWld, ("Generating weakobj object file '%s'.", pszName)); 2858 2859 2860 /* open the file */ 2861 phFile = fopen(pszName, "wr"); 2962 /* zero returns */ 2963 *pszObjName = '\0'; 2964 if (pszDefName) 2965 *pszDefName = '\0'; 2966 2967 /* generate the object file */ 2968 rc = wldTempFile(pWld, pszObjName, "wk", ".obj"); 2969 if (rc) 2970 return wldErr(pWld, "Failed to generate temporary object file for weak aliases."); 2971 WLDINFO(pWld, ("Generating object file '%s' for weak aliases.", pszObjName)); 2972 2973 /* open it */ 2974 phFile = fopen(pszObjName, "wr"); 2862 2975 if (phFile) 2863 2976 { … … 2893 3006 WLDINFO(pWld, ("No weak alias needed, deleting file.")); 2894 3007 fclose(phFile); 2895 remove(psz Name);2896 *psz Name = '\0';3008 remove(pszObjName); 3009 *pszObjName = '\0'; 2897 3010 } 2898 3011 else … … 2906 3019 else 2907 3020 { 2908 wldErr(pWld, "Failed to write to '%s'.", psz Name);3021 wldErr(pWld, "Failed to write to '%s'.", pszObjName); 2909 3022 rc = -1; 2910 3023 fclose(phFile); 2911 remove(psz Name);2912 *psz Name = '\0';3024 remove(pszObjName); 3025 *pszObjName = '\0'; 2913 3026 } 2914 3027 } … … 2916 3029 else 2917 3030 { 2918 wldErr(pWld, "Failed to open '%s' for writing.", pszName); 2919 *pszName = '\0'; 3031 wldErr(pWld, "Failed to open '%s' for writing.", pszObjName); 3032 *pszObjName = '\0'; 3033 } 3034 3035 /* do the definition file */ 3036 if (!rc && pWld->pDef && pszDefName) 3037 { 3038 rc = wldTempFile(pWld, pszDefName, "wk", ".def"); 3039 if (!rc) 3040 { 3041 WLDINFO(pWld, ("Generating definition file '%s' for weak exports.", pszDefName)); 3042 3043 /* open it */ 3044 phFile = fopen(pszDefName, "w"); 3045 if (phFile) 3046 { 3047 FILE *phOrgDef = fopen(pWld->pDef->pszModName, "r"); 3048 if (phOrgDef) 3049 { 3050 char *pachOrgDef = fsize 3051 struct _md *pMD; 3052 3053 /* open original def file */ 3054 pMD = _md_open(pWld->pDef->pszModName); 3055 if (pMD) 3056 { 3057 /* parse it */ 3058 _md_next_token(pMD); 3059 rc = _md_parse(pMD, wldDefCallbackGenerateWeakAliases, phFile); 3060 _md_close(pMD); 3061 } 3062 else 3063 rc = wldErr(pWld, "_md_open on '%s'.\n", pszDefName); 3064 fclose(phOrgFile); 3065 } 3066 else 3067 rc = wldErr(pWld, "Failed to open '%s' for reading.\n", pszDefName); 3068 fclose(phFile); 3069 } 3070 else 3071 rc = wldErr(pWld, "Failed to open '%s' for writing.\n", pszDefName); 3072 } 3073 else 3074 rc = wldErr(pWld, "Failed to generate temporary definition file for weak aliases."); 3075 } 3076 3077 /* cleanup */ 3078 if (rc && pszDefName && *pszDefName) 3079 { 3080 remove(pszDefName); 3081 *pszDefName = '\0'; 3082 } 3083 if (rc && pszObjName && *pszObjName) 3084 { 3085 remove(pszObjName); 3086 *pszObjName = '\0'; 2920 3087 } 2921 3088 -
Property cvs2svn:cvs-rev
changed from
-
trunk/src/emx/src/emxomf/weakld.h
-
Property cvs2svn:cvs-rev
changed from
1.4
to1.5
r534 r535 56 56 int wldAddLibrary(PWLD pWld, FILE *phFile, const char *pszName); 57 57 int wldPass1(PWLD pWld); 58 int wldGenerateWeak obj(PWLD pwld, char *pszName);58 int wldGenerateWeakAliases(PWLD pwld, char *pszObjName, char *pszDefName); 59 59 int wldDestroy(PWLD pWld); 60 60 /** @} */ -
Property cvs2svn:cvs-rev
changed from
Note:
See TracChangeset
for help on using the changeset viewer.