#12355 closed bug (fixed)

Invalid assembly in foreign prim

Reported by: osa1 Owned by:
Priority: normal Milestone: 8.0.2
Component: Compiler Version: 8.1
Keywords: Cc:
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: None/Unknown Test Case:
Blocked By: Blocking:
Related Tickets: Differential Rev(s): Phab:D2563
Wiki Page:


➜  prim_panic ghc Lib.hs
[1 of 1] Compiling Lib              ( Lib.hs, Lib.o )
/tmp/ghc14440_0/ghc_2.s: Assembler messages:

/tmp/ghc14440_0/ghc_2.s:65:0: error:
     Error: number of operands mismatch for `jmp'
`gcc' failed in phase `Assembler'. (Exit code: 1)
➜  prim_panic cat Lib.hs
{-# LANGUAGE GHCForeignImportPrim, UnliftedFFITypes, MagicHash #-}

module Lib where

import GHC.Prim

foreign import prim f1 :: Int# -> Int#

Tried with: HEAD as of today, 8.0.1.

Change History (9)

comment:1 Changed 22 months ago by bgamari

I've proposed to add this example to the testsuite in Phab:D2377.

comment:2 Changed 22 months ago by simonpj

Does anyone know what the problem actually is here?

comment:3 Changed 22 months ago by bgamari

Something is indeed quite fishy. The C-- for this code is as follows,

[section ""data" . Lib.f1_closure" {
         const Lib.f1_info;
 Lib.f1_entry() //  [R2]
         { info_tbl: [(cG7,
                       label: Lib.f1_info
                       rep:HeapRep static { Fun {arity: 1 fun_type: ArgSpec 4} })]
           stack_info: arg_space: 8 updfr_space: Just 8
           _B1::I64 = R2;
           goto cG9;
           R1 = _B1::I64;
           call (R1) args: 8, res: 0, upd: 8;

It looks like the target is being pretty-printed as mempty.

comment:4 Changed 22 months ago by simonpj

Fishy indeed: can you probe further? Thanks

comment:5 Changed 22 months ago by Ben Gamari <ben@…>

In afec447/ghc:

testsuite: Add testcase for #12355

Test Plan: Validate

Reviewers: austin, osa1

Reviewed By: osa1

Subscribers: thomie

Differential Revision: https://phabricator.haskell.org/D2377

GHC Trac Issues: #12355

comment:6 Changed 19 months ago by Ben Gamari <ben@…>

In eda5a4a/ghc:

testsuite: Mark test for #12355 as unbroken on Darwin.

Somehow this testcase works on Darwin but not on Linux. This deserves
further investigation.

comment:7 Changed 19 months ago by hsyl20

Differential Rev(s): 2563
Status: newpatch

The foreign symbol name is missing. With the "prim" calling convention, the empty entity string doesn't get replaced with the function name "f1" (while it does with the "ccall" convention). Hence the "jmp" without target in the generated asm.

Proposed patch: https://phabricator.haskell.org/D2563

comment:8 Changed 18 months ago by Ben Gamari <ben@…>

In 6c739326/ghc:

Check for empty entity string in "prim" foreign imports

Foreign imports with "prim" convention require a valid symbol identifier
(see linked issue). We check this.

Fix line too long

Test Plan: Validate

Reviewers: austin, bgamari

Reviewed By: bgamari

Subscribers: thomie

Differential Revision: https://phabricator.haskell.org/D2563

GHC Trac Issues: #12355

comment:9 Changed 18 months ago by bgamari

Differential Rev(s): 2563Phab:D2563
Milestone: 8.0.2
Resolution: fixed
Status: patchclosed
Note: See TracTickets for help on using tickets.