this repo has no description
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Update mach-o/loader.h and fix a stub-and-resolver export crash.

authored by

Chris Wulff and committed by
Lubos Dolezel
4b886891 709410b1

+169 -33
+139 -24
include/darwin/mach-o/loader.h
··· 1 1 /* 2 - * Copyright (c) 1999-2008 Apple Inc. All Rights Reserved. 2 + * Copyright (c) 1999-2010 Apple Inc. All Rights Reserved. 3 3 * 4 4 * @APPLE_LICENSE_HEADER_START@ 5 5 * ··· 174 174 in the task will be given stack 175 175 execution privilege. Only used in 176 176 MH_EXECUTE filetypes. */ 177 - #define MH_DEAD_STRIPPABLE_DYLIB 0x400000 /* Only for use on dylibs. When 178 - linking against a dylib that 179 - has this bit set, the static linker 180 - will automatically not create a 181 - LC_LOAD_DYLIB load command to the 182 - dylib if no symbols are being 183 - referenced from the dylib. */ 184 177 #define MH_ROOT_SAFE 0x40000 /* When this bit is set, the binary 185 178 declares it is safe for use in 186 179 processes with uid zero */ ··· 197 190 load the main executable at a 198 191 random address. Only used in 199 192 MH_EXECUTE filetypes. */ 193 + #define MH_DEAD_STRIPPABLE_DYLIB 0x400000 /* Only for use on dylibs. When 194 + linking against a dylib that 195 + has this bit set, the static linker 196 + will automatically not create a 197 + LC_LOAD_DYLIB load command to the 198 + dylib if no symbols are being 199 + referenced from the dylib. */ 200 + #define MH_HAS_TLV_DESCRIPTORS 0x800000 /* Contains a section of type 201 + S_THREAD_LOCAL_VARIABLES */ 202 + 203 + #define MH_NO_HEAP_EXECUTION 0x1000000 /* When this bit is set, the OS will 204 + run the main executable with 205 + a non-executable heap even on 206 + platforms (e.g. i386) that don't 207 + require it. Only used in MH_EXECUTE 208 + filetypes. */ 200 209 201 210 /* 202 211 * The load commands directly follow the mach_header. The total size of all ··· 275 284 #define LC_ENCRYPTION_INFO 0x21 /* encrypted segment information */ 276 285 #define LC_DYLD_INFO 0x22 /* compressed dyld information */ 277 286 #define LC_DYLD_INFO_ONLY (0x22|LC_REQ_DYLD) /* compressed dyld information only */ 287 + #define LC_LOAD_UPWARD_DYLIB (0x23 | LC_REQ_DYLD) /* load upward dylib */ 288 + #define LC_VERSION_MIN_MACOSX 0x24 /* build for MacOSX min OS version */ 289 + #define LC_VERSION_MIN_IPHONEOS 0x25 /* build for iPhoneOS min OS version */ 290 + #define LC_FUNCTION_STARTS 0x26 /* compressed table of function start addresses */ 291 + #define LC_DYLD_ENVIRONMENT 0x27 /* string for dyld to treat 292 + like environment variable */ 293 + #define LC_MAIN (0x28|LC_REQ_DYLD) /* replacement for LC_UNIXTHREAD */ 294 + #define LC_DATA_IN_CODE 0x29 /* table of non-instructions in __text */ 295 + #define LC_SOURCE_VERSION 0x2A /* source version used to build binary */ 296 + #define LC_DYLIB_CODE_SIGN_DRS 0x2B /* Code signing DRs copied from linked dylibs */ 297 + 278 298 279 299 /* 280 300 * A variable length string in a load command is represented by an lc_str ··· 465 485 symbol pointers to lazy 466 486 loaded dylibs */ 467 487 /* 488 + * Section types to support thread local variables 489 + */ 490 + #define S_THREAD_LOCAL_REGULAR 0x11 /* template of initial 491 + values for TLVs */ 492 + #define S_THREAD_LOCAL_ZEROFILL 0x12 /* template of initial 493 + values for TLVs */ 494 + #define S_THREAD_LOCAL_VARIABLES 0x13 /* TLV descriptors */ 495 + #define S_THREAD_LOCAL_VARIABLE_POINTERS 0x14 /* pointers to TLV 496 + descriptors */ 497 + #define S_THREAD_LOCAL_INIT_FUNCTION_POINTERS 0x15 /* functions to call 498 + to initialize TLV 499 + values */ 500 + 501 + /* 468 502 * Constants for the section attributes part of the flags field of a section 469 503 * structure. 470 504 */ ··· 710 744 * the name of the dynamic linker (LC_LOAD_DYLINKER). And a dynamic linker 711 745 * contains a dylinker_command to identify the dynamic linker (LC_ID_DYLINKER). 712 746 * A file can have at most one of these. 747 + * This struct is also used for the LC_DYLD_ENVIRONMENT load command and 748 + * contains string for dyld to treat like environment variable. 713 749 */ 714 750 struct dylinker_command { 715 - uint32_t cmd; /* LC_ID_DYLINKER or LC_LOAD_DYLINKER */ 751 + uint32_t cmd; /* LC_ID_DYLINKER, LC_LOAD_DYLINKER or 752 + LC_DYLD_ENVIRONMENT */ 716 753 uint32_t cmdsize; /* includes pathname string */ 717 754 union lc_str name; /* dynamic linker's path name */ 718 755 }; ··· 1116 1153 * of data in the __LINKEDIT segment. 1117 1154 */ 1118 1155 struct linkedit_data_command { 1119 - uint32_t cmd; /* LC_CODE_SIGNATURE or LC_SEGMENT_SPLIT_INFO */ 1156 + uint32_t cmd; /* LC_CODE_SIGNATURE, LC_SEGMENT_SPLIT_INFO, 1157 + LC_FUNCTION_STARTS, LC_DATA_IN_CODE, 1158 + or LC_DYLIB_CODE_SIGN_DRS */ 1120 1159 uint32_t cmdsize; /* sizeof(struct linkedit_data_command) */ 1121 1160 uint32_t dataoff; /* file offset of data in __LINKEDIT segment */ 1122 1161 uint32_t datasize; /* file size of data in __LINKEDIT segment */ ··· 1136 1175 }; 1137 1176 1138 1177 /* 1178 + * The version_min_command contains the min OS version on which this 1179 + * binary was built to run. 1180 + */ 1181 + struct version_min_command { 1182 + uint32_t cmd; /* LC_VERSION_MIN_MACOSX or 1183 + LC_VERSION_MIN_IPHONEOS */ 1184 + uint32_t cmdsize; /* sizeof(struct min_version_command) */ 1185 + uint32_t version; /* X.Y.Z is encoded in nibbles xxxx.yy.zz */ 1186 + uint32_t sdk; /* X.Y.Z is encoded in nibbles xxxx.yy.zz */ 1187 + }; 1188 + 1189 + /* 1139 1190 * The dyld_info_command contains the file offsets and sizes of 1140 1191 * the new compressed form of the information dyld needs to 1141 1192 * load the image. This information is used by dyld on Mac OS X ··· 1164 1215 /* 1165 1216 * Dyld binds an image during the loading process, if the image 1166 1217 * requires any pointers to be initialized to symbols in other images. 1167 - * The rebase information is a stream of byte sized 1218 + * The bind information is a stream of byte sized 1168 1219 * opcodes whose symbolic names start with BIND_OPCODE_. 1169 1220 * Conceptually the bind information is a table of tuples: 1170 1221 * <seg-index, seg-offset, type, symbol-library-ordinal, symbol-name, addend> ··· 1217 1268 * The export area is a stream of nodes. The first node sequentially 1218 1269 * is the start node for the trie. 1219 1270 * 1220 - * Nodes for a symbol start with a byte that is the length of 1271 + * Nodes for a symbol start with a uleb128 that is the length of 1221 1272 * the exported symbol information for the string so far. 1222 - * If there is no exported symbol, the byte is zero. If there 1223 - * is exported info, it follows the length byte. The exported 1224 - * info normally consists of a flags and offset both encoded 1225 - * in uleb128. The offset is location of the content named 1226 - * by the symbol. It is the offset from the mach_header for 1227 - * the image. 1273 + * If there is no exported symbol, the node starts with a zero byte. 1274 + * If there is exported info, it follows the length. 1275 + * 1276 + * First is a uleb128 containing flags. Normally, it is followed by 1277 + * a uleb128 encoded offset which is location of the content named 1278 + * by the symbol from the mach_header for the image. If the flags 1279 + * is EXPORT_SYMBOL_FLAGS_REEXPORT, then following the flags is 1280 + * a uleb128 encoded library ordinal, then a zero terminated 1281 + * UTF8 string. If the string is zero length, then the symbol 1282 + * is re-export from the specified dylib with the same name. 1283 + * If the flags is EXPORT_SYMBOL_FLAGS_STUB_AND_RESOLVER, then following 1284 + * the flags is two uleb128s: the stub offset and the resolver offset. 1285 + * The stub is used by non-lazy pointers. The resolver is used 1286 + * by lazy pointers and must be called to get the actual address to use. 1228 1287 * 1229 - * After the initial byte and optional exported symbol information 1230 - * is a byte of how many edges (0-255) that this node has leaving 1231 - * it, followed by each edge. 1232 - * Each edge is a zero terminated cstring of the addition chars 1288 + * After the optional exported symbol information is a byte of 1289 + * how many edges (0-255) that this node has leaving it, 1290 + * followed by each edge. 1291 + * Each edge is a zero terminated UTF8 of the addition chars 1233 1292 * in the symbol, followed by a uleb128 offset for the node that 1234 1293 * edge points to. 1235 1294 * ··· 1297 1356 #define EXPORT_SYMBOL_FLAGS_KIND_REGULAR 0x00 1298 1357 #define EXPORT_SYMBOL_FLAGS_KIND_THREAD_LOCAL 0x01 1299 1358 #define EXPORT_SYMBOL_FLAGS_WEAK_DEFINITION 0x04 1300 - #define EXPORT_SYMBOL_FLAGS_INDIRECT_DEFINITION 0x08 1301 - #define EXPORT_SYMBOL_FLAGS_HAS_SPECIALIZATIONS 0x10 1359 + #define EXPORT_SYMBOL_FLAGS_REEXPORT 0x08 1360 + #define EXPORT_SYMBOL_FLAGS_STUB_AND_RESOLVER 0x10 1302 1361 1303 1362 /* 1304 1363 * The symseg_command contains the offset and size of the GNU style ··· 1338 1397 uint32_t cmdsize; /* includes pathname string */ 1339 1398 union lc_str name; /* files pathname */ 1340 1399 uint32_t header_addr; /* files virtual address */ 1400 + }; 1401 + 1402 + 1403 + /* 1404 + * The entry_point_command is a replacement for thread_command. 1405 + * It is used for main executables to specify the location (file offset) 1406 + * of main(). If -stack_size was used at link time, the stacksize 1407 + * field will contain the stack size need for the main thread. 1408 + */ 1409 + struct entry_point_command { 1410 + uint32_t cmd; /* LC_MAIN only used in MH_EXECUTE filetypes */ 1411 + uint32_t cmdsize; /* 24 */ 1412 + uint64_t entryoff; /* file (__TEXT) offset of main() */ 1413 + uint64_t stacksize;/* if not zero, initial stack size */ 1414 + }; 1415 + 1416 + 1417 + /* 1418 + * The source_version_command is an optional load command containing 1419 + * the version of the sources used to build the binary. 1420 + */ 1421 + struct source_version_command { 1422 + uint32_t cmd; /* LC_SOURCE_VERSION */ 1423 + uint32_t cmdsize; /* 16 */ 1424 + uint64_t version; /* A.B.C.D.E packed as a24.b10.c10.d10.e10 */ 1425 + }; 1426 + 1427 + 1428 + /* 1429 + * The LC_DATA_IN_CODE load commands uses a linkedit_data_command 1430 + * to point to an array of data_in_code_entry entries. Each entry 1431 + * describes a range of data in a code section. This load command 1432 + * is only used in final linked images. 1433 + */ 1434 + struct data_in_code_entry { 1435 + uint32_t offset; /* from mach_header to start of data range*/ 1436 + uint16_t length; /* number of bytes in data range */ 1437 + uint16_t kind; /* a DICE_KIND_* value */ 1438 + }; 1439 + #define DICE_KIND_DATA 0x0001 /* L$start$data$... label */ 1440 + #define DICE_KIND_JUMP_TABLE8 0x0002 /* L$start$jt8$... label */ 1441 + #define DICE_KIND_JUMP_TABLE16 0x0003 /* L$start$jt16$... label */ 1442 + #define DICE_KIND_JUMP_TABLE32 0x0004 /* L$start$jt32$... label */ 1443 + #define DICE_KIND_ABS_JUMP_TABLE32 0x0005 /* L$start$jta32$... label */ 1444 + 1445 + 1446 + 1447 + /* 1448 + * Sections of type S_THREAD_LOCAL_VARIABLES contain an array 1449 + * of tlv_descriptor structures. 1450 + */ 1451 + struct tlv_descriptor 1452 + { 1453 + void* (*thunk)(struct tlv_descriptor*); 1454 + unsigned long key; 1455 + unsigned long offset; 1341 1456 }; 1342 1457 1343 1458 #endif /* _MACHO_LOADER_H_ */
+30 -1
src/libmach-o/MachOImpl.cpp
··· 246 246 exp->flag = uleb128(p); 247 247 248 248 // TODO: flag == 8 (EXPORT_SYMBOL_FLAGS_REEXPORT) 249 - if (exp->flag & 8) 249 + if (exp->flag & EXPORT_SYMBOL_FLAGS_REEXPORT) 250 250 { 251 251 LOG << "FIXME: reexports not currently handled\n"; 252 252 return; ··· 254 254 255 255 exp->addr = uleb128(p); 256 256 LOG << "export: " << name_buf << " flags=" << std::hex << exp->flag << std::dec << " addr=" << (void*)exp->addr << std::endl; 257 + 258 + if (exp->flag & EXPORT_SYMBOL_FLAGS_STUB_AND_RESOLVER) 259 + { 260 + (void)uleb128(p); // TODO: save & use the resolver info for lazy pointers 261 + LOG << "FIXME: resolver not currently handled\n"; 262 + } 257 263 258 264 m_exports.push_back(exp); 259 265 ··· 564 570 } 565 571 566 572 case LC_LOAD_DYLIB: 573 + case LC_LOAD_WEAK_DYLIB: 574 + case LC_LAZY_LOAD_DYLIB: 575 + case LC_REEXPORT_DYLIB: 576 + case LC_LOAD_UPWARD_DYLIB: 567 577 { 568 578 dylib* lib = &reinterpret_cast<dylib_command*>(cmds_ptr)->dylib; 569 579 const char* name = (char*)cmds_ptr + lib->name.offset; ··· 580 590 m_rpaths.push_back(rpath); 581 591 break; 582 592 } 593 + 594 + case LC_SUB_FRAMEWORK: 595 + case LC_SUB_UMBRELLA: 596 + case LC_SUB_CLIENT: 597 + case LC_SUB_LIBRARY: 598 + case LC_FUNCTION_STARTS: 599 + case LC_DATA_IN_CODE: 600 + case LC_CODE_SIGNATURE: 601 + case LC_SEGMENT_SPLIT_INFO: 602 + case LC_ID_DYLIB: 603 + case LC_VERSION_MIN_MACOSX: 604 + case LC_VERSION_MIN_IPHONEOS: 605 + case LC_SOURCE_VERSION: 606 + case LC_DYLIB_CODE_SIGN_DRS: 607 + break; 608 + 609 + default: 610 + std::cerr << "Unhandled loader command " << std::hex << (int)cmds_ptr->cmd << std::dec << std::endl; 611 + break; 583 612 584 613 } 585 614
-8
src/libmach-o/MachOImpl.h
··· 97 97 }; 98 98 }; 99 99 100 - #define LC_MAIN (0x28|LC_REQ_DYLD) 101 - struct entry_point_command { 102 - uint32_t cmd; /* LC_MAIN only used in MH_EXECUTE filetypes */ 103 - uint32_t cmdsize; /* 24 */ 104 - uint64_t entryoff; /* file (__TEXT) offset of main() */ 105 - uint64_t stacksize;/* if not zero, initial stack size */ 106 - }; 107 - 108 100 #endif