Thread: Fix for ODBC close
I have applied the following patch to properly exit ODBC. I also patched the ODBC makefile so it links under BSD/OS. The -Bsymbolic under BSD/OS is very harsh under BSD/OS, requiring all symbols even in libc and crt1.o to be resolved before creating the shared library. My 'ld' manual says: -Bsymbolic When creating a shared library, bind references to global symbols to the definition within the shared library, if any. Normally, it is possible for a program linked against a shared library to override the definition within the shared library. This op- tion is only meaningful on ELF platforms which sup- port shared libraries. -- 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 Index: src/interfaces/odbc/GNUmakefile =================================================================== RCS file: /home/projects/pgsql/cvsroot/pgsql/src/interfaces/odbc/GNUmakefile,v retrieving revision 1.8 diff -c -r1.8 GNUmakefile *** src/interfaces/odbc/GNUmakefile 2000/12/16 18:14:25 1.8 --- src/interfaces/odbc/GNUmakefile 2001/02/10 04:25:23 *************** *** 24,30 **** gpps.o tuple.o tuplelist.o dlg_specific.o $(OBJX) SHLIB_LINK = $(filter -lm, $(LIBS)) - all: all-lib # Shared library stuff --- 24,29 ---- *************** *** 33,39 **** --- 32,46 ---- # Symbols must be resolved to the version in the shared library because # the driver manager (e.g., iodbc) provides some symbols with the same # names and we don't want those. (This issue is probably ELF specific.) + # + # BSD/OS fails with libc and crt1.o undefined symbols without this. + # bjm 2001-02-09 + # + ifneq ($(PORTNAME), bsdi) LINK.shared += $(shlib_symbolic) + endif odbc_headers = isql.h isqlext.h iodbc.h odbc_includedir = $(includedir)/iodbc Index: src/interfaces/odbc/socket.c =================================================================== RCS file: /home/projects/pgsql/cvsroot/pgsql/src/interfaces/odbc/socket.c,v retrieving revision 1.7 diff -c -r1.7 socket.c *** src/interfaces/odbc/socket.c 2000/05/27 03:35:14 1.7 --- src/interfaces/odbc/socket.c 2001/02/10 04:25:29 *************** *** 1,4 **** - /* Module: socket.c * * Description: This module contains functions for low level socket --- 1,3 ---- *************** *** 78,84 **** --- 77,87 ---- { if (self->socket != -1) { if ( ! shutdown(self->socket, 2)) /* no sends or receives */ + { + SOCK_put_char(self, 'X'); + SOCK_flush_output(self); closesocket(self->socket); + } } if (self->buffer_in)
Bruce Momjian writes: > I have applied the following patch to properly exit ODBC. I also > patched the ODBC makefile so it links under BSD/OS. The -Bsymbolic > under BSD/OS is very harsh under BSD/OS, requiring all symbols even in > libc and crt1.o to be resolved before creating the shared library. The -Bsymbolic switch is the same on all platforms that have it. You can link without it, but then you won't actually be able to use the ODBC driver. It seems like you need to link in a few other libraries to resolve all symbols. -- Peter Eisentraut peter_e@gmx.net http://yi.org/peter-e/
> Bruce Momjian writes: > > > I have applied the following patch to properly exit ODBC. I also > > patched the ODBC makefile so it links under BSD/OS. The -Bsymbolic > > under BSD/OS is very harsh under BSD/OS, requiring all symbols even in > > libc and crt1.o to be resolved before creating the shared library. > > The -Bsymbolic switch is the same on all platforms that have it. You can > link without it, but then you won't actually be able to use the ODBC > driver. It seems like you need to link in a few other libraries to > resolve all symbols. OK, if this is true on all platforms, why isn't -lc needed? -- 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
> > Bruce Momjian writes: > > > > > I have applied the following patch to properly exit ODBC. I also > > > patched the ODBC makefile so it links under BSD/OS. The -Bsymbolic > > > under BSD/OS is very harsh under BSD/OS, requiring all symbols even in > > > libc and crt1.o to be resolved before creating the shared library. > > > > The -Bsymbolic switch is the same on all platforms that have it. You can > > link without it, but then you won't actually be able to use the ODBC > > driver. It seems like you need to link in a few other libraries to > > resolve all symbols. > > OK, if this is true on all platforms, why isn't -lc needed? > And if -lc is somehow done by default with ld -Bsymbolic, how do I deal with a link that accesses crt1.o startup symbols, like environ and __progname? -- 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
> > > Bruce Momjian writes: > > > > > > > I have applied the following patch to properly exit ODBC. I also > > > > patched the ODBC makefile so it links under BSD/OS. The -Bsymbolic > > > > under BSD/OS is very harsh under BSD/OS, requiring all symbols even in > > > > libc and crt1.o to be resolved before creating the shared library. > > > > > > The -Bsymbolic switch is the same on all platforms that have it. You can > > > link without it, but then you won't actually be able to use the ODBC > > > driver. It seems like you need to link in a few other libraries to > > > resolve all symbols. > > > > OK, if this is true on all platforms, why isn't -lc needed? > > > > And if -lc is somehow done by default with ld -Bsymbolic, how do I deal > with a link that accesses crt1.o startup symbols, like environ and > __progname? > OK, the following fixes the link on BSDI, while allowing -Bsymbolic. I have to explicitly include -R crt1.o to be used to resolve symbols, but not to be linked in. Without -R, I get undefined 'main' which makes sense. I am still confused why other OS's work, unless -lc is assumed by ld, and their libc's have no crt1.o references. -- 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 Index: src/interfaces/odbc/GNUmakefile =================================================================== RCS file: /home/projects/pgsql/cvsroot/pgsql/src/interfaces/odbc/GNUmakefile,v retrieving revision 1.9 diff -c -r1.9 GNUmakefile *** src/interfaces/odbc/GNUmakefile 2001/02/10 05:50:27 1.9 --- src/interfaces/odbc/GNUmakefile 2001/02/10 11:26:13 *************** *** 36,43 **** # BSD/OS fails with libc and crt1.o undefined symbols without this. # bjm 2001-02-09 # - ifneq ($(PORTNAME), bsdi) LINK.shared += $(shlib_symbolic) endif odbc_headers = isql.h isqlext.h iodbc.h --- 36,44 ---- # BSD/OS fails with libc and crt1.o undefined symbols without this. # bjm 2001-02-09 # LINK.shared += $(shlib_symbolic) + ifeq ($(PORTNAME), bsdi) + SHLIB_LINK += -lc -R /usr/lib/crt1.o endif odbc_headers = isql.h isqlext.h iodbc.h
Bruce Momjian writes: > > The -Bsymbolic switch is the same on all platforms that have it. You can > > link without it, but then you won't actually be able to use the ODBC > > driver. It seems like you need to link in a few other libraries to > > resolve all symbols. > > OK, if this is true on all platforms, why isn't -lc needed? Theory 1: Many other platforms use the compiler driver ([g]cc) to link shared libraries. That makes all the right things happen. Most likely this should happen on a lot more platforms that currently use ld directly. Theory 2: Not many people have tried to build the ODBC driver on non-mainstream platforms. -- Peter Eisentraut peter_e@gmx.net http://yi.org/peter-e/
> Bruce Momjian writes: > > > > The -Bsymbolic switch is the same on all platforms that have it. You can > > > link without it, but then you won't actually be able to use the ODBC > > > driver. It seems like you need to link in a few other libraries to > > > resolve all symbols. > > > > OK, if this is true on all platforms, why isn't -lc needed? > > Theory 1: Many other platforms use the compiler driver ([g]cc) to link > shared libraries. That makes all the right things happen. Most likely > this should happen on a lot more platforms that currently use ld directly. > > Theory 2: Not many people have tried to build the ODBC driver on > non-mainstream platforms. I just tried gcc and got: #$ gcc -shared -soname libpsqlodbc.so.0 -Bsymbolic info.o bind.o columninfo.o connection.o convert.o drvconn.o environ.o execute.o lobj.o misc.o options.o pgtypes.o psqlodbc.o qresult.o results.o socket.o parse.o statement.o gpps.o tuple.o tuplelist.o dlg_specific.o -L/usr/local/lib -L/usr/contrib/lib -lm -o libpsqlodbc.so.0.26 gcc: unrecognized option `-soname' gcc: file path prefix `symbolic' never used -- 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
Bruce Momjian writes: > I just tried gcc and got: > > #$ gcc -shared -soname libpsqlodbc.so.0 -Bsymbolic info.o bind.o > columninfo.o connection.o convert.o drvconn.o environ.o execute.o lobj.o > misc.o options.o pgtypes.o psqlodbc.o qresult.o results.o socket.o > parse.o statement.o gpps.o tuple.o tuplelist.o dlg_specific.o > -L/usr/local/lib -L/usr/contrib/lib -lm -o libpsqlodbc.so.0.26 > gcc: unrecognized option `-soname' > gcc: file path prefix `symbolic' never used Try gcc -shared -Wl,-soname,libpsqlodbc.so.0 -Wl,-Bsymbolic ... -- Peter Eisentraut peter_e@gmx.net http://yi.org/peter-e/
> Bruce Momjian writes: > > > I just tried gcc and got: > > > > #$ gcc -shared -soname libpsqlodbc.so.0 -Bsymbolic info.o bind.o > > columninfo.o connection.o convert.o drvconn.o environ.o execute.o lobj.o > > misc.o options.o pgtypes.o psqlodbc.o qresult.o results.o socket.o > > parse.o statement.o gpps.o tuple.o tuplelist.o dlg_specific.o > > -L/usr/local/lib -L/usr/contrib/lib -lm -o libpsqlodbc.so.0.26 > > gcc: unrecognized option `-soname' > > gcc: file path prefix `symbolic' never used > > Try gcc -shared -Wl,-soname,libpsqlodbc.so.0 -Wl,-Bsymbolic ... OK, this works: gcc -shared -Wl,-Bsymbolic,-soname,libpsqlodbc.so.0 info.o bind.o columninfo.o connection.o convert.o drvconn.o environ.o execute.o lobj.o misc.o options.o pgtypes.o psqlodbc.o qresult.o results.o socket.o parse.o statement.o gpps.o tuple.o tuplelist.o dlg_specific.o -L/usr/local/lib -L/usr/contrib/lib -lm -lc -o libpsqlodbc.so.0.26 I replaced the 'ld' with 'gcc -Wl', and that prevents the need for the crt1.o. It still requires -lc: ifneq ($(PORTNAME), bsdi) LINK.shared += $(shlib_symbolic) else LINK.shared = gcc -shared -Wl,-Bsymbolic,-soname,$(soname) SHLIB_LINK += -lc endif It seems the -Bsymbolic needs the gcc, while other links are OK with ld. We may find this is true on many platforms. -- 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
Bruce Momjian writes: > I replaced the 'ld' with 'gcc -Wl', and that prevents the need for the > crt1.o. > > It still requires -lc: > > ifneq ($(PORTNAME), bsdi) > LINK.shared += $(shlib_symbolic) > else > LINK.shared = gcc -shared -Wl,-Bsymbolic,-soname,$(soname) > SHLIB_LINK += -lc > endif You can't hardcode "gcc" like that. I've committed some fixes that should work for you. Please try them out. Also try to build libpq++. > It seems the -Bsymbolic needs the gcc, while other links are OK with ld. > We may find this is true on many platforms. -Bsymbolic requires all symbols in the library to be resolvable at link time. If you use 'ld' then you will need to provide all the appropriate files yourself. The compiler driver normally does that automatically. -- Peter Eisentraut peter_e@gmx.net http://yi.org/peter-e/
> You can't hardcode "gcc" like that. I've committed some fixes that should > work for you. Please try them out. Also try to build libpq++. > > > It seems the -Bsymbolic needs the gcc, while other links are OK with ld. > > We may find this is true on many platforms. > > -Bsymbolic requires all symbols in the library to be resolvable at link > time. If you use 'ld' then you will need to provide all the appropriate > files yourself. The compiler driver normally does that automatically. > Great. I see you modified Makefile.bsdi to properly know it is being used with gcc, and modified Makefile.shlib. Perfect. Should other platforms have this fix too? We didn't need it before -Bsymbolic, but it seems it would be safe to do for FreeBSD and a few others. -- 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
> > -Bsymbolic requires all symbols in the library to be resolvable at link > > time. If you use 'ld' then you will need to provide all the appropriate > > files yourself. The compiler driver normally does that automatically. > > > > Great. I see you modified Makefile.bsdi to properly know it is being > used with gcc, and modified Makefile.shlib. Perfect. > > Should other platforms have this fix too? We didn't need it before > -Bsymbolic, but it seems it would be safe to do for FreeBSD and a few > others. I have applied the following patch for OpenBSD and FreeBSD. They have the same -Bsymbolic handling and same use of LD for linking. I made the duplicate changes Peter made for BSDI. Can anyone commend on the use of 'ld -x' to delete all local symbols? FreeBSD and OpenBSD have it, while BSD/OS does not. I added it to BSDi, and it seems to work fine. Actually, it seems NetBSD already had all these fixes. -- 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 Index: src/Makefile.shlib =================================================================== RCS file: /home/projects/pgsql/cvsroot/pgsql/src/Makefile.shlib,v retrieving revision 1.41 diff -c -r1.41 Makefile.shlib *** src/Makefile.shlib 2001/02/10 16:51:39 1.41 --- src/Makefile.shlib 2001/02/10 17:16:06 *************** *** 112,118 **** ifeq ($(PORTNAME), openbsd) shlib := lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION).$(SO_MINOR_VERSION) ifdef ELF_SYSTEM ! LINK.shared = $(LD) -x -Bshareable -soname $(soname) else LINK.shared = $(LD) -x -Bshareable -Bforcearchive endif --- 112,119 ---- ifeq ($(PORTNAME), openbsd) shlib := lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION).$(SO_MINOR_VERSION) ifdef ELF_SYSTEM ! LINK.shared = $(COMPILER) -shared -Wl,-x,-soname,$(soname) ! SHLIB_LINK += -lc else LINK.shared = $(LD) -x -Bshareable -Bforcearchive endif *************** *** 121,127 **** ifeq ($(PORTNAME), bsdi) shlib := lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION).$(SO_MINOR_VERSION) ifeq ($(DLSUFFIX), .so) ! LINK.shared = $(COMPILER) -shared -Wl,-soname,$(soname) SHLIB_LINK += -lc endif ifeq ($(DLSUFFIX), .o) --- 122,128 ---- ifeq ($(PORTNAME), bsdi) shlib := lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION).$(SO_MINOR_VERSION) ifeq ($(DLSUFFIX), .so) ! LINK.shared = $(COMPILER) -shared -Wl,-x,-soname,$(soname) SHLIB_LINK += -lc endif ifeq ($(DLSUFFIX), .o) *************** *** 132,138 **** ifeq ($(PORTNAME), freebsd) ifdef ELF_SYSTEM shlib := lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION) ! LINK.shared = $(LD) -x -shared -soname $(soname) else shlib := lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION).$(SO_MINOR_VERSION) LINK.shared = $(LD) -x -Bshareable -Bforcearchive --- 133,140 ---- ifeq ($(PORTNAME), freebsd) ifdef ELF_SYSTEM shlib := lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION) ! LINK.shared = $(COMPILER) -shared -Wl,-x,-soname,$(soname) ! SHLIB_LINK += -lc else shlib := lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION).$(SO_MINOR_VERSION) LINK.shared = $(LD) -x -Bshareable -Bforcearchive *************** *** 142,148 **** ifeq ($(PORTNAME), netbsd) shlib := lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION).$(SO_MINOR_VERSION) ifdef ELF_SYSTEM ! LINK.shared = $(COMPILER) -shared -Wl,-soname,$(soname) else LINK.shared = $(LD) -x -Bshareable -Bforcearchive endif --- 144,150 ---- ifeq ($(PORTNAME), netbsd) shlib := lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION).$(SO_MINOR_VERSION) ifdef ELF_SYSTEM ! LINK.shared = $(COMPILER) -shared -Wl,-x,-soname,$(soname) else LINK.shared = $(LD) -x -Bshareable -Bforcearchive endif Index: src/makefiles/Makefile.freebsd =================================================================== RCS file: /home/projects/pgsql/cvsroot/pgsql/src/makefiles/Makefile.freebsd,v retrieving revision 1.13 diff -c -r1.13 Makefile.freebsd *** src/makefiles/Makefile.freebsd 2000/12/16 18:14:25 1.13 --- src/makefiles/Makefile.freebsd 2001/02/10 17:16:07 *************** *** 3,9 **** ifdef ELF_SYSTEM export_dynamic = -export-dynamic rpath = -R$(libdir) ! shlib_symbolic = -Bsymbolic endif DLSUFFIX = .so --- 3,9 ---- ifdef ELF_SYSTEM export_dynamic = -export-dynamic rpath = -R$(libdir) ! shlib_symbolic = -Wl,-Bsymbolic endif DLSUFFIX = .so Index: src/makefiles/Makefile.openbsd =================================================================== RCS file: /home/projects/pgsql/cvsroot/pgsql/src/makefiles/Makefile.openbsd,v retrieving revision 1.6 diff -c -r1.6 Makefile.openbsd *** src/makefiles/Makefile.openbsd 2000/12/16 18:14:25 1.6 --- src/makefiles/Makefile.openbsd 2001/02/10 17:16:07 *************** *** 3,9 **** ifdef ELF_SYSTEM export_dynamic = -Wl,-E rpath = -R$(libdir) ! shlib_symbolic = -Bsymbolic endif DLSUFFIX = .so --- 3,9 ---- ifdef ELF_SYSTEM export_dynamic = -Wl,-E rpath = -R$(libdir) ! shlib_symbolic = -Wl,-Bsymbolic endif DLSUFFIX = .so
pgman@candle.pha.pa.us wrote: > I have applied the following patch to properly exit ODBC. I also > patched the ODBC makefile so it links under BSD/OS. The -Bsymbolic > under BSD/OS is very harsh under BSD/OS, requiring all symbols even in > libc and crt1.o to be resolved before creating the shared library. > > My 'ld' manual says: > > -Bsymbolic > When creating a shared library, bind references to > global symbols to the definition within the shared > library, if any. Normally, it is possible for a > program linked against a shared library to override > the definition within the shared library. This op- > tion is only meaningful on ELF platforms which sup- > port shared libraries. Hmm, removing that may break it when running under a driver manager though... I will check of FreeBSD, it certainly will on Linux ELF. -- Nick Gorham When I die, I want to go like my grandfather did, gently while sleeping, and not like his passangers, screaming in a panic, looking for the inflatable raft. -- Seen on ./