From b55c66e8ab3ed004043c54101aae8935ca7471eb Mon Sep 17 00:00:00 2001 From: Ulrich Sibiller Date: Sat, 28 Sep 2019 21:32:07 +0200 Subject: nxagent/Imakefile: remove ../../exports/lib MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit nxagent links system libraries that link against libX11. Unfortunately, nxagent (and libXcompshad) require a modified libX11 version, nicknamed libNX_X11, for proper functioning. Fortunately, this one can act as a drop-in replacement for the system libX11. So we’ll hack our way out: add a DT_NEEDED entry for libX11 by linking against the system library when building nxagent and link the other system libraries later and set DT_RUNPATH to a special directory containing symlinks from libNX_X11 to libX11. This tricks the loader into pulling in the "fake" libX11 version without checking its SONAME and thus satisfying the DT_NEEDED entry early on - specifically also for the system libraries. Ex.: readelf -a /usr/bin/nxagent | grep NEEDED 0x0000000000000001 (NEEDED) Shared library: [libX11.so.6] ... 0x0000000000000001 (NEEDED) Shared library: [libNX_X11.so.6] ... If, however, you run the build a second time, it will find the newly created libX11 links in ../../exports/lib (used as an additional library search path) instead of the system libX11. The results in a binary looking like this: 0x0000000000000001 (NEEDED) Shared library: [libNX_X11.so.6] ... With such a setup, the whole magic falls apart and system libraries will suddenly pull in the actual system libX11 file. We initially believed a compiler call such as: ${CC} [--unrelated-options ...] [-Lunrelated_library_path ...] -lX11 [more options like -l and -L] -L../../exports/lib -lother_libraries to do "the right thing" and link against the system libX11 (or, at worst, a libX11 found in the library directory search list preceding the link call) and use ../../exports/lib only for later linking operations, since the order of options matters. However, this turned out to be blatantly wrong: while the order of -L arguments does matter for building the search path, the whole search path including elements from *ALL* -L arguments (and the system paths) will always be used when linking libraries. Hence, (counter-intuitively to us) both these calls will be equivalent: ${CC} [--unrelated-options ...] -la -Loverride_liba -lb [-Lunrelated_library_path ...] -lc ${CC} [--unrelated-options ...] -Loverride_liba [-Lunrelated_library_path ...] -la -lb -lc By removing LDPRELIBS from NXAGENTSYSLIBS, ../../exports/lib is no longer used during building/linking and the binaries are built reproducibly. We never intended to use this directory at link time anyway. --- nx-X11/programs/Xserver/Imakefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'nx-X11/programs/Xserver/Imakefile') diff --git a/nx-X11/programs/Xserver/Imakefile b/nx-X11/programs/Xserver/Imakefile index db2f0d7a5..cd81c650b 100644 --- a/nx-X11/programs/Xserver/Imakefile +++ b/nx-X11/programs/Xserver/Imakefile @@ -304,7 +304,7 @@ TIRPC_LIB = $$(pkg-config --libs 'libtirpc') NXAGENT = hw/nxagent/LibraryTargetName(nxagent) NXCOMPEXT = hw/nxagent/compext/LibraryTargetName(compext) NXAGENTLIBS = PreFbLibs $(NXAGENT) FbPostFbLibs $(NXCOMPEXT) $(NXAGENT) $(MI) -NXAGENTSYSLIBS = $(LDPRELIBS) $(XLIB) $(SYSLIBS) $(XPMLIB) $(XMLLIB) $(PIXMANLIB) $(TIRPC_LIB) +NXAGENTSYSLIBS = $(XLIB) $(SYSLIBS) $(XPMLIB) $(XMLLIB) $(PIXMANLIB) $(TIRPC_LIB) NXCOMPEXTSYSLIBS = $(ZLIB) $(PNGLIB) $(JPEGLIB) #if HasParallelMake MakeMutex($(NXAGENTDIRS) $(NXCOMPEXT) $(NXAGENTOBJS) $(NXAGENTLIBS) $(NXCOMPEXTSYSLIBS) $(NXAGENTSYSLIBS)) -- cgit v1.2.3