diff mbox series

[v3] ldconfig-native: Add usrmerge support

Message ID 20231219104301.443343-1-johannes.pointner@br-automation.com
State New
Headers show
Series [v3] ldconfig-native: Add usrmerge support | expand

Commit Message

Johannes Pointner Dec. 19, 2023, 10:42 a.m. UTC
From: Johannes Pointner <johannes.pointner@br-automation.com>

If DISTRO_FEATURE usrmerge is enabled, SLIBDIR is just a symlink to LIBDIR.
ldconfig-native uses hardcoded paths for SLIBDIR and LIBDIR that are fine for
the not usrmerge case. But if usrmerge is enabled ldconfig-native generates a
ld.so.cache for the target, which is done in rootfs.py, that looks like this:
236 libs found in cache `/etc/ld.so.cache'
       libzstd.so.1 (libc6) => /lib/libzstd.so.1
       libz.so.1 (libc6) => /lib/libz.so.1
       libxtables.so.12 (libc6) => /lib/libxtables.so.12
       libxslt.so.1 (libc6) => /lib/libxslt.so.1
       libxml2.so.2 (libc6) => /lib/libxml2.so.2

But it should look like this, which it does in case of not usrmerge:
236 libs found in cache `/etc/ld.so.cache'
        libzstd.so.1 (libc6) => /usr/lib/libzstd.so.1
        libz.so.1 (libc6) => /usr/lib/libz.so.1
        libxtables.so.12 (libc6) => /usr/lib/libxtables.so.12
        libxslt.so.1 (libc6) => /usr/lib/libxslt.so.1
        libxml2.so.2 (libc6) => /usr/lib/libxml2.so.2

As this is part of the generated image(target) this breaks for example the
Qt QLibraryInfo paths if Qt is configured 'relocatable' and leads to the issue
that the QtWebEngine can find the QtWebEngineProcess,
Qt WebEngine resources,...
In the case of Qt this issue appears because Qt tries to determine the library
locations using dladdr and uses this as base to access QtWebEngineProcess or
Qt Webengine resources.

Therefore don't let ldconfig-native parse SLIBDIR if it is a symlink.

Signed-off-by: Johannes Pointner <johannes.pointner@br-automation.com>
---
v3: enhanced explanation

v2: fixed sendemail.from and enhanced explanation

 .../ldconfig-add-usrmerge-support.patch       | 37 +++++++++++++++++++
 .../glibc/ldconfig-native_2.12.1.bb           |  1 +
 2 files changed, 38 insertions(+)
 create mode 100644 meta/recipes-core/glibc/ldconfig-native-2.12.1/ldconfig-add-usrmerge-support.patch

Comments

