Changeset 942
- Timestamp:
- Jan 11, 2004, 1:06:08 AM (22 years ago)
- Location:
- trunk/src/emx/src
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/emx/src/emxomf/emxomfld.c
-
Property cvs2svn:cvs-rev
changed from
1.34
to1.35
r941 r942 47 47 { 48 48 struct name_list *next; 49 unsigned flags; 49 50 char *name; 50 51 } name_list; … … 89 90 command line is added to this list. The -l option also adds an 90 91 entry to this list. add_lib_fnames is used to add another entry at 91 the end of the list. */ 92 the end of the list. 93 The flags member indicates library search method. If set search for 94 static lib, if clear search for shared lib before search for static lib. */ 92 95 static name_list *lib_fnames = NULL; 93 96 static name_list **add_lib_fnames = &lib_fnames; … … 163 166 extern void *xrealloc (void *ptr, size_t n); 164 167 extern char *xstrdup (const char *s); 165 static void add_name_list (name_list ***add, const char *src );168 static void add_name_list (name_list ***add, const char *src, unsigned flags); 166 169 static void conv_path (char *name); 167 170 static void put_arg (const char *src, int path, int quotable); … … 234 237 list. */ 235 238 236 static void add_name_list (name_list ***add, const char *src) 237 { 238 name_list *new; 239 240 new = xmalloc (sizeof (name_list)); 241 new->next = NULL; 242 new->name = xstrdup (src); 243 *(*add) = new; 244 (*add) = &new->next; 239 static void add_name_list (name_list ***add, const char *src, unsigned flags) 240 { 241 name_list *node; 242 243 node = xmalloc (sizeof (name_list)); 244 node->next = NULL; 245 node->name = xstrdup (src); 246 node->flags = flags; 247 *(*add) = node; 248 (*add) = &node->next; 245 249 } 246 250 … … 469 473 } 470 474 471 /* Check if the given file is a valid OMF library. */ 472 473 static int check_omf_library (FILE *f) 475 /** 476 * Checks if the stream phFile is an OMF library. 477 * 478 * @returns 1 if OMF library. 479 * @returns 0 if not OMF library. 480 * @param phFile Filestream to check. 481 */ 482 static int check_omf_library(FILE *phFile) 474 483 { 475 484 #pragma pack(1) 476 struct477 {478 byte rec_type;479 word rec_len;480 dword dict_offset;481 word dict_blocks;482 byte flags;483 } libhdr;485 struct 486 { 487 byte rec_type; 488 word rec_len; 489 dword dict_offset; 490 word dict_blocks; 491 byte flags; 492 } libhdr; 484 493 #pragma pack() 485 494 486 if (fread (&libhdr, 1, sizeof(libhdr), f) == sizeof (libhdr) 487 && !fseek (f, 0, SEEK_SET) 488 && libhdr.rec_type == LIBHDR 489 && libhdr.flags <= 1 /* ASSUME only first bit is used... */ 490 ) 491 { 492 int page_size = libhdr.rec_len + 3; 493 if (page_size >= 16 494 && page_size <= 32768 495 && !(page_size & (page_size - 1)) != 0) 495 if ( fread(&libhdr, 1, sizeof(libhdr), phFile) == sizeof (libhdr) 496 && !fseek(phFile, 0, SEEK_SET) 497 && libhdr.rec_type == LIBHDR 498 && libhdr.flags <= 1 /* ASSUME only first bit is used... */ 499 ) 500 { 501 int page_size = libhdr.rec_len + 3; 502 if (page_size >= 16 503 && page_size <= 32768 504 && !(page_size & (page_size - 1)) != 0) 505 return 1; 506 } 507 return 0; 508 } 509 510 511 /** 512 * Checks if the stream phFile is an OMF object or library. 513 * 514 * @returns 1 if OMF. 515 * @returns 0 if not OMF. 516 * @param phFile Filestream to check. 517 */ 518 static int check_omf(FILE *phFile) 519 { 520 #pragma pack(1) 521 struct 522 { 523 byte rec_type; 524 word rec_len; 525 } omfhdr; 526 #pragma pack() 527 if ( fread(&omfhdr, 1, sizeof(omfhdr), phFile) == sizeof (omfhdr) 528 && omfhdr.rec_type == THEADR 529 && omfhdr.rec_len >= sizeof(omfhdr) 530 && !fseek(phFile, 0, SEEK_SET) 531 ) 496 532 return 1; 497 } 498 499 return 0; 500 } 501 502 503 /* Checks if the file handle is to an omf object or library file. */ 504 505 static int check_omf (FILE *f) 506 { 507 #pragma pack(1) 508 struct 509 { 510 byte rec_type; 511 word rec_len; 512 } omfhdr; 513 #pragma pack() 514 if (fread (&omfhdr, 1, sizeof(omfhdr), f) == sizeof (omfhdr) 515 && omfhdr.rec_type == THEADR 516 && omfhdr.rec_len >= sizeof(omfhdr) 517 && !fseek (f, 0, SEEK_SET) 518 ) 519 { 520 return 1; 521 } 522 523 return !fseek (f, 0, SEEK_SET) && check_omf_library (f); 533 534 return !fseek(phFile, 0, SEEK_SET) 535 && check_omf_library(phFile); 536 } 537 538 539 /** 540 * Checks if the stream phFile is an LX DLL. 541 * 542 * @returns 1 if LX DLL. 543 * @returns 0 if not LX DLL. 544 * @param phFile File stream to check. 545 */ 546 static int check_lx_dll(FILE *phFile) 547 { 548 unsigned long ul; 549 char achMagic[2]; 550 551 if ( fseek(phFile, 0, SEEK_SET) 552 || fread(&achMagic, 1, 2, phFile) != 2) 553 goto thats_not_it; 554 555 if (!memcmp(achMagic, "MZ", 2)) 556 { 557 if ( fseek(phFile, 0x3c, SEEK_SET) 558 || fread(&ul, 1, 4, phFile) != 4 /* offset of the 'new' header */ 559 || ul < 0x40 560 || ul >= 0x10000000 /* 512MB stubs sure */ 561 || fseek(phFile, ul, SEEK_SET) 562 || fread(&achMagic, 1, 2, phFile) != 2) 563 goto thats_not_it; 564 } 565 566 if ( memcmp(achMagic, "LX", 2) 567 || fseek(phFile, 14, SEEK_CUR) 568 || fread(&ul, 1, 4, phFile) != 4) /*e32_mflags*/ 569 goto thats_not_it; 570 571 #define E32MODDLL 0x08000L 572 #define E32MODPROTDLL 0x18000L 573 #define E32MODMASK 0x38000L 574 if ( (ul & E32MODMASK) != E32MODDLL 575 && (ul & E32MODMASK) != E32MODPROTDLL) 576 goto thats_not_it; 577 578 /* it's a LX DLL! */ 579 fseek(phFile, 0, SEEK_SET); 580 return 1; 581 582 583 thats_not_it: 584 fseek(phFile, 0, SEEK_SET); 585 return 0; 524 586 } 525 587 … … 533 595 * @param pszPrefix Prefix. 534 596 * @param pszSuffix Suffix. 597 * @param pszLooklike Filename which name is to be incorporated into the temp filename. 535 598 * @remark The code is nicked from the weak linker. 536 599 */ 537 static int make_tempfile(char *pszFile, const char *pszPrefix, const char *pszSuffix )600 static int make_tempfile(char *pszFile, const char *pszPrefix, const char *pszSuffix, const char *pszLooklike) 538 601 { 539 602 struct stat s; 540 603 unsigned c = 0; 604 char szLooklike[32]; 541 605 pid_t pid = getpid(); 542 606 const char * pszTmp = getenv("TMP"); … … 544 608 if (!pszTmp) pszTmp = getenv("TEMP"); 545 609 if (!pszTmp) pszTmp = "."; 610 if (pszLooklike) 611 { 612 int cch; 613 char *psz = (char*)pszLooklike; /* we're nice fellows. */ 614 while ((psz = strpbrk(psz, ":/\\")) != NULL) 615 pszLooklike = ++psz; 616 cch = strlen(pszLooklike); 617 if (cch + 3 > sizeof(szLooklike)) 618 cch = sizeof(szLooklike) - 3; 619 szLooklike[0] = '_'; 620 memcpy(&szLooklike[1], pszLooklike, cch); 621 szLooklike[cch + 1] = '_'; 622 szLooklike[cch + 2] = '\0'; 623 pszLooklike = psz = &szLooklike[0]; 624 while ((psz = strpbrk(psz, ".@%^&#()")) != NULL) 625 *psz++ = '_'; 626 } 627 else 628 pszLooklike = ""; 546 629 547 630 do … … 551 634 return -1; 552 635 gettimeofday(&tv, NULL); 553 sprintf(pszFile, "%s\\%s% x%lx%d%lx%s", pszTmp, pszPrefix, pid, tv.tv_sec, c, tv.tv_usec, pszSuffix);636 sprintf(pszFile, "%s\\%s%s%x%lx%d%lx%s", pszTmp, pszPrefix, pszLooklike, pid, tv.tv_sec, c, tv.tv_usec, pszSuffix); 554 637 } while (!stat(pszFile, &s)); 555 638 … … 558 641 559 642 560 /* Converts the file indicated by pf & pszFilename to omf closing f and 561 updating filename with the new (temporary filename). A successful 562 return from the function returns a pointe to the filestream for the 563 converted file. On failure NULL is returned, f is closed adn filename 564 is undefined. */ 565 566 static FILE *aout_to_omf (FILE *pf, char *pszFilename, int fLibrary) 643 /** 644 * Converts the file indicated by phFile & pszFilename to omf closing 645 * phFile and updating pszFilename with the new (temporary filename). 646 * 647 * @returns Pointer to an filestream for the converted file and pszFilename 648 * containing the name of the converted file. 649 * @returns exit the program 650 * @param phFile Filestream of the file to convert. (close this) 651 * @param pszFilename Name of the file to convert on entry. 652 * Name of the converted file on return. 653 */ 654 static FILE *aout_to_omf(FILE *pf, char *pszFilename, int fLibrary) 567 655 { 568 656 int rc; … … 573 661 574 662 if (opt_t) 575 fprintf(stderr, "emxomfld: info: converting %s %s to OMF.\n",576 fLibrary ? "lib" : "obj", pszFilename);663 fprintf(stderr, "emxomfld: info: converting %s %s to OMF.\n", 664 fLibrary ? "lib" : "obj", pszFilename); 577 665 578 666 /* … … 581 669 pName = xmalloc(sizeof(name_list)); 582 670 pName->name = pszNewFile = xmalloc(_MAX_PATH); 583 if (make_tempfile(pszNewFile, "ldconv", fLibrary ? ".lib" : ".obj" ))671 if (make_tempfile(pszNewFile, "ldconv", fLibrary ? ".lib" : ".obj", pszFilename)) 584 672 { 585 673 free(pszNewFile); … … 590 678 * Do the conversion. 591 679 */ 592 rc = spawnlp(P_WAIT, "emxomf.exe", "emxomf.exe", 593 "-o", pszNewFile, pszFilename, NULL); 680 rc = spawnlp(P_WAIT, "emxomf.exe", "emxomf.exe", "-o", pszNewFile, pszFilename, NULL); 594 681 if (!rc) 595 682 { … … 605 692 606 693 if (opt_t) 607 fprintf(stderr, "emxomfld: info: convert result '%s'.\n",608 pszFilename);694 fprintf(stderr, "emxomfld: info: convert result '%s'.\n", 695 pszFilename); 609 696 return pf; 610 697 } … … 614 701 free(pName); 615 702 616 fprintf 617 618 exit (2);703 fprintf(stderr, "emxomfld: a.out to omf conversion failed for '%s'.\n", 704 pszFilename); 705 exit(1); 619 706 return NULL; 620 707 } 621 708 622 709 623 /* Converts the file indicated by pf & pszFilename to omf closing f and 624 updating filename with the new (temporary filename). A successful 625 return from the function returns a pointe to the filestream for the 626 converted file. On failure NULL is returned, f is closed adn filename 627 is undefined. */ 628 629 static FILE *lx_to_omf (FILE *pf, char *pszFilename) 710 /** 711 * Converts the file indicated by phFile & pszFilename to omf closing 712 * phFile and updating pszFilename with the new (temporary filename). 713 * 714 * @returns Pointer to an filestream for the converted file and pszFilename 715 * containing the name of the converted file. 716 * @returns exit the program 717 * @param phFile Filestream of the file to convert. (close this) 718 * @param pszFilename Name of the file to convert on entry. 719 * Name of the converted file on return. 720 */ 721 static FILE *lx_to_omf(FILE *pf, char *pszFilename) 630 722 { 631 723 int rc; … … 636 728 637 729 if (opt_t) 638 fprintf(stderr, "emxomfld: info: converting %s %s to an OMF import lib.\n",639 "lib", pszFilename);730 fprintf(stderr, "emxomfld: info: converting %s %s to an OMF import lib.\n", 731 "lib", pszFilename); 640 732 641 733 /* … … 644 736 pName = xmalloc(sizeof(name_list)); 645 737 pName->name = pszNewFile = xmalloc(_MAX_PATH); 646 if (make_tempfile(pszNewFile, "ldconv", ".lib" ))738 if (make_tempfile(pszNewFile, "ldconv", ".lib", pszFilename)) 647 739 { 648 740 free(pszNewFile); … … 653 745 * Do the conversion. 654 746 */ 655 rc = spawnlp(P_WAIT, "emximp.exe", "emximp.exe", 656 "-o", pszNewFile, pszFilename, NULL); 747 rc = spawnlp(P_WAIT, "emximp.exe", "emximp.exe", "-o", pszNewFile, pszFilename, NULL); 657 748 if (!rc) 658 749 { … … 677 768 free(pName); 678 769 679 fprintf (stderr, "emxomfld: a.outto omf conversion failed for '%s'.\n",680 681 exit 770 fprintf(stderr, "emxomfld: lx dll to omf conversion failed for '%s'.\n", 771 pszFilename); 772 exit(2); 682 773 return NULL; 683 774 } 684 775 685 776 686 687 /* Finds the full path of a OMF library or object file. 688 689 This function may perform conversion from a.out to omf if that feature 690 is enabled. 691 692 Object files and libraries will be searched for using the LIB env.var 693 (which is exported so that it is used by ILINK/LINK386 as well), 694 if not found by their path directly. Note that finding object files in 695 the LIB paths contradicts the standard Unix behaviour, so it is a kind 696 of a hack, but this is the way ILINK and LINK386 work. 697 698 If file has no extension, the .obj and .o extensions are tried in turn 699 for object files, and .lib then .a are tried in turn for libraries. 700 Additionaly, for libraries we check for a file with the 'lib' prefix, 701 if one without the 'lib' prefix was not found. The '.o' and '.a' 702 extensions are tried in the last case since otherwise we can find 703 a 'something.a' when 'libsomething.lib' is available. 704 705 We support linking with DLLs if they have a path as we're not yet ready 706 to start searching for them or anything of that kind of real UNIXy 707 behaviour. 708 709 Returns pointer to file stream and FULLNAME set to it's name on success. 710 Returns NULL and FULLNAME a copy of NAME on failure. 711 */ 712 713 static FILE *find_objlib (char *fullname, const char *name, int is_library) 714 { 715 static const char *exts [2][2] = { { ".obj", ".o" }, { ".lib", ".a" } }; 716 FILE *f; 717 size_t pathlen, namelen = strlen (name); 718 const char *libpath, *x; 719 int i, has_ext = 0, is_dll = 0, has_path; 720 721 /* Check if the file name has a path. If it has, we won't check the 722 LIB directories, and won't check if it has a object file extension. */ 723 has_path = (strpbrk (name, ":/\\") != NULL); 724 if (has_path) 725 { 726 has_ext = 1; 727 x = strrchr (name, '.'); 728 if (x && !stricmp(x, ".dll")) 729 is_dll = 1; 730 } 731 else 732 { 733 /* Check if file has a real extension. If it is a object file it should 734 have either .o or .obj, and if it is a library it should have either 735 the .a or .lib extension. Otherwise we don't consider it a extension. */ 736 x = strrchr (name, '.'); 737 if (x) 738 for (i = 0; i < 2; i++) 739 if (!stricmp (x, exts [is_library][i])) 777 /** 778 * Finds the full path of a OMF object file and opens the file. 779 * 780 * This function may perform conversion from a.out to omf if that feature 781 * is enabled. 782 * 783 * We choose to be UNIX compatible her, and not search the LIB env.var. 784 * for unqualified objects. Nor will we add any suffixes to the name 785 * if it's witout any extension. 786 * 787 * @returns Pointer to a file stream for the object file to use in the link. 788 * @returns NULL on failure with pszFullname containing a copy of 789 * pszName (or something like that). 790 * @param pszFullname Where to store the name of the file to be used 791 * in the linking (and which stream is returned). 792 * @param pszName Object name given to on the linker commandline. 793 */ 794 static FILE *find_obj(char *pszFullname, const char *pszName) 795 { 796 FILE *phFile; 797 char *psz; 798 799 /* 800 * Make abspath with slashes the desired way and such. 801 */ 802 if (_abspath(pszFullname, pszName, _MAX_PATH + 1)) 803 { 804 printf("emxomfld: _abspath failed on '%s'!!!\n", pszName); 805 exit(1); 806 } 807 808 psz = pszFullname; 809 while ((psz = strchr(psz, '/')) != NULL) 810 *psz++ = '\\'; 811 812 /* 813 * Try open the file. 814 */ 815 phFile = fopen(pszFullname, "rb"); 816 if (!phFile) 817 return NULL; 818 819 /* 820 * If autoconversion check if such is needed. 821 */ 822 if ( autoconvert_flag 823 && !check_omf(phFile)) 824 phFile = aout_to_omf(phFile, pszFullname, FALSE); 825 826 return phFile; 827 } 828 829 830 831 /* Finds the full path of a library file and opens the file. 832 * 833 * This function may perform conversion from a.out to omf if that feature 834 * is enabled. 835 * 836 * The function assumes that LIB has been updated with all the search paths 837 * specified on the commandline. 838 * 839 * Library names with no extension are given extensions after the rules 840 * indicated by the IS_SHARED parameter. If IS_SHARED is set then libraries 841 * with suffixes indicating shared libraries will be looked for before 842 * libraries with suffixes indicated static libraries. The list is as 843 * follows for set IS_SHARED: 844 * 1. _dll.lib 845 * 2. .lib 846 * 3. .dll 847 * 4. _s.lib 848 * 849 * If IS_SHARED is clear: 850 * 1. _s.lib 851 * 2. .lib 852 * 853 * Library names with no path is searched for in the semicolon separated list 854 * of paths the env.var. LIB contains. For each directory in LIB we'll start 855 * by see if it contains a 'lib' prefixed file, if not found we'll check for 856 * the unprefixed filename. If we're appending suffixes too, we'll loop thru 857 * all the possible suffixes for each directory before advancing to the next, 858 * having the prefixing as the inner most loop. 859 * 860 * @returns Pointer to a file stream for the library file to use in the link. 861 * @returns NULL on failure with pszFullname containing a copy of 862 * pszName (or something like that). 863 * @param pszFullname Where to store the name of the file to be used 864 * in the linking (and which stream is returned). 865 * @param pszName Library name given to on the linker commandline. 866 */ 867 static FILE *find_lib(char *pszFullname, const char *pszName, int fShared) 868 { 869 /* Suffix list for shared linking. */ 870 static const char *apszSharedSuff[] = { "_dll.lib", "_dll.a", ".lib", ".a", ".dll", "_s.lib", "_s.a", NULL }; 871 /* Suffix list for static linking. */ 872 static const char *apszStaticSuff[] = { "_s.lib", "_s.a", ".lib", ".a", NULL }; 873 /* Suffix list for names with extension. */ 874 static const char *apszExtensionSuff[] = { "", NULL }; 875 /* Prefix list for names with path. */ 876 static const char *apszWithPathPref[] = { "", NULL }; 877 /* Prefix list for names with no path. */ 878 static const char *apszWithoutPathPref[]= { "lib", "", NULL }; 879 int fPath; /* set if the library name have a path. */ 880 int fExt; /* set if the library name have an extension. */ 881 const char **papszSuffs; /* Pointer to the suffix list. */ 882 const char **papszPrefs; /* Pointer to the prefix list. */ 883 const char *pszLibPath; /* The path we're searching. */ 884 size_t cchCurPath; /* Size of the current path. */ 885 size_t cchName = strlen(pszName); 886 const char *psz; 887 888 /* 889 * Check if the file name has a path. 890 * (If it has, we won't check the LIB directories.) 891 * Choose the prefix list accordingly. 892 */ 893 fPath = (strpbrk(pszName, ":/\\") != NULL); 894 papszPrefs = fPath ? apszWithPathPref : apszWithoutPathPref; 895 896 /* 897 * Check if the file has a real extension. 898 * Real extension means, .lib, .dll or .a. It also implies something 899 * before the dot. 900 * Choose the suffix list accordingly. 901 */ 902 fExt = ( (cchName > 4 && !stricmp(pszName + cchName - 4, ".lib")) 903 || (cchName > 4 && !stricmp(pszName + cchName - 4, ".dll")) 904 || (cchName > 2 && !stricmp(pszName + cchName - 2, ".a")) ); 905 906 if (!fExt) 907 papszSuffs = fShared ? &apszSharedSuff[0] : &apszStaticSuff[0]; 908 else 909 papszSuffs = apszExtensionSuff; 910 911 /* 912 * Loop 1: LIB (with a fake .\ as the first iteration) 913 * (Looping on pszLibPath, with preinitiated cchCurPath & pszFullname.) 914 */ 915 cchCurPath = 0; 916 if (!fPath) 917 { 918 cchCurPath = 2; 919 memcpy(pszFullname, ".\\", 2); 920 } 921 pszLibPath = getenv("LIB"); 922 do 923 { 924 /* 925 * Loop2: Suffixes. 926 */ 927 int iSuff; 928 for (iSuff = 0; papszSuffs[iSuff]; iSuff++) 929 { 930 /* 931 * Loop3: Prefixes. 932 */ 933 int iPref; 934 for (iPref = 0; papszPrefs[iPref]; iPref++) 740 935 { 741 has_ext = 1; 936 FILE *phFile; 937 int cch = strlen(papszPrefs[iPref]); 938 939 /* 940 * Construct name. 941 */ 942 memcpy(&pszFullname[cchCurPath], papszPrefs[iPref], cch); 943 cch = cchCurPath + cch; 944 memcpy(&pszFullname[cch], pszName, cchName); 945 cch += cchName; 946 strcpy(&pszFullname[cch], papszSuffs[iSuff]); 947 948 /* 949 * Open and if necessary convert it. 950 */ 951 phFile = fopen(pszFullname, "rb"); 952 if (phFile) 953 { 954 if (autoconvert_flag) 955 { 956 if (check_lx_dll(phFile)) 957 phFile = lx_to_omf(phFile, pszFullname); 958 else if (!check_omf(phFile)) 959 phFile = aout_to_omf(phFile, pszFullname, TRUE); 960 } 961 962 /* Replace forward slashes with backslashes (link386). */ 963 while ((pszFullname = strchr(pszFullname, '/')) != NULL) 964 *pszFullname++ = '\\'; 965 return phFile; 966 } 967 } /* next prefix */ 968 } /* next suffix */ 969 970 /* 971 * If a path was specified or no LIB we're done now. 972 */ 973 if (fPath || !pszLibPath) 974 break; 975 976 /* 977 * Next LIB part. 978 */ 979 for (;;) 980 { 981 psz = strchr(pszLibPath, ';'); 982 if (!psz) 983 psz = strchr(pszLibPath, '\0'); 984 cchCurPath = psz - pszLibPath; 985 if (cchCurPath) 986 { 987 memcpy(pszFullname, pszLibPath, cchCurPath); 988 pszLibPath = psz + (*psz == ';'); 989 /* Append last slash if it is not there */ 990 if ( pszFullname[cchCurPath - 1] != '/' 991 && pszFullname[cchCurPath - 1] != '\\') 992 pszFullname[cchCurPath++] = '\\'; 993 break; 994 } 995 if (!*psz) 742 996 break; 743 } 744 } 745 746 /* First loop search file name as-is, then search the paths 747 in the LIB environment variable. */ 748 libpath = getenv ("LIB"); 749 pathlen = 0; 750 if (!has_path) 751 { 752 memcpy(fullname, ".\\", 2); 753 pathlen = 2; 754 } 755 do 756 { 757 /* Step 0: check path+filename (+'.obj/.lib' if !has_ext) 758 * Step 1: if is_library check path+'lib'+filename (+'.lib' if !has_ext) 759 * Step 2: check path+filename (+'.o/.a' if !has_ext) 760 * Step 3: if is_library check path+'lib'+filename (+'.a' if !has_ext) 761 */ 762 for (i = 0; i < 4; i++) 763 { 764 char *cur = fullname + pathlen; 765 766 if ((i & 1) && (!is_library || has_path)) 767 continue; 768 769 if (i & 1) 770 { 771 memcpy (cur, "lib", 3); 772 cur += 3; 773 } 774 775 /* Include final zero in the case we won't append the extension */ 776 memcpy (cur, name, namelen + 1); 777 cur += namelen; 778 779 if (!has_ext) 780 { 781 strcpy (cur, exts [is_library][i/2]); 782 cur = strchr (cur, 0); 783 } 784 785 f = fopen (fullname, "rb"); 786 if (f) 787 { 788 if (autoconvert_flag && is_dll && is_library) 789 f = lx_to_omf (f, fullname); 790 else if (autoconvert_flag && !check_omf (f)) 791 f = aout_to_omf (f, fullname, is_library); 792 793 if (is_library && !check_omf_library (f) /* not sure if this makes sense */) 794 fclose (f); 795 else 796 { 797 /* Replace forward slashes with backslashes (link386). */ 798 while ((fullname = strchr (fullname, '/')) != NULL) 799 *fullname++ = '\\'; 800 return f; 801 } 802 } 997 pszLibPath = psz + 1; 803 998 } 804 805 if (!libpath || has_path) 806 break; 807 808 /* Find the next LIB component. 809 We're skipping empty components. */ 810 for (;;) 811 { 812 x = strchr (libpath, ';'); 813 if (!x) x = strchr (libpath, 0); 814 pathlen = x - libpath; 815 if (pathlen) 816 { 817 memcpy (fullname, libpath, pathlen); 818 libpath = x + (*x == ';'); 819 /* Append last slash if it is not there */ 820 if (fullname [pathlen - 1] != '/' 821 && fullname [pathlen - 1] != '\\') 822 fullname [pathlen++] = '\\'; 823 break; 824 } 825 if (!*x) 826 break; 827 libpath = x + (*x == ';'); 828 } 829 } while (pathlen); 830 831 832 strcpy (fullname, name); 833 return NULL; 834 } 999 } while (cchCurPath); 1000 1001 /* failure */ 1002 return NULL; 1003 } 1004 835 1005 836 1006 /* Weak prelinking for Method 2 Weak support. */ … … 894 1064 for (pcur = obj_fnames; !rc && pcur; pcur = pcur->next) 895 1065 { 896 phfile = find_obj lib (szname, pcur->name, FALSE);1066 phfile = find_obj (szname, pcur->name); 897 1067 rc = WLDAddObject (pwld, phfile, szname); 898 1068 } … … 901 1071 for (pcur = lib_fnames; !rc && pcur; pcur = pcur->next) 902 1072 { 903 phfile = find_ objlib (szname, pcur->name, TRUE);1073 phfile = find_lib (szname, pcur->name, !pcur->flags); 904 1074 rc = WLDAddLibrary (pwld, phfile, szname); 905 1075 free(pcur->name); … … 923 1093 rc = WLDGenerateWeakAliases (pwld, weakobj_fname, weakdef_fname); 924 1094 if (!rc && weakobj_fname[0]) 925 add_name_list (&add_obj_fnames, weakobj_fname );1095 add_name_list (&add_obj_fnames, weakobj_fname, 0); 926 1096 if (!rc && weakdef_fname[0]) 927 1097 def_fname = weakdef_fname; … … 1097 1267 static void usage (void) 1098 1268 { 1099 fprintf (stderr, "emxomfld " VERSION INNOTEK_VERSION "\n" 1100 "Copyright (c) 1992-1996 by Eberhard Mattes\n" 1101 "Copyright (c) 2003 by InnoTek Systemberatung GmbH\n\n"); 1102 1103 fprintf (stderr, 1104 "Usage: emxomfld -o <file> [-l <lib>] [-L <libdir>] [-T <base>] [-igtsS]\n" 1105 " [-Zexe] [-Zdll] [-Zstack <size>] [-Zmap[=<map_file>]]\n" 1106 " [-Z[no-]autoconv] [-O <option>] [-static] [-non_shared]\n" 1107 " [-Bstatic] [-dn] [call_shared] [-Bshared] [-dy] <file>...\n" 1108 "\n" 1109 "Options:\n" 1110 " -Zno-autoconv / -Zautoconv:\n" 1111 " Turns off/on the automatic conversion of a.out libs and objs.\n" 1112 " default: -Zautoconv\n" 1113 " -Bstatic, -non_shared, -dn, -static:\n" 1114 " Link with static libraries.\n" 1115 " The search order is then changed to: lib<name>_s.lib, <name>_s.lib,\n" 1116 " lib<name>.lib, <name>.lib\n" 1117 " -Bshared, -call_shared, -dy:\n" 1118 " Link with shared libraries. This is default.\n" 1119 " The search order is then changed to: lib<name>_dll.lib, <name>_dll.lib,\n" 1120 " lib<name>.lib, <name>.lib, <name>.dll, lib<name>_s.lib, <name>_s.lib.\n" 1121 "\n" 1122 "Environment variables:\n" 1123 " EMXOMFLD_TYPE:\n" 1124 " The type of linker we're using. Values: VAC365, VAC308, LINK386.\n" 1125 " VAC365 ilink.exe from IBM C and C++ Compilers for OS/2 v3.6 or later.\n" 1126 " VAC308 ilink.exe from Visual Age for C++ v3.08.\n" 1127 " LINK386 link386 form OS/2 install or DDK.\n" 1128 " EMXOMFLD_LINKER:\n" 1129 " Name of the linker to use and optionally extra parameters. Spaces in the\n" 1130 " linker name or path is not supported. Quotes are not supported either.\n" 1131 "The default values for these two variables are VAC365 and ilink.exe.\n" 1132 ); 1269 fputs ("emxomfld " VERSION INNOTEK_VERSION "\n" 1270 "Copyright (c) 1992-1996 by Eberhard Mattes\n" 1271 "Copyright (c) 2003 by InnoTek Systemberatung GmbH\n" 1272 "Copyright (c) 2003-2004 by Knut St. Osmundsen\n" 1273 "\n", stderr); 1274 fputs ("Usage: emxomfld -o <file> [-l <lib>] [-L <libdir>] [-T <base>] [-igtsS]\n" 1275 " [-Zexe] [-Zdll] [-Zstack <size>] [-Zmap[=<map_file>]]\n" 1276 " [-Z[no-]autoconv] [-O <option>] [-static] [-non_shared]\n" 1277 " [-Bstatic] [-dn] [call_shared] [-Bshared] [-dy] <file>...\n" 1278 "\n", stderr); 1279 fputs ("Options:\n" 1280 " -Zno-autoconv / -Zautoconv:\n" 1281 " Turns off/on the automatic conversion of a.out libs and objs.\n" 1282 " default: -Zautoconv\n" 1283 " -Bstatic, -non_shared, -dn, -static:\n" 1284 " Link with static libraries.\n" 1285 " The search order is then changed to: lib<name>_s.lib, <name>_s.lib,\n" 1286 " lib<name>.lib, <name>.lib\n", stderr); 1287 fputs (" -Bshared, -call_shared, -dy:\n" 1288 " Link with shared libraries. This is default.\n" 1289 " The search order is then changed to: lib<name>_dll.lib, <name>_dll.lib,\n" 1290 " lib<name>.lib, <name>.lib, <name>.dll, lib<name>_s.lib, <name>_s.lib.\n" 1291 "\n", stderr); 1292 fputs ("Environment variables:\n" 1293 " EMXOMFLD_TYPE:\n" 1294 " The type of linker we're using. Values: VAC365, VAC308, LINK386.\n" 1295 " VAC365 ilink.exe from IBM C and C++ Compilers for OS/2 v3.6 or later.\n" 1296 " VAC308 ilink.exe from Visual Age for C++ v3.08.\n" 1297 " LINK386 link386 form OS/2 install or DDK.\n", stderr); 1298 fputs (" EMXOMFLD_LINKER:\n" 1299 " Name of the linker to use and optionally extra parameters. Spaces in the\n" 1300 " linker name or path is not supported. Quotes are not supported either.\n" 1301 "The default values for these two variables are VAC365 and ilink.exe.\n", stderr); 1133 1302 exit (1); 1134 1303 } … … 1185 1354 char execname[512]; 1186 1355 name_list *pcur; 1356 int opt_libs_static = 0; 1187 1357 int longind; 1188 1358 … … 1205 1375 1206 1376 /* Parse the command line options and other arguments. */ 1207 //while ((c = getopt_long (argc, argv, "o:O:itl:vL:T:sSxX", longopts, &longind)) != EOF)1208 1377 while ((c = getopt_long_only (argc, argv, "-l:y:L:", longopts, &longind)) != EOF) 1209 1378 { … … 1216 1385 break; 1217 1386 1218 case 0: /* Non-option argument */1387 case 1: /* Non-option argument */ 1219 1388 1220 1389 /* Extract the extension to see what to do with this … … 1230 1399 1231 1400 sprintf (tmp, "%s.", optarg); 1232 add_name_list (&add_obj_fnames, tmp );1401 add_name_list (&add_obj_fnames, tmp, 0); 1233 1402 } 1234 1403 … … 1266 1435 1267 1436 else if (stricmp (ext, ".lib") == 0 || stricmp (ext, ".a") == 0 || stricmp (ext, ".dll") == 0) 1268 add_name_list (&add_lib_fnames, optarg );1437 add_name_list (&add_lib_fnames, optarg, opt_libs_static); 1269 1438 1270 1439 /* Otherwise, assume it's an object file. */ 1271 1440 1272 1441 else 1273 add_name_list (&add_obj_fnames, optarg );1442 add_name_list (&add_obj_fnames, optarg, 0); 1274 1443 ++files; 1275 1444 break; … … 1281 1450 1282 1451 case 'l': /* Add library */ 1283 add_name_list (&add_lib_fnames, optarg );1452 add_name_list (&add_lib_fnames, optarg, opt_libs_static); 1284 1453 break; 1285 1454 … … 1289 1458 1290 1459 case 'L': /* Add library directory */ 1291 add_name_list (&add_libdirs, optarg );1460 add_name_list (&add_libdirs, optarg, 0); 1292 1461 break; 1293 1462 … … 1309 1478 1310 1479 case 'O': /* Specify Linker option */ 1311 add_name_list (&add_options, optarg );1480 add_name_list (&add_options, optarg, 0); 1312 1481 break; 1313 1482 … … 1337 1506 usage (); 1338 1507 errno = 0; 1339 stack_size = strtol ( argv[optind], &t, 0);1340 if (errno != 0 || *t != 0 || t == argv[optind])1508 stack_size = strtol (optarg, &t, 0); 1509 if (errno != 0 || *t != 0 || t == optarg) 1341 1510 usage (); 1342 1511 break; … … 1347 1516 case OPT_ZNO_AUTOCONV: 1348 1517 autoconvert_flag = 0; 1518 break; 1519 1520 case OPT_LIBS_STATIC: 1521 opt_libs_static = 1; 1522 break; 1523 case OPT_LIBS_SHARED: 1524 opt_libs_static = 0; 1525 break; 1349 1526 1350 1527 default: … … 1419 1596 { 1420 1597 char szname[_MAX_PATH + 1]; 1421 FILE *phfile = find_obj lib (szname, pcur->name, FALSE);1598 FILE *phfile = find_obj (szname, pcur->name); 1422 1599 if (!phfile) 1423 1600 continue; … … 1430 1607 { 1431 1608 char szname[_MAX_PATH + 1]; 1432 FILE *phfile = find_ objlib (szname, pcur->name, TRUE);1609 FILE *phfile = find_lib (szname, pcur->name, !pcur->flags); 1433 1610 if (!phfile) 1434 1611 continue; -
Property cvs2svn:cvs-rev
changed from
-
trunk/src/emx/src/ld/ld.c
-
Property cvs2svn:cvs-rev
changed from
1.12
to1.13
r941 r942 27 27 #include <stdio.h> 28 28 #include <stdlib.h> 29 #include <stdarg.h> 29 30 #include <io.h> 30 31 #include <process.h> … … 437 438 438 439 /* Demangler for C++. */ 439 extern char *cplus_demangle ();440 440 #include "demangle.h" 441 static char *my_cplus_demangle ( );441 static char *my_cplus_demangle (const char *); 442 442 int demangle_options; 443 443 … … 659 659 Also default text_start to after this file's bss. */ 660 660 char just_syms_flag; 661 662 /* 1 means search for dynamic libs before static. 663 0 means search only static libs. */ 664 char dynamic; 661 665 }; 662 666 … … 863 867 int cl_refs_allocated; 864 868 865 char *xmalloc (); 866 char *xrealloc (); 867 void usage (); 868 void fatal (); 869 void fatal_with_file (); 870 void perror_name (); 871 void perror_file (); 872 void error (); 873 874 int parse (); 875 void initialize_text_start (); 876 void initialize_data_start (); 877 void digest_symbols (); 878 void print_symbols (); 879 void load_symbols (); 880 void decode_command (); 881 void list_undefined_symbols (); 882 void list_unresolved_references (); 883 void write_output (); 884 void write_header (); 885 void write_text (); 886 void read_file_relocation (); 887 void write_data (); 888 void write_rel (); 889 void write_syms (); 890 void write_symsegs (); 891 void mywrite (); 892 void symtab_init (); 893 void padfile (); 894 char *concat (); 895 char *get_file_name (); 896 symbol *getsym (), *getsym_soft (); 897 void do_warnings (); 869 char *xmalloc (int); 870 void *xrealloc (void *, int); 871 void usage (char *, char *); 872 void fatal (char *, ...); 873 void fatal_with_file (char *, struct file_entry *); 874 void perror_name (char *); 875 void perror_file (struct file_entry *); 876 void error (char *, char *, char *, char *); 877 878 int parse (char *, char *, char *); 879 void initialize_text_start (void); 880 void initialize_data_start (void); 881 void digest_symbols (void); 882 void print_symbols (FILE *); 883 void load_symbols (void); 884 void decode_command (int, char **); 885 void write_output (void); 886 void write_header (void); 887 void write_text (void); 888 void read_file_relocation (struct file_entry *); 889 void write_data (void); 890 void write_rel (void); 891 void write_syms (void); 892 void write_symsegs (void); 893 void mywrite (void *, int, int, int); 894 void symtab_init (void); 895 void padfile (int, int); 896 char *concat (const char *, const char *, const char *); 897 char *get_file_name (struct file_entry *); 898 symbol *getsym (char *), *getsym_soft (char *); 899 void do_warnings (FILE *); 898 900 void check_exe (void); 899 901 char *lx_to_aout (const char *pszFilename); 902 int check_lx_dll(int fd); 900 903 void cleanup (void); 904 905 void add_cmdline_ref (struct glosym *sp); 906 void prline_file_name (struct file_entry *entry, FILE *outfile); 907 void deduce_file_type(int desc, struct file_entry *entry); 908 void read_a_out_header (int desc, struct file_entry *entry); 909 void read_header (int desc, struct file_entry *entry); 910 void read_entry_symbols (int desc, struct file_entry *entry); 911 void read_entry_strings (int desc, struct file_entry *entry); 912 unsigned long contains_symbol (struct file_entry *entry, struct nlist *n_ptr); 913 void process_subentry (int desc, struct file_entry *subentry, struct file_entry *entry, struct file_entry **prev_addr); 914 void consider_file_section_lengths (struct file_entry *entry); 915 void relocate_file_addresses (struct file_entry *entry); 916 void describe_file_sections (struct file_entry *entry, FILE *outfile); 917 void list_file_locals (struct file_entry *entry, FILE *outfile); 918 int relocation_entries_relation (struct relocation_info *rel1, struct relocation_info *rel2); 919 void do_relocation_warnings (struct file_entry *entry, int data_segment, FILE *outfile, unsigned char *nlist_bitvector); 920 void do_file_warnings (struct file_entry *entry, FILE *outfile); 921 void initialize_a_out_text_start (void); 922 void initialize_a_out_data_start (void); 923 void compute_a_out_section_offsets (void); 924 void compute_more_a_out_section_offsets (void); 925 void write_a_out_header (void); 926 int hash_string (char *key); 927 void read_file_symbols (struct file_entry *entry); 928 void compute_section_offsets (void); 929 void compute_more_section_offsets (void); 930 void read_relocation (void); 931 int assign_string_table_index (char *name); 932 unsigned long check_each_file (register unsigned long (*function)(), register int arg); 933 934 935 901 936 902 937 … … 1033 1068 {"z", 0, 0, 'z'}, 1034 1069 {"A", 1, 0, 'A'}, 1035 {"Bstatic", 0, 0, 129}, /* For Sun compatibility. */1036 1070 {"D", 1, 0, 'D'}, 1037 1071 {"M", 0, 0, 'M'}, … … 1052 1086 {"V", 1, 0, 'V'}, 1053 1087 {"X", 0, 0, 'X'}, 1088 #define OPT_LIBS_STATIC 0x1000 1089 {"Bstatic", 0, 0, OPT_LIBS_STATIC}, 1090 {"non_shared", 0, 0, OPT_LIBS_STATIC}, 1091 {"dn", 0, 0, OPT_LIBS_STATIC}, 1092 {"static", 0, 0, OPT_LIBS_STATIC}, 1093 #define OPT_LIBS_SHARED 0x1001 1094 {"Bshared", 0, 0, OPT_LIBS_SHARED}, 1095 {"call_shared", 0, 0, OPT_LIBS_SHARED}, 1096 {"dy", 0, 0, OPT_LIBS_SHARED}, 1054 1097 {0, 0, 0, 0} 1055 1098 }; … … 1071 1114 int optc, longind; 1072 1115 register struct file_entry *p; 1116 int opt_libs_static = 0; 1073 1117 1074 1118 number_of_files = 0; … … 1178 1222 case 'A': 1179 1223 number_of_files++; 1180 break;1181 1182 case 129: /* -Bstatic. */1183 /* Ignore. */1184 1224 break; 1185 1225 … … 1271 1311 discard_locals = DISCARD_L; 1272 1312 break; 1313 1314 case OPT_LIBS_STATIC: 1315 case OPT_LIBS_SHARED: 1316 /* processed later */ 1317 break; 1273 1318 } 1274 1319 } … … 1327 1372 case 'A': 1328 1373 if (p != file_table) 1329 usage ("-A specified before an input file other than the first" );1374 usage ("-A specified before an input file other than the first", NULL); 1330 1375 p->filename = optarg; 1331 1376 p->local_sym_name = optarg; … … 1335 1380 1336 1381 case 'l': 1337 p->filename = concat ("", optarg, " .a");1382 p->filename = concat ("", optarg, ""); 1338 1383 p->local_sym_name = concat ("-l", optarg, ""); 1339 1384 p->search_dirs_flag = 1; 1385 p->dynamic = !opt_libs_static; 1340 1386 p++; 1341 1387 break; 1388 1389 case OPT_LIBS_STATIC: 1390 opt_libs_static = 1; 1391 break; 1392 case OPT_LIBS_SHARED: 1393 opt_libs_static = 0; 1394 break; 1342 1395 } 1343 1396 } … … 1398 1451 } 1399 1452 1400 int1453 static int 1401 1454 set_element_prefixed_p (name) 1402 1455 char *name; … … 1419 1472 /* Convenient functions for operating on one or all files being 1420 1473 loaded. */ 1421 void print_file_name ( );1474 void print_file_name (struct file_entry *entry, FILE *outfile); 1422 1475 1423 1476 /* Call FUNCTION on each input file entry. … … 1427 1480 FUNCTION receives two arguments: the entry, and ARG. */ 1428 1481 1429 void1482 static void 1430 1483 each_file (function, arg) 1431 1484 register void (*function)(); … … 1483 1536 /* Like `each_file' but ignore files that were just for symbol definitions. */ 1484 1537 1485 void1538 static void 1486 1539 each_full_file (function, arg) 1487 1540 register void (*function)(); … … 1508 1561 /* Close the input file that is now open. */ 1509 1562 1510 void1563 static void 1511 1564 file_close () 1512 1565 { … … 1520 1573 a new open is not actually done. */ 1521 1574 1522 int1575 static int 1523 1576 file_open (entry) 1524 1577 register struct file_entry *entry; … … 1536 1589 if (entry->search_dirs_flag && n_search_dirs) 1537 1590 { 1591 /* !we're searching for libraries here! */ 1592 static const char *dynamic_suffs[] = { "_dll.a", ".a", ".dll", "_s.a", NULL }; 1593 static const char *static_suffs[] = { "_s.a", ".a", NULL }; 1594 const char **suffs = entry->dynamic ? dynamic_suffs : static_suffs; 1595 int lenname = strlen (entry->filename); 1538 1596 int i; 1539 1597 1540 1598 for (i = 0; i < n_search_dirs; i++) 1541 1599 { 1542 register char *string 1543 = concat (search_dirs[i], "/", entry->filename); 1544 desc = open (string, O_RDONLY|O_BINARY, 0); 1545 1546 if (desc < 0) 1547 { 1548 char *tmp = _getext (entry->filename); 1549 if (tmp && (tolower(tmp[1]) == 'a') && (tmp[2] == 0)) 1600 int lendir = strlen (search_dirs[i]); 1601 register char *string = xmalloc (lendir + lenname + 4 + 6 + 1); 1602 int j; 1603 1604 memcpy (string, search_dirs[i], lendir); 1605 string[lendir++] = '/'; 1606 for (j = 0; suffs[j]; j++) 1550 1607 { 1551 /* Try libxxx */ 1552 free (string); 1553 string = concat (search_dirs[i], "/lib", entry->filename); 1554 desc = open (string, O_RDONLY|O_BINARY, 0); 1555 } 1556 } 1557 if (desc > 0) 1558 { 1559 entry->filename = string; 1560 entry->search_dirs_flag = 0; 1561 break; 1562 } 1608 static const char *prefixes[] = { "lib", ""}; 1609 int k; 1610 for (k = 0; k < sizeof(prefixes) / sizeof(prefixes[0]); k++) 1611 { 1612 int len = strlen (prefixes[k]); 1613 memcpy (string + lendir, prefixes[k], len); 1614 len += lendir; 1615 memcpy (string + len, entry->filename, lenname); 1616 len += lenname; 1617 strcpy (string + len, suffs[j]); 1618 1619 desc = open (string, O_RDONLY|O_BINARY, 0); 1620 if (desc > 0) 1621 { 1622 /* convert? */ 1623 if (check_lx_dll (desc)) 1624 { 1625 string = lx_to_aout (string); 1626 if (!string || (desc = open (string, O_RDONLY|O_BINARY, 0)) < 0) 1627 perror_file (entry); 1628 } 1629 entry->filename = string; 1630 entry->search_dirs_flag = 0; 1631 input_file = entry; 1632 input_desc = desc; 1633 return desc; 1634 } 1635 } /* prefix loop */ 1636 } /* suffix loop */ 1563 1637 free (string); 1564 } 1638 } /* dir loop */ 1565 1639 } 1566 1640 else … … 1816 1890 void 1817 1891 read_entry_strings (desc, entry) 1892 int desc; 1818 1893 struct file_entry *entry; 1819 int desc;1820 1894 { 1821 1895 if (!entry->header_read_flag) … … 1830 1904 /* Read in the symbols of all input files. */ 1831 1905 1832 void read_file_symbols (), read_entry_symbols (), read_entry_strings (); 1833 void enter_file_symbols (), enter_global_ref (), search_library (); 1834 1835 void 1836 load_symbols () 1906 void enter_file_symbols (struct file_entry *entry); 1907 void enter_global_ref (register struct nlist *nlist_p, char *name, struct file_entry *entry); 1908 void search_library (int desc, struct file_entry *entry); 1909 1910 void 1911 load_symbols (void) 1837 1912 { 1838 1913 register int i; … … 2169 2244 /* Searching libraries */ 2170 2245 2171 struct file_entry *decode_library_subfile (); 2172 void linear_library (), symdef_library (); 2246 struct file_entry * decode_library_subfile (int desc, struct file_entry *library_entry, int subfile_offset, int *length_loc); 2247 void symdef_library (int desc, struct file_entry *entry, int member_length); 2248 void linear_library (int desc, struct file_entry *entry); 2173 2249 2174 2250 /* Search the library ENTRY, already open on descriptor DESC. … … 2266 2342 2267 2343 2268 int subfile_wanted_p ( );2344 int subfile_wanted_p (struct file_entry *); 2269 2345 2270 2346 /* Search a library that has a __.SYMDEF member. … … 2557 2633 2558 2634 void 2559 digest_symbols ( )2635 digest_symbols (void) 2560 2636 { 2561 2637 register int i; … … 2996 3072 }; 2997 3073 3074 int next_debug_entry (int use_data_symbols, struct line_debug_entry state_pointer[3]); 3075 struct line_debug_entry * init_debug_scan (int use_data_symbols, struct file_entry *entry); 3076 int address_to_line (unsigned long address, struct line_debug_entry state_pointer[3]); 2998 3077 void qsort (); 2999 3078 /* … … 3232 3311 3233 3312 qsort (reloc_start, reloc_size, sizeof (struct relocation_info), 3234 relocation_entries_relation);3313 (int (*)(const void *, const void *))relocation_entries_relation); 3235 3314 3236 3315 for (reloc = reloc_start; … … 3512 3591 3513 3592 void 3514 initialize_a_out_text_start ( )3593 initialize_a_out_text_start (void) 3515 3594 { 3516 3595 int magic = 0; … … 3562 3641 3563 3642 void 3564 initialize_a_out_data_start ( )3643 initialize_a_out_data_start (void) 3565 3644 { 3566 3645 outheader.a_text = text_size; … … 3572 3651 3573 3652 void 3574 compute_a_out_section_offsets ( )3653 compute_a_out_section_offsets (void) 3575 3654 { 3576 3655 outheader.a_data = data_size; … … 3635 3714 3636 3715 void 3637 compute_more_a_out_section_offsets ( )3716 compute_more_a_out_section_offsets (void) 3638 3717 { 3639 3718 output_symseg_offset = output_strs_offset + output_strs_size; … … 3643 3722 3644 3723 void 3645 write_a_out_header ( )3724 write_a_out_header (void) 3646 3725 { 3647 3726 lseek (outdesc, 0L, 0); … … 3659 3738 3660 3739 void 3661 initialize_text_start ( )3740 initialize_text_start (void) 3662 3741 { 3663 3742 #ifdef A_OUT … … 3675 3754 3676 3755 void 3677 initialize_data_start ( )3756 initialize_data_start (void) 3678 3757 { 3679 3758 #ifdef A_OUT … … 3690 3769 3691 3770 void 3692 compute_section_offsets ( )3771 compute_section_offsets (void) 3693 3772 { 3694 3773 #ifdef A_OUT … … 3705 3784 is finalized. */ 3706 3785 void 3707 compute_more_section_offsets ( )3786 compute_more_section_offsets (void) 3708 3787 { 3709 3788 #ifdef A_OUT … … 3719 3798 /* Write the output file header, once everything is known. */ 3720 3799 void 3721 write_header ( )3800 write_header (void) 3722 3801 { 3723 3802 #ifdef A_OUT … … 3800 3879 3801 3880 void 3802 write_output ( )3881 write_output (void) 3803 3882 { 3804 3883 struct stat statbuf; … … 3982 4061 3983 4062 3984 void modify_location (), perform_relocation (), copy_text (), copy_data (); 4063 void copy_text (struct file_entry *entry); 4064 void copy_data (struct file_entry *entry); 4065 void perform_relocation ( char *data, int pc_relocation, int data_size, 4066 struct relocation_info *reloc_info, int reloc_size, struct file_entry *entry); 3985 4067 3986 4068 /* Relocate the text segment of each input file … … 4007 4089 4008 4090 void 4009 read_relocation ( )4091 read_relocation (void) 4010 4092 { 4011 4093 each_full_file (read_file_relocation, 0); … … 4356 4438 relocating the addresses-to-be-relocated. */ 4357 4439 4358 void coptxtrel (), copdatrel (); 4440 void coptxtrel (struct file_entry *entry); 4441 void copdatrel (struct file_entry *entry); 4359 4442 4360 4443 void … … 4420 4503 RELOC_ADDRESS (&reloc) 4421 4504 = set_sect_start + i * sizeof (unsigned long) - data_start; 4422 mywrite ( (char *)&reloc, sizeof (reloc), 1, outdesc);4505 mywrite (&reloc, sizeof (reloc), 1, outdesc); 4423 4506 break; 4424 4507 case N_ABS: … … 4579 4662 4580 4663 4581 void write_file_syms ( );4582 void write_string_table ( );4664 void write_file_syms (struct file_entry *entry, int *syms_written_addr); 4665 void write_string_table (void); 4583 4666 4584 4667 /* Total size of string table strings allocated so far, … … 4620 4703 4621 4704 void 4622 write_string_table ( )4705 write_string_table (void) 4623 4706 { 4624 4707 register int i; … … 4927 5010 except that we store some information into the beginning of it. */ 4928 5011 4929 void write_file_symseg ( );5012 void write_file_symseg (struct file_entry *entry); 4930 5013 4931 5014 void … … 5153 5236 STRING is a printf format string and ARG is one arg for it. */ 5154 5237 5155 void 5156 fatal (string, arg) 5157 char *string, *arg; 5158 { 5238 void fatal (char *string, ...) 5239 { 5240 va_list args; 5159 5241 fprintf (stderr, "%s: ", progname); 5160 fprintf (stderr, string, arg); 5242 va_start (args, string); 5243 vfprintf (stderr, string, args); 5244 va_end (args); 5161 5245 fprintf (stderr, "\n"); 5162 5246 exit (1); … … 5229 5313 void 5230 5314 mywrite (buf, count, eltsize, desc) 5231 char*buf;5315 void *buf; 5232 5316 int count; 5233 5317 int eltsize; … … 5242 5326 if (val <= 0) 5243 5327 perror_name (output_filename); 5244 buf +=val;5328 buf = (char*)buf + val; 5245 5329 bytes -= val; 5246 5330 } … … 5269 5353 char * 5270 5354 concat (s1, s2, s3) 5271 c har *s1, *s2, *s3;5355 const char *s1, *s2, *s3; 5272 5356 { 5273 5357 register int len1 = strlen (s1), len2 = strlen (s2), len3 = strlen (s3); … … 5288 5372 int 5289 5373 parse (arg, format, error) 5290 char *arg, *format ;5374 char *arg, *format, *error; 5291 5375 { 5292 5376 int x; … … 5310 5394 /* Like realloc but get fatal error if memory is exhausted. */ 5311 5395 5312 char*5396 void * 5313 5397 xrealloc (ptr, size) 5314 char*ptr;5398 void *ptr; 5315 5399 int size; 5316 5400 { … … 5413 5497 } 5414 5498 5499 5500 /** 5501 * Checks if the file FD is an LX DLL. 5502 * 5503 * @returns 1 if LX DLL. 5504 * @returns 0 if not LX DLL. 5505 * @param fd Handle to file to check. 5506 */ 5507 int check_lx_dll(int fd) 5508 { 5509 unsigned long ul; 5510 char achMagic[2]; 5511 5512 if ( lseek(fd, 0, SEEK_SET) 5513 || read(fd, &achMagic, 2) != 2) 5514 goto thats_not_it; 5515 5516 if (!memcmp(achMagic, "MZ", 2)) 5517 { 5518 if ( lseek(fd, 0x3c, SEEK_SET) 5519 || read(fd, &ul, 4) != 4 /* offset of the 'new' header */ 5520 || ul < 0x40 5521 || ul >= 0x10000000 /* 512MB stubs sure */ 5522 || lseek(fd, ul, SEEK_SET) 5523 || read(fd, &achMagic, 2) != 2) 5524 goto thats_not_it; 5525 } 5526 5527 if ( memcmp(achMagic, "LX", 2) 5528 || lseek(fd, 14, SEEK_CUR) 5529 || read(fd, &ul, 4) != 4) /*e32_mflags*/ 5530 goto thats_not_it; 5531 5532 #define E32MODDLL 0x08000L 5533 #define E32MODPROTDLL 0x18000L 5534 #define E32MODMASK 0x38000L 5535 if ( (ul & E32MODMASK) != E32MODDLL 5536 && (ul & E32MODMASK) != E32MODPROTDLL) 5537 goto thats_not_it; 5538 5539 /* it's a LX DLL! */ 5540 lseek(fd, 0, SEEK_SET); 5541 return 1; 5542 5543 5544 thats_not_it: 5545 lseek(fd, 0, SEEK_SET); 5546 return 0; 5547 } 5548 5549 5415 5550 /* atexit worker */ 5416 5551 void cleanup (void) -
Property cvs2svn:cvs-rev
changed from
Note:
See TracChangeset
for help on using the changeset viewer.