[vmkit-commits] [PATCH] Fix symbol search order to fix detection of symbols from vmkit or loaded libs

Will Dietz wdietz2 at illinois.edu
Tue Nov 15 12:13:45 PST 2011


Inlined below.

As described in the commit message, the existing way incorrectly sets
the 'j3' on symbols from loaded libraries, resulting in much badness
when we don't invoke them properly in nativeCompile().

I'm unsure if this was a bug on Mac, but regardless the reordering
should work correctly on both.

~Will

>From 6f485d65e595a1ecd90e4e90a8bbc12b481561bc Mon Sep 17 00:00:00 2001
From: Will Dietz <w at wdtz.org>
Date: Mon, 14 Nov 2011 09:45:35 -0600
Subject: [PATCH 2/2] Fix symbol search order to fix detection of symbols from
 vmkit or loaded libs

dlsym(NULL, *) in linux, for example, will not only search the vmkit process,
  but also all libraries we've opened.  This makes the setting of the 'j3' flag
  incorrect, and this is fixed by a simple reordering.
---
 lib/J3/VMCore/JnjvmClassLoader.cpp |   30 +++++++++++++++++-------------
 1 files changed, 17 insertions(+), 13 deletions(-)

diff --git a/lib/J3/VMCore/JnjvmClassLoader.cpp
b/lib/J3/VMCore/JnjvmClassLoader.cpp
index bf825a8..df206bb 100644
--- a/lib/J3/VMCore/JnjvmClassLoader.cpp
+++ b/lib/J3/VMCore/JnjvmClassLoader.cpp
@@ -977,22 +977,26 @@ const UTF8*
JnjvmClassLoader::constructArrayName(uint32 steps,
 }

 word_t JnjvmClassLoader::loadInLib(const char* buf, bool& j3) {
-  word_t res =
(word_t)TheCompiler->loadMethod(mvm::System::GetSelfHandle(), buf);
-
-  if (!res) {
-    for (std::vector<void*>::iterator i = nativeLibs.begin(),
-              e = nativeLibs.end(); i!= e; ++i) {
-      res = (word_t)TheCompiler->loadMethod((*i), buf);
-      if (res) break;
-    }
-  } else {
+  word_t res;
+
+  // Search loaded libraries first
+  for (std::vector<void*>::iterator i = nativeLibs.begin(),
+      e = nativeLibs.end(); i!= e; ++i) {
+    res = (word_t)TheCompiler->loadMethod((*i), buf);
+    if (res) return res;
+  }
+
+  // Check 'self'
+  res = (word_t)TheCompiler->loadMethod(mvm::System::GetSelfHandle(), buf);
+  if (res) {
     j3 = true;
+    return res;
   }
-
-  if (!res && this != bootstrapLoader)
-    res = bootstrapLoader->loadInLib(buf, j3);

-  return (word_t)res;
+  if (this != bootstrapLoader)
+    return bootstrapLoader->loadInLib(buf, j3);
+
+  return 0;
 }

 void* JnjvmClassLoader::loadLib(const char* buf) {
-- 
1.7.5.1



More information about the vmkit-commits mailing list