public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
From: Richard Sandiford <richard@codesourcery.com>
To: Steven Munroe <munroesj@us.ibm.com>
Cc: binutils@sourceware.org, dje@gcc.gnu.org, mark@codesourcery.com
Subject: Re: Link problems with section anchors
Date: Fri, 04 Aug 2006 09:04:00 -0000	[thread overview]
Message-ID: <87y7u427or.fsf@talisman.home> (raw)
In-Reply-To: <20060804013032.GB23605@bubble.grove.modra.org> (Alan Modra's 	message of "Fri, 4 Aug 2006 11:00:32 +0930")

I wasn't really sure whether to reply to the gcc bug report or the
binutils thread.  As you can see, I chose here.

The gcc bug report (28598) seems a little confused to me.  It appears
to be saying "gcc should not use GOT relocs for anchor symbols", but how
else is it supposed to load the value of the symbol?  From an addressing
perspective, the anchor symbol is no different from any other local symbol.

Perhaps this was influenced by what Alan said:

Alan Modra <amodra@bigpond.net.au> writes:
> I'd say this is a gcc bug.  (The GOT reloc can't really use section
> anchors anyway because sym+off@got has rather useless semantics, so why
> can't gcc use the original symbol?)

...but we don't use sym+off@got for anchors.  Well, OK, I'll have
to equivocate that slightly, but first...

The point of -fsection-anchors is to access (hopefully) several nearby
objects from the same symbol, where "nearby" depends on the addressing
capabilities of the target.  On PPC "nearby" == "within a 32-bit signed
displacement".

We start out by modelling each access as follows: we load an anchor
symbol into a base register, then apply the relative offset of the
object to that base register.  We win if, by doing this, we can access
more than one object from the same symbol.  For example, when using
a GOT, we'll only have one GOT entry for the anchor symbol rather
than several entries for each object.

The equivocation is that, if an anchor is only used once, gcc may
optimise "load ANCHOR then add OFFSET" into "load (ANCHOR + OFFSET)".
But the backend will (should!) handle this load in the same way as it
would handle any another "load (LOCAL + OFFSET)" access.  There is
nothing special about the anchor symbol as far as the addressing
code goes.

In other words, we'd only use "ANCHOR+OFFSET@got" if an anchor is
only used once, and only then if we would also use "LOCAL+OFFSET@got".

> ld can't treat the local symbols in linkonce sections as if they were
> global because .LANCHOR0 in .gnu.linkonce.r.__strtol_ul_max_tab must
> be different from .LANCHOR0 in .gnu.linkonce.r.some_other_name.  Hmm,
> I suppose ld could create a new global name that incorporated the
> section name, and do the same for section groups, but twiddling relocs
> to use a different symbol is non-trivial.

Yes, it sounds like you have a testcase in which anchors are used to
access linkonce objects.  This Should Not Happen, and if it is happening,
is the real bug.  Link-once objects were supposed to be handled by:

static struct object_block *
get_block_for_decl (tree decl)
{
  section *sect;

  if (TREE_CODE (decl) == VAR_DECL)
    {
      [...]
      /* There's no point using object blocks for something that is
	 isolated by definition.  */
      if (DECL_ONE_ONLY (decl))
	return NULL;
    }
}

(In case the emphasis of the comment seems odd; this code is deciding
whether it's worthwhile grouping objects together.  That's a more
general question than "do we want to use anchors for this object"?
The hope is that we might want to group objects together for other
optimisations too, such choosing as a more cache-friendly layout.)

Could someone prepare a testcase?  Thanks.

Richard

  reply	other threads:[~2006-08-04  9:04 UTC|newest]

Thread overview: 60+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <44D2755E.9020600@us.ibm.com>
2006-08-04  1:30 ` Alan Modra
2006-08-04  9:04   ` Richard Sandiford [this message]
2006-08-04 13:53     ` Steven Munroe
2006-08-04 13:54     ` David Edelsohn
2006-08-04 14:01       ` Richard Sandiford
2006-08-04 14:12         ` David Edelsohn
     [not found] <3A3FC75F7C72D711A7DC009027AC9C4B1788D9@jupiter>
2004-05-19  3:30 ` Powerpc Linux build fails Alan Modra
2004-05-19  4:27   ` Geoff Keating
2004-05-19  5:10     ` Alan Modra
2004-05-19 16:24       ` Kumar Gala
2004-05-20  0:44         ` Alan Modra
     [not found] <087e01c3b5da$77d658e0$0202040a@catdog>
2003-11-29  1:42 ` ppc problem with .rodata.str1.4. binutils requirement for gcc 3.3.1? Alan Modra
2003-11-29 18:14   ` Kris Warkentin
2001-12-31 19:09 Compiling kernel 2.4.17 fails at link stage Krishnakumar B
2002-01-04  3:50 ` Alan Modra
2002-01-04 12:39   ` [Linux-ia64] " Alan Modra
  -- strict thread matches above, loose matches on Subject: below --
2001-10-24 18:26 Release 2.12 Hans-Peter Nilsson
2001-10-24 18:38 ` Alan Modra
2001-10-24 18:43   ` David O'Brien
2001-10-24 19:30     ` Alan Modra
2001-10-24 19:35       ` MMIX (was: Re: Release 2.12) Hans-Peter Nilsson
2001-10-24 21:45       ` Release 2.12 Eric Christopher
2001-10-25  8:41         ` H . J . Lu
2001-10-25  8:47       ` H . J . Lu
2001-10-24 18:49   ` Daniel Jacobowitz
2001-10-24 19:43     ` Alan Modra
2001-10-24 20:10       ` Daniel Jacobowitz
2001-10-24 20:35         ` Alan Modra
2001-10-24 20:44           ` Daniel Jacobowitz
2001-10-25  5:09         ` Christopher C. Chimelis
2001-10-25  1:56       ` Philip Blundell
2001-10-25  8:30         ` H . J . Lu
2001-10-25  8:47           ` David O'Brien
     [not found]       ` <amodra@bigpond.net.au>
2002-01-04 17:42         ` [Linux-ia64] Compiling kernel 2.4.17 fails at link stage Grant Grundler
2002-01-04 17:59           ` H . J . Lu
2002-01-04 20:37             ` Grant Grundler
2002-01-04 22:39               ` H . J . Lu
2002-01-07 12:52                 ` Grant Grundler
2002-01-04 19:21           ` Alan Modra
2003-11-29  2:33         ` ppc problem with .rodata.str1.4. binutils requirement for gcc 3.3.1? David Edelsohn
2003-11-29  3:05           ` Alan Modra
2003-11-29  4:06         ` David Edelsohn
2003-11-29  4:10           ` Andrew Pinski
2003-11-29  4:20             ` David Edelsohn
2003-11-29  6:47               ` Alan Modra
2003-11-29 19:40         ` David Edelsohn
2004-05-19 15:19         ` Powerpc Linux build fails David Edelsohn
2004-05-20  0:39           ` Alan Modra
2004-05-20  1:24             ` Alan Modra
2004-05-20  1:46               ` Alan Modra
2004-05-20  2:29         ` David Edelsohn
2004-05-20  3:10           ` Alan Modra
2006-08-04  1:49         ` Link problems with section anchors David Edelsohn
2006-08-04  2:04           ` Alan Modra
2001-10-24 19:37   ` Release 2.12 Russ Allbery
2001-10-24 19:52     ` Alan Modra
2001-10-25  0:46 ` H . J . Lu
2001-10-25  8:57   ` David O'Brien
2001-10-25  9:38     ` H . J . Lu
2001-10-25  9:44       ` H . J . Lu

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=87y7u427or.fsf@talisman.home \
    --to=richard@codesourcery.com \
    --cc=binutils@sourceware.org \
    --cc=dje@gcc.gnu.org \
    --cc=mark@codesourcery.com \
    --cc=munroesj@us.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).