install-strip causes dyld errors on OS X - Mailing list pgsql-hackers

From Meredith L. Patterson
Subject install-strip causes dyld errors on OS X
Date
Msg-id 472690A1.7060100@osogato.com
Whole thread Raw
Responses Re: install-strip causes dyld errors on OS X
List pgsql-hackers
Hi all,

Three years ago, Andrew MacRae logged the following bug:

http://archives.postgresql.org/pgsql-bugs/2004-02/msg00042.php

In brief, when installing on OS X with "make install-strip", 
installation goes fine, but initdb dies here:

creating conversions... ERROR:  could not load library
"/usr/local/pgsql/lib/ascii_and_mic.so": dyld: 
/usr/local/pgsql/bin/postgres
Undefined symbols:        /usr/local/pgsql/lib/ascii_and_mic.so undefined reference to
_pg_ascii2mic expected to be defined in the executable

I encountered this problem today with OS X 10.4 and CVS HEAD, and came 
up with a few possible solutions. The problem has to do with the 
difference between shared libraries and dynamic libraries, and how strip 
behaves with them on OS X.

Here's how it works: When called on an executable which uses dyld, strip 
silently passes itself the -u (save all undefined symbols) and -r (save 
all dynamically-referenced symbols) options. However, the 
internationalization libraries (and a few others, like libplperl and 
libplpython) are compiled as shared libraries (.so as opposed to 
.dylib), so strip doesn't know that those libraries contain undefined 
symbols and are expecting to acquire them from the executable.

I see three possible fixes:

1) Patch config/install-sh such that on OS X, install-strip calls 'strip 
-x'. This removes local symbols only.
2) Determine which symbols are global and undefined in the shared 
libraries that are built, make a list of them, and call 'strip -u -r -s 
symbols_to_keep'. This saves undefined symbols, dynamically referenced 
symbols, and symbols that the shared libraries need.
3) Change the OS X build such that the i18n libs and other shared libs 
are instead built as dylibs.

I've tested (1) as far as getting through initdb, starting the 
postmaster and a few quick things with psql. It would be about a 
four-line patch to install-sh (check for the OS, set stripcmd 
appropriately). It might not leave the resulting binary *as* small as it 
could be, but it certainly works.

(2) sounds like a giant pain in the ass. It's scriptable and could be 
added to the build, but the build takes pretty long as it is and I can't 
imagine anyone wants to make it longer. Unless there's a good reason, 
I'm pre-emptively -1'ing this one.

I haven't done any looking into (3) yet. Why *are* the i18n libs built 
as shared on OS X, anyway?

Cheers,
--mlp
_____________________
Meredith L. Patterson
Founder and CTO
Osogato, Inc.


pgsql-hackers by date:

Previous
From: David Fetter
Date:
Subject: Re: Proposal: real procedures again (8.4)
Next
From: Tom Lane
Date:
Subject: Re: Recovery of Multi-stage WAL actions