public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
* [PATCH, MIPS] Fix typo in N64 PLT stub
@ 2011-11-12  5:28 Maxim Kuvyrkov
  2011-11-13 10:57 ` Richard Sandiford
  0 siblings, 1 reply; 6+ messages in thread
From: Maxim Kuvyrkov @ 2011-11-12  5:28 UTC (permalink / raw)
  To: Richard Sandiford; +Cc: binutils, Maciej W. Rozycki

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

Richard,

The following patch fixes a typo in N64 PLT stub.  The register move that saves return address for dynamic resolver to return to currently uses a 32-bit instruction, which truncates upper bits of the return address.

Now, I imagine you would ask why is there a 64-bit address in the PLT resolver that only works with 32-bit symbols (aka -msym32).  The answer is that the 64-bit return address leaks to the PLT0 from a shared library, which kernel is free to map anywhere it pleases.  The most common case is for C library to call atexit callbacks from a C++ application.

The -msym32 restriction applies only to symbols in executables, as those do have PLTs.  Symbols in shared libraries cannot have PLTs, and, simultaneously, they can't be guaranteed to be mapped to lower 32-bits of address space.

The patch was tested on GCC and GLIBC testsuites on MIPS64 target with no regressions between "-mabi=64" and "-mabi=64 -mplt -msym32" runs.

OK to apply?

Thank you,

--
Maxim Kuvyrkov
CodeSourcery / Mentor Graphics



[-- Attachment #2: bfd-mips-64bit-plt.patch --]
[-- Type: application/octet-stream, Size: 1431 bytes --]

Index: bfd/elfxx-mips.c
===================================================================
--- bfd/elfxx-mips.c	(revision 347109)
+++ bfd/elfxx-mips.c	(working copy)
@@ -999,7 +999,7 @@ static const bfd_vma mips_o32_exec_plt0_
   0x8f990000,	/* lw $25, %lo(&GOTPLT[0])($28)				*/
   0x279c0000,	/* addiu $28, $28, %lo(&GOTPLT[0])			*/
   0x031cc023,	/* subu $24, $24, $28					*/
-  0x03e07821,	/* move $15, $31					*/
+  0x03e07821,	/* move $15, $31	# 32-bit move			*/
   0x0018c082,	/* srl $24, $24, 2					*/
   0x0320f809,	/* jalr $25						*/
   0x2718fffe	/* subu $24, $24, 2					*/
@@ -1013,7 +1013,7 @@ static const bfd_vma mips_n32_exec_plt0_
   0x8dd90000,	/* lw $25, %lo(&GOTPLT[0])($14)				*/
   0x25ce0000,	/* addiu $14, $14, %lo(&GOTPLT[0])			*/
   0x030ec023,	/* subu $24, $24, $14					*/
-  0x03e07821,	/* move $15, $31					*/
+  0x03e07821,	/* move $15, $31	# 32-bit move			*/
   0x0018c082,	/* srl $24, $24, 2					*/
   0x0320f809,	/* jalr $25						*/
   0x2718fffe	/* subu $24, $24, 2					*/
@@ -1027,7 +1027,7 @@ static const bfd_vma mips_n64_exec_plt0_
   0xddd90000,	/* ld $25, %lo(&GOTPLT[0])($14)				*/
   0x25ce0000,	/* addiu $14, $14, %lo(&GOTPLT[0])			*/
   0x030ec023,	/* subu $24, $24, $14					*/
-  0x03e07821,	/* move $15, $31					*/
+  0x03e0782d,	/* move $15, $31	# 64-bit move			*/
   0x0018c0c2,	/* srl $24, $24, 3					*/
   0x0320f809,	/* jalr $25						*/
   0x2718fffe	/* subu $24, $24, 2					*/

[-- Attachment #3: bfd-mips-64bit-plt.ChangeLog --]
[-- Type: application/octet-stream, Size: 120 bytes --]

2011-11-11  Maxim Kuvyrkov  <maxim@codesourcery.com>

	bfd/
	* elfxx-mips.c (mips_n64_exe_plt0_entry): Use 64-bit move.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH, MIPS] Fix typo in N64 PLT stub
  2011-11-12  5:28 [PATCH, MIPS] Fix typo in N64 PLT stub Maxim Kuvyrkov
@ 2011-11-13 10:57 ` Richard Sandiford
  2011-11-13 11:40   ` Maciej W. Rozycki
  0 siblings, 1 reply; 6+ messages in thread
From: Richard Sandiford @ 2011-11-13 10:57 UTC (permalink / raw)
  To: Maxim Kuvyrkov; +Cc: binutils, Maciej W. Rozycki, gingold

Maxim Kuvyrkov <maxim@codesourcery.com> writes:
> The following patch fixes a typo in N64 PLT stub.  The register move
> that saves return address for dynamic resolver to return to currently
> uses a 32-bit instruction, which truncates upper bits of the return
> address.

Ouch.

> Now, I imagine you would ask why is there a 64-bit address in the PLT
> resolver that only works with 32-bit symbols (aka -msym32).

Nah :-)  The PLT's obviously wrong.  Probably a pasto from the n32 version.

Patch is OK, thanks.  Branch too please, although Tristan plans to
release 2.22 this coming week.

Richard

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH, MIPS] Fix typo in N64 PLT stub
  2011-11-13 10:57 ` Richard Sandiford