Richard Purdie Feb. 9, 2024, 5:13 p.m. UTC | #1
On Tue, 2023-12-19 at 11:42 +0100, Johannes Pointner via
lists.openembedded.org wrote:
> From: Johannes Pointner <johannes.pointner@br-automation.com>
> 
> If DISTRO_FEATURE usrmerge is enabled, SLIBDIR is just a symlink to LIBDIR.
> ldconfig-native uses hardcoded paths for SLIBDIR and LIBDIR that are fine for
> the not usrmerge case. But if usrmerge is enabled ldconfig-native generates a
> ld.so.cache for the target, which is done in rootfs.py, that looks like this:
> 236 libs found in cache `/etc/ld.so.cache'
>        libzstd.so.1 (libc6) => /lib/libzstd.so.1
>        libz.so.1 (libc6) => /lib/libz.so.1
>        libxtables.so.12 (libc6) => /lib/libxtables.so.12
>        libxslt.so.1 (libc6) => /lib/libxslt.so.1
>        libxml2.so.2 (libc6) => /lib/libxml2.so.2
> 
> But it should look like this, which it does in case of not usrmerge:
> 236 libs found in cache `/etc/ld.so.cache'
>         libzstd.so.1 (libc6) => /usr/lib/libzstd.so.1
>         libz.so.1 (libc6) => /usr/lib/libz.so.1
>         libxtables.so.12 (libc6) => /usr/lib/libxtables.so.12
>         libxslt.so.1 (libc6) => /usr/lib/libxslt.so.1
>         libxml2.so.2 (libc6) => /usr/lib/libxml2.so.2
> 
> As this is part of the generated image(target) this breaks for example the
> Qt QLibraryInfo paths if Qt is configured 'relocatable' and leads to the issue
> that the QtWebEngine can find the QtWebEngineProcess,
> Qt WebEngine resources,...
> In the case of Qt this issue appears because Qt tries to determine the library
> locations using dladdr and uses this as base to access QtWebEngineProcess or
> Qt Webengine resources.
> 
> Therefore don't let ldconfig-native parse SLIBDIR if it is a symlink.
> 
> Signed-off-by: Johannes Pointner <johannes.pointner@br-automation.com>
> ---
> v3: enhanced explanation
> 
> v2: fixed sendemail.from and enhanced explanation
> 
>  .../ldconfig-add-usrmerge-support.patch       | 37 +++++++++++++++++++
>  .../glibc/ldconfig-native_2.12.1.bb           |  1 +
>  2 files changed, 38 insertions(+)
>  create mode 100644 meta/recipes-core/glibc/ldconfig-native-2.12.1/ldconfig-add-usrmerge-support.patch
> 
> diff --git a/meta/recipes-core/glibc/ldconfig-native-2.12.1/ldconfig-add-usrmerge-support.patch b/meta/recipes-core/glibc/ldconfig-native-2.12.1/ldconfig-add-usrmerge-support.patch
> new file mode 100644
> index 0000000000..3041d433fd
> --- /dev/null
> +++ b/meta/recipes-core/glibc/ldconfig-native-2.12.1/ldconfig-add-usrmerge-support.patch
> @@ -0,0 +1,37 @@
> +From 6e543f39f6bec6eb2e02eea02029c7f4ec533b66 Mon Sep 17 00:00:00 2001
> +From: Johannes Pointner <johannes.pointner@br-automation.com>
> +Date: Fri, 1 Dec 2023 11:02:39 +0100
> +Subject: [PATCH] ldconfig: add usrmerge support
> +
> +Check whether SLIBDIR is a symlink, which is the case if usrmerge
> +is enabled, and if so, ignore it.
> +
> +Upstream-Status: Inappropriate [embedded specific]
> +
> +Signed-off-by: Johannes Pointner <johannes.pointner@br-automation.com>
> +---
> + ldconfig.c | 8 +++++++-
> + 1 file changed, 7 insertions(+), 1 deletion(-)
> +
> +diff --git a/ldconfig.c b/ldconfig.c
> +index e826410..72ac67b 100644
> +--- a/ldconfig.c
> ++++ b/ldconfig.c
> +@@ -1371,10 +1371,16 @@ main (int argc, char **argv)
> + 
> +   if (!opt_only_cline)
> +     {
> ++      struct stat buf;
> ++      int ret;
> +       parse_conf (config_file, true);
> + 
> +       /* Always add the standard search paths.  */
> +-      add_system_dir (SLIBDIR);
> ++      /* Check whether SLIBDIR is a symlink, which is the case if usrmerge
> ++       is enabled, and if so, ignore it. */
> ++      ret = lstat(SLIBDIR ,&buf);
> ++      if(ret == -1 || !S_ISLNK(buf.st_mode))
> ++        add_system_dir (SLIBDIR);
> +       if (strcmp (SLIBDIR, LIBDIR))
> + 	add_system_dir (LIBDIR);
> +       add_system_dir (SLIBDIR32);
> diff --git a/meta/recipes-core/glibc/ldconfig-native_2.12.1.bb b/meta/recipes-core/glibc/ldconfig-native_2.12.1.bb
> index 4db67c3ad4..85fc87257d 100644
> --- a/meta/recipes-core/glibc/ldconfig-native_2.12.1.bb
> +++ b/meta/recipes-core/glibc/ldconfig-native_2.12.1.bb
> @@ -16,6 +16,7 @@ SRC_URI = "file://ldconfig-native-2.12.1.tar.bz2 \
>             file://add-64-bit-flag-for-ELF64-entries.patch \
>             file://no-aux-cache.patch \
>             file://add-riscv-support.patch \
> +           file://ldconfig-add-usrmerge-support.patch \
>  "
>  

Sorry this has sat in the "to review" queue for a while as none of us
could really understand what it is doing or why.

ldconfig caches the lookups that the normal dynamic loader would make.
If you symlink lib to usr/lib and the loader search path has lib first,
ldconfig *will* look at /lib/. This is entirely correct and expected.
It shouldn't really matter whether it sees /lib/XXX or /usr/lib/XXX at
the end of the day, they're the same file, albeit plus/minus a symlink
resolution.

Your patch breaks the standard ordering. My view is we should not
change what is arguably the correct behaviour and potentially cause all
kinds of other unexpected problems due to some Qt specific weirdness
which non of us can really understand.

So sorry but no, we can't accept this.

Cheers,

Richard
diff mbox series

Patch

diff --git a/meta/recipes-core/glibc/ldconfig-native-2.12.1/ldconfig-add-usrmerge-support.patch b/meta/recipes-core/glibc/ldconfig-native-2.12.1/ldconfig-add-usrmerge-support.patch
new file mode 100644
index 0000000000..3041d433fd
--- /dev/null
+++ b/meta/recipes-core/glibc/ldconfig-native-2.12.1/ldconfig-add-usrmerge-support.patch
@@ -0,0 +1,37 @@ 
+From 6e543f39f6bec6eb2e02eea02029c7f4ec533b66 Mon Sep 17 00:00:00 2001
+From: Johannes Pointner <johannes.pointner@br-automation.com>
+Date: Fri, 1 Dec 2023 11:02:39 +0100
+Subject: [PATCH] ldconfig: add usrmerge support
+
+Check whether SLIBDIR is a symlink, which is the case if usrmerge
+is enabled, and if so, ignore it.
+
+Upstream-Status: Inappropriate [embedded specific]
+
+Signed-off-by: Johannes Pointner <johannes.pointner@br-automation.com>
+---
+ ldconfig.c | 8 +++++++-
+ 1 file changed, 7 insertions(+), 1 deletion(-)
+
+diff --git a/ldconfig.c b/ldconfig.c
+index e826410..72ac67b 100644
+--- a/ldconfig.c
++++ b/ldconfig.c
+@@ -1371,10 +1371,16 @@ main (int argc, char **argv)
+ 
+   if (!opt_only_cline)
+     {
++      struct stat buf;
++      int ret;
+       parse_conf (config_file, true);
+ 
+       /* Always add the standard search paths.  */
+-      add_system_dir (SLIBDIR);
++      /* Check whether SLIBDIR is a symlink, which is the case if usrmerge
++       is enabled, and if so, ignore it. */
++      ret = lstat(SLIBDIR ,&buf);
++      if(ret == -1 || !S_ISLNK(buf.st_mode))
++        add_system_dir (SLIBDIR);
+       if (strcmp (SLIBDIR, LIBDIR))
+ 	add_system_dir (LIBDIR);
+       add_system_dir (SLIBDIR32);
diff --git a/meta/recipes-core/glibc/ldconfig-native_2.12.1.bb b/meta/recipes-core/glibc/ldconfig-native_2.12.1.bb
index 4db67c3ad4..85fc87257d 100644
--- a/meta/recipes-core/glibc/ldconfig-native_2.12.1.bb
+++ b/meta/recipes-core/glibc/ldconfig-native_2.12.1.bb
@@ -16,6 +16,7 @@  SRC_URI = "file://ldconfig-native-2.12.1.tar.bz2 \
            file://add-64-bit-flag-for-ELF64-entries.patch \
            file://no-aux-cache.patch \
            file://add-riscv-support.patch \
+           file://ldconfig-add-usrmerge-support.patch \
 "