Loading...
src/ImageLoaderMachO.cpp dyld-239.3 dyld-132.13
--- dyld/dyld-239.3/src/ImageLoaderMachO.cpp
+++ dyld/dyld-132.13/src/ImageLoaderMachO.cpp
@@ -1,6 +1,6 @@
 /* -*- mode: C++; c-basic-offset: 4; tab-width: 4 -*-
  *
- * Copyright (c) 2004-2010 Apple Inc. All rights reserved.
+ * Copyright (c) 2004-2008 Apple Inc. All rights reserved.
  *
  * @APPLE_LICENSE_HEADER_START@
  * 
@@ -27,7 +27,7 @@
 #define __eip	eip 
 #define __rip	rip 
 
-#define __STDC_LIMIT_MACROS
+
 #include <string.h>
 #include <fcntl.h>
 #include <errno.h>
@@ -40,38 +40,26 @@
 #include <mach-o/loader.h> 
 #include <mach-o/nlist.h> 
 #include <sys/sysctl.h>
-#include <sys/syscall.h>
 #include <libkern/OSAtomic.h>
 #include <libkern/OSCacheControl.h>
-#include <stdint.h>
-#include <System/sys/codesign.h>
 
 #include "ImageLoaderMachO.h"
 #include "ImageLoaderMachOCompressed.h"
-#if SUPPORT_CLASSIC_MACHO
 #include "ImageLoaderMachOClassic.h"
-#endif
 #include "mach-o/dyld_images.h"
 
-// <rdar://problem/8718137> use stack guard random value to add padding between dylibs
-extern "C" long __stack_chk_guard;
-
-#ifndef LC_LOAD_UPWARD_DYLIB
-	#define	LC_LOAD_UPWARD_DYLIB (0x23|LC_REQ_DYLD)	/* load of dylib whose initializers run later */
-#endif
+
 
 // relocation_info.r_length field has value 3 for 64-bit executables and value 2 for 32-bit executables
 #if __LP64__
 	#define LC_SEGMENT_COMMAND		LC_SEGMENT_64
 	#define LC_ROUTINES_COMMAND		LC_ROUTINES_64
-	#define LC_SEGMENT_COMMAND_WRONG LC_SEGMENT
 	struct macho_segment_command	: public segment_command_64  {};
 	struct macho_section			: public section_64  {};	
 	struct macho_routines_command	: public routines_command_64  {};	
 #else
 	#define LC_SEGMENT_COMMAND		LC_SEGMENT
 	#define LC_ROUTINES_COMMAND		LC_ROUTINES
-	#define LC_SEGMENT_COMMAND_WRONG LC_SEGMENT_64
 	struct macho_segment_command	: public segment_command {};
 	struct macho_section			: public section  {};	
 	struct macho_routines_command	: public routines_command  {};	
@@ -94,7 +82,7 @@
 	fReadOnlyImportSegment(false),
 #endif
 	fHasSubLibraries(false), fHasSubUmbrella(false), fInUmbrella(false), fHasDOFSections(false), fHasDashInit(false),
