Changeset 60
- Timestamp:
- Apr 29, 2003, 6:13:11 PM (22 years ago)
- Location:
- trunk/src/emx/src/emxomf
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/emx/src/emxomf/emxomf.c
-
Property cvs2svn:cvs-rev
changed from
1.1
to1.2
r59 r60 25 25 #include <stdarg.h> 26 26 #include <string.h> 27 #include <alloca.h> 28 #include <ctype.h> 27 29 #include <getopt.h> 28 30 #include <sys/param.h> … … 125 127 }; 126 128 129 /* This structure keeps track which weak symbol and where it is defined, 130 to simulate weak symbols in OMF (which aren't supported in OMF) */ 131 132 struct weaksym 133 { 134 struct weaksym *next; /* Next weak symbol in chain */ 135 char *name; /* Symbol name */ 136 char *module; /* Object file where it should be defined */ 137 int used; /* 1 if the symbol has been encountered */ 138 }; 139 127 140 128 141 /* The number of symbols in the a.out file. */ … … 237 250 static int opt_x = FALSE; 238 251 252 /* Suppress reading and/or writing of the weaksyms.omf file */ 253 static int opt_w = FALSE; 254 255 /* Remove underscores from all symbol names */ 256 static int opt_rmunder = FALSE; 257 239 258 /* This is the page size for OMF libraries. It is set by the -p 240 259 option. */ … … 258 277 /* The index of the "WEAK$ZERO" symbol or 0. */ 259 278 static int weak_zero_index; 279 280 /* The list of currently known OMF symbols */ 281 static struct weaksym *weak_symbol_list; 282 static struct weaksym **weak_symbol_top = &weak_symbol_list; 283 284 /* 1 whenever the weak symbol list has been altered */ 285 static int weak_list_altered; 286 287 /* The file name of the weak symbol list file */ 288 static char *weak_list_filename; 260 289 261 290 /* OMF name indices: segments, classes, groups, etc. */ … … 348 377 /* The name of the identifier manipulation DLL. If this variable is 349 378 NULL, no IDMDLL record is written. */ 350 static char *idmdll_name = "GPP DEMID";379 static char *idmdll_name = "GPP3DEM"; 351 380 352 381 /* If this variable is TRUE (-b option), we always use the 32-bit … … 499 528 500 529 530 /* Check if we should remove the leading underscore from a symbol name */ 531 static inline int strip_underscore (const char *name) 532 { 533 if (!opt_rmunder) 534 return 0; 535 536 return (*name == '_'); 537 } 538 539 501 540 /* Find an a.out symbol. The underscore character `_' is prepended to 502 541 NAME. On success, a pointer to the symbol table entry (in the … … 506 545 const struct nlist *find_symbol (const char *name) 507 546 { 508 int i, j, n, len, ok,t;547 int i, j, n, len, t; 509 548 const byte *s; 510 549 … … 515 554 while (i < str_size) 516 555 { 517 ok = TRUE; s = name; 518 if (str_ptr[i] == '_') 556 int sym_ofs = i; 557 s = name; 558 if (strip_underscore (str_ptr + i)) 519 559 ++i; 520 else 521 ok = FALSE; 522 if (ok && memcmp (name, str_ptr+i, len+1) == 0) 560 if (memcmp (name, str_ptr+i, len+1) == 0) 523 561 { 524 562 … … 527 565 528 566 n = sym_count; 529 --i; /* Move back to the underscore */530 567 for (j = 0; j < n; ++j) 531 if (sym_ptr[j].string == i)568 if (sym_ptr[j].string == sym_ofs) 532 569 { 533 570 t = sym_ptr[j].type & ~N_EXT; … … 540 577 } 541 578 return NULL; /* Symbol not found */ 579 } 580 581 582 /* Add a symbol to weak symbol list */ 583 584 static struct weaksym *add_weak (const char *symname, const char *modname) 585 { 586 struct weaksym *newsym = malloc (sizeof (struct weaksym)); 587 newsym->name = xstrdup (symname); 588 newsym->module = xstrdup (modname); 589 newsym->used = 0; 590 newsym->next = NULL; 591 *weak_symbol_top = newsym; 592 weak_symbol_top = &newsym->next; 593 weak_list_altered = 1; 594 return newsym; 595 } 596 597 598 /* Load the weak symbols table from the weaksyms.omf file. 599 * We emulate the weak symbol functionality in the following way: 600 * first time we encounter a weak symbol, we mark it as "strong" 601 * and remember the first object file where it was encountered. 602 * Then when another instance of this weak symbol is encountered 603 * the output file name is checked; if it is a different object file, 604 * the symbol is marked as local. Otherwise it is marked as strong. 605 * Finally, when we find any external references to this symbol, they 606 * are marked as "OMF weak reference", e.g. the N_WEAKU type 607 * (which is quite different from a.out weaks, thats why we have 608 * to dig all that mess!). Alas, this mechanism can require multi-pass 609 * builds for complex cases... 610 */ 611 612 static void weak_load (void) 613 { 614 FILE *wf; 615 616 if (opt_w) 617 return; 618 619 /* Find and open the weak symbol list file */ 620 weak_list_filename = getenv ("GCC_WEAKSYMS"); 621 if (!weak_list_filename) 622 weak_list_filename = "weaksyms.omf"; 623 wf = fopen (weak_list_filename, "r"); 624 if (!wf) 625 return; 626 627 /* Every line of the file contains something like: 628 __symbol:object_file 629 or just 630 __symbol 631 */ 632 633 char line [1024]; 634 while (fgets (line, sizeof (line), wf)) 635 { 636 char *eol = strchr (line, 0); 637 while ((eol > line) && (isspace (eol [-1]))) 638 eol--; 639 *eol = 0; 640 char *sep = strchr (line, ':'); 641 if (!sep) 642 { 643 fprintf (stderr, "WARNING: bad line `%s' in weak symbol list file `%s'\n", 644 line, weak_list_filename); 645 continue; 646 } 647 648 *sep = 0; 649 add_weak (line, sep + 1); 650 } 651 652 fclose (wf); 653 654 /* Mark the list as unmodified */ 655 weak_list_altered = 0; 656 } 657 658 659 /* Save the weak symbol list */ 660 661 static void weak_save (void) 662 { 663 FILE *wf; 664 struct weaksym *wsym; 665 666 if (opt_w) 667 return; 668 669 /* Find and open the weak symbol list file */ 670 wf = fopen (weak_list_filename, "w"); 671 if (!wf) 672 return; 673 674 for (wsym = weak_symbol_list; wsym; wsym = wsym->next) 675 fprintf (wf, "%s:%s\n", wsym->name, wsym->module); 676 677 fclose (wf); 678 } 679 680 681 /* Free the weak symbol list */ 682 683 static void weak_free (void) 684 { 685 struct weaksym *cur = weak_symbol_list; 686 while (cur) 687 { 688 struct weaksym *next = cur->next; 689 free (cur->name); 690 free (cur->module); 691 free (cur); 692 cur = next; 693 } 694 weak_symbol_list = NULL; 695 } 696 697 698 /* Find if a symbol is weak */ 699 700 static struct weaksym *is_weak (const char *symname) 701 { 702 struct weaksym *wsym; 703 for (wsym = weak_symbol_list; wsym; wsym = wsym->next) 704 if (!strcmp (symname, wsym->name)) 705 return wsym; 706 return NULL; 542 707 } 543 708 … … 742 907 static void put_sym (const char *src) 743 908 { 744 if ( *src == '_')909 if (strip_underscore (src)) 745 910 ++src; 746 911 put_str (src); … … 965 1130 966 1131 1132 /* Check all external symbol references for weakness; if a symbol is weak, 1133 mark it as N_WEAKU so that it is later writen within a WKEXT record. 1134 Also we convert a.out-style weak symbols here as normal public symbols, 1135 as the sense of weak is reverse in OMF */ 1136 1137 static void weak_process (void) 1138 { 1139 int i; 1140 1141 #define SETTYPE(t) ((struct nlist *)sym_ptr)[i].type = t 1142 1143 for (i = 0; i < sym_count; ++i) 1144 if ((sym_ptr[i].type >= N_WEAKA) && (sym_ptr[i].type <= N_WEAKB)) 1145 { 1146 const char *name = str_ptr + sym_ptr[i].string; 1147 1148 int public = N_EXT; 1149 1150 /* Add the symbol to weak list if not already */ 1151 struct weaksym *wsym = is_weak (name); 1152 if (!wsym) 1153 wsym = add_weak (name, out_fname); 1154 else if (strcmp (out_fname, wsym->module) || wsym->used) 1155 public = 0; 1156 /* If the symbol is exported more than once (e.g. from an archive), 1157 export just the first instance... */ 1158 wsym->used = 1; 1159 1160 /* Now convert it to a normal public symbol */ 1161 switch (sym_ptr[i].type) 1162 { 1163 case N_WEAKA: SETTYPE (N_ABS | public); break; 1164 case N_WEAKT: SETTYPE (N_TEXT | public); break; 1165 case N_WEAKD: SETTYPE (N_DATA | public); break; 1166 case N_WEAKB: SETTYPE (N_BSS | public); break; 1167 } 1168 } 1169 else if ((sym_ptr[i].type & N_EXT) && is_weak (str_ptr + sym_ptr[i].string)) 1170 { 1171 /* Convert a external reference to N_WEAKU */ 1172 /* P.S. As experiments show, WKEXT works somewhat strangely 1173 with LINK386 (sometimes such external references are left 1174 unresolved, even that they could be resolved), thus the 1175 following line is commented out */ 1176 /*SETTYPE (N_WEAKU);*/ 1177 } 1178 1179 #undef SETTYPE 1180 } 1181 1182 967 1183 /* Write ALIAS records into the output file for all indirect 968 1184 references. */ … … 984 1200 { 985 1201 pub_name = str_ptr + sym_ptr[i].string; 986 if ( *pub_name == '_')1202 if (strip_underscore (pub_name)) 987 1203 ++pub_name; 988 1204 if (omflib_add_pub (out_lib, pub_name, mod_page, lib_errmsg) != 0) … … 1034 1250 { 1035 1251 pub_name = name; 1036 if ( *pub_name == '_')1252 if (strip_underscore (pub_name)) 1037 1253 ++pub_name; 1038 1254 if (omflib_add_pub (out_lib, pub_name, mod_page, … … 1076 1292 write_pubdef1 (N_DATA, udat_index, FALSE, text_size); 1077 1293 write_pubdef1 (N_DATA, udat_index, TRUE, text_size); 1294 write_pubdef1 (N_BSS, bss_index, FALSE, text_size + data_size); 1295 write_pubdef1 (N_BSS, bss_index, TRUE, text_size + data_size); 1078 1296 } 1079 1297 … … 1171 1389 The segment attributes byte contains the following fields: 1172 1390 1173 A (bits 5-7) Alignment (101=relocatable, 32-bit alignment) 1391 A (bits 5-7) Alignment (011=relocatable, paragraph (16b) alignment) 1392 (before gcc 3.2.2: 101=relocatable, 32-bit alignment) 1174 1393 C (bits 2-4) Combination (010=PUBLIC, 101=STACK) 1175 1394 B (bit 1) Big (segment length is 64KB) … … 1180 1399 byte seg_attr; 1181 1400 1182 seg_attr = (stack ? 0x b5 : 0xa9);1401 seg_attr = (stack ? 0x75 : 0x69); 1183 1402 if (size > 0x10000 || force_big) 1184 1403 { … … 2135 2354 /* Skip a leading underscore character if present. */ 2136 2355 2137 if ( *pub_name == '_')2356 if (strip_underscore (pub_name)) 2138 2357 ++pub_name; 2139 2358 … … 2629 2848 case N_INDR|N_EXT: 2630 2849 case N_WEAKU: 2850 case N_WEAKA: 2851 case N_WEAKT: 2852 case N_WEAKD: 2853 case N_WEAKB: 2631 2854 case N_SETA: case N_SETA|N_EXT: 2632 2855 case N_SETT: case N_SETT|N_EXT: … … 2847 3070 if (do_set_groups) 2848 3071 write_set_groups (); 3072 3073 /* Process weak symbols */ 3074 weak_process (); 2849 3075 2850 3076 /* Define external, communal and public symbols (EXTDEF, WKEXT, … … 2946 3172 puts (" -I <idmdll> Name the identifier manipulation DLL"); 2947 3173 puts (" -O <directory> Extract files to <directory>"); 3174 puts (" -w Suppress reading/writing of the weaksyms.omf file"); 3175 puts (" -z Remove underscores from all symbol names"); 2948 3176 exit (1); 2949 3177 } … … 3331 3559 /* Parse the command line options. */ 3332 3560 3333 while ((c = getopt (argc, argv, "bdD:gi:I:m:l::o:p:qO:r:R:sux ")) != EOF)3561 while ((c = getopt (argc, argv, "bdD:gi:I:m:l::o:p:qO:r:R:suxwz")) != EOF) 3334 3562 switch (c) 3335 3563 { … … 3408 3636 opt_x = TRUE; 3409 3637 break; 3638 case 'w': 3639 opt_w = TRUE; 3640 break; 3641 case 'z': 3642 opt_rmunder = TRUE; 3643 break; 3410 3644 default: 3411 3645 usage (); … … 3417 3651 usage (); 3418 3652 3653 /* Initialize weak symbol list */ 3654 3655 weak_symbol_list = NULL; 3656 weak_load (); 3657 3419 3658 if (opt_o != NULL) 3420 3659 { 3421 3422 3660 /* If the -o option is used, there must be exactly one input 3423 3661 file name. */ … … 3449 3687 } 3450 3688 3689 /* If the weak symbol list has been altered, save it */ 3690 3691 if (weak_list_altered) 3692 weak_save (); 3693 3694 /* Free the weak symbol list */ 3695 3696 weak_free (); 3697 3451 3698 /* If a LIB response file has been created, finish and close it. */ 3452 3699 -
Property cvs2svn:cvs-rev
changed from
-
trunk/src/emx/src/emxomf/emxomfld.c
-
Property cvs2svn:cvs-rev
changed from
1.1
to1.2
r59 r60 28 28 #include <sys/types.h> 29 29 #include <sys/stat.h> 30 #include < getopt.h>30 #include <emx/getopt.h> 31 31 #include <errno.h> 32 #include <sys/utime.h> 32 33 #include <sys/moddef.h> 34 #include <alloca.h> 33 35 #include "defs.h" 34 36 … … 142 144 int main (int argc, char *argv[]); 143 145 146 /* To avoid including os2.h... */ 147 unsigned DosCopy (char *, char *, unsigned); 148 144 149 145 150 /* Tell the user how to run this program. */ … … 461 466 const char *ext; 462 467 char tmp[512], *t; 468 static char emxshell [200]; 469 470 /* Drop EMXSHELL since it can point to a Unix shell which is bad for us */ 471 sprintf (emxshell, "EMXSHELL=%s", getenv ("OS2_SHELL")); 472 putenv (emxshell); 463 473 464 474 /* Close and delete the response file on exit. */ … … 675 685 statement is used for a segment of class 676 686 'CODE'). Not grouping neighboring code 677 segments would break sets */ 687 segments would break sets 688 689 For ILINK the following option is passed: 690 691 /NOFR[EEFORMAT] Use /NOFREEFORMAT to allow a LINK386-compatible 692 command line syntax, in which different types of file 693 are grouped and separated by commas. 694 */ 678 695 679 696 put_arg (linker_name, TRUE); 697 698 /* If the linker is ILINK, don't use the /BAT{CH} option */ 699 t = _getname (linker_name); 700 if (strnicmp (t, "ILINK", 5)) 680 701 put_arg ("/bat", FALSE); 702 else 703 put_arg ("/nofree", FALSE); 681 704 put_arg ("/nol", FALSE); 682 705 put_arg ("/noe", FALSE); … … 772 795 773 796 rc = system (command_line); 797 /* ILINK returns 4 on warnings: consider this as success */ 798 if (rc == 4) rc = 0; 799 774 800 if (rc < 0) 775 801 { … … 784 810 { 785 811 arg_init (TRUE); 786 put_arg ("rc ", TRUE);812 put_arg ("rc -n", TRUE); 787 813 put_arg (res_fname, TRUE); 788 814 put_arg (output_fname, TRUE); … … 802 828 if (rc == 0 && exe_flag) 803 829 { 804 int h; 805 806 h = open (output_fname, 807 O_WRONLY | O_CREAT | O_TRUNC | O_BINARY, 0666); 808 if (h < 0) 830 char execname[512]; 831 832 t = xstrdup (output_fname); 833 _remext (t); 834 835 _execname((char *)&execname, sizeof(execname)); 836 strcpy(_getname((char *)&execname), "ldstub.bin"); 837 /* Copy stub into file */ 838 DosCopy((char *)&execname, t, 4); 839 /* Now touch it */ 840 if (utime(t, NULL)) 809 841 { 810 842 perror ("emxomfld"); 811 843 exit (2); 812 844 } 813 close (h);845 free (t); 814 846 } 815 847 -
Property cvs2svn:cvs-rev
changed from
-
trunk/src/emx/src/emxomf/stabshll.c
-
Property cvs2svn:cvs-rev
changed from
1.1
to1.2
r59 r60 25 25 #include <string.h> 26 26 #include <time.h> 27 #include <alloca.h> 27 28 #include "defs.h" 28 29 #include "emxomf.h" … … 341 342 static int unnamed_struct_number; 342 343 344 /* Suppress several kinds of warnings since newer gccs generates lots of 345 warnings... */ 346 347 static void no_warning (char *format, ...) 348 { 349 (void)format; 350 } 351 343 352 344 353 /* Start a type table record of type TYPE, with type qualifier QUAL. … … 912 921 /* This should not happen. */ 913 922 914 warning ("stabs type %d not defined", tp->d.stabs_ref);923 no_warning ("stabs type %d not defined", tp->d.stabs_ref); 915 924 return 4; 916 925 … … 934 943 if (tp->d.struc.flags & STRUC_FORWARD) 935 944 { 936 warning ("size of incomplete structure %s is unknown",945 no_warning ("size of incomplete structure %s is unknown", 937 946 tp->d.struc.name); 938 947 return 0; … … 1175 1184 if (*parse_ptr != c) 1176 1185 { 1177 warning ("Invalid symbol data: `%c' expected", c);1186 no_warning ("Invalid symbol data: `%c' expected", c); 1178 1187 return FALSE; 1179 1188 } … … 1224 1233 default: 1225 1234 ++parse_ptr; 1226 warning ("Invalid visibility: %c", *parse_ptr);1235 no_warning ("Invalid visibility: %c", *parse_ptr); 1227 1236 if (*parse_ptr != 0) 1228 1237 ++parse_ptr; … … 1361 1370 else 1362 1371 { 1363 warning ("Unknown range type: %lld..%lld", range_lo, range_hi);1372 no_warning ("Unknown range type: %lld..%lld", range_lo, range_hi); 1364 1373 goto syntax; 1365 1374 } … … 1618 1627 if (*parse_ptr != ':') 1619 1628 { 1620 warning ("Arguments for member function missing");1629 no_warning ("Arguments for member function missing"); 1621 1630 goto syntax; 1622 1631 } … … 1643 1652 break; 1644 1653 default: 1645 warning ("Unknown member function qualifier: %c",1654 no_warning ("Unknown member function qualifier: %c", 1646 1655 *parse_ptr); 1647 1656 if (*parse_ptr != 0) … … 1673 1682 break; 1674 1683 default: 1675 warning ("Unknown member function qualifier: %c",1684 no_warning ("Unknown member function qualifier: %c", 1676 1685 *parse_ptr); 1677 1686 if (*parse_ptr != 0) … … 1979 1988 1980 1989 default: 1981 warning ("Unknown type: %c", *parse_ptr);1990 no_warning ("Unknown type: %c", *parse_ptr); 1982 1991 goto syntax; 1983 1992 } … … 2008 2017 tp = parse_type (type_name); 2009 2018 if (*parse_ptr != 0) 2010 warning ("unexpected character at end of stabs type: %c", *parse_ptr);2019 no_warning ("unexpected character at end of stabs type: %c", *parse_ptr); 2011 2020 return tp; 2012 2021 } … … 2032 2041 if (tp->index == -2) 2033 2042 { 2034 warning ("Cycle detected by make_type");2043 no_warning ("Cycle detected by make_type"); 2035 2044 RETURN (0); 2036 2045 } … … 2044 2053 if (t1 == NULL) 2045 2054 { 2046 warning ("Undefined stabs type %d referenced", tp->d.stabs_ref);2055 no_warning ("Undefined stabs type %d referenced", tp->d.stabs_ref); 2047 2056 RETURN (0x82); /* 32 bit signed */ 2048 2057 } … … 2724 2733 if (sym2 == NULL) 2725 2734 { 2726 warning ("Cannot find address of global variable %s", name);2735 no_warning ("Cannot find address of global variable %s", name); 2727 2736 return; 2728 2737 } -
Property cvs2svn:cvs-rev
changed from
Note:
See TracChangeset
for help on using the changeset viewer.