Thread: --with-tcl build on AIX (and others) fails

--with-tcl build on AIX (and others) fails

From
"Zeugswetter Andreas SB SD"
Date:
The current version of the interfaces/libpgtcl/Makefile fails to build a
shared lib on platforms where the shlib needs to resolve symbols from
the loading executable (tclsh) at link time. (only affects AIX?)

The current version of pl/tcl/Makefile fails to build on some platforms,
e.g. that use a packaged version of tcl that was built with a now
unavailable compiler or that need an exports file to build shlibs.
The patch simplifies this Makefile considerably.

Makefile.shlib fails to clean correctly on some platforms.

I thus ask you again to consider applying this improved patch that fixes
above problems before RC1.
Else please keep it, to apply after release.

Thanks
Andreas

Attachment

Re: --with-tcl build on AIX (and others) fails

From
Tom Lane
Date:
"Zeugswetter Andreas SB SD" <ZeugswetterA@spardat.at> writes:
> The current version of pl/tcl/Makefile fails to build on some platforms,
> e.g. that use a packaged version of tcl that was built with a now
> unavailable compiler or that need an exports file to build shlibs.
> The patch simplifies this Makefile considerably.

I don't think we dare risk a wholesale change in the way pltcl is built
for 7.2.  We're already through the ports testing process for 7.2, and
I don't want to start it over again.

This does look like the direction to go in for 7.3, however.  (I think
Peter had already muttered something about getting rid of the existing
pltcl build process in favor of using Makefile.shlib.)

As for the libpgtcl part of the patch, I don't understand why the Tcl
library should be linked into libpgtcl.  libpgtcl is supposed to be
loaded into a Tcl interpreter, not carry its own interpreter along with
it; but it sure looks like that's what will happen with this patch.

            regards, tom lane

Re: --with-tcl build on AIX (and others) fails

From
"Zeugswetter Andreas SB SD"
Date:
> I don't think we dare risk a wholesale change in the way 
> pltcl is built
> for 7.2.  We're already through the ports testing process for 7.2, and
> I don't want to start it over again.

Ok, that is what I asked for, that you look at it, thanks. 7.3 then.
(Of course there have been other portability problems introduced recently, 
so ...)

This leaves the question how many port testers actually built 
and tested --with-tcl and actually tried a load and pg_connect in tclsh. 
My guess is not too many.
Imho we should start to require port reports to contain certain --with 
features, like perl, tcl, ....

> As for the libpgtcl part of the patch, I don't understand why the Tcl
> library should be linked into libpgtcl.  libpgtcl is supposed to be
> loaded into a Tcl interpreter, not carry its own interpreter 
> along with
> it; but it sure looks like that's what will happen with this patch.

On AIX this is actually an imports file. Now the tricky part is 
the first line of this file. This line has to be correct.

Since the tcl Interpreter is linked with this same exports file
the library is only supposed to be loaded once.
Does anybody have an idea how to actually test this (without tk) ?

