e25bc11
2011-04-04  Jakub Jelinek  <jakub@redhat.com>
e25bc11
595f09c
	* toplev.cc (toplev_main_argv): New variable.
e25bc11
	(toplev_main): Initialize it.
146fdc1
	* graphite.cc (init_isl_pointers): Load libisl.so.23 from gcc's private
e25bc11
	directory.
e25bc11
595f09c
--- gcc/toplev.cc.jj	2008-12-09 23:59:10.000000000 +0100
595f09c
+++ gcc/toplev.cc	2009-01-27 14:33:52.000000000 +0100
cdf9229
@@ -113,6 +113,8 @@ static void finalize (bool);
cdf9229
 static void crash_signal (int) ATTRIBUTE_NORETURN;
cdf9229
 static void compile_file (void);
e25bc11
 
e25bc11
+const char **toplev_main_argv;
e25bc11
+
e25bc11
 /* Decoded options, and number of such options.  */
e25bc11
 struct cl_decoded_option *save_decoded_options;
e25bc11
 unsigned int save_decoded_options_count;
cdf9229
@@ -2239,6 +2241,8 @@ toplev::main (int argc, char **argv)
e25bc11
 
e25bc11
   expandargv (&argc, &argv);
e25bc11
 
e25bc11
+  toplev_main_argv = CONST_CAST2 (const char **, char **, argv);
e25bc11
+
e25bc11
   /* Initialization of GCC's environment, and diagnostics.  */
e25bc11
   general_init (argv[0], m_init_signals);
e25bc11
 
595f09c
--- gcc/graphite.cc.jj	2010-12-01 10:24:32.000000000 -0500
595f09c
+++ gcc/graphite.cc	2010-12-01 11:46:07.832118193 -0500
e25bc11
@@ -64,11 +64,39 @@ __typeof (isl_pointers__) isl_pointers__
e25bc11
 static bool
e25bc11
 init_isl_pointers (void)
e25bc11
 {
e25bc11
-  void *h;
e25bc11
+  void *h = NULL;
e25bc11
+  extern const char **toplev_main_argv;
e25bc11
+  char *buf, *p;
e25bc11
+  size_t len;
e25bc11
 
e25bc11
   if (isl_pointers__.inited)
e25bc11
     return isl_pointers__.h != NULL;
146fdc1
-  h = dlopen ("libisl.so.23", RTLD_LAZY);
e25bc11
+  len = progname - toplev_main_argv[0];
146fdc1
+  buf = XALLOCAVAR (char, len + sizeof "libisl.so.23");
e25bc11
+  memcpy (buf, toplev_main_argv[0], len);
146fdc1
+  strcpy (buf + len, "libisl.so.23");
146fdc1
+  len += sizeof "libisl.so.23";
e25bc11
+  p = strstr (buf, "/libexec/");
e25bc11
+  if (p != NULL)
e25bc11
+    {
e25bc11
+      while (1)
e25bc11
+	{
e25bc11
+	  char *q = strstr (p + 8, "/libexec/");
e25bc11
+	  if (q == NULL)
e25bc11
+	    break;
e25bc11
+	  p = q;
e25bc11
+	}
e25bc11
+      memmove (p + 4, p + 8, len - (p + 8 - buf));
e25bc11
+      h = dlopen (buf, RTLD_LAZY);
e25bc11
+      if (h == NULL)
e25bc11
+	{
e25bc11
+	  len = progname - toplev_main_argv[0];
e25bc11
+	  memcpy (buf, toplev_main_argv[0], len);
146fdc1
+	  strcpy (buf + len, "libisl.so.23");
e25bc11
+	}
e25bc11
+    }
e25bc11
+  if (h == NULL)
e25bc11
+    h = dlopen (buf, RTLD_LAZY);
e25bc11
   isl_pointers__.h = h;
e25bc11
   if (h == NULL)
e25bc11
     return false;