-	fHasInitializers(false), fHasTerminators(false), fRegisteredAsRequiresCoalescing(false)
+	fHasInitializers(false), fHasTerminators(false)
 {
 	fIsSplitSeg = ((mh->flags & MH_SPLIT_SEGS) != 0);        
 
@@ -120,23 +108,15 @@
 
 // determine if this mach-o file has classic or compressed LINKEDIT and number of segments it has
 void ImageLoaderMachO::sniffLoadCommands(const macho_header* mh, const char* path, bool* compressed, 
-											unsigned int* segCount, unsigned int* libCount, const LinkContext& context,
-											const linkedit_data_command** codeSigCmd)
+											unsigned int* segCount, unsigned int* libCount)
 {
 	*compressed = false;
 	*segCount = 0;
 	*libCount = 0;
-	*codeSigCmd = NULL;
-	struct macho_segment_command* segCmd;
-	bool foundLoadCommandSegment = false;
-	uint32_t loadCommandSegmentIndex = 0xFFFFFFFF;
-	uintptr_t loadCommandSegmentVMStart = 0;
-	uintptr_t loadCommandSegmentVMEnd = 0;
-
 	const uint32_t cmd_count = mh->ncmds;
-	const struct load_command* const startCmds    = (struct load_command*)(((uint8_t*)mh) + sizeof(macho_header));
+	const struct load_command* const cmds    = (struct load_command*)(((uint8_t*)mh) + sizeof(macho_header));
 	const struct load_command* const endCmds = (struct load_command*)(((uint8_t*)mh) + sizeof(macho_header) + mh->sizeofcmds);
-	const struct load_command* cmd = startCmds;
+	const struct load_command* cmd = cmds;
 	for (uint32_t i = 0; i < cmd_count; ++i) {
 		switch (cmd->cmd) {
 			case LC_DYLD_INFO:
@@ -144,67 +124,23 @@
 				*compressed = true;
 				break;
 			case LC_SEGMENT_COMMAND:
-				segCmd = (struct macho_segment_command*)cmd;
 				// ignore zero-sized segments
-				if ( segCmd->vmsize != 0 )
+				if ( ((struct macho_segment_command*)cmd)->vmsize != 0 )
 					*segCount += 1;
-				// <rdar://problem/7942521> all load commands must be in an executable segment
-				if ( context.codeSigningEnforced && (segCmd->fileoff < mh->sizeofcmds) && (segCmd->filesize != 0) ) {
-					if ( (segCmd->fileoff != 0) || (segCmd->filesize < (mh->sizeofcmds+sizeof(macho_header))) ) 
-						dyld::throwf("malformed mach-o image: segment %s does not span all load commands", segCmd->segname); 
-					if ( segCmd->initprot != (VM_PROT_READ | VM_PROT_EXECUTE) ) 
-						dyld::throwf("malformed mach-o image: load commands found in segment %s with wrong permissions", segCmd->segname); 
-					if ( foundLoadCommandSegment )
-						throw "load commands in multiple segments";
-					foundLoadCommandSegment = true;
-					loadCommandSegmentIndex = i;
-					loadCommandSegmentVMStart = segCmd->vmaddr;
-					loadCommandSegmentVMEnd   = segCmd->vmaddr + segCmd->vmsize;
-				}
-				break;
-			case LC_SEGMENT_COMMAND_WRONG:
-				dyld::throwf("malformed mach-o image: wrong LC_SEGMENT[_64] for architecture"); 
 				break;
 			case LC_LOAD_DYLIB:
 			case LC_LOAD_WEAK_DYLIB:
 			case LC_REEXPORT_DYLIB:
-			case LC_LOAD_UPWARD_DYLIB:
 				*libCount += 1;
-				break;
-			case LC_CODE_SIGNATURE:
-				*codeSigCmd = (struct linkedit_data_command*)cmd; // only support one LC_CODE_SIGNATURE per image
 				break;
 		}
 		uint32_t cmdLength = cmd->cmdsize;
 		cmd = (const struct load_command*)(((char*)cmd)+cmdLength);
-		if ( (cmd > endCmds) || (cmd < startCmds) ) {
+		if ( cmd > endCmds ) {
 			dyld::throwf("malformed mach-o image: load command #%d length (%u) would exceed sizeofcmds (%u) in %s", 
 							i, cmdLength, mh->sizeofcmds, path);
 		}
 	}
-	
-	if ( context.codeSigningEnforced && !foundLoadCommandSegment )
-		throw "load commands not in a segment";
-	// <rdar://problem/13145644> verify another segment does not over-map load commands
-	cmd = startCmds;
-	if ( context.codeSigningEnforced ) {
-		for (uint32_t i = 0; i < cmd_count; ++i) {
-			switch (cmd->cmd) {
-				case LC_SEGMENT_COMMAND:
-					if ( i != loadCommandSegmentIndex ) {
-						segCmd = (struct macho_segment_command*)cmd;
-						uintptr_t start = segCmd->vmaddr;
-						uintptr_t end = segCmd->vmaddr + segCmd->vmsize;
-						if ( ((start <= loadCommandSegmentVMStart) && (end > loadCommandSegmentVMStart)) 
-						   || ((start >= loadCommandSegmentVMStart) && (start < loadCommandSegmentVMEnd)) )
-							dyld::throwf("malformed mach-o image: segment %s overlaps load commands", segCmd->segname); 
-					}
-					break;
-			}
-			cmd = (const struct load_command*)(((char*)cmd)+cmd->cmdsize);
-		}
-	}
-	
 	// fSegmentsArrayCount is only 8-bits
 	if ( *segCount > 255 )
 		dyld::throwf("malformed mach-o image: more than 255 segments in %s", path);
@@ -227,17 +163,12 @@
 	bool compressed;
 	unsigned int segCount;
 	unsigned int libCount;
-	const linkedit_data_command* codeSigCmd;
-	sniffLoadCommands(mh, path, &compressed, &segCount, &libCount, context, &codeSigCmd);
+	sniffLoadCommands(mh, path, &compressed, &segCount, &libCount);
 	// instantiate concrete class based on content of load commands
 	if ( compressed ) 
 		return ImageLoaderMachOCompressed::instantiateMainExecutable(mh, slide, path, segCount, libCount, context);
 	else
-#if SUPPORT_CLASSIC_MACHO
 		return ImageLoaderMachOClassic::instantiateMainExecutable(mh, slide, path, segCount, libCount, context);
-#else
-		throw "missing LC_DYLD_INFO load command";
-#endif
 }
 
 
@@ -259,37 +190,27 @@
 	bool compressed;
 	unsigned int segCount;
 	unsigned int libCount;
-	const linkedit_data_command* codeSigCmd;
-	sniffLoadCommands((const macho_header*)fileData, path, &compressed, &segCount, &libCount, context, &codeSigCmd);
+	sniffLoadCommands((const macho_header*)fileData, path, &compressed, &segCount, &libCount);
 	// instantiate concrete class based on content of load commands
 	if ( compressed ) 
-		return ImageLoaderMachOCompressed::instantiateFromFile(path, fd, fileData, offsetInFat, lenInFat, info, segCount, libCount, codeSigCmd, context);
+		return ImageLoaderMachOCompressed::instantiateFromFile(path, fd, fileData, offsetInFat, lenInFat, info, segCount, libCount, context);
 	else
-#if SUPPORT_CLASSIC_MACHO
-		return ImageLoaderMachOClassic::instantiateFromFile(path, fd, fileData, offsetInFat, lenInFat, info, segCount, libCount, codeSigCmd, context);
-#else
-		throw "missing LC_DYLD_INFO load command";
-#endif
+		return ImageLoaderMachOClassic::instantiateFromFile(path, fd, fileData, offsetInFat, lenInFat, info, segCount, libCount, context);
 }
 
 // create image by using cached mach-o file
-ImageLoader* ImageLoaderMachO::instantiateFromCache(const macho_header* mh, const char* path, long slide, const struct stat& info, const LinkContext& context)
+ImageLoader* ImageLoaderMachO::instantiateFromCache(const macho_header* mh, const char* path, const struct stat& info, const LinkContext& context)
 {
 	// instantiate right concrete class
 	bool compressed;
 	unsigned int segCount;
 	unsigned int libCount;
-	const linkedit_data_command* codeSigCmd;
-	sniffLoadCommands(mh, path, &compressed, &segCount, &libCount, context, &codeSigCmd);
+	sniffLoadCommands(mh, path, &compressed, &segCount, &libCount);
 	// instantiate concrete class based on content of load commands
 	if ( compressed ) 
-		return ImageLoaderMachOCompressed::instantiateFromCache(mh, path, slide, info, segCount, libCount, context);
+		return ImageLoaderMachOCompressed::instantiateFromCache(mh, path, info, segCount, libCount, context);
 	else
-#if SUPPORT_CLASSIC_MACHO
-		return ImageLoaderMachOClassic::instantiateFromCache(mh, path, slide, info, segCount, libCount, context);
-#else
-		throw "missing LC_DYLD_INFO load command";
-#endif
+		return ImageLoaderMachOClassic::instantiateFromCache(mh, path, info, segCount, libCount, context);
 }
 
 // create image by copying an in-memory mach-o file
@@ -298,34 +219,14 @@
 	bool compressed;
 	unsigned int segCount;
 	unsigned int libCount;
-	const linkedit_data_command* sigcmd;
-	sniffLoadCommands(mh, moduleName, &compressed, &segCount, &libCount, context, &sigcmd);
+	sniffLoadCommands(mh, moduleName, &compressed, &segCount, &libCount);
 	// instantiate concrete class based on content of load commands
 	if ( compressed ) 
 		return ImageLoaderMachOCompressed::instantiateFromMemory(moduleName, mh, len, segCount, libCount, context);
 	else
