diff mbox series

[v2,7/9] gcc-configure-common.inc: add multlib support for i686/i586/x86_64 nativesdk gcc

Message ID 20250123045339.2443875-1-hongxu.jia@windriver.com
State New
Headers show
Series None | expand

Commit Message

Hongxu Jia Jan. 23, 2025, 4:53 a.m. UTC
We have patch 0016-handle-sysroot-support-for-nativesdk-gcc.patch to handle
sysroot support for nativesdk-gcc, and add %r target_relocatable_prefix
into spec file for nativesdk-gcc relocation. It was used for injected
paths SYSTEMLIBS_DIR

Due to the supported SDKMACHINE includes:

  aarch64, i586, i686, loongarch64, ppc64, ppc64le, riscv64, x86_64

Only i586 and x86_64, i686 and x86_64 have multilib relationship,
for i586,i686 and x86_64, this commit:

- Tweak target_relocatable_prefix, set ${root_prefix} to it , and tweak
libdir32 based on ${root_prefix} prefix with "/lib" suffix

- For i686 and i586, hard code `lib' to 32bit osdirname, `lib64' to
libdir64 and 64bit osdirname, whether multlib or not

- For x86_64, use variable baselib to set libdir64 and 64bit osdirnames,
baselib is set to `lib64' for multilib, and `lib' for non multilib

Above setting also covers gcc-nativesdk without multilib

For other situation, the configuration is the same as usual

