Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Handle @executable_path for dlopen

  • Loading branch information...
commit 45906e0f9d2a2e2bdd1091bfecb1217e67d701c3 1 parent dc64505
Shinichiro Hamaji authored November 13, 2011

Showing 1 changed file with 19 additions and 2 deletions. Show diff stats Hide diff stats

  1. 21  ld-mac.cc
21  ld-mac.cc
@@ -225,6 +225,23 @@ static void dumpInt(int bound_name_id) {
225 225
   fflush(stdout);
226 226
 }
227 227
 
  228
+static MachO* loadDylib(string dylib) {
  229
+  static const char executable_str[] = "@executable_path";
  230
+  static const size_t executable_str_len = strlen(executable_str);
  231
+  if (!strncmp(dylib.c_str(), executable_str, executable_str_len)) {
  232
+    string dir = g_darwin_executable_path;
  233
+    size_t found = dir.rfind('/');
  234
+    if (found == string::npos) {
  235
+      dir = ".";
  236
+    } else {
  237
+      dir = dir.substr(0, found);
  238
+    }
  239
+    dylib.replace(0, executable_str_len, dir);
  240
+  }
  241
+
  242
+  return MachO::read(dylib.c_str(), ARCH_NAME);
  243
+}
  244
+
228 245
 typedef unordered_map<string, MachO::Export> Exports;
229 246
 
230 247
 class MachOLoader {
@@ -473,7 +490,7 @@ class MachOLoader {
473 490
         dylib.replace(0, executable_str_len, dir);
474 491
       }
475 492
 
476  
-      auto_ptr<MachO> dylib_mach(MachO::read(dylib.c_str(), ARCH_NAME));
  493
+      auto_ptr<MachO> dylib_mach(loadDylib(dylib.c_str()));
477 494
       load(*dylib_mach);
478 495
     }
479 496
   }
@@ -928,7 +945,7 @@ static void* ld_mac_dlopen(const char* filename, int flag) {
928 945
   timer.start();
929 946
 
930 947
   // TODO(hamaji): Handle failures.
931  
-  auto_ptr<MachO> dylib_mach(MachO::read(filename, ARCH_NAME));
  948
+  auto_ptr<MachO> dylib_mach(loadDylib(filename));
932 949
 
933 950
   MachOLoader* loader = g_loader;
934 951
   CHECK(loader);

0 notes on commit 45906e0

Please sign in to comment.
Something went wrong with that request. Please try again.