On Wed, Nov 16, 2016 at 7:36 PM, Andres Freund <and...@anarazel.de> wrote: > With -Wl,--as-neeeded the linker will dismiss unused symbols found in a > static library. Maybe that's the difference?
The man page --as-needed says that --as-needed modifies the behavior of dynamic libraries, not static ones. If there is any such effect, it is undocumented. Here is the text: LD> This option affects ELF DT_NEEDED tags for dynamic libraries mentioned LD> on the command line after the --as-needed option. Normally the linker will LD> add a DT_NEEDED tag for each dynamic library mentioned on the LD> command line, regardless of whether the library is actually needed or not. LD> --as-needed causes a DT_NEEDED tag to only be emitted for a library LD> that at that point in the link satisfies a non-weak undefined symbol reference LD> from a regular object file or, if the library is not found in the DT_NEEDED LD> lists of other needed libraries, a non-weak undefined symbol reference LD> from another needed dynamic library. Object files or libraries appearing LD> on the command line after the library in question do not affect whether the LD> library is seen as needed. This is similar to the rules for extraction of object LD> files from archives. --no-as-needed restores the default behaviour. Some experimentation on my Mac reveals that my previous statement about how this works was incorrect. See attached patch for what I tried. What I find is: 1. If I create an additional source file in src/common containing a completely unused symbol (wunk) it appears in the nm output for libpgcommon_srv.a but not in the nm output for the postgres binary. 2. If I add an additional function to an existing source file in src/common containing a completely unused symbol (quux) it appears in the nm output for both libpgcommon_srv.a and also in the nm output for the postgres binary. 3. If I create an additional source file in src/backend containing a completely unused symbol (blarfle) it appears in the nm output for the postgres binary. So, it seems that the linker is willing to drop archive members if the entire .o file is used, but not individual symbols. That explains why Michael thinks we need to do something special here, because with his 0001 patch, nothing in the new sha2(_openssl).c file would immediately be used in the backend. And indeed I see now that my earlier testing was done incorrectly, and pgcrypto does in fact fail to build under my proposal. Oops. But I think that's a temporary thing. As soon as the backend is using the sha2 routines for anything (which is the point, right?) the build changes become unnecessary. For example, if I apply this patch: --- a/src/backend/lib/binaryheap.c +++ b/src/backend/lib/binaryheap.c @@ -305,3 +305,7 @@ sift_down(binaryheap *heap, int node_off) node_off = swap_off; } } + +#include "common/sha2.h" +extern void ugh(void); +void ugh(void) { pg_sha224_init(NULL); } ...then the backend ends up sucking in everything in sha2.c and the pgcrypto build works again. -- Robert Haas EnterpriseDB: http://www.enterprisedb.com The Enterprise PostgreSQL Company
diff --git a/src/common/Makefile b/src/common/Makefile index 03dfaa1..f84264a 100644 --- a/src/common/Makefile +++ b/src/common/Makefile @@ -46,7 +46,7 @@ OBJS_COMMON = config_info.o controldata_utils.o exec.o ip.o keywords.o \ OBJS_FRONTEND = $(OBJS_COMMON) fe_memutils.o file_utils.o restricted_token.o -OBJS_SRV = $(OBJS_COMMON:%.o=%_srv.o) +OBJS_SRV = $(OBJS_COMMON:%.o=%_srv.o) wunk.o all: libpgcommon.a libpgcommon_srv.a diff --git a/src/common/ip.c b/src/common/ip.c index 797d910..d517802 100644 --- a/src/common/ip.c +++ b/src/common/ip.c @@ -258,3 +258,11 @@ getnameinfo_unix(const struct sockaddr_un * sa, int salen, return 0; } #endif /* HAVE_UNIX_SOCKETS */ + +extern void quux(void); + +void +quux(void) +{ + /* quux */ +} diff --git a/src/common/wunk.c b/src/common/wunk.c new file mode 100644 index 0000000..2db667c --- /dev/null +++ b/src/common/wunk.c @@ -0,0 +1,7 @@ +extern void wunk(void); + +void +wunk(void) +{ + /* wunk */ +}
-- Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-hackers