[ YOCTO #15722 ]

Signed-off-by: Hongxu Jia <hongxu.jia@windriver.com>
---
Changed in v2, 
Fix `cargo build' failded in SDK, the interpreter of dynamical loader
is not right

$ rustc build.rs
$ ./build
./build: cannot execute: required file not found
$ file build
build: ELF 64-bit LSB pie executable, x86-64, version 1 (SYSV), dynamically linked, interpreter sdk-path-to/sysroots/x86_64-pokysdk-linux/lib64/ld-linux-x86-64.so.2, for GNU/Linux 3.2.0, BuildID[sha1]=4e012c629e30ebc91c3252eb0fd40358cc5b2dfa, not stripped
$ ls sdk-path-to/sysroots/x86_64-pokysdk-linux/lib/ld-linux-x86-64.so.2
sdk-path-to/sysroots/x86_64-pokysdk-linux/lib/ld-linux-x86-64.so.2

For x86_64, use variable baselib to set libdir64 and 64bit osdirnames,
baselib is set to `lib64' for multilib, and `lib' for non multilib

 meta/recipes-devtools/gcc/gcc-configure-common.inc    |  9 +++++++++
 meta/recipes-devtools/gcc/gcc-multilib-config.inc     | 11 +++++++++++
 ...016-handle-sysroot-support-for-nativesdk-gcc.patch |  2 +-
 3 files changed, 21 insertions(+), 1 deletion(-)

Comments

Yoann Congal Jan. 23, 2025, 3:49 p.m. UTC | #1
Hello,

Le jeu. 23 janv. 2025 à 05:53, hongxu via lists.openembedded.org
<hongxu.jia=eng.windriver.com@lists.openembedded.org> a écrit :

> We have patch 0016-handle-sysroot-support-for-nativesdk-gcc.patch to handle
> sysroot support for nativesdk-gcc, and add %r target_relocatable_prefix
> into spec file for nativesdk-gcc relocation. It was used for injected
> paths SYSTEMLIBS_DIR
>
> Due to the supported SDKMACHINE includes:
>
>   aarch64, i586, i686, loongarch64, ppc64, ppc64le, riscv64, x86_64
>
> Only i586 and x86_64, i686 and x86_64 have multilib relationship,
> for i586,i686 and x86_64, this commit:
>
> - Tweak target_relocatable_prefix, set ${root_prefix} to it , and tweak
> libdir32 based on ${root_prefix} prefix with "/lib" suffix
>
> - For i686 and i586, hard code `lib' to 32bit osdirname, `lib64' to
> libdir64 and 64bit osdirname, whether multlib or not
>
> - For x86_64, use variable baselib to set libdir64 and 64bit osdirnames,
> baselib is set to `lib64' for multilib, and `lib' for non multilib
>
> Above setting also covers gcc-nativesdk without multilib
>
> For other situation, the configuration is the same as usual
>
> [ YOCTO #15722 ]
>
> Signed-off-by: Hongxu Jia <hongxu.jia@windriver.com>
> ---
> Changed in v2,
> Fix `cargo build' failded in SDK, the interpreter of dynamical loader
> is not right
>
> $ rustc build.rs
> $ ./build
> ./build: cannot execute: required file not found
> $ file build
> build: ELF 64-bit LSB pie executable, x86-64, version 1 (SYSV),
> dynamically linked, interpreter
> sdk-path-to/sysroots/x86_64-pokysdk-linux/lib64/ld-linux-x86-64.so.2, for
> GNU/Linux 3.2.0, BuildID[sha1]=4e012c629e30ebc91c3252eb0fd40358cc5b2dfa,
> not stripped
> $ ls sdk-path-to/sysroots/x86_64-pokysdk-linux/lib/ld-linux-x86-64.so.2
> sdk-path-to/sysroots/x86_64-pokysdk-linux/lib/ld-linux-x86-64.so.2
>
> For x86_64, use variable baselib to set libdir64 and 64bit osdirnames,
> baselib is set to `lib64' for multilib, and `lib' for non multilib
>

This is the v2 of single patch in the middle of a patch series. Can you send
version iteration of the full series?

Thanks!


>  meta/recipes-devtools/gcc/gcc-configure-common.inc    |  9 +++++++++
>  meta/recipes-devtools/gcc/gcc-multilib-config.inc     | 11 +++++++++++
>  ...016-handle-sysroot-support-for-nativesdk-gcc.patch |  2 +-
>  3 files changed, 21 insertions(+), 1 deletion(-)
>
> diff --git a/meta/recipes-devtools/gcc/gcc-configure-common.inc
> b/meta/recipes-devtools/gcc/gcc-configure-common.inc
> index 5c79936242..bd5c953334 100644
> --- a/meta/recipes-devtools/gcc/gcc-configure-common.inc
> +++ b/meta/recipes-devtools/gcc/gcc-configure-common.inc
> @@ -73,6 +73,14 @@ SYSTEMHEADERS = "${target_includedir}"
>  SYSTEMLIBS = "${target_base_libdir}/"
>  SYSTEMLIBS1 = "${target_libdir}/"
>
> +def tune_target_relocatable_prefix(d):
> +    if d.getVar("SDK_ARCH") in ["x86_64", "i686", "i586"]:
> +        return d.getVar("root_prefix")
> +    else:
> +        return d.getVar("SYSTEMLIBS")
> +TARGET_RELOCATE_PREFIX = "${SYSTEMLIBS}"
> +TARGET_RELOCATE_PREFIX:class-nativesdk =
> "${@tune_target_relocatable_prefix(d)}"
> +
>  do_configure:prepend () {
>         # teach gcc to find correct target includedir when checking libc
> ssp support
>         mkdir -p ${B}/gcc
> @@ -83,6 +91,7 @@ do_configure:prepend () {
>  #define STANDARD_STARTFILE_PREFIX_1 "${SYSTEMLIBS}"
>  #define STANDARD_STARTFILE_PREFIX_2 "${SYSTEMLIBS1}"
>  #define SYSTEMLIBS_DIR "${SYSTEMLIBS}"
> +#define TARGET_RELOCATE_PREFIX "${TARGET_RELOCATE_PREFIX}"
>  #endif /* ! GCC_DEFAULTS_H */
>  _EOF
>         mv ${B}/gcc/defaults.h.new ${B}/gcc/defaults.h
> diff --git a/meta/recipes-devtools/gcc/gcc-multilib-config.inc
> b/meta/recipes-devtools/gcc/gcc-multilib-config.inc
> index 2dbbc23c94..997bb6029b 100644
> --- a/meta/recipes-devtools/gcc/gcc-multilib-config.inc
> +++ b/meta/recipes-devtools/gcc/gcc-multilib-config.inc
> @@ -172,6 +172,17 @@ python gcc_multilib_setup() {
>      target_arch = (d.getVar('TARGET_ARCH_MULTILIB_ORIGINAL') if mlprefix
>                      else d.getVar('TARGET_ARCH'))
>      if pn == "nativesdk-gcc":
> +        sdk_arch = d.getVar('SDK_ARCH')
> +        if sdk_arch in ['x86_64', 'i686', 'i586']:
> +            libdir32 = '%r/lib'
> +            if sdk_arch == 'x86_64':
> +                libdir64 = '%r/' + d.getVar('baselib')
> +                osdirnames = ['../'+d.getVar('baselib') ,'../lib']
> +            else:
> +                libdir64 = '%r/lib64'
> +                osdirnames = ['../lib64', '../lib']
> +            target_config_files =
> gcc_target_config_files[d.getVar("SDK_ARCH")]
> +            write_config(builddir, target_config_files, ['m64', 'm32'],
> ['64', '32'], osdirnames)
>          header_config_files =
> gcc_header_config_files[d.getVar("SDK_ARCH")]
>          write_headers(builddir, header_config_files, libdir32, libdir64,
> libdirx32, libdirn32)
>          return
> diff --git
> a/meta/recipes-devtools/gcc/gcc/0016-handle-sysroot-support-for-nativesdk-gcc.patch
> b/meta/recipes-devtools/gcc/gcc/0016-handle-sysroot-support-for-nativesdk-gcc.patch
> index edd100ee46..7d96a42027 100644
> ---
> a/meta/recipes-devtools/gcc/gcc/0016-handle-sysroot-support-for-nativesdk-gcc.patch
> +++
> b/meta/recipes-devtools/gcc/gcc/0016-handle-sysroot-support-for-nativesdk-gcc.patch
> @@ -389,7 +389,7 @@ index e3e9374d1cc..b080609341b 100644
>   #endif
>   static const char *target_system_root = DEFAULT_TARGET_SYSTEM_ROOT;
>
> -+static char target_relocatable_prefix[4096] __attribute__ ((section
> (".gccrelocprefix"))) = SYSTEMLIBS_DIR;
> ++static char target_relocatable_prefix[4096] __attribute__ ((section
> (".gccrelocprefix"))) = TARGET_RELOCATE_PREFIX;
>  +
>   /* Nonzero means pass the updated target_system_root to the compiler.  */
>
> --
> 2.34.1
>
>
> -=-=-=-=-=-=-=-=-=-=-=-
> Links: You receive all messages sent to this group.
> View/Reply Online (#210174):
> https://lists.openembedded.org/g/openembedded-core/message/210174
> Mute This Topic: https://lists.openembedded.org/mt/110767332/4316185
> Group Owner: openembedded-core+owner@lists.openembedded.org
> Unsubscribe: https://lists.openembedded.org/g/openembedded-core/unsub [
> yoann.congal@smile.fr]
> -=-=-=-=-=-=-=-=-=-=-=-
>
>
hongxu Jan. 23, 2025, 5:17 p.m. UTC | #2
The series is available in https://git.openembedded.org/openembedded-core-contrib/log/?h=mathieu/master-next

selftest/multiconfig: test multiconfig multlib nativesdk gccmathieu/master-next    Hongxu Jia
nativesdk-multiconfig-multlib-toolchain-packager: add recipe    Hongxu Jia
gcc-configure-common.inc: add multlib support for i686/i586/x86_64 nativesdk gcc    Hongxu Jia
meta/conf/bitbake.conf: support multiarch for nativesdk    Hongxu Jia
libgcc-common: apply multilib symlinks for nativesdk libgcc    Hongxu Jia
script/relocate_sdk.py: check dynamic loader arch before relocating interpreter    Hongxu Jia
toolchain-shar-relocate.sh: support multiple dynamic loaders for multilib    Hongxu Jia
multilib_header.bbclass: need multilib headers for nativesdk builds    Hongxu Jia
perl: fix do_install failed for nativesdk-perl    Hongxu Jia

//Hongxu
diff mbox series

Patch

diff --git a/meta/recipes-devtools/gcc/gcc-configure-common.inc b/meta/recipes-devtools/gcc/gcc-configure-common.inc
index 5c79936242..bd5c953334 100644
--- a/meta/recipes-devtools/gcc/gcc-configure-common.inc
+++ b/meta/recipes-devtools/gcc/gcc-configure-common.inc
@@ -73,6 +73,14 @@  SYSTEMHEADERS = "${target_includedir}"
 SYSTEMLIBS = "${target_base_libdir}/"
 SYSTEMLIBS1 = "${target_libdir}/"
 
+def tune_target_relocatable_prefix(d):
+    if d.getVar("SDK_ARCH") in ["x86_64", "i686", "i586"]:
+        return d.getVar("root_prefix")
+    else:
+        return d.getVar("SYSTEMLIBS")
+TARGET_RELOCATE_PREFIX = "${SYSTEMLIBS}"
+TARGET_RELOCATE_PREFIX:class-nativesdk = "${@tune_target_relocatable_prefix(d)}"
+
 do_configure:prepend () {
 	# teach gcc to find correct target includedir when checking libc ssp support
 	mkdir -p ${B}/gcc
@@ -83,6 +91,7 @@  do_configure:prepend () {
 #define STANDARD_STARTFILE_PREFIX_1 "${SYSTEMLIBS}"
 #define STANDARD_STARTFILE_PREFIX_2 "${SYSTEMLIBS1}"
 #define SYSTEMLIBS_DIR "${SYSTEMLIBS}"
+#define TARGET_RELOCATE_PREFIX "${TARGET_RELOCATE_PREFIX}"
 #endif /* ! GCC_DEFAULTS_H */
 _EOF
 	mv ${B}/gcc/defaults.h.new ${B}/gcc/defaults.h
diff --git a/meta/recipes-devtools/gcc/gcc-multilib-config.inc b/meta/recipes-devtools/gcc/gcc-multilib-config.inc
index 2dbbc23c94..997bb6029b 100644
--- a/meta/recipes-devtools/gcc/gcc-multilib-config.inc
+++ b/meta/recipes-devtools/gcc/gcc-multilib-config.inc
@@ -172,6 +172,17 @@  python gcc_multilib_setup() {
     target_arch = (d.getVar('TARGET_ARCH_MULTILIB_ORIGINAL') if mlprefix
                     else d.getVar('TARGET_ARCH'))
     if pn == "nativesdk-gcc":
+        sdk_arch = d.getVar('SDK_ARCH')
+        if sdk_arch in ['x86_64', 'i686', 'i586']:
+            libdir32 = '%r/lib'
+            if sdk_arch == 'x86_64':
+                libdir64 = '%r/' + d.getVar('baselib')
+                osdirnames = ['../'+d.getVar('baselib') ,'../lib']
+            else:
+                libdir64 = '%r/lib64'
+                osdirnames = ['../lib64', '../lib']
+            target_config_files = gcc_target_config_files[d.getVar("SDK_ARCH")]
+            write_config(builddir, target_config_files, ['m64', 'm32'], ['64', '32'], osdirnames)
         header_config_files = gcc_header_config_files[d.getVar("SDK_ARCH")]
         write_headers(builddir, header_config_files, libdir32, libdir64, libdirx32, libdirn32)
         return
diff --git a/meta/recipes-devtools/gcc/gcc/0016-handle-sysroot-support-for-nativesdk-gcc.patch b/meta/recipes-devtools/gcc/gcc/0016-handle-sysroot-support-for-nativesdk-gcc.patch
index edd100ee46..7d96a42027 100644
--- a/meta/recipes-devtools/gcc/gcc/0016-handle-sysroot-support-for-nativesdk-gcc.patch
+++ b/meta/recipes-devtools/gcc/gcc/0016-handle-sysroot-support-for-nativesdk-gcc.patch
@@ -389,7 +389,7 @@  index e3e9374d1cc..b080609341b 100644
  #endif
  static const char *target_system_root = DEFAULT_TARGET_SYSTEM_ROOT;
  
-+static char target_relocatable_prefix[4096] __attribute__ ((section (".gccrelocprefix"))) = SYSTEMLIBS_DIR;
++static char target_relocatable_prefix[4096] __attribute__ ((section (".gccrelocprefix"))) = TARGET_RELOCATE_PREFIX;
 +
  /* Nonzero means pass the updated target_system_root to the compiler.  */