From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 130445 invoked by alias); 10 Oct 2016 12:11:44 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Received: (qmail 130433 invoked by uid 89); 10 Oct 2016 12:11:43 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.6 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_LOW,SPF_PASS autolearn=ham version=3.3.2 spammy=displaying, Reserve, 7478, H*x:Release X-HELO: mx0a-001b2d01.pphosted.com Received: from mx0a-001b2d01.pphosted.com (HELO mx0a-001b2d01.pphosted.com) (148.163.156.1) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Mon, 10 Oct 2016 12:11:41 +0000 Received: from pps.filterd (m0098409.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.17/8.16.0.17) with SMTP id u9AC91Wd066173 for ; Mon, 10 Oct 2016 08:11:40 -0400 Received: from e28smtp07.in.ibm.com (e28smtp07.in.ibm.com [125.16.236.7]) by mx0a-001b2d01.pphosted.com with ESMTP id 26063058b6-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Mon, 10 Oct 2016 08:11:40 -0400 Received: from localhost by e28smtp07.in.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Mon, 10 Oct 2016 17:41:36 +0530 Received: from d28dlp02.in.ibm.com (9.184.220.127) by e28smtp07.in.ibm.com (192.168.1.137) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Mon, 10 Oct 2016 17:41:34 +0530 X-IBM-Helo: d28dlp02.in.ibm.com X-IBM-MailFrom: sangamesh.swamy@in.ibm.com X-IBM-RcptTo: gdb-patches@sourceware.org Received: from d28relay09.in.ibm.com (d28relay09.in.ibm.com [9.184.220.160]) by d28dlp02.in.ibm.com (Postfix) with ESMTP id 326B0394004E for ; Mon, 10 Oct 2016 17:41:34 +0530 (IST) Received: from d50lp01.ny.us.ibm.com ([146.89.104.207]) by d28relay09.in.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id u9ACBWXY30933022 for ; Mon, 10 Oct 2016 17:41:33 +0530 Received: from localhost by d50lp01.ny.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Mon, 10 Oct 2016 08:11:31 -0400 Received: from smtp.notes.na.collabserv.com (192.155.248.73) by d50lp01.ny.us.ibm.com (158.87.18.20) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; (version=TLSv1/SSLv3 cipher=AES128-SHA bits=128/128) Mon, 10 Oct 2016 08:11:27 -0400 Received: from localhost by smtp.notes.na.collabserv.com with smtp.notes.na.collabserv.com ESMTP for from ; Mon, 10 Oct 2016 12:11:26 -0000 Received: from us1a3-smtp02.a3.dal06.isc4sb.com (10.106.154.159) by smtp.notes.na.collabserv.com (10.106.227.90) with smtp.notes.na.collabserv.com ESMTP; Mon, 10 Oct 2016 12:11:23 -0000 Received: from us1a3-mail142.a3.dal06.isc4sb.com ([10.146.38.78]) by us1a3-smtp02.a3.dal06.isc4sb.com with ESMTP id 2016101012112265-358707 ; Mon, 10 Oct 2016 12:11:22 +0000 In-Reply-To: <20161008143755.10ABE10BEE3@oc8523832656.ibm.com> To: "Ulrich Weigand" Cc: gdb-patches@sourceware.org Subject: Re: set sysroot command on AIX has no effect. From: "Sangamesh Mallayya" Date: Mon, 10 Oct 2016 12:11:00 -0000 References: from "Sangamesh Mallayya" at Oct 08, 2016 06:44:40 PM <20161008143755.10ABE10BEE3@oc8523832656.ibm.com> MIME-Version: 1.0 X-KeepSent: 715ED758:00DC97FD-65258048:00413E8B; type=4; name=$KeepSent X-LLNOutbound: False X-Disclaimed: 1491 X-TNEFEvaluated: 1 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="US-ASCII" x-cbid: 16101012-0052-0000-0000-0000031AABCE X-IBM-ISS-SpamDetectors: Score=0.40962; BY=0; FL=0; FP=0; FZ=0; HX=0; KW=0; PH=0; SC=0.40962; ST=0; TS=0; UL=0; ISC= X-IBM-ISS-DetailInfo: BY=3.00005886; HX=3.00000240; KW=3.00000007; PH=3.00000004; SC=3.00000186; SDB=6.00766435; UDB=6.00366579; UTC=2016-10-10 12:11:24 x-cbparentid: 16101012-3108-0000-0000-000001569626 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused X-Content-Scanned: Fidelis XPS MAILER X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused Message-Id: X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:,, definitions=2016-10-10_07:,, signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 suspectscore=0 malwarescore=0 phishscore=0 adultscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1609300000 definitions=main-1610100205 X-SW-Source: 2016-10/txt/msg00216.txt.bz2 Hi Ulrich, > Sangamesh Mallayya wrote: >=20 > >> Well, of course, you have to check for NULL. What I'm suggesting is=20 to > >> use something along the lines of: > >>=20 > >> found_pathname =3D solib_find (filename, &found_file); > >> if (found_pathname =3D=3D NULL) > >> // error handling > >> archive_bfd =3D solib_bfd_fopen (found_pathname, found_file); > > > >Yes, i did try these steps. But this won't set the sysroot path as we=20 > >intend to. > >The final object filename we want is the one returned from solib_find,=20 > >which is a sysroot prefixed pathname. > >After solib_bfd_fopen call we can't refer to found_pathname as it's=20 been=20 > >freed in solib_bfd_fopen at the end, and assertion failure later. >=20 > 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). >=20 > >> > + pathname =3D solib_find (filename, &found_file); > >> > + if (pathname =3D=3D NULL) > >> > + perror_with_name (filename); > >> > archive_bfd =3D gdb_bfd_open (filename, gnutarget, -1); > >> > if (archive_bfd =3D=3D NULL) > >> > { > >>=20 > >> This has a number of problems: > >> - you still use gdb_bfd_open with filename, which means it still=20 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=20 > >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=20 > >from actual file and gdb_bfd_open does find the file and return it's=20 bfd. > >Here if we pass the path returned from solib_find to gdb_bfd_open=20 instead=20 > >of filename then no issue is seen. >=20 > 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". >=20 > >I think, better we use found_pathname variable to store returned value=20 > >from solib_find instead of using existing pathname variable to avoid=20 > >confusion. > >And may assign object filename as "object_bfd->filename =3D xstrdup=20 > >(found_pathname);" ? >=20 > 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) >=20 > 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. >=20 > >The only problem i think if we use solib_find without using=20 > >solib_bfd_fopen is found_file descriptor. > >Let me know your view. >=20 > 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; =20 if (pathname[path_len - 1] !=3D ')') return solib_bfd_open (pathname); @@ -669,12 +671,24 @@ member_name =3D xstrprintf ("%.*s", path_len - filename_len - 2, sep += =20 1); make_cleanup (xfree, member_name); =20 - archive_bfd =3D 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 =3D solib_find (filename, &found_file); + if (found_pathname =3D=3D NULL) + perror_with_name (pathname); + found_pathname1 =3D xstrdup (found_pathname); + found_path_len =3D strlen (found_pathname1) + strlen (sep); + /* Reserve a space for appending parenthesized member name to=20 filename, + as path returned from solib_find is just a filename */ + found_pathname1 =3D xrealloc (found_pathname1, found_path_len); + archive_bfd =3D solib_bfd_fopen (found_pathname, found_file); if (archive_bfd =3D=3D 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; } =20 @@ -681,6 +695,7 @@ if (bfd_check_format (archive_bfd, bfd_object)) { do_cleanups (cleanup); + xfree (found_pathname1); return archive_bfd; } =20 @@ -690,6 +705,7 @@ filename, bfd_errmsg (bfd_get_error ())); gdb_bfd_unref (archive_bfd); do_cleanups (cleanup); + xfree (found_pathname1); return NULL; } =20 @@ -711,6 +727,7 @@ warning (_("\"%s\": member \"%s\" missing."), filename,=20 member_name); gdb_bfd_unref (archive_bfd); do_cleanups (cleanup); + xfree (found_pathname1); return NULL; } =20 @@ -721,6 +738,7 @@ gdb_bfd_unref (archive_bfd); gdb_bfd_unref (object_bfd); do_cleanups (cleanup); + xfree (found_pathname1); return NULL; } =20 @@ -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 =3D xstrdup (pathname); + strcat (found_pathname1, sep); + object_bfd->filename =3D found_pathname1; =20 gdb_bfd_unref (archive_bfd); do_cleanups (cleanup);