-#if SUPPORT_CLASSIC_MACHO
 		return ImageLoaderMachOClassic::instantiateFromMemory(moduleName, mh, len, segCount, libCount, context);
-#else
-		throw "missing LC_DYLD_INFO load command";
-#endif
-}
-
-
-int ImageLoaderMachO::crashIfInvalidCodeSignature()
-{
-	// Now that segments are mapped in, try reading from first executable segment.
-	// If code signing is enabled the kernel will validate the code signature
-	// when paging in, and kill the process if invalid.
-	for(unsigned int i=0; i < fSegmentsCount; ++i) {
-		if ( (segFileOffset(i) == 0) && (segFileSize(i) != 0) ) {
-			// return read value to ensure compiler does not optimize away load
-			int* p = (int*)segActualLoadAddress(i);
-			return *p;
-		}
-	}
-	return 0;
-}
+}
+
 
 
 void ImageLoaderMachO::parseLoadCmds()
@@ -338,7 +239,7 @@
 #if TEXT_RELOC_SUPPORT
 		// __TEXT segment always starts at beginning of file and contains mach_header and load commands
 		if ( strcmp(segName(i),"__TEXT") == 0 ) {
-			if ( segHasRebaseFixUps(i) && (fSlide != 0) )
+			if ( segHasRebaseFixUps(i) )
 				fTextSegmentRebases = true;
 			if ( segHasBindFixUps(i) )
 				fTextSegmentBinds = true;
@@ -357,7 +258,6 @@
 	// keep count of prebound images with weak exports
 	if ( this->participatesInCoalescing() ) {
 		++fgImagesRequiringCoalescing;
-		fRegisteredAsRequiresCoalescing = true;
 		if ( this->hasCoalescedExports() ) 
 			++fgImagesHasWeakDefinitions;
 	}
@@ -370,8 +270,6 @@
 	const dyld_info_command* dyldInfo = NULL;
 	const macho_nlist* symbolTable = NULL;
 	const char* symbolTableStrings = NULL;
-	const struct load_command* firstUnknownCmd = NULL;
-	const struct version_min_command* minOSVersionCmd = NULL;
 	const dysymtab_command* dynSymbolTable = NULL;
 	const uint32_t cmd_count = ((macho_header*)fMachOData)->ncmds;
 	const struct load_command* const cmds = (struct load_command*)&fMachOData[sizeof(macho_header)];
@@ -436,35 +334,14 @@
 			case LC_RPATH:
 			case LC_LOAD_WEAK_DYLIB:
 		    case LC_REEXPORT_DYLIB:
-			case LC_LOAD_UPWARD_DYLIB:
-			case LC_MAIN:
 				// do nothing, just prevent LC_REQ_DYLD exception from occuring
 				break;
-			case LC_VERSION_MIN_MACOSX:
-			case LC_VERSION_MIN_IPHONEOS:
-				minOSVersionCmd = (version_min_command*)cmd;
-				break;
 			default:
-				if ( (cmd->cmd & LC_REQ_DYLD) != 0 ) {
-					if ( firstUnknownCmd == NULL )
-						firstUnknownCmd = cmd;
-				}
-				break;
+				if ( (cmd->cmd & LC_REQ_DYLD) != 0 )
+					dyld::throwf("unknown required load command 0x%08X", cmd->cmd);
 		}
 		cmd = (const struct load_command*)(((char*)cmd)+cmd->cmdsize);
 	}
-	if ( firstUnknownCmd != NULL ) {
-		if ( minOSVersionCmd != NULL )  {
-			dyld::throwf("cannot load '%s' because it was built for OS version %u.%u (load command 0x%08X is unknown)", 
-						 this->getShortName(),
-						 minOSVersionCmd->version >> 16, ((minOSVersionCmd->version >> 8) & 0xff), 
-						 firstUnknownCmd->cmd);
-		}
-		else {
-			dyld::throwf("cannot load '%s' (load command 0x%08X is unknown)", this->getShortName(), firstUnknownCmd->cmd);
-		}
-	}
-	
 	
 	if ( dyldInfo != NULL )
 		this->setDyldInfo(dyldInfo);
