Changeset 653
- Timestamp:
- Sep 7, 2003, 11:10:32 AM (22 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/emx/src/emxomf/emxomfld.c
-
Property cvs2svn:cvs-rev
changed from
1.26
to1.27
r652 r653 117 117 118 118 /* Weak alias object file. */ 119 static char weakobj_fname[_MAX_PATH ];119 static char weakobj_fname[_MAX_PATH + 1]; 120 120 121 121 /* Weak definition file (modified def_fname). */ 122 static char weakdef_fname[_MAX_PATH ];122 static char weakdef_fname[_MAX_PATH + 1]; 123 123 124 124 /* Non-zero if debugging information is to be omitted. Set by the -s … … 460 460 for (list = libdirs; list != NULL; list = list->next) 461 461 { 462 if ( tmp[len-1] != ';')462 if (list != libdirs && tmp[len-1] != ';') 463 463 tmp[len++] = ';'; 464 464 strcpy (tmp+len, list->name); … … 486 486 } 487 487 488 489 /* finds the full path of a library or object file, after check 490 default extentions an such. 491 492 Object files will be searched for using the LIB env.var if not found. 493 494 Library hacks: 495 1. file with .lib extention. 496 2. file with .lib extention and lib prefix. 497 3. file with .a extention which is an OMF library. 498 4. file with .a extention and lib prefix which is an OMF library. 499 */ 500 501 static FILE * find_objlib2(char *pszfullname, const char *pszname, const char * const *papszexts, int flibhacks) 502 { 503 const char * psz; 504 char * psz2; 505 int cch; 506 int i; 507 int fextension; 508 FILE * phFile; 509 char cchname = strlen (pszname); 510 511 /* Plain name first - the easist option */ 512 memcpy (pszfullname, pszname, cchname + 1); 513 phFile = fopen (pszfullname, "rb"); 514 if (phFile) 515 return phFile; 516 517 /* Plain name with all extentions. */ 518 psz = strrchr (pszname, '.'); 519 fextension = (psz && !strpbrk (psz, ":\\/")); 520 if (!fextension) 521 { 522 psz2 = pszfullname + cchname; 523 for (i = 0; papszexts[i]; i++) 524 { 525 strcpy (psz2, papszexts[i]); 526 phFile = fopen (pszfullname, "rb"); 527 if (phFile) 528 return phFile; 529 } 530 } 531 532 /* Search LIBS. */ 533 if (!strpbrk (pszname, ":\\/")) 534 { 535 int ffound; 536 const char * pszend; 537 for (psz = getenv("LIB"), ffound = 0; !ffound && psz; psz = pszend + (pszend != NULL)) 538 { 539 pszend = strchr(psz, ';'); 540 if (pszend <= psz) 541 continue; 542 543 /* normalize the name */ 544 cch = pszend - psz; 545 memcpy(pszfullname, psz, pszend - psz); 546 if ( pszfullname[cch-1] != '\\' 547 && pszfullname[cch-1] != '/' 548 && pszfullname[cch-1] != ':') 549 pszfullname[cch++] = '\\'; 550 memcpy(pszfullname + cch, pszname, cchname + 1); 551 552 if (!fextension) 488 /* Check if the given file is a valid OMF library. */ 489 490 static int check_omf_library (FILE *f) 491 { 492 #pragma pack(1) 493 struct 494 { 495 byte rec_type; 496 word rec_len; 497 dword dict_offset; 498 word dict_blocks; 499 byte flags; 500 } libhdr; 501 #pragma pack() 502 503 if (fread (&libhdr, 1, sizeof(libhdr), f) == sizeof (libhdr) 504 && libhdr.rec_type == LIBHDR 505 && libhdr.flags <= 1 /* ASSUME only first bit is used... */ 506 && !fseek (f, 0, SEEK_SET)) 507 { 508 int page_size = libhdr.rec_len + 3; 509 if (page_size >= 16 510 && page_size <= 32768 511 && !(page_size & (page_size - 1)) != 0) 512 return 1; 513 } 514 515 return 0; 516 } 517 518 /* finds the full path of a library or object file. 519 520 Object files and libraries will be searched for using the LIB env.var 521 (which is exported so that it is used by ILINK/LINK386 as well), 522 if not found by their path directly. Note that finding object files in 523 the LIB paths contradicts the standard Unix behaviour, so it is a kind 524 of a hack, but this is the way ILINK and LINK386 work. 525 526 If file has no extension, the .obj and .o extensions are tried in turn 527 for object files, and .lib then .a are tried in turn for libraries. 528 Additionaly, for libraries we check for a file with the 'lib' prefix, 529 if one without the 'lib' prefix was not found. The '.o' and '.a' 530 extensions are tried in the last case since otherwise we can find 531 a 'something.a' when 'libsomething.lib' is available. 532 */ 533 534 static FILE *find_objlib (char *fullname, const char *name, int is_library) 535 { 536 const char *exts [2][2] = { { ".obj", ".o" }, { ".lib", ".a" } }; 537 FILE *f; 538 size_t pathlen, namelen = strlen (name); 539 char *libpath, *x; 540 int i, has_ext = 0, has_path; 541 542 /* Check if the file name has a path. If it has, we won't check the 543 LIB directories, and won't check if it has a object file extension. */ 544 has_path = (strpbrk (name, ":/\\") != NULL); 545 if (has_path) 546 has_ext = 1; 547 else 548 { 549 /* Check if file has a real extension. If it is a object file it should 550 have either .o or .obj, and if it is a library it should have either 551 the .a or .lib extension. Otherwise we don't consider it a extension. */ 552 x = strrchr (name, '.'); 553 if (x) 554 for (i = 0; i < 2; i++) 555 if (strcmp (x, exts [is_library][i]) == 0) 553 556 { 554 /* search thru extensions. */ 555 for (i = 0; papszexts[i]; i++) 557 has_ext = 1; 558 break; 559 } 560 } 561 562 /* First loop search file name as-is, then search the paths 563 in the LIB environment variable. */ 564 libpath = getenv ("LIB"); 565 pathlen = 0; 566 do 567 { 568 /* Step 0: check path+filename (+'.obj/.lib' if !has_ext) 569 * Step 1: if is_library check path+'lib'+filename (+'.lib' if !has_ext) 570 * Step 2: check path+filename (+'.o/.a' if !has_ext) 571 * Step 3: if is_library check path+'lib'+filename (+'.a' if !has_ext) 572 */ 573 for (i = 0; i < 4; i++) 574 { 575 char *cur = fullname + pathlen; 576 577 if ((i & 1) && !is_library) 578 continue; 579 580 if (i & 1) 581 { 582 memcpy (cur, "lib", 3); 583 cur += 3; 584 } 585 586 /* Include final zero in the case we won't append the extension */ 587 memcpy (cur, name, namelen + 1); 588 cur += namelen; 589 590 if (!has_ext) 591 { 592 strcpy (cur, exts [is_library][i/2]); 593 cur = strchr (cur, 0); 594 } 595 596 f = fopen (fullname, "rb"); 597 if (f) 598 { 599 if (is_library && !check_omf_library (f)) 600 fclose (f); 601 else 556 602 { 557 strcpy(pszfullname + cch + cchname, papszexts[i]); 558 phFile = fopen (pszfullname, "rb"); 559 if (phFile) 560 break; 561 if (flibhacks) 562 { 563 memcpy(pszfullname + cch, "lib", 3); 564 memcpy(pszfullname + cch + 3, pszname, cchname); 565 strcpy(pszfullname + cch + 3 + cchname, papszexts[i]); 566 phFile = fopen (pszfullname, "rb"); 567 if (phFile) 568 break; 569 memcpy(pszfullname + cch, pszname, cchname + 1); 570 } 603 /* Replace forward slashes with backslashes 604 since Knut likes them :) */ 605 while ((fullname = strchr (fullname, '/')) != NULL) 606 *fullname++ = '\\'; 607 return f; 571 608 } 572 609 } 573 else 574 phFile = fopen (pszfullname, "rb"); 575 576 if (!flibhacks && phFile) 577 return phFile; 578 579 if (phFile) 580 { 581 #pragma pack(1) 582 struct 583 { 584 byte rec_type; 585 word rec_len; 586 dword dict_offset; 587 word dict_blocks; 588 byte flags; 589 } libhdr; 590 #pragma pack() 591 /* For .a libraries we will chech for a valid OMF library header. */ 592 if (memicmp(pszfullname + strlen(pszfullname) - 2, ".a", 3)) 593 return phFile; 594 if ( fread(&libhdr, 1, sizeof(libhdr), phFile) == sizeof(libhdr) 595 && libhdr.rec_type == LIBHDR 596 && libhdr.flags <= 1 /* ASSUME only first bit is used... */ 597 && !fseek(phFile, 0, SEEK_SET) 598 ) 599 { 600 int page_size = libhdr.rec_len + 3; 601 if ( page_size >= 16 602 && page_size <= 32768 603 && !(page_size & (page_size - 1)) != 0) 604 return phFile; 605 } 606 fclose(phFile); 607 phFile = NULL; 608 } 609 } /* foreach path in $LIB */ 610 } 611 strcpy(pszfullname, pszname); 610 } 611 612 if (!libpath || has_path) 613 break; 614 615 /* Find where next LIB component ends */ 616 x = strchr (libpath, ';'); 617 if (!x) x = strchr (libpath, 0); 618 pathlen = x - libpath; 619 620 if (pathlen) 621 { 622 memcpy (fullname, libpath, pathlen); 623 /* Append last slash if it is not there */ 624 if (fullname [pathlen - 1] != '/' 625 && fullname [pathlen - 1] != '\\') 626 fullname [pathlen++] = '\\'; 627 } 628 629 /* Advance past ';' in LIB */ 630 libpath = x + 1; 631 } while (*x); 632 612 633 return NULL; 613 634 } 614 615 616 /* Wrapper around find_objlib which fixes the slashes - this looks better imho. */617 618 static FILE * find_objlib(char *pszfullname, const char *pszname, const char * const *papszexts, int flibhacks)619 {620 FILE * phFile = find_objlib2(pszfullname, pszname, papszexts, flibhacks);621 while ((pszfullname = strchr(pszfullname, '/')) != NULL)622 *pszfullname++ = '\\';623 return phFile;624 }625 626 627 635 628 636 /* Weak prelinking for Method 2 Weak support. */ … … 674 682 name_list * pcur; 675 683 FILE *phfile; 676 char szname[_MAX_PATH ];684 char szname[_MAX_PATH + 1]; 677 685 678 686 /* definition file if any */ … … 686 694 for (pcur = obj_fnames; !rc && pcur; pcur = pcur->next) 687 695 { 688 static const char * objexts[] = { ".obj", ".o", NULL }; 689 phfile = find_objlib (szname, pcur->name, objexts, TRUE); 696 phfile = find_objlib (szname, pcur->name, FALSE); 690 697 rc = WLDAddObject (pwld, phfile, szname); 691 698 } … … 694 701 for (pcur = lib_fnames; !rc && pcur; pcur = pcur->next) 695 702 { 696 static const char * libexts[] = { ".lib", ".a", NULL }; 697 phfile = find_objlib (szname, pcur->name, libexts, TRUE); 703 phfile = find_objlib (szname, pcur->name, TRUE); 698 704 rc = WLDAddLibrary (pwld, phfile, szname); 699 705 free(pcur->name); … … 895 901 char tmp[512], *t; 896 902 char execname[512]; 903 name_list *pcur; 897 904 898 905 /* Get options from response files (@filename) and wildcard (*.o) on the command. */ … … 1116 1123 "*** Linker type: %s\n", linker_name, linker_type); 1117 1124 1118 1125 /* apply library hacks */ 1126 for (pcur = lib_fnames, rc = 0; !rc && pcur; pcur = pcur->next) 1127 { 1128 char szname[_MAX_PATH + 1]; 1129 FILE *phfile = find_objlib (szname, pcur->name, TRUE); 1130 if (!phfile) 1131 continue; 1132 free (pcur->name); 1133 pcur->name = xstrdup(szname); 1134 fclose(phfile); 1135 } 1119 1136 1120 1137 /* Do the weak prelinking unless GCC_WEAKSYMS are set. … … 1123 1140 if (!getenv("GCC_WEAKSYMS")) 1124 1141 weak_prelink (); 1125 else1126 {1127 /* apply library hacks */1128 name_list *pcur;1129 for (pcur = lib_fnames; !rc && pcur; pcur = pcur->next)1130 {1131 static const char * libexts[] = { ".lib", ".a", NULL };1132 char szname[_MAX_PATH];1133 FILE *phfile = find_objlib (szname, pcur->name, libexts, TRUE);1134 if (!phfile)1135 continue;1136 free(pcur->name);1137 pcur->name = xstrdup(szname);1138 fclose(phfile);1139 }1140 1141 }1142 1142 1143 1143 /* Start building the linker command line. We can use a response -
Property cvs2svn:cvs-rev
changed from
Note:
See TracChangeset
for help on using the changeset viewer.