Changeset 517


Ignore:
Timestamp:
Aug 4, 2003, 2:05:48 AM (22 years ago)
Author:
bird
Message:

Definition files.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/emx/src/emxomf/weakld.c

    • Property cvs2svn:cvs-rev changed from 1.7 to 1.8
    r516 r517  
    5454#define WLDINTERR(pWld, pMod)   wldIntErr(pWld, pMod, __FILE__, __LINE__, __FUNCTION__);
    5555
    56 #if 0 /*def DEBUG*/
     56/*#define WLD_ENABLED_DBG*/
     57#ifdef WLD_ENABLED_DBG
    5758#define SYMDBG(pSym, pszMsg)    symDbg(pSym, pszMsg);
    5859#define WLDDBG(a)               wldDbg a
     
    8283#include <sys/types.h>
    8384#include <sys/omflib.h>
     85#include <sys/moddef.h>
    8486#include "defs.h"
    8587#include "grow.h"
     
    234236             * Valid when type is WLDSF_IMPORT.
    235237             * @{ */
     238            /** Import name. */
     239            const char *        pszImpName;
    236240            /** Import module. */
    237             const char*         pszImpMod;
     241            const char *        pszImpMod;
    238242            /** Import Ordinal (WLDSF_IMPORT).
    239243             * 0 means no ordinal. */
     
    318322    WLDSYMTAB           Global;
    319323
     324    /** Module definition file. */
     325    PWLDMOD             pDef;
     326
    320327    /** Linked list (FIFO) of objects included in the link. */
    321328    PWLDMOD             pObjs;
     
    342349/** @group Weak LD - Linker Methods (Private)
    343350 * @{ */
     351#ifdef WLD_ENABLED_DBG
    344352static void         wldDbg(const char *pszFormat, ...);
     353#endif
    345354static void         wldInfo(const char *pszFormat, ...);
     355static int          wldWarn(PWLD pWld, const char *pszFormat, ...);
    346356static int          wldErr(PWLD pWld, const char *pszFormat, ...);
    347357static void         wldIntErr(PWLD pWld, PWLDMOD pMod, const char *pszFile, unsigned iLine, const char *pszFunction);
    348358static unsigned     pass1ReadOMFMod(PWLD pWld, PWLDMOD pMod, int fLibSearch);
     359/** Parameter structure for wldDefCallback(). */
     360typedef 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;
     369static int          wldDefCallback(struct _md *pMD, const _md_stmt *pStmt, _md_token eToken, void *pvArg);
    349370/** @} */
    350371
     
    358379static int          libLoadUndefSymbols(PWLD pWld, PWLDLIB pLib, PWLDSYM pSym, unsigned *pcLoaded);
    359380static int          libErr(PWLDLIB pLib, const char *pszFormat, ...);
     381#if 0
    360382static void         libWarn(PWLDLIB pLib, const char *pszFormat, ...);
     383#endif
    361384/** @} */
    362385
     
    388411static int          symSearchLibEnum(PWLD pWld, PWLDSYM pSym, void *pvUser);
    389412static inline unsigned symHash(const char* pszSym, unsigned cch);
     413#ifdef WLD_ENABLED_DBG
    390414static void         symDbg(PWLDSYM pSym, const char *pszMsg);
     415#endif
    391416static PWLDSYM      symAdd(PWLD pWld, PWLDMOD pMod, unsigned fFlags, const char *pachName, int cchName, PWLDSYMACTION peAction);
    392417static 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,
    394420                                 const char *pachModName, int cchModName,
    395421                                 unsigned uOrdinal);
     
    422448*******************************************************************************/
    423449
    424 #ifdef DEBUG
     450#ifdef WLD_ENABLED_DBG
    425451/**
    426452 * Put out a debug message.
     
    459485
    460486/**
    461  * Put out a info message.
     487 * Put out a warning message.
     488 * @param   pszFormat   Format string.
     489 * @param   ...         Format arguments.
     490 */
     491static 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.
    462506 * @param   pszFormat   Format string.
    463507 * @param   ...         Format arguments.
     
    918962}
    919963
     964#if 0
    920965/**
    921966 * Put out a warning for this library.
     
    935980        fputc('\n', stderr);
    936981}
    937 
     982#endif
    938983
    939984
     
    12321277
    12331278
    1234 #ifdef DEBUG
     1279#ifdef WLD_ENABLED_DBG
    12351280/**
    12361281 * Symbol debug output.
     
    15221567 * @param   pMod        Pointer to module
    15231568 * @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.
    15261573 * @param   pachModName Module name where the export should be resolved on load time.
    15271574 * @param   cchModName  Length of that name. -1 if zero terminated string.
    15281575 * @param   uOrdinal    The ordinal it's exported with from the module.
    1529  *                      0 if exported by the name pachIntName represent.
     1576 *                      0 if exported by the name pachImpName represent.
    15301577 */
    15311578PWLDSYM 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,
    15331581                     const char *pachModName, int cchModName,
    15341582                     unsigned uOrdinal)
     
    15361584    WLDSYMACTION    eAction;
    15371585    PWLDSYM         pSym;
     1586    const char *    pszImpName;
    15381587    const char *    pszImpMod;
    15391588
    15401589    pSym = symAdd(pWld, pMod, WLDSF_IMPORT | (fLibSearch ? WLDSF_LIBSEARCH : 0),
    1541                   pachIntName, cchIntName, &eAction);
     1590                  pachName, cchName, &eAction);
    15421591    if (!pSym)
    15431592        return NULL;
    15441593
     1594    /* Add the strings we'll need them very soon */
    15451595    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 */
    15461608    switch (eAction)
    15471609    {
     
    15491611        case WLDSA_UP:
    15501612            pSym->u.import.pszImpMod = pszImpMod;
     1613            pSym->u.import.pszImpName = pszImpName;
    15511614            pSym->u.import.uImpOrd   = uOrdinal;
    15521615            break;
     
    15591622                {
    15601623                    pSym->u.import.pszImpMod = pszImpMod;
     1624                    pSym->u.import.pszImpName = pszImpName;
    15611625                    pSym->u.import.uImpOrd = uOrdinal;
    15621626                }
     
    15641628                {
    15651629                    if (    pSym->u.import.pszImpMod != pszImpMod
     1630                        &&  pSym->u.import.pszImpName != pszImpName
    15661631                        &&  pSym->u.import.uImpOrd != uOrdinal)
    15671632                    {
    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);
    15701645                    }
    15711646                    else if (pSym->u.import.uImpOrd != uOrdinal)
     
    15731648                        modWarn(pMod, "Existing import '%s' have different ordinal (%d != %d).",
    15741649                                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);
    15801650                    }
    15811651                }
     
    20352105                                pSym = symAddImport(pWld, pMod, fLibSearch,
    20362106                                                    u1.pch + 1, *u1.puch,
     2107                                                    u1.pch + 1, *u1.puch,
    20372108                                                    u2.pch + 1, *u2.puch,
    20382109                                                    ul);
     
    22822353        return 8;
    22832354    }
    2284     if (pWld->fFlags & WLDC_VERBOSE)
    2285         fprintf(stderr, "weakld: info: adding object %s.\n", pszName);
     2355    WLDINFO(pWld, ("adding object %s.\n", pszName));
    22862356
    22872357    /*
     
    23482418
    23492419/**
     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 */
     2430static 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/**
    23502509 * Adds an definition file to the linking process.
    23512510 * The definition file will be analysed and the file handle closed.
     
    23632522int     wldAddDefFile(PWLD pWld, FILE *phFile, const char *pszName)
    23642523{
     2524    struct _md *    pMD;
     2525    int             rc = -1;
    23652526    if (!phFile)
    23662527        phFile = fopen(pszName, "r");
    23672528    if (!phFile)
    23682529    {
    2369         fprintf(stderr, "weakld: cannot open deffile file '%s'.\n", pszName);
     2530        wldErr(pWld, "cannot open deffile file '%s'.\n", pszName);
    23702531        return 8;
    23712532    }
    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, &param);
     2559        _md_close(pMD);
     2560    }
     2561    else
     2562        wldErr(pWld, "_md_use_file on '%s'.\n", pszName);
     2563
     2564    fclose(phFile);
     2565    return rc;
    23772566}
    23782567
     
    24032592        return 8;
    24042593    }
    2405     if (pWld->fFlags & WLDC_VERBOSE)
    2406         fprintf(stderr, "weakld: info: adding library %s\n", pszName);
     2594    WLDINFO(pWld, ("adding library %s\n", pszName));
    24072595
    24082596    /* add it to the link, do nothing till we're asked to do the searching. */
Note: See TracChangeset for help on using the changeset viewer.