powerpc: fix ifunc-sel.h with GCC 6

Message ID 1469093774-25485-1-git-send-email-aurelien@aurel32.net
State Committed
Delegated to: Tulio Magno Quites Machado Filho
Headers

Commit Message

Aurelien Jarno July 21, 2016, 9:36 a.m. UTC
  On 32-bit PowerPC GCC 6 always saves the PIC register on the stack in
the prologue and adjust the stack in the epilogue. It is therefore not
possible anymore to just exit the function in the inline asm code,
otherwise it corrupts the stack pointer. This causes the following tests
to fail when using GCC 6:

FAIL: elf/ifuncmain1
FAIL: elf/ifuncmain1pic
FAIL: elf/ifuncmain1picstatic
FAIL: elf/ifuncmain1pie
FAIL: elf/ifuncmain1staticpic
FAIL: elf/ifuncmain1staticpie
FAIL: elf/ifuncmain1vis
FAIL: elf/ifuncmain1vispic
FAIL: elf/ifuncmain1vispie
FAIL: elf/ifuncmain2pic
FAIL: elf/ifuncmain2picstatic
FAIL: elf/ifuncmain3
FAIL: elf/ifuncmain4picstatic
FAIL: elf/ifuncmain5
FAIL: elf/ifuncmain5picstatic
FAIL: elf/ifuncmain5staticpic

The solution is to replace the beqlr instructions by a beq to the end
of the inline asm code. This fixes all the above failures.

ChangeLog:
	* sysdeps/powerpc/ifunc-sel.h (ifunc_sel): Replace beqlr instructions
	by beq instructions jumping to the end of the function.
---
 ChangeLog                   | 5 +++++
 sysdeps/powerpc/ifunc-sel.h | 7 ++++---
 2 files changed, 9 insertions(+), 3 deletions(-)
  

Comments

Aurelien Jarno July 21, 2016, 11:22 a.m. UTC | #1
On 2016-07-21 11:36, Aurelien Jarno wrote:
> On 32-bit PowerPC GCC 6 always saves the PIC register on the stack in
> the prologue and adjust the stack in the epilogue. It is therefore not
> possible anymore to just exit the function in the inline asm code,
> otherwise it corrupts the stack pointer. This causes the following tests
> to fail when using GCC 6:
> 
> FAIL: elf/ifuncmain1
> FAIL: elf/ifuncmain1pic
> FAIL: elf/ifuncmain1picstatic
> FAIL: elf/ifuncmain1pie
> FAIL: elf/ifuncmain1staticpic
> FAIL: elf/ifuncmain1staticpie
> FAIL: elf/ifuncmain1vis
> FAIL: elf/ifuncmain1vispic
> FAIL: elf/ifuncmain1vispie
> FAIL: elf/ifuncmain2pic
> FAIL: elf/ifuncmain2picstatic
> FAIL: elf/ifuncmain3
> FAIL: elf/ifuncmain4picstatic
> FAIL: elf/ifuncmain5
> FAIL: elf/ifuncmain5picstatic
> FAIL: elf/ifuncmain5staticpic
> 
> The solution is to replace the beqlr instructions by a beq to the end
> of the inline asm code. This fixes all the above failures.
> 
> ChangeLog:
> 	* sysdeps/powerpc/ifunc-sel.h (ifunc_sel): Replace beqlr instructions
> 	by beq instructions jumping to the end of the function.
> ---
>  ChangeLog                   | 5 +++++
>  sysdeps/powerpc/ifunc-sel.h | 7 ++++---
>  2 files changed, 9 insertions(+), 3 deletions(-)

I forgot to say that I have tested this patch on ppc, ppc64 and ppc64le.
No regression in the testsuite.
  
Florian Weimer July 21, 2016, 11:53 a.m. UTC | #2
On 07/21/2016 11:36 AM, Aurelien Jarno wrote:
> On 32-bit PowerPC GCC 6 always saves the PIC register on the stack in
> the prologue and adjust the stack in the epilogue. It is therefore not
> possible anymore to just exit the function in the inline asm code,
> otherwise it corrupts the stack pointer. This causes the following tests
> to fail when using GCC 6:

