Changeset 2097 for trunk


Ignore:
Timestamp:
Jun 28, 2005, 2:03:05 AM (20 years ago)
Author:
bird
Message:

Generate .def-file for dlls without one - forgot cleanup.

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

Legend:

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

    • Property cvs2svn:cvs-rev changed from 1.42 to 1.43
    r2096 r2097  
    123123  char *symbol;                 /* Symbol attached to the string */
    124124  char *str;                    /* The value of the string */
    125 };
    126 
    127 /* This structure keeps track which weak symbol and where it is defined,
    128    to simulate weak symbols in OMF (which aren't supported in OMF) */
    129 
    130 struct weaksym
    131 {
    132   struct weaksym *next;         /* Next weak symbol in chain */
    133   char *name;                   /* Symbol name */
    134   char *module;                 /* Object file where it should be defined */
    135   int used;                     /* 1 if the symbol has been encountered */
    136125};
    137126
     
    249238static int opt_x = FALSE;
    250239
    251 /* Suppress reading and/or writing of the weaksyms.omf file */
    252 static int opt_w = FALSE;
    253 
    254240/* Remove underscores from all symbol names */
    255241static int opt_rmunder = FALSE;
     
    279265/* The index of the "WEAK$ZERO" symbol or 0. */
    280266static int weak_zero_index;
    281 
    282 /* The list of currently known OMF symbols */
    283 static struct weaksym *weak_symbol_list;
    284 static struct weaksym **weak_symbol_top = &weak_symbol_list;
    285 
    286 /* 1 whenever the weak symbol list has been altered */
    287 static int weak_list_altered;
    288 
    289 /* The file name of the weak symbol list file.
    290    If NULL the new method is used, if not NULL the old method is used. */
    291 static char *weak_list_filename;
    292267
    293268/* OMF name indices: segments, classes, groups, etc. */
     
    615590    error ("Internal error! Invalid index (%d) passed to set_hll_type().", index);
    616591  sym_more[index].hll_type = hll_type;
    617 }
    618 
    619 
    620 /* Add a symbol to 0 symbol list */
    621 
    622 static struct weaksym *add_weak (const char *symname, const char *modname)
    623 {
    624   struct weaksym *newsym = xmalloc (sizeof (struct weaksym));
    625   newsym->name = xstrdup (symname);
    626   newsym->module = xstrdup (modname);
    627   newsym->used = 0;
    628   newsym->next = NULL;
    629   *weak_symbol_top = newsym;
    630   weak_symbol_top = &newsym->next;
    631   weak_list_altered = 1;
    632   return newsym;
    633 }
    634 
    635 
    636 /* Load the weak symbols table from the weaksyms.omf file.
    637  * We emulate the weak symbol functionality in the following way:
    638  * first time we encounter a weak symbol, we mark it as "strong"
    639  * and remember the first object file where it was encountered.
    640  * Then when another instance of this weak symbol is encountered
    641  * the output file name is checked; if it is a different object file,
    642  * the symbol is marked as local. Otherwise it is marked as strong.
    643  * Finally, when we find any external references to this symbol, they
    644  * are marked as "OMF weak reference", e.g. the N_WEAKU type
    645  * (which is quite different from a.out weaks, thats why we have
    646  * to dig all that mess!). Alas, this mechanism can require multi-pass
    647  * builds for complex cases...
    648  */
    649 
    650 static void weak_load (void)
    651 {
    652   FILE *wf;
    653   char line [1024];
    654 
    655 
    656   /* Find and open the weak symbol list file
    657      #483: If not present we'll use the new method. */
    658   weak_list_filename = getenv ("GCC_WEAKSYMS");
    659   if (!weak_list_filename)
    660     return ;
    661   if (opt_w)
    662     return;
    663   wf = fopen (weak_list_filename, "r");
    664   if (!wf)
    665     return;
    666 
    667   /* Every line of the file contains something like:
    668        __symbol:object_file
    669      or just
    670        __symbol
    671   */
    672 
    673   while (fgets (line, sizeof (line), wf))
    674     {
    675       char *eol = strchr (line, 0);
    676       while ((eol > line) && (isspace (eol [-1])))
    677         eol--;
    678       *eol = 0;
    679       char *sep = strchr (line, ':');
    680       if (!sep)
    681         {
    682           fprintf (stderr, "WARNING: bad line `%s' in weak symbol list file `%s'\n",
    683             line, weak_list_filename);
    684           continue;
    685         }
    686 
    687       *sep = 0;
    688       add_weak (line, sep + 1);
    689     }
    690 
    691   fclose (wf);
    692 
    693   /* Mark the list as unmodified */
    694   weak_list_altered = 0;
    695 }
    696 
    697 
    698 /* Save the weak symbol list */
    699 
    700 static void weak_save (void)
    701 {
    702   FILE *wf;
    703   struct weaksym *wsym;
    704 
    705   if (opt_w)
    706     return;
    707 
    708   /* Find and open the weak symbol list file */
    709   wf = fopen (weak_list_filename, "w");
    710   if (!wf)
    711     return;
    712 
    713   for (wsym = weak_symbol_list; wsym; wsym = wsym->next)
    714     fprintf (wf, "%s:%s\n", wsym->name, wsym->module);
    715 
    716   fclose (wf);
    717 }
    718 
    719 
    720 /* Free the weak symbol list */
    721 
    722 static void weak_free (void)
    723 {
    724   struct weaksym *cur = weak_symbol_list;
    725   while (cur)
    726     {
    727       struct weaksym *next = cur->next;
    728       free (cur->name);
    729       free (cur);
    730       free (cur->module);
    731       cur = next;
    732     }
    733   weak_symbol_list = NULL;
    734 }
    735 
    736 
    737 /* Find if a symbol is weak */
    738 
    739 static struct weaksym *is_weak (const char *symname)
    740 {
    741   struct weaksym *wsym;
    742   for (wsym = weak_symbol_list; wsym; wsym = wsym->next)
    743     if (!strcmp (symname, wsym->name))
    744       return wsym;
    745   return NULL;
    746592}
    747593
     
    12151061
    12161062
    1217 /* Check all external symbol references for weakness; if a symbol is weak,
    1218    mark it as N_WEAKU so that it is later writen within a WKEXT record.
    1219    Also we convert a.out-style weak symbols here as normal public symbols,
    1220    as the sense of weak is reverse in OMF
    1221 
    1222    Weak Hack Method 1.
    1223    */
    1224 
    1225 static void weak_process (void)
    1226 {
    1227   int i;
    1228 
    1229   if (!weak_list_filename)
    1230       return;
    1231 
    1232 #define SETTYPE(t) ((struct nlist *)sym_ptr)[i].n_type = t
    1233 
    1234   for (i = 0; i < sym_count; ++i)
    1235     if ((sym_ptr[i].n_type >= N_WEAKA) && (sym_ptr[i].n_type <= N_WEAKB))
    1236       {
    1237         const char *name = (const char *)(str_ptr + sym_ptr[i].n_un.n_strx);
    1238 
    1239         int public = N_EXT;
    1240 
    1241         /* Add the symbol to weak list if not already */
    1242         struct weaksym *wsym = is_weak (name);
    1243         if (!wsym)
    1244           wsym = add_weak (name, out_fname);
    1245         else if (strcmp (out_fname, wsym->module) || wsym->used)
    1246           public = 0;
    1247         /* If the symbol is exported more than once (e.g. from an archive),
    1248            export just the first instance... */
    1249         wsym->used = 1;
    1250 
    1251         /* Now convert it to a normal public symbol */
    1252         switch (sym_ptr[i].n_type)
    1253           {
    1254             case N_WEAKA: SETTYPE (N_ABS  | public); break;
    1255             case N_WEAKT: SETTYPE (N_TEXT | public); break;
    1256             case N_WEAKD: SETTYPE (N_DATA | public); break;
    1257             case N_WEAKB: SETTYPE (N_BSS  | public); break;
    1258           }
    1259       }
    1260     #if 0
    1261     else if ((sym_ptr[i].n_type & N_EXT) && is_weak (str_ptr + sym_ptr[i].n_un.n_strx))
    1262       {
    1263          /* Convert a external reference to N_WEAKU */
    1264          /* P.S. As experiments show, WKEXT works somewhat strangely
    1265             with LINK386 (sometimes such external references are left
    1266             unresolved, even that they could be resolved), thus the
    1267             following line is commented out */
    1268          /*SETTYPE (N_WEAKU);*/
    1269       }
    1270     #endif
    1271 #undef SETTYPE
    1272 }
    1273 
    1274 
    12751063/**
    12761064 * Generates new names for weak symbols.
     
    12871075 *                      This must be at least 256, the code make this assumption!
    12881076 * @remark I'm sorry this function is written in my coding style - not!
    1289  * @remark Weak Hack Method 2.
    12901077 */
    12911078static const char *weak_process_name(const struct nlist *pSym, const char *pszOrgName, char *pachName, int cchName)
     
    14681255              {
    14691256                /* for weaksymbols we may have to decorate the name */
    1470                 if (   !weak_list_filename
    1471                     && sym_ptr[i].n_type >= N_WEAKU && sym_ptr[i].n_type <= N_WEAKB )
     1257                if ( sym_ptr[i].n_type >= N_WEAKU && sym_ptr[i].n_type <= N_WEAKB )
    14721258                    name = weak_process_name(&sym_ptr[i], name, szName, sizeof(szName));
    14731259
     
    15601346static void write_pubdef (void)
    15611347{
    1562   write_pubdef1 (N_ABS,  0,          FALSE, 0);
    1563   write_pubdef1 (N_ABS,  0,          TRUE, 0);
    1564   write_pubdef1 (N_TEXT, text_index, FALSE, 0);
    1565   write_pubdef1 (N_TEXT, text_index, TRUE,  0);
    1566   write_pubdef1 (N_DATA, udat_index, FALSE, text_size);
    1567   write_pubdef1 (N_DATA, udat_index, TRUE,  text_size);
    1568   write_pubdef1 (N_BSS,  bss_index,  FALSE, text_size + data_size);
    1569   write_pubdef1 (N_BSS,  bss_index,  TRUE,  text_size + data_size);
    1570   if (!weak_list_filename)
    1571   {
    1572       write_pubdef1 (N_WEAKA, 0,          FALSE, 0);
    1573       write_pubdef1 (N_WEAKA, 0,          TRUE, 0);
    1574       write_pubdef1 (N_WEAKT, text_index, FALSE, 0);
    1575       write_pubdef1 (N_WEAKT, text_index, TRUE,  0);
    1576       write_pubdef1 (N_WEAKD, udat_index, FALSE, text_size);
    1577       write_pubdef1 (N_WEAKD, udat_index, TRUE,  text_size);
    1578       write_pubdef1 (N_WEAKB, bss_index,  FALSE, text_size + data_size);
    1579       write_pubdef1 (N_WEAKB, bss_index,  TRUE,  text_size + data_size);
    1580   }
     1348  write_pubdef1 (N_ABS,   0,          FALSE, 0);
     1349  write_pubdef1 (N_ABS,   0,          TRUE, 0);
     1350  write_pubdef1 (N_TEXT,  text_index, FALSE, 0);
     1351  write_pubdef1 (N_TEXT,  text_index, TRUE,  0);
     1352  write_pubdef1 (N_DATA,  udat_index, FALSE, text_size);
     1353  write_pubdef1 (N_DATA,  udat_index, TRUE,  text_size);
     1354  write_pubdef1 (N_BSS,   bss_index,  FALSE, text_size + data_size);
     1355  write_pubdef1 (N_BSS,   bss_index,  TRUE,  text_size + data_size);
     1356  write_pubdef1 (N_WEAKA, 0,          FALSE, 0);
     1357  write_pubdef1 (N_WEAKA, 0,          TRUE, 0);
     1358  write_pubdef1 (N_WEAKT, text_index, FALSE, 0);
     1359  write_pubdef1 (N_WEAKT, text_index, TRUE,  0);
     1360  write_pubdef1 (N_WEAKD, udat_index, FALSE, text_size);
     1361  write_pubdef1 (N_WEAKD, udat_index, TRUE,  text_size);
     1362  write_pubdef1 (N_WEAKB, bss_index,  FALSE, text_size + data_size);
     1363  write_pubdef1 (N_WEAKB, bss_index,  TRUE,  text_size + data_size);
    15811364  /* kso #456 2003-06-10: The debugger looks for 'main' not '_main'. */
    15821365  write_pubdef_main ();
     
    38223605  write_rec ();
    38233606
    3824   /* Process weak symbols */
    3825   weak_process ();
    3826 
    38273607  /* Convert imports and exports. These show up very early in VAC
    38283608     generated OMF files. */
     
    39293709  puts ("  -t                 Add timestamping to the weak symbol mangling (def)");
    39303710  puts ("  -j                 Do not add timestamping to the weak symbol mangling");
    3931   puts ("  -w                 Suppress reading/writing of the weaksyms.omf file");
    3932   puts ("                     (Only used if GCC_WEAKSYMS is set.)");
    39333711  puts ("  -z                 Remove underscores from all symbol names");
    39343712  puts ("  -P <dbgpackdll>    Name the dbgpack DLL (ilink)");
     
    44394217        opt_x = TRUE;
    44404218        break;
    4441       case 'w':
    4442         opt_w = TRUE;
    4443         break;
    44444219      case 'z':
    44454220        opt_rmunder = TRUE;
     
    44574232    usage ();
    44584233
    4459   /* Initialize weak symbol list */
    4460 
    4461   weak_symbol_list = NULL;
    4462   weak_load ();
    4463 
    44644234  if (opt_o != NULL)
    44654235    {
     
    44934263    }
    44944264
    4495   /* If the weak symbol list has been altered, save it */
    4496 
    4497   if (weak_list_altered)
    4498     weak_save ();
    4499 
    4500   /* Free the weak symbol list */
    4501 
    4502   weak_free ();
    4503 
    45044265  /* If a LIB response file has been created, finish and close it. */
    45054266
  • trunk/src/emx/src/emxomf/emxomfld.c

    • Property cvs2svn:cvs-rev changed from 1.40 to 1.41
    r2096 r2097  
    11881188static void gen_deffile(void)
    11891189{
    1190     char *psz = xmalloc(_MAX_PATH);
     1190    char *          psz;
     1191    name_list      *pName;
     1192
     1193    /*
     1194     * Make temporary file.
     1195     */
     1196    pName = (name_list *)xmalloc(sizeof(*pName));
     1197    pName->name = psz = xmalloc(_MAX_PATH);
    11911198    if (!make_tempfile(psz, "lddef", ".def", NULL))
    11921199    {
     
    12161223                        "---- End of generated def-file.\n",
    12171224                        psz, cchName, pszName);
     1225
     1226            /* add to auto delete list for removal on exit(). */
     1227            pName->next = conv_list;
     1228            conv_list = pName;
    12181229            return;
    12191230        }
    12201231    }
    12211232    free(psz);
     1233    free(pName);
    12221234}
    12231235
     
    17021714    gen_deffile();
    17031715
    1704   /* Do the weak prelinking unless GCC_WEAKSYMS are set.
    1705      Important that this is done after make_env(). */
    1706 
    1707   if (!getenv("GCC_WEAKSYMS"))
    1708       weak_prelink ();
     1716  /* Do the weak prelinking. Important that this is done after make_env(). */
     1717
     1718  weak_prelink ();
    17091719
    17101720  /* Start building the linker command line.  We can use a response
  • trunk/src/emx/src/ld/ld.c

    • Property cvs2svn:cvs-rev changed from 1.18 to 1.19
    r2096 r2097  
    929929int assign_string_table_index (char *name);
    930930unsigned long check_each_file (register unsigned long (*function)(), register int arg);
    931 static int      make_tempfile(char *pszFile, const char *pszPrefix, const char *pszSuffix);
     931static void     gen_deffile (void);
    932932
    933933
     
    39063906    unlink (touch_filename);
    39073907}
    3908 
    3909 /* Generates a definition file for a dll which doesn't have one. */
    3910 
    3911 static void gen_deffile(void)
    3912 {
    3913     char *psz = xmalloc(_MAX_PATH);
    3914     if (!make_tempfile(psz, "lddef", ".def"))
    3915     {
    3916         FILE *pFile = fopen(psz, "w");
    3917         if (pFile)
    3918         {
    3919             const char *pszName = _getname(exe_filename);
    3920             size_t cchName = strlen(pszName);
    3921             if (cchName > 4 && !stricmp(pszName + cchName - 4, ".dll"))
    3922                 cchName -= 4;
    3923             fprintf(pFile,
    3924                     ";; Autogenerated by ld\n"
    3925                     "LIBRARY %.*s INITINSTANCE TERMINSTANCE\n"
    3926                     "DATA MULTIPLE\n"
    3927                     "CODE SHARED\n"
    3928                     "\n",
    3929                     cchName, pszName);
    3930             if (trace_files)
    3931                 fprintf(stderr,
    3932                         "--- Generated def-file %s:\n"
    3933                         ";; Autogenerated by ld\n"
    3934                         "LIBRARY %.*s INITINSTANCE TERMINSTANCE\n"
    3935                         "DATA MULTIPLE NONSHARED\n"
    3936                         "CODE SINGLE SHARED\n"
    3937                         "---- End of generated def-file.\n",
    3938                         psz, cchName, pszName);
    3939             fclose(pFile);
    3940             def_filename = psz;
    3941             return;
    3942         }
    3943     }
    3944     free(psz);
    3945 }
    3946 
    39473908
    39483909/* Write the output file */
     
    56955656}
    56965657
     5658/* Generates a definition file for a dll which doesn't have one. */
     5659
     5660static void gen_deffile(void)
     5661{
     5662    char *          psz;
     5663    struct lx_tmp  *pName;
     5664
     5665    /*
     5666     * Make temporary file.
     5667     */
     5668    pName = (struct lx_tmp *)xmalloc(sizeof(*pName));
     5669    pName->name = psz = xmalloc(_MAX_PATH);
     5670    if (!make_tempfile(psz, "lddef", ".def"))
     5671    {
     5672        FILE *pFile = fopen(psz, "w");
     5673        if (pFile)
     5674        {
     5675            const char *pszName = _getname(exe_filename);
     5676            size_t cchName = strlen(pszName);
     5677            if (cchName > 4 && !stricmp(pszName + cchName - 4, ".dll"))
     5678                cchName -= 4;
     5679            fprintf(pFile,
     5680                    ";; Autogenerated by ld\n"
     5681                    "LIBRARY %.*s INITINSTANCE TERMINSTANCE\n"
     5682                    "DATA MULTIPLE\n"
     5683                    "CODE SHARED\n"
     5684                    "\n",
     5685                    cchName, pszName);
     5686            if (trace_files)
     5687                fprintf(stderr,
     5688                        "--- Generated def-file %s:\n"
     5689                        ";; Autogenerated by ld\n"
     5690                        "LIBRARY %.*s INITINSTANCE TERMINSTANCE\n"
     5691                        "DATA MULTIPLE NONSHARED\n"
     5692                        "CODE SINGLE SHARED\n"
     5693                        "---- End of generated def-file.\n",
     5694                        psz, cchName, pszName);
     5695            fclose(pFile);
     5696            def_filename = psz;
     5697
     5698            /* add to auto delete list for removal on exit(). */
     5699            pName->next = conv_list;
     5700            conv_list = pName;
     5701            return;
     5702        }
     5703    }
     5704    free(psz);
     5705    free(pName);
     5706}
     5707
    56975708
    56985709/* atexit worker */
Note: See TracChangeset for help on using the changeset viewer.