diff options
author | Tom Lane | 2019-01-02 18:57:42 +0000 |
---|---|---|
committer | Tom Lane | 2019-01-02 18:57:54 +0000 |
commit | 69ae9dcb444a667533344562f134444856fb3414 (patch) | |
tree | bd785d9854f8e210edae8acb9b3b7eb9ebe2e791 /src/makefiles | |
parent | 97c39498e5ca9208d3de5a443a2282923619bf91 (diff) |
Ensure link commands list *.o files before LDFLAGS.
It's important for link commands to list *.o input files before -l
switches for libraries, as library code may not get pulled into the link
unless referenced by an earlier command-line entry. This is certainly
necessary for static libraries (.a style). Apparently on some platforms
it is also necessary for shared libraries, as reported by Donald Dong.
We often put -l switches for within-tree libraries into LDFLAGS, meaning
that link commands that list *.o files after LDFLAGS are hazardous.
Most of our link commands got this right, but a few did not. In
particular, places that relied on gmake's default implicit link rule
failed, because that puts LDFLAGS first. Fix that by overriding the
built-in rule with our own. The implicit link rules in
src/makefiles/Makefile.* for single-.o-file shared libraries mostly
got this wrong too, so fix them. I also changed the link rules for the
backend and a couple of other places for consistency, even though they
are not (currently) at risk because they aren't adding any -l switches
to LDFLAGS.
Arguably, the real problem here is that we're abusing LDFLAGS by
putting -l switches in it and we should stop doing that. But changing
that would be quite invasive, so I'm not eager to do so.
Perhaps this is a candidate for back-patching, but so far it seems
that problems can only be exhibited in test code we don't normally
build, and at least some of the problems are new in HEAD anyway.
So I'll refrain for now.
Donald Dong and Tom Lane
Discussion: https://postgr.es/m/CAKABAquXn-BF-vBeRZxhzvPyfMqgGuc74p8BmQZyCFDpyROBJQ@mail.gmail.com
Diffstat (limited to 'src/makefiles')
-rw-r--r-- | src/makefiles/Makefile.aix | 2 | ||||
-rw-r--r-- | src/makefiles/Makefile.darwin | 2 | ||||
-rw-r--r-- | src/makefiles/Makefile.freebsd | 2 | ||||
-rw-r--r-- | src/makefiles/Makefile.hpux | 4 | ||||
-rw-r--r-- | src/makefiles/Makefile.linux | 2 | ||||
-rw-r--r-- | src/makefiles/Makefile.netbsd | 2 | ||||
-rw-r--r-- | src/makefiles/Makefile.openbsd | 2 | ||||
-rw-r--r-- | src/makefiles/Makefile.solaris | 4 |
8 files changed, 10 insertions, 10 deletions
diff --git a/src/makefiles/Makefile.aix b/src/makefiles/Makefile.aix index e5ad89d1470..0f6c0289384 100644 --- a/src/makefiles/Makefile.aix +++ b/src/makefiles/Makefile.aix @@ -40,4 +40,4 @@ MKLDEXPORT=$(top_srcdir)/$(MKLDEXPORT_DIR)/mkldexport.sh # Rule for building a shared library from a single .o file %$(DLSUFFIX): %.o %.exp - $(CC) $(CFLAGS) $(LDFLAGS) $(LDFLAGS_SL) -o $@ $*.o -Wl,-bE:$*.exp $(BE_DLLLIBS) + $(CC) $(CFLAGS) $*.o $(LDFLAGS) $(LDFLAGS_SL) -o $@ -Wl,-bE:$*.exp $(BE_DLLLIBS) diff --git a/src/makefiles/Makefile.darwin b/src/makefiles/Makefile.darwin index 7a8ba3e5274..e2b1d44959f 100644 --- a/src/makefiles/Makefile.darwin +++ b/src/makefiles/Makefile.darwin @@ -10,4 +10,4 @@ endif # Rule for building a shared library from a single .o file %.so: %.o - $(CC) $(CFLAGS) $(LDFLAGS) $(LDFLAGS_SL) -bundle $(BE_DLLLIBS) -o $@ $< + $(CC) $(CFLAGS) $< $(LDFLAGS) $(LDFLAGS_SL) -bundle $(BE_DLLLIBS) -o $@ diff --git a/src/makefiles/Makefile.freebsd b/src/makefiles/Makefile.freebsd index 5a98e5a2b0b..ce03c8dcd26 100644 --- a/src/makefiles/Makefile.freebsd +++ b/src/makefiles/Makefile.freebsd @@ -13,7 +13,7 @@ CFLAGS_SL = -fPIC -DPIC # Rule for building a shared library from a single .o file %.so: %.o ifdef ELF_SYSTEM - $(CC) $(CFLAGS) $(LDFLAGS) $(LDFLAGS_SL) -shared -o $@ $< + $(CC) $(CFLAGS) $< $(LDFLAGS) $(LDFLAGS_SL) -shared -o $@ else $(LD) $(LDREL) $(LDOUT) $<.obj -x $< @echo building shared object $@ diff --git a/src/makefiles/Makefile.hpux b/src/makefiles/Makefile.hpux index 97bd0ba6d9e..30dd3eb77e6 100644 --- a/src/makefiles/Makefile.hpux +++ b/src/makefiles/Makefile.hpux @@ -40,13 +40,13 @@ endif %$(DLSUFFIX): %.o ifeq ($(GCC), yes) ifeq ($(with_gnu_ld), yes) - $(CC) $(CFLAGS) $(LDFLAGS) $(LDFLAGS_SL) -shared -o $@ $< `$(CC) $(LDFLAGS) -print-libgcc-file-name` + $(CC) $(CFLAGS) $< $(LDFLAGS) $(LDFLAGS_SL) -shared -o $@ `$(CC) $(LDFLAGS) -print-libgcc-file-name` else $(LD) -b -o $@ $< `$(CC) $(LDFLAGS) -print-libgcc-file-name` endif else ifeq ($(with_gnu_ld), yes) - $(CC) $(CFLAGS) $(LDFLAGS) $(LDFLAGS_SL) -shared -o $@ $< + $(CC) $(CFLAGS) $< $(LDFLAGS) $(LDFLAGS_SL) -shared -o $@ else $(LD) -b -o $@ $< endif diff --git a/src/makefiles/Makefile.linux b/src/makefiles/Makefile.linux index f4f091caef5..ac58fe45de0 100644 --- a/src/makefiles/Makefile.linux +++ b/src/makefiles/Makefile.linux @@ -12,4 +12,4 @@ CFLAGS_SL = -fPIC # Rule for building a shared library from a single .o file %.so: %.o - $(CC) $(CFLAGS) $(LDFLAGS) $(LDFLAGS_SL) -shared -o $@ $< + $(CC) $(CFLAGS) $< $(LDFLAGS) $(LDFLAGS_SL) -shared -o $@ diff --git a/src/makefiles/Makefile.netbsd b/src/makefiles/Makefile.netbsd index 43841c15973..7bb9721fa5b 100644 --- a/src/makefiles/Makefile.netbsd +++ b/src/makefiles/Makefile.netbsd @@ -15,7 +15,7 @@ CFLAGS_SL = -fPIC -DPIC # Rule for building a shared library from a single .o file %.so: %.o ifdef ELF_SYSTEM - $(CC) $(CFLAGS) $(LDFLAGS) $(LDFLAGS_SL) -shared -o $@ $< + $(CC) $(CFLAGS) $< $(LDFLAGS) $(LDFLAGS_SL) -shared -o $@ else $(LD) $(LDREL) $(LDOUT) $<.obj -x $< @echo building shared object $@ diff --git a/src/makefiles/Makefile.openbsd b/src/makefiles/Makefile.openbsd index d8fde49d5c8..eda311087cb 100644 --- a/src/makefiles/Makefile.openbsd +++ b/src/makefiles/Makefile.openbsd @@ -13,7 +13,7 @@ CFLAGS_SL = -fPIC -DPIC # Rule for building a shared library from a single .o file %.so: %.o ifdef ELF_SYSTEM - $(CC) $(CFLAGS) $(LDFLAGS) $(LDFLAGS_SL) -shared -o $@ $< + $(CC) $(CFLAGS) $< $(LDFLAGS) $(LDFLAGS_SL) -shared -o $@ else $(LD) $(LDREL) $(LDOUT) $<.obj -x $< @echo building shared object $@ diff --git a/src/makefiles/Makefile.solaris b/src/makefiles/Makefile.solaris index e459de30cf4..a7f5652f0ca 100644 --- a/src/makefiles/Makefile.solaris +++ b/src/makefiles/Makefile.solaris @@ -19,9 +19,9 @@ endif # Rule for building a shared library from a single .o file %.so: %.o ifeq ($(GCC), yes) - $(CC) $(CFLAGS) $(LDFLAGS) $(LDFLAGS_SL) -shared -o $@ $< + $(CC) $(CFLAGS) $< $(LDFLAGS) $(LDFLAGS_SL) -shared -o $@ else - $(CC) $(CFLAGS) $(LDFLAGS) $(LDFLAGS_SL) -G -o $@ $< + $(CC) $(CFLAGS) $< $(LDFLAGS) $(LDFLAGS_SL) -G -o $@ endif sqlmansect = 5sql |