>  	   : "=r" (ret)
>  	   : "X" (&global), "X" (f1), "X" (f2), "X" (f3));
>    return ret;

The inline assembly still lacks clobbers for registers 11 and 12, and 
the "X" constraint is incorrect (it should be "i", I think).

Florian
  
Florian Weimer July 21, 2016, 12:08 p.m. UTC | #3
On 07/21/2016 01:53 PM, Florian Weimer wrote:
> On 07/21/2016 11:36 AM, Aurelien Jarno wrote:
>> On 32-bit PowerPC GCC 6 always saves the PIC register on the stack in
>> the prologue and adjust the stack in the epilogue. It is therefore not
>> possible anymore to just exit the function in the inline asm code,
>> otherwise it corrupts the stack pointer. This causes the following tests
>> to fail when using GCC 6:
>
>>         : "=r" (ret)
>>         : "X" (&global), "X" (f1), "X" (f2), "X" (f3));
>>    return ret;
>
> The inline assembly still lacks clobbers for registers 11 and 12, and
> the "X" constraint is incorrect (it should be "i", I think).

And a comment why bcl 20,31 is used instead of bl wouldn't hurt, either. 
  A colleague explained to me it's a hint to the implementation not to 
perform return stack optimization, although the observable effect is 
identical to bl.

Florian
  
Andreas Schwab July 21, 2016, 12:21 p.m. UTC | #4
Florian Weimer <fweimer@redhat.com> writes:

> And a comment why bcl 20,31 is used instead of bl wouldn't hurt,
> either.

That's the canonical way to setup a reference to the TOC.

Andreas.
  
Aurelien Jarno July 21, 2016, 12:57 p.m. UTC | #5
On 2016-07-21 13:53, Florian Weimer wrote:
> On 07/21/2016 11:36 AM, Aurelien Jarno wrote:
> > On 32-bit PowerPC GCC 6 always saves the PIC register on the stack in
> > the prologue and adjust the stack in the epilogue. It is therefore not
> > possible anymore to just exit the function in the inline asm code,
> > otherwise it corrupts the stack pointer. This causes the following tests
> > to fail when using GCC 6:
> 
> >  	   : "=r" (ret)
> >  	   : "X" (&global), "X" (f1), "X" (f2), "X" (f3));
> >    return ret;
> 
> The inline assembly still lacks clobbers for registers 11 and 12, and the
> "X" constraint is incorrect (it should be "i", I think).

I agree that this should be fixed, and I'll try to work on that. That
said it should probably be done as an additional patch, my patch doesn't
touch that part.

Aurelien
  
Florian Weimer July 21, 2016, 2:27 p.m. UTC | #6
On 07/21/2016 02:21 PM, Andreas Schwab wrote:
> Florian Weimer <fweimer@redhat.com> writes:
>
>> And a comment why bcl 20,31 is used instead of bl wouldn't hurt,
>> either.
>
> That's the canonical way to setup a reference to the TOC.

Yes, I figured that out in the meantime.  Is “bcl 20,31” always used for 
that?  The second opcode argument doesn't really matter, after all.

Florian
  
Florian Weimer July 21, 2016, 2:27 p.m. UTC | #7
On 07/21/2016 02:57 PM, Aurelien Jarno wrote:
> On 2016-07-21 13:53, Florian Weimer wrote:
>> On 07/21/2016 11:36 AM, Aurelien Jarno wrote:
>>> On 32-bit PowerPC GCC 6 always saves the PIC register on the stack in
>>> the prologue and adjust the stack in the epilogue. It is therefore not
>>> possible anymore to just exit the function in the inline asm code,
>>> otherwise it corrupts the stack pointer. This causes the following tests
>>> to fail when using GCC 6:
>>
>>>  	   : "=r" (ret)
>>>  	   : "X" (&global), "X" (f1), "X" (f2), "X" (f3));
>>>    return ret;
>>
>> The inline assembly still lacks clobbers for registers 11 and 12, and the
>> "X" constraint is incorrect (it should be "i", I think).
>
> I agree that this should be fixed, and I'll try to work on that. That
> said it should probably be done as an additional patch, my patch doesn't
> touch that part.

