public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
From: Roland McGrath <roland@hack.frob.com>
To: binutils@sourceware.org
Cc: Roland McGrath <mcgrathr@google.com>
Subject: gold regression vs BFD ld: __ehdr_start
Date: Sun, 30 Mar 2014 01:15:00 -0000	[thread overview]
Message-ID: <20140330011513.D6435744AE@topped-with-meat.com> (raw)

With trunk on x86_64-linux-gnu:

	$ cat foo.s
		.text
		.globl _start
	_start:
		lea __ehdr_start(%rip), %r11
	$ ./gas/as-new -o foo.o foo.s
	$ ./ld/ld-new -shared -o foo.so foo.o
	$ readelf -rs foo.so

	There are no relocations in this file.

	Symbol table '.dynsym' contains 6 entries:
	   Num:    Value          Size Type    Bind   Vis      Ndx Name
	     0: 0000000000000000     0 NOTYPE  LOCAL  DEFAULT  UND 
	     1: 00000000000001c1     0 SECTION LOCAL  DEFAULT    4 
	     2: 00000000000001c1     0 NOTYPE  GLOBAL DEFAULT    4 _start
	     3: 0000000000200278     0 NOTYPE  GLOBAL DEFAULT    6 __bss_start
	     4: 0000000000200278     0 NOTYPE  GLOBAL DEFAULT    6 _edata
	     5: 0000000000200278     0 NOTYPE  GLOBAL DEFAULT    6 _end

	Symbol table '.symtab' contains 14 entries:
	   Num:    Value          Size Type    Bind   Vis      Ndx Name
	     0: 0000000000000000     0 NOTYPE  LOCAL  DEFAULT  UND 
	     1: 00000000000000e8     0 SECTION LOCAL  DEFAULT    1 
	     2: 0000000000000118     0 SECTION LOCAL  DEFAULT    2 
	     3: 00000000000001a8     0 SECTION LOCAL  DEFAULT    3 
	     4: 00000000000001c1     0 SECTION LOCAL  DEFAULT    4 
	     5: 00000000000001c8     0 SECTION LOCAL  DEFAULT    5 
	     6: 00000000002001c8     0 SECTION LOCAL  DEFAULT    6 
	     7: 0000000000000000     0 NOTYPE  LOCAL  DEFAULT    1 __ehdr_start
	     8: 00000000002001c8     0 OBJECT  LOCAL  DEFAULT    6 _DYNAMIC
	     9: 0000000000000000     0 OBJECT  LOCAL  DEFAULT    6 _GLOBAL_OFFSET_TABLE_
	    10: 00000000000001c1     0 NOTYPE  GLOBAL DEFAULT    4 _start
	    11: 0000000000200278     0 NOTYPE  GLOBAL DEFAULT    6 __bss_start
	    12: 0000000000200278     0 NOTYPE  GLOBAL DEFAULT    6 _edata
	    13: 0000000000200278     0 NOTYPE  GLOBAL DEFAULT    6 _end
	$ ./gold/ld-new -shared -o foo.so foo.o
	./gold/ld-new: error: foo.o: requires dynamic R_X86_64_PC32 reloc against '__ehdr_start' which may overflow at runtime; recompile with -fPIC
	[Exit 1]
	$ 

I think when __ehdr_start was first added to BFD ld, it may have behaved
this way too.  But it works properly now.  The key issue is that when the
__ehdr_start symbol is in its indeterminate state, it still needs to be
understood to be STV_HIDDEN so that it doesn't generate dynamic relocs.
When it is eventually found that it can be defined and it is--a decision
that can only be made after layout--then it will be defined as STV_HIDDEN,
so it should always get static resolution.  If at the end of the way it
can't be defined (layout with no readable segment covering the file
headers), then it is probably fine to get an error rather than generating
the dynamic relocs that would be normal for any random undefined
symbol--albeit, that is a regression relative to pre-2.23 linkers when
users happen to use this once mundane, now magic symbol name.  (I'm not
sure any more if 2.24/trunk BFD ld has that regression against its own
pre-2.23 behavior or not.)

I think what has to happen is something analogous to what BFD ld does now:
Add the symbol early on in an undefined or indeterminate state, and then
define it (or don't) later on.  It's not very clear to me how to do that
correctly in gold.  It would seem clearest if it can be done in
define_standard_symbols.  But I don't know what Layout::finalize (where
it's created now) should do to find it and adjust it to point at the right
segment.  I also don't know how either case would interact with a user
defining (in input or script) this symbol name himself, in which case (IIRC
the BFD ld behavior) the user's symbol should be wholly unmolested (but it
might be that BFD ld uses the user's value but marks it STV_HIDDEN
anyway--I'm not sure).

This is yet another time I've wished we had a common test suite for both
linkers to verify matching behavior.  Of course I understand why output
doesn't match byte-for-byte and why the whole style of the existing ld
testsuite doesn't mesh well with a more semantically-precise testing
methodology.  But still, harumph.


Thanks,
Roland

             reply	other threads:[~2014-03-30  1:15 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-03-30  1:15 Roland McGrath [this message]
2014-03-31 19:19 ` Ian Lance Taylor
2014-03-31 21:03   ` Cary Coutant
2014-03-31 21:07     ` Roland McGrath
2014-03-31 21:18       ` Cary Coutant
2014-03-31 21:27         ` Roland McGrath
2014-03-31 22:19           ` Cary Coutant
2014-04-01 16:34             ` Roland McGrath
2014-04-01 21:50               ` Cary Coutant
2014-04-01 22:28                 ` Cary Coutant
2014-04-01 22:50                 ` Roland McGrath
2014-04-01 22:59                 ` Cary Coutant
2014-04-01 23:02                   ` Cary Coutant
2014-04-03 17:27                     ` Roland McGrath
2014-04-23 21:08                       ` Roland McGrath
2014-04-23 21:45                         ` Cary Coutant
2014-04-23 22:03                           ` Roland McGrath
2014-05-06 21:53                             ` Cary Coutant
2014-05-06 21:54                               ` Roland McGrath

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=20140330011513.D6435744AE@topped-with-meat.com \
    --to=roland@hack.frob.com \
    --cc=binutils@sourceware.org \
    --cc=mcgrathr@google.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).