FreeBSD 5.3: Sharedlibs using sharedlibs (and Tcl)

Peter Much pmc at
Wed Mar 16 12:12:44 PST 2005

On Wed, Mar 16, 2005 at 03:35:16PM +0100, Palle Girgensohn wrote:
! --On onsdag, mars 16, 2005 11.43.31 +0100 Peter Much 
! <pmc at> wrote:
! >! So, you're saying that pctclsh *can* access, but pgaccess *cannot*?
! >Odd...  ! I would expect they'd both use the same lib to connect, no?
! >I'll have to
! >
! >They use the same libraries, yes. But Tcl interpreter seem to need more
! >advice on where to find sub-functions in other libraries. It looks
! >like this:
! >
! >pgtclsh  -finds-> -finds-> -finds->
! >pgaccess -loads-> -finds-> -fails->
! Uh, OK. I'm not qualified enough with linkers to answer this, I'm afraid. 
! Did you try the pgsql-interfaces mailing list?

Oh well, same with me. I sent a copy of one of my reports to that
list, yes. But only got feedback that it will be evaluated by
moderator, as I am not signed on that list.
I'm actually no professional psql user - the database is just a small
part of my installation, mainly logging the lowlevel error counts 
from my exabyte drives and providing reports about tape wearout.
And the kerberos is just there for fun, as a reference installation.

Nevertheless, I would think this is not a matter for the postgres
community. Because this would happen the same way with any other
application that provides Tcl support and kerberos support (or maybe
also with other components of the system, if they are used from Tcl).

So it seems either a Tcl problem or a linker/loader problem. Which,
I cannot say - maybe both.

! >And then I found that it is enough to place into the explicit
! >references to libkrb5 and the other kerberos libs. That is what the
! >"readelf -a" output in my other mail shows.
! sounds like a better solution, yes... Shouldn't they always be there? 
! Sounds like a bug to me?

Thats the question. 
I just did a little more investigation (like reading manpages)
and found out _WHY_ it does work for pgtclsh but not for pgaccess. 

There is a command "ldd" that shows nested library dependencies
for any program. 
For pgtclsh it shows all the kerberos libs:

bash-3.00# ldd /usr/local/bin/pgtclsh
/usr/local/bin/pgtclsh: => /usr/local/lib/ (0x28075000) => /usr/local/lib/ (0x2807d000) => /usr/local/lib/ (0x28097000) => /lib/ (0x28135000) => /usr/lib/ (0x2814f000) => /usr/lib/ (0x28186000) => /lib/ (0x281a6000) => /usr/lib/ (0x2829b000) => /lib/ (0x282a9000) => /usr/lib/ (0x282c1000) => /lib/ (0x282c3000) => /lib/ (0x282d3000) => /lib/ (0x282ff000) => /lib/ (0x2830b000) => /usr/local/lib/ (0x283e4000) => /usr/lib/ (0x283ed000) => /lib/ (0x2841b000) => /usr/local/lib/ (0x2845a000)

But for (this is the first elf binary that pgaccess gets
to see) it does not show these kerberos libraries (I use the old here, not the one that I have modified):

bash-3.00# ldd /usr/local/lib/
/usr/local/lib/ => /usr/local/lib/ (0x2815a000) => /usr/local/lib/ (0x28174000) => /lib/ (0x28212000) => /usr/local/lib/ (0x2822c000) => /usr/lib/ (0x28235000) => /lib/ (0x28263000) => /usr/local/lib/ (0x28358000)

Then the explanation became simple: these kerberos libraries get
just LITERALLY LISTED WITHIN THE pgtclsh BINARY! And this is an
impossible method for a Tcl script.

bash-3.00# readelf -d /usr/local/bin/pgtclsh | grep krb5
 0x00000001 (NEEDED) Shared library: []

So now we have a full explanation for the behaviour, but not really
a solution.
Instead, this looks like a fundamental question about how to load
nested elf sharedlibs from interpreter languages.

>From my technical viewpoint, the only solution that makes sense
would be: every shared library must reference all other shared
libraries from which it uses functions. The shared library cannot
rely on the executable to do this job, because the executable
may be an interpreter script, which neither is able to do this
nor would it want to know them all.

>From this viewpoint, the linker command that creates
is defective. So You were right and its a problem for the 
postgresql developers.

But as I am not competent with shared libraries and development
systems and such stuff, I would very much appreciate the opinion
of somebody with profound knowledge of these things. And anyway,
perl should have similar problems.

Ok, lets see - which nice mailinglists do we crosspost today? 
I go with questions and ports, and add hackers. I think we're now
deep enough in the rabbithole for them. ;-)
And psql-interfaces.


More information about the freebsd-ports mailing list