Your patch looks good to me, but one of the POWER maintainers should 
comment.

Thanks,
Florian
  
Andreas Schwab July 21, 2016, 3:23 p.m. UTC | #8
Florian Weimer <fweimer@redhat.com> writes:

> Yes, I figured that out in the meantime.  Is “bcl 20,31” always used for
> that?  The second opcode argument doesn't really matter, after all. 

It's what gcc uses.  I don't know if there is any deeper meaning behind
that particular encoding.

Andreas.
  
Tulio Magno Quites Machado Filho July 21, 2016, 5:48 p.m. UTC | #9
Aurelien Jarno <aurelien@aurel32.net> writes:

> On 32-bit PowerPC GCC 6 always saves the PIC register on the stack in
> the prologue and adjust the stack in the epilogue. It is therefore not
> possible anymore to just exit the function in the inline asm code,
> otherwise it corrupts the stack pointer. This causes the following tests
> to fail when using GCC 6:
>
> FAIL: elf/ifuncmain1
> FAIL: elf/ifuncmain1pic
> FAIL: elf/ifuncmain1picstatic
> FAIL: elf/ifuncmain1pie
> FAIL: elf/ifuncmain1staticpic
> FAIL: elf/ifuncmain1staticpie
> FAIL: elf/ifuncmain1vis
> FAIL: elf/ifuncmain1vispic
> FAIL: elf/ifuncmain1vispie
> FAIL: elf/ifuncmain2pic
> FAIL: elf/ifuncmain2picstatic
> FAIL: elf/ifuncmain3
> FAIL: elf/ifuncmain4picstatic
> FAIL: elf/ifuncmain5
> FAIL: elf/ifuncmain5picstatic
> FAIL: elf/ifuncmain5staticpic
>
> The solution is to replace the beqlr instructions by a beq to the end
> of the inline asm code. This fixes all the above failures.
>
> ChangeLog:
> 	* sysdeps/powerpc/ifunc-sel.h (ifunc_sel): Replace beqlr instructions
> 	by beq instructions jumping to the end of the function.

I'd prefer to remove this file.

Alan, do we still need this file?

> ---
>  ChangeLog                   | 5 +++++
>  sysdeps/powerpc/ifunc-sel.h | 7 ++++---
>  2 files changed, 9 insertions(+), 3 deletions(-)
>
> diff --git a/ChangeLog b/ChangeLog
> index 97c46a1..b18a8cd 100644
> --- a/ChangeLog
> +++ b/ChangeLog
> @@ -1,3 +1,8 @@
> +2016-07-21  Aurelien Jarno  <aurelien@aurel32.net>
> +
> +	* sysdeps/powerpc/ifunc-sel.h (ifunc_sel): Replace beqlr instructions
> +	by beq instructions jumping to the end of the function.
> +
>  2016-07-21  Szabolcs Nagy  <szabolcs.nagy@arm.com>
>
>  	* sysdeps/aarch64/libm-test-ulps: Updated.
> diff --git a/sysdeps/powerpc/ifunc-sel.h b/sysdeps/powerpc/ifunc-sel.h
> index 526d8ed..79d110f 100644
> --- a/sysdeps/powerpc/ifunc-sel.h
> +++ b/sysdeps/powerpc/ifunc-sel.h
> @@ -17,13 +17,14 @@ ifunc_sel (int (*f1) (void), int (*f2) (void), int (*f3) (void))
>  	   "addis %0,11,%2-1b@ha\n\t"
>  	   "addi %0,%0,%2-1b@l\n\t"
>  	   "cmpwi 12,1\n\t"
> -	   "beqlr\n\t"
> +	   "beq 2f\n\t"
>  	   "addis %0,11,%3-1b@ha\n\t"
>  	   "addi %0,%0,%3-1b@l\n\t"
>  	   "cmpwi 12,-1\n\t"
> -	   "beqlr\n\t"
> +	   "beq 2f\n\t"
>  	   "addis %0,11,%4-1b@ha\n\t"
> -	   "addi %0,%0,%4-1b@l"
> +	   "addi %0,%0,%4-1b@l\n\t"
> +	   "2:"
>  	   : "=r" (ret)
>  	   : "X" (&global), "X" (f1), "X" (f2), "X" (f3));
>    return ret;
> -- 
> 2.8.1
>
  
