Changeset 510
- Timestamp:
- Aug 1, 2003, 9:12:04 PM (22 years ago)
- Location:
- trunk/src/emx/src/emxomf
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/emx/src/emxomf/emxomfld.c
-
Property cvs2svn:cvs-rev
changed from
1.13
to1.14
r509 r510 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); … … 512 512 /* normalize the name */ 513 513 cch = pszend - psz; 514 strncpy(pszfullname, psz, pszend - psz);514 memcpy(pszfullname, psz, pszend - psz); 515 515 if ( pszfullname[cch-1] != '\\' 516 516 && pszfullname[cch-1] != '/' … … 531 531 { 532 532 memcpy(pszfullname + cch, "lib", 3); 533 memcpy(pszfullname + cch , pszname, cchname);534 strcpy(pszfullname + cch + cchname, papszexts[i]);533 memcpy(pszfullname + cch + 3, pszname, cchname); 534 strcpy(pszfullname + cch + 3 + cchname, papszexts[i]); 535 535 phFile = fopen (pszfullname, "rb"); 536 536 if (phFile) … … 578 578 } /* foreach path in $LIB */ 579 579 } 580 strcpy(pszfullname, pszname); 580 581 return NULL; 581 582 } -
Property cvs2svn:cvs-rev
changed from
-
trunk/src/emx/src/emxomf/weakld.c
-
Property cvs2svn:cvs-rev
changed from
1.4
to1.5
r509 r510 54 54 #define WLDINTERR(pWld, pMod) wldIntErr(pWld, pMod, __FILE__, __LINE__, __FUNCTION__); 55 55 56 #ifdef DEBUG 57 58 #define SYMDBG(pSym, pszMsg) symDbg(pSym, pszMsg); 59 #else 60 #define SYMDBG(pSym, pszMsg) do {} while (0) 61 #endif 62 56 63 57 64 /** Helpers for checking if a symbol is defined strongly. */ … … 60 67 || (fFlags & (WLDSF_TYPEMASK | WLDSF_WEAK)) == WLDSF_IMPORT \ 61 68 ) 62 /** Helpers for checking if a symbol is strongly undefined. No weaks included! */63 #define SYM_IS_UNDEFINED(fFlags) ( (fFlags & (WLDSF_TYPEMASK | WLDSF_WEAK)) == WLDSF_UNDEF)64 69 65 70 … … 187 192 PWLDMOD pMod; 188 193 189 /** @group Import Attributes 190 * Valid when type is WLDSF_IMPORT. 191 * @{ */ 192 /** Import module. */ 193 const char* pszImpMod; 194 /** Import Ordinal (WLDSF_IMPORT). 195 * 0 means no ordinal. */ 196 unsigned uImpOrd; 197 /** @} */ 194 /** Per type data union */ 195 union type_data 196 { 197 struct import_data 198 { 199 /** @group Import Attributes 200 * Valid when type is WLDSF_IMPORT. 201 * @{ */ 202 /** Import module. */ 203 const char* pszImpMod; 204 /** Import Ordinal (WLDSF_IMPORT). 205 * 0 means no ordinal. */ 206 unsigned uImpOrd; 207 /** @} */ 208 } import; 209 210 struct comm_data 211 { 212 /** Size of comm object */ 213 signed long cb; 214 /** Number of elements. */ 215 signed long cElements; 216 } comm; 217 } u; 198 218 199 219 /** Weak default resolution. … … 313 333 314 334 static void wldInfo(const char *pszFormat, ...); 335 static int wldErr(PWLD pWld, const char *pszFormat, ...); 315 336 static void wldIntErr(PWLD pWld, PWLDMOD pMod, const char *pszFile, unsigned iLine, const char *pszFunction); 316 static int modErr or(PWLDMOD pMod, const char *pszFormat, ...);337 static int modErr(PWLDMOD pMod, const char *pszFormat, ...); 317 338 static void modWarn(PWLDMOD pMod, const char *pszFormat, ...); 318 339 static FILE * modOpen(PWLDMOD pMod); … … 320 341 321 342 static inline unsigned hash(const char* pszSym, unsigned cch); 322 static PWLDSYM symAdd(PWLD pWld, PWLDMOD pMod, unsigned fFlags, const char *pachName, int cchName, 323 unsigned long ulValue, unsigned iSegment, PWLDSYMACTION peAction); 343 static void symDbg(PWLDSYM pSym, const char *pszMsg); 324 344 325 345 … … 350 370 } 351 371 372 /** 373 * Put out a info message. 374 * @param pszFormat Format string. 375 * @param ... Format arguments. 376 */ 377 static int wldErr(PWLD pWld, const char *pszFormat, ...) 378 { 379 va_list args; 380 fprintf(stderr, "weakld: error: "); 381 382 va_start(args, pszFormat); 383 vfprintf(stderr, pszFormat, args); 384 va_end(args); 385 if (pszFormat[strlen(pszFormat) - 1] != '\n') 386 fputc('\n', stderr); 387 return -1; 388 } 389 352 390 353 391 /** … … 383 421 * @param ... Format arguments. 384 422 */ 385 static int modErr or(PWLDMOD pMod, const char *pszFormat, ...)423 static int modErr(PWLDMOD pMod, const char *pszFormat, ...) 386 424 { 387 425 va_list args; … … 455 493 /* Position the stream at the start of the module. */ 456 494 if (!pMod->phFile) 457 modErr or(pMod, "failed to reopen.");495 modErr(pMod, "failed to reopen."); 458 496 else 459 497 { 460 498 if (fseek(pMod->phFile, pMod->off, SEEK_SET)) 461 499 { 462 modErr or(pMod, "failed to seek to module start (%#x).", pMod->off);500 modErr(pMod, "failed to seek to module start (%#x).", pMod->off); 463 501 modClose(pMod); 464 502 return NULL; … … 485 523 486 524 487 525 typedef int (*PFNSYMENUM)(PWLD pWld, PWLDSYM pSym, void *pvUser); 526 527 /** 528 * Symbol enumerator. 529 * 530 * @returns return code from last pfnEnum call. 531 * @param pWld Weak Linker Instance. 532 * @param pSymTab The symbol table to enumerate. 533 * @param fFlags The flags which (pSym->fFlags & fMask) much equal. 534 * @param fMask The flag mask. 535 * @param pfnEnum Enumeration callback function. 536 * @param pvUser User arguments to pfnEnum. 537 */ 538 static int symEnum(PWLD pWld, PWLDSYMTAB pSymTab, unsigned fFlags, unsigned fMask, PFNSYMENUM pfnEnum, void *pvUser) 539 { 540 int i; 541 PWLDSYM pSym; 542 int rc; 543 544 for (i = 0; i < sizeof(pSymTab->ap) / sizeof(pSymTab->ap[0]); i++) 545 { 546 for (pSym = pSymTab->ap[i]; pSym; pSym = pSym->pHashNext) 547 { 548 if ((pSym->fFlags & fMask) == fFlags) 549 { 550 rc = pfnEnum(pWld, pSym, pvUser); 551 if (rc) 552 return rc; 553 } 554 } 555 } 556 557 return 0; 558 } 559 560 561 #ifdef DEBUG 562 /** 563 * Symbol debug output. 564 * @param pSym Symbol to dump. 565 * @param pszMsg Message to put first in the dump. 566 */ 567 static void symDbg(PWLDSYM pSym, const char *pszMsg) 568 { 569 if (pszMsg) 570 fprintf(stderr, "weakld: dbg: %s:", pszMsg); 571 else 572 fprintf(stderr, "weakld: dbg:"); 573 if (pSym) 574 { 575 fprintf(stderr, " '%s'", pSym->pszName); 576 switch (pSym->fFlags & WLDSF_TYPEMASK) 577 { 578 case WLDSF_PUBLIC: fprintf(stderr, " PUBLIC"); break; 579 case WLDSF_COMM: fprintf(stderr, " COMM"); break; 580 case WLDSF_IMPORT: fprintf(stderr, " IMPORT"); break; 581 case WLDSF_UNDEF: fprintf(stderr, " UNDEF"); break; 582 case WLDSF_WKEXT: fprintf(stderr, " WKEXT"); break; 583 default: fprintf(stderr, " !!!internal error!!!"); asm("int $3"); break; 584 } 585 if (pSym->fFlags & WLDSF_WEAK) 586 fprintf(stderr, " WEAK"); 587 if (pSym->fFlags & WLDSF_ALIAS) 588 fprintf(stderr, " ALIAS"); 589 if (pSym->fFlags & WLDSF_EXPORT) 590 fprintf(stderr, " ALIAS"); 591 if (pSym->fFlags & WLDSF_UNCERTAIN) 592 fprintf(stderr, " UNCERTAIN"); 593 } 594 else 595 fprintf(stderr, " <Symbol is NULL>"); 596 fprintf(stderr, "\n"); 597 } 598 #endif 488 599 489 600 … … 517 628 * 2. adding a WKEXT where a PUBLIC or COMM exists. 518 629 * 3. adding a WKEXT where a UNDEF which isn't UNCERTAIN exists. 519 * 4. adding a COMM where a !WEAK COMM exists. (todo value check)630 * 4. adding a COMM where a !WEAK COMM exists. 520 631 * 5. adding a WEAK PUBLIC or WEAK COMM where a PUBLIC or COMM exists. 521 632 * … … 550 661 * @param pachName Pointer to symbol name. 551 662 * @param cchName Length to add, use -1 if zeroterminated. 552 * @param ulValue Value of the symbol (if it's relevant for this kind of symbol). (ignored)553 * @param iSegment Segment of pMod in which this symbol is defined (only if relevant). (ignored)554 663 * @param pflAction What we actually did. 555 664 * WLDSA_NEW, WLDSA_UP, WLDSA_OLD, WLDSA_ERR. 556 665 */ 557 static PWLDSYM symAdd(PWLD pWld, PWLDMOD pMod, unsigned fFlags, const char *pachName, int cchName, 558 unsigned long ulValue, unsigned iSegment, PWLDSYMACTION peAction) 666 static PWLDSYM symAdd(PWLD pWld, PWLDMOD pMod, unsigned fFlags, const char *pachName, int cchName, PWLDSYMACTION peAction) 559 667 { 560 668 PWLDSYM pSym; /* The symbol. */ … … 578 686 { 579 687 cchNameWeak = cchName; 580 cchName = pach Name - pach;688 cchName = pach - pachName; 581 689 fFlags |= WLDSF_WEAK; 582 690 /* If WKEXT we'll upgrade it to weak undefined. (yeah, big deal?) */ … … 586 694 } 587 695 uHash = hash(pachName, cchName); 588 pszName = (pWld->fFlags & WLDC_CASE_INSENSITIVE ? strpool_addn : strpool_addnu)(pWld->pStrMisc, pachName, cchName);696 pszName = (pWld->fFlags & WLDC_CASE_INSENSITIVE ? strpool_addnu : strpool_addn)(pWld->pStrMisc, pachName, cchName); 589 697 590 698 /* search for existing symbol */ … … 622 730 * 2. adding a WKEXT where a PUBLIC or COMM exists. 623 731 * 3. adding a WKEXT where a UNDEF which isn't UNCERTAIN exists. 624 * 4. adding a COMM where a !WEAK COMM exists. (todo value check)732 * 4. adding a COMM where a !WEAK COMM exists. 625 733 * 5. adding a WEAK PUBLIC or WEAK COMM where a PUBLIC or COMM exists. 626 734 */ … … 702 810 pSym->fFlags = (pSym->fFlags & ~(WLDSF_TYPEMASK | WLDSF_WEAK | WLDSF_UNCERTAIN | WLDSF_LIBSEARCH)) | fFlags; 703 811 if (peAction) *peAction = WLDSA_UP; 812 memset(&pSym->u, 0, sizeof(pSym->u)); 704 813 } 705 814 /* … … 711 820 else 712 821 { 713 modErr or(pMod, "Duplicate symbol '%s'.", pszName);822 modErr(pMod, "Duplicate symbol '%s'.", pszName); 714 823 if (pSym->pMod) 715 modErr or(pSym->pMod, "Previous symbol defined in this module.");824 modErr(pSym->pMod, "Previous symbol defined in this module."); 716 825 wldInfo("fFlags new 0x%04x fFlags old 0x%04x.", fFlags, pSym->fFlags); 717 826 pSym = NULL; … … 748 857 749 858 pSym = symAdd(pWld, pMod, WLDSF_IMPORT | (fLibSearch ? WLDSF_LIBSEARCH : 0), 750 pachIntName, cchIntName, 0, 0,&eAction);859 pachIntName, cchIntName, &eAction); 751 860 if (!pSym) 752 861 return NULL; … … 756 865 { 757 866 case WLDSA_NEW: 758 pSym-> pszImpMod = pszImpMod;759 pSym->u ImpOrd= uOrdinal;867 pSym->u.import.pszImpMod = pszImpMod; 868 pSym->u.import.uImpOrd = uOrdinal; 760 869 break; 761 870 … … 764 873 if ((pSym->fFlags & WLDSF_TYPEMASK) == WLDSF_IMPORT) 765 874 { 766 if (!pSym-> pszImpMod)875 if (!pSym->u.import.pszImpMod) 767 876 { 768 pSym-> pszImpMod = pszImpMod;769 pSym->u ImpOrd = uOrdinal;877 pSym->u.import.pszImpMod = pszImpMod; 878 pSym->u.import.uImpOrd = uOrdinal; 770 879 } 771 880 else 772 881 { 773 if ( pSym-> pszImpMod != pszImpMod774 && pSym->u ImpOrd != uOrdinal)882 if ( pSym->u.import.pszImpMod != pszImpMod 883 && pSym->u.import.uImpOrd != uOrdinal) 775 884 { 776 885 modWarn(pMod, "Existing import '%s' have different module name than the new ('%s' != '%s') and different ordinal (%d != %d).", 777 pSym->pszName, pSym-> pszImpMod, pszImpMod, pSym->uImpOrd, uOrdinal);886 pSym->pszName, pSym->u.import.pszImpMod, pszImpMod, pSym->u.import.uImpOrd, uOrdinal); 778 887 } 779 else if (pSym->u ImpOrd != uOrdinal)888 else if (pSym->u.import.uImpOrd != uOrdinal) 780 889 { 781 890 modWarn(pMod, "Existing import '%s' have different ordinal (%d != %d).", 782 pSym->pszName, pSym->u ImpOrd, uOrdinal);891 pSym->pszName, pSym->u.import.uImpOrd, uOrdinal); 783 892 } 784 else if (pSym-> pszImpMod != pszImpMod)893 else if (pSym->u.import.pszImpMod != pszImpMod) 785 894 { 786 895 modWarn(pMod, "Existing import '%s' have different module name than the new ('%s' != '%s').", 787 pSym->pszName, pSym-> pszImpMod, pszImpMod);896 pSym->pszName, pSym->u.import.pszImpMod, pszImpMod); 788 897 } 789 898 } … … 841 950 */ 842 951 pSym = symAdd(pWld, pMod, WLDSF_UNDEF | (fLibSearch ? WLDSF_LIBSEARCH : 0), 843 pachExpName, cchExpName, 0, 0,NULL);952 pachExpName, cchExpName, NULL); 844 953 if (!pSym) 845 954 return NULL; … … 861 970 */ 862 971 pSymAlias = symAdd(pWld, pMod, WLDSF_UNDEF | (fLibSearch ? WLDSF_LIBSEARCH : 0), 863 pachIntName, cchIntName, 0, 0,NULL);972 pachIntName, cchIntName, NULL); 864 973 if (!pSymAlias) 865 974 return NULL; 866 975 if (pSymAlias != pSym && (pSym->fFlags & WLDSF_ALIAS) && pSym->pAliasFor != pSymAlias) 867 976 { 868 modErr or(pMod, "Can't export an alias!.");977 modErr(pMod, "Can't export an alias!."); 869 978 pSym = NULL; 870 979 } … … 885 994 } 886 995 996 997 /** 998 * Adds a public symbol. 999 * 1000 * @returns see symAdd() 1001 * @param pWld Pointer to linker instance. 1002 * @param pMod Pointer to module 1003 * @param fLibSearch Set if we're doing library search at this time. 1004 * @param pachName Exported name. 1005 * @param cchName Length of that name. -1 if zero terminated string. 1006 * @param ulValue Value of the symbol. 1007 * @param iSegment Segment of pMod in which this symbol is defined. 1008 * Use -1 if segment is not relevant. 1009 */ 1010 static PWLDSYM symAddPublic(PWLD pWld, PWLDMOD pMod, int fLibSearch, 1011 const char *pachName, int cchName, 1012 unsigned long ulValue, int iSegment, int iGroup) 1013 { 1014 PWLDSYM pSym; 1015 1016 pSym = symAdd(pWld, pMod, WLDSF_PUBLIC | (fLibSearch ? WLDSF_LIBSEARCH : 0), 1017 pachName, cchName, NULL); 1018 if (!pSym) 1019 return NULL; 1020 /* @todo: handle values ulValue, iSegment and iGroup? Not really required for this job... */ 1021 return pSym; 1022 } 1023 1024 1025 /** 1026 * Adds an undefined symbol. 1027 * 1028 * @returns see symAdd() 1029 * @param pWld Pointer to linker instance. 1030 * @param pMod Pointer to module 1031 * @param fLibSearch Set if we're doing library search at this time. 1032 * @param pachName Exported name. 1033 * @param cchName Length of that name. -1 if zero terminated string. 1034 */ 1035 static PWLDSYM symAddUnDef(PWLD pWld, PWLDMOD pMod, int fLibSearch, 1036 const char *pachName, int cchName) 1037 { 1038 PWLDSYM pSym; 1039 1040 pSym = symAdd(pWld, pMod, WLDSF_UNDEF | (fLibSearch ? WLDSF_LIBSEARCH : 0), 1041 pachName, cchName, NULL); 1042 if (!pSym) 1043 return NULL; 1044 return pSym; 1045 } 1046 1047 1048 /** 1049 * Adds an undefined symbol. 1050 * 1051 * @returns see symAdd() 1052 * @param pWld Pointer to linker instance. 1053 * @param pMod Pointer to module 1054 * @param fLibSearch Set if we're doing library search at this time. 1055 * @param pachName Exported name. 1056 * @param cchName Length of that name. -1 if zero terminated string. 1057 */ 1058 static PWLDSYM symAddAlias(PWLD pWld, PWLDMOD pMod, int fLibSearch, 1059 const char *pachAliasName, int cchAliasName, 1060 const char *pachName, int cchName 1061 ) 1062 { 1063 WLDSYMACTION eAction; 1064 PWLDSYM pSym; 1065 1066 /* 1067 * Start by adding the alias it self. 1068 */ 1069 pSym = symAdd(pWld, pMod, WLDSF_PUBLIC | WLDSF_ALIAS | (fLibSearch ? WLDSF_LIBSEARCH : 0), 1070 pachAliasName, cchAliasName, &eAction); 1071 if (!pSym) 1072 return NULL; 1073 switch (eAction) 1074 { 1075 case WLDSA_NEW: 1076 case WLDSA_UP: 1077 { 1078 if (!pSym->pAliasFor) 1079 { 1080 PWLDSYM pSym2 = symAdd(pWld, pMod, WLDSF_UNDEF | (fLibSearch ? WLDSF_LIBSEARCH : 0), 1081 pachName, cchName, NULL); 1082 if (!pSym2) 1083 return NULL; 1084 pSym->pAliasFor = pSym2; 1085 } 1086 else 1087 { 1088 modErr(pMod, "Aliased symbol apparently existed already (upgraded - internal error?)."); 1089 pSym = NULL; 1090 } 1091 break; 1092 } 1093 1094 case WLDSA_OLD: 1095 modErr(pMod, "Aliased symbol already exists."); 1096 pSym = NULL; 1097 break; 1098 default: 1099 WLDINTERR(pWld, pMod); 1100 } 1101 1102 return pSym; 1103 } 1104 1105 1106 /** 1107 * Adds(/Marks) an communal symbol. 1108 * 1109 * @returns see symAdd() 1110 * @param pWld Pointer to linker instance. 1111 * @param pMod Pointer to module 1112 * @param fLibSearch Set if we're doing library search at this time. 1113 * @param fDataType Datatype. 1114 * @param cElements Number of elements. 1115 * @param cbElement Size of one element. 1116 * @param pachName Symbol name. 1117 * @param cchName Length of the name. -1 if zero terminated string. 1118 */ 1119 static PWLDSYM symAddComdef(PWLD pWld, PWLDMOD pMod, int fLibSearch, 1120 const char *pachName, int cchName, 1121 signed long cElements, signed long cbElement) 1122 { 1123 PWLDSYM pSym; 1124 WLDSYMACTION eAction; 1125 1126 /* 1127 * Add external name. 1128 */ 1129 pSym = symAdd(pWld, pMod, WLDSF_COMM | (fLibSearch ? WLDSF_LIBSEARCH : 0), 1130 pachName, cchName, NULL); 1131 if (!pSym) 1132 return NULL; 1133 1134 cbElement *= (cElements > 0 ? cElements : 1); /* make it a size */ 1135 switch (eAction) 1136 { 1137 case WLDSA_NEW: 1138 pSym->u.comm.cb = cbElement * (cElements > 0 ? cElements : 1); 1139 pSym->u.comm.cElements = cElements; 1140 break; 1141 1142 case WLDSA_UP: 1143 case WLDSA_OLD: 1144 /* merge size */ 1145 if (pSym->u.comm.cElements < cElements) 1146 pSym->u.comm.cElements = cElements; 1147 if (pSym->u.comm.cb < cbElement) 1148 pSym->u.comm.cb = cbElement; 1149 pSym = NULL; 1150 break; 1151 1152 default: 1153 WLDINTERR(pWld, pMod); 1154 } 1155 1156 return pSym; 1157 } 1158 887 1159 /** 888 1160 * Reads an OMF module from a file. … … 908 1180 int fFirst = 1; /* First record indicator. */ 909 1181 /* generic stuff we'll use alot with not status associated. */ 910 int cch;1182 //int cch; 911 1183 PWLDSYM pSym; 912 PWLDSYM pSym2;1184 //PWLDSYM pSym2; 913 1185 int i; 914 1186 unsigned long ul; 915 unsigned short us; 1187 signed long l, l2, l3; 1188 unsigned short us, us2, us3; 916 1189 unsigned char uch, uch2, uch3; 917 1190 … … 935 1208 void * pv; 936 1209 } u, u1, u2, u3; 1210 937 1211 /** macro for getting a OMF index out of the buffer */ 938 1212 #define OMF_GETINDEX() (*u.puch & 0x80 ? ((*u.pch++ & 0x7f) << 8) + *u.pch++ : *u.pch++) 939 1213 #define OMF_BYTE() (*u.puch++) 940 1214 #define OMF_WORD() (*u.pus++) 1215 #define OMF_24BITWORD() (OMF_BYTE() | (OMF_WORD() << 8)) 1216 #define OMF_DWORD() (*u.pul++) 941 1217 #define OMF_MORE() (u.puch - &achBuffer[0] < (int)OmfRec.cb - 1) 1218 #define OMF_IS32BIT() ((OmfRec.chType & REC32) != 0) 1219 #define OMF_GETTYPELEN(l) \ 1220 do \ 1221 { \ 1222 l = OMF_BYTE(); \ 1223 if (l > 128) \ 1224 switch (l) \ 1225 { \ 1226 case 0x81: l = OMF_WORD(); break; \ 1227 case 0x84: l = OMF_24BITWORD(); break; \ 1228 case 0x88: l = OMF_DWORD(); break; \ 1229 default: \ 1230 modErr(pMod, "Invalid type length!"); \ 1231 goto failure; \ 1232 } \ 1233 } while (0) 1234 942 1235 943 1236 u.pv = &achBuffer[0]; … … 946 1239 if (fread(&OmfRec, sizeof(OmfRec), 1, phFile) != 1) 947 1240 { 948 modErr or(pMod, "read error. (offset ~= %#x).", ftell(phFile));1241 modErr(pMod, "read error. (offset ~= %#x).", ftell(phFile)); 949 1242 goto failure; 950 1243 } … … 954 1247 if (OmfRec.chType != THEADR) 955 1248 { 956 modErr or(pMod, "invalid object module (offset %#x).", pMod->off);1249 modErr(pMod, "invalid object module (offset %#x).", pMod->off); 957 1250 goto failure; 958 1251 } … … 983 1276 if (fread(achBuffer, OmfRec.cb, 1, phFile) != 1) 984 1277 { 985 modErr or(pMod, "read error. (offset ~= %#x)", ftell(phFile));1278 modErr(pMod, "read error. (offset ~= %#x)", ftell(phFile)); 986 1279 goto failure; 987 1280 } … … 1010 1303 || !papExts[iDefault]) 1011 1304 { 1012 modErr or(pMod, "Invalid WKEXT record.");1305 modErr(pMod, "Invalid WKEXT record."); 1013 1306 goto failure; 1014 1307 } … … 1017 1310 papExts[iWeak]->fFlags = (papExts[iWeak]->fFlags & ~(WLDSF_TYPEMASK | WLDSF_UNCERTAIN)) | WLDSF_WKEXT; 1018 1311 papExts[iWeak]->pWeakDefault = papExts[iDefault]; 1312 SYMDBG(papExts[iWeak], "WKEXT"); 1019 1313 } 1020 1314 else if ( (papExts[iWeak]->fFlags & WLDSF_TYPEMASK) == WLDSF_WKEXT … … 1046 1340 ul); 1047 1341 if (!pSym) goto failure; 1342 SYMDBG(pSym, "IMPDEF"); 1048 1343 break; 1049 1344 } … … 1069 1364 ul); 1070 1365 if (!pSym) goto failure; 1366 SYMDBG(pSym, "EXPDEF"); 1071 1367 break; 1072 1368 } … … 1076 1372 break; 1077 1373 1078 case EXTDEF: case EXTDEF | REC32:1374 case EXTDEF: 1079 1375 { 1376 while (OMF_MORE()) 1377 { 1378 u1 = u; u.pch += 1 + *u.puch; 1379 ul = OMF_GETINDEX(); /* typeindex */ 1380 pSym = symAddUnDef(pWld, pMod, fLibSearch, u1.puch + 1, *u1.puch); 1381 if (!pSym) goto failure; 1382 SYMDBG(pSym, "EXTDEF"); 1383 } 1080 1384 break; 1081 1385 } … … 1083 1387 case PUBDEF: case PUBDEF | REC32: 1084 1388 { 1389 us2 = OMF_GETINDEX(); /* group index */ 1390 us3 = OMF_GETINDEX(); /* segment index */ 1391 if (!us3) 1392 us = OMF_WORD(); /* base frame - ignored */ 1393 while (OMF_MORE()) 1394 { 1395 u1 = u; u.pch += 1 + *u.puch; /* public name */ 1396 ul = OMF_IS32BIT() ? OMF_DWORD() : OMF_WORD(); 1397 us = OMF_GETINDEX(); /* typeindex */ 1398 pSym = symAddPublic(pWld, pMod, fLibSearch, u1.puch + 1, *u1.puch, 1399 ul, us3, us2); 1400 if (!pSym) goto failure; 1401 SYMDBG(pSym, "PUBDEF"); 1402 } 1085 1403 break; 1086 1404 } … … 1088 1406 case ALIAS: case ALIAS | REC32: 1089 1407 { 1408 while (OMF_MORE()) 1409 { 1410 u1 = u; u.pch += 1 + *u.puch; /* alias name */ 1411 u2 = u; u.pch += 1 + *u.puch; /* substitutt name. */ 1412 pSym = symAddAlias(pWld, pMod, fLibSearch, 1413 u1.puch + 1, *u1.puch, 1414 u2.puch + 1, *u2.puch); 1415 if (!pSym) goto failure; 1416 SYMDBG(pSym, "ALIAS"); 1417 } 1090 1418 break; 1091 1419 } … … 1093 1421 case COMDEF: case COMDEF | REC32: 1094 1422 { 1423 while (OMF_MORE()) 1424 { 1425 u1 = u; u.pch += 1 + *u.puch; /* communal name (specs say 1-2 length...) */ 1426 us2 = OMF_GETINDEX(); /* typeindex */ 1427 uch2 = OMF_BYTE(); /* date type */ 1428 switch (uch2) 1429 { 1430 case COMDEF_TYPEFAR: 1431 OMF_GETTYPELEN(l2); /* number of elements */ 1432 OMF_GETTYPELEN(l3); /* element size */ 1433 break; 1434 case COMDEF_TYPENEAR: 1435 l2 = 1; /* number of elements */ 1436 OMF_GETTYPELEN(l3); /* element size */ 1437 break; 1438 default: 1439 modErr(pMod, "Invalid COMDEF type %x.", (int)uch2); 1440 goto failure; 1441 } 1442 1443 pSym = symAddComdef(pWld, pMod, fLibSearch, 1444 u1.puch + 1, *u1.puch, 1445 l2, l3); 1446 if (!pSym) goto failure; 1447 SYMDBG(pSym, "ALIAS"); 1448 } 1095 1449 break; 1096 1450 } … … 1102 1456 1103 1457 case LIBHDR: 1104 modErr or(pMod, "invalid object module (LIBHDR).");1458 modErr(pMod, "invalid object module (LIBHDR)."); 1105 1459 goto failure; 1106 1460 default: … … 1111 1465 1112 1466 #undef OMF_GETINDEX 1467 #undef OMF_BYTE 1468 #undef OMF_WORD 1469 #undef OMF_24BITWORD 1470 #undef OMF_DWORD 1471 #undef OMF_MORE 1472 #undef OMF_IS32BIT 1473 #undef OMF_GETTYPELEN 1113 1474 } 1114 1475 … … 1341 1702 1342 1703 /** 1704 * Symbol enumeration callback function of wld_generate_weakobj(). 1705 * It writes alias for weak symbols. 1706 * 1707 * @returns 0 on success 1708 * @returns !0 on failure after writing sufficient error message. 1709 * @param pWld Linker instance. 1710 * @param pSym Symbol. 1711 * @param pvUser Pointer to a FILE stream. 1712 */ 1713 static int weakobjEnum(PWLD pWld, PWLDSYM pSym, void *pvUser) 1714 { 1715 if (pSym->pszWeakName) 1716 { 1717 int cch = strlen(pSym->pszWeakName); 1718 int cchAlias = strlen(pSym->pszName); 1719 unsigned char uch; 1720 OMFREC hdr; 1721 1722 WLDINFO(pWld, ("using weak %s for %s", pSym->pszWeakName, pSym->pszName)); 1723 1724 /* paranoia */ 1725 if (cchAlias > 255) 1726 { 1727 wldErr(pWld, "Symbol '%s' are too long (%d).", pSym->pszName, cchAlias); 1728 return -1; 1729 } 1730 if (cch > 255) 1731 { 1732 wldErr(pWld, "Symbol '%s' are too long (%d).", pSym->pszWeakName, cch); 1733 return -1; 1734 } 1735 1736 /* write header */ 1737 hdr.chType = ALIAS; 1738 hdr.cb = cchAlias + cch + 3; 1739 if (fwrite(&hdr, sizeof(hdr), 1, (FILE*)pvUser) != 1) 1740 { 1741 wldErr(pWld, "Error occured while writing weak aliases. (1)"); 1742 return -1; 1743 } 1744 1745 /* write alias string */ 1746 uch = cchAlias; 1747 if ( fwrite(&uch, sizeof(uch), 1, (FILE*)pvUser) != 1 1748 || fwrite(pSym->pszName, cchAlias, 1, (FILE*)pvUser) != 1 1749 ) 1750 1751 { 1752 wldErr(pWld, "Error occured while writing weak aliases (2)."); 1753 return -1; 1754 } 1755 1756 /* write substitute string */ 1757 uch = cch; 1758 if ( fwrite(&uch, sizeof(uch), 1, (FILE*)pvUser) != 1 1759 || fwrite(pSym->pszWeakName, cch, 1, (FILE*)pvUser) != 1 1760 ) 1761 1762 { 1763 wldErr(pWld, "Error occured while writing weak aliases (3)."); 1764 return -1; 1765 } 1766 1767 /* write substitute CRC */ 1768 uch = 0; 1769 if (fwrite(&uch, sizeof(uch), 1, (FILE*)pvUser) != 1) 1770 1771 { 1772 wldErr(pWld, "Error occured while writing weak aliases (4)."); 1773 return -1; 1774 } 1775 } 1776 return 0; 1777 } 1778 1779 1780 /** 1343 1781 * Generates a object file containing alias for resolving the weak 1344 1782 * symbol references in the linked executable. … … 1355 1793 { 1356 1794 char * psz; 1795 FILE * phFile; 1796 int rc = -1; 1357 1797 1358 1798 *pszName = '\0'; … … 1370 1810 fprintf(stderr, "weakld: info: generating weakobj object file '%s'.\n", pszName); 1371 1811 1372 *pszName = '\0'; 1373 return 0; 1374 1375 } 1376 1812 /* open the file */ 1813 phFile = fopen(pszName, "wr"); 1814 if (phFile) 1815 { 1816 #pragma pack(1) 1817 struct omfstuff 1818 { 1819 OMFREC hdr; 1820 char ach[256]; 1821 } omf; 1822 #pragma pack() 1823 int cch; 1824 off_t offAlias; 1825 1826 /* Write object file header. */ 1827 cch = strlen("wk.obj"); 1828 omf.hdr.chType = THEADR; 1829 omf.hdr.cb = cch + 2; /* name + crc */ 1830 omf.ach[0] = cch; /* module name */ 1831 memcpy(&omf.ach[1], "wk.obj", cch); 1832 omf.ach[1+cch] = 0; /* crc */ 1833 fwrite(&omf, omf.hdr.cb + sizeof(OMFREC), 1, phFile); 1834 /* todo: check if we'll need more shit here to satisfy the linkers */ 1835 1836 1837 /* Make aliases */ 1838 offAlias = ftell(phFile); /* save this to see if anything is added. */ 1839 rc = symEnum(pWld, &pWld->Global, 1840 WLDSF_WEAK, WLDSF_WEAK, 1841 weakobjEnum, phFile); 1842 if (rc || ftell(phFile) == offAlias) 1843 { 1844 if (!rc) 1845 WLDINFO(pWld, ("No weak alias needed, deleting file.")); 1846 fclose(phFile); 1847 remove(pszName); 1848 *pszName = '\0'; 1849 } 1850 else 1851 { 1852 /* write end of module */ 1853 omf.hdr.chType = MODEND; 1854 omf.hdr.cb = 2; 1855 omf.ach[0] = omf.ach[1] = 0; 1856 if (fwrite(&omf, omf.hdr.cb + sizeof(OMFREC), 1, phFile) == 1) 1857 fclose(phFile); 1858 else 1859 { 1860 wldErr(pWld, "Failed to write to '%s'.", pszName); 1861 rc = -1; 1862 fclose(phFile); 1863 remove(pszName); 1864 *pszName = '\0'; 1865 } 1866 } 1867 } 1868 else 1869 { 1870 wldErr(pWld, "Failed to open '%s' for writing.", pszName); 1871 *pszName = '\0'; 1872 } 1873 1874 return rc; 1875 } 1876 -
Property cvs2svn:cvs-rev
changed from
Note:
See TracChangeset
for help on using the changeset viewer.