[haiku-commits] Re: haiku: hrev46152 - in src: kits/package/solver build/libpackage/solver build/libpackage

  • From: Ingo Weinhold <ingo_weinhold@xxxxxx>
  • To: haiku-commits@xxxxxxxxxxxxx
  • Date: Tue, 01 Oct 2013 05:58:52 +0200

On 10/01/2013 03:59 AM, revol@xxxxxxx wrote:
8bf87f9: Actually fix the build

   Looks like I was too quick on previous commit.

Interestingly that didn't appear on the mailing list, nor was it tagged. :-/

   It seems -pthread is actually not that much needed on Linux though...
   although the manpage says "compile and link with -pthread". Go figure.

   Now dlopen() uses RTLD_LAZY | RTLD_LOCAL for Linux, which seems
   to work here.

                                           [ François Revol <revol@xxxxxxx> ]

----------------------------------------------------------------------------

Revision:    hrev46152
Commit:      8bf87f93417aa5ea697a68e409ebea80569bf294
URL:         http://cgit.haiku-os.org/haiku/commit/?id=8bf87f9
Author:      François Revol <revol@xxxxxxx>
Date:        Tue Oct  1 01:57:24 2013 UTC

----------------------------------------------------------------------------

3 files changed, 7 insertions(+), 4 deletions(-)
src/build/libpackage/Jamfile        | 1 +
src/build/libpackage/solver/Jamfile | 2 --
src/kits/package/solver/Solver.cpp  | 8 ++++++--

----------------------------------------------------------------------------

diff --git a/src/build/libpackage/Jamfile b/src/build/libpackage/Jamfile
index 1d35d4c..464f406 100644
--- a/src/build/libpackage/Jamfile
+++ b/src/build/libpackage/Jamfile
@@ -9,6 +9,7 @@ SEARCH_SOURCE += [ FDirName $(HAIKU_TOP) src kits package 
manager ] ;
  SEARCH_SOURCE += [ FDirName $(HAIKU_TOP) src kits package solver ] ;

  USES_BE_API on libpackage_build.so = true ;
+LINKFLAGS on libpackage_build.so += $(HOST_PTHREAD_LINKFLAGS) ;

This is not The Way (tm). There are already three ways for this kind of problem:

1. Add the library to HOST_LINKFLAGS. This is e.g. done for "-lm".
2. Add it to HOST[_STATIC]_LIBROOT. This is e.g. done for "/usr/lib/libgnuregex.so" (FreeBSD). 3. Introduce a new variable with the libraries and add it explicitly to the library list of rule invocations that build the applications/libraries. This is done for HOST_NETWORK_LIBS.

Well, 3. is actually like 2., just for a different (Haiku) library. The pthread functionality is in libroot, so either 1. or 2. should be used. HOST_LIBROOT is used automatically when USES_BE_API is set on the target in question, so the variable should only contain stuff that explicitly contributes to BeOS/Haiku specific libroot functionality. That does make the use for "/usr/lib/libgnuregex.so" kind of incorrect, I guess. That leaves HOST_LINKFLAGS for POSIX/BSD stuff that is linked automatically in Haiku (usually by virtue of being in libroot).

[...]
diff --git a/src/kits/package/solver/Solver.cpp 
b/src/kits/package/solver/Solver.cpp
index 7f5c630..53bb31b 100644
--- a/src/kits/package/solver/Solver.cpp
+++ b/src/kits/package/solver/Solver.cpp
@@ -25,10 +25,14 @@ static pthread_once_t sLoadLibsolvSolverAddOnInitOnce = 
PTHREAD_ONCE_INIT;
  static void
  load_libsolv_solver_add_on()
  {
+       int flags = 0;
  #ifdef HAIKU_TARGET_PLATFORM_HAIKU
-       void* imageHandle = dlopen("libpackage-add-on-libsolv.so", 0);
+       void* imageHandle = dlopen("libpackage-add-on-libsolv.so", flags);
  #else
-       void* imageHandle = dlopen("libpackage-add-on-libsolv_build.so", 0);
+#ifdef HAIKU_HOST_PLATFORM_LINUX
+       flags = RTLD_LAZY | RTLD_LOCAL;
+#endif
+       void* imageHandle = dlopen("libpackage-add-on-libsolv_build.so", flags);
  #endif
        if (imageHandle == NULL)
                return;

Besides that flags in not really used in the Haiku case, this is unnecessarily complicated. According to the specs for dlopen():

"The mode parameter ... may have the following values: RTLD_LAZY ... RTLD_NOW"

And:

To determine the scope of visibility for the symbols loaded with a dlopen() invocation, the mode parameter should be a bitwise-inclusive OR with one of the following values: RTLD_GLOBAL ... RTLD_LOCAL ...

If neither RTLD_GLOBAL nor RTLD_LOCAL is specified, the default behavior is unspecified."

So, while RTLD_GLOBAL/RTLD_LOCAL can probably be omitted, one of RTLD_LAZY/RTLD_NOW is required. At any event, the safest option is to always specify "RTLD_LAZY | RTLD_LOCAL".

CU, Ingo


Other related posts: