diff --git a/cctools/ld64/src/ld/Options.cpp b/cctools/ld64/src/ld/Options.cpp
index e4b37ec..5dd207c 100644
--- a/cctools/ld64/src/ld/Options.cpp
+++ b/cctools/ld64/src/ld/Options.cpp
@@ -4017,11 +4017,27 @@ bool Options::shouldUseBuildVersion(ld::Platform plat, uint32_t minOSvers) const
 
 void Options::buildSearchPaths(int argc, const char* argv[])
 {
-	bool addStandardLibraryDirectories = true;
+	int addStandardLibraryDirectories = 1;
 	std::vector<const char*> libraryPaths;
 	std::vector<const char*> frameworkPaths;
+	char rawPath[PATH_MAX];
+	char path[PATH_MAX];
 	libraryPaths.reserve(10);
 	frameworkPaths.reserve(10);
+
+	// Conda-specific modification:
+	// If CONDA_BUILD_SYSROOT is set then add that as fSDKPaths, in the same way and
+	// place that CROSS_SYSROOT is handled (though it is one or the other).
+	const char* condaBuildDisableLD64Hacks = getenv("CONDA_BUILD_DISABLE_LD64_HACKS");
+	const char* envCondaBuildSysroot = (condaBuildDisableLD64Hacks == NULL) ? getenv("CONDA_BUILD_SYSROOT") : NULL;
+	if (envCondaBuildSysroot != NULL) {
+		addStandardLibraryDirectories = 2;
+		realpath(envCondaBuildSysroot, path);
+		if (strlen(path)) {
+			envCondaBuildSysroot = strdup(path);
+		}
+	}
+
 	// scan through argv looking for -L, -F, -Z, and -syslibroot options
 	for(int i=0; i < argc; ++i) {
 		if ( (argv[i][0] == '-') && (argv[i][1] == 'L') ) {
@@ -4053,7 +4069,7 @@ void Options::buildSearchPaths(int argc, const char* argv[])
 			frameworkPaths.push_back(frameworkSearchDir);
 		}
 		else if ( strcmp(argv[i], "-Z") == 0 )
-			addStandardLibraryDirectories = false;
+			addStandardLibraryDirectories = 0;
 		else if ( strcmp(argv[i], "-v") == 0 ) {
 			fVerbose = true;
 			extern const char ldVersionString[];
@@ -4146,11 +4162,19 @@ void Options::buildSearchPaths(int argc, const char* argv[])
 			fBundleBitcode = true;
 		}
 	}
+
+	if((envCondaBuildSysroot != NULL) && (fSDKPaths.size() == 0))
+		fSDKPaths.push_back(envCondaBuildSysroot);
+
 	int standardLibraryPathsStartIndex = libraryPaths.size();
 	int standardFrameworkPathsStartIndex = frameworkPaths.size();
 	if ( addStandardLibraryDirectories ) {
+		// Not that conda will care, but fix:
+		// https://langui.sh/2015/07/24/osx-clang-include-lib-search-paths/
+		if ( addStandardLibraryDirectories == 1 ) {
+			libraryPaths.push_back("/usr/local/lib");
+		}
 		libraryPaths.push_back("/usr/lib");
-		libraryPaths.push_back("/usr/local/lib");
 
 		frameworkPaths.push_back("/Library/Frameworks/");
 		frameworkPaths.push_back("/System/Library/Frameworks/");
@@ -4166,7 +4190,8 @@ void Options::buildSearchPaths(int argc, const char* argv[])
 	}
 
 	// now merge sdk and library paths to make real search paths
-	fLibrarySearchPaths.reserve(libraryPaths.size()*(fSDKPaths.size()+1));
+	fLibrarySearchPaths.reserve(libraryPaths.size()*(fSDKPaths.size()+2));
+
 	int libIndex = 0;
 	for (std::vector<const char*>::iterator it = libraryPaths.begin(); it != libraryPaths.end(); ++it, ++libIndex) {
 		const char* libDir = *it;
@@ -4211,7 +4236,7 @@ void Options::buildSearchPaths(int argc, const char* argv[])
 					else
 						fLibrarySearchPaths.push_back(libDir);
 				}
-				else if ( !addStandardLibraryDirectories || (strcmp(libDir, "/usr/local/lib") != 0) ) {
+				else if ( (addStandardLibraryDirectories == 0) || (strcmp(libDir, "/usr/local/lib") != 0) ) {
 					warning("directory not found for option '-L%s'", libDir);
 				}
 			}
