diff mbox series

[2/2] uninative: Add pthread linking workaround

Message ID 20240315142926.3832940-2-richard.purdie@linuxfoundation.org
State Accepted, archived
Commit 5ec2bc7ef663db4c04c85eee518297d442556481
Headers show
Series [1/2] expat: Upgrade 2.6.1 -> 2.6.2 | expand

Commit Message

Richard Purdie March 15, 2024, 2:29 p.m. UTC
With newer glibc versions, pthread was merged into the main library so there is
no longer any need to link with -lpthread. On newer systems this means that linker
flag is dropped from places like pkgconfig .pc files. If uninative then uses this
newer library on an older system, the flag is missing and linker errors about missing
symbols occur.

Adding the linkage unconditionally to our uninative linking flags avoids that problem
at a potential cost of slight over linking.

Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
---
 meta/classes-global/uninative.bbclass | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

Comments

Khem Raj March 15, 2024, 4:06 p.m. UTC | #1
On Fri, Mar 15, 2024 at 7:29 AM Richard Purdie
<richard.purdie@linuxfoundation.org> wrote:
>
> With newer glibc versions, pthread was merged into the main library so there is
> no longer any need to link with -lpthread. On newer systems this means that linker
> flag is dropped from places like pkgconfig .pc files. If uninative then uses this
> newer library on an older system, the flag is missing and linker errors about missing
> symbols occur.
>
> Adding the linkage unconditionally to our uninative linking flags avoids that problem
> at a potential cost of slight over linking.
>

There is another unintended consequence of linking pthreads
unconditionally on older versions
where certain functions which are required to be thread-safe are
implemented as weak stubs in
libc so single threaded programs do not incur the cost of ensuring
thread safety, but when pthread
it linked in, it will replace these stubs with thread safe versions
which are correct in muti-threaded env
but incur performance cost. I do not know how much of this is going to
impact the uninative stuff
but I thought I would mention it for reference.

> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
> ---
>  meta/classes-global/uninative.bbclass | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/meta/classes-global/uninative.bbclass b/meta/classes-global/uninative.bbclass
> index 9b8b4565dd4..d05b61c48eb 100644
> --- a/meta/classes-global/uninative.bbclass
> +++ b/meta/classes-global/uninative.bbclass
> @@ -143,8 +143,8 @@ def enable_uninative(d):
>          d.setVar("NATIVELSBSTRING", "universal%s" % oe.utils.host_gcc_version(d))
>          d.appendVar("SSTATEPOSTUNPACKFUNCS", " uninative_changeinterp")
>          d.appendVarFlag("SSTATEPOSTUNPACKFUNCS", "vardepvalueexclude", "| uninative_changeinterp")
> -        d.appendVar("BUILD_LDFLAGS", " -Wl,--allow-shlib-undefined -Wl,--dynamic-linker=${UNINATIVE_LOADER}")
> -        d.appendVarFlag("BUILD_LDFLAGS", "vardepvalueexclude", "| -Wl,--allow-shlib-undefined -Wl,--dynamic-linker=${UNINATIVE_LOADER}")
> +        d.appendVar("BUILD_LDFLAGS", " -Wl,--allow-shlib-undefined -Wl,--dynamic-linker=${UNINATIVE_LOADER} -Wl,-lpthread")
> +        d.appendVarFlag("BUILD_LDFLAGS", "vardepvalueexclude", "| -Wl,--allow-shlib-undefined -Wl,--dynamic-linker=${UNINATIVE_LOADER} -Wl,-lpthread")
>          d.appendVarFlag("BUILD_LDFLAGS", "vardepsexclude", "UNINATIVE_LOADER")
>          d.prependVar("PATH", "${UNINATIVE_STAGING_DIR}-uninative/${BUILD_ARCH}-linux${bindir_native}:")
>
> --
> 2.40.1
>
>
> -=-=-=-=-=-=-=-=-=-=-=-
> Links: You receive all messages sent to this group.
> View/Reply Online (#197132): https://lists.openembedded.org/g/openembedded-core/message/197132
> Mute This Topic: https://lists.openembedded.org/mt/104948451/1997914
> Group Owner: openembedded-core+owner@lists.openembedded.org
> Unsubscribe: https://lists.openembedded.org/g/openembedded-core/unsub [raj.khem@gmail.com]
> -=-=-=-=-=-=-=-=-=-=-=-
>
diff mbox series

Patch

diff --git a/meta/classes-global/uninative.bbclass b/meta/classes-global/uninative.bbclass
index 9b8b4565dd4..d05b61c48eb 100644
--- a/meta/classes-global/uninative.bbclass
+++ b/meta/classes-global/uninative.bbclass
@@ -143,8 +143,8 @@  def enable_uninative(d):
         d.setVar("NATIVELSBSTRING", "universal%s" % oe.utils.host_gcc_version(d))
         d.appendVar("SSTATEPOSTUNPACKFUNCS", " uninative_changeinterp")
         d.appendVarFlag("SSTATEPOSTUNPACKFUNCS", "vardepvalueexclude", "| uninative_changeinterp")
-        d.appendVar("BUILD_LDFLAGS", " -Wl,--allow-shlib-undefined -Wl,--dynamic-linker=${UNINATIVE_LOADER}")
-        d.appendVarFlag("BUILD_LDFLAGS", "vardepvalueexclude", "| -Wl,--allow-shlib-undefined -Wl,--dynamic-linker=${UNINATIVE_LOADER}")
+        d.appendVar("BUILD_LDFLAGS", " -Wl,--allow-shlib-undefined -Wl,--dynamic-linker=${UNINATIVE_LOADER} -Wl,-lpthread")
+        d.appendVarFlag("BUILD_LDFLAGS", "vardepvalueexclude", "| -Wl,--allow-shlib-undefined -Wl,--dynamic-linker=${UNINATIVE_LOADER} -Wl,-lpthread")
         d.appendVarFlag("BUILD_LDFLAGS", "vardepsexclude", "UNINATIVE_LOADER")
         d.prependVar("PATH", "${UNINATIVE_STAGING_DIR}-uninative/${BUILD_ARCH}-linux${bindir_native}:")