pgtclsh does work, but the shlib with above Makefile cannot be loaded 
by tclsh because it misses a -bnoentry flag :-(

With -bnoentry it does load and pg_connect and pg_exec and pg_result, 
is this a sufficient test ?
This again is probably a bug in Makefile.shlib on aix, since I guess 
all of our shlibs don't have a main function. Unfortunately a different 
flag has to be used on different aix Versions :-( Don't know if we still 
need to worry about AIX 4.2 and below, though.

Andreas


Re: --with-tcl build on AIX (and others) fails

From
Bruce Momjian
Date:
Saved for 7.3:

    http://candle.pha.pa.us/cgi-bin/pgpatches2

---------------------------------------------------------------------------

Zeugswetter Andreas SB SD wrote:
>
> The current version of the interfaces/libpgtcl/Makefile fails to build a
> shared lib on platforms where the shlib needs to resolve symbols from
> the loading executable (tclsh) at link time. (only affects AIX?)
>
> The current version of pl/tcl/Makefile fails to build on some platforms,
> e.g. that use a packaged version of tcl that was built with a now
> unavailable compiler or that need an exports file to build shlibs.
> The patch simplifies this Makefile considerably.
>
> Makefile.shlib fails to clean correctly on some platforms.
>
> I thus ask you again to consider applying this improved patch that fixes
> above problems before RC1.
> Else please keep it, to apply after release.
--
  Bruce Momjian                        |  http://candle.pha.pa.us
  pgman@candle.pha.pa.us               |  (610) 853-3000
  +  If your life is a hard drive,     |  830 Blythe Avenue
  +  Christ can be your backup.        |  Drexel Hill, Pennsylvania 19026

Re: --with-tcl build on AIX (and others) fails

From
Tom Lane
Date:
"Zeugswetter Andreas SB SD" <ZeugswetterA@spardat.at> writes:
> This leaves the question how many port testers actually built 
> and tested --with-tcl and actually tried a load and pg_connect in tclsh. 
> My guess is not too many.

Good point.

> Imho we should start to require port reports to contain certain --with 
> features, like perl, tcl, ....

Yes, it'd be nice to ask people to check those things.  However if
someone doesn't have Tcl installed, I'm not going to reject the
port report...

> pgtclsh does work, but the shlib with above Makefile cannot be loaded 
> by tclsh because it misses a -bnoentry flag :-(
> With -bnoentry it does load and pg_connect and pg_exec and pg_result, 
> is this a sufficient test ?

I think so.
        regards, tom lane


Re: --with-tcl build on AIX (and others) fails

From
Tom Lane
Date:
I tried out the patch that Andreas sent in a couple weeks ago, and find
that as-is it fails on HPUX.  The attached version works okay on both
HPUX 10.20 and RH Linux 7.2, however.  Anyone want to try it on other
platforms?  (Note this only covers Andreas' proposed changes for pltcl,
not for libpgtcl.)

            regards, tom lane

*** src/Makefile.shlib.orig    Sun Nov 11 20:45:36 2001
--- src/Makefile.shlib    Sun Jan 20 17:03:25 2002
***************
*** 400,406 ****
  clean-lib:
      rm -f lib$(NAME).a
  ifeq ($(enable_shared), yes)
!     rm -f $(shlib) lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION) lib$(NAME)$(DLSUFFIX)
  endif
  ifeq ($(PORTNAME), win)
      rm -rf $(NAME).def
--- 400,409 ----
  clean-lib:
      rm -f lib$(NAME).a
  ifeq ($(enable_shared), yes)
!     rm -f lib$(NAME)$(DLSUFFIX) lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION)
lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION).$(SO_MINOR_VERSION)
! ifdef EXPSUFF
!     rm -f lib$(NAME)$(EXPSUFF)
! endif
  endif
  ifeq ($(PORTNAME), win)
      rm -rf $(NAME).def
*** src/pl/tcl/Makefile.orig    Sat Oct 13 00:23:50 2001
--- src/pl/tcl/Makefile    Sun Jan 20 17:20:56 2002
***************
*** 26,97 ****
  endif
  endif

!
! # Change following to how shared library that contains references to
! # libtcl must get built on your system. Since these definitions come
! # from the tclConfig.sh script, they should work if the shared build
! # of tcl was successful on this system. However, tclConfig.sh lies to
! # us a little bit (at least in versions 7.6 through 8.0.4) --- it
! # doesn't mention -lc in TCL_LIBS, but you still need it on systems
! # that want to hear about dependent libraries...

  ifneq ($(TCL_SHLIB_LD_LIBS),)
  # link command for a shared lib must mention shared libs it uses
! SHLIB_EXTRA_LIBS=$(TCL_LIBS) -lc
  else
  ifeq ($(PORTNAME), hpux)
  # link command for a shared lib must mention shared libs it uses,
  # even though Tcl doesn't think so...
