From 60ce07c1e7dbeedd94a57ba21c14ff07c4ada4db Mon Sep 17 00:00:00 2001
From: Apple <opensource@apple.com>
Date: Thu, 14 Jul 2011 22:38:47 +0000
Subject: [PATCH] ld64-123.2.1.tar.gz

---
 ChangeLog             | 12 ++++++++++--
 doc/man/man1/ld.1     |  8 ++++----
 src/ld/Options.cpp    |  6 ++++--
 src/ld/OutputFile.cpp |  2 +-
 4 files changed, 19 insertions(+), 9 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index bc918bb..e2d1d2c 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,4 +1,12 @@
 
+-------- tagged ld64-123.2.1
+
+2010-03-07    Nick Kledzik    <kledzik@apple.com>
+
+    <rdar://problem/8955206> enable i386 ASLR
+
+-------- tagged ld64-123.2
+
 2010-12-10    Nick Kledzik    <kledzik@apple.com>
 
 	<rdar://problem/8746980> Man page typo: "dysmutil" under object_path_lto
@@ -71,7 +79,7 @@
 
 2010-11-01    Nick Kledzik    <kledzik@apple.com>
 
-	<rdar://problem/8612861> Durango is missing dof sections for armv7 slice
+	<rdar://problem/8612861>
 
 -------- tagged ld64-120.3
 
@@ -544,7 +552,7 @@
 
 2010-06-09    Nick Kledzik    <kledzik@apple.com>
 
-	<rdar://problem/8076986> Barolo: 'rebase' makes timestamps invalid/unreadable for GDB
+	<rdar://problem/8076986>
 
 2010-06-09    Nick Kledzik    <kledzik@apple.com>
 
diff --git a/doc/man/man1/ld.1 b/doc/man/man1/ld.1
index d4d1329..c1aa2bc 100644
--- a/doc/man/man1/ld.1
+++ b/doc/man/man1/ld.1
@@ -1,4 +1,4 @@
-.Dd Sept 2, 2010
+.Dd March 7, 2011
 .Dt ld 1
 .Os Darwin
 .Sh NAME
@@ -331,9 +331,9 @@ This option is also called -dylib_current_version for compatibility.
 This makes a special kind of main executable that is position independent (PIE).  On Mac OS X 10.5 and later, the OS
 the OS will load a PIE at a random address each time it is executed.  You cannot create a PIE from .o files compiled 
 with -mdynamic-no-pic.  That means the codegen is less optimal, but the address randomization adds some 
-security. When targeting Mac OS X 10.7 or later PIE is the default for x86_64 main executables.
+security. When targeting Mac OS X 10.7 or later PIE is the default for main executables.
 .It Fl no_pie
-Do not make a position independent executable (PIE).  This is the default, except for x86_64 for 10.7 or later.
+Do not make a position independent executable (PIE).  This is the default, when targeting 10.6 and earlier.
 .It Fl pagezero_size Ar size
 By default the linker creates an unreadable segment starting at address zero named __PAGEZERO.  Its existence
 will cause a bus error if a NULL pointer is dereferenced.  The argument
@@ -516,7 +516,7 @@ This option causes the linker to instead produce traditional relocation informat
 .It Fl allow_heap_execute
 Normally i386 main executables will be marked so that the Mac OS X 10.7 and later kernel 
 will only allow pages with the x-bit to execute instructions. This option overrides that
-behavior and allows instructions on any page to be run.
+behavior and allows instructions on any page to be executed.
 .It Fl no_eh_labels
 Normally in -r mode, the linker produces .eh labels on all FDEs in the __eh_frame section.
 This option suppresses those labels.  Those labels are not needed by the Mac OS X 10.6
diff --git a/src/ld/Options.cpp b/src/ld/Options.cpp
index 1de3379..c06e1f3 100644
--- a/src/ld/Options.cpp
+++ b/src/ld/Options.cpp
@@ -3454,8 +3454,10 @@ void Options::reconfigureDefaults()
 		fCanUseUpwardDylib = true;
 		
 	// x86_64 for MacOSX 10.7 defaults to PIE
-	if ( (fArchitecture == CPU_TYPE_X86_64) && (fOutputKind == kDynamicExecutable) && (fMacVersionMin >= ld::mac10_7) ) {
-		fPositionIndependentExecutable = true;
+	if ( ((fArchitecture == CPU_TYPE_X86_64) || (fArchitecture == CPU_TYPE_I386))
+		&& (fOutputKind == kDynamicExecutable)
+		&& (fMacVersionMin >= ld::mac10_7) ) {
+			fPositionIndependentExecutable = true;
 	}
 
 	// armv7 for iOS4.3 defaults to PIE
diff --git a/src/ld/OutputFile.cpp b/src/ld/OutputFile.cpp
index bb368c2..963e9e5 100644
--- a/src/ld/OutputFile.cpp
+++ b/src/ld/OutputFile.cpp
@@ -2583,7 +2583,7 @@ void OutputFile::noteTextReloc(const ld::Atom* atom, const ld::Atom* target)
 		if ( _options.warnAboutTextRelocs() )
 			warning("text reloc in %s to %s", atom->name(), target->name());
 	} 
-	else if ( _options.positionIndependentExecutable() && (_options.iphoneOSVersionMin() >= ld::iPhone4_3) ) {
+	else if ( _options.positionIndependentExecutable() && ((_options.iphoneOSVersionMin() >= ld::iPhone4_3) || (_options.macosxVersionMin() >= ld::mac10_7)) ) {
 		if ( ! this->pieDisabled ) {
 			warning("PIE disabled. Absolute addressing (perhaps -mdynamic-no-pic) not allowed in code signed PIE, "
 				"but used in %s from %s. " 
-- 
2.45.2