Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 122128 - Linking against lua fails when compiled with -Wl,--as-needed
Summary: Linking against lua fails when compiled with -Wl,--as-needed
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: [OLD] Library (show other bugs)
Hardware: All Linux
: High normal (vote)
Assignee: Tom Payne (RETIRED)
Depends on:
Blocks: as-needed
  Show dependency tree
Reported: 2006-02-08 07:28 UTC by Benjamin Schindler (RETIRED)
Modified: 2006-10-15 09:10 UTC (History)
2 users (show)

See Also:
Package list:
Runtime testing required: ---

files/lua-5.0.2-LDFLAGS_and_as-needed.patch (lua-5.0.2-LDFLAGS_and_as-needed.patch,1.79 KB, patch)
2006-05-07 09:51 UTC, TGL
Details | Diff
lua-5.0.2-ebuild.patch (lua-5.0.2-ebuild.patch,669 bytes, patch)
2006-05-07 09:52 UTC, TGL
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Benjamin Schindler (RETIRED) gentoo-dev 2006-02-08 07:28:02 UTC
I just started writing an ebuild for a game using lua, and it fails to configure when --as-needed is specified. 

I found that, doing the following sed:

sed -i -e 's:^\(.*-shared.*\):\1 $(DLLIB) $(EXTRA_LIBS):' Makefile

Fixes the problem. It's needed because the -ldl and -lm libraries get a NEEDED entry in the so file. Programs that link against liblua without adding -lm -ldl themselves fail get unresolved symbols, like:

/usr/lib/gcc/x86_64-pc-linux-gnu/3.4.4/../../../../lib64/ undefined reference to `log'
/usr/lib/gcc/x86_64-pc-linux-gnu/3.4.4/../../../../lib64/ undefined reference to `sqrt'
/usr/lib/gcc/x86_64-pc-linux-gnu/3.4.4/../../../../lib64/ undefined reference to `dlerror'
Comment 1 TGL 2006-05-07 09:51:25 UTC
I will attach patches for lua-5.0.2 and its ebuild which do the following:
 * make lua respect user's LDFLAGS when linking binaries or libs (in addition, the default -Wl,-E is still used for the binaries).
 * fix unresolved symbols of liblualib by linking it to liblua and the other libs it needs.

I don't know much packages to test this, but according to "ldd -r" the libs should be sane now. Does it work for your game too?
Comment 2 TGL 2006-05-07 09:51:59 UTC
Created attachment 86374 [details, diff]
Comment 3 TGL 2006-05-07 09:52:53 UTC
Created attachment 86375 [details, diff]

patch is for -5.0.2.ebuild, not the masked -r1 (i've not looked at this one)
Comment 4 Benjamin Schindler (RETIRED) gentoo-dev 2006-05-15 12:04:19 UTC
The game is currently in a broken state so I cannot comment, but looking at lib the ebuild produces, it looks correct
Comment 5 Stefan Schweizer (RETIRED) gentoo-dev 2006-06-25 09:55:53 UTC
twp allowe3d me to apply this one. It makes xmoto work with as-needed for me, thank you!

+  25 Jun 2006; Stefan Schweizer <>
+  +files/lua-5.0.2-LDFLAGS_and_as-needed.patch, lua-5.0.2.ebuild:
+  as-needed patch thanks to TGL <> in bug 122128 from
+  Benjamin Schindler <>
Comment 6 Emanuele Giaquinta (RETIRED) gentoo-dev 2006-10-14 01:55:25 UTC
This patch is wrong; you add "-L$(LIB) -llua" for but the symlink to is created only after is generated so ld links the static archive, liblua.a; in fact you can check with 'scanelf -n' that has no NEEDED on Do you understand what this imply?
Comment 7 Emanuele Giaquinta (RETIRED) gentoo-dev 2006-10-15 09:10:56 UTC
I have disabled the patch in lua-5.0.2, because the right one depends on the libs having an soname; it is already fixed in lua-5.0.3 which will be soon unmasked.