diff mbox series

[V2] rust-cross-canadian: Fix for the issue caused by using sdk shell

Message ID 20220907021817.3309235-1-sundeep.kokkonda@gmail.com
State Accepted, archived
Commit 7cd6faf4e0147eef557f83fb266a25935e26efff
Headers show
Series [V2] rust-cross-canadian: Fix for the issue caused by using sdk shell | expand

Commit Message

Sundeep KOKKONDA Sept. 7, 2022, 2:18 a.m. UTC
[YOCTO #14892]
This is a fix for the fix in YOCTO #14878. When the shebang is more than
128 characters the default shell /bin/sh is used instead of SDK shell as
a fallback, which causes problems with LD_LIBRARY_PATH. With this patch
shell usage is avoided as we use a C wrapper and unset LD_LIBRARY_PATH
that way.

Signed-off-by: Sundeep KOKKONDA <sundeep.kokkonda@gmail.com>
---
 .../rust/files/target-rust-ccld.c             | 21 +++++++++++++++++++
 .../rust/rust-cross-canadian.inc              | 20 +++++++++++++++---
 2 files changed, 38 insertions(+), 3 deletions(-)
 create mode 100644 meta/recipes-devtools/rust/files/target-rust-ccld.c

Comments

Richard Purdie Sept. 7, 2022, 7:55 a.m. UTC | #1
On Wed, 2022-09-07 at 07:48 +0530, Sundeep KOKKONDA wrote:
> [YOCTO #14892]
> This is a fix for the fix in YOCTO #14878. When the shebang is more than
> 128 characters the default shell /bin/sh is used instead of SDK shell as
> a fallback, which causes problems with LD_LIBRARY_PATH. With this patch
> shell usage is avoided as we use a C wrapper and unset LD_LIBRARY_PATH
> that way.
> 
> Signed-off-by: Sundeep KOKKONDA <sundeep.kokkonda@gmail.com>
> ---
>  .../rust/files/target-rust-ccld.c             | 21 +++++++++++++++++++
>  .../rust/rust-cross-canadian.inc              | 20 +++++++++++++++---
>  2 files changed, 38 insertions(+), 3 deletions(-)
>  create mode 100644 meta/recipes-devtools/rust/files/target-rust-ccld.c
> 
> diff --git a/meta/recipes-devtools/rust/files/target-rust-ccld.c b/meta/recipes-devtools/rust/files/target-rust-ccld.c
> new file mode 100644
> index 0000000000..fa98c1dbd7
> --- /dev/null
> +++ b/meta/recipes-devtools/rust/files/target-rust-ccld.c
> @@ -0,0 +1,21 @@
> +/*
> +*
> +* Copyright (C) 2022      Wind River Systems
> +*
> +* SPDX-License-Identifier: MIT
> +*
> +*/
> +
> +#include <string.h>
> +#include <stdlib.h>
> +#include <unistd.h>
> +
> +int main (int argc, char *argv[])
> +{
> +    unsetenv("LD_LIBRARY_PATH");
> +    execvp("target-rust-ccld-wrapper", argv);
> +
> +    return 0;
> +}
> +
> +
> diff --git a/meta/recipes-devtools/rust/rust-cross-canadian.inc b/meta/recipes-devtools/rust/rust-cross-canadian.inc
> index 7bf75a4712..7536579313 100644
> --- a/meta/recipes-devtools/rust/rust-cross-canadian.inc
> +++ b/meta/recipes-devtools/rust/rust-cross-canadian.inc
> @@ -7,13 +7,18 @@ LICENSE = "MIT"
>  
>  MODIFYTOS = "0"
>  
> +DEPENDS += "virtual/${SDK_PREFIX}gcc-crosssdk virtual/nativesdk-libc virtual/nativesdk-${SDK_PREFIX}compilerlibs"
> +
> +SRC_URI += "file://target-rust-ccld.c"
> +LIC_FILES_CHKSUM = "file://target-rust-ccld.c;md5=b6bc5662440675fd7d64688087a2f679;endline=7"
> +S = "${WORKDIR}"

Thanks. This patch changes the license which is good but it doesn't
update the LIC_FILES_CHKSUM. Since this is blocking the release build,
I've fixed that. Please work out why that didn't show up in your local
testing though!

Cheers,

Richard
diff mbox series

Patch

diff --git a/meta/recipes-devtools/rust/files/target-rust-ccld.c b/meta/recipes-devtools/rust/files/target-rust-ccld.c
new file mode 100644
index 0000000000..fa98c1dbd7
--- /dev/null
+++ b/meta/recipes-devtools/rust/files/target-rust-ccld.c
@@ -0,0 +1,21 @@ 
+/*
+*
+* Copyright (C) 2022      Wind River Systems
+*
+* SPDX-License-Identifier: MIT
+*
+*/
+
+#include <string.h>
+#include <stdlib.h>
+#include <unistd.h>
+
+int main (int argc, char *argv[])
+{
+    unsetenv("LD_LIBRARY_PATH");
+    execvp("target-rust-ccld-wrapper", argv);
+
+    return 0;
+}
+
+
diff --git a/meta/recipes-devtools/rust/rust-cross-canadian.inc b/meta/recipes-devtools/rust/rust-cross-canadian.inc
index 7bf75a4712..7536579313 100644
--- a/meta/recipes-devtools/rust/rust-cross-canadian.inc
+++ b/meta/recipes-devtools/rust/rust-cross-canadian.inc
@@ -7,13 +7,18 @@  LICENSE = "MIT"
 
 MODIFYTOS = "0"
 
+DEPENDS += "virtual/${SDK_PREFIX}gcc-crosssdk virtual/nativesdk-libc virtual/nativesdk-${SDK_PREFIX}compilerlibs"
+
+SRC_URI += "file://target-rust-ccld.c"
+LIC_FILES_CHKSUM = "file://target-rust-ccld.c;md5=b6bc5662440675fd7d64688087a2f679;endline=7"
+S = "${WORKDIR}"
+
 # Need to use our SDK's sh here, see #14878
 create_sdk_wrapper () {
         file="$1"
         shift
-
         cat <<- EOF > "${file}"
-		#!${base_prefix}/bin/sh
+		#!/bin/sh
 		\$$1 \$@
 		EOF
 
@@ -32,8 +37,17 @@  do_install () {
     install -m 0644 "${RUST_TARGETS_DIR}/${RUST_TARGET_SYS}.json" "${RUSTLIB_DIR}"
 
     # Uses SDK's CC as linker so linked binaries works out of box.
+    # We have a problem as rust sets LD_LIBRARY_PATH and this will break running host
+    # binaries (even /bin/sh) in the SDK as they detect a newer glibc from the SDK
+    # in those paths and we hit symbol errors. We saw particular problems with symbol
+    # mismatch on ubuntu1804 during development. To avoid this we have an SDK built
+    # binary which unsets LD_LIBRARY_PATH, which can then call the wrapper script
+    # where the context is easier to do the env maniupations needed
     install -d ${SYS_BINDIR}
-    create_sdk_wrapper "${SYS_BINDIR}/target-rust-ccld" "CC"
+    outfile="${SYS_BINDIR}/target-rust-ccld"
+    ${CC} ${WORKDIR}/target-rust-ccld.c -o $outfile
+    chmod +x "$outfile"
+    create_sdk_wrapper "${SYS_BINDIR}/target-rust-ccld-wrapper" "CC"
 
     ENV_SETUP_DIR=${D}${base_prefix}/environment-setup.d
     mkdir "${ENV_SETUP_DIR}"