@@ -477,8 +354,8 @@
 // for UnmapSegments() to work
 void ImageLoaderMachO::destroy()
 {
-	// update count of images with weak exports
-	if ( fRegisteredAsRequiresCoalescing ) {
+	// keep count of images with weak exports
+	if ( this->participatesInCoalescing() ) {
 		--fgImagesRequiringCoalescing;
 		if ( this->hasCoalescedExports() ) 
 			--fgImagesHasWeakDefinitions;
@@ -751,57 +628,39 @@
 	fSlide = slide;
 }
 
-void ImageLoaderMachO::loadCodeSignature(const struct linkedit_data_command* codeSigCmd, int fd,  uint64_t offsetInFatFile, const LinkContext& context)
-{
-	// if dylib being loaded has no code signature load command
-	if ( codeSigCmd == NULL ) {
-#if __MAC_OS_X_VERSION_MIN_REQUIRED
-		bool codeSigningEnforced = context.codeSigningEnforced;
-		if ( context.mainExecutableCodeSigned && !codeSigningEnforced ) {
-			static bool codeSignEnforcementDynamicallyEnabled = false;
-			if ( !codeSignEnforcementDynamicallyEnabled ) {
-				uint32_t flags;
-				if ( csops(0, CS_OPS_STATUS, &flags, sizeof(flags)) != -1 ) {
-					if ( flags & CS_ENFORCEMENT ) {
-						codeSignEnforcementDynamicallyEnabled = true;
-					}
+#if CODESIGNING_SUPPORT
+void ImageLoaderMachO::loadCodeSignature(const uint8_t* fileData, int fd,  uint64_t offsetInFatFile)
+{
+	// look for code signature load command
+	// do this in the read() memory buffer - not in the mapped __TEXT segment
+	const uint32_t cmd_count = ((macho_header*)fileData)->ncmds;
+	const struct load_command* const cmds = (struct load_command*)&fileData[sizeof(macho_header)];
+	const struct load_command* cmd = cmds;
+	for (uint32_t i = 0; i < cmd_count; ++i) {
+		if ( cmd->cmd == LC_CODE_SIGNATURE ) {
+			const struct linkedit_data_command *sigcmd = (struct linkedit_data_command*) cmd;
+			// fLinkEditBase is not set up yet, so compute it
+			const uint8_t* linkEditBase = NULL;
+			for(unsigned int i=0; i < fSegmentsCount; ++i) {
+				// set up pointer to __LINKEDIT segment
+				if ( strcmp(segName(i),"__LINKEDIT") == 0 ) {
+					linkEditBase = (uint8_t*)(segActualLoadAddress(i) - segFileOffset(i));
+					break;
 				}
 			}
-			codeSigningEnforced = codeSignEnforcementDynamicallyEnabled;
-		}
-		// if we require dylibs to be code signed
-		if ( codeSigningEnforced  ) {
-			// if there is a non-load command based code signature, use it
-			off_t offset = (off_t)offsetInFatFile;
-			if ( fcntl(fd, F_FINDSIGS, &offset, sizeof(offset)) != -1 )
-				return;
-			// otherwise gracefully return from dlopen()
-			dyld::throwf("required code signature missing for '%s'\n", this->getPath());
-		}
+			fsignatures_t siginfo;
+			siginfo.fs_file_start=offsetInFatFile;				// CD coverage offset 
+			siginfo.fs_blob_start=(void*)(linkEditBase+sigcmd->dataoff);	// start of CD in file
+			siginfo.fs_blob_size=sigcmd->datasize;			// size of CD
+			int result = fcntl(fd, F_ADDSIGS, &siginfo);
+			if ( result == -1 ) 
+				dyld::log("dyld: code signature failed for %s with errno=%d\n", this->getPath(), errno);
+			break; // only support one LC_CODE_SIGNATURE
+		}
+		cmd = (const struct load_command*)(((char*)cmd)+cmd->cmdsize);
+	}
+}
 #endif
-	}
-	else {
-#if __MAC_OS_X_VERSION_MIN_REQUIRED
-		// <rdar://problem/13622786> ignore code signatures in binaries built with pre-10.9 tools
-		if ( this->sdkVersion() < DYLD_MACOSX_VERSION_10_9 ) {
-			return;
-		}
-#endif
-		fsignatures_t siginfo;
-		siginfo.fs_file_start=offsetInFatFile;				// start of mach-o slice in fat file 
-		siginfo.fs_blob_start=(void*)(long)(codeSigCmd->dataoff);	// start of CD in mach-o file
-		siginfo.fs_blob_size=codeSigCmd->datasize;			// size of CD
-		int result = fcntl(fd, F_ADDFILESIGS, &siginfo);
-		if ( result == -1 ) {
-			if ( (errno == EPERM) || (errno == EBADEXEC) )
-				dyld::throwf("code signature invalid for '%s'\n", this->getPath());
-			if ( context.verboseCodeSignatures ) 
-				dyld::log("dyld: Failed registering code signature for %s, errno=%d\n", this->getPath(), errno);
-			else
-				dyld::log("dyld: Registered code signature for %s\n", this->getPath());
-		}
-	}
-}
 
 
 const char* ImageLoaderMachO::getInstallPath() const
@@ -813,85 +672,6 @@
 	return NULL;
 }
 
-void ImageLoaderMachO::registerInterposing()
-{
-	// mach-o files advertise interposing by having a __DATA __interpose section
-	struct InterposeData { uintptr_t replacement; uintptr_t replacee; };
-	const uint32_t cmd_count = ((macho_header*)fMachOData)->ncmds;
-	const struct load_command* const cmds = (struct load_command*)&fMachOData[sizeof(macho_header)];
-	const struct load_command* cmd = cmds;
-	for (uint32_t i = 0; i < cmd_count; ++i) {
-		switch (cmd->cmd) {
-			case LC_SEGMENT_COMMAND:
-				{
-					const struct macho_segment_command* seg = (struct macho_segment_command*)cmd;
-					const struct macho_section* const sectionsStart = (struct macho_section*)((char*)seg + sizeof(struct macho_segment_command));
-					const struct macho_section* const sectionsEnd = &sectionsStart[seg->nsects];
-					for (const struct macho_section* sect=sectionsStart; sect < sectionsEnd; ++sect) {
-						if ( ((sect->flags & SECTION_TYPE) == S_INTERPOSING) || ((strcmp(sect->sectname, "__interpose") == 0) && (strcmp(seg->segname, "__DATA") == 0)) ) {
-							const InterposeData* interposeArray = (InterposeData*)(sect->addr + fSlide);
-							const unsigned int count = sect->size / sizeof(InterposeData);
-							for (uint32_t i=0; i < count; ++i) {
-								ImageLoader::InterposeTuple tuple;
-								tuple.replacement		= interposeArray[i].replacement;
-								tuple.replacementImage	= this;
-								tuple.replacee			= interposeArray[i].replacee;
-								// <rdar://problem/7937695> verify that replacement is in this image
-								if ( this->containsAddress((void*)tuple.replacement) ) {
-									for (std::vector<InterposeTuple>::iterator it=fgInterposingTuples.begin(); it != fgInterposingTuples.end(); it++) {
-										if ( it->replacee == tuple.replacee ) {
-											tuple.replacee = it->replacement;
-										}
-									}
-									ImageLoader::fgInterposingTuples.push_back(tuple);
-								}
-							}
-						}
-					}
-				}
-				break;
-		}
-		cmd = (const struct load_command*)(((char*)cmd)+cmd->cmdsize);
-	}
-}
-
-uint32_t ImageLoaderMachO::sdkVersion() const
-{
-	const uint32_t cmd_count = ((macho_header*)fMachOData)->ncmds;
-	const struct load_command* const cmds = (struct load_command*)&fMachOData[sizeof(macho_header)];
-	const struct load_command* cmd = cmds;
-	const struct version_min_command* versCmd;
-	for (uint32_t i = 0; i < cmd_count; ++i) {
-		switch ( cmd->cmd ) {
-			case LC_VERSION_MIN_MACOSX:
-			case LC_VERSION_MIN_IPHONEOS:
-				versCmd = (version_min_command*)cmd;
-				return versCmd->sdk;
-		}
-		cmd = (const struct load_command*)(((char*)cmd)+cmd->cmdsize);
-	}
-	return 0;
-}
-
-void* ImageLoaderMachO::getThreadPC() const
-{
-	const uint32_t cmd_count = ((macho_header*)fMachOData)->ncmds;
-	const struct load_command* const cmds = (struct load_command*)&fMachOData[sizeof(macho_header)];
-	const struct load_command* cmd = cmds;
-	for (uint32_t i = 0; i < cmd_count; ++i) {
-		if ( cmd->cmd == LC_MAIN ) {
-			entry_point_command* mainCmd = (entry_point_command*)cmd;
-			void* entry = (void*)(mainCmd->entryoff + (char*)fMachOData);
-			// <rdar://problem/8543820&9228031> verify entry point is in image
-			if ( this->containsAddress(entry) )
-				return entry;
-			else
-				throw "LC_MAIN entryoff is out of range";
-		}
-		cmd = (const struct load_command*)(((char*)cmd)+cmd->cmdsize);
-	}
-	return NULL;
-}
 
 
 void* ImageLoaderMachO::getMain() const
@@ -903,28 +683,30 @@
 		switch (cmd->cmd) {
 			case LC_UNIXTHREAD:
 			{
-			#if __i386__
+			#if __ppc__
+				const ppc_thread_state_t* registers = (ppc_thread_state_t*)(((char*)cmd) + 16);
+				return (void*)(registers->srr0 + fSlide);
+			#elif __ppc64__
+				const ppc_thread_state64_t* registers = (ppc_thread_state64_t*)(((char*)cmd) + 16);
+				return (void*)(registers->srr0 + fSlide);
+			#elif __i386__
 				const i386_thread_state_t* registers = (i386_thread_state_t*)(((char*)cmd) + 16);
-				void* entry = (void*)(registers->eip + fSlide);
+				return (void*)(registers->eip + fSlide);
 			#elif __x86_64__
 				const x86_thread_state64_t* registers = (x86_thread_state64_t*)(((char*)cmd) + 16);
-				void* entry = (void*)(registers->rip + fSlide);
+				return (void*)(registers->rip + fSlide);
 			#elif __arm__
 				const arm_thread_state_t* registers = (arm_thread_state_t*)(((char*)cmd) + 16);
-				void* entry = (void*)(registers->__pc + fSlide);
+				return (void*)(registers->__pc + fSlide);
 			#else
 				#warning need processor specific code
 			#endif
-				// <rdar://problem/8543820&9228031> verify entry point is in image
-				if ( this->containsAddress(entry) ) {
-					return entry;
-				}
 			}
 			break;
 		}
 		cmd = (const struct load_command*)(((char*)cmd)+cmd->cmdsize);
 	}
-	throw "no valid entry point";
+	return NULL;
 }
 
 bool ImageLoaderMachO::needsAddedLibSystemDepency(unsigned int libCount, const macho_header* mh)
@@ -946,7 +728,6 @@
 			case LC_LOAD_DYLIB:
 			case LC_LOAD_WEAK_DYLIB:
 			case LC_REEXPORT_DYLIB:
-			case LC_LOAD_UPWARD_DYLIB:
 				return false;
 			case LC_ID_DYLIB:
 				{
@@ -975,7 +756,6 @@
 		lib->info.maxVersion = 0;
 		lib->required = false;
 		lib->reExported = false;
-		lib->upward = false;
 	}
 	else {
 		uint32_t index = 0;
@@ -987,7 +767,6 @@
 				case LC_LOAD_DYLIB:
 				case LC_LOAD_WEAK_DYLIB:
 				case LC_REEXPORT_DYLIB:
-				case LC_LOAD_UPWARD_DYLIB:
 				{
 					const struct dylib_command* dylib = (struct dylib_command*)cmd;
 					DependentLibraryInfo* lib = &libs[index++];
@@ -998,7 +777,6 @@
 					lib->info.maxVersion = dylib->dylib.current_version;
 					lib->required = (cmd->cmd != LC_LOAD_WEAK_DYLIB);
 					lib->reExported = (cmd->cmd == LC_REEXPORT_DYLIB);
-					lib->upward = (cmd->cmd == LC_LOAD_UPWARD_DYLIB);
 				}
 				break;
 			}
@@ -1032,7 +810,6 @@
 	for (uint32_t i = 0; i < cmd_count; ++i) {
 		switch (cmd->cmd) {
 			case LC_RPATH:
-				const char* pathToAdd = NULL;
 				const char* path = (char*)cmd + ((struct rpath_command*)cmd)->path.offset;
 				if ( strncmp(path, "@loader_path/", 13) == 0 ) {
 					if ( context.processIsRestricted  && (context.mainExecutable == this) ) {
@@ -1048,7 +825,7 @@
 							strcpy(&addPoint[1], &path[13]);
 						else
 							strcpy(newRealPath, &path[13]);
-						pathToAdd = strdup(newRealPath);
+						path = strdup(newRealPath);
 					}
 				}
 				else if ( strncmp(path, "@executable_path/", 17) == 0 ) {
@@ -1065,7 +842,7 @@
 							strcpy(&addPoint[1], &path[17]);
 						else
 							strcpy(newRealPath, &path[17]);
-						pathToAdd = strdup(newRealPath);
+						path = strdup(newRealPath);
 					}
 				}
 				else if ( (path[0] != '/') && context.processIsRestricted ) {
@@ -1078,27 +855,26 @@
 					bool found = false;
 					for(const char** rp = context.rootPaths; *rp != NULL; ++rp) {
 						char newPath[PATH_MAX];
-						strlcpy(newPath, *rp, PATH_MAX);
-						strlcat(newPath, path, PATH_MAX);
+						strcpy(newPath, *rp);
+						strcat(newPath, path);
 						struct stat stat_buf;
 						if ( stat(newPath, &stat_buf) != -1 ) {
 							//dyld::log("combined DYLD_ROOT_PATH and LC_RPATH: %s\n", newPath);
-							pathToAdd = strdup(newPath);
+							path = strdup(newPath);
 							found = true;
 							break;
 						}
 					}
 					if ( ! found ) {
 						// make copy so that all elements of 'paths' can be freed
-						pathToAdd = strdup(path);
+						path = strdup(path);
 					}
 				}
 				else {
 					// make copy so that all elements of 'paths' can be freed
-					pathToAdd = strdup(path);
+					path = strdup(path);
 				}
-				if ( pathToAdd != NULL )
-					paths.push_back(pathToAdd);
+				paths.push_back(path);
 				break;
 		}
 		cmd = (const struct load_command*)(((char*)cmd)+cmd->cmdsize);
@@ -1196,11 +972,8 @@
 		segMakeWritable(textSegmentIndex, context);
 	}
 	else {
-	#if !__i386__ && !__x86_64__
-		// some processors require range to be invalidated before it is made executable
+		segProtect(textSegmentIndex, context);
 		sys_icache_invalidate((void*)segActualLoadAddress(textSegmentIndex), segSize(textSegmentIndex));
-	#endif
-		segProtect(textSegmentIndex, context);
 	}
 }
 #endif
