using -Wl, --as-needed with libsecret and glib? [was: Re: error building pinentry 0.9.2 with libsecret]

Daniel Kahn Gillmor dkg at fifthhorseman.net
Wed May 13 21:52:09 CEST 2015


On Wed 2015-05-13 15:14:26 -0400, Daniel Kahn Gillmor wrote:
> hi there pinentry people--
>
> trying to build pinentry 0.9.2 with libsecret on a debian testing
> system, and i get the following error when linking
> pinentry/pinentry-curses.c:
>
> gcc  -g -O2 -fstack-protector-strong -Wformat -Werror=format-security -Wall -Wcast-align -Wshadow -Wstrict-prototypes -Wno-pointer-sign  -Wl,-z,relro -Wl,--as-needed -o pinentry-curses pinentry-curses.o -lsecret-1 -lgio-2.0 -lgobject-2.0 -lglib-2.0  ../pinentry/libpinentry.a ../pinentry/libpinentry-curses.a ../assuan/libassuan.a ../secmem/libsecmem.a  -lncursesw  
> ../pinentry/libpinentry.a(password-cache.o): In function `password_cache_save':
> /home/dkg/src/pkg-gnupg/pinentry/pinentry/password-cache.c:80: undefined reference to `secret_password_store_sync'
> /home/dkg/src/pkg-gnupg/pinentry/pinentry/password-cache.c:89: undefined reference to `g_error_free'
> ../pinentry/libpinentry.a(password-cache.o): In function `password_cache_lookup':
> /home/dkg/src/pkg-gnupg/pinentry/pinentry/password-cache.c:109: undefined reference to `secret_password_lookup_nonpageable_sync'
> /home/dkg/src/pkg-gnupg/pinentry/pinentry/password-cache.c:131: undefined reference to `secret_password_free'
> /home/dkg/src/pkg-gnupg/pinentry/pinentry/password-cache.c:117: undefined reference to `g_error_free'
> collect2: error: ld returned 1 exit status
> Makefile:389: recipe for target 'pinentry-curses' failed
> make: *** [pinentry-curses] Error 1
>
> I'm a little confused, because i see the -lsecret-1 in the linking line,
> and i'd expect secret_password_store to be defined there.
>
> And i'd think that g_error_free would be available from -lglib-2.0.
>
> i think Kristian Fiskerstrand is seeing the same concerns building on
> gentoo.

the problem seems to be related to the -Wl,--as-needed linker option,
which Kristian is using too.

I've minimized it to this test case, which seems like it shouldn't be
happening, unless there's some sort of bad interaction between glib and
ld's --as-needed flag:

---------------
0 dkg at alice:~/src/pkg-gnupg/pinentry$ cat test.c
#include <glib.h>

int main(int argc, char * argv[]) {
  GError *error = NULL;
  g_error_free (error);
  
  return 0;
}
0 dkg at alice:~/src/pkg-gnupg/pinentry$ gcc -o test $(pkg-config --cflags --libs glib-2.0)   test.c
0 dkg at alice:~/src/pkg-gnupg/pinentry$ gcc -o test -Wl,--as-needed  $(pkg-config --cflags --libs glib-2.0)   test.c
/home/dkg/tmp/ccJ27dyL.o: In function `main':
test.c:(.text+0x1f): undefined reference to `g_error_free'
collect2: error: ld returned 1 exit status
1 dkg at alice:~/src/pkg-gnupg/pinentry$ gcc -o test  $(pkg-config --cflags --libs glib-2.0)   -Wl,--as-needed test.c
0 dkg at alice:~/src/pkg-gnupg/pinentry$
----------------

So what matters is whether the supplied -l flags go before or after
-Wl,--as-needed.  (indeed, the ld man page suggests that --as-needed
only applies to arguments that follow it on the linker command line)

I'd like to be able to use --as-needed to minimize unnecessary linking.

I found this, but it doesn't seem to resolve the issue:

https://sigquit.wordpress.com/2011/02/16/why-asneeded-doesnt-work-as-expected-for-your-libraries-on-your-autotools-project/

Any pointers?

    --dkg



More information about the Gnupg-devel mailing list