Alan Modra July 22, 2016, 3:36 a.m. UTC | #10
On Thu, Jul 21, 2016 at 02:48:09PM -0300, Tulio Magno Quites Machado Filho wrote:
> Aurelien Jarno <aurelien@aurel32.net> writes:
> > 	* sysdeps/powerpc/ifunc-sel.h (ifunc_sel): Replace beqlr instructions
> > 	by beq instructions jumping to the end of the function.
> 
> I'd prefer to remove this file.
> 
> Alan, do we still need this file?

To do without it, I think you'd need to bump the glibc binutils
requirement to 2.24, in order to have this linker fix:
https://sourceware.org/ml/binutils/2013-03/msg00299.html
  
Aurelien Jarno July 22, 2016, 7:07 a.m. UTC | #11
On 2016-07-22 13:06, Alan Modra wrote:
> On Thu, Jul 21, 2016 at 02:48:09PM -0300, Tulio Magno Quites Machado Filho wrote:
> > Aurelien Jarno <aurelien@aurel32.net> writes:
> > > 	* sysdeps/powerpc/ifunc-sel.h (ifunc_sel): Replace beqlr instructions
> > > 	by beq instructions jumping to the end of the function.
> > 
> > I'd prefer to remove this file.
> > 
> > Alan, do we still need this file?
> 
> To do without it, I think you'd need to bump the glibc binutils
> requirement to 2.24, in order to have this linker fix:
> https://sourceware.org/ml/binutils/2013-03/msg00299.html

In that case, one possibility is to support ifunc only when the
installed binutils is at least 2.24. This is basically just changing
the minimum version in the "Prevent building POWER8 code without support
in assembler" patch.

Aurelien
  
