[pacman-dev] [PATCH] Add "-Wl,--as-needed" to libalpm LDFLAGS.

Dan McGee dpmcgee at gmail.com
Sun Mar 20 12:29:32 EDT 2011


On Sat, Mar 19, 2011 at 6:29 PM, Allan McRae <allan at archlinux.org> wrote:
> On 20/03/11 06:28, Lukas Fleischer wrote:
>>
>> Also includes a Debian patch (from #347650) that makes libtool play
>> nicely with "-Wl,--as-needed".
>>
>> Signed-off-by: Lukas Fleischer<archlinux at cryptocrack.de>
>> ---
>>  lib/libalpm/Makefile.am |    2 +-
>>  ltmain.sh               |   14 ++++++++++++++
>>  2 files changed, 15 insertions(+), 1 deletions(-)
>>
>> diff --git a/lib/libalpm/Makefile.am b/lib/libalpm/Makefile.am
>> index 1bda571..4c329b8 100644
>> --- a/lib/libalpm/Makefile.am
>> +++ b/lib/libalpm/Makefile.am
>> @@ -52,7 +52,7 @@ libalpm_la_SOURCES += \
>>        md5.h md5.c
>>  endif
>>
>> -libalpm_la_LDFLAGS = -no-undefined -version-info $(LIB_VERSION_INFO)
>> +libalpm_la_LDFLAGS = -no-undefined -version-info $(LIB_VERSION_INFO)
>> -Wl,--as-needed
>
> This part is not needed.   With the changes below the build obeys the given
> LDFLAGS.   Unless of course we want to make this the default.
>
>
>>  libalpm_la_LIBADD = $(LTLIBINTL)
>>
>>  # vim:set ts=2 sw=2 noet:
>> diff --git a/ltmain.sh b/ltmain.sh
>> index 6c02b18..4e98c79 100755
>> --- a/ltmain.sh
>> +++ b/ltmain.sh
>> @@ -5790,6 +5790,11 @@ func_mode_link ()
>>        arg=$func_stripname_result
>>        ;;
>>
>> +      -Wl,--as-needed|-Wl,--no-as-needed)
>> +       deplibs="$deplibs $arg"
>> +       continue
>> +       ;;
>> +
>>        -Wl,*)
>>        func_stripname '-Wl,' '' "$arg"
>>        args=$func_stripname_result
>> @@ -6150,6 +6155,15 @@ func_mode_link ()
>>        lib=
>>        found=no
>>        case $deplib in
>> +       -Wl,--as-needed|-Wl,--no-as-needed)
>> +         if test "$linkmode,$pass" = "prog,link"; then
>> +           compile_deplibs="$deplib $compile_deplibs"
>> +           finalize_deplibs="$deplib $finalize_deplibs"
>> +         else
>> +           deplibs="$deplib $deplibs"
>> +         fi
>> +         continue
>> +         ;;
>>
>>  -mt|-mthreads|-kthread|-Kthread|-pthread|-pthreads|--thread-safe|-threads)
>>          if test "$linkmode,$pass" = "prog,link"; then
>>            compile_deplibs="$deplib $compile_deplibs"
>
> This hack will do until libtool gets it fixed.   Just to clarify what the
> issues is here, libtool likes to reorder arguments that you pass to it.
>  That puts -Wl,--as-needed after all the -lfoo statements which stops it
> working.   And this is a hack as it requires -Wl,--as-needed to be
> separately specified  (-Wl,--as-needed,--something-else will not work).  But
> this fix is in widespread use while we wait for the proper fix so I will
> give it an ack.

Applied this but still seeing problems...hmm.

