Ticket #220: emxomf-03-fix-symbol-too-long.diff
File emxomf-03-fix-symbol-too-long.diff, 7.9 KB (added by , 14 years ago) |
---|
-
emxomf.c
old new 796 796 return psz; 797 797 } 798 798 799 /* Put the string pszName into the given buffer pOutBuf (which must be at least 800 256 bytes long). The string length must not exceed 255 bytes (OMF format 801 requirement); if it is too long, display a warning and truncate the string. 802 The string returned in pOutBuf is zero-terminated. The function returns the 803 length of the resulting string. */ 799 804 800 801 802 803 /* Put the string pszName into the current OMF record. 804 In the OMF record, the string is preceded by a length byte. The 805 string length must not exceed 255; if it is too long, display a 806 warning and truncate the string. Moreover, there must be enough 807 space left in the OMF record; if there isn't, display an error 808 message and abort. */ 809 810 static void put_nstr(const char *pszName, size_t cch) 805 static int make_nstr (const char *pszName, size_t cch, char *pOutBuf) 811 806 { 812 807 if ( cch > SYMBOL_MAX_LENGTH 813 808 && !strstr(pszName + SYMBOL_MAX_LENGTH - SYMBOL_WEAK_LENGTH, "!_") … … 825 820 psz = format_u64((uint32_t)uHash, &szHash[2], 62, 6); 826 821 assert(psz - &szHash[0] == SYMBOL_HASH_LENGTH); 827 822 828 if (!fits(1 + SYMBOL_MAX_LENGTH + SYMBOL_HASH_LENGTH)) 829 doesn_fit(); 830 out_data[out_idx++] = SYMBOL_MAX_LENGTH + SYMBOL_HASH_LENGTH; 831 memcpy(out_data + out_idx, pszName, SYMBOL_MAX_LENGTH); 832 out_idx += SYMBOL_MAX_LENGTH; 833 memcpy(out_data + out_idx, szHash, SYMBOL_HASH_LENGTH); 834 out_idx += SYMBOL_HASH_LENGTH; 823 memcpy(pOutBuf, pszName, SYMBOL_MAX_LENGTH); 824 memcpy(pOutBuf + SYMBOL_MAX_LENGTH, szHash, SYMBOL_HASH_LENGTH); 825 pOutBuf[SYMBOL_MAX_LENGTH + SYMBOL_HASH_LENGTH] = '\0'; 826 827 if (!quiet) 828 warning ("Truncated symbol '%.*s' to '%.*s%s'", cch, pszName, SYMBOL_MAX_LENGTH, pszName, szHash); 835 829 836 warning ("Truncated symbol '%.*s' to '%.*s%s'", cch, pszName, SYMBOL_MAX_LENGTH, pszName, szHash);830 return SYMBOL_MAX_LENGTH + SYMBOL_HASH_LENGTH; 837 831 } 838 832 else 839 833 { 840 834 assert(cch <= 0xff); 841 835 cch &= 0xff; 842 if (!fits(1+cch)) 843 doesn_fit(); 844 out_data[out_idx++] = (byte)cch; 845 memcpy(out_data+out_idx, pszName, cch); 846 out_idx += cch; 836 memcpy(pOutBuf, pszName, cch); 837 pOutBuf[cch] = '\0'; 838 return cch; 847 839 } 848 840 } 849 841 842 /* Put the string pszName into the current OMF record. In the OMF record, the 843 string is preceded by a length byte. The string length must not exceed 255 844 (which is guaranteed by make_nstr()). Moreover, there must be enough space 845 left in the OMF record; if there isn't, display an error message and abort.*/ 846 847 static void put_nstr(const char *pszName, size_t cch) 848 { 849 char szName[256]; 850 851 make_nstr(pszName, cch, szName); 852 cch = strlen(szName); 853 854 if (!fits(1 + cch)) 855 doesn_fit(); 856 out_data[out_idx++] = (byte)cch; 857 memcpy(out_data+out_idx, szName, cch); 858 out_idx += cch; 859 } 860 850 861 /* Put the null-terminated string pszName into the current OMF record. 851 862 See put_nstr() for full details on string handling. */ 852 863 … … 1182 1193 pachName[SYMBOL_MAX_LENGTH + 1] = '_'; 1183 1194 format_u64(u32Hash, &pachName[SYMBOL_MAX_LENGTH + 2], 62, 6); 1184 1195 memcpy(&pachName[SYMBOL_MAX_LENGTH + SYMBOL_HASH_LENGTH], weak_marker, SYMBOL_WEAK_LENGTH + 1); 1185 warning("Truncated symbol '%s' to '%s' (weak)", pszOrgName, pachName); 1196 if (!quiet) 1197 warning("Truncated symbol '%s' to '%s' (weak)", pszOrgName, pachName); 1186 1198 } 1187 1199 1188 1200 return pachName; … … 1201 1213 { 1202 1214 int i; 1203 1215 const char *pub_name; 1216 char szPubName[256]; 1217 int cchPubName; 1204 1218 1205 1219 for (i = 0; i < sym_count - 1; ++i) 1206 1220 if (sym_ptr[i].n_type == (N_INDR|N_EXT) && sym_ptr[i+1].n_type == N_EXT) 1207 1221 { 1222 pub_name = (const char *)(str_ptr + sym_ptr[i].n_un.n_strx); 1223 if (strip_underscore (pub_name)) 1224 ++pub_name; 1225 cchPubName = make_nstr (pub_name, strlen(pub_name), szPubName); 1226 1208 1227 init_rec (ALIAS); 1209 put_sym ((const char *)(str_ptr + sym_ptr[i].n_un.n_strx)); 1228 put_8 (cchPubName); 1229 put_mem (szPubName, cchPubName); 1210 1230 put_sym ((const char *)(str_ptr + sym_ptr[i+1].n_un.n_strx)); 1211 1231 write_rec (); 1212 1232 1213 1233 if (out_lib != NULL) 1214 1234 { 1215 pub_name = (const char *)(str_ptr + sym_ptr[i].n_un.n_strx); 1216 if (strip_underscore (pub_name)) 1217 ++pub_name; 1218 if (omflib_add_pub (out_lib, pub_name, mod_page, lib_errmsg) != 0) 1235 if (omflib_add_pub (out_lib, szPubName, mod_page, lib_errmsg) != 0) 1219 1236 error (lib_errmsg); 1220 1237 } 1221 1238 } … … 1249 1266 const char *name, *pub_name; 1250 1267 dword address; 1251 1268 char szName[256]; 1269 char szPubName[256]; 1270 int cchPubName; 1252 1271 1253 1272 started = FALSE; 1254 1273 for (i = 0; i < sym_count; ++i) … … 1267 1286 /* for weaksymbols we may have to decorate the name */ 1268 1287 if ( sym_ptr[i].n_type >= N_WEAKU && sym_ptr[i].n_type <= N_WEAKB ) 1269 1288 name = weak_process_name(&sym_ptr[i], name, szName, sizeof(szName)); 1289 pub_name = name; 1290 if (strip_underscore (pub_name)) 1291 ++pub_name; 1292 cchPubName = make_nstr (pub_name, strlen(pub_name), szPubName); 1270 1293 1271 1294 if ( out_lib != NULL 1272 1295 && ( ( (sym_ptr[i].n_type & N_EXT) … … 1275 1298 || sym_ptr[i].n_type == N_WEAKT 1276 1299 || sym_ptr[i].n_type == N_WEAKD ) ) 1277 1300 { 1278 pub_name = name; 1279 if (strip_underscore (pub_name)) 1280 ++pub_name; 1281 if (omflib_add_pub (out_lib, pub_name, mod_page, 1301 if (omflib_add_pub (out_lib, szPubName, mod_page, 1282 1302 lib_errmsg) != 0) 1283 1303 error (lib_errmsg); 1284 1304 } … … 1297 1317 put_16 (0); 1298 1318 started = TRUE; 1299 1319 } 1300 put_sym (name); 1320 put_8 (cchPubName); 1321 put_mem (szPubName, cchPubName); 1301 1322 if (big) 1302 1323 put_32 (address); 1303 1324 else … … 1330 1351 int big = ((address >= 0x10000 || force_big) == big); 1331 1352 1332 1353 name++; /* skip the underscore */ 1354 1355 /* Note: no need to call make_nstr() as main definitely fits 255 bytes */ 1356 1333 1357 if (out_lib != NULL) 1334 1358 { 1335 1359 if (omflib_add_pub (out_lib, name, mod_page, lib_errmsg) != 0) … … 2413 2437 static void make_import (const char *pub_name, const char *proc_name, 2414 2438 long ord, const char *mod) 2415 2439 { 2440 char szPubName[256]; 2441 int cchPubName; 2442 2416 2443 /* Skip a leading underscore character if present. */ 2417 2444 2418 2445 if (strip_underscore (pub_name)) 2419 2446 ++pub_name; 2420 2447 2448 cchPubName = make_nstr (pub_name, strlen(pub_name), szPubName); 2449 2421 2450 /* Make the symbol public in the output library. */ 2422 2451 2423 if (omflib_add_pub (out_lib, pub_name, mod_page, lib_errmsg) != 0)2452 if (omflib_add_pub (out_lib, szPubName, mod_page, lib_errmsg) != 0) 2424 2453 error (lib_errmsg); 2425 2454 2426 2455 /* Write the import definition record. */ … … 2436 2465 put_16 (ord); 2437 2466 else if (strcmp (proc_name, pub_name) == 0) 2438 2467 put_8 (0); 2439 else 2440 put_str (proc_name); 2468 else { 2469 put_8 (cchPubName); 2470 put_mem (szPubName, cchPubName); 2471 } 2441 2472 write_rec (); 2442 2473 init_rec (MODEND|REC32); 2443 2474 put_8 (0x00); /* Non-main module without start address */