public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Aditya Kamath1 <Aditya.Kamath1@ibm.com>
To: Alan Modra <amodra@gmail.com>
Cc: Ulrich Weigand <Ulrich.Weigand@de.ibm.com>,
	Aditya Kamath1 via Gdb-patches <gdb-patches@sourceware.org>,
	Alan Modra <amodra@au1.ibm.com>,
	Sangamesh Mallayya <sangamesh.swamy@in.ibm.com>
Subject: RE: [Patch] Fix AIX shared library load broken during fork ().
Date: Mon, 10 Jul 2023 14:29:46 +0000	[thread overview]
Message-ID: <CH2PR15MB3544465145F0BFC7E7F9415DD630A@CH2PR15MB3544.namprd15.prod.outlook.com> (raw)
In-Reply-To: <ZKwRefHPfRLOg9kF@squeak.grove.modra.org>

[-- Attachment #1: Type: text/plain, Size: 6642 bytes --]

Hi Alan, Ulrich and community,

Thank you for the reply.

>As the comment in add_range says, you should be able to read the same
>element more than once due to _bfd_get_elf_at_filepos calling
>_bfd_look_for_bfd_in_cache, which caches elements by file position.

>So why isn't that working?

>Oh, I think I see the bug.  no_element_cache is set when reading the
>first element of an archive to figure out the proper target.  If
>no_element_cache is set then we can't call add_range.

>Can you try this patch?

So actually it does not work. Kindly check the output pasted below and the patch applied.

Kindly let me know what we can do next..

Thanks and regards,
Aditya.

bash-5.1$ ./gdb ~/gdb_tests/multi-thread-fork
GNU gdb (GDB) 14.0.50.20230602-git
Copyright (C) 2023 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later http://gnu.org/licenses/gpl.html
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Type "show copying" and "show warranty" for details.
This GDB was configured as "powerpc64-ibm-aix7.2.0.0".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
https://www.gnu.org/software/gdb/bugs/.
Find the GDB manual and other documentation resources online at:
    http://www.gnu.org/software/gdb/documentation/.

For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from /home/aditya/gdb_tests/multi-thread-fork...
(gdb) set detach-on-fork off
(gdb) r
Starting program: /home/aditya/gdb_tests/multi-thread-fork
[New Thread 258]
[New Thread 515]
[New inferior 2 (process 20054400)]
warning: "/usr/lib/libpthreads.a": member "shr_comm.o" missing.
warning: "/usr/lib/libpthread.a": member "shr_xpg5.o" missing.
warning: "/usr/lib/libc.a": member "shr.o" missing.
warning: Could not load shared library symbols for 3 libraries, e.g. /usr/lib/libpthreads.a(shr_comm.o).
Use the "info sharedlibrary" command to see the complete listing.
Do you need "set solib-search-path" or "set sysroot"?
I am parent
[New process 22282610]
[New inferior 3 (process 17564062)]
warning: "/usr/lib/libpthreads.a": member "shr_comm.o" missing.
warning: "/usr/lib/libpthread.a": member "shr_xpg5.o" missing.
warning: "/usr/lib/libc.a": member "shr.o" missing.
warning: Could not load shared library symbols for 3 libraries, e.g. /usr/lib/libpthreads.a(shr_comm.o).
Use the "info sharedlibrary" command to see the complete listing.
Do you need "set solib-search-path" or "set sysroot"?
I am parent

Thread 1.4 received signal SIGINT, Interrupt.
[Switching to process 22282610]
0xd0595fb0 in _p_nsleep () from /usr/lib/libpthread.a(shr_xpg5.o)
(gdb) inferior 2
[Switching to inferior 2 [process 20054400] (/home/aditya/gdb_tests/multi-thread-fork)]
[Switching to thread 2.1 (process 20054400)]
#0  0xd0594fc8 in ?? ()
(gdb) info sharedlibrary
From        To          Syms Read   Shared Object Library
                        No          /usr/lib/libpthreads.a(shr_comm.o)
0xd05bb240  0xd05bb9a1  Yes (*)     /usr/lib/libcrypt.a(shr.o)
                        No          /usr/lib/libpthread.a(shr_xpg5.o)
                        No          /usr/lib/libc.a(shr.o)
(*): Shared library is missing debugging information.
(gdb) q
A debugging session is active.

        Inferior 1 [process 22282610] will be killed.
        Inferior 2 [process 20054400] will be killed.
        Inferior 3 [process 17564062] will be killed.

Quit anyway? (y or n) y
bash-5.1$
bash-5.1$ diff -u ../bfd/coff-rs6000.c_orig ../bfd/coff-rs6000.c
--- ../bfd/coff-rs6000.c_orig   2023-07-10 09:20:47.209312912 +0000
+++ ../bfd/coff-rs6000.c        2023-07-10 09:25:54.078326997 +0000
@@ -1744,7 +1744,8 @@
   /* Skip over the XCOFFARFMAG at the end of the file name.  */
   if (bfd_seek (abfd, (namlen & 1) + SXCOFFARFMAG, SEEK_CUR) != 0
-      || !add_range (abfd, start, abfd->where + ret->parsed_size))
+     || (!abfd->no_element_cache
+     && !add_range (abfd, start, abfd->where + ret->parsed_size)))
     {
       free (ret);
       return NULL;

From: Alan Modra <amodra@gmail.com>
Date: Monday, 10 July 2023 at 7:41 PM
To: Aditya Kamath1 <Aditya.Kamath1@ibm.com>
Cc: Ulrich Weigand <Ulrich.Weigand@de.ibm.com>, Aditya Kamath1 via Gdb-patches <gdb-patches@sourceware.org>, Alan Modra <amodra@au1.ibm.com>, Sangamesh Mallayya <sangamesh.swamy@in.ibm.com>
Subject: [EXTERNAL] Re: [Patch] Fix AIX shared library load broken during fork ().
On Mon, Jul 10, 2023 at 11:35:09AM +0000, Aditya Kamath1 wrote:
> In the recent commit {https://sourceware.org/git/?p=binutils-gdb.git;a=commitdiff;h=de7b90610e9e939c49290229c282eb9171c560b9 } the committer mentions that he has added a add_range () function which now adds a start, end range which now guards anyone from calling or having two or more file pointer pointing to the same file in the archive. So, if this is the case, then we BFD goes to execute the following condition
> +  if (bfd_seek (abfd, (namlen & 1) + SXCOFFARFMAG, SEEK_CUR) != 0
> +      || !add_range (abfd, start, abfd->where + ret->parsed_size))
> +    {
> +      free (ret);
> +      return NULL;
> +    }
>
>
> We will satisy the add_range () part of the OR condition and free the ret variable and return NULL. Kindly note this happens in the coff-rs6000.c file in bfd directory.

As the comment in add_range says, you should be able to read the same
element more than once due to _bfd_get_elf_at_filepos calling
_bfd_look_for_bfd_in_cache, which caches elements by file position.

So why isn't that working?

Oh, I think I see the bug.  no_element_cache is set when reading the
first element of an archive to figure out the proper target.  If
no_element_cache is set then we can't call add_range.

Can you try this patch?

        * coff-rs6000.c (_bfd_xcoff_read_ar_hdr): Don't add_range when
        no_element_cache is set.

diff --git a/bfd/coff-rs6000.c b/bfd/coff-rs6000.c
index 271a24fff69..bb9604b0780 100644
--- a/bfd/coff-rs6000.c
+++ b/bfd/coff-rs6000.c
@@ -1744,7 +1744,8 @@ _bfd_xcoff_read_ar_hdr (bfd *abfd)

   /* Skip over the XCOFFARFMAG at the end of the file name.  */
   if (bfd_seek (abfd, (namlen & 1) + SXCOFFARFMAG, SEEK_CUR) != 0
-      || !add_range (abfd, start, abfd->where + ret->parsed_size))
+      || (!abfd->no_element_cache
+         && !add_range (abfd, start, abfd->where + ret->parsed_size)))
     {
       free (ret);
       return NULL;


--
Alan Modra
Australia Development Lab, IBM

  reply	other threads:[~2023-07-10 14:29 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-07-10 11:35 Aditya Kamath1
2023-07-10 14:11 ` Alan Modra
2023-07-10 14:29   ` Aditya Kamath1 [this message]
2023-07-10 15:04     ` Alan Modra
2023-07-10 16:00 ` Tom Tromey
2023-07-10 23:17   ` Alan Modra
2023-07-11  5:08     ` Aditya Kamath1

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CH2PR15MB3544465145F0BFC7E7F9415DD630A@CH2PR15MB3544.namprd15.prod.outlook.com \
    --to=aditya.kamath1@ibm.com \
    --cc=Ulrich.Weigand@de.ibm.com \
    --cc=amodra@au1.ibm.com \
    --cc=amodra@gmail.com \
    --cc=gdb-patches@sourceware.org \
    --cc=sangamesh.swamy@in.ibm.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).