@@ -1231,27 +1004,14 @@
 
 
 
-uintptr_t ImageLoaderMachO::getExportedSymbolAddress(const Symbol* sym, const LinkContext& context, 
-											const ImageLoader* requestor, bool runResolver) const
-{
-	return this->getSymbolAddress(sym, requestor, context, runResolver);
-}
-
-uintptr_t ImageLoaderMachO::getSymbolAddress(const Symbol* sym, const ImageLoader* requestor, 
-												const LinkContext& context, bool runResolver) const
-{
-	uintptr_t result = exportedSymbolAddress(context, sym, requestor, runResolver);
-	// check for interposing overrides
-	for (std::vector<InterposeTuple>::iterator it=fgInterposingTuples.begin(); it != fgInterposingTuples.end(); it++) {
-		// replace all references to 'replacee' with 'replacement'
-		if ( (result == it->replacee) && (requestor != it->replacementImage) ) {
-			if ( context.verboseInterposing ) {
-				dyld::log("dyld interposing: replace 0x%lX with 0x%lX in %s\n", 
-					it->replacee, it->replacement, this->getPath());
-			}
-			result = it->replacement;
-		}
-	}
+uintptr_t ImageLoaderMachO::getExportedSymbolAddress(const Symbol* sym, const LinkContext& context, const ImageLoader* requestor) const
+{
+	return this->getSymbolAddress(sym, requestor, context);
+}
+
+uintptr_t ImageLoaderMachO::getSymbolAddress(const Symbol* sym, const ImageLoader* requestor, const LinkContext& context) const
+{
+	uintptr_t result = exportedSymbolAddress(sym);
 	return result;
 }
 
@@ -1389,11 +1149,8 @@
 }
 
 
