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