Adhemerval Zanella July 22, 2016, 2:25 p.m. UTC | #12
On 21/07/2016 14:48, Tulio Magno Quites Machado Filho wrote:
> Aurelien Jarno <aurelien@aurel32.net> writes:
> 
>> On 32-bit PowerPC GCC 6 always saves the PIC register on the stack in
>> the prologue and adjust the stack in the epilogue. It is therefore not
>> possible anymore to just exit the function in the inline asm code,
>> otherwise it corrupts the stack pointer. This causes the following tests
>> to fail when using GCC 6:
>>
>> FAIL: elf/ifuncmain1
>> FAIL: elf/ifuncmain1pic
>> FAIL: elf/ifuncmain1picstatic
>> FAIL: elf/ifuncmain1pie
>> FAIL: elf/ifuncmain1staticpic
>> FAIL: elf/ifuncmain1staticpie
>> FAIL: elf/ifuncmain1vis
>> FAIL: elf/ifuncmain1vispic
>> FAIL: elf/ifuncmain1vispie
>> FAIL: elf/ifuncmain2pic
>> FAIL: elf/ifuncmain2picstatic
>> FAIL: elf/ifuncmain3
>> FAIL: elf/ifuncmain4picstatic
>> FAIL: elf/ifuncmain5
>> FAIL: elf/ifuncmain5picstatic
>> FAIL: elf/ifuncmain5staticpic
>>
>> The solution is to replace the beqlr instructions by a beq to the end
>> of the inline asm code. This fixes all the above failures.
>>
>> ChangeLog:
>> 	* sysdeps/powerpc/ifunc-sel.h (ifunc_sel): Replace beqlr instructions
>> 	by beq instructions jumping to the end of the function.
> 
> I'd prefer to remove this file.
> 
> Alan, do we still need this file?
> 
>> ---
>>  ChangeLog                   | 5 +++++
>>  sysdeps/powerpc/ifunc-sel.h | 7 ++++---
>>  2 files changed, 9 insertions(+), 3 deletions(-)
>>
>> diff --git a/ChangeLog b/ChangeLog
>> index 97c46a1..b18a8cd 100644
>> --- a/ChangeLog
>> +++ b/ChangeLog
>> @@ -1,3 +1,8 @@
>> +2016-07-21  Aurelien Jarno  <aurelien@aurel32.net>
>> +
>> +	* sysdeps/powerpc/ifunc-sel.h (ifunc_sel): Replace beqlr instructions
>> +	by beq instructions jumping to the end of the function.
>> +
>>  2016-07-21  Szabolcs Nagy  <szabolcs.nagy@arm.com>
>>
>>  	* sysdeps/aarch64/libm-test-ulps: Updated.
>> diff --git a/sysdeps/powerpc/ifunc-sel.h b/sysdeps/powerpc/ifunc-sel.h
>> index 526d8ed..79d110f 100644
>> --- a/sysdeps/powerpc/ifunc-sel.h
>> +++ b/sysdeps/powerpc/ifunc-sel.h
>> @@ -17,13 +17,14 @@ ifunc_sel (int (*f1) (void), int (*f2) (void), int (*f3) (void))
>>  	   "addis %0,11,%2-1b@ha\n\t"
>>  	   "addi %0,%0,%2-1b@l\n\t"
>>  	   "cmpwi 12,1\n\t"
>> -	   "beqlr\n\t"
>> +	   "beq 2f\n\t"
>>  	   "addis %0,11,%3-1b@ha\n\t"
>>  	   "addi %0,%0,%3-1b@l\n\t"
>>  	   "cmpwi 12,-1\n\t"
>> -	   "beqlr\n\t"
>> +	   "beq 2f\n\t"
>>  	   "addis %0,11,%4-1b@ha\n\t"
>> -	   "addi %0,%0,%4-1b@l"
>> +	   "addi %0,%0,%4-1b@l\n\t"
>> +	   "2:"
>>  	   : "=r" (ret)
>>  	   : "X" (&global), "X" (f1), "X" (f2), "X" (f3));
>>    return ret;
>> -- 
>> 2.8.1
>>
> 

I think the idea of these function are to solely test ifunc implementation
and I think we should keep them.

Also, if we are fixing it here it would be a good idea to also fix the
same implementation on gold/binutils (gold/testsuite/ifunc-sel.h).
  
Tulio Magno Quites Machado Filho July 22, 2016, 2:25 p.m. UTC | #13
Aurelien Jarno <aurelien@aurel32.net> writes:

> On 2016-07-22 13:06, Alan Modra wrote:
>> On Thu, Jul 21, 2016 at 02:48:09PM -0300, Tulio Magno Quites Machado Filho wrote:
>> > Aurelien Jarno <aurelien@aurel32.net> writes:
>> > > 	* sysdeps/powerpc/ifunc-sel.h (ifunc_sel): Replace beqlr instructions
>> > > 	by beq instructions jumping to the end of the function.
>> > 
>> > I'd prefer to remove this file.
>> > 
>> > Alan, do we still need this file?
>> 
>> To do without it, I think you'd need to bump the glibc binutils
>> requirement to 2.24, in order to have this linker fix:
>> https://sourceware.org/ml/binutils/2013-03/msg00299.html

Great!  Thanks!
I run some tests on ppc, ppc64 and ppc64le without this file and I noticed
just one failure from elf/ifuncmain6pie using Binutils 2.26.1 on ppc.
Are there any other requirements to get it working?

> In that case, one possibility is to support ifunc only when the
> installed binutils is at least 2.24. This is basically just changing
> the minimum version in the "Prevent building POWER8 code without support
> in assembler" patch.

In that case and due to the error I mentioned previously, I prefer to carry
this file a little longer with your fix and a source code comment, i.e.:
/* TODO: Remove this file when the minimum required Binutils is 2.24.  The
   following implementation is required when using a linker that doesn't have
   the following fix:
   https://sourceware.org/ml/binutils/2013-03/msg00299.html  */
  
