Changeset 942


Ignore:
Timestamp:
Jan 11, 2004, 1:06:08 AM (22 years ago)
Author:
bird
Message:

Implmented new library search order.

Location:
trunk/src/emx/src
Files:
2 edited

Legend:

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

    • Property cvs2svn:cvs-rev changed from 1.34 to 1.35
    r941 r942  
    4747{
    4848  struct name_list *next;
     49  unsigned flags;
    4950  char *name;
    5051} name_list;
     
    8990   command line is added to this list.  The -l option also adds an
    9091   entry to this list. add_lib_fnames is used to add another entry at
    91    the end of the list. */
     92   the end of the list.
     93   The flags member indicates library search method. If set search for
     94   static lib, if clear search for shared lib before search for static lib. */
    9295static name_list *lib_fnames = NULL;
    9396static name_list **add_lib_fnames = &lib_fnames;
     
    163166extern void *xrealloc (void *ptr, size_t n);
    164167extern char *xstrdup (const char *s);
    165 static void add_name_list (name_list ***add, const char *src);
     168static void add_name_list (name_list ***add, const char *src, unsigned flags);
    166169static void conv_path (char *name);
    167170static void put_arg (const char *src, int path, int quotable);
     
    234237   list. */
    235238
    236 static void add_name_list (name_list ***add, const char *src)
    237 {
    238   name_list *new;
    239 
    240   new = xmalloc (sizeof (name_list));
    241   new->next = NULL;
    242   new->name = xstrdup (src);
    243   *(*add) = new;
    244   (*add) = &new->next;
     239static void add_name_list (name_list ***add, const char *src, unsigned flags)
     240{
     241  name_list *node;
     242
     243  node = xmalloc (sizeof (name_list));
     244  node->next  = NULL;
     245  node->name  = xstrdup (src);
     246  node->flags = flags;
     247  *(*add) = node;
     248  (*add) = &node->next;
    245249}
    246250
     
    469473}
    470474
    471 /* Check if the given file is a valid OMF library. */
    472 
    473 static int check_omf_library (FILE *f)
     475/**
     476 * Checks if the stream phFile is an OMF library.
     477 *
     478 * @returns 1 if OMF library.
     479 * @returns 0 if not OMF library.
     480 * @param   phFile  Filestream to check.
     481 */
     482static int check_omf_library(FILE *phFile)
    474483{
    475484#pragma pack(1)
    476   struct
    477   {
    478     byte rec_type;
    479     word rec_len;
    480     dword dict_offset;
    481     word dict_blocks;
    482     byte flags;
    483   } libhdr;
     485    struct
     486    {
     487        byte rec_type;
     488        word rec_len;
     489        dword dict_offset;
     490        word dict_blocks;
     491        byte flags;
     492    } libhdr;
    484493#pragma pack()
    485494
    486   if (fread (&libhdr, 1, sizeof(libhdr), f) == sizeof (libhdr)
    487    && !fseek (f, 0, SEEK_SET)
    488    && libhdr.rec_type == LIBHDR
    489    && libhdr.flags <= 1 /* ASSUME only first bit is used... */
    490       )
    491     {
    492       int page_size = libhdr.rec_len + 3;
    493       if (page_size >= 16
    494        && page_size <= 32768
    495        && !(page_size & (page_size - 1)) != 0)
     495    if (    fread(&libhdr, 1, sizeof(libhdr), phFile) == sizeof (libhdr)
     496        &&  !fseek(phFile, 0, SEEK_SET)
     497        &&  libhdr.rec_type == LIBHDR
     498        &&  libhdr.flags <= 1 /* ASSUME only first bit is used... */
     499       )
     500    {
     501        int page_size = libhdr.rec_len + 3;
     502        if (page_size >= 16
     503            && page_size <= 32768
     504            && !(page_size & (page_size - 1)) != 0)
     505            return 1;
     506    }
     507    return 0;
     508}
     509
     510
     511/**
     512 * Checks if the stream phFile is an OMF object or library.
     513 *
     514 * @returns 1 if OMF.
     515 * @returns 0 if not OMF.
     516 * @param   phFile  Filestream to check.
     517 */
     518static int check_omf(FILE *phFile)
     519{
     520#pragma pack(1)
     521    struct
     522    {
     523        byte rec_type;
     524        word rec_len;
     525    } omfhdr;
     526#pragma pack()
     527    if (    fread(&omfhdr, 1, sizeof(omfhdr), phFile) == sizeof (omfhdr)
     528        &&  omfhdr.rec_type == THEADR
     529        &&  omfhdr.rec_len >= sizeof(omfhdr)
     530        &&  !fseek(phFile, 0, SEEK_SET)
     531       )
    496532        return 1;
    497     }
    498 
    499   return 0;
    500 }
    501 
    502 
    503 /* Checks if the file handle is to an omf object or library file. */
    504 
    505 static int check_omf (FILE *f)
    506 {
    507 #pragma pack(1)
    508   struct
    509   {
    510     byte rec_type;
    511     word rec_len;
    512   } omfhdr;
    513 #pragma pack()
    514   if (fread (&omfhdr, 1, sizeof(omfhdr), f) == sizeof (omfhdr)
    515    && omfhdr.rec_type == THEADR
    516    && omfhdr.rec_len >= sizeof(omfhdr)
    517    && !fseek (f, 0, SEEK_SET)
    518       )
    519     {
    520       return 1;
    521     }
    522 
    523   return !fseek (f, 0, SEEK_SET) && check_omf_library (f);
     533
     534    return !fseek(phFile, 0, SEEK_SET)
     535        && check_omf_library(phFile);
     536}
     537
     538
     539/**
     540 * Checks if the stream phFile is an LX DLL.
     541 *
     542 * @returns 1 if LX DLL.
     543 * @returns 0 if not LX DLL.
     544 * @param   phFile  File stream to check.
     545 */
     546static int check_lx_dll(FILE *phFile)
     547{
     548    unsigned long   ul;
     549    char            achMagic[2];
     550
     551    if (    fseek(phFile, 0, SEEK_SET)
     552        ||  fread(&achMagic, 1, 2, phFile) != 2)
     553        goto thats_not_it;
     554
     555    if (!memcmp(achMagic, "MZ", 2))
     556    {
     557        if (    fseek(phFile, 0x3c, SEEK_SET)
     558            ||  fread(&ul, 1, 4, phFile) != 4 /* offset of the 'new' header */
     559            ||  ul < 0x40
     560            ||  ul >= 0x10000000 /* 512MB stubs sure */
     561            ||  fseek(phFile, ul, SEEK_SET)
     562            ||  fread(&achMagic, 1, 2, phFile) != 2)
     563            goto thats_not_it;
     564    }
     565
     566    if (    memcmp(achMagic, "LX", 2)
     567        ||  fseek(phFile, 14, SEEK_CUR)
     568        ||  fread(&ul, 1, 4, phFile) != 4) /*e32_mflags*/
     569        goto thats_not_it;
     570
     571#define E32MODDLL        0x08000L
     572#define E32MODPROTDLL    0x18000L
     573#define E32MODMASK       0x38000L
     574    if (   (ul & E32MODMASK) != E32MODDLL
     575        && (ul & E32MODMASK) != E32MODPROTDLL)
     576        goto thats_not_it;
     577
     578    /* it's a LX DLL! */
     579    fseek(phFile, 0, SEEK_SET);
     580    return 1;
     581
     582
     583thats_not_it:
     584    fseek(phFile, 0, SEEK_SET);
     585    return 0;
    524586}
    525587
     
    533595 * @param   pszPrefix   Prefix.
    534596 * @param   pszSuffix   Suffix.
     597 * @param   pszLooklike Filename which name is to be incorporated into the temp filename.
    535598 * @remark  The code is nicked from the weak linker.
    536599 */
    537 static int      make_tempfile(char *pszFile, const char *pszPrefix, const char *pszSuffix)
     600static int      make_tempfile(char *pszFile, const char *pszPrefix, const char *pszSuffix, const char *pszLooklike)
    538601{
    539602    struct stat     s;
    540603    unsigned        c = 0;
     604    char            szLooklike[32];
    541605    pid_t           pid = getpid();
    542606    const char *    pszTmp = getenv("TMP");
     
    544608    if (!pszTmp)    pszTmp = getenv("TEMP");
    545609    if (!pszTmp)    pszTmp = ".";
     610    if (pszLooklike)
     611    {
     612        int     cch;
     613        char   *psz = (char*)pszLooklike; /* we're nice fellows. */
     614        while ((psz = strpbrk(psz, ":/\\")) != NULL)
     615            pszLooklike = ++psz;
     616        cch = strlen(pszLooklike);
     617        if (cch + 3 > sizeof(szLooklike))
     618            cch = sizeof(szLooklike) - 3;
     619        szLooklike[0] = '_';
     620        memcpy(&szLooklike[1], pszLooklike, cch);
     621        szLooklike[cch + 1] = '_';
     622        szLooklike[cch + 2] = '\0';
     623        pszLooklike = psz = &szLooklike[0];
     624        while ((psz = strpbrk(psz, ".@%^&#()")) != NULL)
     625            *psz++ = '_';
     626    }
     627    else
     628        pszLooklike = "";
    546629
    547630    do
     
    551634            return -1;
    552635        gettimeofday(&tv, NULL);
    553         sprintf(pszFile, "%s\\%s%x%lx%d%lx%s", pszTmp, pszPrefix, pid, tv.tv_sec, c, tv.tv_usec, pszSuffix);
     636        sprintf(pszFile, "%s\\%s%s%x%lx%d%lx%s", pszTmp, pszPrefix, pszLooklike, pid, tv.tv_sec, c, tv.tv_usec, pszSuffix);
    554637    } while (!stat(pszFile, &s));
    555638
     
    558641
    559642
    560 /* Converts the file indicated by pf & pszFilename to omf closing f and
    561    updating filename with the new (temporary filename). A successful
    562    return from the function returns a pointe to the filestream for the
    563    converted file. On failure NULL is returned, f is closed adn filename
    564    is undefined. */
    565 
    566 static FILE *aout_to_omf (FILE *pf, char *pszFilename, int fLibrary)
     643/**
     644 * Converts the file indicated by phFile & pszFilename to omf closing
     645 * phFile and updating pszFilename with the new (temporary filename).
     646 *
     647 * @returns Pointer to an filestream for the converted file and pszFilename
     648 *          containing the name of the converted file.
     649 * @returns exit the program
     650 * @param   phFile      Filestream of the file to convert. (close this)
     651 * @param   pszFilename Name of the file to convert on entry.
     652 *                      Name of the converted file on return.
     653 */
     654static FILE *aout_to_omf(FILE *pf, char *pszFilename, int fLibrary)
    567655{
    568656    int         rc;
     
    573661
    574662    if (opt_t)
    575       fprintf(stderr, "emxomfld: info: converting %s %s to OMF.\n",
    576               fLibrary ? "lib" : "obj", pszFilename);
     663        fprintf(stderr, "emxomfld: info: converting %s %s to OMF.\n",
     664                fLibrary ? "lib" : "obj", pszFilename);
    577665
    578666    /*
     
    581669    pName = xmalloc(sizeof(name_list));
    582670    pName->name = pszNewFile = xmalloc(_MAX_PATH);
    583     if (make_tempfile(pszNewFile, "ldconv", fLibrary ? ".lib" : ".obj"))
     671    if (make_tempfile(pszNewFile, "ldconv", fLibrary ? ".lib" : ".obj", pszFilename))
    584672    {
    585673        free(pszNewFile);
     
    590678     * Do the conversion.
    591679     */
    592     rc = spawnlp(P_WAIT, "emxomf.exe", "emxomf.exe",
    593                  "-o", pszNewFile, pszFilename, NULL);
     680    rc = spawnlp(P_WAIT, "emxomf.exe", "emxomf.exe", "-o", pszNewFile, pszFilename, NULL);
    594681    if (!rc)
    595682    {
     
    605692
    606693            if (opt_t)
    607               fprintf(stderr, "emxomfld: info: convert result '%s'.\n",
    608                       pszFilename);
     694                fprintf(stderr, "emxomfld: info: convert result '%s'.\n",
     695                        pszFilename);
    609696            return pf;
    610697        }
     
    614701    free(pName);
    615702
    616     fprintf (stderr, "emxomfld: a.out to omf conversion failed for '%s'.\n",
    617              pszFilename);
    618     exit (2);
     703    fprintf(stderr, "emxomfld: a.out to omf conversion failed for '%s'.\n",
     704            pszFilename);
     705    exit(1);
    619706    return NULL;
    620707}
    621708
    622709
    623 /* Converts the file indicated by pf & pszFilename to omf closing f and
    624    updating filename with the new (temporary filename). A successful
    625    return from the function returns a pointe to the filestream for the
    626    converted file. On failure NULL is returned, f is closed adn filename
    627    is undefined. */
    628 
    629 static FILE *lx_to_omf (FILE *pf, char *pszFilename)
     710/**
     711 * Converts the file indicated by phFile & pszFilename to omf closing
     712 * phFile and updating pszFilename with the new (temporary filename).
     713 *
     714 * @returns Pointer to an filestream for the converted file and pszFilename
     715 *          containing the name of the converted file.
     716 * @returns exit the program
     717 * @param   phFile      Filestream of the file to convert. (close this)
     718 * @param   pszFilename Name of the file to convert on entry.
     719 *                      Name of the converted file on return.
     720 */
     721static FILE *lx_to_omf(FILE *pf, char *pszFilename)
    630722{
    631723    int         rc;
     
    636728
    637729    if (opt_t)
    638       fprintf(stderr, "emxomfld: info: converting %s %s to an OMF import lib.\n",
    639              "lib", pszFilename);
     730        fprintf(stderr, "emxomfld: info: converting %s %s to an OMF import lib.\n",
     731                "lib", pszFilename);
    640732
    641733    /*
     
    644736    pName = xmalloc(sizeof(name_list));
    645737    pName->name = pszNewFile = xmalloc(_MAX_PATH);
    646     if (make_tempfile(pszNewFile, "ldconv", ".lib"))
     738    if (make_tempfile(pszNewFile, "ldconv", ".lib", pszFilename))
    647739    {
    648740        free(pszNewFile);
     
    653745     * Do the conversion.
    654746     */
    655     rc = spawnlp(P_WAIT, "emximp.exe", "emximp.exe",
    656                  "-o", pszNewFile, pszFilename, NULL);
     747    rc = spawnlp(P_WAIT, "emximp.exe", "emximp.exe", "-o", pszNewFile, pszFilename, NULL);
    657748    if (!rc)
    658749    {
     
    677768    free(pName);
    678769
    679     fprintf (stderr, "emxomfld: a.out to omf conversion failed for '%s'.\n",
    680              pszFilename);
    681     exit (2);
     770    fprintf(stderr, "emxomfld: lx dll to omf conversion failed for '%s'.\n",
     771            pszFilename);
     772    exit(2);
    682773    return NULL;
    683774}
    684775
    685776
    686 
    687 /* Finds the full path of a OMF library or object file.
    688 
    689    This function may perform conversion from a.out to omf if that feature
    690    is enabled.
    691 
    692    Object files and libraries will be searched for using the LIB env.var
    693    (which is exported so that it is used by ILINK/LINK386 as well),
    694    if not found by their path directly. Note that finding object files in
    695    the LIB paths contradicts the standard Unix behaviour, so it is a kind
    696    of a hack, but this is the way ILINK and LINK386 work.
    697 
    698    If file has no extension, the .obj and .o extensions are tried in turn
    699    for object files, and .lib then .a are tried in turn for libraries.
    700    Additionaly, for libraries we check for a file with the 'lib' prefix,
    701    if one without the 'lib' prefix was not found. The '.o' and '.a'
    702    extensions are tried in the last case since otherwise we can find
    703    a 'something.a' when 'libsomething.lib' is available.
    704 
    705    We support linking with DLLs if they have a path as we're not yet ready
    706    to start searching for them or anything of that kind of real UNIXy
    707    behaviour.
    708 
    709    Returns pointer to file stream and FULLNAME set to it's name on success.
    710    Returns NULL and FULLNAME a copy of NAME on failure.
    711    */
    712 
    713 static FILE *find_objlib (char *fullname, const char *name, int is_library)
    714 {
    715   static const char *exts [2][2] = { { ".obj", ".o" }, { ".lib", ".a" } };
    716   FILE *f;
    717   size_t pathlen, namelen = strlen (name);
    718   const char *libpath, *x;
    719   int i, has_ext = 0, is_dll = 0, has_path;
    720 
    721   /* Check if the file name has a path. If it has, we won't check the
    722      LIB directories, and won't check if it has a object file extension. */
    723   has_path = (strpbrk (name, ":/\\") != NULL);
    724   if (has_path)
    725     {
    726       has_ext = 1;
    727       x = strrchr (name, '.');
    728       if (x && !stricmp(x, ".dll"))
    729         is_dll = 1;
    730     }
    731   else
    732     {
    733       /* Check if file has a real extension. If it is a object file it should
    734          have either .o or .obj, and if it is a library it should have either
    735          the .a or .lib extension. Otherwise we don't consider it a extension. */
    736       x = strrchr (name, '.');
    737       if (x)
    738         for (i = 0; i < 2; i++)
    739           if (!stricmp (x, exts [is_library][i]))
     777/**
     778 * Finds the full path of a OMF object file and opens the file.
     779 *
     780 * This function may perform conversion from a.out to omf if that feature
     781 * is enabled.
     782 *
     783 * We choose to be UNIX compatible her, and not search the LIB env.var.
     784 * for unqualified objects. Nor will we add any suffixes to the name
     785 * if it's witout any extension.
     786 *
     787 * @returns Pointer to a file stream for the object file to use in the link.
     788 * @returns NULL on failure with pszFullname containing a copy of
     789 *          pszName (or something like that).
     790 * @param   pszFullname Where to store the name of the file to be used
     791 *                      in the linking (and which stream is returned).
     792 * @param   pszName     Object name given to on the linker commandline.
     793 */
     794static FILE *find_obj(char *pszFullname, const char *pszName)
     795{
     796    FILE   *phFile;
     797    char   *psz;
     798
     799    /*
     800     * Make abspath with slashes the desired way and such.
     801     */
     802    if (_abspath(pszFullname, pszName, _MAX_PATH + 1))
     803    {
     804        printf("emxomfld: _abspath failed on '%s'!!!\n", pszName);
     805        exit(1);
     806    }
     807
     808    psz = pszFullname;
     809    while ((psz = strchr(psz, '/')) != NULL)
     810      *psz++ = '\\';
     811
     812    /*
     813     * Try open the file.
     814     */
     815    phFile = fopen(pszFullname, "rb");
     816    if (!phFile)
     817        return NULL;
     818
     819    /*
     820     * If autoconversion check if such is needed.
     821     */
     822    if (    autoconvert_flag
     823        &&  !check_omf(phFile))
     824        phFile = aout_to_omf(phFile, pszFullname, FALSE);
     825
     826    return phFile;
     827}
     828
     829
     830
     831/* Finds the full path of a library file and opens the file.
     832 *
     833 * This function may perform conversion from a.out to omf if that feature
     834 * is enabled.
     835 *
     836 * The function assumes that LIB has been updated with all the search paths
     837 * specified on the commandline.
     838 *
     839 * Library names with no extension are given extensions after the rules
     840 * indicated by the IS_SHARED parameter. If IS_SHARED is set then libraries
     841 * with suffixes indicating shared libraries will be looked for before
     842 * libraries with suffixes indicated static libraries. The list is as
     843 * follows for set IS_SHARED:
     844 *      1. _dll.lib
     845 *      2. .lib
     846 *      3. .dll
     847 *      4. _s.lib
     848 *
     849 * If IS_SHARED is clear:
     850 *      1. _s.lib
     851 *      2. .lib
     852 *
     853 * Library names with no path is searched for in the semicolon separated list
     854 * of paths the env.var. LIB contains. For each directory in LIB we'll start
     855 * by see if it contains a 'lib' prefixed file, if not found we'll check for
     856 * the unprefixed filename. If we're appending suffixes too, we'll loop thru
     857 * all the possible suffixes for each directory before advancing to the next,
     858 * having the prefixing as the inner most loop.
     859 *
     860 * @returns Pointer to a file stream for the library file to use in the link.
     861 * @returns NULL on failure with pszFullname containing a copy of
     862 *          pszName (or something like that).
     863 * @param   pszFullname Where to store the name of the file to be used
     864 *                      in the linking (and which stream is returned).
     865 * @param   pszName     Library name given to on the linker commandline.
     866 */
     867static FILE *find_lib(char *pszFullname, const char *pszName, int fShared)
     868{
     869    /* Suffix list for shared linking. */
     870    static const char *apszSharedSuff[]     = { "_dll.lib", "_dll.a", ".lib",  ".a", ".dll", "_s.lib", "_s.a", NULL };
     871    /* Suffix list for static linking. */
     872    static const char *apszStaticSuff[]     = { "_s.lib", "_s.a", ".lib",  ".a", NULL };
     873    /* Suffix list for names with extension. */
     874    static const char *apszExtensionSuff[]  = { "", NULL };
     875    /* Prefix list for names with path. */
     876    static const char *apszWithPathPref[]   = { "", NULL };
     877    /* Prefix list for names with no path. */
     878    static const char *apszWithoutPathPref[]= { "lib", "", NULL };
     879    int             fPath;              /* set if the library name have a path. */
     880    int             fExt;               /* set if the library name have an extension. */
     881    const char    **papszSuffs;         /* Pointer to the suffix list. */
     882    const char    **papszPrefs;         /* Pointer to the prefix list. */
     883    const char     *pszLibPath;         /* The path we're searching. */
     884    size_t          cchCurPath;         /* Size of the current path. */
     885    size_t          cchName = strlen(pszName);
     886    const char     *psz;
     887
     888    /*
     889     * Check if the file name has a path.
     890     * (If it has, we won't check the LIB directories.)
     891     * Choose the prefix list accordingly.
     892     */
     893    fPath = (strpbrk(pszName, ":/\\") != NULL);
     894    papszPrefs = fPath ? apszWithPathPref : apszWithoutPathPref;
     895
     896    /*
     897     * Check if the file has a real extension.
     898     * Real extension means, .lib, .dll or .a. It also implies something
     899     * before the dot.
     900     * Choose the suffix list accordingly.
     901     */
     902    fExt = (    (cchName > 4 && !stricmp(pszName + cchName - 4, ".lib"))
     903            ||  (cchName > 4 && !stricmp(pszName + cchName - 4, ".dll"))
     904            ||  (cchName > 2 && !stricmp(pszName + cchName - 2, ".a")) );
     905
     906    if (!fExt)
     907        papszSuffs = fShared ? &apszSharedSuff[0] : &apszStaticSuff[0];
     908    else
     909        papszSuffs = apszExtensionSuff;
     910
     911    /*
     912     * Loop 1: LIB (with a fake .\ as the first iteration)
     913     * (Looping on pszLibPath, with preinitiated cchCurPath & pszFullname.)
     914     */
     915    cchCurPath = 0;
     916    if (!fPath)
     917    {
     918        cchCurPath = 2;
     919        memcpy(pszFullname, ".\\", 2);
     920    }
     921    pszLibPath = getenv("LIB");
     922    do
     923    {
     924        /*
     925         * Loop2: Suffixes.
     926         */
     927        int iSuff;
     928        for (iSuff = 0; papszSuffs[iSuff]; iSuff++)
     929        {
     930            /*
     931             * Loop3: Prefixes.
     932             */
     933            int iPref;
     934            for (iPref = 0; papszPrefs[iPref]; iPref++)
    740935            {
    741               has_ext = 1;
     936                FILE   *phFile;
     937                int     cch = strlen(papszPrefs[iPref]);
     938
     939                /*
     940                 * Construct name.
     941                 */
     942                memcpy(&pszFullname[cchCurPath], papszPrefs[iPref], cch);
     943                cch = cchCurPath + cch;
     944                memcpy(&pszFullname[cch], pszName, cchName);
     945                cch += cchName;
     946                strcpy(&pszFullname[cch], papszSuffs[iSuff]);
     947
     948                /*
     949                 * Open and if necessary convert it.
     950                 */
     951                phFile = fopen(pszFullname, "rb");
     952                if (phFile)
     953                {
     954                    if (autoconvert_flag)
     955                    {
     956                        if (check_lx_dll(phFile))
     957                            phFile = lx_to_omf(phFile, pszFullname);
     958                        else if (!check_omf(phFile))
     959                            phFile = aout_to_omf(phFile, pszFullname, TRUE);
     960                    }
     961
     962                    /* Replace forward slashes with backslashes (link386). */
     963                    while ((pszFullname = strchr(pszFullname, '/')) != NULL)
     964                      *pszFullname++ = '\\';
     965                    return phFile;
     966                }
     967            } /* next prefix */
     968        } /* next suffix */
     969
     970        /*
     971         * If a path was specified or no LIB we're done now.
     972         */
     973        if (fPath || !pszLibPath)
     974            break;
     975
     976        /*
     977         * Next LIB part.
     978         */
     979        for (;;)
     980        {
     981            psz = strchr(pszLibPath, ';');
     982            if (!psz)
     983                psz = strchr(pszLibPath, '\0');
     984            cchCurPath = psz - pszLibPath;
     985            if (cchCurPath)
     986            {
     987                memcpy(pszFullname, pszLibPath, cchCurPath);
     988                pszLibPath = psz + (*psz == ';');
     989                /* Append last slash if it is not there */
     990                if (   pszFullname[cchCurPath - 1] != '/'
     991                    && pszFullname[cchCurPath - 1] != '\\')
     992                    pszFullname[cchCurPath++] = '\\';
     993                break;
     994              }
     995            if (!*psz)
    742996              break;
    743             }
    744     }
    745 
    746   /* First loop search file name as-is, then search the paths
    747      in the LIB environment variable. */
    748   libpath = getenv ("LIB");
    749   pathlen = 0;
    750   if (!has_path)
    751     {
    752       memcpy(fullname, ".\\", 2);
    753       pathlen = 2;
    754     }
    755   do
    756     {
    757       /* Step 0: check path+filename (+'.obj/.lib' if !has_ext)
    758        * Step 1: if is_library check path+'lib'+filename (+'.lib' if !has_ext)
    759        * Step 2: check path+filename (+'.o/.a' if !has_ext)
    760        * Step 3: if is_library check path+'lib'+filename (+'.a' if !has_ext)
    761        */
    762       for (i = 0; i < 4; i++)
    763         {
    764           char *cur = fullname + pathlen;
    765 
    766           if ((i & 1) && (!is_library || has_path))
    767             continue;
    768 
    769           if (i & 1)
    770             {
    771               memcpy (cur, "lib", 3);
    772               cur += 3;
    773             }
    774 
    775           /* Include final zero in the case we won't append the extension */
    776           memcpy (cur, name, namelen + 1);
    777           cur += namelen;
    778 
    779           if (!has_ext)
    780             {
    781               strcpy (cur, exts [is_library][i/2]);
    782               cur = strchr (cur, 0);
    783             }
    784 
    785           f = fopen (fullname, "rb");
    786           if (f)
    787             {
    788               if (autoconvert_flag && is_dll && is_library)
    789                 f = lx_to_omf (f, fullname);
    790               else if (autoconvert_flag && !check_omf (f))
    791                 f = aout_to_omf (f, fullname, is_library);
    792 
    793               if (is_library && !check_omf_library (f) /* not sure if this makes sense */)
    794                 fclose (f);
    795               else
    796                 {
    797                   /* Replace forward slashes with backslashes (link386). */
    798                   while ((fullname = strchr (fullname, '/')) != NULL)
    799                     *fullname++ = '\\';
    800                   return f;
    801                 }
    802             }
     997            pszLibPath = psz + 1;
    803998        }
    804 
    805       if (!libpath || has_path)
    806         break;
    807 
    808       /* Find the next LIB component.
    809          We're skipping empty components. */
    810       for (;;)
    811         {
    812           x = strchr (libpath, ';');
    813           if (!x) x = strchr (libpath, 0);
    814           pathlen = x - libpath;
    815           if (pathlen)
    816             {
    817               memcpy (fullname, libpath, pathlen);
    818               libpath = x + (*x == ';');
    819               /* Append last slash if it is not there */
    820               if (fullname [pathlen - 1] != '/'
    821                && fullname [pathlen - 1] != '\\')
    822                 fullname [pathlen++] = '\\';
    823               break;
    824             }
    825           if (!*x)
    826             break;
    827           libpath = x + (*x == ';');
    828         }
    829     } while (pathlen);
    830 
    831 
    832   strcpy (fullname, name);
    833   return NULL;
    834 }
     999    } while (cchCurPath);
     1000
     1001    /* failure */
     1002    return NULL;
     1003}
     1004
    8351005
    8361006/* Weak prelinking for Method 2 Weak support. */
     
    8941064      for (pcur = obj_fnames; !rc && pcur; pcur = pcur->next)
    8951065        {
    896           phfile = find_objlib (szname, pcur->name, FALSE);
     1066          phfile = find_obj (szname, pcur->name);
    8971067          rc = WLDAddObject (pwld, phfile, szname);
    8981068        }
     
    9011071      for (pcur = lib_fnames; !rc && pcur; pcur = pcur->next)
    9021072        {
    903           phfile = find_objlib (szname, pcur->name, TRUE);
     1073          phfile = find_lib (szname, pcur->name, !pcur->flags);
    9041074          rc = WLDAddLibrary (pwld, phfile, szname);
    9051075          free(pcur->name);
     
    9231093        rc = WLDGenerateWeakAliases (pwld, weakobj_fname, weakdef_fname);
    9241094      if (!rc && weakobj_fname[0])
    925         add_name_list (&add_obj_fnames, weakobj_fname);
     1095        add_name_list (&add_obj_fnames, weakobj_fname, 0);
    9261096      if (!rc && weakdef_fname[0])
    9271097        def_fname = weakdef_fname;
     
    10971267static void usage (void)
    10981268{
    1099   fprintf (stderr, "emxomfld " VERSION INNOTEK_VERSION "\n"
    1100            "Copyright (c) 1992-1996 by Eberhard Mattes\n"
    1101            "Copyright (c) 2003 by InnoTek Systemberatung GmbH\n\n");
    1102 
    1103   fprintf (stderr,
    1104            "Usage: emxomfld -o <file> [-l <lib>] [-L <libdir>] [-T <base>] [-igtsS]\n"
    1105            "                [-Zexe] [-Zdll] [-Zstack <size>] [-Zmap[=<map_file>]]\n"
    1106            "                [-Z[no-]autoconv] [-O <option>] [-static] [-non_shared]\n"
    1107            "                [-Bstatic] [-dn] [call_shared] [-Bshared] [-dy] <file>...\n"
    1108            "\n"
    1109            "Options:\n"
    1110            " -Zno-autoconv / -Zautoconv:\n"
    1111            "    Turns off/on the automatic conversion of a.out libs and objs.\n"
    1112            "    default: -Zautoconv\n"
    1113            " -Bstatic, -non_shared, -dn, -static:\n"
    1114            "    Link with static libraries.\n"
    1115            "    The search order is then changed to: lib<name>_s.lib, <name>_s.lib,\n"
    1116            "    lib<name>.lib, <name>.lib\n"
    1117            " -Bshared, -call_shared, -dy:\n"
    1118            "    Link with shared libraries. This is default.\n"
    1119            "    The search order is then changed to: lib<name>_dll.lib, <name>_dll.lib,\n"
    1120            "    lib<name>.lib, <name>.lib, <name>.dll, lib<name>_s.lib, <name>_s.lib.\n"
    1121            "\n"
    1122            "Environment variables:\n"
    1123            "  EMXOMFLD_TYPE:\n"
    1124            "    The type of linker we're using. Values: VAC365, VAC308, LINK386.\n"
    1125            "        VAC365   ilink.exe from IBM C and C++ Compilers for OS/2 v3.6 or later.\n"
    1126            "        VAC308   ilink.exe from Visual Age for C++ v3.08.\n"
    1127            "        LINK386  link386 form OS/2 install or DDK.\n"
    1128            "  EMXOMFLD_LINKER:\n"
    1129            "    Name of the linker to use and optionally extra parameters. Spaces in the\n"
    1130            "    linker name or path is not supported. Quotes are not supported either.\n"
    1131            "The default values for these two variables are VAC365 and ilink.exe.\n"
    1132            );
     1269  fputs ("emxomfld " VERSION INNOTEK_VERSION "\n"
     1270         "Copyright (c) 1992-1996 by Eberhard Mattes\n"
     1271         "Copyright (c) 2003 by InnoTek Systemberatung GmbH\n"
     1272         "Copyright (c) 2003-2004 by Knut St. Osmundsen\n"
     1273         "\n", stderr);
     1274  fputs ("Usage: emxomfld -o <file> [-l <lib>] [-L <libdir>] [-T <base>] [-igtsS]\n"
     1275         "                [-Zexe] [-Zdll] [-Zstack <size>] [-Zmap[=<map_file>]]\n"
     1276         "                [-Z[no-]autoconv] [-O <option>] [-static] [-non_shared]\n"
     1277         "                [-Bstatic] [-dn] [call_shared] [-Bshared] [-dy] <file>...\n"
     1278         "\n", stderr);
     1279  fputs ("Options:\n"
     1280         " -Zno-autoconv / -Zautoconv:\n"
     1281         "    Turns off/on the automatic conversion of a.out libs and objs.\n"
     1282         "    default: -Zautoconv\n"
     1283         " -Bstatic, -non_shared, -dn, -static:\n"
     1284         "    Link with static libraries.\n"
     1285         "    The search order is then changed to: lib<name>_s.lib, <name>_s.lib,\n"
     1286         "    lib<name>.lib, <name>.lib\n", stderr);
     1287  fputs (" -Bshared, -call_shared, -dy:\n"
     1288         "    Link with shared libraries. This is default.\n"
     1289         "    The search order is then changed to: lib<name>_dll.lib, <name>_dll.lib,\n"
     1290         "    lib<name>.lib, <name>.lib, <name>.dll, lib<name>_s.lib, <name>_s.lib.\n"
     1291         "\n", stderr);
     1292  fputs ("Environment variables:\n"
     1293         "  EMXOMFLD_TYPE:\n"
     1294         "    The type of linker we're using. Values: VAC365, VAC308, LINK386.\n"
     1295         "        VAC365   ilink.exe from IBM C and C++ Compilers for OS/2 v3.6 or later.\n"
     1296         "        VAC308   ilink.exe from Visual Age for C++ v3.08.\n"
     1297         "        LINK386  link386 form OS/2 install or DDK.\n", stderr);
     1298  fputs ("  EMXOMFLD_LINKER:\n"
     1299         "    Name of the linker to use and optionally extra parameters. Spaces in the\n"
     1300         "    linker name or path is not supported. Quotes are not supported either.\n"
     1301         "The default values for these two variables are VAC365 and ilink.exe.\n", stderr);
    11331302  exit (1);
    11341303}
     
    11851354  char execname[512];
    11861355  name_list *pcur;
     1356  int   opt_libs_static = 0;
    11871357  int   longind;
    11881358
     
    12051375
    12061376  /* Parse the command line options and other arguments. */
    1207   //while ((c = getopt_long (argc, argv, "o:O:itl:vL:T:sSxX", longopts, &longind)) != EOF)
    12081377  while ((c = getopt_long_only (argc, argv, "-l:y:L:", longopts, &longind)) != EOF)
    12091378    {
     
    12161385          break;
    12171386
    1218         case 0:                   /* Non-option argument */
     1387        case 1:                   /* Non-option argument */
    12191388
    12201389          /* Extract the extension to see what to do with this
     
    12301399
    12311400              sprintf (tmp, "%s.", optarg);
    1232               add_name_list (&add_obj_fnames, tmp);
     1401              add_name_list (&add_obj_fnames, tmp, 0);
    12331402            }
    12341403
     
    12661435
    12671436          else if (stricmp (ext, ".lib") == 0 || stricmp (ext, ".a") == 0 || stricmp (ext, ".dll") == 0)
    1268             add_name_list (&add_lib_fnames, optarg);
     1437            add_name_list (&add_lib_fnames, optarg, opt_libs_static);
    12691438
    12701439          /* Otherwise, assume it's an object file. */
    12711440
    12721441          else
    1273             add_name_list (&add_obj_fnames, optarg);
     1442            add_name_list (&add_obj_fnames, optarg, 0);
    12741443          ++files;
    12751444          break;
     
    12811450
    12821451        case 'l':                 /* Add library */
    1283           add_name_list (&add_lib_fnames, optarg);
     1452          add_name_list (&add_lib_fnames, optarg, opt_libs_static);
    12841453          break;
    12851454
     
    12891458
    12901459        case 'L':                 /* Add library directory */
    1291           add_name_list (&add_libdirs, optarg);
     1460          add_name_list (&add_libdirs, optarg, 0);
    12921461          break;
    12931462
     
    13091478
    13101479        case 'O':                 /* Specify Linker option */
    1311           add_name_list (&add_options, optarg);
     1480          add_name_list (&add_options, optarg, 0);
    13121481          break;
    13131482
     
    13371506            usage ();
    13381507          errno = 0;
    1339           stack_size = strtol (argv[optind], &t, 0);
    1340           if (errno != 0 || *t != 0 || t == argv[optind])
     1508          stack_size = strtol (optarg, &t, 0);
     1509          if (errno != 0 || *t != 0 || t == optarg)
    13411510            usage ();
    13421511          break;
     
    13471516        case OPT_ZNO_AUTOCONV:
    13481517          autoconvert_flag = 0;
     1518          break;
     1519
     1520        case OPT_LIBS_STATIC:
     1521          opt_libs_static = 1;
     1522          break;
     1523        case OPT_LIBS_SHARED:
     1524          opt_libs_static = 0;
     1525          break;
    13491526
    13501527        default:
     
    14191596    {
    14201597      char szname[_MAX_PATH + 1];
    1421       FILE *phfile = find_objlib (szname, pcur->name, FALSE);
     1598      FILE *phfile = find_obj (szname, pcur->name);
    14221599      if (!phfile)
    14231600        continue;
     
    14301607    {
    14311608      char szname[_MAX_PATH + 1];
    1432       FILE *phfile = find_objlib (szname, pcur->name, TRUE);
     1609      FILE *phfile = find_lib (szname, pcur->name, !pcur->flags);
    14331610      if (!phfile)
    14341611        continue;
  • trunk/src/emx/src/ld/ld.c

    • Property cvs2svn:cvs-rev changed from 1.12 to 1.13
    r941 r942  
    2727#include <stdio.h>
    2828#include <stdlib.h>
     29#include <stdarg.h>
    2930#include <io.h>
    3031#include <process.h>
     
    437438
    438439/* Demangler for C++.  */
    439 extern char *cplus_demangle ();
    440440#include "demangle.h"
    441 static char *my_cplus_demangle ();
     441static char *my_cplus_demangle (const char *);
    442442int demangle_options;
    443443
     
    659659     Also default text_start to after this file's bss. */
    660660  char just_syms_flag;
     661
     662  /* 1 means search for dynamic libs before static.
     663     0 means search only static libs. */
     664  char dynamic;
    661665};
    662666
     
    863867int cl_refs_allocated;
    864868
    865 char *xmalloc ();
    866 char *xrealloc ();
    867 void usage ();
    868 void fatal ();
    869 void fatal_with_file ();
    870 void perror_name ();
    871 void perror_file ();
    872 void error ();
    873 
    874 int parse ();
    875 void initialize_text_start ();
    876 void initialize_data_start ();
    877 void digest_symbols ();
    878 void print_symbols ();
    879 void load_symbols ();
    880 void decode_command ();
    881 void list_undefined_symbols ();
    882 void list_unresolved_references ();
    883 void write_output ();
    884 void write_header ();
    885 void write_text ();
    886 void read_file_relocation ();
    887 void write_data ();
    888 void write_rel ();
    889 void write_syms ();
    890 void write_symsegs ();
    891 void mywrite ();
    892 void symtab_init ();
    893 void padfile ();
    894 char *concat ();
    895 char *get_file_name ();
    896 symbol *getsym (), *getsym_soft ();
    897 void do_warnings ();
     869char *xmalloc (int);
     870void *xrealloc (void *, int);
     871void usage (char *, char *);
     872void fatal (char *, ...);
     873void fatal_with_file (char *, struct file_entry *);
     874void perror_name (char *);
     875void perror_file (struct file_entry *);
     876void error (char *, char *, char *, char *);
     877
     878int parse (char *, char *, char *);
     879void initialize_text_start (void);
     880void initialize_data_start (void);
     881void digest_symbols (void);
     882void print_symbols (FILE *);
     883void load_symbols (void);
     884void decode_command (int, char **);
     885void write_output (void);
     886void write_header (void);
     887void write_text (void);
     888void read_file_relocation (struct file_entry *);
     889void write_data (void);
     890void write_rel (void);
     891void write_syms (void);
     892void write_symsegs (void);
     893void mywrite (void *, int, int, int);
     894void symtab_init (void);
     895void padfile (int, int);
     896char *concat (const char *, const char *, const char *);
     897char *get_file_name (struct file_entry *);
     898symbol *getsym (char *), *getsym_soft (char *);
     899void do_warnings (FILE *);
    898900void check_exe (void);
    899901char *lx_to_aout (const char *pszFilename);
     902int check_lx_dll(int fd);
    900903void cleanup (void);
     904
     905void add_cmdline_ref (struct glosym *sp);
     906void prline_file_name (struct file_entry *entry, FILE *outfile);
     907void deduce_file_type(int desc, struct file_entry *entry);
     908void read_a_out_header (int desc, struct file_entry *entry);
     909void read_header (int desc, struct file_entry *entry);
     910void read_entry_symbols (int desc, struct file_entry *entry);
     911void read_entry_strings (int desc, struct file_entry *entry);
     912unsigned long contains_symbol (struct file_entry *entry, struct nlist *n_ptr);
     913void process_subentry (int desc, struct file_entry *subentry, struct file_entry *entry, struct file_entry **prev_addr);
     914void consider_file_section_lengths (struct file_entry *entry);
     915void relocate_file_addresses (struct file_entry *entry);
     916void describe_file_sections (struct file_entry *entry, FILE *outfile);
     917void list_file_locals (struct file_entry *entry, FILE *outfile);
     918int relocation_entries_relation (struct relocation_info *rel1, struct relocation_info *rel2);
     919void do_relocation_warnings (struct file_entry *entry, int data_segment, FILE *outfile, unsigned char *nlist_bitvector);
     920void do_file_warnings (struct file_entry *entry, FILE *outfile);
     921void initialize_a_out_text_start (void);
     922void initialize_a_out_data_start (void);
     923void compute_a_out_section_offsets (void);
     924void compute_more_a_out_section_offsets (void);
     925void write_a_out_header (void);
     926int hash_string (char *key);
     927void read_file_symbols (struct file_entry *entry);
     928void compute_section_offsets (void);
     929void compute_more_section_offsets (void);
     930void read_relocation (void);
     931int assign_string_table_index (char *name);
     932unsigned long check_each_file (register unsigned long (*function)(), register int arg);
     933
     934
     935
    901936
    902937
     
    10331068  {"z", 0, 0, 'z'},
    10341069  {"A", 1, 0, 'A'},
    1035   {"Bstatic", 0, 0, 129},       /* For Sun compatibility. */
    10361070  {"D", 1, 0, 'D'},
    10371071  {"M", 0, 0, 'M'},
     
    10521086  {"V", 1, 0, 'V'},
    10531087  {"X", 0, 0, 'X'},
     1088#define OPT_LIBS_STATIC     0x1000
     1089  {"Bstatic", 0, 0, OPT_LIBS_STATIC},
     1090  {"non_shared", 0, 0, OPT_LIBS_STATIC},
     1091  {"dn", 0, 0, OPT_LIBS_STATIC},
     1092  {"static", 0, 0, OPT_LIBS_STATIC},
     1093#define OPT_LIBS_SHARED     0x1001
     1094  {"Bshared", 0, 0, OPT_LIBS_SHARED},
     1095  {"call_shared", 0, 0, OPT_LIBS_SHARED},
     1096  {"dy", 0, 0, OPT_LIBS_SHARED},
    10541097  {0, 0, 0, 0}
    10551098};
     
    10711114  int optc, longind;
    10721115  register struct file_entry *p;
     1116  int opt_libs_static = 0;
    10731117
    10741118  number_of_files = 0;
     
    11781222        case 'A':
    11791223          number_of_files++;
    1180           break;
    1181 
    1182         case 129:               /* -Bstatic. */
    1183           /* Ignore. */
    11841224          break;
    11851225
     
    12711311          discard_locals = DISCARD_L;
    12721312          break;
     1313
     1314        case OPT_LIBS_STATIC:
     1315        case OPT_LIBS_SHARED:
     1316          /* processed later */
     1317          break;
    12731318        }
    12741319    }
     
    13271372        case 'A':
    13281373          if (p != file_table)
    1329             usage ("-A specified before an input file other than the first");
     1374            usage ("-A specified before an input file other than the first", NULL);
    13301375          p->filename = optarg;
    13311376          p->local_sym_name = optarg;
     
    13351380
    13361381        case 'l':
    1337           p->filename = concat ("", optarg, ".a");
     1382          p->filename = concat ("", optarg, "");
    13381383          p->local_sym_name = concat ("-l", optarg, "");
    13391384          p->search_dirs_flag = 1;
     1385          p->dynamic = !opt_libs_static;
    13401386          p++;
    13411387          break;
     1388
     1389        case OPT_LIBS_STATIC:
     1390          opt_libs_static = 1;
     1391          break;
     1392        case OPT_LIBS_SHARED:
     1393          opt_libs_static = 0;
     1394          break;
    13421395        }
    13431396    }
     
    13981451}
    13991452
    1400 int
     1453static int
    14011454set_element_prefixed_p (name)
    14021455     char *name;
     
    14191472/* Convenient functions for operating on one or all files being
    14201473   loaded.  */
    1421 void print_file_name ();
     1474void print_file_name (struct file_entry *entry, FILE *outfile);
    14221475
    14231476/* Call FUNCTION on each input file entry.
     
    14271480   FUNCTION receives two arguments: the entry, and ARG.  */
    14281481
    1429 void
     1482static void
    14301483each_file (function, arg)
    14311484     register void (*function)();
     
    14831536/* Like `each_file' but ignore files that were just for symbol definitions.  */
    14841537
    1485 void
     1538static void
    14861539each_full_file (function, arg)
    14871540     register void (*function)();
     
    15081561/* Close the input file that is now open.  */
    15091562
    1510 void
     1563static void
    15111564file_close ()
    15121565{
     
    15201573   a new open is not actually done.  */
    15211574
    1522 int
     1575static int
    15231576file_open (entry)
    15241577     register struct file_entry *entry;
     
    15361589  if (entry->search_dirs_flag && n_search_dirs)
    15371590    {
     1591      /* !we're searching for libraries here! */
     1592      static const char *dynamic_suffs[] = { "_dll.a", ".a", ".dll", "_s.a", NULL };
     1593      static const char *static_suffs[]  = { "_s.a", ".a", NULL };
     1594      const char **suffs = entry->dynamic ? dynamic_suffs : static_suffs;
     1595      int lenname = strlen (entry->filename);
    15381596      int i;
    15391597
    15401598      for (i = 0; i < n_search_dirs; i++)
    15411599        {
    1542           register char *string
    1543             = concat (search_dirs[i], "/", entry->filename);
    1544           desc = open (string, O_RDONLY|O_BINARY, 0);
    1545 
    1546           if (desc < 0)
    1547           {
    1548             char *tmp = _getext (entry->filename);
    1549             if (tmp && (tolower(tmp[1]) == 'a') && (tmp[2] == 0))
     1600          int lendir = strlen (search_dirs[i]);
     1601          register char *string = xmalloc (lendir + lenname + 4 + 6 + 1);
     1602          int j;
     1603
     1604          memcpy (string, search_dirs[i], lendir);
     1605          string[lendir++] = '/';
     1606          for (j = 0; suffs[j]; j++)
    15501607            {
    1551               /* Try libxxx */
    1552               free (string);
    1553               string = concat (search_dirs[i], "/lib", entry->filename);
    1554               desc = open (string, O_RDONLY|O_BINARY, 0);
    1555             }
    1556           }
    1557           if (desc > 0)
    1558             {
    1559               entry->filename = string;
    1560               entry->search_dirs_flag = 0;
    1561               break;
    1562             }
     1608              static const char *prefixes[] = { "lib", ""};
     1609              int k;
     1610              for (k = 0; k < sizeof(prefixes) / sizeof(prefixes[0]); k++)
     1611                {
     1612                  int len = strlen (prefixes[k]);
     1613                  memcpy (string + lendir, prefixes[k], len);
     1614                  len += lendir;
     1615                  memcpy (string + len, entry->filename, lenname);
     1616                  len += lenname;
     1617                  strcpy (string + len, suffs[j]);
     1618
     1619                  desc = open (string, O_RDONLY|O_BINARY, 0);
     1620                  if (desc > 0)
     1621                    {
     1622                      /* convert? */
     1623                      if (check_lx_dll (desc))
     1624                        {
     1625                          string = lx_to_aout (string);
     1626                          if (!string || (desc = open (string, O_RDONLY|O_BINARY, 0)) < 0)
     1627                            perror_file (entry);
     1628                        }
     1629                      entry->filename = string;
     1630                      entry->search_dirs_flag = 0;
     1631                      input_file = entry;
     1632                      input_desc = desc;
     1633                      return desc;
     1634                    }
     1635                } /* prefix loop */
     1636            } /* suffix loop */
    15631637          free (string);
    1564         }
     1638        } /* dir loop */
    15651639    }
    15661640  else
     
    18161890void
    18171891read_entry_strings (desc, entry)
     1892     int desc;
    18181893     struct file_entry *entry;
    1819      int desc;
    18201894{
    18211895  if (!entry->header_read_flag)
     
    18301904/* Read in the symbols of all input files.  */
    18311905
    1832 void read_file_symbols (), read_entry_symbols (), read_entry_strings ();
    1833 void enter_file_symbols (), enter_global_ref (), search_library ();
    1834 
    1835 void
    1836 load_symbols ()
     1906void enter_file_symbols (struct file_entry *entry);
     1907void enter_global_ref (register struct nlist *nlist_p, char *name, struct file_entry *entry);
     1908void search_library (int desc, struct file_entry *entry);
     1909
     1910void
     1911load_symbols (void)
    18371912{
    18381913  register int i;
     
    21692244/* Searching libraries */
    21702245
    2171 struct file_entry *decode_library_subfile ();
    2172 void linear_library (), symdef_library ();
     2246struct file_entry * decode_library_subfile (int desc, struct file_entry *library_entry, int subfile_offset, int *length_loc);
     2247void symdef_library (int desc, struct file_entry *entry, int member_length);
     2248void linear_library (int desc, struct file_entry *entry);
    21732249
    21742250/* Search the library ENTRY, already open on descriptor DESC.
     
    22662342
    22672343
    2268 int subfile_wanted_p ();
     2344int subfile_wanted_p (struct file_entry *);
    22692345
    22702346/* Search a library that has a __.SYMDEF member.
     
    25572633
    25582634void
    2559 digest_symbols ()
     2635digest_symbols (void)
    25602636{
    25612637  register int i;
     
    29963072};
    29973073
     3074int next_debug_entry (int use_data_symbols, struct line_debug_entry state_pointer[3]);
     3075struct line_debug_entry * init_debug_scan (int use_data_symbols, struct file_entry *entry);
     3076int address_to_line (unsigned long address, struct line_debug_entry state_pointer[3]);
    29983077void qsort ();
    29993078/*
     
    32323311
    32333312  qsort (reloc_start, reloc_size, sizeof (struct relocation_info),
    3234          relocation_entries_relation);
     3313         (int (*)(const void *, const void *))relocation_entries_relation);
    32353314
    32363315  for (reloc = reloc_start;
     
    35123591
    35133592void
    3514 initialize_a_out_text_start ()
     3593initialize_a_out_text_start (void)
    35153594{
    35163595  int magic = 0;
     
    35623641
    35633642void
    3564 initialize_a_out_data_start ()
     3643initialize_a_out_data_start (void)
    35653644{
    35663645  outheader.a_text = text_size;
     
    35723651
    35733652void
    3574 compute_a_out_section_offsets ()
     3653compute_a_out_section_offsets (void)
    35753654{
    35763655  outheader.a_data = data_size;
     
    36353714
    36363715void
    3637 compute_more_a_out_section_offsets ()
     3716compute_more_a_out_section_offsets (void)
    36383717{
    36393718  output_symseg_offset = output_strs_offset + output_strs_size;
     
    36433722
    36443723void
    3645 write_a_out_header ()
     3724write_a_out_header (void)
    36463725{
    36473726  lseek (outdesc, 0L, 0);
     
    36593738
    36603739void
    3661 initialize_text_start ()
     3740initialize_text_start (void)
    36623741{
    36633742#ifdef A_OUT
     
    36753754
    36763755void
    3677 initialize_data_start ()
     3756initialize_data_start (void)
    36783757{
    36793758#ifdef A_OUT
     
    36903769
    36913770void
    3692 compute_section_offsets ()
     3771compute_section_offsets (void)
    36933772{
    36943773#ifdef A_OUT
     
    37053784   is finalized.  */
    37063785void
    3707 compute_more_section_offsets ()
     3786compute_more_section_offsets (void)
    37083787{
    37093788#ifdef A_OUT
     
    37193798/* Write the output file header, once everything is known.  */
    37203799void
    3721 write_header ()
     3800write_header (void)
    37223801{
    37233802#ifdef A_OUT
     
    38003879
    38013880void
    3802 write_output ()
     3881write_output (void)
    38033882{
    38043883  struct stat statbuf;
     
    39824061
    39834062
    3984 void modify_location (), perform_relocation (), copy_text (), copy_data ();
     4063void copy_text (struct file_entry *entry);
     4064void copy_data (struct file_entry *entry);
     4065void perform_relocation ( char *data, int pc_relocation, int data_size,
     4066    struct relocation_info *reloc_info, int reloc_size, struct file_entry *entry);
    39854067
    39864068/* Relocate the text segment of each input file
     
    40074089
    40084090void
    4009 read_relocation ()
     4091read_relocation (void)
    40104092{
    40114093  each_full_file (read_file_relocation, 0);
     
    43564438   relocating the addresses-to-be-relocated.  */
    43574439
    4358 void coptxtrel (), copdatrel ();
     4440void coptxtrel (struct file_entry *entry);
     4441void copdatrel (struct file_entry *entry);
    43594442
    43604443void
     
    44204503            RELOC_ADDRESS (&reloc)
    44214504              = set_sect_start + i * sizeof (unsigned long) - data_start;
    4422             mywrite ((char *)&reloc, sizeof (reloc), 1, outdesc);
     4505            mywrite (&reloc, sizeof (reloc), 1, outdesc);
    44234506            break;
    44244507          case N_ABS:
     
    45794662
    45804663
    4581 void write_file_syms ();
    4582 void write_string_table ();
     4664void write_file_syms (struct file_entry *entry, int *syms_written_addr);
     4665void write_string_table (void);
    45834666
    45844667/* Total size of string table strings allocated so far,
     
    46204703
    46214704void
    4622 write_string_table ()
     4705write_string_table (void)
    46234706{
    46244707  register int i;
     
    49275010   except that we store some information into the beginning of it.  */
    49285011
    4929 void write_file_symseg ();
     5012void write_file_symseg (struct file_entry *entry);
    49305013
    49315014void
     
    51535236   STRING is a printf format string and ARG is one arg for it.  */
    51545237
    5155 void
    5156 fatal (string, arg)
    5157      char *string, *arg;
    5158 {
     5238void fatal (char *string, ...)
     5239{
     5240  va_list args;
    51595241  fprintf (stderr, "%s: ", progname);
    5160   fprintf (stderr, string, arg);
     5242  va_start (args, string);
     5243  vfprintf (stderr, string, args);
     5244  va_end (args);
    51615245  fprintf (stderr, "\n");
    51625246  exit (1);
     
    52295313void
    52305314mywrite (buf, count, eltsize, desc)
    5231      char *buf;
     5315     void *buf;
    52325316     int count;
    52335317     int eltsize;
     
    52425326      if (val <= 0)
    52435327        perror_name (output_filename);
    5244       buf += val;
     5328      buf = (char*)buf + val;
    52455329      bytes -= val;
    52465330    }
     
    52695353char *
    52705354concat (s1, s2, s3)
    5271      char *s1, *s2, *s3;
     5355     const char *s1, *s2, *s3;
    52725356{
    52735357  register int len1 = strlen (s1), len2 = strlen (s2), len3 = strlen (s3);
     
    52885372int
    52895373parse (arg, format, error)
    5290      char *arg, *format;
     5374     char *arg, *format, *error;
    52915375{
    52925376  int x;
     
    53105394/* Like realloc but get fatal error if memory is exhausted.  */
    53115395
    5312 char *
     5396void *
    53135397xrealloc (ptr, size)
    5314      char *ptr;
     5398     void *ptr;
    53155399     int size;
    53165400{
     
    54135497}
    54145498
     5499
     5500/**
     5501 * Checks if the file FD is an LX DLL.
     5502 *
     5503 * @returns 1 if LX DLL.
     5504 * @returns 0 if not LX DLL.
     5505 * @param   fd  Handle to file to check.
     5506 */
     5507int check_lx_dll(int fd)
     5508{
     5509    unsigned long   ul;
     5510    char            achMagic[2];
     5511
     5512    if (    lseek(fd, 0, SEEK_SET)
     5513        ||  read(fd, &achMagic, 2) != 2)
     5514        goto thats_not_it;
     5515
     5516    if (!memcmp(achMagic, "MZ", 2))
     5517    {
     5518        if (    lseek(fd, 0x3c, SEEK_SET)
     5519            ||  read(fd, &ul, 4) != 4 /* offset of the 'new' header */
     5520            ||  ul < 0x40
     5521            ||  ul >= 0x10000000 /* 512MB stubs sure */
     5522            ||  lseek(fd, ul, SEEK_SET)
     5523            ||  read(fd, &achMagic, 2) != 2)
     5524            goto thats_not_it;
     5525    }
     5526
     5527    if (    memcmp(achMagic, "LX", 2)
     5528        ||  lseek(fd, 14, SEEK_CUR)
     5529        ||  read(fd, &ul, 4) != 4) /*e32_mflags*/
     5530        goto thats_not_it;
     5531
     5532#define E32MODDLL        0x08000L
     5533#define E32MODPROTDLL    0x18000L
     5534#define E32MODMASK       0x38000L
     5535    if (   (ul & E32MODMASK) != E32MODDLL
     5536        && (ul & E32MODMASK) != E32MODPROTDLL)
     5537        goto thats_not_it;
     5538
     5539    /* it's a LX DLL! */
     5540    lseek(fd,  0, SEEK_SET);
     5541    return 1;
     5542
     5543
     5544thats_not_it:
     5545    lseek(fd, 0, SEEK_SET);
     5546    return 0;
     5547}
     5548
     5549
    54155550/* atexit worker */
    54165551void cleanup (void)
Note: See TracChangeset for help on using the changeset viewer.