Subject: ld --as-needed broken ?
To: None <tech-toolchain@netbsd.org>
From: Patrick Welche <prlw1@newn.cam.ac.uk>
List: tech-toolchain
Date: 05/06/2005 17:27:54
It's the first time I see --as-needed, so I thought I would post here before
sending a PR..

psql uses --as-needed to compile:

gcc -O2 -Wall -Wmissing-prototypes -Wpointer-arith -Wendif-labels -fno-strict-aliasing -g command.o common.o help.o input.o stringutils.o mainloop.o copy.o startup.o prompt.o variables.o large_obj.o print.o describe.o psqlscan.o tab-complete.o mbprint.o  -L../../../src/port -lpgport -L../../../src/interfaces/libpq -lpq -L../../../src/port -Wl,--as-needed -Wl,-R/usr/local/pgsql/lib -lpgport -lssl -lcrypto -lz -ledit -ltermcap -lcrypt -lresolv -lcompat -lm -lutil  -o psql

Now, the important bit is that -ledit and -ltermcap which it depends on are
present, however:

% ldd ./psql   
./psql:
        -lcrypt.0 => /usr/lib/libcrypt.so.0
        -lcrypto.2 => /usr/lib/libcrypto.so.2
        -lssl.3 => /usr/lib/libssl.so.3
        -lresolv.1 => /usr/lib/libresolv.so.1
        -lpq.4 => /usr/local/pgsql/lib/libpq.so.4
        -ledit.2 => /usr/lib/libedit.so.2
        -lc.12 => /usr/lib/libc.so.12
% ./psql template1
Welcome to psql 8.1devel, the PostgreSQL interactive terminal.

Type:  \copyright for distribution terms
       \h for help with SQL commands
       \? for help with psql commands
       \g or terminate with semicolon to execute query
       \q to quit

/usr/lib/libedit.so.2: Undefined PLT symbol "tgetent" (symnum = 158)

and I must bin the --as-needed flag to get a working psql.

Here is what info says:

`--as-needed'
`--no-as-needed'
     This option affects ELF DT_NEEDED tags for dynamic libraries
     mentioned on the command line after the `--as-needed' option.
     Normally, the linker will add a DT_NEEDED tag for each dynamic
     library mentioned on the command line, regardless of whether the
     library is actually needed. `--as-needed' causes DT_NEEDED tags to
     only be emitted for libraries that satisfy some reference from
     regular objects.  `--no-as-needed' restores the default behaviour.

So, does that mean that as none of the object files directly reference
libtermcap, it is dropped from the "needed" list as there isn't a way
of knowing that libedit depends on libtermcap?


Cheers,

Patrick
(-current/i386 of 25 April)