! SHLIB_EXTRA_LIBS=$(TCL_LIBS) -lc
  else
  # link command for a shared lib must NOT mention shared libs it uses
! SHLIB_EXTRA_LIBS=
! endif
  endif
-
- %$(TCL_SHLIB_SUFFIX): %.o
-     $(TCL_SHLIB_LD) -o $@ $< $(TCL_LIB_SPEC) $(SHLIB_EXTRA_LIBS)
-
-
- CC = $(TCL_CC)
-
- # Since we are using Tcl's choice of C compiler, which might not be
- # the same one selected for Postgres, do NOT use CFLAGS from
- # Makefile.global. Instead use TCL's CFLAGS plus necessary -I
- # directives.
-
- # Can choose either TCL_CFLAGS_OPTIMIZE or TCL_CFLAGS_DEBUG here, as
- # needed
- override CPPFLAGS += $(TCL_DEFS)
- override CFLAGS = $(TCL_CFLAGS_OPTIMIZE) $(TCL_SHLIB_CFLAGS)
-
-
- #
- # DLOBJS is the dynamically-loaded object file.
- #
- DLOBJS= pltcl$(DLSUFFIX)
-
- INFILES= $(DLOBJS)
-
- #
- # plus exports files
- #
- ifdef EXPSUFF
- INFILES+= $(DLOBJS:.o=$(EXPSUFF))
  endif


! # Provide dummy targets for the case where we can't build the shared library.

  ifeq ($(TCL_SHARED_BUILD), 1)

! all: $(INFILES)
      $(MAKE) -C modules $@

- pltcl$(DLSUFFIX): pltcl.o
-
  install: all installdirs
!     $(INSTALL_SHLIB) $(DLOBJS) $(DESTDIR)$(pkglibdir)/$(DLOBJS)
      $(MAKE) -C modules $@

  installdirs:
--- 26,64 ----
  endif
  endif

! # Set up extra libs that must be mentioned in pltcl.so's link command.
! # Aside from libtcl.so, on many platforms we must mention the shared
! # libraries that libtcl.so depends on.  Don't forget -lc, which the
! # Tcl makefiles unaccountably exclude from $(TCL_LIBS).

  ifneq ($(TCL_SHLIB_LD_LIBS),)
  # link command for a shared lib must mention shared libs it uses
! SHLIB_LINK=$(TCL_LIB_SPEC) $(TCL_LIBS) -lc
  else
  ifeq ($(PORTNAME), hpux)
  # link command for a shared lib must mention shared libs it uses,
  # even though Tcl doesn't think so...
! SHLIB_LINK=$(TCL_LIB_SPEC) $(TCL_LIBS) -lc
  else
  # link command for a shared lib must NOT mention shared libs it uses
! SHLIB_LINK=$(TCL_LIB_SPEC)
  endif
  endif

+ NAME = pltcl
+ SO_MAJOR_VERSION = 2
+ SO_MINOR_VERSION = 0
+ OBJS = pltcl.o

! include $(top_srcdir)/src/Makefile.shlib

  ifeq ($(TCL_SHARED_BUILD), 1)

! all: all-lib
      $(MAKE) -C modules $@

  install: all installdirs
!     $(INSTALL_SHLIB) $(shlib) $(DESTDIR)$(pkglibdir)/$(NAME)$(DLSUFFIX)
      $(MAKE) -C modules $@

  installdirs:
***************
*** 99,105 ****
      $(MAKE) -C modules $@

  uninstall:
!     rm -f $(DESTDIR)$(pkglibdir)/$(DLOBJS)
      $(MAKE) -C modules $@

  else # TCL_SHARED_BUILD = 0
--- 66,72 ----
      $(MAKE) -C modules $@

  uninstall:
!     rm -f $(DESTDIR)$(pkglibdir)/$(NAME)$(DLSUFFIX)
      $(MAKE) -C modules $@

  else # TCL_SHARED_BUILD = 0
