Skip to content

Commit 2ab0f47

Browse files
committed
unix: disable preadv() and pwritev() on macOS
Compiling against the 11.0 SDK will introduce these symbols. Why, I'm not sure, as the CPython source code appears to put them behind a __builtin_available() check. There might be something wonky going on. Anyway, this symbol didn't exist until the 11.0 SDK. So it should be safe to disable it.
1 parent 4f69d43 commit 2ab0f47

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed

cpython-unix/build-cpython.sh

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -525,6 +525,20 @@ if [ "${PYBUILD_PLATFORM}" = "macos" ]; then
525525
# as Homebrew or MacPorts. So nerf the check to prevent this.
526526
CONFIGURE_FLAGS="${CONFIGURE_FLAGS} ac_cv_lib_intl_textdomain=no"
527527

528+
# When building against an 11.0+ SDK, preadv() and pwritev() are
529+
# detected and used, despite only being available in the 11.0+ SDK. This
530+
# prevents object files from re-linking when built with older SDKs.
531+
# So we disable them. But not in aarch64-apple-darwin, as that target
532+
# requires the 11.0 SDK.
533+
#
534+
# This solution is less than ideal. Modern versions of Python support
535+
# weak linking and it should be possible to coerce these functions into
536+
# being weakly linked.
537+
if [ "${TARGET_TRIPLE}" != "aarch64-apple-darwin" ]; then
538+
CONFIGURE_FLAGS="${CONFIGURE_FLAGS} ac_cv_func_preadv=no"
539+
CONFIGURE_FLAGS="${CONFIGURE_FLAGS} ac_cv_func_pwritev=no"
540+
fi
541+
528542
if [ "${BUILD_TRIPLE}" != "${TARGET_TRIPLE}" ]; then
529543
# Python's configure doesn't support cross-compiling on macOS. So we need
530544
# to explicitly set MACHDEP to avoid busted checks. The code for setting

src/main.rs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -351,6 +351,14 @@ static PLATFORM_TAG_BY_TRIPLE: Lazy<HashMap<&'static str, &'static str>> = Lazy:
351351
.collect()
352352
});
353353

354+
/// Symbols that we don't want to appear in mach-o binaries.
355+
const MACHO_BANNED_SYMBOLS_NON_AARCH64: &[&str] = &[
356+
// _readv and _pwritev are introduced when building with the macOS 11 SDK.
357+
// If present, they can cause errors re-linking object files. So we ban their
358+
// existence.
359+
"_preadv", "_pwritev",
360+
];
361+
354362
fn allowed_dylibs_for_triple(triple: &str) -> Vec<MachOAllowedDylib> {
355363
match triple {
356364
"aarch64-apple-darwin" => DARWIN_ALLOWED_DYLIBS.clone(),
@@ -496,6 +504,22 @@ fn validate_macho(
496504
}
497505
}
498506

507+
if let Some(symbols) = &macho.symbols {
508+
for symbol in symbols {
509+
let (name, _) = symbol?;
510+
511+
if target_triple != "aarch64-apple-darwin"
512+
&& MACHO_BANNED_SYMBOLS_NON_AARCH64.contains(&name)
513+
{
514+
errors.push(format!(
515+
"{} references unallowed symbol {}",
516+
path.display(),
517+
name
518+
));
519+
}
520+
}
521+
}
522+
499523
Ok((errors, seen_dylibs))
500524
}
501525

0 commit comments

Comments
 (0)