It would certainly seem so on AIX.

In tracking down why postgres 8.x would segfault on AIX 5.3, it became
apparent to me that libreadline.a is a problematic library to link
against and that libedit.a is preferable (and for reasons other than
that readline is GPL while postgres is BSD-licensed).

With AIX 5, the easiest way to get a shared object is to pass "-bexpall"
to the linker. This results in all symbols being exported. The problem
with this is that the linker will export all of libreadline's and
libhistory's symbols. In the case of libreadline.so.4 (and .5) on AIX 5
this includes symbols like strncpy and memmove, but on .4, not memcpy.
This is likely because libc.a does not export them.

What results from this is that when postgres is linked against readline
on AIX, it gets these memory functions through readline instead of its
own code. When readline 4.3 is used (what IBM provides in their "AIX
Toolbox for Linux"), postgres is known to crash. These segfaults (if
postgres was compiled with gcc) have occurred on AIX 5.3ML3, AIX 5.3ML1,
and AIX 5.2ML7. With readline 5.0, postgres merely gets these functions
through the shared library memory segments instead of the user memory
segments[6].

While it is possible to build libreadline in a manner that doesn't
export strncpy, neither of the prebuilt readlines for AIX 5 that I
checked were both shared and did not export strncpy. IBM's readline[5]
exports strncpy, UCLA's readline[4] is static. Building a shared
readline that doesn't export strncpy requires creating export files for
libreadline and libhistory that only list the symbols that they are
supposed to export and editing the shared library Makefile to add the
exports flags to the appropriate linker calls.

Whatever strategy we might take, using readline on AIX requires
considerable trickery and hacking around with the build environments.
Simply put, it's ghastly.

On the other hand, the port of NetBSD's editline that I tried[1] works
without build-hackery to the library and has reasonable exports. The
only changes to postgres that I needed to make were confined to telling
the configure script to check for libedit before libreadline and adding
a test for histedit.h. The attached patch contains my modifications.

It is also possible to use a wrapper like rlwrap[2] instead of linking
postgres against libreadline or libedit.

[1] port of NetBSD's editline
http://www.thrysoee.dk/editline/
[2] rlwrap
http://utopia.knoware.nl/~hlub/uck/software/
[3] IBM Redbook "AIX 5L Porting Guide", section 9.2
http://www.redbooks.ibm.com/abstracts/sg246034.html?Open
http://www.redbooks.ibm.com/redbooks/pdfs/sg246034.pdf
[4] UCLA's readline package
http://aixpdslib.seas.ucla.edu/packages/readline.html
[5] IBM's readline package
http://www-03.ibm.com/servers/aix/products/aixos/linux/download.html
[6] IBM Redbook "Developing and Porting C and C++ Applications on AIX",
page 110
http://www.redbooks.ibm.com/abstracts/sg245674.html?Open
http://www.redbooks.ibm.com/redbooks/pdfs/sg245674.pdf

--
Seneca Cunningham
scunning@ca.afilias.info

