Changeset 2001


Ignore:
Timestamp:
Jun 6, 2005, 4:13:06 AM (20 years ago)
Author:
bird
Message:

o Added support for new EMX a.out stab N_EXP (0x6c). This encodes export

definitions. (gcc can do declspec(dllexport) now.)
TODO: ld needs updating, probably this is the right time to drop the

old ld and fixup the binutils port!

Location:
trunk/src/emx
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/emx/ChangeLog.LIBC

    • Property cvs2svn:cvs-rev changed from 1.50 to 1.51
    r2000 r2001  
    88        o Default TCPIP mode is __USB_LIBC_TCPIP. When either TCPV40HDRS or TCPV41HDRS
    99          are defined we are in strict mode and __USB_LIBC_TCPIP will not be defined.
    10 
    1110    - libomflib, emxomfar:
    1211        o Allow multiple modules by the same basename. This is not in tradition with
    1312          other librarians, but it solves incompatible behaviour between emxomfar and ar.
    14 
    1513    - ld:
    1614        o Avoid using alloca since we might easily run out of stack for big objects
    1715          with debuginfo.
     16    - emxomf:
     17        o Added support for new EMX a.out stab N_EXP (0x6c). This encodes export
     18          definitions. (gcc can do __declspec(dllexport) now.)
     19          TODO: ld needs updating, probably this is the right time to drop the
     20                old ld and fixup the binutils port!
    1821
    19222005-05-08: knut st. osmundsen <bird-gccos2-spam@anduin.net>
  • trunk/src/emx/include/a_out.h

    • Property cvs2svn:cvs-rev changed from 1.5 to 1.6
    r2000 r2001  
    141141#define N_WEAKB 0x11            /* Weak bss symbol.  */
    142142/* emx */
    143 #define N_IMP1  0x68            /* Import definition symbol */
     143#define N_IMP1  0x68            /* Import reference symbol */
    144144#define N_IMP2  0x6a            /* Import definition symbol */
     145#define N_EXP   0x6c            /* Export definition symbol */
    145146
    146147
  • trunk/src/emx/include/sys/omflib.h

    • Property cvs2svn:cvs-rev changed from 1.6 to 1.7
    r2000 r2001  
    7878
    7979#if !defined (IMPDEF_CLASS)
    80 #define IMPDEF_CLASS    0xa0
     80#define IMPDEF_CLASS    CLASS_OMFEXT
    8181#define LIBMOD_CLASS    0xa3
    82 #define IMPDEF_SUBTYPE  0x01
     82#define IMPDEF_SUBTYPE  OMFEXT_IMPDEF
    8383#endif
    8484
  • trunk/src/emx/src/emxomf/emxomf.c

    • Property cvs2svn:cvs-rev changed from 1.41 to 1.42
    r2000 r2001  
    575575    {
    576576      int sym_ofs = i;
    577       s = name;
    578       if (strip_underscore (str_ptr + i))
     577      s = (const byte *)name;
     578      if (strip_underscore ((const char *)(str_ptr + i)))
    579579        ++i;
    580580      if (memcmp (name, str_ptr+i, len+1) == 0)
     
    594594              }
    595595        }
    596       i += strlen (str_ptr+i) + 1;
     596      i += strlen ((const char *)(str_ptr + i)) + 1;
    597597    }
    598598  return NULL;                  /* Symbol not found */
     
    917917
    918918
    919 /* Put the null-terminated string pszName into the current OMF record.
     919/* Put the string pszName into the current OMF record.
    920920   In the OMF record, the string is preceded by a length byte.  The
    921921   string length must not exceed 255; if it is too long, display a
     
    924924   message and abort. */
    925925
    926 static void put_str(const char *pszName)
    927 {
    928     int cch = strlen(pszName);
     926static void put_nstr(const char *pszName, size_t cch)
     927{
    929928    if (cch > 255)
    930929    {
     
    937936        const char *psz;
    938937        unsigned    uHash;
    939         for (psz = pszName, uHash = 5381; *psz; psz++)  /* hash alg: original djb2. */
     938        for (psz = pszName, uHash = 5381, cch2 = cch; cch > 0; psz++, cch--) /* hash alg: original djb2. */
    940939            uHash += (uHash << 5) + *psz;
    941940        cch2 = sprintf(szHash, "!_%X", 0x7fffffff & uHash);
     
    958957        out_idx += cch;
    959958    }
     959}
     960
     961/* Put the null-terminated string pszName into the current OMF record.
     962   See put_nstr() for full details on string handling. */
     963
     964static void put_str(const char *pszName)
     965{
     966    int cch = strlen(pszName);
     967    put_nstr(pszName, cch);
    960968}
    961969
     
    10591067   and quit. */
    10601068
    1061 static void put_mem (const char *src, int size)
     1069static void put_mem (const void *src, int size)
    10621070{
    10631071  if (!fits (size))
     
    11471155    else if (sym_ptr[i].n_type == N_EXT && sym_ptr[i].n_value == 0)
    11481156      {
    1149         name = str_ptr + sym_ptr[i].n_un.n_strx;
     1157        name = (const char *)(str_ptr + sym_ptr[i].n_un.n_strx);
    11501158        sym_more[i].index = sym_index++;
    11511159        if (memcmp (name, "_16_", 4) == 0)
     
    11611169          }
    11621170        sym_more[i].index = sym_index++;
    1163         add_extdef (&started, str_ptr + sym_ptr[i].n_un.n_strx, sym_more[i].hll_type);
     1171        add_extdef (&started, (const char *)(str_ptr + sym_ptr[i].n_un.n_strx), sym_more[i].hll_type);
    11641172      }
    11651173#if 1 /* this isn't actually required if only the assembler could do what it's supposed to... */
     
    11681176           external records for this, perhaps...
    11691177           At least I can't see why this will be wrong. */
    1170         name = str_ptr + sym_ptr[i].n_un.n_strx;
     1178        name = (const char *)(str_ptr + sym_ptr[i].n_un.n_strx);
    11711179        sym_more[i].index = sym_index++;
    11721180        add_extdef (&started, name, sym_more[i].hll_type);
     
    12271235    if ((sym_ptr[i].n_type >= N_WEAKA) && (sym_ptr[i].n_type <= N_WEAKB))
    12281236      {
    1229         const char *name = str_ptr + sym_ptr[i].n_un.n_strx;
     1237        const char *name = (const char *)(str_ptr + sym_ptr[i].n_un.n_strx);
    12301238
    12311239        int public = N_EXT;
     
    14011409      {
    14021410        init_rec (ALIAS);
    1403         put_sym (str_ptr + sym_ptr[i].n_un.n_strx);
    1404         put_sym (str_ptr + sym_ptr[i+1].n_un.n_strx);
     1411        put_sym ((const char *)(str_ptr + sym_ptr[i].n_un.n_strx));
     1412        put_sym ((const char *)(str_ptr + sym_ptr[i+1].n_un.n_strx));
    14051413        write_rec ();
    14061414
    14071415        if (out_lib != NULL)
    14081416          {
    1409             pub_name = str_ptr + sym_ptr[i].n_un.n_strx;
     1417            pub_name = (const char *)(str_ptr + sym_ptr[i].n_un.n_strx);
    14101418            if (strip_underscore (pub_name))
    14111419              ++pub_name;
     
    14541462        if ((address >= 0x10000 || force_big) == big)
    14551463          {
    1456             name = str_ptr + sym_ptr[i].n_un.n_strx;
     1464            name = (const char *)(str_ptr + sym_ptr[i].n_un.n_strx);
    14571465            if (   (sym_ptr[i].n_type & N_EXT)
    14581466                || (type == N_TEXT && strncmp (name, "___POST$", 8) == 0)
     
    15181526      if ((sym_ptr[i].n_type & ~N_EXT) == N_TEXT)
    15191527        {
    1520           const char * name    = str_ptr + sym_ptr[i].n_un.n_strx;
     1528          const char * name    = (const char *)(str_ptr + sym_ptr[i].n_un.n_strx);
    15211529          dword        address = sym_ptr[i].n_value;
    15221530          if (   (sym_ptr[i].n_type & N_EXT)
     
    16101618    else if (sym_ptr[i].n_type == N_EXT && sym_ptr[i].n_value != 0)
    16111619      {
    1612         name = str_ptr + sym_ptr[i].n_un.n_strx;
     1620        name = (const char *)(str_ptr + sym_ptr[i].n_un.n_strx);
    16131621        sym_more[i].index = sym_index++;
    16141622        if (memcmp (name, "_16_", 4) == 0)
     
    16281636        put_idx (0);                  /* Type index */
    16291637        put_8 (0x62);                 /* Data type */
     1638        if (size < 4)
     1639            size = 4; /* VAC308 ilink freaks out if size = 1 or something */
    16301640        if (size < 0x80)
    16311641          put_8 (size);
     
    22242234             this set is already known. */
    22252235
    2226           name = str_ptr + sym_ptr[i].n_un.n_strx;
     2236          name = (const char *)(str_ptr + sym_ptr[i].n_un.n_strx);
    22272237          for (set_ptr = sets; set_ptr != NULL; set_ptr = set_ptr->next)
    22282238            if (strcmp (set_ptr->name, name) == 0)
     
    24752485         get the string from the cache. */
    24762486
    2477       sym_name = str_ptr + sym_ptr[rel->r_symbolnum].n_un.n_strx;
     2487      sym_name = (const char *)(str_ptr + sym_ptr[rel->r_symbolnum].n_un.n_strx);
    24782488      for (p = modstr_cache; p != NULL; p = p->next)
    24792489        if (strcmp (p->symbol, sym_name) == 0)
     
    25282538                  case N_TEXT|N_EXT:
    25292539                  case N_DATA|N_EXT:
    2530                     if (strcmp (m_str + m_sym[i].n_un.n_strx, sym_name) == 0)
     2540                    if (strcmp ((const char *)(m_str + m_sym[i].n_un.n_strx), sym_name) == 0)
    25312541                      {
    25322542                        m_sym += i; found = TRUE; break;
     
    26612671      {
    26622672      case N_IMP1|N_EXT:
    2663         name1 = str_ptr + sym_ptr[i].n_un.n_strx;
     2673        name1 = (const char *)(str_ptr + sym_ptr[i].n_un.n_strx);
    26642674        break;
    26652675      case N_IMP2|N_EXT:
    2666         name2 = str_ptr + sym_ptr[i].n_un.n_strx;
     2676        name2 = (const char *)(str_ptr + sym_ptr[i].n_un.n_strx);
    26672677        break;
    26682678      default:
     
    27322742        {
    27332743        case N_IMP1|N_EXT:
    2734           name1 = str_ptr + sym_ptr[i].n_un.n_strx;
     2744          name1 = (const char *)(str_ptr + sym_ptr[i].n_un.n_strx);
    27352745          break;
    27362746        case N_IMP2|N_EXT:
    2737           name2 = str_ptr + sym_ptr[i].n_un.n_strx;
     2747          name2 = (const char *)(str_ptr + sym_ptr[i].n_un.n_strx);
    27382748          break;
    27392749        }
     
    28292839      case N_TEXT|N_EXT:
    28302840        if (pub_name != NULL) return FALSE;
    2831         pub_name = str_ptr + sym_ptr[i].n_un.n_strx;
     2841        pub_name = (const char *)(str_ptr + sym_ptr[i].n_un.n_strx);
    28322842        break;
    28332843
     
    28372847
    28382848      case N_SETT|N_EXT:
    2839         if (strcmp (str_ptr + sym_ptr[i].n_un.n_strx, "__os2dll") != 0)
     2849        if (strcmp ((const char *)(str_ptr + sym_ptr[i].n_un.n_strx), "__os2dll") != 0)
    28402850          return FALSE;
    28412851        table_off = sym_ptr[i].n_value;
     
    28892899  make_import (pub_name, ord != 0 ? NULL : proc_name, ord, dll_name);
    28902900  return TRUE;
     2901}
     2902
     2903/**
     2904 * Emits a OMF export record if the symbols is defined in this module.
     2905 */
     2906static void make_export(const char *pszSymbol, size_t cchSymbol,
     2907                        const char *pszExpName, size_t cchExpName, unsigned iOrdinal)
     2908{
     2909    const struct nlist *pSym;
     2910    char *pszSym = alloca(cchSymbol + 1);
     2911    memcpy(pszSym, pszSymbol, cchSymbol);
     2912    pszSym[cchSymbol] = '\0';
     2913
     2914    pSym = find_symbol(pszSym);
     2915    if (pSym)
     2916    {
     2917        /*
     2918         * Write the export definition record.
     2919         */
     2920        uint8_t fFlags = 0;
     2921        if (iOrdinal)
     2922            fFlags |= 1 << 7; /* have ordinal */
     2923        if (cchExpName && !iOrdinal)
     2924           fFlags |= 1 << 6; /* resident name */
     2925
     2926        init_rec(COMENT);
     2927        put_8(0x00);
     2928        put_8(CLASS_OMFEXT);
     2929        put_8(OMFEXT_EXPDEF);
     2930        put_8(fFlags);
     2931        put_nstr(pszExpName, cchExpName);
     2932        put_nstr(pszSymbol, cchSymbol);
     2933        if (iOrdinal)
     2934            put_16(iOrdinal);
     2935        write_rec();
     2936    }
     2937}
     2938
     2939
     2940/* Convert export entries.
     2941
     2942   The exports are encoded as N_EXT (0x6c) stab entries. The value is -42,
     2943   and the symbol name is on the form: "<exportname>,<ordinal>=<symbol>,code|data"
     2944   The exportname can be empty if ordinal is not 0. Ordinal 0 means not exported by
     2945   any special ordinal number.
     2946
     2947   Export entries for symbols which are not defined in the object are ignored. */
     2948static void write_export (void)
     2949{
     2950    int i;
     2951
     2952    /* Search the symbol table for N_IMP1 and N_IMP2 symbols.  These are
     2953       unique to import modules. */
     2954
     2955    for (i = 0; i < sym_count; ++i)
     2956    {
     2957        const char *pszName;
     2958        size_t      cchName;
     2959        const char *pszOrdinal;
     2960        const char *pszSymbol;
     2961        size_t      cchSymbol;
     2962        const char *pszType;
     2963        int         iOrdinal;
     2964        char       *pszOrdinalEnd;
     2965        if (sym_ptr[i].n_type != N_EXP)
     2966            continue;
     2967        pszName = (const char *)(str_ptr + sym_ptr[i].n_un.n_strx);
     2968
     2969        /*
     2970         * Parse it.
     2971         */
     2972        /* find equal sign first, we'll use this for validating the ordinal. */
     2973        pszSymbol = strchr(pszName, '=');
     2974        if (!pszSymbol)
     2975            error("Invalid export record: missing `='. \nstabs: %s", pszName);
     2976
     2977        /* ordinal */
     2978        pszOrdinal = strchr(pszName, ',');
     2979        if (!pszOrdinal || pszOrdinal >= pszSymbol)
     2980            error("Invalid export record: missing ordinal.\nstabs: %s", pszName);
     2981        cchName = pszOrdinal - pszName;
     2982        pszOrdinal++;
     2983        iOrdinal = strtol(pszOrdinal, &pszOrdinalEnd, 0);
     2984        if (iOrdinal < 0 || iOrdinal >= 0x10000)
     2985            error("Invalid export record: ordinal value is out of range (0-65k): %d\nstabs:%s",
     2986                  iOrdinal, pszName);
     2987        if (pszOrdinalEnd != pszSymbol)
     2988            error("Invalid export record: ordinal field doesn't end at `=.\nstabs:%s", pszName);
     2989
     2990        /* type and symbol */
     2991        pszSymbol++;
     2992        pszType = strchr(pszSymbol, ',');
     2993        if (!pszType)
     2994            error("Invalid export record: Symbol type is missing\nstabs:%s", pszName);
     2995        cchSymbol = pszType - pszSymbol;
     2996        pszType++;
     2997        if (strcmp(pszType, "code") && strcmp(pszType, "data") && strcmp(pszType, "bss") && strcmp(pszType, "common"))
     2998            error("Invalid export record: Invalid symbol type: %s\nstabs:%s", pszType, pszName);
     2999        if (!cchSymbol)
     3000            error("Invalid export record: No (internal) symbol name.\nstabs:%s", pszName);
     3001
     3002        /*
     3003         * Hand it on to the worker which looks up the symbol
     3004         * and emits the OMF export record if found.
     3005         */
     3006        make_export(pszSymbol, cchSymbol, pszName, cchName, iOrdinal);
     3007    }
    28913008}
    28923009
     
    29513068    if (sym_ptr[i].n_type == N_SO)
    29523069      {
    2953         p1 = str_ptr + sym_ptr[i].n_un.n_strx;
     3070        p1 = (const char *)(str_ptr + sym_ptr[i].n_un.n_strx);
    29543071        len = strlen (p1);
    29553072        if (len > 0 && p1[len-1] == '/' )
     
    32343351      {
    32353352      case N_SOL:
    3236         file_index = file_find (str_ptr + sym_ptr[i].n_un.n_strx);
     3353        file_index = file_find ((const char *)(str_ptr + sym_ptr[i].n_un.n_strx));
    32373354        break;
    32383355      case N_SLINE:
     
    34903607                    case N_IMP1|N_EXT:
    34913608                    case N_IMP2|N_EXT:
     3609      case N_EXP:   case N_EXP|N_EXT:
    34923610      case N_LSYM:
    34933611      case N_SOL:
     
    37073825  weak_process ();
    37083826
     3827  /* Convert imports and exports. These show up very early in VAC
     3828     generated OMF files. */
     3829  write_import_i2 ();
     3830  write_export ();
     3831
    37093832  /* Define external, communal and public symbols (EXTDEF, WKEXT,
    37103833     COMDEF, PUBDEF, and ALIAS records).  This must be done after
     
    37173840  write_set_pub ();
    37183841  write_alias ();
    3719   write_import_i2 ();
    37203842
    37213843  /* Write link pass separator. */
  • trunk/src/emx/src/emxomf/weakld.c

    • Property cvs2svn:cvs-rev changed from 1.31 to 1.32
    r2000 r2001  
    349349        /** @} */
    350350        /** no idea what this implies */
    351         WLDSEF_NODATA           = 0x04
     351        WLDSEF_NODATA           = 0x04,
     352        /** From an EXPORT section of a .DEF-file. */
     353        WLDSEF_DEF_FILE         = 0x80
    352354    }                   fExport;
    353355    /** Export word count. */
     
    20752077    if (pSym->fFlags & WLDSF_EXPORT)
    20762078    {
    2077         /* Just warn and ignore */
    2078         modWarn(pMod, "Export '%s' is already defined.", pSym->pszName);
     2079        if (    (pSym->fExport & WLDSEF_DEF_FILE)
     2080            &&  (fExport & WLDSEF_DEF_FILE))
     2081            modWarn(pMod, "Export '%s' is already defined.", pSym->pszName);
     2082        if (    !(pSym->fExport & WLDSEF_DEF_FILE)
     2083            &&  (fExport & WLDSEF_DEF_FILE))
     2084            pSym->fExport = fExport;
    20792085    }
    20802086    else
     
    25182524                                ul = 0;                         /* ordinal */
    25192525                                if (*u1.pch & 0x80)
    2520                                     ul = OMF_BYTE();
     2526                                    ul = OMF_WORD();
    25212527                                pSym = symAddExport(pWld, pMod, fLibSearch,
    25222528                                                    (*u1.puch & 0x40 ? WLDSEF_RESIDENT : WLDSEF_DEFAULT) | (*u1.puch & 0x20 ? WLDSEF_NODATA : 0),
    25232529                                                    ((unsigned)*u1.puch) & 0x1f,
    2524                                                     u2.pch + 1, *u1.puch,
    2525                                                     u3.pch + 1, *u2.puch,
     2530                                                    u2.pch + 1, *u2.puch,
     2531                                                    u3.pch + 1, *u3.puch,
    25262532                                                    ul);
    25272533                                if (!pSym) goto failure;
     
    29412947                cWords = pStmt->export.pwords;
    29422948            pSym = symAddExport(pParam->pWld, pParam->pMod, 0,
    2943                                 fFlags, cWords,
     2949                                fFlags | WLDSEF_DEF_FILE, cWords,
    29442950                                pStmt->export.entryname, -1,
    29452951                                pStmt->export.internalname, -1,
Note: See TracChangeset for help on using the changeset viewer.