Changeset 517
- Timestamp:
- Aug 4, 2003, 2:05:48 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.7
to1.8
r516 r517 54 54 #define WLDINTERR(pWld, pMod) wldIntErr(pWld, pMod, __FILE__, __LINE__, __FUNCTION__); 55 55 56 #if 0 /*def DEBUG*/ 56 /*#define WLD_ENABLED_DBG*/ 57 #ifdef WLD_ENABLED_DBG 57 58 #define SYMDBG(pSym, pszMsg) symDbg(pSym, pszMsg); 58 59 #define WLDDBG(a) wldDbg a … … 82 83 #include <sys/types.h> 83 84 #include <sys/omflib.h> 85 #include <sys/moddef.h> 84 86 #include "defs.h" 85 87 #include "grow.h" … … 234 236 * Valid when type is WLDSF_IMPORT. 235 237 * @{ */ 238 /** Import name. */ 239 const char * pszImpName; 236 240 /** Import module. */ 237 const char *pszImpMod;241 const char * pszImpMod; 238 242 /** Import Ordinal (WLDSF_IMPORT). 239 243 * 0 means no ordinal. */ … … 318 322 WLDSYMTAB Global; 319 323 324 /** Module definition file. */ 325 PWLDMOD pDef; 326 320 327 /** Linked list (FIFO) of objects included in the link. */ 321 328 PWLDMOD pObjs; … … 342 349 /** @group Weak LD - Linker Methods (Private) 343 350 * @{ */ 351 #ifdef WLD_ENABLED_DBG 344 352 static void wldDbg(const char *pszFormat, ...); 353 #endif 345 354 static void wldInfo(const char *pszFormat, ...); 355 static int wldWarn(PWLD pWld, const char *pszFormat, ...); 346 356 static int wldErr(PWLD pWld, const char *pszFormat, ...); 347 357 static void wldIntErr(PWLD pWld, PWLDMOD pMod, const char *pszFile, unsigned iLine, const char *pszFunction); 348 358 static unsigned pass1ReadOMFMod(PWLD pWld, PWLDMOD pMod, int fLibSearch); 359 /** Parameter structure for wldDefCallback(). */ 360 typedef struct wldDefCallback_param 361 { 362 /** Linker instance. */ 363 PWLD pWld; 364 /** Name of .def file. */ 365 PWLDMOD pMod; 366 /** Callback return code. Zero ok; non-zero failure; */ 367 int rc; 368 } WLDDEFCBPARAM, *PWLDDEFCBPARAM; 369 static int wldDefCallback(struct _md *pMD, const _md_stmt *pStmt, _md_token eToken, void *pvArg); 349 370 /** @} */ 350 371 … … 358 379 static int libLoadUndefSymbols(PWLD pWld, PWLDLIB pLib, PWLDSYM pSym, unsigned *pcLoaded); 359 380 static int libErr(PWLDLIB pLib, const char *pszFormat, ...); 381 #if 0 360 382 static void libWarn(PWLDLIB pLib, const char *pszFormat, ...); 383 #endif 361 384 /** @} */ 362 385 … … 388 411 static int symSearchLibEnum(PWLD pWld, PWLDSYM pSym, void *pvUser); 389 412 static inline unsigned symHash(const char* pszSym, unsigned cch); 413 #ifdef WLD_ENABLED_DBG 390 414 static void symDbg(PWLDSYM pSym, const char *pszMsg); 415 #endif 391 416 static PWLDSYM symAdd(PWLD pWld, PWLDMOD pMod, unsigned fFlags, const char *pachName, int cchName, PWLDSYMACTION peAction); 392 417 static PWLDSYM symAddImport(PWLD pWld, PWLDMOD pMod, int fLibSearch, 393 const char *pachIntName, int cchIntName, 418 const char *pachName, int cchName, 419 const char *pachImpName, int cchImpName, 394 420 const char *pachModName, int cchModName, 395 421 unsigned uOrdinal); … … 422 448 *******************************************************************************/ 423 449 424 #ifdef DEBUG450 #ifdef WLD_ENABLED_DBG 425 451 /** 426 452 * Put out a debug message. … … 459 485 460 486 /** 461 * Put out a info message. 487 * Put out a warning message. 488 * @param pszFormat Format string. 489 * @param ... Format arguments. 490 */ 491 static int wldWarn(PWLD pWld, const char *pszFormat, ...) 492 { 493 va_list args; 494 fprintf(stderr, "weakld: warning: "); 495 496 va_start(args, pszFormat); 497 vfprintf(stderr, pszFormat, args); 498 va_end(args); 499 if (pszFormat[strlen(pszFormat) - 1] != '\n') 500 fputc('\n', stderr); 501 return 4; 502 } 503 504 /** 505 * Put out a error message. 462 506 * @param pszFormat Format string. 463 507 * @param ... Format arguments. … … 918 962 } 919 963 964 #if 0 920 965 /** 921 966 * Put out a warning for this library. … … 935 980 fputc('\n', stderr); 936 981 } 937 982 #endif 938 983 939 984 … … 1232 1277 1233 1278 1234 #ifdef DEBUG1279 #ifdef WLD_ENABLED_DBG 1235 1280 /** 1236 1281 * Symbol debug output. … … 1522 1567 * @param pMod Pointer to module 1523 1568 * @param fLibSearch Set if we're doing library search at this time. 1524 * @param pachIntName Internal name, the one which can be referenced in this module. 1525 * @param cchIntName Length of that name. -1 if zero terminated string. 1569 * @param pachName The name which can be referenced in this module. 1570 * @param cchName Length of that name. -1 if zero terminated string. 1571 * @param pachImpName Internal name, the name used to import the symbol. 1572 * @param cchImpName Length of that name. -1 if zero terminated string. 1526 1573 * @param pachModName Module name where the export should be resolved on load time. 1527 1574 * @param cchModName Length of that name. -1 if zero terminated string. 1528 1575 * @param uOrdinal The ordinal it's exported with from the module. 1529 * 0 if exported by the name pachI ntName represent.1576 * 0 if exported by the name pachImpName represent. 1530 1577 */ 1531 1578 PWLDSYM symAddImport(PWLD pWld, PWLDMOD pMod, int fLibSearch, 1532 const char *pachIntName, int cchIntName, 1579 const char *pachName, int cchName, 1580 const char *pachImpName, int cchImpName, 1533 1581 const char *pachModName, int cchModName, 1534 1582 unsigned uOrdinal) … … 1536 1584 WLDSYMACTION eAction; 1537 1585 PWLDSYM pSym; 1586 const char * pszImpName; 1538 1587 const char * pszImpMod; 1539 1588 1540 1589 pSym = symAdd(pWld, pMod, WLDSF_IMPORT | (fLibSearch ? WLDSF_LIBSEARCH : 0), 1541 pach IntName, cchIntName, &eAction);1590 pachName, cchName, &eAction); 1542 1591 if (!pSym) 1543 1592 return NULL; 1544 1593 1594 /* Add the strings we'll need them very soon */ 1545 1595 pszImpMod = strpool_addnu(pWld->pStrMisc, pachModName, cchModName); 1596 pszImpName = NULL; 1597 if (!uOrdinal) 1598 { 1599 if (!pachImpName || cchImpName == 0 ) 1600 { 1601 pachImpName = pachName; 1602 cchImpName = cchName; 1603 } 1604 pszImpName = strpool_addn(pWld->pStrMisc, pachImpName, cchImpName); 1605 } 1606 1607 /* Process the symbol */ 1546 1608 switch (eAction) 1547 1609 { … … 1549 1611 case WLDSA_UP: 1550 1612 pSym->u.import.pszImpMod = pszImpMod; 1613 pSym->u.import.pszImpName = pszImpName; 1551 1614 pSym->u.import.uImpOrd = uOrdinal; 1552 1615 break; … … 1559 1622 { 1560 1623 pSym->u.import.pszImpMod = pszImpMod; 1624 pSym->u.import.pszImpName = pszImpName; 1561 1625 pSym->u.import.uImpOrd = uOrdinal; 1562 1626 } … … 1564 1628 { 1565 1629 if ( pSym->u.import.pszImpMod != pszImpMod 1630 && pSym->u.import.pszImpName != pszImpName 1566 1631 && pSym->u.import.uImpOrd != uOrdinal) 1567 1632 { 1568 modWarn(pMod, "Existing import '%s' have different module name than the new ('%s' != '%s') and different ordinal (%d != %d).", 1569 pSym->pszName, pSym->u.import.pszImpMod, pszImpMod, pSym->u.import.uImpOrd, uOrdinal); 1633 modWarn(pMod, "Existing import '%s' have different module name than the new ('%s' != '%s'), different ordinal (%d != %d), and different name (%s != %s).", 1634 pSym->pszName, pSym->u.import.pszImpMod, pszImpMod, pSym->u.import.uImpOrd, uOrdinal, pSym->u.import.pszImpName, pszImpName); 1635 } 1636 else if (pSym->u.import.pszImpMod != pszImpMod) 1637 { 1638 modWarn(pMod, "Existing import '%s' have different module name than the new ('%s' != '%s').", 1639 pSym->pszName, pSym->u.import.pszImpMod, pszImpMod); 1640 } 1641 else if (pSym->u.import.pszImpName != pszImpName) 1642 { 1643 modWarn(pMod, "Existing import '%s' have different import name (%s != %s).", 1644 pSym->pszName, pSym->u.import.pszImpName, pszImpName); 1570 1645 } 1571 1646 else if (pSym->u.import.uImpOrd != uOrdinal) … … 1573 1648 modWarn(pMod, "Existing import '%s' have different ordinal (%d != %d).", 1574 1649 pSym->pszName, pSym->u.import.uImpOrd, uOrdinal); 1575 }1576 else if (pSym->u.import.pszImpMod != pszImpMod)1577 {1578 modWarn(pMod, "Existing import '%s' have different module name than the new ('%s' != '%s').",1579 pSym->pszName, pSym->u.import.pszImpMod, pszImpMod);1580 1650 } 1581 1651 } … … 2035 2105 pSym = symAddImport(pWld, pMod, fLibSearch, 2036 2106 u1.pch + 1, *u1.puch, 2107 u1.pch + 1, *u1.puch, 2037 2108 u2.pch + 1, *u2.puch, 2038 2109 ul); … … 2282 2353 return 8; 2283 2354 } 2284 if (pWld->fFlags & WLDC_VERBOSE) 2285 fprintf(stderr, "weakld: info: adding object %s.\n", pszName); 2355 WLDINFO(pWld, ("adding object %s.\n", pszName)); 2286 2356 2287 2357 /* … … 2348 2418 2349 2419 /** 2420 * Callback function for parsing a module definition file. 2421 * 2422 * @returns 0 on success. 2423 * @returns -1 to stop the parsing. 2424 * @param pMD Pointer to module definition file handle. 2425 * @param pStmt Statement we're processing. 2426 * @param eToken Token we're processing. 2427 * @param pvArg Private arguments - pointer to an WLDDEFCBPARAM structure. 2428 * On failure, we'll update the structures rc member. 2429 */ 2430 static int wldDefCallback(struct _md *pMD, const _md_stmt *pStmt, _md_token eToken, void *pvArg) 2431 { 2432 unsigned fFlags; 2433 unsigned uOrdinal; 2434 unsigned cWords; 2435 PWLDSYM pSym; 2436 PWLDDEFCBPARAM pParam = (PWLDDEFCBPARAM)pvArg; 2437 2438 switch (eToken) 2439 { 2440 /* 2441 * One import. 2442 */ 2443 case _MD_IMPORTS: 2444 uOrdinal = 0; 2445 if (pStmt->import.flags & _MDIP_ORDINAL) 2446 uOrdinal = pStmt->import.ordinal; 2447 pSym = symAddImport(pParam->pWld, pParam->pMod, 0, 2448 pStmt->import.entryname, -1, 2449 pStmt->import.internalname, -1, 2450 pStmt->import.modulename, -1, 2451 uOrdinal); 2452 if (!pSym) 2453 { 2454 pParam->rc = -3; 2455 return -3; 2456 } 2457 break; 2458 2459 2460 /* 2461 * One export. 2462 */ 2463 case _MD_EXPORTS: 2464 fFlags = uOrdinal = cWords = 0; 2465 if (pStmt->export.flags & _MDEP_ORDINAL) 2466 uOrdinal = pStmt->export.ordinal; 2467 if (pStmt->export.flags & _MDEP_RESIDENTNAME) 2468 fFlags |= WLDSEF_NONRESIDENT; 2469 else if (pStmt->export.flags & _MDEP_NONAME) 2470 fFlags |= WLDSEF_NONAME; 2471 else 2472 fFlags |= WLDSEF_DEFAULT; 2473 if (pStmt->export.flags & _MDEP_NODATA) 2474 fFlags |= WLDSEF_NODATA; 2475 if (pStmt->export.flags & _MDEP_PWORDS) 2476 cWords = pStmt->export.pwords; 2477 pSym = symAddExport(pParam->pWld, pParam->pMod, 0, 2478 fFlags, cWords, 2479 pStmt->export.entryname, -1, 2480 pStmt->export.internalname, -1, 2481 uOrdinal); 2482 if (!pSym) 2483 { 2484 pParam->rc = -4; 2485 return -4; 2486 } 2487 break; 2488 2489 /* 2490 * Parse error. 2491 */ 2492 case _MD_parseerror: 2493 modErr(pParam->pMod, "Parse error %d on line %d. (errorcode=%d stmt=%d)", 2494 _md_get_linenumber(pMD), pStmt->error.code, pStmt->error.stmt); 2495 pParam->rc = -2; 2496 break; 2497 2498 /* 2499 * Ignore everything else (it's here to get rid of gcc warnings). 2500 */ 2501 default: 2502 break; 2503 } 2504 return 0; 2505 } 2506 2507 2508 /** 2350 2509 * Adds an definition file to the linking process. 2351 2510 * The definition file will be analysed and the file handle closed. … … 2363 2522 int wldAddDefFile(PWLD pWld, FILE *phFile, const char *pszName) 2364 2523 { 2524 struct _md * pMD; 2525 int rc = -1; 2365 2526 if (!phFile) 2366 2527 phFile = fopen(pszName, "r"); 2367 2528 if (!phFile) 2368 2529 { 2369 fprintf(stderr, "weakld:cannot open deffile file '%s'.\n", pszName);2530 wldErr(pWld, "cannot open deffile file '%s'.\n", pszName); 2370 2531 return 8; 2371 2532 } 2372 if (pWld->fFlags & WLDC_VERBOSE) 2373 fprintf(stderr, "weakld: info: adding deffile %s\n", pszName); 2374 2375 2376 return 0; 2533 WLDINFO(pWld, ("adding deffile %s\n", pszName)); 2534 2535 if (pWld->pDef) 2536 wldWarn(pWld, "%s: There is already a definition file '%s' loaded.", pszName, pWld->pDef->pszModName); 2537 2538 /* 2539 * Process the .def file and be done with it. 2540 */ 2541 pMD = _md_use_file(phFile); 2542 if (pMD) 2543 { 2544 PWLDMOD pMod; 2545 WLDDEFCBPARAM param; 2546 2547 pMod = xmalloc(sizeof(*pMod)); 2548 memset(pMod, 0, sizeof(*pMod)); 2549 pMod->off = -1; 2550 pMod->pszModName = strpool_add(pWld->pStrMisc, pszName); 2551 pWld->pDef = pMod; 2552 2553 /* parse it */ 2554 _md_next_token(pMD); 2555 param.pWld = pWld; 2556 param.pMod = pMod; 2557 param.rc = 0; 2558 rc = _md_parse(pMD, wldDefCallback, ¶m); 2559 _md_close(pMD); 2560 } 2561 else 2562 wldErr(pWld, "_md_use_file on '%s'.\n", pszName); 2563 2564 fclose(phFile); 2565 return rc; 2377 2566 } 2378 2567 … … 2403 2592 return 8; 2404 2593 } 2405 if (pWld->fFlags & WLDC_VERBOSE) 2406 fprintf(stderr, "weakld: info: adding library %s\n", pszName); 2594 WLDINFO(pWld, ("adding library %s\n", pszName)); 2407 2595 2408 2596 /* add it to the link, do nothing till we're asked to do the searching. */ -
Property cvs2svn:cvs-rev
changed from
Note:
See TracChangeset
for help on using the changeset viewer.