Search Discussions

  • Andrew Dunstan at Nov 22, 2005 at 12:50 am
    Nice analysis, but we can't hack configure like that. It has to be able
    to be fully generated from its sources. I think the other source file
    you would need to look at is config/programs.m4. (Not sure about quoting
    $ac_popdir - why only that one?)

    Also, I suspect we'd want to enable the libedit preference with a switch
    rather than just force it, if we want to go this way.

    cheers

    andrew

    Seneca Cunningham wrote:
    It would certainly seem so on AIX.

    In tracking down why postgres 8.x would segfault on AIX 5.3, it became
    apparent to me that libreadline.a is a problematic library to link
    against and that libedit.a is preferable (and for reasons other than
    that readline is GPL while postgres is BSD-licensed).

    With AIX 5, the easiest way to get a shared object is to pass "-bexpall"
    to the linker. This results in all symbols being exported. The problem
    with this is that the linker will export all of libreadline's and
    libhistory's symbols. In the case of libreadline.so.4 (and .5) on AIX 5
    this includes symbols like strncpy and memmove, but on .4, not memcpy.
    This is likely because libc.a does not export them.

    What results from this is that when postgres is linked against readline
    on AIX, it gets these memory functions through readline instead of its
    own code. When readline 4.3 is used (what IBM provides in their "AIX
    Toolbox for Linux"), postgres is known to crash. These segfaults (if
    postgres was compiled with gcc) have occurred on AIX 5.3ML3, AIX 5.3ML1,
    and AIX 5.2ML7. With readline 5.0, postgres merely gets these functions
    through the shared library memory segments instead of the user memory
    segments[6].

    While it is possible to build libreadline in a manner that doesn't
    export strncpy, neither of the prebuilt readlines for AIX 5 that I
    checked were both shared and did not export strncpy. IBM's readline[5]
    exports strncpy, UCLA's readline[4] is static. Building a shared
    readline that doesn't export strncpy requires creating export files for
    libreadline and libhistory that only list the symbols that they are
    supposed to export and editing the shared library Makefile to add the
    exports flags to the appropriate linker calls.

    Whatever strategy we might take, using readline on AIX requires
    considerable trickery and hacking around with the build environments.
    Simply put, it's ghastly.

    On the other hand, the port of NetBSD's editline that I tried[1] works
    without build-hackery to the library and has reasonable exports. The
    only changes to postgres that I needed to make were confined to telling
    the configure script to check for libedit before libreadline and adding
    a test for histedit.h. The attached patch contains my modifications.

    It is also possible to use a wrapper like rlwrap[2] instead of linking
    postgres against libreadline or libedit.

    [1] port of NetBSD's editline
    http://www.thrysoee.dk/editline/
    [2] rlwrap
    http://utopia.knoware.nl/~hlub/uck/software/
    [3] IBM Redbook "AIX 5L Porting Guide", section 9.2
    http://www.redbooks.ibm.com/abstracts/sg246034.html?Open
    http://www.redbooks.ibm.com/redbooks/pdfs/sg246034.pdf
    [4] UCLA's readline package
    http://aixpdslib.seas.ucla.edu/packages/readline.html
    [5] IBM's readline package
    http://www-03.ibm.com/servers/aix/products/aixos/linux/download.html
    [6] IBM Redbook "Developing and Porting C and C++ Applications on AIX",
    page 110
    http://www.redbooks.ibm.com/abstracts/sg245674.html?Open
    http://www.redbooks.ibm.com/redbooks/pdfs/sg245674.pdf
    [patch snipped]
  • Tom Lane at Nov 22, 2005 at 1:09 am

    Andrew Dunstan writes:
    Also, I suspect we'd want to enable the libedit preference with a switch
    rather than just force it, if we want to go this way.
    Quite. My recollection is that there are other platforms on which
    readline works and libedit is broken. (Readline used to work just
    fine even on AIX ;-))

    regards, tom lane
  • Andreas Zeugswetter at Nov 22, 2005 at 9:07 am

    With AIX 5, the easiest way to get a shared object is to pass
    "-bexpall"
    to the linker. This results in all symbols being exported.
    Yes, that is another reason not to use this broken switch.
    And last time I checked (AIX 4.3.3), -bexpall did not export all needed
    symbols
    (e.g. globals) from the backend eighter. And the counterpart -bimpall
    did also not work.
    Dynamic loading did not work without the .imp and .exp files :-(

    Andreas

    PS: I'd prefer if readline was only linked where it is needed, namely in
    psql.
  • Martijn van Oosterhout at Nov 22, 2005 at 9:58 am

    On Tue, Nov 22, 2005 at 10:07:15AM +0100, Zeugswetter Andreas DCP SD wrote:
    PS: I'd prefer if readline was only linked where it is needed, namely in
    psql.
    The problem as stated is that people don't want to maintain lists of
    libraries as needed by each program, so we link all of them.

    Since it seems to always be the same few libraries that cause us
    problems, maybe a simpler approach would be to, in the Makefile, use
    filter-out to exclude libraries you *know* aren't needed. Like in the
    Makefile we put:

    postgres: $(OBJS)
    $(CC) $(CFLAGS) $(LDFLAGS) $(export_dynamic) $^ $(filter-out -lreadline -ledit, $(LIBS)) -o $@

    So instead of maintaining lists of what each binary needs, we can
    maintain a few lists of what certain binaries *don't* need. Actually, I
    think the backend is the only thing important enough to worry about
    this, although if readline is exporting memcpy that it's quite possible
    other binaries might be affected. Maybe create a BACKEND_LIBS which
    contains a shorter list.

    Even the GCC --as-needed flag can't save you from libs exporting
    functions they shouldn't...

    Have a nice day,
    --
    Martijn van Oosterhout <kleptog@svana.org> http://svana.org/kleptog/
    Patent. n. Genius is 5% inspiration and 95% perspiration. A patent is a
    tool for doing 5% of the work and then sitting around waiting for someone
    else to do the other 95% so you can sue them.
  • Jim C. Nasby at Nov 22, 2005 at 8:49 pm

    On Mon, Nov 21, 2005 at 07:50:48PM -0500, Andrew Dunstan wrote:

    Nice analysis, but we can't hack configure like that. It has to be able
    to be fully generated from its sources. I think the other source file
    you would need to look at is config/programs.m4. (Not sure about quoting
    $ac_popdir - why only that one?)

    Also, I suspect we'd want to enable the libedit preference with a switch
    rather than just force it, if we want to go this way.
    BTW, we've run into issues with readline from a licensing standpoint. It
    would be really nice if libedit was supported where practical (I suspect
    most mainstream OSes support libedit) since it's BSD licensed.
    --
    Jim C. Nasby, Sr. Engineering Consultant jnasby@pervasive.com
    Pervasive Software http://pervasive.com work: 512-231-6117
    vcard: http://jim.nasby.net/pervasive.vcf cell: 512-569-9461
  • Bruce Momjian at Nov 25, 2005 at 5:02 pm
    Martijn van Oosterhout wrote:
    -- Start of PGP signed section.
    On Tue, Nov 22, 2005 at 10:07:15AM +0100, Zeugswetter Andreas DCP SD wrote:
    PS: I'd prefer if readline was only linked where it is needed, namely in
    psql.
    The problem as stated is that people don't want to maintain lists of
    libraries as needed by each program, so we link all of them.

    Since it seems to always be the same few libraries that cause us
    problems, maybe a simpler approach would be to, in the Makefile, use
    filter-out to exclude libraries you *know* aren't needed. Like in the
    Makefile we put:

    postgres: $(OBJS)
    $(CC) $(CFLAGS) $(LDFLAGS) $(export_dynamic) $^ $(filter-out -lreadline -ledit, $(LIBS)) -o $@
    Agreed. I have no idea why this has not been done already.

    --
    Bruce Momjian | http://candle.pha.pa.us
    pgman@candle.pha.pa.us | (610) 359-1001
    + If your life is a hard drive, | 13 Roberts Road
    + Christ can be your backup. | Newtown Square, Pennsylvania 19073

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouppgsql-ports @
categoriespostgresql
postedNov 21, '05 at 10:38p
activeNov 25, '05 at 5:02p
posts7
users7
websitepostgresql.org
irc#postgresql

People

Translate

site design / logo © 2022 Grokbase