]> code.ossystems Code Review - openembedded-core.git/commitdiff
rust-common: Hack around LD_LIBRARY_PATH issues on centos7
authorRichard Purdie <richard.purdie@linuxfoundation.org>
Wed, 1 Sep 2021 14:28:26 +0000 (15:28 +0100)
committerRichard Purdie <richard.purdie@linuxfoundation.org>
Thu, 2 Sep 2021 20:22:25 +0000 (21:22 +0100)
When building cargo-native on centos7 with buildtools tarball installed,
we see failures:

/bin/sh: /lib64/libc.so.6: version `GLIBC_2.33' not found (required by /home/pokybuild/yocto-worker/reproducible-centos/build/build-st/tmp/work/x86_64-linux/cargo-native/1.54.0-r0/recipe-sysroot-native/usr/lib/libtinfo.so.5)

We also see this for libstd-rs once cargo-native is fixed.

The reason for this is that the wrapper script
cargo-native/1.54.0-r0/wrapper/target-rust-ccld has /bin/sh as it's
interpreter and cargo calls this with LD_LIBRARY_PATH set to include the
recipe-sysroot-native. The host /bin/sh links to libtinfo from the host
but it finds the version in the sysroot which needs a newer libc. This
results in the above error since the loader is an older libc and the two
are incompatible.

Our ccld wrapper calls gcc/ld which don't need the LD_LIBRARY_PATH
variable set. We can't patch this out the source since we're using
a prebuilt binary to generate a new cargo binary so this is impossible
to bootstrap.

Instead, put a binary wrapper into place which removes LD_LIBRARY_PATH
from the environment before calling the original wrapper (left in shell
as it is simpler to maintain).

Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
meta/classes/rust-common.bbclass
meta/files/rust-ccld-wrapper.c [new file with mode: 0644]

index e1bc0193c3ebdbf3f39fe017fb593b573a231b0b..a8803d61b6ac631e309062785cef070aeeb41a43 100644 (file)
@@ -169,6 +169,11 @@ do_rust_create_wrappers () {
        # Yocto Target / Rust Target archiver
        create_wrapper "${RUST_TARGET_AR}" "${WRAPPER_TARGET_AR}"
 
+       # Need to filter out LD_LIBRARY_PATH from the linker without using shell
+       mv ${RUST_BUILD_CCLD} ${RUST_BUILD_CCLD}.real
+       ${BUILD_CC} ${COREBASE}/meta/files/rust-ccld-wrapper.c -o ${RUST_BUILD_CCLD}
+       mv ${RUST_TARGET_CCLD} ${RUST_TARGET_CCLD}.real
+       ${BUILD_CC} ${COREBASE}/meta/files/rust-ccld-wrapper.c -o ${RUST_TARGET_CCLD}
 }
 
 addtask rust_create_wrappers before do_configure after do_patch
diff --git a/meta/files/rust-ccld-wrapper.c b/meta/files/rust-ccld-wrapper.c
new file mode 100644 (file)
index 0000000..6bc9958
--- /dev/null
@@ -0,0 +1,29 @@
+/*
+ * Copyright 2021 Richard Purdie
+ *
+ * SPDX-License-Identifier: GPL-2.0-only
+ */
+
+#include <errno.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+
+/*
+ * Run the original script (argv[0] + ".real") with LD_LIBRARY_PATH unset
+ * This avoids issues where cargo is running a wrapper script using /bin/sh from the host
+ * which links to something which has an incompatible version in in recipe-sysroot-native
+ * such as libtinfo on centos 7.
+ */
+
+int main(int argc, char* argv[]) {
+    char *real = malloc(strlen(argv[0] + 5));
+    strcpy(real, argv[0]);
+    strcpy(real + strlen(argv[0]), ".real");
+    putenv("LD_LIBRARY_PATH=");
+    if(execv(real, argv) == -1) {
+        printf("Wrapper failed to execute, error: %s\n", strerror(errno));
+        return -1;
+    }
+}