public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Alan Modra <amodra@gmail.com>
To: will schmidt <will_schmidt@vnet.ibm.com>
Cc: Ulrich Weigand <uweigand@de.ibm.com>,
	gdb-patches@sourceware.org, rogerio <rogealve@br.ibm.com>,
	"Carl E. Love" <cel@us.ibm.com>
Subject: Re: gdb compile for powerpc64 target - Could not find symbol ".TOC."
Date: Thu, 24 Jun 2021 12:41:18 +0930	[thread overview]
Message-ID: <YNP31jXifafwTmbf@squeak.grove.modra.org> (raw)
In-Reply-To: <01c0a5da1434349f6118c1bfb9f500fd932c77d9.camel@vnet.ibm.com>

On Wed, Jun 23, 2021 at 12:37:48PM -0500, will schmidt wrote:
> On Wed, 2021-06-23 at 17:36 +0200, Ulrich Weigand wrote:
> > On Tue, Jun 22, 2021 at 01:54:56PM -0500, will schmidt wrote:
> > 
> > > During gdb/compile/compile-object-load.c:
> > > compile-object-load() the following is emitted:
> > > 	warning: Could not find symbol ".TOC." for compiled module 
> > > 	"/tmp/gdbobj-wIKWtk/out15.o".
> > > 
> > > My best guess is that we need to incorporate some amount of special
> > > handling for the TOC entry to help find the symbols we are after. 
> > > But.. I havn't stumbled across anything similar for other targets,
> > > and
> > > I havn't yet gleamed enlightenment looking at the existing code in
> > > compile-object-load.  :-)    As a hack I have tried treating the 
> > > TOC symbol like we do the GOT entry, those attempts will later
> > > crash as
> > > we will trip over a zero dereference when trying to get at the
> > > symbol
> > > to print it.

I'm not at all familiar with gdb/compile, but it looks like anything
to do with the GOT is unsupported.  I can't see any handling for GOT
relocs, for example.  

Now .TOC. should be handled exactly as _GLOBAL_OFFSET_TABLE_, but
compile-object-load.c is just broken, I think.  You can't set .TOC. or
_GLOBAL_OFFSET_TABLE_ to zero and expect everything to be rosy, for
code that uses those symbols.

> > 
> > Yes, we probably do need a proper value for .TOC.  Usually, this
> > is set by the linker to 0x8000 bytes after the beginning of the .toc
> > section, I think.

Again, I'm not familiar enough with the gdb compile support to give
proper advice.  If calls to functions in the newly compiled/loaded
code is always via global entry points then you have some freedom in
choosing your own .TOC. value.  If direct calls to the local entry
point are made then .TOC. should be set to the value used in whatever
context is going to call the newly loaded object.  That would be
tricky.

Oh, and another thing, even if you manage to set a value for .TOC.,
bfd_get_relocated_section_contents uses reloc howtos to perform
relocations.  bfd.c:_bfd_get_gp_value is used for all the TOC16
relocs, which means elf_gp should be set to .TOC. and you can't leave
the bfd format as bfd_object.

> > Looks like there is a BFD routine ppc64_elf_set_toc that will define
> > that symbol, but that's probably never called here if you just load
> > a plain object file.
> 
> 
> 
> > 
> > Alan, do you have any suggestions of how to handle this, maybe?
> > 
> > 
> > > With "set debug compile" enabled, a few bits of possibly relevant
> > > info..
> > > 
> > > 	COLLECT_GCC_OPTIONS='-m64' '-mcmodel=large' '-A' 'system=linux'
> > 
> > Can you try without -mcmodel=large ?   The particular reference to
> > the .TOC. symbol you show below originated from this option.
> > However, even without that there may still be references to .TOC.
> 
> Yes..  without specifying mcmodel (defaults to medium?) same result.
> Also just tried with each of large,medium,small in turn.. same results.
> 
> 
> 
> 
> Thanks
> -Will
> 
> > 
> > Bye,
> > Ulricj
> > 

-- 
Alan Modra
Australia Development Lab, IBM

  reply	other threads:[~2021-06-24  3:11 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-06-22 18:54 will schmidt
2021-06-23 15:36 ` Ulrich Weigand
2021-06-23 17:37   ` will schmidt
2021-06-24  3:11     ` Alan Modra [this message]
2021-06-24  4:39       ` Alan Modra
2021-06-24 15:32       ` Ulrich Weigand
2021-06-24 23:05         ` Alan Modra
2021-06-25 14:49           ` will schmidt
2021-07-09 16:51           ` will schmidt
2021-07-10  1:01             ` Alan Modra
2021-07-13  4:33               ` will schmidt
2021-07-13 11:11                 ` Alan Modra
2021-07-13 22:59                   ` will schmidt

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=YNP31jXifafwTmbf@squeak.grove.modra.org \
    --to=amodra@gmail.com \
    --cc=cel@us.ibm.com \
    --cc=gdb-patches@sourceware.org \
    --cc=rogealve@br.ibm.com \
    --cc=uweigand@de.ibm.com \
    --cc=will_schmidt@vnet.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).