Changeset 3751
- Timestamp:
- Mar 4, 2012, 10:17:28 PM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
TabularUnified trunk/emx/src/emxomf/weakld.c ¶
r3668 r3751 240 240 */ 241 241 WLDSF_WKEXT = 0x0005, 242 /** Exported name. 243 * This is used when the exported name differs from the internal one. 244 * This name is not considered in the linking, only the internal one. */ 245 WLDSF_EXP_NM = 0x0006, 242 246 /** @} */ 243 247 … … 266 270 WLDSF_ALIAS = 0x0800, 267 271 268 /** Exported symbol.269 * This symbol is to be exported. */270 WLDSF_EXPORT = 0x1000,271 272 272 /** Internal flags which indicates that the symbol was exported in 273 273 * the definition file. This to select symbols which only appears in … … 277 277 278 278 /** Internal flag to say that we've already aliased this weak 279 * in the definition file. 280 */ 279 * in the definition file. */ 281 280 WLDSF_WEAKALIASDONE = 0x8000 282 281 } fFlags; … … 326 325 327 326 /** Symbol this is an alias for. 328 * Valid when WLDSF_ALIAS isset. */327 * Valid when WLDSF_ALIAS or WLDSF_EXP_NM are set. */ 329 328 struct wldsym * pAliasFor; 330 329 331 330 /** @group Export Attributes 332 * Valid when WLDSF_EXP ORTis set.331 * Valid when WLDSF_EXP_NM is set. 333 332 * @{ */ 334 333 /** Export flags. */ … … 386 385 /** Global symbols. */ 387 386 WLDSYMTAB Global; 387 /** Exported symbols. */ 388 WLDSYMTAB Exported; 388 389 389 390 /** Module definition file. */ … … 515 516 static void symDumpReferers(PWLDSYM pSym); 516 517 static void symDbg(PWLDSYM pSym, const char *pszMsg); 517 static PWLDSYM symAdd(PWLD pWld, PWLDMOD pMod, unsigned fFlags, const char *pachName, int cchName, PWLDSYM ACTION peAction);518 static PWLDSYM symAdd(PWLD pWld, PWLDMOD pMod, unsigned fFlags, const char *pachName, int cchName, PWLDSYMTAB pSymTab, PWLDSYMACTION peAction); 518 519 static PWLDSYM symAddImport(PWLD pWld, PWLDMOD pMod, int fLibSearch, 519 520 const char *pachName, int cchName, … … 1615 1616 * @param pWld Linker Instance. 1616 1617 * @param pszName Name of the symbol to find. 1617 */ 1618 static PWLDSYM symLookup(PWLD pWld, const char *pszName) 1618 * @param pSymTab The symbol table to look it up in. 1619 */ 1620 static PWLDSYM symLookupCommon(PWLD pWld, const char *pszName, PWLDSYMTAB pSymTab) 1619 1621 { 1620 1622 PWLDSYM pSym; … … 1649 1651 1650 1652 /* look it up */ 1651 for (pSym = p Wld->Global.ap[uHash % WLDSYM_HASH_SIZE]; pSym; pSym = pSym->pHashNext)1653 for (pSym = pSymTab->ap[uHash % WLDSYM_HASH_SIZE]; pSym; pSym = pSym->pHashNext) 1652 1654 if (SYM_EQUAL(pWld, pSym, pszName, fFlags, uHash, cchName)) 1653 1655 return pSym; … … 1657 1659 1658 1660 1661 /** 1662 * Find the symbol by the name pszName. 1663 * 1664 * @returns Pointer to matching symbol. 1665 * @returns NULL if not found. 1666 * @param pWld Linker Instance. 1667 * @param pszName Name of the symbol to find. 1668 */ 1669 static PWLDSYM symLookup(PWLD pWld, const char *pszName) 1670 { 1671 return symLookupCommon(pWld, pszName, &pWld->Global); 1672 } 1673 1674 1675 /** 1676 * Find the export symbol by the name pszName. 1677 * 1678 * @returns Pointer to matching symbol. 1679 * @returns NULL if not found. 1680 * @param pWld Linker Instance. 1681 * @param pszName Name of the symbol to find. 1682 */ 1683 static PWLDSYM symLookupExport(PWLD pWld, const char *pszName) 1684 { 1685 return symLookupCommon(pWld, pszName, &pWld->Exported); 1686 } 1659 1687 1660 1688 … … 1864 1892 case WLDSF_UNDEF: psz += sprintf(psz, "UNDEF"); break; 1865 1893 case WLDSF_WKEXT: psz += sprintf(psz, "WKEXT"); break; 1894 case WLDSF_EXP_NM: psz += sprintf(psz, "EXPORT"); break; 1866 1895 default: psz += sprintf(psz, "!!!internal error!!! "); asm("int $3"); break; 1867 1896 } … … 1870 1899 if (pSym->fFlags & WLDSF_ALIAS) 1871 1900 psz += sprintf(psz, " ALIAS"); 1872 if (pSym->fFlags & WLDSF_EXPORT)1873 psz += sprintf(psz, " EXPORT");1874 1901 if (pSym->fFlags & WLDSF_UNCERTAIN) 1875 1902 psz += sprintf(psz, " UNCERTAIN"); … … 1933 1960 * @param fFlags Symbol flags. 1934 1961 * All the flags in WLDSF_TYPEMASK, WLDSF_WEAK and WLDSF_LIBSEARCH. 1935 * WLDSF_EXPORT isn't handled and should not be defined.1936 1962 * WLDSF_ALIAS and WLDSF_UNCERTAIN is ignored as they have no 1937 1963 * sideeffects when resolving symbols. 1938 1964 * @param pachName Pointer to symbol name. 1939 1965 * @param cchName Length to add, use -1 if zeroterminated. 1966 * @param pSymTab The symbol table to add it to. 1940 1967 * @param pflAction What we actually did. 1941 1968 * WLDSA_NEW, WLDSA_UP, WLDSA_OLD, WLDSA_ERR. … … 1972 1999 * 1973 2000 */ 1974 static PWLDSYM symAdd(PWLD pWld, PWLDMOD pMod, unsigned fFlags, const char *pachName, int cchName, PWLDSYMACTION peAction) 2001 static PWLDSYM symAdd(PWLD pWld, PWLDMOD pMod, unsigned fFlags, const char *pachName, int cchName, 2002 PWLDSYMTAB pSymTab, PWLDSYMACTION peAction) 1975 2003 { 1976 2004 PWLDSYM pSym; /* The symbol. */ … … 2009 2037 2010 2038 /* search for existing symbol */ 2011 for (pSym = p Wld->Global.ap[uHash % WLDSYM_HASH_SIZE]; pSym; pSym = pSym->pHashNext)2039 for (pSym = pSymTab->ap[uHash % WLDSYM_HASH_SIZE]; pSym; pSym = pSym->pHashNext) 2012 2040 if (SYM_EQUAL(pWld, pSym, pszName, fFlags, uHash, cchName)) 2013 2041 break; … … 2029 2057 WLDINFO(pWld, ("Weak symbol '%s'.", pSym->pszWeakName)); 2030 2058 } 2031 pSym->pHashNext = p Wld->Global.ap[uHash % WLDSYM_HASH_SIZE];2032 p Wld->Global.ap[uHash % WLDSYM_HASH_SIZE] = pSym;2059 pSym->pHashNext = pSymTab->ap[uHash % WLDSYM_HASH_SIZE]; 2060 pSymTab->ap[uHash % WLDSYM_HASH_SIZE] = pSym; 2033 2061 if (peAction) *peAction = WLDSA_NEW; 2034 2062 WLDDBG2(("symAdd: New symbol '%s'", pSym->pszName)); … … 2045 2073 * 5. adding a WEAK PUBLIC or WEAK COMM where a PUBLIC or COMM exists. 2046 2074 * 6. adding a WEAK UNDEF where WEAK UNDEF exists. 2075 * 7. adding a EXP_NM that already exists. 2047 2076 */ 2048 2077 if ( ( /* 1 */ … … 2065 2094 ((fFlags & (WLDSF_TYPEMASK | WLDSF_WEAK)) == (WLDSF_UNDEF | WLDSF_WEAK)) 2066 2095 && ((pSym->fFlags & (WLDSF_TYPEMASK | WLDSF_WEAK)) == (WLDSF_UNDEF | WLDSF_WEAK)) 2096 ) || ( /* 7 */ 2097 ((fFlags & WLDSF_TYPEMASK) == WLDSF_EXP_NM) 2098 && ((pSym->fFlags & WLDSF_TYPEMASK) == WLDSF_EXP_NM) 2067 2099 )) 2068 2100 { … … 2215 2247 2216 2248 pSym = symAdd(pWld, pMod, WLDSF_IMPORT | (fLibSearch ? WLDSF_LIBSEARCH : 0), 2217 pachName, cchName, & eAction);2249 pachName, cchName, &pWld->Global, &eAction); 2218 2250 if (!pSym) 2219 2251 return NULL; … … 2244 2276 case WLDSA_NEW: 2245 2277 case WLDSA_UP: 2246 pSym->u.import.pszImpMod = pszImpMod;2278 pSym->u.import.pszImpMod = pszImpMod; 2247 2279 pSym->u.import.pszImpName = pszImpName; 2248 pSym->u.import.uImpOrd = uOrdinal;2280 pSym->u.import.uImpOrd = uOrdinal; 2249 2281 break; 2250 2282 … … 2323 2355 unsigned uOrdinal) 2324 2356 { 2325 PWLDSYM pSym; 2357 PWLDSYM pSymExp; 2358 PWLDSYM pSymInt; 2326 2359 2327 2360 /* set default name */ … … 2331 2364 cchIntName = cchExpName; 2332 2365 } 2366 2367 /* 2368 * Add the internal name. 2369 */ 2370 pSymInt = symAdd(pWld, pMod, WLDSF_UNDEF | (fLibSearch ? WLDSF_LIBSEARCH : 0), 2371 pachIntName, cchIntName, &pWld->Global, NULL); 2372 if (!pSymInt) 2373 return NULL; 2333 2374 2334 2375 /* 2335 2376 * Add external name. 2336 2377 */ 2337 pSym = symAdd(pWld, pMod, WLDSF_UNDEF| (fLibSearch ? WLDSF_LIBSEARCH : 0),2338 pachExpName, cchExpName, NULL);2339 if (!pSym )2378 pSymExp = symAdd(pWld, pMod, WLDSF_EXP_NM | (fLibSearch ? WLDSF_LIBSEARCH : 0), 2379 pachExpName, cchExpName, &pWld->Exported, NULL); 2380 if (!pSymExp) 2340 2381 return NULL; 2341 2382 … … 2343 2384 * Is the exported symbol already exported? 2344 2385 */ 2345 if (pSym->fFlags & WLDSF_EXPORT) 2346 { 2347 if ( (pSym->fExport & WLDSEF_DEF_FILE) 2386 if (pSymExp->pAliasFor) 2387 { 2388 if (pSymExp->pAliasFor != pSymInt) 2389 modWarn(pMod, "Export '%s' (int '%s') is already defined with a different resolution '%s'.", 2390 pSymExp->pszName, pSymInt->pszName, pSymExp->pAliasFor->pszName); 2391 else if ( (pSymExp->fExport & WLDSEF_DEF_FILE) 2392 && (fExport & WLDSEF_DEF_FILE)) 2393 modWarn(pMod, "Export '%s' (int '%s') is already defined.", pSymExp->pszName, pSymInt->pszName); 2394 2395 if ( !(pSymExp->fExport & WLDSEF_DEF_FILE) 2348 2396 && (fExport & WLDSEF_DEF_FILE)) 2349 modWarn(pMod, "Export '%s' is already defined.", pSym->pszName); 2350 if ( !(pSym->fExport & WLDSEF_DEF_FILE) 2351 && (fExport & WLDSEF_DEF_FILE)) 2352 pSym->fExport = fExport; 2353 } 2354 else 2355 { 2356 PWLDSYM pSymAlias; 2357 2358 pSym->fFlags |= WLDSF_EXPORT; 2359 2360 /* 2361 * Add internal name. 2362 */ 2363 pSymAlias = symAdd(pWld, pMod, WLDSF_UNDEF | (fLibSearch ? WLDSF_LIBSEARCH : 0), 2364 pachIntName, cchIntName, NULL); 2365 if (!pSymAlias) 2366 return NULL; 2367 if (pSymAlias != pSym && (pSym->fFlags & WLDSF_ALIAS) && pSym->pAliasFor != pSymAlias) 2368 { 2369 modErr(pMod, "Can't export an alias!."); 2370 pSym = NULL; 2371 } 2372 else 2373 { 2374 if (pSym != pSymAlias) 2375 { 2376 pSym->fFlags |= WLDSF_ALIAS; 2377 pSym->fFlags &= ~WLDSF_UNDEF; 2378 pSym->pAliasFor = pSymAlias; 2379 } 2380 pSym->fExport = fExport; 2381 pSym->cExpWords = cExpWords; 2382 pSym->uExpOrd = uOrdinal; 2383 } 2384 } 2385 2386 return pSym; 2397 pSymExp->fExport = fExport; 2398 return pSymExp; 2399 } 2400 2401 pSymExp->pAliasFor = pSymInt; 2402 pSymExp->fExport = fExport; 2403 pSymExp->cExpWords = cExpWords; 2404 pSymExp->uExpOrd = uOrdinal; 2405 2406 return pSymExp; 2387 2407 } 2388 2408 … … 2408 2428 2409 2429 pSym = symAdd(pWld, pMod, WLDSF_PUBLIC | (fLibSearch ? WLDSF_LIBSEARCH : 0), 2410 pachName, cchName, NULL);2430 pachName, cchName, &pWld->Global, NULL); 2411 2431 if (!pSym) 2412 2432 return NULL; … … 2432 2452 2433 2453 pSym = symAdd(pWld, pMod, WLDSF_UNDEF | WLDSF_UNCERTAIN | (fLibSearch ? WLDSF_LIBSEARCH : 0), 2434 pachName, cchName, NULL);2454 pachName, cchName, &pWld->Global, NULL); 2435 2455 if (!pSym) 2436 2456 return NULL; … … 2461 2481 */ 2462 2482 pSym = symAdd(pWld, pMod, WLDSF_PUBLIC | WLDSF_ALIAS | (fLibSearch ? WLDSF_LIBSEARCH : 0), 2463 pachAliasName, cchAliasName, & eAction);2483 pachAliasName, cchAliasName, &pWld->Global, &eAction); 2464 2484 if (!pSym) 2465 2485 return NULL; … … 2472 2492 { 2473 2493 PWLDSYM pSym2 = symAdd(pWld, pMod, WLDSF_UNDEF | (fLibSearch ? WLDSF_LIBSEARCH : 0), 2474 pachName, cchName, NULL);2494 pachName, cchName, &pWld->Global, NULL); 2475 2495 if (!pSym2) 2476 2496 return NULL; … … 2523 2543 */ 2524 2544 pSym = symAdd(pWld, pMod, WLDSF_COMM | (fLibSearch ? WLDSF_LIBSEARCH : 0), 2525 pachName, cchName, & eAction);2545 pachName, cchName, &pWld->Global, &eAction); 2526 2546 if (!pSym) 2527 2547 return NULL; … … 2552 2572 2553 2573 return pSym; 2574 } 2575 2576 2577 /** 2578 * Destroys a symbol table, freeing all symbols 2579 * 2580 * @param pSymTab The symbol table to destroy. 2581 */ 2582 static void symDestroyTab(PWLDSYMTAB pSymTab) 2583 { 2584 unsigned uHash; 2585 for (uHash = 0; uHash < sizeof(pSymTab->ap) / sizeof(pSymTab->ap[0]); uHash++) 2586 { 2587 PWLDSYM pSym = pSymTab->ap[uHash]; 2588 while (pSym) 2589 { 2590 PWLDSYM pNext = pSym->pHashNext; 2591 if (pSym->paReferers) 2592 free(pSym->paReferers); 2593 free(pSym); 2594 pSym = pNext; 2595 } 2596 pSymTab->ap[uHash] = NULL; 2597 } 2554 2598 } 2555 2599 … … 3022 3066 PWLDMOD pObj; 3023 3067 PWLDLIB pLib; 3024 unsigned uHash;3025 3068 3026 3069 if (!pWld) … … 3055 3098 3056 3099 /* free symbols */ 3057 for (uHash = 0; uHash < sizeof(pWld->Global.ap) / sizeof(pWld->Global.ap[0]); uHash++) 3058 { 3059 PWLDSYM pSym = pWld->Global.ap[uHash]; 3060 while (pSym) 3061 { 3062 PWLDSYM pNext = pSym->pHashNext; 3063 if (pSym->paReferers) 3064 free(pSym->paReferers); 3065 free(pSym); 3066 pSym = pNext; 3067 } 3068 } 3100 symDestroyTab(&pWld->Global); 3101 symDestroyTab(&pWld->Exported); 3069 3102 3070 3103 /* members and finally the instance structure. */ … … 3275 3308 uOrdinal = pStmt->import.ordinal; 3276 3309 pSym = symAddImport(pParam->pWld, pParam->pMod, 0, 3310 pStmt->import.internalname[0] ? pStmt->import.internalname : pStmt->import.entryname, -1, 3277 3311 pStmt->import.entryname[0] ? pStmt->import.entryname : pStmt->import.internalname, -1, 3278 pStmt->import.internalname, -1,3279 3312 pStmt->import.modulename, -1, 3280 3313 uOrdinal); … … 3956 3989 PWLDSYM pSymExp; 3957 3990 3958 pSymExp = symLookup (pParam->pWld, pStmt->export.entryname);3991 pSymExp = symLookupExport(pParam->pWld, pStmt->export.entryname); 3959 3992 if (pStmt->export.internalname[0]) 3960 3993 pSymInt = symLookup(pParam->pWld, pStmt->export.internalname); … … 4199 4232 { 4200 4233 if (0)//pWld->fFlags & WLDC_LINKER_WLINK) 4201 rc = symEnum(pWld, &pWld-> Global,4202 WLDSF_EXPORT | WLDSF_EXPORT_DEF | WLDSF_WEAK, WLDSF_EXPORT |WLDSF_EXPORT_DEF | WLDSF_WEAK | WLDSF_WEAKALIASDONE,4234 rc = symEnum(pWld, &pWld->Exported, 4235 WLDSF_EXPORT_DEF | WLDSF_WEAK, WLDSF_EXPORT_DEF | WLDSF_WEAK | WLDSF_WEAKALIASDONE, 4203 4236 wldGenerateDefExportEnum, ¶m); 4204 4237 else 4205 rc = symEnum(pWld, &pWld-> Global,4206 WLDSF_ EXPORT | WLDSF_WEAK, WLDSF_EXPORT |WLDSF_WEAK | WLDSF_EXPORT_DEF | WLDSF_WEAKALIASDONE,4238 rc = symEnum(pWld, &pWld->Exported, 4239 WLDSF_WEAK, WLDSF_WEAK | WLDSF_EXPORT_DEF | WLDSF_WEAKALIASDONE, 4207 4240 wldGenerateDefExportEnum, ¶m); 4208 4241 }
Note:
See TracChangeset
for help on using the changeset viewer.