Changeset 2673 for trunk/emx/src/emxomf
- Timestamp:
- Mar 19, 2006, 6:21:22 AM (20 years ago)
- Location:
- trunk/emx/src/emxomf
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/emx/src/emxomf/emxomf.smak
r1183 r2673 9 9 .TCF := $(CFLAGS.DEF.VERSION) 10 10 .TDEP := @O@libomflib$A 11 .TLDF := -liberty 11 12 include mkexe.smak 12 13 -
trunk/emx/src/emxomf/emxomfld.c
r2300 r2673 349 349 if (response_file == NULL) 350 350 { 351 int fd; 351 352 352 353 /* Complain if we are not allowed to use a response … … 363 364 364 365 strcpy (response_fname, "ldXXXXXX"); 365 if (mktemp (response_fname) == NULL) 366 fd = mkstemp (response_fname); 367 if (fd < 0) 366 368 { 367 369 perror ("emxomfld"); 368 370 exit (2); 369 371 } 372 close(fd); 370 373 response_file = fopen (response_fname, "wt"); 371 374 if (response_file == NULL) … … 1161 1164 static void arg_init (int rsp) 1162 1165 { 1163 response_fname[0] = '\0'; 1166 if (response_fname[0] != '\0') 1167 { 1168 remove (response_fname); 1169 response_fname[0] = '\0'; 1170 } 1164 1171 command_line[0] = '\0'; 1165 1172 line_len = 0; … … 1496 1503 fprintf (stderr, 1497 1504 "emxomfld: multiple module definition files\n"); 1498 usage ();1505 return 1; 1499 1506 } 1500 1507 def_fname = _realrealpath(optarg, NULL, 0); … … 1512 1519 fprintf (stderr, 1513 1520 "emxomfld: multiple binary resource files\n"); 1514 usage ();1521 return 1; 1515 1522 } 1516 1523 res_fname = _realrealpath(optarg, NULL, 0); … … 1585 1592 { 1586 1593 fprintf (stderr, "emxomfld: multiple map files files\n"); 1587 usage ();1594 return 1; 1588 1595 } 1589 1596 map_fname = optarg; … … 1593 1600 case OPT_ZSTACK: 1594 1601 if (!optarg) 1595 usage ();1602 return 1; 1596 1603 errno = 0; 1597 1604 stack_size = strtol (optarg, &t, 0); 1598 1605 if (errno != 0 || *t != 0 || t == optarg) 1599 usage ();1606 return 1; 1600 1607 break; 1601 1608 … … 1622 1629 if (optind > 1) 1623 1630 fprintf (stderr, "emxomfld: invalid option (%s)\n", argv[optind - 1]); 1624 usage (); 1631 else 1632 usage (); 1633 return 1; 1625 1634 } 1626 1635 } … … 1639 1648 { 1640 1649 fprintf (stderr, "emxomfld: no input files\n"); 1641 usage ();1650 return 1; 1642 1651 } 1643 1652 … … 1656 1665 else if (map_fname == NULL) 1657 1666 { 1658 t = xstrdup (output_fname); 1667 int cch = strlen (output_fname) + 1; 1668 t = xmalloc (cch + 4); 1669 memcpy (t, output_fname, cch); 1659 1670 _remext (t); 1671 strcat (t, ".map"); 1660 1672 map_fname = t; 1661 1673 } -
trunk/emx/src/emxomf/stabshll.c
r1885 r2673 20 20 Boston, MA 02111-1307, USA. */ 21 21 //#define HLL_DEBUG 1 22 23 #define DEMANGLE_PROC_NAMES 1 22 24 23 25 /******************************************************************************* … … 31 33 #include <alloca.h> 32 34 #include <ctype.h> 35 #ifdef DEMANGLE_PROC_NAMES 36 # include <demangle.h> 37 #endif 33 38 #include "defs.h" 34 39 #include "emxomf.h" … … 2225 2230 if (!parse_mangled_args ()) 2226 2231 goto syntax; 2227 tf->mnglname = strpool_addn(str_pool, pszMangled, parse_ptr - pszMangled - 1); /* ASSUMES no textra spaces! */2232 tf->mnglname = strpool_addn(str_pool, pszMangled, parse_ptr - pszMangled - 1); /* ASSUMES no extra spaces! */ 2228 2233 tf->flags = parse_visibility () | MEMBER_FUNCTION; 2229 2234 switch (*parse_ptr) … … 3315 3320 struct relocation_info r; 3316 3321 const char *str, *p, *p2; 3317 const char *name; 3318 int n, /* size of name. */ 3319 ti, 3320 ticlass; 3322 const char *name, *mnglname; 3323 #ifdef DEMANGLE_PROC_NAMES 3324 char *pszFree; 3325 #endif 3326 size_t cchName, cchMnglName; 3327 int ti, ticlass; 3321 3328 3322 3329 str = str_ptr + symbol->n_un.n_strx; … … 3324 3331 if (p == NULL) 3325 3332 abort (); 3326 n = p - str; 3327 3328 /** @todo name demangling */ 3329 name = strpool_addn (str_pool, str, n); 3333 cchName = cchMnglName = p - str; 3334 name = mnglname = strpool_addn (str_pool, str, cchMnglName); 3330 3335 proc_start_addr = symbol->n_value; 3336 3337 #ifdef DEMANGLE_PROC_NAMES 3338 /* demangle the name */ 3339 pszFree = cplus_demangle (mnglname, DMGL_ANSI | DMGL_PARAMS); 3340 if (!pszFree && (*mnglname == '_' || *mnglname == '*')) 3341 pszFree = cplus_demangle (mnglname + 1, DMGL_ANSI | DMGL_PARAMS); 3342 if (pszFree) 3343 { 3344 cchName = strlen (pszFree); 3345 name = pszFree; 3346 } 3347 else if (*mnglname == '*') 3348 { 3349 cchName--; 3350 name++; 3351 } 3352 #endif 3331 3353 3332 3354 /* now let's see if there is a memfunc for this name. */ 3333 3355 for (t1 = type_head; t1; t1 = t1->next) 3334 3356 if ( t1->tag == ty_memfunc 3335 && t1->d.memfunc.mnglname == name)3357 && t1->d.memfunc.mnglname == mnglname) 3336 3358 break; 3337 3359 … … 3358 3380 */ 3359 3381 /** @todo: the string parsing still is a bit spooky. */ 3360 for (p2 = p; (p2 = strstr (p2, name)) != NULL; p2 += n)3361 if (p2[-1] == ':' && p2[ n] == ';')3382 for (p2 = p; (p2 = strstr (p2, mnglname)) != NULL; p2 += cchMnglName) 3383 if (p2[-1] == ':' && p2[cchMnglName] == ';') 3362 3384 { 3363 3385 int stab = atoi (&p[3]); … … 3373 3395 if (ticlass < 0) 3374 3396 { 3375 warning (" Can't figure out which class method '%s' is a member of!", name);3397 warning (" Can't figure out which class method '%s' is a member of!", mnglname); 3376 3398 ticlass = 0; 3377 3399 } … … 3411 3433 make_type (t2, &ti); 3412 3434 3413 sst_start (cplusplus_flag || n> 255 ? SST_CPPproc : SST_proc);3435 sst_start (cplusplus_flag || cchName > 255 ? SST_CPPproc : SST_proc); 3414 3436 r.r_address = sst.size; 3415 3437 buffer_dword (&sst, symbol->n_value); /* Segment offset */ … … 3421 3443 buffer_word (&sst, 0); /* Class type (for member functions) */ 3422 3444 buffer_byte (&sst, 8); /* 32-bit near */ 3423 if (cplusplus_flag || n> 255)3445 if (cplusplus_flag || cchName > 255) 3424 3446 buffer_enc (&sst, name); /* Proc name */ 3425 3447 else … … 3434 3456 buffer_mem (&sst_reloc, &r, sizeof (r)); 3435 3457 set_hll_type (symbol - sym_ptr, ti); 3458 3459 #ifdef DEMANGLE_PROC_NAMES 3460 /* free the demangled name. */ 3461 free (pszFree); 3462 #endif 3436 3463 } 3437 3464 -
trunk/emx/src/emxomf/weakld.c
r2235 r2673 73 73 74 74 /** Compares a existing symbol with a new symbol. */ 75 #define SYM_EQUAL(pWld, pSym, _pszName, _fFlags, _uHash, _cchName) \75 #define SYM_EQUAL(pWld, pSym, _pszName, _fFlags, _uHash, _cchName) \ 76 76 ( (pSym)->uHash == (_uHash) \ 77 && ( !((_fFlags) & WLDSF_TRUNCATED) && !((pSym)->fFlags & WLDSF_TRUNCATED) \ 78 ? (pSym)->pszName == (_pszName) \ 79 : symCompareTrucated(pWld, pSym, _pszName, _cchName) ) \ 80 ) 77 && (pSym)->pszName == (_pszName) \ 78 ) 81 79 82 80 /** Compares a existing symbol with a potential symbol. */ 83 #define SYM_EQUAL2(pWld, pSym, _pszName, _fFlags, _uHash, _cchName, _pfn) \81 #define SYM_EQUAL2(pWld, pSym, _pszName, _fFlags, _uHash, _cchName, _pfn) \ 84 82 ( (pSym)->uHash == (_uHash) \ 85 && ( !((_fFlags) & WLDSF_TRUNCATED) && !((pSym)->fFlags & WLDSF_TRUNCATED) \ 86 ? !_pfn((pSym)->pszName, (_pszName), (_cchName)) && !(pSym)->pszName[(_cchName)] \ 87 : symCompareTrucated(pWld, pSym, _pszName, _cchName) ) \ 88 ) 83 && !_pfn((pSym)->pszName, (_pszName), (_cchName)) \ 84 && !(pSym)->pszName[(_cchName)] \ 85 ) 89 86 90 87 … … 187 184 188 185 /** 189 * Truncated EXTDEF name.190 */191 typedef struct wldsymtrunc192 {193 /** Full name. */194 const char * pszName;195 /** Pointer to the next symbol. */196 struct wldsymtrunc *pNext;197 } WLDSYMTRUNC, *PWLDSYMTRUNC;198 199 /**200 186 * Symbol structure. 201 187 */ … … 208 194 /** The full hash value. */ 209 195 unsigned uHash; 210 /** LIFO of truncated name variations. */211 PWLDSYMTRUNC pTrunc;212 196 213 197 /** Symbol flags. */ … … 278 262 * in the definition file. 279 263 */ 280 WLDSF_WEAKALIASDONE = 0x8000, 281 282 /** Internal flag which indicates that the symbol have been 283 * truncated by emxomf. */ 284 WLDSF_TRUNCATED = 0x10000, 264 WLDSF_WEAKALIASDONE = 0x8000 285 265 } fFlags; 286 266 … … 486 466 static int symSearchLibEnum(PWLD pWld, PWLDSYM pSym, void *pvUser); 487 467 static inline unsigned symHash(const char* pszSym, unsigned cch, unsigned fWldCaseFlag); 488 static int symCompareTrucated(PWLD pWld, PWLDSYM pSym1, const char *pszName2, unsigned cchName2);489 468 static const char * symGetDescr(PWLDSYM pSym); 490 469 static void symDumpReferers(PWLDSYM pSym); … … 1265 1244 1266 1245 1267 /**1268 * Internal worker for SYM_EQUAL()1269 *1270 * Compares truncated symbols. The hash for these symbols matches and at least1271 * one of them is truncated.1272 *1273 * @returns 1 if matches1274 * @returns 0 if not matching.1275 * @param pWld Linker Instance.1276 * @param pSym1 Symbol 1.1277 * @param pszName2 Symbol 2 name.1278 * @param cchName2 Symbol 2 name length.1279 */1280 static int symCompareTrucated(PWLD pWld, PWLDSYM pSym1, const char *pszName2, unsigned cchName2)1281 {1282 /* Truncated string comparision means comparing MIN(cchName2, strlen(pSym1->pszName)) chars. */1283 const char *pszName1 = pSym1->pszName;1284 if (pWld->fFlags & WLDC_CASE_INSENSITIVE)1285 {1286 while (cchName2-- > 0 && *pszName1)1287 {1288 if (toupper(*pszName1) != toupper(*pszName2))1289 return 0;1290 pszName1++;1291 pszName2++;1292 }1293 }1294 else1295 {1296 while (cchName2-- > 0 && *pszName1)1297 {1298 if (*pszName1 != *pszName2)1299 return 0;1300 pszName1++;1301 pszName2++;1302 }1303 }1304 return 1;1305 }1306 1307 1308 1246 1309 1247 /** … … 1341 1279 break; 1342 1280 } 1343 else if ( psz[0] == '!'1344 && psz[1] == '_'1345 && psz - psz > 200)1346 {1347 uHash = strtol(&psz[2], NULL, 16);1348 fFlags |= WLDSF_TRUNCATED;1349 cchName = psz - pszName;1350 break;1351 }1352 1281 1353 1282 pszName = (pWld->fFlags & WLDC_CASE_INSENSITIVE ? strpool_addnu : strpool_addn)(pWld->pStrMisc, pszName, cchName); … … 1516 1445 if (cchName > 200) 1517 1446 break; 1518 }1519 else if ( psz[0] == '!'1520 && psz[1] == '_'1521 && psz - pszName > 200)1522 {1523 uHash = strtol(&psz[2], NULL, 16);1524 fFlags |= WLDSF_TRUNCATED;1525 cchName = psz - pszName;1526 break;1527 1447 } 1528 1448 … … 1681 1601 const char *pszName; /* The symbol name in the string pool */ 1682 1602 int cchNameWeak = 0; /* Indicator and length of the weak name. (0 if not weak) */ 1683 int cchNameTrunc = 0; /* Full length of truncated symbol name. */1684 1603 /* general stuff */ 1685 1604 const char * pach; … … 1708 1627 break; 1709 1628 } 1710 else if ( pach[0] == '!'1711 && pach[1] == '_'1712 && pach - pachName > 200)1713 {1714 uHash = strtol(&pach[2], NULL, 16);1715 fFlags |= WLDSF_TRUNCATED;1716 cchNameTrunc = cchNameWeak ? cchNameWeak : cchName;1717 cchName = pach - pachName;1718 break;1719 }1720 1629 } 1721 1630 pszName = (pWld->fFlags & WLDC_CASE_INSENSITIVE ? strpool_addnu : strpool_addn)(pWld->pStrMisc, pachName, cchName); 1722 if (!(fFlags & WLDSF_TRUNCATED)) 1723 uHash = symHash(pszName, cchName, pWld->fFlags & WLDC_CASE_INSENSITIVE); 1631 uHash = symHash(pszName, cchName, pWld->fFlags & WLDC_CASE_INSENSITIVE); 1724 1632 1725 1633 /* search for existing symbol */ … … 1895 1803 } 1896 1804 } 1897 1898 /*1899 * Maintain list of truncated aliases.1900 */1901 if ( !SYM_IS_DEFINED(fFlags)1902 && ((fFlags & WLDSF_TRUNCATED) || (pSym->fFlags & WLDSF_TRUNCATED)))1903 {1904 PWLDSYMTRUNC pTrunc = pSym->pTrunc;1905 const char *pszSubName = pSym->pszWeakName;1906 if (!pszSubName)1907 pszSubName = strpool_addn(pWld->pStrMisc, pachName, cchNameTrunc);1908 1909 while (pTrunc && pTrunc->pszName != pszSubName)1910 pTrunc = pTrunc->pNext;1911 if (!pTrunc)1912 {1913 pTrunc = xmalloc(sizeof(*pTrunc));1914 pTrunc->pszName = pszSubName;1915 pTrunc->pNext = pSym->pTrunc;1916 pSym->pTrunc = pTrunc;1917 }1918 }1919 1805 } 1920 1806 … … 3440 3326 static int wldGenerateObjEnum(PWLD pWld, PWLDSYM pSym, void *pvUser) 3441 3327 { 3442 const char *pszSubName = pSym->pszWeakName; 3328 #pragma pack(1) 3329 struct omfstuff 3330 { 3331 OMFREC hdr; 3332 union 3333 { 3334 char ach[640]; 3335 OMFLIBHDRX libhdr; 3336 }; 3337 } omf; 3338 #pragma pack() 3443 3339 PWLDGOEPARAM pParam = (PWLDGOEPARAM)pvUser; 3340 int cchAlias; 3444 3341 int cch; 3445 WLDSYMTRUNC Trunc;3446 PWLDSYMTRUNC pTrunc;3447 3342 3448 3343 /* 3449 * If weak, we'll make fake trunc record.3344 * Skip non-weak symbols (a bit of paranoia). 3450 3345 */ 3451 if (pSym->pszWeakName) 3452 { 3453 Trunc.pNext = pSym->pTrunc; 3454 Trunc.pszName = pSym->pszName; 3455 pTrunc = &Trunc; 3456 } 3457 else 3458 { 3459 pTrunc = pSym->pTrunc; 3460 pszSubName = pSym->pszName; 3461 } 3462 cch = strlen(pszSubName); 3346 if ( !pSym->pszWeakName 3347 || pSym->pszName == pSym->pszWeakName) 3348 { 3349 WLDDBG(("not weak: '%s'\n", pSym->pszName)); 3350 return 0; 3351 } 3463 3352 3464 3353 /* 3465 * Walk trunc record list.3354 * Create the alias record. 3466 3355 */ 3467 while (pTrunc) 3468 { 3469 if (pTrunc->pszName != pszSubName) 3470 { 3471 #pragma pack(1) 3472 struct omfstuff 3473 { 3474 OMFREC hdr; 3475 union 3476 { 3477 char ach[640]; 3478 OMFLIBHDRX libhdr; 3479 }; 3480 } omf; 3481 #pragma pack() 3482 int cchAlias = strlen(pTrunc->pszName); 3483 3484 WLDINFO(pWld, ("using weak/trunc %s for %s", pszSubName, pTrunc->pszName)); 3485 3486 /* paranoia */ 3487 if (cchAlias > 255) 3488 { 3489 wldErr(pWld, "Symbol '%s' are too long (%d).", pTrunc->pszName, cchAlias); 3490 return -1; 3491 } 3492 if (cch > 255) 3493 { 3494 wldErr(pWld, "Symbol '%s' are too long (%d).", pszSubName, cch); 3495 return -1; 3496 } 3497 3498 /* end the current object? */ 3499 if ((pWld->fFlags & WLDC_LINKER_LINK386) && pParam->cAliases >= 32) 3500 { 3501 int rc = wldObjEnd(pWld, pParam->phFile, 32); 3502 if (rc) 3503 return rc; 3504 pParam->cAliases = 0; 3505 } 3506 3507 /* make new object ? */ 3508 if (!pParam->cAliases) 3509 { 3510 sprintf(omf.ach, "wk%d.obj", pParam->iLibFile++); 3511 int rc = wldObjStart(pWld, pParam->phFile, omf.ach); 3512 if (rc) 3513 return rc; 3514 } 3515 3516 /* Alias record */ 3517 omf.hdr.chType = ALIAS; 3518 omf.hdr.cb = cchAlias + cch + 3; 3519 omf.ach[0] = cchAlias; 3520 memcpy(&omf.ach[1], pTrunc->pszName, cchAlias); /* alias */ 3521 omf.ach[cchAlias + 1] = cch; 3522 memcpy(&omf.ach[cchAlias + 2], pszSubName, cch); /* subtitute */ 3523 omf.ach[cchAlias + cch + 2] = 0; /* crc */ 3524 if (fwrite(&omf, omf.hdr.cb + sizeof(OMFREC), 1, pParam->phFile) != 1) 3525 { 3526 wldErr(pWld, "Error occured while writing weak/trunc aliases. (2)"); 3527 return -1; 3528 } 3529 pParam->cAliases++; 3530 } 3531 3532 /* next */ 3533 pTrunc = pTrunc->pNext; 3534 } 3356 cchAlias = strlen(pSym->pszName); 3357 cch = strlen(pSym->pszWeakName); 3358 WLDINFO(pWld, ("using weak %s for %s", pSym->pszWeakName, pSym->pszName)); 3359 3360 /* paranoia */ 3361 if (cchAlias > 255) 3362 { 3363 wldErr(pWld, "Symbol '%s' are too long (%d).", pSym->pszName, cchAlias); 3364 return -1; 3365 } 3366 if (cch > 255) 3367 { 3368 wldErr(pWld, "Symbol '%s' are too long (%d).", pSym->pszWeakName, cch); 3369 return -1; 3370 } 3371 3372 /* end the current object? */ 3373 if ((pWld->fFlags & WLDC_LINKER_LINK386) && pParam->cAliases >= 32) 3374 { 3375 int rc = wldObjEnd(pWld, pParam->phFile, 32); 3376 if (rc) 3377 return rc; 3378 pParam->cAliases = 0; 3379 } 3380 3381 /* make new object ? */ 3382 if (!pParam->cAliases) 3383 { 3384 sprintf(omf.ach, "wk%d.obj", pParam->iLibFile++); 3385 int rc = wldObjStart(pWld, pParam->phFile, omf.ach); 3386 if (rc) 3387 return rc; 3388 } 3389 3390 /* Alias record */ 3391 omf.hdr.chType = ALIAS; 3392 omf.hdr.cb = cchAlias + cch + 3; 3393 omf.ach[0] = cchAlias; 3394 memcpy(&omf.ach[1], pSym->pszName, cchAlias); /* alias */ 3395 omf.ach[cchAlias + 1] = cch; 3396 memcpy(&omf.ach[cchAlias + 2], pSym->pszWeakName, cch); /* subtitute */ 3397 omf.ach[cchAlias + cch + 2] = 0; /* crc */ 3398 if (fwrite(&omf, omf.hdr.cb + sizeof(OMFREC), 1, pParam->phFile) != 1) 3399 { 3400 wldErr(pWld, "Error occured while writing weak/trunc aliases. (2)"); 3401 return -1; 3402 } 3403 pParam->cAliases++; 3535 3404 3536 3405 return 0;
Note:
See TracChangeset
for help on using the changeset viewer.