Alan Modra July 22, 2016, 3:33 p.m. UTC | #14
On Fri, Jul 22, 2016 at 11:25:38AM -0300, Tulio Magno Quites Machado Filho wrote:
> Aurelien Jarno <aurelien@aurel32.net> writes:
> 
> > On 2016-07-22 13:06, Alan Modra wrote:
> >> On Thu, Jul 21, 2016 at 02:48:09PM -0300, Tulio Magno Quites Machado Filho wrote:
> >> > Aurelien Jarno <aurelien@aurel32.net> writes:
> >> > > 	* sysdeps/powerpc/ifunc-sel.h (ifunc_sel): Replace beqlr instructions
> >> > > 	by beq instructions jumping to the end of the function.
> >> > 
> >> > I'd prefer to remove this file.
> >> > 
> >> > Alan, do we still need this file?
> >> 
> >> To do without it, I think you'd need to bump the glibc binutils
> >> requirement to 2.24, in order to have this linker fix:
> >> https://sourceware.org/ml/binutils/2013-03/msg00299.html
> 
> Great!  Thanks!
> I run some tests on ppc, ppc64 and ppc64le without this file and I noticed
> just one failure from elf/ifuncmain6pie using Binutils 2.26.1 on ppc.
> Are there any other requirements to get it working?

Yes.  Rewrite ld.so ifunc handling to process ifunc relocs last,
globally.

Without that, ifuncmain6pie will fail on any target that uses the GOT
to return the address of "one" from foo_ifunc.  Currently, foo_ifunc
is called during processing of ifuncmod6.so dynamic relocations,
which happens before ifuncmain6pie has been relocated.  That means
foo_ifunc returns an unrelocated GOT entry.
  
Benjamin Herrenschmidt July 24, 2016, 8:14 p.m. UTC | #15
On Thu, 2016-07-21 at 17:23 +0200, Andreas Schwab wrote:
> Florian Weimer <fweimer@redhat.com> writes:
> 
> > 
> > Yes, I figured that out in the meantime.  Is “bcl 20,31” always
> > used for
> > that?  The second opcode argument doesn't really matter, after
> > all. 
> 
> It's what gcc uses.  I don't know if there is any deeper meaning
> behind that particular encoding.

There is. It tells the CPU not to push the address onto the link
stack. Without this, you end up with an out of sync return stack
and so your subsequent real returns get mispredicted.

Cheers,
Ben.
  
Florian Weimer July 25, 2016, 8:25 a.m. UTC | #16
On 07/24/2016 10:14 PM, Benjamin Herrenschmidt wrote:
> On Thu, 2016-07-21 at 17:23 +0200, Andreas Schwab wrote:
>> Florian Weimer <fweimer@redhat.com> writes:
>>
>>>
>>> Yes, I figured that out in the meantime.  Is “bcl 20,31” always
>>> used for
>>> that?  The second opcode argument doesn't really matter, after
>>> all.
>>
>> It's what gcc uses.  I don't know if there is any deeper meaning
>> behind that particular encoding.
>>
> There is. It tells the CPU not to push the address onto the link
> stack. Without this, you end up with an out of sync return stack
> and so your subsequent real returns get mispredicted.

Yes, a colleague told me that as well, thanks.  Do you know if only this 
specific encoding has this property, or are there many equivalent 
encodings which have the same effect?

Thanks,
Florian
  
Andreas Schwab July 25, 2016, 8:47 a.m. UTC | #17
On Mo, Jul 25 2016, Florian Weimer <fweimer@redhat.com> wrote:

> Yes, a colleague told me that as well, thanks.  Do you know if only this
> specific encoding has this property, or are there many equivalent
> encodings which have the same effect?

See the Programming Note near the end of section 2.4 in the PowerISA
Book I.  It mentions only this special form.

Andreas.
  
