[PATCH] liblua: link shared library against libm to fix undefined sinh on glibc

Mabrooka “Yosr” Ben Belgacem <[email protected]>
Newsgroups gmane.comp.lang.lua.general
Message-ID <[email protected]>
Hello Lua maintainers,

While running unit tests in a glibc-based environment, I encountered a 
runtime
issue when loading the shared library liblua.so.5.1.5:

*     Failed to load lib /lib/liblua.so.5.1.5: undefined symbol: sinh*

This happens because *liblua.so *is under-linked: it does not explicitly 
declare 
*libm.so* as a dependency in its *DT_NEEDED* entries.
On glibc-based systems, standard math functions like sinh, cos, etc., 
are provided by libm, which is a separate shared library.
Without declaring libm as a dependency, loading liblua.so directly will 
fail 
unless the consumer explicitly links against *-lm*, which incorrectly shifts
responsibility for resolving these symbols from the library itself to its 
users.

Linking *-lm* in downstream applications or test binaries masks the issue 
but is not a proper solution: 
*the shared library itself should declare all libraries required to resolve 
its own symbols.*

*Proposed Fix:*

Update the shared library link stage for liblua.so to explicitly link 
against libm (-lm). 
This ensures that:

1. All direct dependencies of liblua are correctly declared.
2. liblua.so can be safely loaded on glibc-based systems without requiring 
consumers 
   to add -lm.

This change has been verified on a glibc system and resolves the undefined *'sinh' 
*symbol.

*Patch:*

---
diff --git a/Makefile b/Makefile
index 7fea77e5b1..14aa34ba52 100644
--- a/Makefile
+++ b/Makefile
@@ -94,6 +94,7 @@ define Build/Configure
 TARGET_CFLAGS += -DLUA_USE_LINUX $(FPIC) -std=gnu99
+TARGET_LDFLAGS += -lm
---

Signed-off-by: Mabrouka <[email protected]>

-- 
You received this message because you are subscribed to the Google Groups "lua-l" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
To view this discussion visit https://groups.google.com/d/msgid/lua-l/2f00c512-d728-47cf-acc8-5c4f54ef4506n%40googlegroups.com.
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.