Changeset 535


Ignore:
Timestamp:
Aug 5, 2003, 9:46:37 PM (22 years ago)
Author:
bird
Message:

trying to update definition file...

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 to 1.21
    r534 r535  
    113113static FILE *response_file = NULL;
    114114
     115/* Force the use of a response file from the next put_arg(). */
     116static int force_response_file = FALSE;
     117
    115118/* Weak alias object file. */
    116119static char weakobj_fname[_MAX_PATH];
     120
     121/* Weak definition file (modified def_fname). */
     122static char weakdef_fname[_MAX_PATH];
    117123
    118124/* Non-zero if debugging information is to be omitted.  Set by the -s
     
    327333
    328334      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))
    330337        {
    331338
     
    385392              command_line[line_len++] = '@';
    386393              strcpy (command_line+line_len, response_fname);
     394
     395              if (force_response_file)
     396                force_response_file = FALSE;
    387397            }
    388398          else if (line_len != 0)
     
    645655    if (    !strnicmp(pOpt->name, "/I", 2)
    646656        ||  !strnicmp(pOpt->name, "-I", 2))
    647         fFlags |= WLDC_VERBOSE;
     657        fFlags = fFlags;                /* Ignore - require opt_t. */
    648658    else
    649659    if (    !strnicmp(pOpt->name, "/NOIN", 5)
     
    704714      /* generate weak aliases. */
    705715      if (!rc)
    706         rc = wldGenerateWeakobj (pwld, weakobj_fname);
     716        rc = wldGenerateWeakAliases (pwld, weakobj_fname, weakdef_fname);
    707717      if (!rc && weakobj_fname[0])
    708718        add_name_list (&add_obj_fnames, weakobj_fname);
     719      if (!rc && weakdef_fname[0])
     720        strcpy (def_fname, weakdef_fname);
    709721
    710722      /* cleanup the linker */
     
    740752  line_len = 0;
    741753  response_flag = rsp;
     754  force_response_file = FALSE;
    742755}
    743756
     
    827840      if (!(argi % 32))
    828841        argv = xrealloc(argv, sizeof(argv[0]) * (argi + 32 + 1));
    829       argv[argi++] = xstrdup(psz);
     842      argv[argi++] = psz;
    830843
    831844      /* next */
     
    839852    fprintf(stderr, "*** Return from %s is %d\n", pszwhat, rc);
    840853
     854  free(argv);
    841855  return rc;
    842856}
     
    862876      remove (weakobj_fname);
    863877      weakobj_fname[0] = '\0';
     878    }
     879  if (weakdef_fname[0] != '\0')
     880    {
     881      remove (weakdef_fname);
     882      weakdef_fname[0] = '\0';
    864883    }
    865884}
     
    12591278
    12601279  /* Put the object file names onto the command line. */
    1261 
     1280 
     1281  force_response_file = TRUE;           /* link386 workaround. */
    12621282  put_args (obj_fnames, TRUE);
    12631283  put_arg (",", FALSE, FALSE);
  • trunk/src/emx/src/emxomf/weakld.c

    • Property cvs2svn:cvs-rev changed from 1.12 to 1.13
    r534 r535  
    8282#include <string.h>
    8383#include <sys/types.h>
     84#include <sys/time.h>
     85#include <sys/stat.h>
     86#include <process.h>
    8487#include <sys/omflib.h>
    8588#include <sys/moddef.h>
     
    564567    {
    565568        pLib->phFile = fopen(pLib->pszLibName, "rb");
    566         if (pLib->phFile)
     569        if (!pLib->phFile)
    567570            libErr(pLib, "Failed to open library.");
    568571    }
     
    576579static void         libClose(PWLDLIB pLib)
    577580{
    578     if (!pLib->phFile)
     581    if (pLib->phFile)
    579582    {
    580583        fclose(pLib->phFile);
     
    23422345    {
    23432346        void *pv = pObj;   
     2347        modClose(pObj);
    23442348        pObj = pObj->pNext;
    23452349        free(pv);
     
    23482352    {
    23492353        void *pv = pObj;   
     2354        modClose(pObj);
    23502355        pObj = pObj->pNext;
    23512356        free(pv);
     
    23562361    {
    23572362        void *pv = pLib;   
     2363        libClose(pLib);
    23582364        pLib = pLib->pNext;
    23592365        free(pv);
     
    24112417        pWld->ppObjsAdd = &pMod->pNext;
    24122418        rc = pass1ReadOMFMod(pWld, pMod, 0);
     2419        modClose(pMod);
    24132420    }
    24142421    else if (OmfRec.chType == LIBHDR)
     
    24352442                }
    24362443                rc = pass1ReadOMFMod(pWld, pMod, 0);
     2444                pMod->phFile = NULL;
    24372445                if (rc)
    24382446                    break;
     
    24472455            fread(&OmfRec, sizeof(OmfRec), 1, phFile);
    24482456        }
     2457        fclose(phFile);
    24492458    }
    24502459    else
    24512460    {
     2461        fclose(phFile);
    24522462        fprintf(stderr, "weakld: invalid object file '%s'.\n", pszName);
    24532463        rc = -1;
     
    28262836
    28272837
     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 */
     2850static 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 */
     2919static 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
    28282942/**
    28292943 * Generates a object file containing alias for resolving the weak
     
    28342948 * @returns 0 on success.
    28352949 * @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 */
     2956int     wldGenerateWeakAliases(PWLD pWld, char *pszObjName, char *pszDefName)
    28412957{
    28422958    char *      psz;
     
    28442960    int         rc;
    28452961
    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");
    28622975    if (phFile)
    28632976    {
     
    28933006                WLDINFO(pWld, ("No weak alias needed, deleting file."));
    28943007            fclose(phFile);
    2895             remove(pszName);
    2896             *pszName = '\0';
     3008            remove(pszObjName);
     3009            *pszObjName = '\0';
    28973010        }
    28983011        else
     
    29063019           else
    29073020           {
    2908                wldErr(pWld, "Failed to write to '%s'.", pszName);
     3021               wldErr(pWld, "Failed to write to '%s'.", pszObjName);
    29093022               rc = -1;
    29103023               fclose(phFile);
    2911                remove(pszName);
    2912                *pszName = '\0';
     3024               remove(pszObjName);
     3025               *pszObjName = '\0';
    29133026           }
    29143027        }
     
    29163029    else
    29173030    {
    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';
    29203087    }
    29213088
  • trunk/src/emx/src/emxomf/weakld.h

    • Property cvs2svn:cvs-rev changed from 1.4 to 1.5
    r534 r535  
    5656int     wldAddLibrary(PWLD pWld, FILE *phFile, const char *pszName);
    5757int     wldPass1(PWLD pWld);
    58 int     wldGenerateWeakobj(PWLD pwld, char *pszName);
     58int     wldGenerateWeakAliases(PWLD pwld, char *pszObjName, char *pszDefName);
    5959int     wldDestroy(PWLD pWld);
    6060/** @} */
Note: See TracChangeset for help on using the changeset viewer.