Re: [OE-core] [PATCH] rust-cross-canadian: Fix for the linker issues caused by using the shell

Richard Purdie
2022-09-04T21:35:08Z

On Sun, 2022-09-04 at 23:39 +0530, Sundeep KOKKONDA wrote:
> [Yocto #14892]
> This is a fix for YOCTO #14878 patch. When sheband is more than 128 characters the default shell /bin/sh is used to execute the linker instead of SDK shell, which causes problems with LD_LIBRARY_PATH.
> With this patch shell usage is avoided.
>
> Signed-off-by: Sundeep KOKKONDA <sundeep.kokkonda@gmail.com>
> ---
> .../rust/files/target-rust-ccld.c | 39 +++++++++++++++++++
> .../rust/rust-cross-canadian.inc | 11 +++---
> 2 files changed, 44 insertions(+), 6 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..13f06b38f8
> --- /dev/null
> +++ b/meta/recipes-devtools/rust/files/target-rust-ccld.c
> @@ -0,0 +1,39 @@
> +/*
> +*
> +* Copyright (C) 2022 Wind River Systems
> +*
> +* SPDX-License-Identifier: GPL-2.0-only
> +*
> +*/
> +
> +#include <string.h>
> +#include <stdlib.h>
> +#include <unistd.h>
> +
> +int main (int argc, char *argv[])
> +{
> + int i=0;
> + char cc[1024];
> + char *cmd[1024];
> + char *ccargs[2][1024];

I'm a bit concerned about the fixed lengths coded here. What if there
are more than 2 arguments in CC/LD? What if one of the arguments (or
the variable) is longer than 1024?

> +
> + strcpy(cc,getenv("LD"));

The original code this replaces uses CC?

> + char * pch;
> + pch = strtok (cc," ");
> + while (pch != NULL)
> + {
> + strcpy(ccargs+i,pch);
> + printf ("%s\n",ccargs+i);
> + pch = strtok (NULL, " ");
> + i++;
> + }
> +
> + strcpy(cmd,ccargs+0);
> +
> + unsetenv("LD_LIBRARY_PATH");
> + execv(cmd,argv);
> +

Where is ccargs used here (other than the first entry)?

Cheers,

Richard