-void __attribute__((noreturn)) ImageLoaderMachO::throwSymbolNotFound(const LinkContext& context, const char* symbol, 
-																	const char* referencedFrom, const char* expectedIn)
-{
-	// record values for possible use by CrashReporter or Finder
-	(*context.setErrorStrings)(dyld_error_kind_symbol_missing, referencedFrom, expectedIn, symbol);
+void __attribute__((noreturn)) ImageLoaderMachO::throwSymbolNotFound(const char* symbol, const char* referencedFrom, const char* expectedIn)
+{
 	dyld::throwf("Symbol not found: %s\n  Referenced from: %s\n  Expected in: %s\n", symbol, referencedFrom, expectedIn); 
 }
 
@@ -1439,9 +1196,6 @@
 						((targetImage != NULL) ? targetImage->getShortName() : "<weak>import-missing>"),
 						 symbolName, (uintptr_t)location, value);
 	}
-#if LOG_BINDINGS
-//	dyld::logBindings("%s: %s\n", targetImage->getShortName(), symbolName);
-#endif
 	
 	// do actual update
 	uintptr_t* locationToFix = (uintptr_t*)location;
@@ -1482,7 +1236,9 @@
 
 #if SUPPORT_OLD_CRT_INITIALIZATION
 // first 16 bytes of "start" in crt1.o
-#if __i386__
+#if __ppc__
+	static uint32_t sStandardEntryPointInstructions[4] = { 0x7c3a0b78, 0x3821fffc, 0x54210034, 0x38000000 };
+#elif __i386__
 	static uint8_t sStandardEntryPointInstructions[16] = { 0x6a, 0x00, 0x89, 0xe5, 0x83, 0xe4, 0xf0, 0x83, 0xec, 0x10, 0x8b, 0x5d, 0x04, 0x89, 0x5c, 0x24 };
 #endif
 #endif
@@ -1505,10 +1261,11 @@
 	const uint32_t cmd_count = mh->ncmds;
 	const struct load_command* const cmds = (struct load_command*)&fMachOData[sizeof(macho_header)];
 	const struct load_command* cmd;
