• Tom Lane's avatar
    Prevent mis-linking of src/port and src/common functions on *BSD. · e3d77ea6
    Tom Lane authored
    On ELF-based platforms (and maybe others?) it's possible for a shared
    library, when dynamically loaded into the backend, to call the backend
    versions of src/port and src/common functions rather than the frontend
    versions that are actually linked into the shlib.  This is the cause
    of bug #15367 from Jeremy Evans, and is likely to lead to more problems
    in future; it's accidental that we've failed to notice any bad effects
    up to now.
    
    The recommended way to fix this on ELF-based platforms is to use a
    linker "version script" that makes the shlib's versions of the functions
    local.  (Apparently, -Bsymbolic would fix it as well, but with other
    side effects that we don't want.)  Doing so has the additional benefit
    that we can make sure the shlib only exposes the symbols that are meant
    to be part of its API, and not ones that are just for cross-file
    references within the shlib.  So we'd already been using a version
    script for libpq on popular platforms, but it's now apparent that it's
    necessary for correctness on every ELF-based platform.
    
    Hence, add appropriate logic to the openbsd, freebsd, and netbsd stanzas
    of Makefile.shlib; this is just a copy-and-paste from the linux stanza.
    There may be additional work to do if commit ed0cdf0e reveals that the
    problem exists elsewhere, but this is all that is known to be needed
    right now.
    
    Back-patch to v10 where SCRAM support came in.  The problem is ancient,
    but analysis suggests that there were no really severe consequences
    in older branches.  Hence, I won't take the risk of such a large change
    in the build process for older branches.
    
    In passing, remove a rather opaque comment about -Bsymbolic; I don't
    think it's very on-point about why we don't use that, if indeed that's
    what it's talking about at all.
    
    Patch by me; thanks to Andrew Gierth for helping to diagnose the problem,
    and for additional testing.
    
    Discussion: https://postgr.es/m/153626613985.23143.4743626885618266803@wrigleys.postgresql.org
    e3d77ea6
Makefile.shlib 15.7 KB