Changeset 485
- Timestamp:
- Jul 30, 2003, 8:10:01 PM (22 years ago)
- Location:
- trunk/src/emx/src/emxomf
- Files:
-
- 2 added
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/emx/src/emxomf/emxomf.c
-
Property cvs2svn:cvs-rev
changed from
1.17
to1.18
r484 r485 1110 1110 add_extdef (&started, str_ptr + sym_ptr[i].n_un.n_strx); 1111 1111 } 1112 else if (sym_ptr[i].n_type >= N_WEAKA && sym_ptr[i].n_type <= N_WEAKB) 1113 { /* Not convinced about this yet, I mean there should really be 1114 external records for this, perhaps... 1115 At least I can't see why this will be wrong. */ 1116 name = str_ptr + sym_ptr[i].n_un.n_strx; 1117 sym_more[i].index = sym_index++; 1118 add_extdef (&started, name); 1119 } 1112 1120 if (started) 1113 1121 write_rec (); … … 1147 1155 mark it as N_WEAKU so that it is later writen within a WKEXT record. 1148 1156 Also we convert a.out-style weak symbols here as normal public symbols, 1149 as the sense of weak is reverse in OMF */ 1157 as the sense of weak is reverse in OMF 1158 1159 Weak Hack Method 1. 1160 */ 1150 1161 1151 1162 static void weak_process (void) … … 1184 1195 } 1185 1196 } 1197 #if 0 1186 1198 else if ((sym_ptr[i].n_type & N_EXT) && is_weak (str_ptr + sym_ptr[i].n_un.n_strx)) 1187 1199 { … … 1193 1205 /*SETTYPE (N_WEAKU);*/ 1194 1206 } 1195 1207 #endif 1196 1208 #undef SETTYPE 1197 1209 } … … 1211 1223 * @param cchName Size of the buffer pointed to by pachName. 1212 1224 * @remark I'm sorry this function is written in my coding style - not! 1225 * @remark Weak Hack Method 2. 1213 1226 */ 1214 1227 static const char *weak_process_name(const struct nlist *pSym, const char *pszOrgName, char *pachName, int cchName) … … 1217 1230 { 1218 1231 /* 1219 * Hmmm... Check that we handle this correctly else where1232 * Weak external. 1220 1233 */ 1221 1234 case N_WEAKU: /* 0x0d Weak undefined symbol. */ -
Property cvs2svn:cvs-rev
changed from
-
trunk/src/emx/src/emxomf/emxomf.smak
-
Property cvs2svn:cvs-rev
changed from
1.7
to1.8
r484 r485 20 20 .TARGET := emxomfld.exe 21 21 .TKIND := $(TOOLFMT) 22 .TSRC := src/emxomf/emxomfld.c22 .TSRC := $(addprefix src/emxomf/,emxomfld.c grow.c weakld.c) 23 23 .TCF := $(CFLAGS.DEF.VERSION) 24 24 .TDEP := @O@moddef$A -
Property cvs2svn:cvs-rev
changed from
-
trunk/src/emx/src/emxomf/emxomfld.c
-
Property cvs2svn:cvs-rev
changed from
1.11
to1.12
r484 r485 36 36 #include <sys/omflib.h> 37 37 #include "defs.h" 38 #include "weakld.h" 38 39 39 40 #define FALSE 0 … … 109 110 static FILE *response_file = NULL; 110 111 112 /* Weak alias object file. */ 113 static char weakobj_fname[_MAX_PATH]; 114 111 115 /* Non-zero if debugging information is to be omitted. Set by the -s 112 116 and -S options. */ … … 132 136 133 137 static void usage (void) NORETURN2; 134 static void *xmalloc (size_t n); 135 static char *xstrdup (const char *s); 138 extern void *xmalloc (size_t n); 139 extern void *xrealloc (void *ptr, size_t n); 140 extern char *xstrdup (const char *s); 136 141 static void add_name_list (name_list ***add, const char *src); 137 142 static void conv_path (char *name); … … 156 161 static void usage (void) 157 162 { 158 fprintf (stderr, "emxomfld " VERSION INNOTEK_VERSION " -- " 159 "Copyright (c) 1992-1996 by Eberhard Mattes\n\n"); 163 fprintf (stderr, "emxomfld " VERSION INNOTEK_VERSION "\n" 164 "Copyright (c) 1992-1996 by Eberhard Mattes\n" 165 "Copyright (c) 2003 by InnoTek Systemberatung GmbH\n\n"); 166 160 167 fprintf (stderr, 161 168 "Usage: emxomfld -o <file> [-l <lib>] [-L <libdir>] [-T <base>] [-sS]\n" … … 169 176 used like malloc(), but we don't have to check the return value. */ 170 177 171 staticvoid *xmalloc (size_t n)178 void *xmalloc (size_t n) 172 179 { 173 180 void *p; … … 181 188 return p; 182 189 } 190 191 192 /* Change the allocation of PTR to N bytes. Quit on failure. This 193 function is used like realloc(), but we don't have to check the 194 return value. */ 195 196 void *xrealloc (void *ptr, size_t n) 197 { 198 void *p; 199 200 p = realloc (ptr, n); 201 if (p == NULL) 202 { 203 fprintf (stderr, "emxomfld: out of memory\n"); 204 exit (2); 205 } 206 return p; 207 } 208 183 209 184 210 … … 187 213 return value. */ 188 214 189 staticchar *xstrdup (const char *s)215 char *xstrdup (const char *s) 190 216 { 191 217 char *p; … … 387 413 388 414 389 /* Put a list of library arguments on to the command line or into the390 response file. Filenames without path and extension will be 'resolved'391 using libdirs and the LIB environment variable and a '.lib' extension.392 If not found a search for a 'lib' prefixed filename is attempted, if393 still not found we'll let link386 do the complaining and pass filename394 unresolved to link386.395 396 The motivation for doing this is to have the same behaviour of ld and397 emxomfld which allows us to lax the libsomething.lib to something.lib398 renaming and addapt to the gcc/unix library naming standards.399 (see Innotek Defect #416)400 401 Note. make_env () *must* be called before this function is called. */402 403 static void put_lib_args(const name_list *list)404 {405 const char *pszLib = getenv ("LIB");406 for (;list != NULL; list = list->next)407 {408 char szFilename[260];409 int fFound = 0;410 411 if (!strpbrk (list->name, ":\\/."))412 { /* search for it */413 const char *psz, *pszEnd;414 for (psz = pszLib; !fFound && psz; psz = pszEnd + (pszEnd != NULL))415 {416 pszEnd = strchr(psz, ';');417 if (pszEnd > psz)418 {419 int cchPath = pszEnd - psz;420 struct stat s;421 422 strncpy(szFilename, psz, pszEnd - psz);423 if ( szFilename[cchPath-1] != '\\'424 && szFilename[cchPath-1] != '/'425 && szFilename[cchPath-1] != ':')426 szFilename[cchPath++] = '\\';427 428 /* Files we're looking for:429 * 1. file with .lib extention.430 * 2. file with .lib extention and lib prefix.431 * 3. file with .a extention which is an OMF library.432 * 4. file with .a extention and lib prefix which is an OMF library.433 */434 strcat(strcpy(szFilename + cchPath, list->name), ".lib");435 fFound = !stat(szFilename, &s);436 if (!fFound)437 {438 strcat(strcpy(strcpy(szFilename + cchPath, "lib") + 3, list->name), ".lib");439 fFound = !stat(szFilename, &s);440 if (!fFound)441 {442 strcat(strcpy(szFilename + cchPath, list->name), ".a");443 fFound = !stat(szFilename, &s);444 if (!fFound)445 {446 strcat(strcpy(strcpy(szFilename + cchPath, "lib") + 3, list->name), ".a");447 fFound = !stat(szFilename, &s);448 }449 /*450 * Is this an OMF library?451 * We will open it hand do some verification of the LIBHDR.452 */453 if (fFound)454 {455 FILE *pFile = fopen(szFilename, "rb");456 fFound = 0;457 if (pFile)458 {459 #pragma pack(1)460 struct461 {462 byte rec_type;463 word rec_len;464 dword dict_offset;465 word dict_blocks;466 byte flags;467 } libhdr;468 #pragma pack()469 if ( fread(&libhdr, 1, sizeof(libhdr), pFile) == sizeof(libhdr)470 && libhdr.rec_type == LIBHDR471 && libhdr.flags <= 1 /* ASSUME only first bit is used... */472 )473 {474 int page_size = libhdr.rec_len + 3;475 if ( page_size >= 16476 && page_size <= 32768477 && !(page_size & (page_size - 1)) != 0)478 fFound = 1;479 }480 fclose(pFile);481 }482 }483 }484 }485 }486 } /* foreach path in $LIB */487 }488 489 put_arg (fFound ? szFilename : list->name, TRUE, TRUE);490 //fprintf(stderr, "%s -> %s\n", list->name, fFound ? szFilename : strpbrk(list->name, ":\\/.") ? "not searched for" : "not found");491 } /* foreach list entry */492 }493 494 495 415 /* Build the environment for LINK386: define the LIB environment 496 416 variable. */ … … 536 456 537 457 458 /* finds the full path of a library or object file, after check 459 default extentions an such. 460 461 Object files will be searched for using the LIB env.var if not found. 462 463 Library hacks: 464 1. file with .lib extention. 465 2. file with .lib extention and lib prefix. 466 3. file with .a extention which is an OMF library. 467 4. file with .a extention and lib prefix which is an OMF library. 468 */ 469 470 static FILE * find_objlib(char *pszfullname, const char *pszname, 471 const char * const *papszexts, int flibhacks) 472 { 473 const char * psz; 474 char * psz2; 475 int cch; 476 int i; 477 int fextension; 478 FILE * phFile; 479 char cchname = strlen (pszname); 480 481 /* Plain name first - the easist option */ 482 memcpy (pszfullname, pszname, cchname + 1); 483 phFile = fopen (pszfullname, "rb"); 484 if (phFile) 485 return phFile; 486 487 /* Plain name with all extentions. */ 488 psz = strrchr (pszname, '.'); 489 fextension = (psz && !strpbrk (psz, ":\\/")); 490 if (!fextension) 491 { 492 psz2 = pszfullname + cchname; 493 for (i = 0; papszexts[i]; i++) 494 { 495 strcpy (psz2, papszexts[i]); 496 phFile = fopen (pszfullname, "rb"); 497 if (phFile) 498 return phFile; 499 } 500 } 501 502 /* Search LIBS. */ 503 if (!strpbrk (pszname, ":\\/")) 504 { 505 int ffound; 506 const char * pszend; 507 for (psz = getenv("LIB"), ffound = 0; !ffound && psz; psz = pszend + (pszend != NULL)) 508 { 509 pszend = strchr(psz, ';'); 510 if (pszend <= psz) 511 continue; 512 513 /* normalize the name */ 514 cch = pszend - psz; 515 strncpy(pszfullname, psz, pszend - psz); 516 if ( pszfullname[cch-1] != '\\' 517 && pszfullname[cch-1] != '/' 518 && pszfullname[cch-1] != ':') 519 pszfullname[cch++] = '\\'; 520 memcpy(pszfullname + cch, pszname, cchname + 1); 521 522 if (!fextension) 523 { 524 /* search thru extensions. */ 525 for (i = 0; papszexts[i]; i++) 526 { 527 strcpy(pszfullname + cch + cchname, papszexts[i]); 528 phFile = fopen (pszfullname, "rb"); 529 if (phFile) 530 break; 531 if (flibhacks) 532 { 533 memcpy(pszfullname + cch, "lib", 3); 534 memcpy(pszfullname + cch, pszname, cchname); 535 strcpy(pszfullname + cch + cchname, papszexts[i]); 536 phFile = fopen (pszfullname, "rb"); 537 if (phFile) 538 break; 539 memcpy(pszfullname + cch, pszname, cchname + 1); 540 } 541 } 542 } 543 else 544 phFile = fopen (pszfullname, "rb"); 545 546 if (phFile) 547 { 548 #pragma pack(1) 549 struct 550 { 551 byte rec_type; 552 word rec_len; 553 dword dict_offset; 554 word dict_blocks; 555 byte flags; 556 } libhdr; 557 #pragma pack() 558 if (!flibhacks) 559 return phFile; 560 /* For .a libraries we will chech for a valid OMF library header. */ 561 if (memicmp(pszfullname + strlen(pszfullname) - 2, ".a", 3)) 562 return phFile; 563 if ( fread(&libhdr, 1, sizeof(libhdr), phFile) == sizeof(libhdr) 564 && libhdr.rec_type == LIBHDR 565 && libhdr.flags <= 1 /* ASSUME only first bit is used... */ 566 ) 567 { 568 int page_size = libhdr.rec_len + 3; 569 if ( page_size >= 16 570 && page_size <= 32768 571 && !(page_size & (page_size - 1)) != 0) 572 return phFile; 573 } 574 fclose(phFile); 575 phFile = NULL; 576 } 577 } /* foreach path in $LIB */ 578 } 579 return NULL; 580 } 581 582 583 /* Weak prelinking for Method 2 Weak support. */ 584 585 static void weak_prelink () 586 { 587 int rc = 0; 588 PWLD pwld; 589 590 pwld = wld_create (0); 591 if (pwld) 592 { 593 name_list * pcur; 594 FILE *phfile; 595 char szname[_MAX_PATH]; 596 597 /* objects */ 598 for (pcur = obj_fnames; !rc && pcur; pcur = pcur->next) 599 { 600 static const char * objexts[] = { ".obj", ".o", NULL }; 601 phfile = find_objlib (szname, pcur->name, objexts, TRUE); 602 rc = wld_add_object (pwld, phfile, szname); 603 } 604 605 /* definition file if any */ 606 if (def_fname && def_fname[0]) 607 { 608 phfile = fopen (def_fname, "r"); 609 rc = wld_add_deffile (pwld, phfile, def_fname); 610 } 611 612 /* libraries */ 613 for (pcur = lib_fnames; !rc && pcur; pcur = pcur->next) 614 { 615 static const char * libexts[] = { ".lib", ".a", NULL }; 616 phfile = find_objlib (szname, pcur->name, libexts, TRUE); 617 rc = wld_add_library (pwld, phfile, szname); 618 free(pcur->name); 619 pcur->name = xstrdup(szname); 620 } 621 622 /* generate weak aliases. */ 623 if (!rc) 624 rc = wld_generate_weakobj (pwld, weakobj_fname); 625 if (!rc && weakobj_fname[0]) 626 add_name_list (&add_obj_fnames, weakobj_fname); 627 628 /* cleanup the linker */ 629 wld_destroy (pwld); 630 } 631 else 632 { 633 rc = 8; 634 fprintf (stderr, "emxomfld: failed to create weak linker.\n"); 635 } 636 637 if (rc) 638 exit(rc); 639 } 640 641 538 642 /* Start a new set of command line arguments. If RSP is non-zero, we 539 643 are allowed to use a response file. */ … … 575 679 response_file = NULL; 576 680 } 577 if (response_fname[0] != 0)681 if (response_fname[0] != '\0') 578 682 { 579 683 remove (response_fname); 580 response_fname[0] = 0; 684 response_fname[0] = '\0'; 685 } 686 if (weakobj_fname[0] != '\0') 687 { 688 remove (weakobj_fname); 689 weakobj_fname[0] = '\0'; 581 690 } 582 691 } … … 790 899 } 791 900 792 t = getenv ("EMXOMFLD_LINKER"); 793 if (t != NULL) 794 linker_name = t; 795 796 /* Build the environment for LINK386. 797 This must be done before calling put_lib_args (). */ 901 /* Build the environment for LINK386. */ 798 902 799 903 make_env (); 904 905 /* Do the weak prelinking unless GCC_WEAKSYMS are set. 906 Important that this is done after make_env(). */ 907 908 if (!getenv("GCC_WEAKSYMS")) 909 weak_prelink (); 910 else 911 { 912 /* apply library hack */ 913 name_list *pcur; 914 for (pcur = lib_fnames; !rc && pcur; pcur = pcur->next) 915 { 916 static const char * libexts[] = { ".lib", ".a", NULL }; 917 char szname[_MAX_PATH]; 918 FILE *phfile = find_objlib (szname, pcur->name, libexts, TRUE); 919 if (!phfile) 920 continue; 921 free(pcur->name); 922 pcur->name = xstrdup(szname); 923 } 924 925 } 926 800 927 801 928 /* Start building the LINK386 command line. We can use a response … … 829 956 */ 830 957 958 t = getenv ("EMXOMFLD_LINKER"); 959 if (t != NULL) 960 linker_name = t; 831 961 put_arg (linker_name, TRUE, FALSE); 832 962 … … 914 1044 /* Put the library file names onto the command line. */ 915 1045 916 put_ lib_args (lib_fnames);1046 put_args (lib_fnames, TRUE); 917 1047 put_arg (",", FALSE, FALSE); 918 1048 -
Property cvs2svn:cvs-rev
changed from
-
trunk/src/emx/src/emxomf/grow.c
-
Property cvs2svn:cvs-rev
changed from
1.1
to1.2
r484 r485 332 332 return strpool_addn (p, s, strlen (s)); 333 333 } 334 335 336 /* Add the string S of LEN characters to the string pool P. The 337 string must not contain null characters. A pointer to a string of 338 the string pool is returned. If a string identical to S already 339 exists in the string pool, a pointer to that string is returned. 340 Otherwise, a new string entry is added to the string pool. */ 341 342 const char *strpool_look (struct strpool *p, const char *s, int len) 343 { 344 unsigned hash; 345 int i; 346 struct string *v; 347 348 hash = 0; 349 for (i = 0; i < len; ++i) 350 hash = hash * 65599 + s[i]; 351 hash %= STRPOOL_HASH_SIZE; 352 for (v = p->table[hash]; v != NULL; v = v->next) 353 if (strlen (v->string) == len && memcmp (v->string, s, len) == 0) 354 return v->string; 355 v = xmalloc (sizeof (*v) + len); 356 memcpy (v->string, s, len); 357 v->string[len] = 0; 358 v->next = p->table[hash]; 359 p->table[hash] = v; 360 return v->string; 361 } 362 -
Property cvs2svn:cvs-rev
changed from
Note:
See TracChangeset
for help on using the changeset viewer.