buglibffcall - foreign function call libraries - Bugs: bug #52502, trampoline broken on 64-bit little...

 
 

bug #52502: trampoline broken on 64-bit little endian MIPS

Submitted by:  Sébastien Villemot <svillemot>
Submitted on:  Sat 25 Nov 2017 01:54:45 PM UTC  
 
Category: NoneSeverity: 3 - Normal
Item Group: crashStatus: Fixed
Privacy: PublicAssigned to: Bruno Haible <haible>
Open/Closed: Open

Add a New Comment(Rich Markup)
   

You are not logged in

Please log in, so followups can be emailed to you.

 

(Jump to the original submission Jump to the original submission)

Sun 26 Nov 2017 11:36:41 AM UTC, comment #8:

Great, thanks for fixing this in the git!

Sébastien Villemot <svillemot>
Sat 25 Nov 2017 09:13:48 PM UTC, comment #7:

Thanks Sébastien!

> what matters in my patch is to have the jump (J) before the NOP. When the NOP comes first, I get a bus error.


I see. This is consistent with https://stackoverflow.com/questions/3807480 . I had seen similar things with IRIX 4 years ago, and thought that it did not apply to modern hardware any more. Apparently it does.

Fixed through these two commits:
http://git.savannah.gnu.org/gitweb/?p=libffcall.git;a=commitdiff;h=7bb35bc0149b1034f4b6ff5bb6df440024e4c77e
http://git.savannah.gnu.org/gitweb/?p=libffcall.git;a=commitdiff;h=0363b6fda4de25be575c0e7a090f8fa8032ee54d

Bruno Haible <haible>
Project AdministratorIn charge of this item.
Sat 25 Nov 2017 08:55:58 PM UTC, comment #6:

For info, here is the hardware on which I am making the test (excerpt from /proc/cpuinfo):

cpu model : Cavium Octeon III V0.2 FPU V0.0
isa : mips1 mips2 mips3 mips4 mips5 mips64r2

Kernel:
Linux eller 4.9.0-4-octeon #1 SMP Debian 4.9.51-1 (2017-09-28) mips64 GNU/Linux

And the userland in Debian unstable/sid.

Sébastien Villemot <svillemot>
Sat 25 Nov 2017 08:39:43 PM UTC, comment #5:

Apparently what matters in my patch is to have the jump (J) before the NOP. When the NOP comes first, I get a bus error.

Sébastien Villemot <svillemot>
Sat 25 Nov 2017 07:50:15 PM UTC, comment #4:

Replacing ICACHE by BCACHE does not fix the crash.

So as strange as it may seem, my patch is for the time being the only solution that I have for this issue.

Sébastien Villemot <svillemot>
Sat 25 Nov 2017 07:25:20 PM UTC, comment #3:

Indeed the instructions happen to commute, I had not realized that.

But my patch fixes a real crash, I could verify it on a mips64el box. So this is very puzzling.

Note that I have access to real mips64el hardware (not an emulator as you do), I don't know if that makes a difference.

Here is a log of the build failure:
https://buildd.debian.org/status/fetch.php?pkg=ffcall&arch=mips64el&ver=2.0-1&stamp=1510832475&raw=0

I am going to test the cache thing and tell you whether it makes a difference.

Sébastien Villemot <svillemot>
Sat 25 Nov 2017 05:10:38 PM UTC, comment #2:

> assembly instructions are hardcoded in big-endian mode


Indeed. But it cannot provoke a bug because the instructions happen to commute:

* ld $2,24($25) DF 22 00 18
* ld $3,32($25) DF 23 00 20
* sd $3,0($2) FC 43 00 00
* ld $25,40($25) DF 39 00 28
* j $25 03 20 00 08
* nop 00 00 00 00

does the same thing as

* ld $3,32($25) DF 23 00 20
* ld $2,24($25) DF 22 00 18
* ld $25,40($25) DF 39 00 28
* sd $3,0($2) FC 43 00 00
* nop 00 00 00 00
* j $25 03 20 00 08

But it is a maintainably problem anyway, therefore I'm going to fix it by storing 32-bit words.

Bruno Haible <haible>
Project AdministratorIn charge of this item.
Sat 25 Nov 2017 04:49:50 PM UTC, comment #1:

This is very strange. For me, libffcall-2.0 passes its "make check" tests - including trampoline - on mips64el and mips64eb.

Here are details about my mips64el configuration:
/etc/debian_version: Debian 8.7
uname -srm: Linux 3.16.0-4-5kc-malta mips64
Hardware: qemu-system-mips64el
Environment variables: CC="gcc -mabi=64" CXX="g++ -mabi=64"

Can you give details about yours?

> that I am going to apply to the Debian package


Please hold on, until we have investigated the issue.

The usual cause of a crash in test1 is when the cache flushing (implemented in function cacheflush in glibc, as a system call) does not work.

Can you try changing this line in trampoline.c:
cacheflush(function_x,TRAMP_CODE_LENGTH,ICACHE);
to
cacheflush(function_x,TRAMP_CODE_LENGTH,BCACHE);
and see whether this helps?

Bruno Haible <haible>
Project AdministratorIn charge of this item.
Sat 25 Nov 2017 01:54:45 PM UTC, original submission:

On 64-bit little endian MIPS (mips64el in Debian), test1 segfaults.

This is because assembly instructions are hardcoded in big-endian mode.

I attach a patch that fixes the issue (and that I am going to apply to the Debian package).

Sébastien Villemot <svillemot>

 

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attach File(s):
   
   
Comment:
   

Attached Files

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -unavailable- added by haible (Posted a comment)
  • -unavailable- added by svillemot (Submitted the item)
  •  

    Do you think this task is very important?
    If so, you can click here to add your encouragement to it.
    This task has 0 encouragements so far.

    Only logged-in users can vote.

     

    Please enter the title of George Orwell's famous dystopian book (it's a date):

     

     

    Follow 5 latest changes.

    Date Changed By Updated Field Previous Value => Replaced By
    Sat 25 Nov 2017 09:13:48 PM UTChaibleItem Groupport=>crash
      StatusNeed Info=>Fixed
    Sat 25 Nov 2017 04:49:50 PM UTChaibleStatusNone=>Need Info
      Assigned toNone=>haible
    Sat 25 Nov 2017 01:54:45 PM UTCsvillemotAttached File-=>Added trampoline-mips64el.patch, #42481

    Back to the top


    Powered by Savane 3.1-cleanup1