/bin/sh ../../libtool --tag=CC   --mode=link gcc -std=gnu99 -pedantic
-D_GNU_SOURCE  -fvisibility=internal -fgnu89-inline -march=x86-64
-mtune=generic -O2 -pipe -fstack-protector-all -D_FORTIFY_SOURCE=2 -g
-Wall -Werror -no-undefined -version-info 6:0:0 -Wl,--hash-style=gnu
-Wl,--as-needed -o libalpm.la -rpath /usr/lib add.lo alpm.lo
alpm_list.lo backup.lo be_local.lo be_package.lo be_sync.lo
conflict.lo db.lo delta.lo deps.lo diskspace.lo dload.lo error.lo
group.lo handle.lo log.lo package.lo pkghash.lo remove.lo sync.lo
trans.lo util.lo version.lo   -lfetch -lssl -larchive  -lssp
libtool: link: gcc -std=gnu99 -shared  -fPIC -DPIC  .libs/add.o
.libs/alpm.o .libs/alpm_list.o .libs/backup.o .libs/be_local.o
.libs/be_package.o .libs/be_sync.o .libs/conflict.o .libs/db.o
.libs/delta.o .libs/deps.o .libs/diskspace.o .libs/dload.o
.libs/error.o .libs/group.o .libs/handle.o .libs/log.o .libs/package.o
.libs/pkghash.o .libs/remove.o .libs/sync.o .libs/trans.o .libs/util.o
.libs/version.o   -Wl,--as-needed -lfetch -lssl /usr/lib/libarchive.so
-lacl -lattr -lexpat -llzma -lbz2 -lz -lcrypto -lssp  -march=x86-64
-mtune=generic -O2 -Wl,--hash-style=gnu   -Wl,-soname -Wl,libalpm.so.6
-o .libs/libalpm.so.6.0.0
libtool: link: (cd ".libs" && rm -f "libalpm.so.6" && ln -s
"libalpm.so.6.0.0" "libalpm.so.6")
libtool: link: (cd ".libs" && rm -f "libalpm.so" && ln -s
"libalpm.so.6.0.0" "libalpm.so")
libtool: link: ar cru .libs/libalpm.a  add.o alpm.o alpm_list.o
backup.o be_local.o be_package.o be_sync.o conflict.o db.o delta.o
deps.o diskspace.o dload.o error.o group.o handle.o log.o package.o
pkghash.o remove.o sync.o trans.o util.o version.o
libtool: link: ranlib .libs/libalpm.a
libtool: link: ( cd ".libs" && rm -f "libalpm.la" && ln -s
"../libalpm.la" "libalpm.la" )


dmcgee at galway ~/projects/pacman-maint (maint)
$ ldd lib/libalpm/.libs/libalpm.so
	linux-vdso.so.1 =>  (0x00007fff38dff000)
	libfetch.so => /usr/lib/libfetch.so (0x00007faf13b0e000)
	libarchive.so.2 => /usr/lib/libarchive.so.2 (0x00007faf138cb000)
	libcrypto.so.1.0.0 => /usr/lib/libcrypto.so.1.0.0 (0x00007faf1350e000)
	libssp.so.0 => /usr/lib/libssp.so.0 (0x00007faf1330c000)
	libc.so.6 => /lib/libc.so.6 (0x00007faf12fab000)
	libssl.so.1.0.0 => /usr/lib/libssl.so.1.0.0 (0x00007faf12d4e000)
	libacl.so.1 => /lib/libacl.so.1 (0x00007faf12b47000)
	libattr.so.1 => /lib/libattr.so.1 (0x00007faf12943000)
	libexpat.so.1 => /usr/lib/libexpat.so.1 (0x00007faf12719000)
	liblzma.so.5 => /usr/lib/liblzma.so.5 (0x00007faf124f7000)
	libbz2.so.1.0 => /lib/libbz2.so.1.0 (0x00007faf122e7000)
	libz.so.1 => /usr/lib/libz.so.1 (0x00007faf120ce000)
	libdl.so.2 => /lib/libdl.so.2 (0x00007faf11eca000)
	/lib/ld-linux-x86-64.so.2 (0x00007faf13f76000)
	libpthread.so.0 => /lib/libpthread.so.0 (0x00007faf11cac000)


More information about the pacman-dev mailing list