Changeset 537
- Timestamp:
- Aug 6, 2003, 2:16:54 AM (22 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/emx/src/emxomf/weakld.c
-
Property cvs2svn:cvs-rev
changed from
1.13
to1.14
r536 r537 38 38 * type groups, but the choice was made to differenciate this using flags. 39 39 * So, symbol enumeration is done using flag masks. 40 * 40 * @todo: Finish this stuff. 41 41 * 42 42 */ … … 441 441 442 442 443 /******************************************************************************* 444 * 445 * H e l p e r s 446 * H e l p e r s 447 * H e l p e r s 448 * 449 *******************************************************************************/ 443 444 445 446 447 448 449 450 /*============================================================================= 451 * * 452 * * 453 * W E A K L I N K E R M E T H O D S * 454 * W E A K L I N K E R M E T H O D S * 455 * W E A K L I N K E R M E T H O D S * 456 * W E A K L I N K E R M E T H O D S * 457 * W E A K L I N K E R M E T H O D S * 458 * * 459 * * 460 *============================================================================*/ 461 450 462 451 463 #ifdef WLD_ENABLED_DBG … … 552 564 553 565 566 567 /*============================================================================= 568 * * 569 * * 570 * L I B R A R Y M E T H O D S * 571 * L I B R A R Y M E T H O D S * 572 * L I B R A R Y M E T H O D S * 573 * L I B R A R Y M E T H O D S * 574 * L I B R A R Y M E T H O D S * 575 * * 576 * * 577 *============================================================================*/ 554 578 555 579 … … 631 655 pLib->pDict = NULL; 632 656 return -1; 633 #endif 657 #endif 634 658 } 635 659 … … 908 932 909 933 /* update statistics */ 910 if (pcLoaded) 934 if (pcLoaded) 911 935 (*pcLoaded)++; 912 936 … … 997 1021 998 1022 999 1000 1023 /*============================================================================= 1024 * * 1025 * * 1026 * M O D U L E M E T H O D S * 1027 * M O D U L E M E T H O D S * 1028 * M O D U L E M E T H O D S * 1029 * M O D U L E M E T H O D S * 1030 * M O D U L E M E T H O D S * 1031 * * 1032 * * 1033 *============================================================================*/ 1001 1034 1002 1035 … … 1107 1140 1108 1141 1142 1143 1144 1145 1146 1147 1148 /*============================================================================= 1149 * * 1150 * * 1151 * S Y M B O L M E T H O D S * 1152 * S Y M B O L M E T H O D S * 1153 * S Y M B O L M E T H O D S * 1154 * S Y M B O L M E T H O D S * 1155 * * 1156 * * 1157 *============================================================================*/ 1158 1159 1160 /** 1161 * Calculate the hash value of a symbol. 1162 * @returns hash value. 1163 * @param pszSym Symbol to calculate it for. 1164 * @param cch Symbol length. 1165 * @todo This ain't respecting case sensitivity. 1166 */ 1167 static inline unsigned symHash(const char* pszSym, unsigned cch) 1168 { 1169 unsigned uHash = 0; 1170 while ( cch 1171 && (pszSym[0] != '$' || pszSym[1] != 'w' || pszSym[2] != '$') 1172 ) 1173 { 1174 uHash = uHash * 63377 + *pszSym; 1175 pszSym++; 1176 cch--; 1177 } 1178 uHash %= WLDSYM_HASH_SIZE; 1179 return uHash; 1180 } 1181 1182 /** 1183 * Find the symbol by the name pszName. 1184 * @returns Pointer to matching symbol. 1185 * @returns NULL if not found. 1186 * @param pWld Linker Instance. 1187 * @param pszName Name of the symbol to find. 1188 */ 1189 static PWLDSYM symLookup(PWLD pWld, const char *pszName) 1190 { 1191 PWLDSYM pSym; 1192 const char *psz; 1193 unsigned cchName; 1194 unsigned uHash; 1195 1196 /* 1197 * Calculate the hash of the symbol 1198 * 1199 * It's easier just to add it to the string table than starting to 1200 * check the correct case function and such. As there is a good 1201 * likelyhood that the symbol exists there is little expense in doing 1202 * this compared to the convenience. If it's slow we'll optimize grow.c 1203 * (if possible) and gain everywhere. 1204 */ 1205 psz = strstr(pszName, "$w$"); 1206 cchName = psz ? psz - pszName : strlen(pszName); 1207 pszName = (pWld->fFlags & WLDC_CASE_INSENSITIVE ? strpool_addnu : strpool_addn)(pWld->pStrMisc, pszName, cchName); 1208 uHash = symHash(pszName, cchName); 1209 1210 /* look it up */ 1211 for (pSym = pWld->Global.ap[uHash]; pSym; pSym = pSym->pHashNext) 1212 if (pSym->pszName == pszName) 1213 return pSym; 1214 1215 return NULL; 1216 } 1217 1218 1219 1220 1109 1221 /** 1110 1222 * Symbol enumerator. … … 1322 1434 #endif 1323 1435 1324 1325 /**1326 * Calculate the hash value of a symbol.1327 * @returns hash value.1328 * @param pszSym Symbol to calculate it for.1329 * @param cch Symbol length.1330 * @todo This ain't respecting case sensitivity.1331 */1332 static inline unsigned symHash(const char* pszSym, unsigned cch)1333 {1334 unsigned uHash = 0;1335 while ( cch1336 && (pszSym[0] != '$' || pszSym[1] != 'w' || pszSym[2] != '$')1337 )1338 {1339 uHash = uHash * 65599 + *pszSym;1340 pszSym++;1341 cch--;1342 }1343 uHash %= WLDSYM_HASH_SIZE;1344 return uHash;1345 }1346 1436 1347 1437 /** … … 1465 1555 if ( ( /* 1 */ 1466 1556 (fFlags & WLDSF_TYPEMASK) == WLDSF_UNDEF 1467 && ((pSym->fFlags & WLDSF_TYPEMASK) == WLDSF_PUBLIC || (pSym->fFlags & WLDSF_TYPEMASK) == WLDSF_COMM 1557 && ((pSym->fFlags & WLDSF_TYPEMASK) == WLDSF_PUBLIC || (pSym->fFlags & WLDSF_TYPEMASK) == WLDSF_COMM 1468 1558 || (pSym->fFlags & (WLDSF_TYPEMASK | WLDSF_WEAK)) == WLDSF_UNDEF || (pSym->fFlags & (WLDSF_TYPEMASK)) == WLDSF_IMPORT) 1469 1559 ) || ( /* 2 */ … … 1929 2019 } 1930 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 /*============================================================================= 2032 * * 2033 * * 2034 * M I S C M E T H O D S * 2035 * M I S C M E T H O D S * 2036 * M I S C M E T H O D S * 2037 * M I S C M E T H O D S * 2038 * M I S C M E T H O D S * 2039 * * 2040 * * 2041 *============================================================================*/ 2042 2043 1931 2044 /** 1932 2045 * Reads an OMF module from a file. … … 2290 2403 2291 2404 2292 /******************************************************************************* 2293 * 2294 * P u b l i c I n t e r f a c e 2295 * P u b l i c I n t e r f a c e 2296 * P u b l i c I n t e r f a c e 2297 * 2298 *******************************************************************************/ 2299 2300 2301 2405 2406 2407 2408 2409 2410 2411 /*============================================================================= 2412 * * 2413 * * 2414 * P U B L I C M E T H O D S * 2415 * P U B L I C M E T H O D S * 2416 * P U B L I C M E T H O D S * 2417 * P U B L I C M E T H O D S * 2418 * P U B L I C M E T H O D S * 2419 * * 2420 * * 2421 *============================================================================*/ 2302 2422 2303 2423 /** … … 2344 2464 for (pObj = pWld->pObjs; pObj;) 2345 2465 { 2346 void *pv = pObj; 2466 void *pv = pObj; 2347 2467 modClose(pObj); 2348 2468 pObj = pObj->pNext; … … 2351 2471 for (pObj = pWld->pDef; pObj;) 2352 2472 { 2353 void *pv = pObj; 2473 void *pv = pObj; 2354 2474 modClose(pObj); 2355 2475 pObj = pObj->pNext; … … 2360 2480 for (pLib = pWld->pLibs; pLib;) 2361 2481 { 2362 void *pv = pLib; 2482 void *pv = pLib; 2363 2483 libClose(pLib); 2364 2484 pLib = pLib->pNext; … … 2836 2956 2837 2957 2958 /** Parameter structure for wlddefCallback (module definition parser callback). */ 2959 typedef struct wlddefCallback_param 2960 { 2961 /** Linker Instance. */ 2962 PWLD pWld; 2963 /** Read file stream of the current definition file. */ 2964 FILE *phOrgFile; 2965 /** Write file stream of the new, modified, defintion file. */ 2966 FILE *phNewFile; 2967 /** Our current linenumber index. */ 2968 unsigned iLine; 2969 } WLDDCPARAM, *PWLDDCPARAM; 2838 2970 2839 2971 /** … … 2845 2977 * @param pStmt Statement we're processing. 2846 2978 * @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; 2979 * @param pvArg Pointer to a WLDDCPARAM structure. 2980 * @sketch 2981 * 2982 * If it exports a weak symbol Then 2983 * While linenumber(_md) > linenumber phOrgFile 2984 * Copy line from phOrgFile to phNewFile 2985 * Write modifed line to phNewFile and 2986 * Skip a line in phOrgFile. 2987 * Endif 2988 * 2989 * The caller of _md_parse will make sure the last chunk of the file is 2990 * copied to the new file. 2991 */ 2992 static int wlddefCallback(struct _md *pMD, const _md_stmt *pStmt, _md_token eToken, void *pvArg) 2993 { 2994 PWLDDCPARAM pParam = (PWLDDCPARAM)pvArg; 2857 2995 2858 2996 switch (eToken) … … 2862 3000 */ 2863 3001 case _MD_EXPORTS: 2864 fFlags = uOrdinal = cWords = 0; 3002 { 3003 char szTmp[1024]; 3004 int cch; 3005 unsigned iMDLine; 3006 PWLDSYM pSymInt = NULL; 3007 PWLDSYM pSymExp; 3008 3009 pSymExp = symLookup(pParam->pWld, pStmt->export.entryname); 3010 if (pStmt->export.internalname[0]) 3011 pSymInt = symLookup(pParam->pWld, pStmt->export.internalname); 3012 if (!pSymExp && !pSymInt) 3013 { 3014 wldWarn(pParam->pWld, "Failed to find exported symbols! (%s, %s, %d)", 3015 pStmt->export.entryname, pStmt->export.internalname, pStmt->export.ordinal); 3016 return 0; /* .ignore it. good idea? */ 3017 } 3018 3019 /* Skip it all if neither of the symbols are weak. */ 3020 if ( !(pSymExp->fFlags & WLDSF_WEAK) 3021 && (!pSymInt || !(pSymInt->fFlags & WLDSF_WEAK))) 3022 return 0; 3023 3024 /* Copy line from org to new so we're up to date. */ 3025 iMDLine = _md_get_linenumber(pMD); 3026 while (pParam->iLine < iMDLine) 3027 { 3028 if (!fgets(szTmp, 512 /* this is the size _md_* uses */, pParam->phOrgFile)) 3029 { 3030 wldErr(pParam->pWld, "Read error while reading original .def file."); 3031 strcpy(szTmp, ";read error"); 3032 } 3033 3034 if (++pParam->iLine >= iMDLine) /* skip last line. */ 3035 break; 3036 if (fputs(szTmp, pParam->phNewFile) < 0) 3037 return wldErr(pParam->pWld, "Write error."); 3038 } 3039 3040 /* if the internal symbol is weak, replace it with the right $w$. */ 3041 if (pSymInt && (pSymInt->fFlags & WLDSF_WEAK)) 3042 cch = sprintf(szTmp, " \"%s\" = \"%s\"", pStmt->export.entryname, pSymInt->pszWeakName); 3043 else 3044 cch = sprintf(szTmp, " \"%s\" = \"%s\"", pStmt->export.entryname, pSymExp->pszWeakName); 2865 3045 if (pStmt->export.flags & _MDEP_ORDINAL) 2866 uOrdinal = pStmt->export.ordinal;3046 cch += sprintf(&szTmp[cch], " @%d", pStmt->export.ordinal); 2867 3047 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; 3048 cch += sprintf(&szTmp[cch], " RESIDENTNAME"); 3049 if (pStmt->export.flags & _MDEP_NONAME) 3050 cch += sprintf(&szTmp[cch], " NONAME"); 2873 3051 if (pStmt->export.flags & _MDEP_NODATA) 2874 fFlags |= WLDSEF_NODATA;3052 cch += sprintf(&szTmp[cch], " NODATA"); 2875 3053 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 } 3054 cch += sprintf(&szTmp[cch], " %d", pStmt->export.pwords); 3055 cch += sprintf(&szTmp[cch], " ; !weakld changed this!\n"); 3056 3057 if (fputs(szTmp, pParam->phNewFile) < 0) 3058 return wldErr(pParam->pWld, "Write error."); 2887 3059 break; 3060 } 2888 3061 2889 3062 /* … … 2891 3064 */ 2892 3065 case _MD_parseerror: 2893 wldErr(p Wld, "Parse error %d on line %d. (errorcode=%d stmt=%d)",3066 wldErr(pParam->pWld, "Parse error %d on line %d. (errorcode=%d stmt=%d)", 2894 3067 _md_get_linenumber(pMD), pStmt->error.code, pStmt->error.stmt); 2895 pParam->rc = -2;2896 3068 break; 2897 3069 … … 2900 3072 */ 2901 3073 default: 2902 pMD->2903 3074 break; 2904 3075 } … … 2935 3106 sprintf(pszFile, "%s\\%s%x%lx%d%lx%s", pszTmp, pszPrefix, pid, tv.tv_sec, c, tv.tv_usec, pszSuffix); 2936 3107 } while (!stat(pszFile, &s)); 2937 3108 2938 3109 return 0; 2939 3110 } … … 2956 3127 int wldGenerateWeakAliases(PWLD pWld, char *pszObjName, char *pszDefName) 2957 3128 { 2958 char * psz;2959 3129 FILE * phFile; 2960 3130 int rc; … … 2965 3135 *pszDefName = '\0'; 2966 3136 2967 /* generate the object file */ 3137 /* 3138 * Generate the object file 3139 */ 2968 3140 rc = wldTempFile(pWld, pszObjName, "wk", ".obj"); 2969 3141 if (rc) … … 2993 3165 omf.ach[1+cch] = 0; /* crc */ 2994 3166 fwrite(&omf, omf.hdr.cb + sizeof(OMFREC), 1, phFile); 2995 /* todo: check if we'll need more shit here to satisfy the linkers*/3167 /* todo: link386 doesn't like if there are too many alias in one module btw. */ 2996 3168 2997 3169 … … 3033 3205 } 3034 3206 3035 /* do the definition file */ 3036 if (!rc && pWld->pDef && pszDefName) 3207 3208 /* 3209 * Do the definition file. 3210 * We don't need to do this if the above code failed or 3211 * didn't issue any aliases. 3212 */ 3213 if (!rc && pWld->pDef && pszDefName && pszObjName[0]) 3037 3214 { 3038 3215 rc = wldTempFile(pWld, pszDefName, "wk", ".def"); … … 3041 3218 WLDINFO(pWld, ("Generating definition file '%s' for weak exports.", pszDefName)); 3042 3219 3043 /* open it*/3220 /* open output file */ 3044 3221 phFile = fopen(pszDefName, "w"); 3045 3222 if (phFile) 3046 3223 { 3047 FILE *phOrgDef = fopen(pWld->pDef->pszModName, "r"); 3048 if (phOrgDef) 3224 /* open original file */ 3225 FILE *phOrgFile = fopen(pWld->pDef->pszModName, "r"); 3226 if (phOrgFile) 3049 3227 { 3050 char *pachOrgDef = fsize 3051 struct _md *pMD; 3052 3053 /* open original def file */ 3054 pMD = _md_open(pWld->pDef->pszModName); 3228 /* open original def file with the ModDef library. */ 3229 struct _md *pMD = _md_open(pWld->pDef->pszModName); 3055 3230 if (pMD) 3056 3231 { 3232 WLDDCPARAM param; 3233 param.pWld = pWld; 3234 param.phOrgFile = phOrgFile; 3235 param.phNewFile = phFile; 3236 param.iLine = 0; 3237 3057 3238 /* parse it */ 3058 3239 _md_next_token(pMD); 3059 rc = _md_parse(pMD, wld DefCallbackGenerateWeakAliases, phFile);3240 rc = _md_parse(pMD, wlddefCallback, ¶m); 3060 3241 _md_close(pMD); 3242 3243 /* copy the rest of the file */ 3244 if (!rc) 3245 { 3246 char szTmp[512]; 3247 while (fgets(szTmp, sizeof(szTmp), phOrgFile)) 3248 if (fputs(szTmp, phFile) < 0) 3249 rc = wldErr(pWld, "Write error."); 3250 } 3061 3251 } 3062 3252 else … … 3065 3255 } 3066 3256 else 3067 rc = wldErr(pWld, "Failed to open '%s' for reading.\n", p szDefName);3257 rc = wldErr(pWld, "Failed to open '%s' for reading.\n", pWld->pDef->pszModName); 3068 3258 fclose(phFile); 3069 3259 } -
Property cvs2svn:cvs-rev
changed from
Note:
See TracChangeset
for help on using the changeset viewer.