Обсуждение: LD_LIBRARY_PATH_RPATH
At least on my FreeBSD 11 box, the current definition of $(with_temp_install) is not sufficient to ensure that the various .so files are loaded from tmp_install and not from the compiled rpath (which will be the final install dir, which may of course contain old libraries). LD_LIBRARY_PATH_RPATH=1 fixes this (by giving LD_LIBRARY_PATH priority over the DT_RPATH tag in the object). Is this also an issue on any other platforms? -- Andrew (irc:RhodiumToad)
Andrew Gierth <andrew@tao11.riddles.org.uk> writes: > At least on my FreeBSD 11 box, the current definition of > $(with_temp_install) is not sufficient to ensure that the various .so > files are loaded from tmp_install and not from the compiled rpath (which > will be the final install dir, which may of course contain old > libraries). > LD_LIBRARY_PATH_RPATH=1 fixes this (by giving LD_LIBRARY_PATH priority > over the DT_RPATH tag in the object). > Is this also an issue on any other platforms? Hm. Can't reproduce that on current NetBSD or macOS; don't have OpenBSD booted up to try right now. However, if it helps on some platforms, I can't see much harm in adding it in the relevant places. It should be a no-op everywhere else. regards, tom lane
>>>>> "Tom" == Tom Lane <tgl@sss.pgh.pa.us> writes: >> At least on my FreeBSD 11 box, the current definition of >> $(with_temp_install) is not sufficient to ensure that the various >> .so files are loaded from tmp_install and not from the compiled >> rpath (which will be the final install dir, which may of course >> contain old libraries). >> LD_LIBRARY_PATH_RPATH=1 fixes this (by giving LD_LIBRARY_PATH >> priority over the DT_RPATH tag in the object). >> Is this also an issue on any other platforms? Tom> Hm. Can't reproduce that on current NetBSD or macOS; don't have Tom> OpenBSD booted up to try right now. The OpenBSD manpage I found says that they give LD_LIBRARY_PATH priority over DT_RPATH, so I guess it's not an issue there. Tom> However, if it helps on some platforms, I can't see much harm in Tom> adding it in the relevant places. It should be a no-op everywhere Tom> else. Is there some reason why ld_library_path_var is defined using a bunch of $(if) constructs rather than putting the value (if not LD_LIBRARY_PATH) in the individual port makefiles? -- Andrew (irc:RhodiumToad)
>>>>> "Tom" == Tom Lane <tgl@sss.pgh.pa.us> writes: >> At least on my FreeBSD 11 box, the current definition of >> $(with_temp_install) is not sufficient to ensure that the various .so >> files are loaded from tmp_install and not from the compiled rpath (which >> will be the final install dir, which may of course contain old >> libraries). >> LD_LIBRARY_PATH_RPATH=1 fixes this (by giving LD_LIBRARY_PATH priority >> over the DT_RPATH tag in the object). >> Is this also an issue on any other platforms? Tom> Hm. Can't reproduce that on current NetBSD or macOS; don't have Tom> OpenBSD booted up to try right now. Tom> However, if it helps on some platforms, I can't see much harm in Tom> adding it in the relevant places. It should be a no-op everywhere Tom> else. Oh, I see why it hasn't previously been an issue - the behavior varies according to whether both DT_RPATH and DT_RUNPATH, or just DT_RPATH, are defined in the program header; and when I build using default cc (clang), I get both tags (which makes LD_LIBRARY_PATH_RPATH unnecessary), whereas when I build using ports gcc using the recommended additional -Wl,-R option, for whatever reason that ends up setting only DT_RPATH. Confusing. Probably safest to add the env var anyway. -- Andrew (irc:RhodiumToad)
Andrew Gierth <andrew@tao11.riddles.org.uk> writes: > Is there some reason why ld_library_path_var is defined using a bunch of > $(if) constructs rather than putting the value (if not LD_LIBRARY_PATH) > in the individual port makefiles? I might be wrong, but I think that code is Peter's. I agree that having the per-port makefiles set it seems simpler (or maybe move it to the template files, and have the configure script define the variable?) However, does that help any with this requirement? If the core makefile logic becomes platform independent for this, then it's harder to see where to squeeze in an extra variable setting. regards, tom lane
>>>>> "Tom" == Tom Lane <tgl@sss.pgh.pa.us> writes: >> Is there some reason why ld_library_path_var is defined using a >> bunch of $(if) constructs rather than putting the value (if not >> LD_LIBRARY_PATH) in the individual port makefiles? Tom> I might be wrong, but I think that code is Peter's. I agree that Tom> having the per-port makefiles set it seems simpler (or maybe move Tom> it to the template files, and have the configure script define the Tom> variable?) Tom> However, does that help any with this requirement? No, it just happened to be adjacent. I'm basically thinking along these lines: diff --git a/src/Makefile.global.in b/src/Makefile.global.in index 6852853041..6e602dde48 100644 --- a/src/Makefile.global.in +++ b/src/Makefile.global.in @@ -413,13 +413,15 @@ $(1)="$(if $($(1)),$(2):$$$(1),$(2))" endef # platform-specific environment variable to set shared library path -define ld_library_path_var -$(if $(filter $(PORTNAME),darwin),DYLD_LIBRARY_PATH,$(if $(filter $(PORTNAME),aix),LIBPATH,$(if $(filter $(PORTNAME),hpux),SHLIB_PATH,LD_LIBRARY_PATH))) -endef - -define with_temp_install -PATH="$(abs_top_builddir)/tmp_install$(bindir):$$PATH" $(call add_to_path,$(ld_library_path_var),$(abs_top_builddir)/tmp_install$(libdir)) -endef +# individual ports can override this later, this is the default name +ld_library_path_var = LD_LIBRARY_PATH + +# with_temp_install_extra is for individual ports to define if they +# need something more here. If not defined then the call does nothing. +with_temp_install = \ + PATH="$(abs_top_builddir)/tmp_install$(bindir):$$PATH" \ + $(call add_to_path,$(strip $(ld_library_path_var)),$(abs_top_builddir)/tmp_install$(libdir)) \ + $(call with_temp_install_extra,$(abs_top_builddir)/tmp_install) ifeq ($(enable_tap_tests),yes) diff --git a/src/makefiles/Makefile.aix b/src/makefiles/Makefile.aix index 0f6c028938..ba3695dd57 100644 --- a/src/makefiles/Makefile.aix +++ b/src/makefiles/Makefile.aix @@ -23,6 +23,9 @@ else LDFLAGS_SL += -Wl,-bnoentry -Wl,-H512 -Wl,-bM:SRE endif +# env var name to use in place of LD_LIBRARY_PATH +ld_library_path_var = LIBPATH + POSTGRES_IMP= postgres.imp diff --git a/src/makefiles/Makefile.darwin b/src/makefiles/Makefile.darwin index e2b1d44959..b17598f058 100644 --- a/src/makefiles/Makefile.darwin +++ b/src/makefiles/Makefile.darwin @@ -2,6 +2,9 @@ AROPT = crs DLSUFFIX = .so +# env var name to use in place of LD_LIBRARY_PATH +ld_library_path_var = DYLD_LIBRARY_PATH + ifdef PGXS BE_DLLLIBS = -bundle_loader $(bindir)/postgres else diff --git a/src/makefiles/Makefile.freebsd b/src/makefiles/Makefile.freebsd index ce03c8dcd2..98a6f50615 100644 --- a/src/makefiles/Makefile.freebsd +++ b/src/makefiles/Makefile.freebsd @@ -9,6 +9,14 @@ DLSUFFIX = .so CFLAGS_SL = -fPIC -DPIC +# extra stuff for $(with_temp_install) +# we need this to get LD_LIBRARY_PATH searched ahead of the compiled-in +# rpath, if no DT_RUNPATH is present in the executable. The conditions +# under which DT_RUNPATH are added seem unpredictable, so be safe. + +define with_temp_install_extra +LD_LIBRARY_PATH_RPATH=1 +endef # Rule for building a shared library from a single .o file %.so: %.o diff --git a/src/makefiles/Makefile.hpux b/src/makefiles/Makefile.hpux index 30dd3eb77e..c871fb0c7e 100644 --- a/src/makefiles/Makefile.hpux +++ b/src/makefiles/Makefile.hpux @@ -36,6 +36,9 @@ else CFLAGS_SL = +Z endif +# env var name to use in place of LD_LIBRARY_PATH +ld_library_path_var = SHLIB_PATH + # Rule for building a shared library from a single .o file %$(DLSUFFIX): %.o ifeq ($(GCC), yes) -- Andrew (irc:RhodiumToad)