Aurelien Jarno Aug. 2, 2016, 10:43 a.m. UTC | #18
On 2016-07-21 14:48, Tulio Magno Quites Machado Filho wrote:
> Aurelien Jarno <aurelien@aurel32.net> writes:
> 
> > On 32-bit PowerPC GCC 6 always saves the PIC register on the stack in
> > the prologue and adjust the stack in the epilogue. It is therefore not
> > possible anymore to just exit the function in the inline asm code,
> > otherwise it corrupts the stack pointer. This causes the following tests
> > to fail when using GCC 6:
> >
> > FAIL: elf/ifuncmain1
> > FAIL: elf/ifuncmain1pic
> > FAIL: elf/ifuncmain1picstatic
> > FAIL: elf/ifuncmain1pie
> > FAIL: elf/ifuncmain1staticpic
> > FAIL: elf/ifuncmain1staticpie
> > FAIL: elf/ifuncmain1vis
> > FAIL: elf/ifuncmain1vispic
> > FAIL: elf/ifuncmain1vispie
> > FAIL: elf/ifuncmain2pic
> > FAIL: elf/ifuncmain2picstatic
> > FAIL: elf/ifuncmain3
> > FAIL: elf/ifuncmain4picstatic
> > FAIL: elf/ifuncmain5
> > FAIL: elf/ifuncmain5picstatic
> > FAIL: elf/ifuncmain5staticpic
> >
> > The solution is to replace the beqlr instructions by a beq to the end
> > of the inline asm code. This fixes all the above failures.
> >
> > ChangeLog:
> > 	* sysdeps/powerpc/ifunc-sel.h (ifunc_sel): Replace beqlr instructions
> > 	by beq instructions jumping to the end of the function.
> 
> I'd prefer to remove this file.
> 
> Alan, do we still need this file?

Now that 2.25 is open for development, what should we do? I think we can
get the patch in, and try to remove this file in a second step.

Aurelien
  
Tulio Magno Quites Machado Filho Aug. 2, 2016, 2:44 p.m. UTC | #19
Aurelien Jarno <aurelien@aurel32.net> writes:

> On 2016-07-21 14:48, Tulio Magno Quites Machado Filho wrote:
>> Aurelien Jarno <aurelien@aurel32.net> writes:
>> 
>> > On 32-bit PowerPC GCC 6 always saves the PIC register on the stack in
>> > the prologue and adjust the stack in the epilogue. It is therefore not
>> > possible anymore to just exit the function in the inline asm code,
>> > otherwise it corrupts the stack pointer. This causes the following tests
>> > to fail when using GCC 6:
>> >
>> > FAIL: elf/ifuncmain1
>> > FAIL: elf/ifuncmain1pic
>> > FAIL: elf/ifuncmain1picstatic
>> > FAIL: elf/ifuncmain1pie
>> > FAIL: elf/ifuncmain1staticpic
>> > FAIL: elf/ifuncmain1staticpie
>> > FAIL: elf/ifuncmain1vis
>> > FAIL: elf/ifuncmain1vispic
>> > FAIL: elf/ifuncmain1vispie
>> > FAIL: elf/ifuncmain2pic
>> > FAIL: elf/ifuncmain2picstatic
>> > FAIL: elf/ifuncmain3
>> > FAIL: elf/ifuncmain4picstatic
>> > FAIL: elf/ifuncmain5
>> > FAIL: elf/ifuncmain5picstatic
>> > FAIL: elf/ifuncmain5staticpic
>> >
>> > The solution is to replace the beqlr instructions by a beq to the end
>> > of the inline asm code. This fixes all the above failures.
>> >
>> > ChangeLog:
>> > 	* sysdeps/powerpc/ifunc-sel.h (ifunc_sel): Replace beqlr instructions
>> > 	by beq instructions jumping to the end of the function.
>> 
>> I'd prefer to remove this file.
>> 
>> Alan, do we still need this file?
>
> Now that 2.25 is open for development, what should we do? I think we can
> get the patch in, and try to remove this file in a second step.

I agree.  As Alan explained, we still need it.

Thanks!
  
