Changeset 479


Ignore:
Timestamp:
Jul 30, 2003, 2:13:59 AM (22 years ago)
Author:
bird
Message:

#483: Initial coding completed.

File:
1 edited

Legend:

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

    • Property cvs2svn:cvs-rev changed from 1.16 to 1.17
    r478 r479  
    3333#include <sys/types.h>
    3434#include <sys/stat.h>
     35#include <sys/time.h>
    3536#include <ar.h>
    3637
     
    260261/* Remove underscores from all symbol names */
    261262static int opt_rmunder = FALSE;
     263
     264/* Add timestamp to symbol to make it more unique. */
     265static int opt_weakts = FALSE;
    262266
    263267/* This is the page size for OMF libraries.  It is set by the -p
     
    343347static char mod_name[256];
    344348
     349/* This variable holds a normalized module name used with weak syms.  See get_mod_name(). */
     350static char weak_mod_name[256];
     351
    345352/* This growing array holds the file name table for generating line
    346353   number information.  */
     
    573580                if (t == N_TEXT || t == N_DATA || t == N_BSS
    574581                    /* kso #465 2003-06-04: Find weak symbols too. */
    575                     || t == N_WEAKT || t == N_WEAKD || t == N_WEAKB
    576                     || t == N_WEAKA /* hmm.. */
     582                    || (t >= N_WEAKA && t <= N_WEAKB)
    577583                    || (t == 0 && sym_ptr[j].n_value != 0))
    578584                  return sym_ptr+j;
     
    622628    return;
    623629
    624   /* Find and open the weak symbol list file 
     630  /* Find and open the weak symbol list file
    625631     #483: If not present we'll use the new method. */
    626632  weak_list_filename = getenv ("GCC_WEAKSYMS");
     
    11471153  int i;
    11481154
     1155  if (!weak_list_filename)
     1156      return;
     1157
    11491158#define SETTYPE(t) ((struct nlist *)sym_ptr)[i].n_type = t
    11501159
     
    11921201 * Generates new names for weak symbols.
    11931202 *
    1194  * These names will be catch bye emxomfld and an alias from the generated to 
     1203 * These names will be catch bye emxomfld and an alias from the generated to
    11951204 * the real name will be generated and put in a library before linking.
    11961205 *
     
    12031212 * @remark I'm sorry this function is written in my coding style - not!
    12041213 */
    1205 static char *weak_process_name(struct nlist *pSym, char *pszOrgName, char *pachName, int cchName));
    1206 {
    1207     for (i = 0; i < sym_count; ++i)
    1208     {
    1209 
    1210         switch (sym_ptr->n_type)
     1214static const char *weak_process_name(const struct nlist *pSym, const char *pszOrgName, char *pachName, int cchName)
     1215{
     1216    switch (sym_ptr->n_type)
     1217    {
     1218        /*
     1219         * Hmmm... Check that we handle this correctly else where
     1220         */
     1221        case N_WEAKU:               /* 0x0d  Weak undefined symbol. */
     1222        default:
     1223            break;
     1224
     1225        /*
     1226         * These symbols are defined in this module, so we need to
     1227         * make a unique and recognizable name for them.
     1228         */
     1229        case N_WEAKA:               /* 0x0e  Weak absolute symbol. */
     1230        case N_WEAKT:               /* 0x0f  Weak text symbol. */
     1231        case N_WEAKD:               /* 0x10  Weak data symbol. */
     1232        case N_WEAKB:               /* 0x11  Weak bss symbol. */
    12111233        {
    1212             /*
    1213              * Hmmm... Check that we handle this correctly else where
    1214              */
    1215             case N_WEAKU:               /* 0x0d  Weak undefined symbol. */
    1216                 break;
    1217 
    1218             /*
    1219              * I'm uncertain what this means, needs to google 
    1220              * for and explanation of how this is used.
    1221              */   
    1222             case N_WEAKA:               /* 0x0e  Weak absolute symbol. */
    1223                 break;
    1224                        
    1225             /*
    1226              * These symbols are defined in this module, so we need to
    1227              * make a unique and recognizable name for them.
    1228              */
    1229             case N_WEAKT:               /* 0x0f  Weak text symbol. */
    1230             case N_WEAKD:               /* 0x10  Weak data symbol. */
    1231             case N_WEAKB:               /* 0x11  Weak bss symbol. */
     1234            if (!opt_weakts)
     1235                snprintf(pachName, cchName, "%s$w$%s",
     1236                         pszOrgName, weak_mod_name);
     1237            else
    12321238            {
    1233                 int cch = strlen(pszOrgName);
    1234                 memcpy(pachName, pszOrgName, cch);
    1235 
    1236                 break;
     1239                struct timeval tv = {0, 0};
     1240                gettimeofday(&tv, NULL);
     1241                snprintf(pachName, cchName, "%s$w$%s%lx%lx",
     1242                         pszOrgName, weak_mod_name, tv.tv_sec, tv.tv_usec);
    12371243            }
     1244            return pachName;
    12381245        }
    1239     }
     1246
     1247    }
     1248    /* default is to keep the original name */
     1249    return pszOrgName;
    12401250}
    12411251
     
    12961306  const char *name, *pub_name;
    12971307  dword address;
    1298   char  szName[260];
     1308  char  szName[256];
    12991309
    13001310  started = FALSE;
    13011311  for (i = 0; i < sym_count; ++i)
    1302     if ((sym_ptr[i].n_type & ~N_EXT) == type)
     1312    if (   (sym_ptr[i].n_type & ~N_EXT) == type
     1313        || (type >= N_WEAKU && type <= N_WEAKB && sym_ptr[i].n_type == type)
     1314        )
    13031315      {
    13041316        address = sym_ptr[i].n_value - start;
     
    13081320            if (   (sym_ptr[i].n_type & N_EXT)
    13091321                || (type == N_TEXT && strncmp (name, "___POST$", 8) == 0)
    1310                 || (sym_ptr[i].n_type >= N_WEAKU && sym_ptr[i].n_type <= N_WEAKB)
    1311                    )
     1322                || (sym_ptr[i].n_type >= N_WEAKU && sym_ptr[i].n_type <= N_WEAKB) )
    13121323              {
    13131324                if ((sym_ptr[i].n_type & N_EXT) && out_lib != NULL)
     
    13201331                      error (lib_errmsg);
    13211332                  }
    1322            
     1333
    13231334                /* for weaksymbols we may have to decorate the name */
    13241335                if (   !weak_list_filename
    1325                     && sym_ptr[i].n_type >= N_WEAKU
    1326                     && sym_ptr[i].n_type <= N_WEAKB
    1327                        )
    1328                     name = weak_process_name(sym_ptr[i], name, szName, sizeof(szName));
     1336                    && sym_ptr[i].n_type >= N_WEAKU && sym_ptr[i].n_type <= N_WEAKB )
     1337                    name = weak_process_name(&sym_ptr[i], name, szName, sizeof(szName));
    13291338
    13301339                if (started && !fits (strlen (name) + 6))
     
    14011410  write_pubdef1 (N_TEXT, text_index, FALSE, 0);
    14021411  write_pubdef1 (N_TEXT, text_index, TRUE, 0);
    1403   if (!write_pubdef_main)
     1412  if (!weak_list_filename)
    14041413  {
    14051414      write_pubdef1 (N_WEAKT, text_index, FALSE, 0);
     
    14101419  write_pubdef1 (N_DATA, udat_index, FALSE, text_size);
    14111420  write_pubdef1 (N_DATA, udat_index, TRUE, text_size);
    1412   if (!write_pubdef_main)
     1421  if (!weak_list_filename)
    14131422  {
    14141423      write_pubdef1 (N_WEAKD, text_index, FALSE, 0);
     
    14171426  write_pubdef1 (N_BSS, bss_index, FALSE, text_size + data_size);
    14181427  write_pubdef1 (N_BSS, bss_index, TRUE, text_size + data_size);
    1419   if (!write_pubdef_main)
     1428  if (!weak_list_filename)
    14201429  {
    14211430      write_pubdef1 (N_WEAKB, bss_index, FALSE, text_size + data_size);
     
    27112720  int i, len, ok;
    27122721  const char *p1, *p2;
     2722  char *p3;
    27132723
    27142724  ok = FALSE;
     
    27342744      _strncpy (mod_name, p1, sizeof (mod_name));
    27352745    }
     2746
     2747  /* Find the base name and lenght (excluding extension)
     2748     This is used for weak symbol handling. */
     2749  for (p1 = "\\/:", p2 = mod_name; *p1; p1++)
     2750    if ((p3 = strrchr(p2, *p1)) != NULL)
     2751      p2 = p3 + 1;
     2752  for (p3 = weak_mod_name; *p2; p2++)
     2753    if (isalnum(*p2) || *p2 == '$' || *p2 == '_' || *p2 == '@')
     2754        *p3++ = *p2;
     2755  *p3 = '\0';
    27362756}
    27372757
     
    29192939
    29202940
    2921   /* 
    2922    * If no lines or no files, we don't want to issue any LINNUM records. 
     2941  /*
     2942   * If no lines or no files, we don't want to issue any LINNUM records.
    29232943   */
    29242944  if (valid_lines <= 0 || file_grow.count <= 0)
     
    33023322  write_debug_style ();
    33033323
    3304   /* Method 2 Weak symbol processing (generate names). */
    3305 
    3306   weak_process_names();
    3307 
    33083324  /* Define all the OMF names (LNAMES record).  Of course, we must not
    33093325     define new OMF names after this point. */
     
    34613477  puts ("  -I <idmdll>        Name the identifier manipulation DLL");
    34623478  puts ("  -O <directory>     Extract files to <directory>");
     3479  puts ("  -t                 Add timestamping to the weak symbol mangling");
    34633480  puts ("  -w                 Suppress reading/writing of the weaksyms.omf file");
    34643481  puts ("  -z                 Remove underscores from all symbol names");
     
    39583975        opt_rmunder = TRUE;
    39593976        break;
     3977      case 't':
     3978        opt_weakts = TRUE;
     3979        break;
    39603980      default:
    39613981        usage ();
Note: See TracChangeset for help on using the changeset viewer.