Skip to content

Commit

Permalink
unix: stop using pthread_yield()
Browse files Browse the repository at this point in the history
This symbol was removed from glibc 2.34. Its replacement (sched_yield())
appears to have been available forever. So we disable the usage of
pthread_yield(). We also add verification for ELF banned symbols.
  • Loading branch information
indygreg committed Oct 17, 2021
1 parent b3fc971 commit 3d6e597
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
11 changes: 9 additions & 2 deletions cpython-unix/build-bdb.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,19 @@ tar -xf db-${BDB_VERSION}.tar.gz

pushd db-${BDB_VERSION}/build_unix

CONFIGURE_FLAGS="--enable-dbm --disable-shared"

# configure looks for pthread_yield(), which was dropped from glibc 2.34.
# Its replacement is sched_yield(). Fortunately, bdb's source code will fall
# back to sched_yield() if pthread_yield() isn't available. So we just lie
# to configure and tell it pthread_yield() isn't available.
CONFIGURE_FLAGS="${CONFIGURE_FLAGS} ac_cv_func_pthread_yield=no"

CFLAGS="${EXTRA_TARGET_CFLAGS} -fPIC" CPPFLAGS="${EXTRA_TARGET_CFLAGS} -fPIC" ../dist/configure \
--build=${BUILD_TRIPLE} \
--host=${TARGET_TRIPLE} \
--prefix=/tools/deps \
--enable-dbm \
--disable-shared
${CONFIGURE_FLAGS}

make -j ${NUM_CPUS}
make -j ${NUM_CPUS} install DESTDIR=${ROOT}/out
13 changes: 13 additions & 0 deletions src/validation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,11 @@ static PLATFORM_TAG_BY_TRIPLE: Lazy<HashMap<&'static str, &'static str>> = Lazy:
.collect()
});

const ELF_BANNED_SYMBOLS: &[&str] = &[
// Deprecated as of glibc 2.34 in favor of sched_yield.
"pthread_yield",
];

/// Symbols that we don't want to appear in mach-o binaries.
const MACHO_BANNED_SYMBOLS_NON_AARCH64: &[&str] = &[
// _readv and _pwritev are introduced when building with the macOS 11 SDK.
Expand Down Expand Up @@ -524,6 +529,14 @@ fn validate_elf(
undefined_symbols.sort();

for symbol in undefined_symbols {
if ELF_BANNED_SYMBOLS.contains(&symbol.symbol.as_str()) {
errors.push(format!(
"{} defines banned ELF symbol {}",
path.display(),
symbol.symbol,
));
}

if let Some(version) = &symbol.version {
let parts: Vec<&str> = version.splitn(2, '_').collect();

Expand Down

0 comments on commit 3d6e597

Please sign in to comment.