@ 2011-11-13 11:40   ` Maciej W. Rozycki
  2011-11-13 11:50     ` Richard Sandiford
  0 siblings, 1 reply; 6+ messages in thread
From: Maciej W. Rozycki @ 2011-11-13 11:40 UTC (permalink / raw)
  To: Richard Sandiford; +Cc: Maxim Kuvyrkov, binutils, gingold

On Sun, 13 Nov 2011, Richard Sandiford wrote:

> > Now, I imagine you would ask why is there a 64-bit address in the PLT
> > resolver that only works with 32-bit symbols (aka -msym32).
> 
> Nah :-)  The PLT's obviously wrong.  Probably a pasto from the n32 version.
> 
> Patch is OK, thanks.  Branch too please, although Tristan plans to
> release 2.22 this coming week.

 For the avoidance of someone's future confusion -- yes, we all know these 
subtle details, but there are mere mortals out there too ;) -- I'd suggest 
updating the comment like:

# 32-bit move (addu)
# 64-bit move (daddu)

or maybe even:

# 32-bit move (addu $15, $31, $0)
# 64-bit move (daddu $15, $31, $0)

What do you think?

  Maciej

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH, MIPS] Fix typo in N64 PLT stub
  2011-11-13 11:40   ` Maciej W. Rozycki
@ 2011-11-13 11:50     ` Richard Sandiford
  2011-11-15 12:59       ` Maciej W. Rozycki
  0 siblings, 1 reply; 6+ messages in thread
From: Richard Sandiford @ 2011-11-13 11:50 UTC (permalink / raw)
  To: Maciej W. Rozycki; +Cc: Maxim Kuvyrkov, binutils, gingold

"Maciej W. Rozycki" <macro@codesourcery.com> writes:
> On Sun, 13 Nov 2011, Richard Sandiford wrote:
>
>> > Now, I imagine you would ask why is there a 64-bit address in the PLT
>> > resolver that only works with 32-bit symbols (aka -msym32).
>> 
>> Nah :-)  The PLT's obviously wrong.  Probably a pasto from the n32 version.
>> 
>> Patch is OK, thanks.  Branch too please, although Tristan plans to
>> release 2.22 this coming week.
>
>  For the avoidance of someone's future confusion -- yes, we all know these 
> subtle details, but there are mere mortals out there too ;) -- I'd suggest 
> updating the comment like:
>
> # 32-bit move (addu)
> # 64-bit move (daddu)
>
> or maybe even:
>
> # 32-bit move (addu $15, $31, $0)
> # 64-bit move (daddu $15, $31, $0)
>
> What do you think?

Good idea.  The first one seems better to me FWIW.

Richard

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH, MIPS] Fix typo in N64 PLT stub
  2011-11-13 11:50     ` Richard Sandiford
@ 2011-11-15 12:59       ` Maciej W. Rozycki
  2011-11-16  1:06         ` Maxim Kuvyrkov
  0 siblings, 1 reply; 6+ messages in thread
From: Maciej W. Rozycki @ 2011-11-15 12:59 UTC (permalink / raw)
  To: Maxim Kuvyrkov; +Cc: Richard Sandiford, binutils, gingold

Maxim,

> >> Patch is OK, thanks.  Branch too please, although Tristan plans to
> >> release 2.22 this coming week.

 Your change's still missing from 2.22 (binutils-2_22-branch), please push 
it.

  Maciej

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH, MIPS] Fix typo in N64 PLT stub
  2011-11-15 12:59       ` Maciej W. Rozycki
@ 2011-11-16  1:06         ` Maxim Kuvyrkov
  0 siblings, 0 replies; 6+ messages in thread
From: Maxim Kuvyrkov @ 2011-11-16  1:06 UTC (permalink / raw)
  To: Maciej W. Rozycki; +Cc: Richard Sandiford, binutils, gingold

On 16/11/2011, at 1:58 AM, Maciej W. Rozycki wrote:

> Maxim,
> 
>>>> Patch is OK, thanks.  Branch too please, although Tristan plans to
>>>> release 2.22 this coming week.
> 
> Your change's still missing from 2.22 (binutils-2_22-branch), please push 
> it.

Done.  Thanks for reminder.

--
Maxim Kuvyrkov
CodeSourcery / Mentor Graphics

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2011-11-16  1:06 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-11-12  5:28 [PATCH, MIPS] Fix typo in N64 PLT stub Maxim Kuvyrkov
2011-11-13 10:57 ` Richard Sandiford
2011-11-13 11:40   ` Maciej W. Rozycki
2011-11-13 11:50     ` Richard Sandiford
2011-11-15 12:59       ` Maciej W. Rozycki
2011-11-16  1:06         ` Maxim Kuvyrkov

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).