-	// There used to be some optimizations to skip this section scan, but we need to handle the 
-	// __dyld section in libdyld.dylib, so everything needs to be scanned for now.
-	// <rdar://problem/10910062> CrashTracer: 1,295 crashes in bash at bash: getenv
-	if ( true ) {
+	// set up __dyld section
+	// optimizations:
+	//   1) do nothing if image is in dyld shared cache and dyld loaded at same address as when cache built
+	//	 2) first read __dyld value, if already correct don't write, this prevents dirtying a page
+	if ( !fInSharedCache || !context.dyldLoadedAtSameAddressNeededBySharedCache ) {
 		cmd = cmds;
 		for (uint32_t i = 0; i < cmd_count; ++i) {
 			if ( cmd->cmd == LC_SEGMENT_COMMAND ) {
@@ -1550,16 +1307,6 @@
 				#endif
 								}
 							}
-							else if ( mh->filetype == MH_DYLIB ) {
-								const char* installPath = this->getInstallPath();
-								if ( (installPath != NULL) && (strncmp(installPath, "/usr/lib/", 9) == 0) ) {
-									if ( sect->size > offsetof(DATAdyld, vars) ) {
-										// use ProgramVars from libdyld.dylib but tweak mh field to correct value
-										dd->vars.mh = context.mainExecutable->machHeader();
-										context.setNewProgramVars(dd->vars);
-									}
-								}
-							}
 						}
 						else if ( (strcmp(sect->sectname, "__program_vars" ) == 0) && (mh->filetype == MH_EXECUTE) ) {
 							// this is a Mac OS X 10.6 or later main executable 
@@ -1586,22 +1333,22 @@
 	// lookup _NXArgc
 	sym = this->findExportedSymbol("_NXArgc", false, NULL);
 	if ( sym != NULL )
-		vars.NXArgcPtr = (int*)this->getExportedSymbolAddress(sym, context, this, false);
+		vars.NXArgcPtr = (int*)this->getExportedSymbolAddress(sym, context, this);
 		
 	// lookup _NXArgv
 	sym = this->findExportedSymbol("_NXArgv", false, NULL);
 	if ( sym != NULL )
-		vars.NXArgvPtr = (const char***)this->getExportedSymbolAddress(sym, context, this, false);
+		vars.NXArgvPtr = (const char***)this->getExportedSymbolAddress(sym, context, this);
 		
 	// lookup _environ
 	sym = this->findExportedSymbol("_environ", false, NULL);
 	if ( sym != NULL )
-		vars.environPtr = (const char***)this->getExportedSymbolAddress(sym, context, this, false);
+		vars.environPtr = (const char***)this->getExportedSymbolAddress(sym, context, this);
 		
 	// lookup __progname
 	sym = this->findExportedSymbol("___progname", false, NULL);
 	if ( sym != NULL )
-		vars.__prognamePtr = (const char**)this->getExportedSymbolAddress(sym, context, this, false);
+		vars.__prognamePtr = (const char**)this->getExportedSymbolAddress(sym, context, this);
 		
 	context.setNewProgramVars(vars);
 }
@@ -1610,7 +1357,8 @@
 bool ImageLoaderMachO::usablePrebinding(const LinkContext& context) const
 {
 	// if prebound and loaded at prebound address, and all libraries are same as when this was prebound, then no need to bind
-	if ( ((this->isPrebindable() && (this->getSlide() == 0)) || fInSharedCache)
+	if ( (this->isPrebindable() || fInSharedCache)
+		&& (this->getSlide() == 0) 
 		&& this->usesTwoLevelNameSpace()
 		&& this->allDependentLibrariesAsWhenPreBound() ) {
 		// allow environment variables to disable prebinding
@@ -1641,12 +1389,8 @@
 			switch (cmd->cmd) {
 				case LC_ROUTINES_COMMAND:
 					Initializer func = (Initializer)(((struct macho_routines_command*)cmd)->init_address + fSlide);
-					// <rdar://problem/8543820&9228031> verify initializers are in image
-					if ( ! this->containsAddress((void*)func) ) {
-						dyld::throwf("initializer function %p not in mapped image for %s\n", func, this->getPath());
-					}
 					if ( context.verboseInit )
-						dyld::log("dyld: calling -init function %p in %s\n", func, this->getPath());
+						dyld::log("dyld: calling -init function 0x%p in %s\n", func, this->getPath());
 					func(context.argc, context.argv, context.envp, context.apple, &context.programVars);
 					break;
 			}
@@ -1673,18 +1417,14 @@
 						const uint32_t count = sect->size / sizeof(uintptr_t);
 						for (uint32_t i=0; i < count; ++i) {
 							Initializer func = inits[i];
-							// <rdar://problem/8543820&9228031> verify initializers are in image
-							if ( ! this->containsAddress((void*)func) ) {
-								dyld::throwf("initializer function %p not in mapped image for %s\n", func, this->getPath());
-							}
 							if ( context.verboseInit )
 								dyld::log("dyld: calling initializer function %p in %s\n", func, this->getPath());
 							func(context.argc, context.argv, context.envp, context.apple, &context.programVars);
 						}
 					}
 				}
+				cmd = (const struct load_command*)(((char*)cmd)+cmd->cmdsize);
 			}
-			cmd = (const struct load_command*)(((char*)cmd)+cmd->cmdsize);
 		}
 	}
 }
@@ -1726,17 +1466,11 @@
 }	
 
 