***************
*** 114,119 ****
  Makefile.tcldefs: mkMakefile.tcldefs.sh
      $(SHELL) $< '$(TCL_CONFIG_SH)' '$@'

! clean distclean maintainer-clean:
!     rm -f $(INFILES) pltcl.o Makefile.tcldefs
      $(MAKE) -C modules $@
--- 81,86 ----
  Makefile.tcldefs: mkMakefile.tcldefs.sh
      $(SHELL) $< '$(TCL_CONFIG_SH)' '$@'

! clean distclean maintainer-clean: clean-lib
!     rm -f $(OBJS) Makefile.tcldefs
      $(MAKE) -C modules $@

Re: --with-tcl build on AIX (and others) fails

From
Peter Eisentraut
Date:
Tom Lane writes:

> I tried out the patch that Andreas sent in a couple weeks ago, and find
> that as-is it fails on HPUX.  The attached version works okay on both
> HPUX 10.20 and RH Linux 7.2, however.  Anyone want to try it on other
> platforms?  (Note this only covers Andreas' proposed changes for pltcl,
> not for libpgtcl.)

Back to this one...

I think we're hung up on this part:

> ! # Set up extra libs that must be mentioned in pltcl.so's link command.
> ! # Aside from libtcl.so, on many platforms we must mention the shared
> ! # libraries that libtcl.so depends on.  Don't forget -lc, which the
> ! # Tcl makefiles unaccountably exclude from $(TCL_LIBS).
>
>   ifneq ($(TCL_SHLIB_LD_LIBS),)
>   # link command for a shared lib must mention shared libs it uses
> ! SHLIB_LINK=$(TCL_LIB_SPEC) $(TCL_LIBS) -lc
>   else
>   ifeq ($(PORTNAME), hpux)
>   # link command for a shared lib must mention shared libs it uses,
>   # even though Tcl doesn't think so...
> ! SHLIB_LINK=$(TCL_LIB_SPEC) $(TCL_LIBS) -lc
>   else
>   # link command for a shared lib must NOT mention shared libs it uses
> ! SHLIB_LINK=$(TCL_LIB_SPEC)
>   endif
>   endif

This is still wrong because it depends on information that Tcl generated
during its build using its compiler and linker configuration.

Also, if you use GCC to link, specifying -lc is almost certainly wrong in
any case.

I think what should work is this:  Assign

SHLIB_LINK = $(TCL_LIB_SPEC) $(TCL_LIBS)

unconditionally.  If the port doesn't like mention of shared lib
dependencies, it should ignore SHLIB_LINK in Makefile.shlib.  If the port
wants to have -lc, it should add it to SHLIB_LINK in Makefile.shlib.

-- 
Peter Eisentraut   peter_e@gmx.net



Re: --with-tcl build on AIX (and others) fails

From
"Zeugswetter Andreas SB SD"
Date:
> I think what should work is this:  Assign
>
> SHLIB_LINK = $(TCL_LIB_SPEC) $(TCL_LIBS)
>
> unconditionally.  If the port doesn't like mention of shared lib
> dependencies, it should ignore SHLIB_LINK in Makefile.shlib.
> If the port wants to have -lc, it should add it to SHLIB_LINK in Makefile.shlib.

Yes, that was also my first take, but then it broke HPUX, because HPUX does
not add -lc in Makefile.shlib.

There are some other "wrong" -lc's for ports that use the compiler for linking.

One open Problem is, that $(TCL_LIB_SPEC) is not gcc safe when tcl was built with
a native compiler but pg is to be built with gcc (I guess this is quite common on
AIX, since you get tcl from BULL, but build pg yourself).

TCL_LIB_SPEC='-bI:/usr/local/lib/libtcl8.2${TCL_DBGX}.exp'
but should be:
TCL_LIB_SPEC='-Wl,-bI:/usr/local/lib/libtcl8.2${TCL_DBGX}.exp'

Any idea how to fix this ?

Andreas