set sysroot command on AIX has no effect.

Sangamesh Mallayya sangamesh.swamy@in.ibm.com
Mon Oct 10 12:11:00 GMT 2016


Hi Ulrich,

> Sangamesh Mallayya wrote:
> 
> >> Well, of course, you have to check for NULL.  What I'm suggesting is 
to
> >> use something along the lines of:
> >> 
> >>   found_pathname = solib_find (filename, &found_file);
> >>   if (found_pathname == NULL)
> >>     // error handling
> >>   archive_bfd = solib_bfd_fopen (found_pathname, found_file);
> >
> >Yes, i did try these steps. But this won't set the sysroot path as we 
> >intend to.
> >The final object filename we want is the one returned from solib_find, 
> >which is a sysroot prefixed pathname.
> >After solib_bfd_fopen call we can't refer to found_pathname as it's 
been 
> >freed in solib_bfd_fopen at the end, and assertion failure later.
> 
> Well, if you want to reuse the found_pathname, you'll just have to
> duplicate it (there's already a call to xstrdup later in the function,
> you may have to move it earlier).
> 
> >> > +   pathname = solib_find (filename, &found_file);
> >> > +   if (pathname == NULL)
> >> > +       perror_with_name (filename);
> >> >     archive_bfd = gdb_bfd_open (filename, gnutarget, -1);
> >> >     if (archive_bfd == NULL)
> >> >       {
> >> 
> >> This has a number of problems:
> >> - you still use gdb_bfd_open with filename, which means it still 
won't
> >>   find the file  (I assume you meant to use pathname?)
> >
> >pathname we get is something like "/usr/lib/libc.a(shr.o)", Offcourse 
> >their is no such file with this pathname in the system.
> >So we set a filename as "/usr/lib/libc.a" after separating member name 
> >from actual file and gdb_bfd_open does find the file and return it's 
bfd.
> >Here if we pass the path returned from solib_find to gdb_bfd_open 
instead 
> >of filename then no issue is seen.
> 
> My point was, the code as shown above does *not* pass the path returned
> from solib_find to gdb_bfd_open!  The path returned from solib_find is
> assigned to "pathname" (overriding the value pathname that was input to
> the function), but then gdb_bfd_open is still called with "filename".
> 
> >I think, better we use found_pathname variable to store returned value 
> >from solib_find instead of using existing pathname variable to avoid 
> >confusion.
> >And may assign object filename as "object_bfd->filename = xstrdup 
> >(found_pathname);" ?
> 
> Agreed (see above).  However, note that this will *not* contain the
> object name in parentheses.  For example, if you initially get a
> pathname of:
>   /usr/lib/libc.a(shr.o)
> Then you separate out the filename into:
>   /usr/lib/libc.a
> Then you pass this to solib_find and get a full name including sysroot:
>   /path/to/sysroot/usr/lib/libc.a
> But what you probably want to use as name in the final solib object is:
>   /path/to/sysroot/usr/lib/libc.a(shr.o)
> 
> My point was that in order to get this, you'll have to append the
> "(shr.o)" back on to the result you got from solib_find.
> 
> >The only problem i think if we use solib_find without using 
> >solib_bfd_fopen is found_file descriptor.
> >Let me know your view.
> 
> Please do use the pair of solib_find / solib_bfd_fopen; they were
> designed to be used with each other, that's why they have the
> interface they do.

Thanks a lot for the detailed explanation and guidance.

Here is the change i have it right now which takes care of.

1) calling solib_find and then solib_bfd_fopen.
2) Appending parenthesized member name.

Let me know your view on this.

--- ./gdb/solib-aix.c_orig      2016-10-04 03:22:01.000000000 -0500
+++ ./gdb/solib-aix.c   2016-10-10 06:23:32.000000000 -0500
@@ -648,6 +648,8 @@
    char *member_name;
    bfd *archive_bfd, *object_bfd;
    struct cleanup *cleanup;
+   int found_file, found_path_len;
+   char *found_pathname, *found_pathname1;
 
    if (pathname[path_len - 1] != ')')
      return solib_bfd_open (pathname);
@@ -669,12 +671,24 @@
    member_name = xstrprintf ("%.*s", path_len - filename_len - 2, sep + 
1);
    make_cleanup (xfree, member_name);
 
-   archive_bfd = gdb_bfd_open (filename, gnutarget, -1);
+   /* Calling solib_find makes certain that sysroot path is set properly
+      if program has a dependency on .a archive and sysroot is set via
+      set sysroot command */
+   found_pathname = solib_find (filename, &found_file);
+   if (found_pathname == NULL)
+       perror_with_name (pathname);
+   found_pathname1 = xstrdup (found_pathname);
+   found_path_len = strlen (found_pathname1) + strlen (sep);
+   /* Reserve a space for appending parenthesized member name to 
filename,
+      as path returned from solib_find is just a filename */
+   found_pathname1 = xrealloc (found_pathname1, found_path_len);
+   archive_bfd = solib_bfd_fopen (found_pathname, found_file);
    if (archive_bfd == NULL)
      {
        warning (_("Could not open `%s' as an executable file: %s"),
               filename, bfd_errmsg (bfd_get_error ()));
        do_cleanups (cleanup);
+       xfree (found_pathname1);
        return NULL;
      }
 
@@ -681,6 +695,7 @@
    if (bfd_check_format (archive_bfd, bfd_object))
      {
        do_cleanups (cleanup);
+       xfree (found_pathname1);
        return archive_bfd;
      }
 
@@ -690,6 +705,7 @@
               filename, bfd_errmsg (bfd_get_error ()));
        gdb_bfd_unref (archive_bfd);
        do_cleanups (cleanup);
+       xfree (found_pathname1);
        return NULL;
      }
 
@@ -711,6 +727,7 @@
        warning (_("\"%s\": member \"%s\" missing."), filename, 
member_name);
        gdb_bfd_unref (archive_bfd);
        do_cleanups (cleanup);
+       xfree (found_pathname1);
        return NULL;
      }
 
@@ -721,6 +738,7 @@
        gdb_bfd_unref (archive_bfd);
        gdb_bfd_unref (object_bfd);
        do_cleanups (cleanup);
+       xfree (found_pathname1);
        return NULL;
      }
 
@@ -729,7 +747,8 @@
       synthetic name.  Otherwise, we would only be displaying the name
       of the archive member object.  */
    xfree (bfd_get_filename (object_bfd));
-   object_bfd->filename = xstrdup (pathname);
+   strcat (found_pathname1, sep);
+   object_bfd->filename = found_pathname1;
 
    gdb_bfd_unref (archive_bfd);
    do_cleanups (cleanup);



More information about the Gdb-patches mailing list