Aurelien Jarno Aug. 2, 2016, 10:23 p.m. UTC | #20
On 2016-08-02 11:44, Tulio Magno Quites Machado Filho wrote:
> Aurelien Jarno <aurelien@aurel32.net> writes:
> 
> > On 2016-07-21 14:48, Tulio Magno Quites Machado Filho wrote:
> >> Aurelien Jarno <aurelien@aurel32.net> writes:
> >> 
> >> > On 32-bit PowerPC GCC 6 always saves the PIC register on the stack in
> >> > the prologue and adjust the stack in the epilogue. It is therefore not
> >> > possible anymore to just exit the function in the inline asm code,
> >> > otherwise it corrupts the stack pointer. This causes the following tests
> >> > to fail when using GCC 6:
> >> >
> >> > FAIL: elf/ifuncmain1
> >> > FAIL: elf/ifuncmain1pic
> >> > FAIL: elf/ifuncmain1picstatic
> >> > FAIL: elf/ifuncmain1pie
> >> > FAIL: elf/ifuncmain1staticpic
> >> > FAIL: elf/ifuncmain1staticpie
> >> > FAIL: elf/ifuncmain1vis
> >> > FAIL: elf/ifuncmain1vispic
> >> > FAIL: elf/ifuncmain1vispie
> >> > FAIL: elf/ifuncmain2pic
> >> > FAIL: elf/ifuncmain2picstatic
> >> > FAIL: elf/ifuncmain3
> >> > FAIL: elf/ifuncmain4picstatic
> >> > FAIL: elf/ifuncmain5
> >> > FAIL: elf/ifuncmain5picstatic
> >> > FAIL: elf/ifuncmain5staticpic
> >> >
> >> > The solution is to replace the beqlr instructions by a beq to the end
> >> > of the inline asm code. This fixes all the above failures.
> >> >
> >> > ChangeLog:
> >> > 	* sysdeps/powerpc/ifunc-sel.h (ifunc_sel): Replace beqlr instructions
> >> > 	by beq instructions jumping to the end of the function.
> >> 
> >> I'd prefer to remove this file.
> >> 
> >> Alan, do we still need this file?
> >
> > Now that 2.25 is open for development, what should we do? I think we can
> > get the patch in, and try to remove this file in a second step.
> 
> I agree.  As Alan explained, we still need it.

Thanks, I have pushed both patches.

Aurelien
  

Patch

diff --git a/ChangeLog b/ChangeLog
index 97c46a1..b18a8cd 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@ 
+2016-07-21  Aurelien Jarno  <aurelien@aurel32.net>
+
+	* sysdeps/powerpc/ifunc-sel.h (ifunc_sel): Replace beqlr instructions
+	by beq instructions jumping to the end of the function.
+
 2016-07-21  Szabolcs Nagy  <szabolcs.nagy@arm.com>
 
 	* sysdeps/aarch64/libm-test-ulps: Updated.
diff --git a/sysdeps/powerpc/ifunc-sel.h b/sysdeps/powerpc/ifunc-sel.h
index 526d8ed..79d110f 100644
--- a/sysdeps/powerpc/ifunc-sel.h
+++ b/sysdeps/powerpc/ifunc-sel.h
@@ -17,13 +17,14 @@  ifunc_sel (int (*f1) (void), int (*f2) (void), int (*f3) (void))
 	   "addis %0,11,%2-1b@ha\n\t"
 	   "addi %0,%0,%2-1b@l\n\t"
 	   "cmpwi 12,1\n\t"
-	   "beqlr\n\t"
+	   "beq 2f\n\t"
 	   "addis %0,11,%3-1b@ha\n\t"
 	   "addi %0,%0,%3-1b@l\n\t"
 	   "cmpwi 12,-1\n\t"
-	   "beqlr\n\t"
+	   "beq 2f\n\t"
 	   "addis %0,11,%4-1b@ha\n\t"
-	   "addi %0,%0,%4-1b@l"
+	   "addi %0,%0,%4-1b@l\n\t"
+	   "2:"
 	   : "=r" (ret)
 	   : "X" (&global), "X" (f1), "X" (f2), "X" (f3));
   return ret;