* [Patch v2] Handle .TOC. sections during gdb-compile for rs6000 target.
@ 2021-07-28 19:08 will schmidt
2021-07-29 7:18 ` Ulrich Weigand
0 siblings, 1 reply; 5+ messages in thread
From: will schmidt @ 2021-07-28 19:08 UTC (permalink / raw)
To: gdb-patches; +Cc: Alan Modra, Ulrich Weigand, rogerio, Carl E. Love
[gdb] Handle .TOC. sections during gdb-compile for rs6000 target.
Hi,
[V2] Multiple changes and cleanups per feedback. Added logic
to iterate through the sections to find one with SEC_ALLOC flags
set to serve as a substitite for an absent .toc section.
This was/is exercised with the test suite running in a power9 LE
environment. Per that testing, I don't believe I've got a case
where we had to resort as far as using the bfd_abs_section_ptr
as a fallback, so additional scrutiny may be required for that
portion of this patch.
[V1, updated]
When we encounter a .TOC. symbol in the object we are loading,
we need to associate this with the .toc section in order to
properly resolve other symbols in the object. IF a .toc section
is not found, iterate the sections until we find one with the
SEC_ALLOC flag. If that also fails, fall back to using
bfd_abs_section_ptr.
This is part of a short series of patches that allows gdb-compile
support to function for the ppc64le target.
OK for trunk?
Thanks
-Will
gdb/Changelog:
yyyy-mm-dd Will Schmidt <will_schmidt@vnet.ibm.com>
* gdb/compile/compile-object-load.c (compile_object_load):
Add handling for the .TOC. symbol.
diff --git a/gdb/compile/compile-object-load.c b/gdb/compile/compile-object-load.c
index 1c512801bcd..70742bf9b8e 100644
--- a/gdb/compile/compile-object-load.c
+++ b/gdb/compile/compile-object-load.c
@@ -720,10 +720,52 @@ compile_object_load (const compile_file_names &file_names,
need for _GLOBAL_OFFSET_TABLE_. Together with -fPIE the data
remain PC-relative even with _GLOBAL_OFFSET_TABLE_ as zero. */
sym->value = 0;
continue;
}
+ if (strcmp (sym->name, ".TOC.") == 0)
+ {
+ /* Handle the .TOC. symbol as the linker would do. Set the .TOC.
+ sections value and the section to point to the ".toc" section,
+ and pass the toc->vma value into bfd_set_gp_value().
+ If the .toc section is not found, use the first section
+ with the SEC_ALLOC flag set. Im the unlikely case that
+ we still do not have a section identified, fall back to using
+ bfd_abs_section_ptr. */
+ asection *toc_fallback = bfd_get_section_by_name(abfd.get(), ".toc");
+ if (toc_fallback == NULL) {
+ for (asection *tsect = abfd->sections; tsect != nullptr;
+ tsect = tsect->next) {
+ if (bfd_section_flags (tsect) & SEC_ALLOC) {
+ if (compile_debug)
+ fprintf_unfiltered (gdb_stdlog,
+ "Using section [%s] as .toc fallback.\n",
+ tsect->name);
+ toc_fallback = tsect;
+ break;
+ }
+ }
+ }
+ if (toc_fallback == NULL) {
+ /* If we've gotten here, we have not found a section usable
+ as a backup for the .toc section. Use bfd_abs_section_ptr. */
+ if (compile_debug)
+ fprintf_unfiltered (gdb_stdlog,
+ "Using bfd_abs_section_ptr as .toc fallback.\n");
+ toc_fallback = bfd_abs_section_ptr;
+ }
+ sym->section = toc_fallback;
+ sym->value = 0x8000;
+ bfd_set_gp_value(abfd.get(), toc_fallback->vma);
+ if (compile_debug)
+ fprintf_unfiltered (gdb_stdlog,
+ "Connectiong ELF symbol \"%s\" to the .toc section (%s)\n",
+ sym->name,
+ paddress (target_gdbarch (), sym->value));
+ continue;
+ }
+
bmsym = lookup_minimal_symbol (sym->name, NULL, NULL);
switch (bmsym.minsym == NULL
? mst_unknown : MSYMBOL_TYPE (bmsym.minsym))
{
case mst_text:
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [Patch v2] Handle .TOC. sections during gdb-compile for rs6000 target.
2021-07-28 19:08 [Patch v2] Handle .TOC. sections during gdb-compile for rs6000 target will schmidt
@ 2021-07-29 7:18 ` Ulrich Weigand
2021-07-29 8:26 ` Alan Modra
0 siblings, 1 reply; 5+ messages in thread
From: Ulrich Weigand @ 2021-07-29 7:18 UTC (permalink / raw)
To: will schmidt; +Cc: Alan Modra, Carl E. Love, gdb-patches, rogerio
"will schmidt" <will_schmidt@vnet.ibm.com> wrote on 28.07.2021 21:08:21:
> + sym->section = toc_fallback;
> + sym->value = 0x8000;
> + bfd_set_gp_value(abfd.get(), toc_fallback->vma);
For compatibility with BFD, shouldn't this be rather:
bfd_set_gp_value(abfd.get(), toc_fallback->vma + sym->value);
Alan, can you confirm?
Bye,
Ulrich
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [Patch v2] Handle .TOC. sections during gdb-compile for rs6000 target.
2021-07-29 7:18 ` Ulrich Weigand
@ 2021-07-29 8:26 ` Alan Modra
2021-07-29 11:49 ` Ulrich Weigand
0 siblings, 1 reply; 5+ messages in thread
From: Alan Modra @ 2021-07-29 8:26 UTC (permalink / raw)
To: Ulrich Weigand; +Cc: will schmidt, Carl E. Love, gdb-patches, rogerio
On Thu, Jul 29, 2021 at 09:18:18AM +0200, Ulrich Weigand wrote:
>
>
> "will schmidt" <will_schmidt@vnet.ibm.com> wrote on 28.07.2021 21:08:21:
>
> > + sym->section = toc_fallback;
> > + sym->value = 0x8000;
> > + bfd_set_gp_value(abfd.get(), toc_fallback->vma);
>
> For compatibility with BFD, shouldn't this be rather:
>
> bfd_set_gp_value(abfd.get(), toc_fallback->vma + sym->value);
>
> Alan, can you confirm?
No, see bfd/elf64-ppc.c:ppc64_elf_sec_toc. A long time ago I chose
the value of elf_gp used in elf64-ppc.c to be the start of the toc
section rather than the value of ".TOC.". The value is somewhat
arbitrary. Yes, I could change it to be the value of .TOC., but for
now the value above is correct.
--
Alan Modra
Australia Development Lab, IBM
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [Patch v2] Handle .TOC. sections during gdb-compile for rs6000 target.
2021-07-29 8:26 ` Alan Modra
@ 2021-07-29 11:49 ` Ulrich Weigand
2021-08-05 17:50 ` will schmidt
0 siblings, 1 reply; 5+ messages in thread
From: Ulrich Weigand @ 2021-07-29 11:49 UTC (permalink / raw)
To: Alan Modra; +Cc: Carl E. Love, gdb-patches, rogerio, will schmidt
"Alan Modra" <amodra@gmail.com> wrote on 29.07.2021 10:26:11:
> On Thu, Jul 29, 2021 at 09:18:18AM +0200, Ulrich Weigand wrote:
> >
> >
> > "will schmidt" <will_schmidt@vnet.ibm.com> wrote on 28.07.2021
21:08:21:
> >
> > > + sym->section = toc_fallback;
> > > + sym->value = 0x8000;
> > > + bfd_set_gp_value(abfd.get(), toc_fallback->vma);
> >
> > For compatibility with BFD, shouldn't this be rather:
> >
> > bfd_set_gp_value(abfd.get(), toc_fallback->vma + sym->value);
> >
> > Alan, can you confirm?
>
> No, see bfd/elf64-ppc.c:ppc64_elf_sec_toc. A long time ago I chose
> the value of elf_gp used in elf64-ppc.c to be the start of the toc
> section rather than the value of ".TOC.". The value is somewhat
> arbitrary. Yes, I could change it to be the value of .TOC., but for
> now the value above is correct.
I see, thanks for the explanation.
Will, the patch is OK for trunk then.
Thanks,
Ulrich
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [Patch v2] Handle .TOC. sections during gdb-compile for rs6000 target.
2021-07-29 11:49 ` Ulrich Weigand
@ 2021-08-05 17:50 ` will schmidt
0 siblings, 0 replies; 5+ messages in thread
From: will schmidt @ 2021-08-05 17:50 UTC (permalink / raw)
To: Ulrich Weigand, Alan Modra; +Cc: Carl E. Love, gdb-patches, rogerio
On Thu, 2021-07-29 at 13:49 +0200, Ulrich Weigand wrote:
> "Alan Modra" <amodra@gmail.com> wrote on 29.07.2021 10:26:11:
> > On Thu, Jul 29, 2021 at 09:18:18AM +0200, Ulrich Weigand wrote:
> > >
> > >
> > > "will schmidt" <will_schmidt@vnet.ibm.com> wrote on 28.07.2021
> 21:08:21:
> > >
> > > > + sym->section = toc_fallback;
> > > > + sym->value = 0x8000;
> > > > + bfd_set_gp_value(abfd.get(), toc_fallback->vma);
> > >
> > > For compatibility with BFD, shouldn't this be rather:
> > >
> > > bfd_set_gp_value(abfd.get(), toc_fallback->vma + sym-
> >value);
> > >
> > > Alan, can you confirm?
> >
> > No, see bfd/elf64-ppc.c:ppc64_elf_sec_toc. A long time ago I chose
> > the value of elf_gp used in elf64-ppc.c to be the start of the toc
> > section rather than the value of ".TOC.". The value is somewhat
> > arbitrary. Yes, I could change it to be the value of .TOC., but
> for
> > now the value above is correct.
>
> I see, thanks for the explanation.
>
> Will, the patch is OK for trunk then.
Committed with some additional indentation and cosmetic tweaks,
Thanks
-WIll
>
> Thanks,
> Ulrich
>
>
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2021-08-05 17:50 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-07-28 19:08 [Patch v2] Handle .TOC. sections during gdb-compile for rs6000 target will schmidt
2021-07-29 7:18 ` Ulrich Weigand
2021-07-29 8:26 ` Alan Modra
2021-07-29 11:49 ` Ulrich Weigand
2021-08-05 17:50 ` will schmidt
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).