diff mbox series

[2/2] fix(trylink): always link against pthread if requested

Message ID 20230728091906.660334-2-michael.adler@siemens.com
State Accepted
Delegated to: Stefano Babic
Headers show
Series [1/2] fix(Makefile): correct argument count for trylink invocation | expand

Commit Message

Michael Adler July 28, 2023, 9:19 a.m. UTC
Every *.so produced by swupdate requires `pthread_create` as can be seen
by running `strings` on the respective *.so file.
Previously, trylink removed pthread from the list of required runtime libs.
This is problematic if swupdate is built against luajit and
lua_swupdate.so is used as a library in a Lua script, e.g.

$ echo 'require("lua_swupdate")' | luajit
luajit: error loading module 'lua_swupdate' from file '/usr/lib/aarch64-linux-gnu/lua/5.1/lua_swupdate.so':
        /usr/lib/aarch64-linux-gnu/lua/5.1/lua_swupdate.so: undefined symbol: pthread_sigmask
stack traceback: [...]

Signed-off-by: Michael Adler <michael.adler@siemens.com>
Signed-off-by: Christian Storm <christian.storm@siemens.com>
---
 scripts/trylink | 6 ++++++
 1 file changed, 6 insertions(+)

Comments

Stefano Babic Aug. 2, 2023, 3:22 p.m. UTC | #1
On 28.07.23 11:19, 'Michael Adler' via swupdate wrote:
> Every *.so produced by swupdate requires `pthread_create` as can be seen
> by running `strings` on the respective *.so file.
> Previously, trylink removed pthread from the list of required runtime libs.
> This is problematic if swupdate is built against luajit and
> lua_swupdate.so is used as a library in a Lua script, e.g.
> 
> $ echo 'require("lua_swupdate")' | luajit
> luajit: error loading module 'lua_swupdate' from file '/usr/lib/aarch64-linux-gnu/lua/5.1/lua_swupdate.so':
>          /usr/lib/aarch64-linux-gnu/lua/5.1/lua_swupdate.so: undefined symbol: pthread_sigmask
> stack traceback: [...]
> 
> Signed-off-by: Michael Adler <michael.adler@siemens.com>
> Signed-off-by: Christian Storm <christian.storm@siemens.com>
> ---
>   scripts/trylink | 6 ++++++
>   1 file changed, 6 insertions(+)
> 
> diff --git a/scripts/trylink b/scripts/trylink
> index 94a262a..be652df 100755
> --- a/scripts/trylink
> +++ b/scripts/trylink
> @@ -141,6 +141,12 @@ while test "$LDLIBS"; do
>       all_needed=true
>       last_needed=false
>       for one in $LDLIBS; do
> +	if [ "$one" = "pthread" ]; then
> +		# always link against pthread since this detection mechanism
> +		# tends to remove it even though it's needed at runtime, see
> +		# e.g. `strings lua_swupdate.so.0.1`.
> +		continue
> +	fi
>   	without_one=`echo " $LDLIBS " | sed "s/ $one / /g" | xargs`
>   	# "lib1 lib2 lib3" -> "-llib1 -llib2 -llib3"
>   	l_list=`echo "$without_one" | sed -e 's/ / -l/g' -e 's/^/-l/' -e 's/^-l$//'`

Applied to -master, thanks !

Best regards,
Stefano Babic
diff mbox series

Patch

diff --git a/scripts/trylink b/scripts/trylink
index 94a262a..be652df 100755
--- a/scripts/trylink
+++ b/scripts/trylink
@@ -141,6 +141,12 @@  while test "$LDLIBS"; do
     all_needed=true
     last_needed=false
     for one in $LDLIBS; do
+	if [ "$one" = "pthread" ]; then
+		# always link against pthread since this detection mechanism
+		# tends to remove it even though it's needed at runtime, see
+		# e.g. `strings lua_swupdate.so.0.1`.
+		continue
+	fi
 	without_one=`echo " $LDLIBS " | sed "s/ $one / /g" | xargs`
 	# "lib1 lib2 lib3" -> "-llib1 -llib2 -llib3"
 	l_list=`echo "$without_one" | sed -e 's/ / -l/g' -e 's/^/-l/' -e 's/^-l$//'`