Changeset 511
- Timestamp:
- Aug 2, 2003, 5:57:20 AM (22 years ago)
- Location:
- trunk/src/emx/src/emxomf
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/emx/src/emxomf/emxomfld.c
-
Property cvs2svn:cvs-rev
changed from
1.14
to1.15
r510 r511 456 456 457 457 458 /* finds the full path of a library or object file, after check 459 default extentions an such. 460 458 /* finds the full path of a library or object file, after check 459 default extentions an such. 460 461 461 Object files will be searched for using the LIB env.var if not found. 462 462 463 463 Library hacks: 464 464 1. file with .lib extention. … … 477 477 FILE * phFile; 478 478 char cchname = strlen (pszname); 479 479 480 480 /* Plain name first - the easist option */ 481 481 memcpy (pszfullname, pszname, cchname + 1); … … 501 501 /* Search LIBS. */ 502 502 if (!strpbrk (pszname, ":\\/")) 503 { 503 { 504 504 int ffound; 505 505 const char * pszend; … … 602 602 PWLD pwld; 603 603 604 pwld = wld _create (WLDC_VERBOSE);604 pwld = wldCreate (WLDC_VERBOSE); 605 605 if (pwld) 606 606 { … … 614 614 static const char * objexts[] = { ".obj", ".o", NULL }; 615 615 phfile = find_objlib (szname, pcur->name, objexts, TRUE); 616 rc = wld _add_object (pwld, phfile, szname);616 rc = wldAddObject (pwld, phfile, szname); 617 617 } 618 618 … … 621 621 { 622 622 phfile = fopen (def_fname, "r"); 623 rc = wld _add_deffile (pwld, phfile, def_fname);623 rc = wldAddDefFile (pwld, phfile, def_fname); 624 624 } 625 625 … … 629 629 static const char * libexts[] = { ".lib", ".a", NULL }; 630 630 phfile = find_objlib (szname, pcur->name, libexts, TRUE); 631 rc = wld _add_library (pwld, phfile, szname);631 rc = wldAddLibrary (pwld, phfile, szname); 632 632 free(pcur->name); 633 633 pcur->name = xstrdup(szname); 634 634 } 635 635 636 /* complete pass 1 */ 637 if (!rc) 638 { 639 rc = wldPass1 (pwld); 640 /* ignore unresolved externals for now. */ 641 if (rc == 42) 642 rc = 0; 643 } 644 636 645 /* generate weak aliases. */ 637 646 if (!rc) 638 rc = wld _generate_weakobj (pwld, weakobj_fname);647 rc = wldGenerateWeakobj (pwld, weakobj_fname); 639 648 if (!rc && weakobj_fname[0]) 640 649 add_name_list (&add_obj_fnames, weakobj_fname); 641 650 642 651 /* cleanup the linker */ 643 wld _destroy (pwld);652 wldDestroy (pwld); 644 653 } 645 654 else … … 917 926 make_env (); 918 927 919 /* Do the weak prelinking unless GCC_WEAKSYMS are set. 928 /* Do the weak prelinking unless GCC_WEAKSYMS are set. 920 929 Important that this is done after make_env(). */ 921 930 -
Property cvs2svn:cvs-rev
changed from
-
trunk/src/emx/src/emxomf/weakld.c
-
Property cvs2svn:cvs-rev
changed from
1.5
to1.6
r510 r511 1 /* $Id$ 2 * 1 /* $Id$ */ 2 /** @file 3 3 * Weak Symbol Pre-Linker. 4 4 * … … 55 55 56 56 #ifdef DEBUG 57 58 57 #define SYMDBG(pSym, pszMsg) symDbg(pSym, pszMsg); 58 #define WLDDBG(a) wldDbg a 59 #define WLDDBG2(a) wldDbg a 59 60 #else 60 61 #define SYMDBG(pSym, pszMsg) do {} while (0) 61 #endif 62 #define WLDDBG(a) do {} while (0) 63 #define WLDDBG2(a) do {} while (0) 64 #endif 62 65 63 66 … … 87 90 * Structures and Typedefs * 88 91 *******************************************************************************/ 92 /** @group OMF stuff 93 * @{ */ 94 95 /** OMF record header. */ 96 #pragma pack(1) 97 typedef struct OMFREC 98 { 99 unsigned char chType; 100 unsigned short cb; 101 } OMFREC, *POMFREC; 102 #pragma pack() 103 104 105 /** OMF library header. */ 106 #pragma pack(1) 107 typedef struct OMFLIBHDR 108 { 109 unsigned char chType; 110 unsigned short cb; 111 unsigned long offDict; 112 unsigned short cDictBlocks; 113 unsigned char fchFlags; 114 } OMFLIBHDR, *POMFLIBHDR; 115 #pragma pack() 116 /** @} */ 117 118 89 119 /** 90 120 * Library structure … … 96 126 /** Filehandle if open */ 97 127 FILE * phFile; 128 /** Pointer to extended dictiorary. */ 129 void * pDict; 130 /** Library header. */ 131 OMFLIBHDR LibHdr; 98 132 /** Linked list next pointer. */ 99 133 struct wldlib * pNext; … … 289 323 290 324 /** Linked list (FIFO) of libraries to be searched in the link. */ 291 PWLD MODpLibs;292 PWLD MOD* ppLibsAdd;325 PWLDLIB pLibs; 326 PWLDLIB * ppLibsAdd; 293 327 294 328 /** string pool for miscellaneous string. */ … … 301 335 302 336 303 /** @group OMF stuff304 * @{ */305 306 /** OMF record header. */307 #pragma pack(1)308 typedef struct OMFREC309 {310 unsigned char chType;311 unsigned short cb;312 } OMFREC, *POMFREC;313 #pragma pack()314 315 316 /** OMF library header. */317 #pragma pack(1)318 typedef struct OMFLIBHDR319 {320 unsigned char chType;321 unsigned short cb;322 unsigned long offDict;323 unsigned short cDictBlocks;324 unsigned char fchFlags;325 } OMFLIBHDR, *POMFLIBHDR;326 #pragma pack()327 328 /** @} */329 337 330 338 … … 332 340 extern void *xmalloc (size_t n); 333 341 342 /** @group Weak LD - Linker Methods (Private) 343 * @{ */ 344 static void wldDbg(const char *pszFormat, ...); 334 345 static void wldInfo(const char *pszFormat, ...); 335 346 static int wldErr(PWLD pWld, const char *pszFormat, ...); 336 347 static void wldIntErr(PWLD pWld, PWLDMOD pMod, const char *pszFile, unsigned iLine, const char *pszFunction); 348 static unsigned pass1ReadOMFMod(PWLD pWld, PWLDMOD pMod, int fLibSearch); 349 /** @} */ 350 351 /** @group Weak LD - Library Methods (Private) 352 * @{ */ 353 static FILE * libOpen(PWLDLIB pLib); 354 static void libClose(PWLDLIB pLib); 355 static int libLoadDict(PWLDLIB pLib); 356 static void libCloseDict(PWLDLIB pLib); 357 static int libTryLoadSymbolThruDictionary(PWLD pWld, PWLDLIB pLib, PWLDSYM pSym, unsigned *pcLoaded); 358 static int libLoadUndefSymbols(PWLD pWld, PWLDLIB pLib, PWLDSYM pSym, unsigned *pcLoaded); 359 static int libErr(PWLDLIB pLib, const char *pszFormat, ...); 360 static void libWarn(PWLDLIB pLib, const char *pszFormat, ...); 361 /** @} */ 362 363 /** @group Weak LD - Module Methods (Private) 364 * @{ */ 365 static FILE * modOpen(PWLDMOD pMod); 366 static void modClose(PWLDMOD pMod); 337 367 static int modErr(PWLDMOD pMod, const char *pszFormat, ...); 338 368 static void modWarn(PWLDMOD pMod, const char *pszFormat, ...); 339 static FILE * modOpen(PWLDMOD pMod); 340 static void modClose(PWLDMOD pMod); 341 342 static inline unsigned hash(const char* pszSym, unsigned cch); 369 /** @} */ 370 371 /** @group Weak LD - Symbole Methods (Private) 372 * @{ */ 373 typedef int (*PFNSYMENUM)(PWLD pWld, PWLDSYM pSym, void *pvUser); 374 static int symHaveUndefined(PWLD pWld); 375 static int symEnum(PWLD pWld, PWLDSYMTAB pSymTab, unsigned fFlags, unsigned fMask, PFNSYMENUM pfnEnum, void *pvUser); 376 static int symPrintUnDefEnum(PWLD pWld, PWLDSYM pSym, void *pvUser); 377 static int symMatchUnDef(PWLD pWld, const unsigned char *pachPascalString, PWLDSYM pSym); 378 /** Pointed to by the pvUser parameter of symSearchLibEnum(). */ 379 typedef struct symSearchLibEnum_param 380 { 381 /** Set if there are more undefined symbols. */ 382 int fMore; 383 /** Library to search for symbols in. */ 384 PWLDLIB pLib; 385 /** Number modules which was loaded. */ 386 unsigned cLoaded; 387 } WLDSLEPARAM, *PWLDSLEPARAM; 388 static int symSearchLibEnum(PWLD pWld, PWLDSYM pSym, void *pvUser); 389 static inline unsigned symHash(const char* pszSym, unsigned cch); 343 390 static void symDbg(PWLDSYM pSym, const char *pszMsg); 391 static PWLDSYM symAdd(PWLD pWld, PWLDMOD pMod, unsigned fFlags, const char *pachName, int cchName, PWLDSYMACTION peAction); 392 static PWLDSYM symAddImport(PWLD pWld, PWLDMOD pMod, int fLibSearch, 393 const char *pachIntName, int cchIntName, 394 const char *pachModName, int cchModName, 395 unsigned uOrdinal); 396 static PWLDSYM symAddExport(PWLD pWld, PWLDMOD pMod, int fLibSearch, 397 unsigned fExport, 398 unsigned cExpWords, 399 const char *pachExpName, int cchExpName, 400 const char *pachIntName, int cchIntName, 401 unsigned uOrdinal); 402 static PWLDSYM symAddPublic(PWLD pWld, PWLDMOD pMod, int fLibSearch, 403 const char *pachName, int cchName, 404 unsigned long ulValue, int iSegment, int iGroup); 405 static PWLDSYM symAddUnDef(PWLD pWld, PWLDMOD pMod, int fLibSearch, 406 const char *pachName, int cchName); 407 static PWLDSYM symAddAlias(PWLD pWld, PWLDMOD pMod, int fLibSearch, 408 const char *pachAliasName, int cchAliasName, 409 const char *pachName, int cchName); 410 static PWLDSYM symAddComdef(PWLD pWld, PWLDMOD pMod, int fLibSearch, 411 const char *pachName, int cchName, 412 signed long cElements, signed long cbElement); 413 /** @} */ 344 414 345 415 … … 352 422 *******************************************************************************/ 353 423 354 355 /** 356 * Put out a infomessage.424 #ifdef DEBUG 425 /** 426 * Put out a debug message. 357 427 * @param pszFormat Format string. 358 428 * @param ... Format arguments. 359 429 */ 360 static void wld Info(const char *pszFormat, ...)430 static void wldDbg(const char *pszFormat, ...) 361 431 { 362 432 va_list args; 363 fprintf(stderr, "weakld: info: ");433 fprintf(stderr, "weakld: dbg: "); 364 434 365 435 va_start(args, pszFormat); … … 369 439 fputc('\n', stderr); 370 440 } 441 #endif 371 442 372 443 /** … … 375 446 * @param ... Format arguments. 376 447 */ 448 static void wldInfo(const char *pszFormat, ...) 449 { 450 va_list args; 451 fprintf(stderr, "weakld: info: "); 452 453 va_start(args, pszFormat); 454 vfprintf(stderr, pszFormat, args); 455 va_end(args); 456 if (pszFormat[strlen(pszFormat) - 1] != '\n') 457 fputc('\n', stderr); 458 } 459 460 /** 461 * Put out a info message. 462 * @param pszFormat Format string. 463 * @param ... Format arguments. 464 */ 377 465 static int wldErr(PWLD pWld, const char *pszFormat, ...) 378 466 { 379 467 va_list args; 380 468 fprintf(stderr, "weakld: error: "); 381 469 382 470 va_start(args, pszFormat); 383 471 vfprintf(stderr, pszFormat, args); … … 415 503 416 504 417 /** 418 * Report error in module. 419 * @param pMod Pointer to module to report error on. 420 * @param pszFormat Format string. 421 * @param ... Format arguments. 422 */ 423 static int modErr(PWLDMOD pMod, const char *pszFormat, ...) 505 506 507 508 509 510 511 512 /** 513 * Open this library file. 514 * 515 * @returns Pointer to open file stream. 516 * @returns NULL on failure. 517 * @param pLib Library to open. 518 */ 519 static FILE * libOpen(PWLDLIB pLib) 520 { 521 if (!pLib->phFile) 522 { 523 pLib->phFile = fopen(pLib->pszLibName, "rb"); 524 if (pLib->phFile) 525 libErr(pLib, "Failed to open library."); 526 } 527 return pLib->phFile; 528 } 529 530 /** 531 * Close this library file. 532 * @param pLib Library to close. 533 */ 534 static void libClose(PWLDLIB pLib) 535 { 536 if (!pLib->phFile) 537 { 538 fclose(pLib->phFile); 539 pLib->phFile = NULL; 540 } 541 } 542 543 /** 544 * Load the dictionar for this library into memory. 545 * 546 * @returns 0 if we successfully loaded the dictionary. 547 * @returns -1 if we fail to read the dictionary into memory. 548 * @returns 1 if there is no dictionary. 549 * @param pLib Library which dictionary is to be loaded. 550 * @remark This method will open the library. libClose() must be 551 * called after this function is used. 552 */ 553 static int libLoadDict(PWLDLIB pLib) 554 { 555 FILE *phFile; 556 557 /* been here, done that? */ 558 if (pLib->pDict) 559 return 0; 560 561 /* check if it acutally is a library and have an ext dict */ 562 if ( pLib->LibHdr.chType != LIBHDR 563 || pLib->LibHdr.offDict != 0 564 || pLib->LibHdr.cDictBlocks != 0) 565 return 1; 566 567 /* ensure it's open. */ 568 phFile = libOpen(pLib); 569 if (!phFile) 570 return -1; 571 572 /* position us */ 573 if (fseek(phFile, pLib->LibHdr.offDict, SEEK_SET)) 574 return libErr(pLib, "Failed to seek to extended dictionary (offset %d).", pLib->LibHdr.offDict); 575 576 /* read it */ 577 pLib->pDict = xmalloc(pLib->LibHdr.cDictBlocks * 512); 578 if (fread(pLib->pDict, 512, pLib->LibHdr.cDictBlocks, phFile) == pLib->LibHdr.cDictBlocks) 579 return 0; 580 libErr(pLib, "Failed to read extended dictionary."); 581 free(pLib->pDict); 582 pLib->pDict = NULL; 583 return -1; 584 } 585 586 /** 587 * This closes the extended dictionary. 588 * 589 * @param pLib Library which extended dictionary should be closed. 590 * @remark Will not close the library file, libClose() must be used for that. 591 */ 592 static void libCloseDict(PWLDLIB pLib) 593 { 594 if (pLib->pDict) 595 { 596 free(pLib->pDict); 597 pLib->pDict = NULL; 598 } 599 } 600 601 602 /** 603 * Does a dictionary lookup on an undefined name. 604 * 605 * @returns 0 on non failure. 606 * @returns 42 if not found. 607 * @returns -1 on link abort error. 608 * @param pWld Linker instance. 609 * @param pLib Library to search. 610 * @param pSym Undefined symbol to search for. 611 * @param pcLoaded Number of modules which was loaded from this library. 612 */ 613 static int libTryLoadSymbolThruDictionary(PWLD pWld, PWLDLIB pLib, PWLDSYM pSym, unsigned *pcLoaded) 614 { 615 //return 42; 616 return libLoadUndefSymbols(pWld, pLib, pSym, pcLoaded); /* @todo implement this function! */ 617 } 618 619 620 /** 621 * Read thru an module looking for definitions for undef symbols. 622 * If a definition is found we'll load the module containing it. 623 * 624 * @returns 0 on non failure. 625 * @returns 42 if none found. 626 * @returns -1 on link abort error. 627 * @param pWld Linker instance. 628 * @param pLib Library to search. 629 * @param pSym Undefined symbol to search for. 630 * If NULL we'll try and see if any defined global symbol we 631 * encounter is undefined. 632 * @param pcLoaded Number of modules which was loaded from this library. 633 */ 634 static int libLoadUndefSymbols(PWLD pWld, PWLDLIB pLib, PWLDSYM pSym, unsigned *pcLoaded) 635 { 636 FILE * phFile = pLib->phFile; 637 unsigned char uchEnd1, uchEnd2; 638 OMFREC OmfRec; 639 off_t offCurMod; 640 int fSkipRestOfModule = 0; 641 /* generic stuff */ 642 unsigned long ul; 643 signed long l2, l3; 644 unsigned short us, us2, us3; 645 unsigned char uch, uch2; 646 647 648 /* Position the library at the first module record. */ 649 if (fseek(phFile, pLib->LibHdr.chType == LIBHDR ? pLib->LibHdr.cb + 3 : 0, SEEK_SET)) 650 return libErr(pLib, "Error when seeking to first module."); 651 652 if (pLib->LibHdr.chType != LIBHDR) 653 { 654 uchEnd1 = MODEND; 655 uchEnd2 = MODEND | REC32; 656 } 657 else 658 uchEnd1 = uchEnd2 = LIBEND; 659 660 OmfRec.chType = uchEnd1; 661 fread(&OmfRec, sizeof(OmfRec), 1, phFile); 662 while (OmfRec.chType != uchEnd1 && OmfRec.chType != uchEnd2) 663 { 664 int fRead = 0; 665 int fLoad = 0; 666 switch (OmfRec.chType) 667 { 668 case THEADR: 669 fSkipRestOfModule = 0; 670 offCurMod = ftell(phFile) - sizeof(OmfRec); 671 break; 672 673 /* read */ 674 case PUBDEF: case PUBDEF | REC32: 675 case ALIAS: case ALIAS | REC32: 676 case COMDEF: case COMDEF | REC32: 677 case COMDAT: case COMDAT | REC32: 678 case COMENT: case COMENT | REC32: 679 fRead = !fSkipRestOfModule; 680 break; 681 } 682 683 if (fRead) 684 { 685 unsigned char achBuffer[OMF_MAX_REC + 8]; 686 union 687 { 688 unsigned char * puch; 689 signed char * pch; 690 unsigned short * pus; 691 signed short * ps; 692 unsigned long * pul; 693 signed long * pl; 694 void * pv; 695 } u, u1, u2; 696 697 /** macro for getting a OMF index out of the buffer */ 698 #define OMF_GETINDEX() (*u.puch & 0x80 ? ((*u.pch++ & 0x7f) << 8) + *u.pch++ : *u.pch++) 699 #define OMF_BYTE() (*u.puch++) 700 #define OMF_WORD() (*u.pus++) 701 #define OMF_24BITWORD() (OMF_BYTE() | (OMF_WORD() << 8)) 702 #define OMF_DWORD() (*u.pul++) 703 #define OMF_MORE() (u.puch - &achBuffer[0] < (int)OmfRec.cb - 1 && !fLoad) /* (different from the next) */ 704 #define OMF_IS32BIT() ((OmfRec.chType & REC32) != 0) 705 #define OMF_GETTYPELEN(l) \ 706 do \ 707 { \ 708 l = OMF_BYTE(); \ 709 if (l > 128) \ 710 switch (l) \ 711 { \ 712 case 0x81: l = OMF_WORD(); break; \ 713 case 0x84: l = OMF_24BITWORD(); break; \ 714 case 0x88: l = OMF_DWORD(); break; \ 715 default: \ 716 libErr(pLib, "Invalid type length!");/* (different from the next) */ \ 717 return -1; \ 718 } \ 719 } while (0) 720 721 u.pv = &achBuffer[0]; 722 723 /* read it */ 724 if (fread(achBuffer, OmfRec.cb, 1, phFile) != 1) 725 { 726 libErr(pLib, "Read error. (2)"); 727 break; 728 } 729 730 /* extract public symbols. */ 731 switch (OmfRec.chType) 732 { 733 case COMENT: case COMENT | REC32: 734 switch (*++u.pch) 735 { 736 case CLASS_PASS: 737 fSkipRestOfModule = 1; 738 break; 739 case CLASS_OMFEXT: 740 { 741 switch (OMF_BYTE()) 742 { /* 743 * Import definition. 744 */ 745 case OMFEXT_IMPDEF: 746 { 747 uch = OMF_BYTE(); /* flags */ 748 u1 = u; u.pch += 1 + *u.puch; /* internal name */ 749 u2 = u; u.pch += 1 + *u.puch; /* module name */ 750 ul = 0; /* ordinal */ 751 if (uch & 1) 752 ul = OMF_WORD(); 753 if (symMatchUnDef(pWld, u1.pch, pSym)) 754 fLoad = 1; 755 break; 756 } 757 } 758 } 759 } /* comment class */ 760 break; 761 762 case PUBDEF: case PUBDEF | REC32: 763 { 764 us2 = OMF_GETINDEX(); /* group index */ 765 us3 = OMF_GETINDEX(); /* segment index */ 766 if (!us3) 767 us = OMF_WORD(); /* base frame - ignored */ 768 while (OMF_MORE()) 769 { 770 u1 = u; u.pch += 1 + *u.puch; /* public name */ 771 ul = OMF_IS32BIT() ? OMF_DWORD() : OMF_WORD(); 772 us = OMF_GETINDEX(); /* typeindex */ 773 if (symMatchUnDef(pWld, u1.pch, pSym)) 774 fLoad = 1; 775 } 776 break; 777 } 778 779 case ALIAS: case ALIAS | REC32: 780 { 781 while (OMF_MORE()) 782 { 783 u1 = u; u.pch += 1 + *u.puch; /* alias name */ 784 u2 = u; u.pch += 1 + *u.puch; /* substitutt name. */ 785 if (symMatchUnDef(pWld, u1.pch, pSym)) 786 fLoad = 1; 787 } 788 break; 789 } 790 791 case COMDEF: case COMDEF | REC32: 792 { 793 while (OMF_MORE()) 794 { 795 u1 = u; u.pch += 1 + *u.puch; /* communal name (specs say 1-2 length...) */ 796 us2 = OMF_GETINDEX(); /* typeindex */ 797 uch2 = OMF_BYTE(); /* date type */ 798 switch (uch2) 799 { 800 case COMDEF_TYPEFAR: 801 OMF_GETTYPELEN(l2); /* number of elements */ 802 OMF_GETTYPELEN(l3); /* element size */ 803 break; 804 case COMDEF_TYPENEAR: 805 l2 = 1; /* number of elements */ 806 OMF_GETTYPELEN(l3); /* element size */ 807 break; 808 default: 809 libErr(pLib, "Invalid COMDEF type %x.", (int)uch2); 810 return -1; 811 } 812 if (symMatchUnDef(pWld, u1.pch, pSym)) 813 fLoad = 1; 814 } 815 break; 816 } 817 818 case COMDAT: case COMDAT | REC32: 819 { 820 /* @todo */ 821 break; 822 } 823 } /* switch */ 824 825 #undef OMF_GETINDEX 826 #undef OMF_BYTE 827 #undef OMF_WORD 828 #undef OMF_24BITWORD 829 #undef OMF_DWORD 830 #undef OMF_MORE 831 #undef OMF_IS32BIT 832 #undef OMF_GETTYPELEN 833 834 /* 835 * Shall we load this module? 836 */ 837 if (fLoad) 838 { 839 off_t offSave = ftell(phFile); 840 PWLDMOD pMod; 841 int rc; 842 843 pMod = xmalloc(sizeof(*pMod)); 844 memset(pMod, 0, sizeof(*pMod)); 845 pMod->off = offCurMod; 846 pMod->pLib = pLib; 847 pMod->phFile = phFile; 848 *pWld->ppObjsAdd = pMod; 849 pWld->ppObjsAdd = &pMod->pNext; 850 851 rc = pass1ReadOMFMod(pWld, pMod, 0); 852 if (rc) 853 { 854 libErr(pLib, "Failed when reading module at offset %x.", offCurMod); 855 return rc; 856 } 857 858 /* if one symbol, we're done now */ 859 if (pSym) 860 return 0; 861 862 /* Resume searching, but skip the rest of this one */ 863 fSkipRestOfModule = 1; 864 fseek(phFile, offSave, SEEK_SET); 865 } 866 } 867 else 868 { 869 off_t offSkip = OmfRec.cb; 870 /* Skip to next record. */ 871 if (OmfRec.chType == MODEND || OmfRec.chType == (MODEND | REC32)) 872 { 873 unsigned cbPage = pLib->LibHdr.cb + 3; 874 off_t off = ftell(phFile) + offSkip; 875 off -= cbPage * (off / cbPage); /* don't trust this to be 2**n. */ 876 if (off) 877 offSkip += cbPage - off; 878 } 879 if (fseek(phFile, offSkip, SEEK_CUR)) 880 { 881 libErr(pLib, "Seek error."); 882 break; 883 } 884 } 885 886 /* next header */ 887 if (fread(&OmfRec, sizeof(OmfRec), 1, phFile) != 1) 888 { 889 libErr(pLib, "Read error."); 890 break; 891 } 892 } 893 894 895 return 42; 896 } 897 898 899 /** 900 * Put out an error for this library. 901 * @param pLib Library which the warning occured in. 902 * @param pszFormat Message format. 903 * @param ... Format args. 904 */ 905 static int libErr(PWLDLIB pLib, const char *pszFormat, ...) 424 906 { 425 907 va_list args; 426 if (pMod->pLib) 427 fprintf(stderr, "weakld: %s(%s) - error: ", pMod->pLib->pszLibName, pMod->pszModName); 428 else 429 fprintf(stderr, "weakld: %s - error: ", pMod->pszModName); 908 fprintf(stderr, "weakld: %s: error: ", pLib->pszLibName); 430 909 431 910 va_start(args, pszFormat); … … 437 916 } 438 917 439 440 /** 441 * Report warning in module. 442 * @param pMod Pointer to module to report warning on. 443 * @param pszFormat Format string. 444 * @param ... Format arguments. 445 */ 446 static void modWarn(PWLDMOD pMod, const char *pszFormat, ...) 918 /** 919 * Put out a warning for this library. 920 * @param pLib Library which the warning occured in. 921 * @param pszFormat Message format. 922 * @param ... Format args. 923 */ 924 static void libWarn(PWLDLIB pLib, const char *pszFormat, ...) 447 925 { 448 926 va_list args; 449 if (pMod->pLib) 450 fprintf(stderr, "weakld: %s(%s) - warning: ", pMod->pLib->pszLibName, pMod->pszModName); 451 else 452 fprintf(stderr, "weakld: %s - warning: ", pMod->pszModName); 927 fprintf(stderr, "weakld: %s: warning: ", pLib->pszLibName); 453 928 454 929 va_start(args, pszFormat); … … 458 933 fputc('\n', stderr); 459 934 } 935 936 937 938 939 940 941 942 943 460 944 461 945 … … 507 991 } 508 992 509 510 993 /** 511 994 * Closes the module. … … 522 1005 } 523 1006 524 525 typedef int (*PFNSYMENUM)(PWLD pWld, PWLDSYM pSym, void *pvUser); 1007 /** 1008 * Report error in module. 1009 * @param pMod Pointer to module to report error on. 1010 * @param pszFormat Format string. 1011 * @param ... Format arguments. 1012 */ 1013 static int modErr(PWLDMOD pMod, const char *pszFormat, ...) 1014 { 1015 va_list args; 1016 if (pMod->pLib) 1017 fprintf(stderr, "weakld: %s(%s) - error: ", pMod->pLib->pszLibName, pMod->pszModName); 1018 else 1019 fprintf(stderr, "weakld: %s - error: ", pMod->pszModName); 1020 1021 va_start(args, pszFormat); 1022 vfprintf(stderr, pszFormat, args); 1023 va_end(args); 1024 if (pszFormat[strlen(pszFormat) - 1] != '\n') 1025 fputc('\n', stderr); 1026 return -1; 1027 } 1028 1029 /** 1030 * Report warning in module. 1031 * @param pMod Pointer to module to report warning on. 1032 * @param pszFormat Format string. 1033 * @param ... Format arguments. 1034 */ 1035 static void modWarn(PWLDMOD pMod, const char *pszFormat, ...) 1036 { 1037 va_list args; 1038 if (pMod->pLib) 1039 fprintf(stderr, "weakld: %s(%s) - warning: ", pMod->pLib->pszLibName, pMod->pszModName); 1040 else 1041 fprintf(stderr, "weakld: %s - warning: ", pMod->pszModName); 1042 1043 va_start(args, pszFormat); 1044 vfprintf(stderr, pszFormat, args); 1045 va_end(args); 1046 if (pszFormat[strlen(pszFormat) - 1] != '\n') 1047 fputc('\n', stderr); 1048 } 1049 1050 1051 526 1052 527 1053 /** … … 548 1074 if ((pSym->fFlags & fMask) == fFlags) 549 1075 { 550 rc = pfnEnum(pWld, pSym, pvUser); 1076 rc = pfnEnum(pWld, pSym, pvUser); 551 1077 if (rc) 552 1078 return rc; … … 557 1083 return 0; 558 1084 } 1085 1086 1087 /** 1088 * Worker for wldHaveUndefined(). 1089 * @returns 42 and halts the search. 1090 * @param pWld Linker instance. 1091 * @param pSym Symbol. 1092 * @param pvUser Pointer to a FILE stream. 1093 */ 1094 static int symHaveUndefinedEnum(PWLD pWld, PWLDSYM pSym, void *pvUser) 1095 { 1096 return 42; 1097 } 1098 1099 /** 1100 * Checks if there is unresovled symbols in the link. 1101 * 1102 * @returns 1 if there is undefined symbols 1103 * @returns 0 if all symbols are defined. 1104 * @param pWld Linker instance. 1105 */ 1106 static int symHaveUndefined(PWLD pWld) 1107 { 1108 return symEnum(pWld, &pWld->Global, WLDSF_UNDEF, WLDSF_TYPEMASK | WLDSF_WEAK, symHaveUndefinedEnum, NULL) == 42; 1109 } 1110 1111 1112 /** 1113 * Enumerates the current undefined externals and try to resolve 1114 * them using the current library passed in the pvUser structure. 1115 * @returns 1116 * @param pWld Linker instance. 1117 * @param pSym Undefined symbol. 1118 * @param pvUser Pointer to a WLDSLEPARAM structure. 1119 * fMore will be set 1120 */ 1121 static int symSearchLibEnum(PWLD pWld, PWLDSYM pSym, void *pvUser) 1122 { 1123 int rc; 1124 unsigned cLoaded = 0; 1125 PWLDSLEPARAM pParam = (PWLDSLEPARAM)pvUser; 1126 1127 SYMDBG(pSym, "Searching for"); 1128 1129 /* 1130 * If we have a dictionary, we'll us it. 1131 */ 1132 if (pParam->pLib->pDict) 1133 rc = libTryLoadSymbolThruDictionary(pWld, pParam->pLib, pSym, &cLoaded); 1134 else 1135 rc = libLoadUndefSymbols(pWld, pParam->pLib, pSym, &cLoaded); 1136 1137 /* Housekeeping. */ 1138 pParam->cLoaded += cLoaded; 1139 if (rc == 42) /* more undef from the load. */ 1140 { 1141 pParam->fMore = 1; 1142 rc = 0; 1143 } 1144 1145 return rc; 1146 } 1147 1148 /** 1149 * Worker for enumerating unresolved symbols. 1150 * 1151 * @returns 0 1152 * @param pWld Linker instance. 1153 * @param pSym Undefined symbol. 1154 * @param pvUser NULL 1155 */ 1156 static int symPrintUnDefEnum(PWLD pWld, PWLDSYM pSym, void *pvUser) 1157 { 1158 PWLDMOD pMod = pSym->pMod; 1159 1160 if (pMod) 1161 modErr(pMod, "Unresolved symbol '%s'.", pSym->pszName); 1162 else 1163 wldErr(pWld, "Unresolved symbol '%s'.", pSym->pszName); 1164 return 0; 1165 } 1166 1167 /** 1168 * Prints unresolved symbols. 1169 * 1170 * @param pWld Linker instance. 1171 */ 1172 static void symPrintUnDefs(PWLD pWld) 1173 { 1174 symEnum(pWld, &pWld->Global, WLDSF_UNDEF, WLDSF_TYPEMASK | WLDSF_WEAK, symPrintUnDefEnum, NULL); 1175 } 1176 1177 /** 1178 * Checks the OMF encoded name with the specified undefined 1179 * symbol, or all undefined symbols. 1180 * 1181 * @returns 1 if symbol matches. 1182 * @returns 0 if symbol mis-matches. 1183 * @param pWld Linker instance. 1184 * @param pachPascalString OMF encoded string. 1185 * @param pSym If NULL match all, if !NULL match this. 1186 */ 1187 static int symMatchUnDef(PWLD pWld, const unsigned char *pachPascalString, PWLDSYM pSym) 1188 { 1189 int cch = *pachPascalString; 1190 const char *psz = pachPascalString + 1; 1191 int (*pfn)(const char *, const char *, size_t) = (pWld->fFlags & WLDC_CASE_INSENSITIVE) ? strnicmp : strncmp; 1192 1193 if (pSym) 1194 return !pfn(pSym->pszName, psz, cch) && !pSym->pszName[cch]; 1195 else 1196 { 1197 #if 1 /* hashed */ 1198 unsigned uHash = symHash(psz, cch); 1199 for (pSym = pWld->Global.ap[uHash]; pSym; pSym = pSym->pHashNext) 1200 { 1201 if ((pSym->fFlags & (WLDSF_TYPEMASK | WLDSF_WEAK)) == WLDSF_UNDEF) 1202 { 1203 if (!pfn(pSym->pszName, psz, cch) && !pSym->pszName[cch]) 1204 return 1; 1205 } 1206 } 1207 #else 1208 /* raw */ 1209 int i; 1210 for (i = 0; i < sizeof(pWld->Global.ap) / sizeof(pWld->Global.ap[0]); i++) 1211 { 1212 for (pSym = pWld->Global.ap[i]; pSym; pSym = pSym->pHashNext); 1213 { 1214 if ((pSym->fFlags & (WLDSF_TYPEMASK | WLDSF_WEAK)) == WLDSF_UNDEF) 1215 { 1216 if (!pfn(pSym->pszName, psz, cch) && !pSym->pszName[cch]) 1217 return 1; 1218 } 1219 } 1220 } 1221 #endif 1222 } 1223 return 0; 1224 } 1225 1226 1227 1228 1229 559 1230 560 1231 … … 596 1267 fprintf(stderr, "\n"); 597 1268 } 598 #endif 1269 #endif 599 1270 600 1271 … … 604 1275 * @param pszSym Symbol to calculate it for. 605 1276 * @param cch Symbol length. 606 */ 607 static inline unsigned hash(const char* pszSym, unsigned cch) 1277 * @todo This ain't respecting case sensitivity. 1278 */ 1279 static inline unsigned symHash(const char* pszSym, unsigned cch) 608 1280 { 609 1281 unsigned uHash = 0; 610 while (cch && *pszSym && *pszSym != '$') 1282 while ( cch 1283 && (pszSym[0] != '$' || pszSym[1] != 'w' || pszSym[2] != '$') 1284 ) 611 1285 { 612 1286 uHash = uHash * 65599 + *pszSym; … … 625 1299 * 626 1300 * We'll simply return existing symbol when: 627 * 1. adding a UNDEF where a PUBLIC or COMM exists.1301 * 1. adding a UNDEF where a PUBLIC or COMM or !WEAK UNDEF exists. 628 1302 * 2. adding a WKEXT where a PUBLIC or COMM exists. 629 1303 * 3. adding a WKEXT where a UNDEF which isn't UNCERTAIN exists. 630 * 4. adding a COMM where a !WEAK COMM exists. 1304 * 4. adding a COMM where a !WEAK COMM exists. 631 1305 * 5. adding a WEAK PUBLIC or WEAK COMM where a PUBLIC or COMM exists. 632 1306 * … … 693 1367 break; 694 1368 } 695 uHash = hash(pachName, cchName);696 1369 pszName = (pWld->fFlags & WLDC_CASE_INSENSITIVE ? strpool_addnu : strpool_addn)(pWld->pStrMisc, pachName, cchName); 1370 uHash = symHash(pszName, cchName); 697 1371 698 1372 /* search for existing symbol */ … … 721 1395 pWld->Global.ap[uHash] = pSym; 722 1396 if (peAction) *peAction = WLDSA_NEW; 1397 WLDDBG2(("symAdd: New symbol '%s'", pSym->pszName)); 723 1398 } 724 1399 else … … 730 1405 * 2. adding a WKEXT where a PUBLIC or COMM exists. 731 1406 * 3. adding a WKEXT where a UNDEF which isn't UNCERTAIN exists. 732 * 4. adding a COMM where a !WEAK COMM exists. 1407 * 4. adding a COMM where a !WEAK COMM exists. 733 1408 * 5. adding a WEAK PUBLIC or WEAK COMM where a PUBLIC or COMM exists. 734 1409 */ 735 1410 if ( ( /* 1 */ 736 1411 (fFlags & WLDSF_TYPEMASK) == WLDSF_UNDEF 737 && ((pSym->fFlags & WLDSF_TYPEMASK) == WLDSF_PUBLIC || (pSym->fFlags & WLDSF_TYPEMASK) == WLDSF_COMM) 1412 && ((pSym->fFlags & WLDSF_TYPEMASK) == WLDSF_PUBLIC || (pSym->fFlags & WLDSF_TYPEMASK) == WLDSF_COMM 1413 || (pSym->fFlags & (WLDSF_TYPEMASK | WLDSF_WEAK)) == WLDSF_UNDEF) 738 1414 ) || ( /* 2 */ 739 1415 (fFlags & WLDSF_TYPEMASK) == WLDSF_WKEXT … … 751 1427 { 752 1428 if (peAction) *peAction = WLDSA_OLD; 1429 WLDDBG2(("symAdd: Old symbol '%s'", pSym->pszName)); 753 1430 } 754 1431 /* … … 763 1440 modWarn(pMod, "Ignoring import '%s' as it's defined already.", pszName); 764 1441 if (peAction) *peAction = WLDSA_OLD; 1442 WLDDBG2(("symAdd: Old symbol '%s'", pSym->pszName)); 765 1443 } 766 1444 /* … … 792 1470 pSym->fFlags = (pSym->fFlags & ~(WLDSF_TYPEMASK | WLDSF_WEAK | WLDSF_UNCERTAIN | WLDSF_LIBSEARCH)) | fFlags; 793 1471 if (peAction) *peAction = WLDSA_UP; 1472 WLDDBG2(("symAdd: Upgraded symbol '%s'", pSym->pszName)); 794 1473 } 795 1474 /* … … 811 1490 if (peAction) *peAction = WLDSA_UP; 812 1491 memset(&pSym->u, 0, sizeof(pSym->u)); 1492 WLDDBG2(("symAdd: Upgraded symbol '%s'", pSym->pszName)); 813 1493 } 814 1494 /* … … 820 1500 else 821 1501 { 822 modErr(pMod, "Duplicate symbol '%s' .",pszName);1502 modErr(pMod, "Duplicate symbol '%s' ('%s').", pszName, pSym->pszName); 823 1503 if (pSym->pMod) 824 1504 modErr(pSym->pMod, "Previous symbol defined in this module."); … … 1131 1811 if (!pSym) 1132 1812 return NULL; 1133 1813 1134 1814 cbElement *= (cElements > 0 ? cElements : 1); /* make it a size */ 1135 1815 switch (eAction) … … 1153 1833 WLDINTERR(pWld, pMod); 1154 1834 } 1155 1835 1156 1836 return pSym; 1157 1837 } … … 1185 1865 int i; 1186 1866 unsigned long ul; 1187 signed long l , l2, l3;1867 signed long l2, l3; 1188 1868 unsigned short us, us2, us3; 1189 unsigned char uch, uch2, uch3; 1190 1869 unsigned char uch, uch2; 1870 1871 /* We're counting indexes from 1, so add dummy zero entry. */ 1872 papExts = xmalloc(sizeof(papExts[0])*64); 1873 papExts[0] = NULL; 1874 cExts = 1; 1191 1875 1192 1876 … … 1208 1892 void * pv; 1209 1893 } u, u1, u2, u3; 1210 1894 1211 1895 /** macro for getting a OMF index out of the buffer */ 1212 1896 #define OMF_GETINDEX() (*u.puch & 0x80 ? ((*u.pch++ & 0x7f) << 8) + *u.pch++ : *u.pch++) … … 1233 1917 } while (0) 1234 1918 1235 1236 1919 u.pv = &achBuffer[0]; 1237 1920 … … 1267 1950 case COMDAT: case COMDAT | REC32: 1268 1951 case COMENT: case COMENT | REC32: 1952 case THEADR: case THEADR | REC32: 1269 1953 case LIBHDR: 1270 1954 break; … … 1283 1967 switch (OmfRec.chType) 1284 1968 { 1969 case THEADR: 1970 { 1971 if (!pMod->pszModName) 1972 { 1973 pMod->pszModName = strpool_addn(pWld->pStrMisc, u.pch + 1, *u.puch); 1974 WLDINFO(pWld, ("%s", pMod->pszModName)); 1975 } 1976 break; 1977 } 1978 1285 1979 case COMENT: case COMENT | REC32: 1286 1980 switch (*++u.pch) … … 1381 2075 if (!pSym) goto failure; 1382 2076 SYMDBG(pSym, "EXTDEF"); 2077 /* put into array of externals */ 2078 if (!(cExts % 64)) 2079 { 2080 cExts += 64; 2081 papExts = xrealloc(papExts, sizeof(papExts[0]) * cExts); 2082 } 2083 papExts[cExts++] = pSym; 1383 2084 } 1384 2085 break; … … 1396 2097 ul = OMF_IS32BIT() ? OMF_DWORD() : OMF_WORD(); 1397 2098 us = OMF_GETINDEX(); /* typeindex */ 1398 pSym = symAddPublic(pWld, pMod, fLibSearch, u1.puch + 1, *u1.puch, 2099 pSym = symAddPublic(pWld, pMod, fLibSearch, u1.puch + 1, *u1.puch, 1399 2100 ul, us3, us2); 1400 2101 if (!pSym) goto failure; … … 1410 2111 u1 = u; u.pch += 1 + *u.puch; /* alias name */ 1411 2112 u2 = u; u.pch += 1 + *u.puch; /* substitutt name. */ 1412 pSym = symAddAlias(pWld, pMod, fLibSearch, 1413 u1.puch + 1, *u1.puch, 2113 pSym = symAddAlias(pWld, pMod, fLibSearch, 2114 u1.puch + 1, *u1.puch, 1414 2115 u2.puch + 1, *u2.puch); 1415 2116 if (!pSym) goto failure; … … 1433 2134 break; 1434 2135 case COMDEF_TYPENEAR: 1435 l2 = 1; /* number of elements */ 1436 OMF_GETTYPELEN(l3); /* element size */ 2136 l2 = 1; /* number of elements */ 2137 OMF_GETTYPELEN(l3); /* element size */ 1437 2138 break; 1438 2139 default: … … 1441 2142 } 1442 2143 1443 pSym = symAddComdef(pWld, pMod, fLibSearch, 1444 u1.puch + 1, *u1.puch, 2144 pSym = symAddComdef(pWld, pMod, fLibSearch, 2145 u1.puch + 1, *u1.puch, 1445 2146 l2, l3); 1446 2147 if (!pSym) goto failure; … … 1481 2182 /* Make all the EXTDEFs uncertain. */ 1482 2183 for (i = 0; i < cExts; i++) 1483 papExts[i]->fFlags &= ~WLDSF_UNCERTAIN; 2184 if (papExts[i]) 2185 papExts[i]->fFlags &= ~WLDSF_UNCERTAIN; 1484 2186 1485 2187 return 0; … … 1511 2213 * @param fFlags Linker flags as defined by enum wld_create_flags. 1512 2214 */ 1513 PWLD wld _create(int fFlags)2215 PWLD wldCreate(int fFlags) 1514 2216 { 1515 2217 PWLD pWld = xmalloc(sizeof(*pWld)); … … 1519 2221 pWld->fFlags = fFlags; 1520 2222 pWld->pStrMisc = strpool_init(); 1521 pWld->pp LibsAdd = &pWld->pObjs;1522 pWld->pp ObjsAdd = &pWld->pLibs;2223 pWld->ppObjsAdd = &pWld->pObjs; 2224 pWld->ppLibsAdd = &pWld->pLibs; 1523 2225 1524 2226 /* done */ … … 1535 2237 * @param pWld Linker instance to destroy. 1536 2238 */ 1537 int wld _destroy(PWLD pWld)2239 int wldDestroy(PWLD pWld) 1538 2240 { 1539 2241 if (!pWld) … … 1565 2267 * or wld_generate_weaklib()! 1566 2268 */ 1567 int wld _add_object(PWLD pWld, FILE *phFile, const char *pszName)2269 int wldAddObject(PWLD pWld, FILE *phFile, const char *pszName) 1568 2270 { 1569 2271 OMFREC OmfRec = {0,0}; … … 1655 2357 * or wld_generate_weaklib()! 1656 2358 */ 1657 int wld _add_deffile(PWLD pWld, FILE *phFile, const char *pszName)2359 int wldAddDefFile(PWLD pWld, FILE *phFile, const char *pszName) 1658 2360 { 1659 2361 if (!phFile) … … 1685 2387 * @author Don't call wld_add_library after wld_generate_weaklib()! 1686 2388 */ 1687 int wld_add_library(PWLD pWld, FILE *phFile, const char *pszName) 1688 { 2389 int wldAddLibrary(PWLD pWld, FILE *phFile, const char *pszName) 2390 { 2391 PWLDLIB pLib; 2392 int rc = 0; 2393 1689 2394 if (!phFile) 1690 2395 phFile = fopen(pszName, "r"); … … 1697 2402 fprintf(stderr, "weakld: info: adding library %s\n", pszName); 1698 2403 1699 return 0; 2404 /* add it to the link, do nothing till we're asked to do the searching. */ 2405 pLib = xmalloc(sizeof(*pLib)); 2406 pLib->phFile = phFile; 2407 pLib->pszLibName = strpool_add(pWld->pStrMisc, pszName); 2408 pLib->pNext = NULL; 2409 2410 /* read the library header. */ 2411 if ( !fseek(phFile, 0, SEEK_SET) 2412 && fread(&pLib->LibHdr, sizeof(OMFREC), 1, phFile) == 1 2413 && ( pLib->LibHdr.chType != LIBHDR 2414 || fread(&pLib->LibHdr.offDict, sizeof(pLib->LibHdr) - sizeof(OMFREC), 1, phFile) == 1 2415 ) 2416 ) 2417 { 2418 /* link it in */ 2419 *pWld->ppLibsAdd = pLib; 2420 pWld->ppLibsAdd = &pLib->pNext; 2421 libClose(pLib); 2422 } 2423 else 2424 { 2425 /* We failed. */ 2426 libErr(pLib, "Invalid library format or read error."); 2427 fclose(phFile); 2428 free(pLib); 2429 rc = -1; 2430 } 2431 2432 return rc; 2433 } 2434 2435 2436 /** 2437 * Does the linker pass one - chiefly library search as .def and .obj is 2438 * already processed as pass 1. 2439 * 2440 * @returns 0 on success (all symbols resolved) 2441 * @returns 42 if there are unresolved symbols. 2442 * @returns Something else on all other errors. 2443 * @param pWld Linker Instance. 2444 */ 2445 int wldPass1(PWLD pWld) 2446 { 2447 int fMore; 2448 int cLoaded; 2449 int fFirstTime = 1; 2450 2451 WLDINFO(pWld, ("Pass 1")); 2452 do 2453 { 2454 PWLDLIB pLib; 2455 2456 cLoaded = fMore = 0; 2457 for (pLib = pWld->pLibs; pLib; pLib = pLib->pNext) 2458 { 2459 int rc; 2460 WLDSLEPARAM param; 2461 WLDINFO(pWld, ("%s", pLib->pszLibName)); 2462 2463 /* 2464 * Open the library 2465 */ 2466 if (!libOpen(pLib)) 2467 continue; 2468 2469 /* 2470 * Load extended dictionary if we wanna use it. 2471 */ 2472 if (fFirstTime && !(pWld->fFlags & WLDC_NO_EXTENDED_DICTIONARY_SEARCH)) 2473 libLoadDict(pLib); 2474 else 2475 libCloseDict(pLib); 2476 2477 /* 2478 * Enumerate undefined symbols and try load them from this library. 2479 */ 2480 do 2481 { 2482 param.fMore = FALSE; 2483 param.cLoaded = 0; 2484 param.pLib = pLib; 2485 if (pLib->pDict) 2486 rc = symEnum(pWld, &pWld->Global, WLDSF_UNDEF, WLDSF_TYPEMASK | WLDSF_WEAK, symSearchLibEnum, ¶m); 2487 else 2488 { 2489 rc = libLoadUndefSymbols(pWld, pLib, NULL, ¶m.cLoaded); 2490 if (rc == 42) 2491 { 2492 param.fMore = 1; 2493 rc = 0; 2494 } 2495 } 2496 cLoaded += param.cLoaded; 2497 if (!param.fMore && param.cLoaded) 2498 param.fMore = symHaveUndefined(pWld); 2499 } while (!rc && param.cLoaded > 0); 2500 2501 /* close it */ 2502 libClose(pLib); 2503 if (rc && rc != 42) 2504 return rc; 2505 } 2506 2507 /* We only trust this if it's set. */ 2508 fMore = symHaveUndefined(pWld); 2509 fFirstTime = 0; 2510 } while (fMore && cLoaded > 0); 2511 2512 /* @todo: proper warning? */ 2513 if (fMore) 2514 symPrintUnDefs(pWld); 2515 2516 return fMore ? 42 : 0; 1700 2517 } 1701 2518 … … 1740 2557 { 1741 2558 wldErr(pWld, "Error occured while writing weak aliases. (1)"); 1742 return -1; 2559 return -1; 1743 2560 } 1744 2561 … … 1751 2568 { 1752 2569 wldErr(pWld, "Error occured while writing weak aliases (2)."); 1753 return -1; 2570 return -1; 1754 2571 } 1755 2572 … … 1762 2579 { 1763 2580 wldErr(pWld, "Error occured while writing weak aliases (3)."); 1764 return -1; 2581 return -1; 1765 2582 } 1766 2583 … … 1771 2588 { 1772 2589 wldErr(pWld, "Error occured while writing weak aliases (4)."); 1773 return -1; 2590 return -1; 1774 2591 } 1775 2592 } … … 1790 2607 * This is an empty string if no weak symbols were found! 1791 2608 */ 1792 int wld _generate_weakobj(PWLD pWld, char *pszName)2609 int wldGenerateWeakobj(PWLD pWld, char *pszName) 1793 2610 { 1794 2611 char * psz; 1795 2612 FILE * phFile; 1796 int rc = -1; 1797 2613 int rc; 2614 2615 /* generate the file */ 1798 2616 *pszName = '\0'; 1799 2617 psz = _tempnam(NULL, "weako"); … … 1806 2624 tmpnam(pszName); 1807 2625 strcat(pszName, "wk.obj"); 1808 1809 if (pWld->fFlags & WLDC_VERBOSE) 1810 fprintf(stderr, "weakld: info: generating weakobj object file '%s'.\n", pszName); 2626 WLDINFO(pWld, ("Generating weakobj object file '%s'.", pszName)); 2627 1811 2628 1812 2629 /* open the file */ … … 1837 2654 /* Make aliases */ 1838 2655 offAlias = ftell(phFile); /* save this to see if anything is added. */ 1839 rc = symEnum(pWld, &pWld->Global, 2656 rc = symEnum(pWld, &pWld->Global, 1840 2657 WLDSF_WEAK, WLDSF_WEAK, 1841 2658 weakobjEnum, phFile); -
Property cvs2svn:cvs-rev
changed from
-
trunk/src/emx/src/emxomf/weakld.h
-
Property cvs2svn:cvs-rev
changed from
1.2
to1.3
r510 r511 1 /* $Id$ 1 /* $Id$ */ 2 /** @file 2 3 * 3 4 * Weak Pre-Linker. … … 30 31 *******************************************************************************/ 31 32 struct wld; 33 /** Weak LD Instance Pointer. */ 32 34 typedef struct wld * PWLD; 33 35 … … 47 49 * Functions * 48 50 *******************************************************************************/ 49 PWLD wld_create(int fFlags); 50 int wld_add_object(PWLD pWld, FILE *phFile, const char *pszName); 51 int wld_add_deffile(PWLD pWld, FILE *phFile, const char *pszName); 52 int wld_add_library(PWLD pWld, FILE *phFile, const char *pszName); 53 int wld_generate_weakobj(PWLD pwld, char *pszName); 54 int wld_destroy(PWLD pWld); 51 /** @group Weak LD - Public methods. 52 * @{ */ 53 PWLD wldCreate(int fFlags); 54 int wldAddObject(PWLD pWld, FILE *phFile, const char *pszName); 55 int wldAddDefFile(PWLD pWld, FILE *phFile, const char *pszName); 56 int wldAddLibrary(PWLD pWld, FILE *phFile, const char *pszName); 57 int wldPass1(PWLD pWld); 58 int wldGenerate_weakobj(PWLD pwld, char *pszName); 59 int wldDestroy(PWLD pWld); 60 /** @} */ 55 61 56 62 #endif -
Property cvs2svn:cvs-rev
changed from
Note:
See TracChangeset
for help on using the changeset viewer.