-bool ImageLoaderMachO::doInitialization(const LinkContext& context)
-{
-	CRSetCrashLogMessage2(this->getPath());
-
+void ImageLoaderMachO::doInitialization(const LinkContext& context)
+{
 	// mach-o has -init and static initializers
 	doImageInit(context);
 	doModInitFunctions(context);
-	
-	CRSetCrashLogMessage2(NULL);
-	
-	return (fHasDashInit || fHasInitializers);
 }
 
 bool ImageLoaderMachO::needsInitialization()
@@ -1769,10 +1503,6 @@
 						const uint32_t count = sect->size / sizeof(uintptr_t);
 						for (uint32_t i=count; i > 0; --i) {
 							Terminator func = terms[i-1];
-							// <rdar://problem/8543820&9228031> verify terminators are in image
-							if ( ! this->containsAddress((void*)func) ) {
-								dyld::throwf("termination function %p not in mapped image for %s\n", func, this->getPath());
-							}
 							if ( context.verboseInit )
 								dyld::log("dyld: calling termination function %p in %s\n", func, this->getPath());
 							func();
@@ -1786,13 +1516,12 @@
 }
 
 
-void ImageLoaderMachO::printStatistics(unsigned int imageCount, const InitializerTimingList& timingInfo)
-{
-	ImageLoader::printStatistics(imageCount, timingInfo);
+void ImageLoaderMachO::printStatistics(unsigned int imageCount)
+{
+	ImageLoader::printStatistics(imageCount);
 	dyld::log("total symbol trie searches:    %d\n", fgSymbolTrieSearchs);
 	dyld::log("total symbol table binary searches:    %d\n", fgSymbolTableBinarySearchs);
-	dyld::log("total images defining weak symbols:  %u\n", fgImagesHasWeakDefinitions);
-	dyld::log("total images using weak symbols:  %u\n", fgImagesRequiringCoalescing);
+	dyld::log("total images defining/using weak symbols:  %u/%u\n", fgImagesHasWeakDefinitions, fgImagesRequiringCoalescing);
 }
 
 
@@ -1828,7 +1557,7 @@
 			if ( strcmp(segName(i), "__PAGEZERO") == 0 )
 				continue;
 			if ( !reserveAddressRange(segPreferredLoadAddress(i), segSize(i)) )
-				dyld::throwf("can't map unslidable segment %s to 0x%lX with size 0x%lX", segName(i), segPreferredLoadAddress(i), segSize(i));
+				throw "can't map";
 		}
 	}
 	else {
@@ -1844,17 +1573,15 @@
 	vm_size_t size = length;
 	// in PIE programs, load initial dylibs after main executable so they don't have fixed addresses either
 	if ( fgNextPIEDylibAddress != 0 ) {
-		 // add small (0-3 pages) random padding between dylibs
-		addr = fgNextPIEDylibAddress + (__stack_chk_guard/fgNextPIEDylibAddress & (sizeof(long)-1))*4096;
-		//dyld::log("padding 0x%08llX, guard=0x%08llX\n", (long long)(addr - fgNextPIEDylibAddress), (long long)(__stack_chk_guard));
-		kern_return_t r = vm_alloc(&addr, size, VM_FLAGS_FIXED | VM_MAKE_TAG(VM_MEMORY_DYLIB));
+		addr = fgNextPIEDylibAddress + (arc4random() & 0x3) * 4096; // add small random padding between dylibs
+		kern_return_t r = vm_allocate(mach_task_self(), &addr, size, VM_FLAGS_FIXED);
 		if ( r == KERN_SUCCESS ) {
 			fgNextPIEDylibAddress = addr + size;
 			return addr;
 		}
 		fgNextPIEDylibAddress = 0;
 	}
-	kern_return_t r = vm_alloc(&addr, size, VM_FLAGS_ANYWHERE | VM_MAKE_TAG(VM_MEMORY_DYLIB));
+	kern_return_t r = vm_allocate(mach_task_self(), &addr, size, VM_FLAGS_ANYWHERE);
 	if ( r != KERN_SUCCESS ) 
 		throw "out of address space";
 	
@@ -1865,7 +1592,7 @@
 {
 	vm_address_t addr = start;
 	vm_size_t size = length;
-	kern_return_t r = vm_alloc(&addr, size, VM_FLAGS_FIXED | VM_MAKE_TAG(VM_MEMORY_DYLIB));
+	kern_return_t r = vm_allocate(mach_task_self(), &addr, size, false /*only this range*/);
 	if ( r != KERN_SUCCESS ) 
 		return false;
 	return true;
@@ -1883,13 +1610,10 @@
 	for(unsigned int i=0, e=segmentCount(); i < e; ++i) {
 		vm_offset_t fileOffset = segFileOffset(i) + offsetInFat;
 		vm_size_t size = segFileSize(i);
-		uintptr_t requestedLoadAddress = segPreferredLoadAddress(i) + slide;
+		void* requestedLoadAddress = (void*)(segPreferredLoadAddress(i) + slide);
 		int protection = 0;
 		if ( !segUnaccessible(i) ) {
-			// If has text-relocs, don't set x-bit initially.
-			// Instead set it later after text-relocs have been done.
-			// The iPhone OS does not like it when you make executable code writable.
-			if ( segExecutable(i) && !(segHasRebaseFixUps(i) && (slide != 0)) )
+			if ( segExecutable(i) )
 				protection   |= PROT_EXEC;
 			if ( segReadable(i) )
 				protection   |= PROT_READ;
@@ -1907,20 +1631,19 @@
 				dyld::throwf("truncated mach-o error: segment %s extends to %llu which is past end of file %llu", 
 								segName(i), (uint64_t)(fileOffset+size), fileLen);
 			}
-			void* loadAddress = xmmap((void*)requestedLoadAddress, size, protection, MAP_FIXED | MAP_PRIVATE, fd, fileOffset);
+			void* loadAddress = mmap(requestedLoadAddress, size, protection, MAP_FIXED | MAP_PRIVATE, fd, fileOffset);
 			if ( loadAddress == ((void*)(-1)) ) {
 				dyld::throwf("mmap() error %d at address=0x%08lX, size=0x%08lX segment=%s in Segment::map() mapping %s", 
-					errno, requestedLoadAddress, (uintptr_t)size, segName(i), getPath());
+					errno, (uintptr_t)requestedLoadAddress, (uintptr_t)size, segName(i), getPath());
 			}
 		}
 		// update stats
 		++ImageLoader::fgTotalSegmentsMapped;
 		ImageLoader::fgTotalBytesMapped += size;
 		if ( context.verboseMapping )
-			dyld::log("%18s at 0x%08lX->0x%08lX with permissions %c%c%c\n", segName(i), requestedLoadAddress, requestedLoadAddress+size-1,
+			dyld::log("%18s at 0x%08lX->0x%08lX with permissions %c%c%c\n", segName(i), (uintptr_t)requestedLoadAddress, (uintptr_t)((char*)requestedLoadAddress+size-1),
 				(protection & PROT_READ) ? 'r' : '.',  (protection & PROT_WRITE) ? 'w' : '.',  (protection & PROT_EXEC) ? 'x' : '.' );
 	}
-
 	// update slide to reflect load location			
 	this->setSlide(slide);
 }
@@ -1966,10 +1689,8 @@
 	vm_size_t size = segSize(segIndex);
 	const bool setCurrentPermissions = false;
 	kern_return_t r = vm_protect(mach_task_self(), addr, size, setCurrentPermissions, protection);
-	if ( r != KERN_SUCCESS ) {
-        dyld::throwf("vm_protect(0x%08llX, 0x%08llX, false, 0x%02X) failed, result=%d for segment %s in %s",
-            (long long)addr, (long long)size, protection, r, segName(segIndex), this->getPath());
-    }
+	if ( r != KERN_SUCCESS ) 
+		throw "can't set vm permissions for mapped segment";
 	if ( context.verboseMapping ) {
 		dyld::log("%18s at 0x%08lX->0x%08lX altered permissions to %c%c%c\n", segName(segIndex), (uintptr_t)addr, (uintptr_t)addr+size-1,
 			(protection & PROT_READ) ? 'r' : '.',  (protection & PROT_WRITE) ? 'w' : '.',  (protection & PROT_EXEC) ? 'x' : '.' );
@@ -1982,13 +1703,11 @@
 	vm_size_t size = segSize(segIndex);
 	const bool setCurrentPermissions = false;
 	vm_prot_t protection = VM_PROT_WRITE | VM_PROT_READ;
-	if ( segExecutable(segIndex) && !segHasRebaseFixUps(segIndex) )
+	if ( segExecutable(segIndex) )
 		protection |= VM_PROT_EXECUTE;
 	kern_return_t r = vm_protect(mach_task_self(), addr, size, setCurrentPermissions, protection);
-	if ( r != KERN_SUCCESS ) {
-        dyld::throwf("vm_protect(0x%08llX, 0x%08llX, false, 0x%02X) failed, result=%d for segment %s in %s",
-            (long long)addr, (long long)size, protection, r, segName(segIndex), this->getPath());
-    }
+	if ( r != KERN_SUCCESS ) 
+		throw "can't set vm permissions for mapped segment";
 	if ( context.verboseMapping ) {
 		dyld::log("%18s at 0x%08lX->0x%08lX altered permissions to %c%c%c\n", segName(segIndex), (uintptr_t)addr, (uintptr_t)addr+size-1,
 			(protection & PROT_READ) ? 'r' : '.',  (protection & PROT_WRITE) ? 'w' : '.',  (protection & PROT_EXEC) ? 'x' : '.' );