|
#5967: incompatible implicit declaration of function 'memcpy'
------------------------------+--------------------------------------------- Reporter: nomeata | Owner: Type: bug | Status: new Priority: normal | Component: Compiler Version: 7.4.1 | Keywords: Os: Unknown/Multiple | Architecture: Unknown/Multiple Failure: Other | Testcase: Blockedby: | Blocking: Related: | ------------------------------+--------------------------------------------- In various build logs of Haskell packages on (at least) mips, mipsel, s390 and s390x, I find the above warnings for the generated .hc files. In one case (aeson), it even leads to an error, aborting the build. Here is the full build log: https://buildd.debian.org/status/fetch.php?pkg=haskell- aeson&arch=mips&ver=0.6.0.0-4&stamp=1330462970 and here are more of those: https://buildd.debian.org/status/package.php?p=haskell-aeson It does not occur on other “strange” architectures such as arm and armel. Thanks, Joachim -- Ticket URL: <http://hackage.haskell.org/trac/ghc/ticket/5967> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler _______________________________________________ Glasgow-haskell-bugs mailing list [hidden email] http://www.haskell.org/mailman/listinfo/glasgow-haskell-bugs |
|
#5967: incompatible implicit declaration of function 'memcpy'
------------------------------+--------------------------------------------- Reporter: nomeata | Owner: Type: bug | Status: new Priority: normal | Component: Compiler Version: 7.4.1 | Keywords: Os: Unknown/Multiple | Architecture: Unknown/Multiple Failure: Other | Testcase: Blockedby: | Blocking: Related: | ------------------------------+--------------------------------------------- Comment(by nomeata): Looking at the generated C code right now. The conflicting definitions of memcpy are: {{{ ;EF_(memcpy); {void * (*ghcFunPtr)(void *, void *, W_); ghcFunPtr = ((void * (*)(void *, void *, W_))(W_)&memcpy); _sbJq = (W_)ghcFunPtr((void *)_ccwP, (void *)_ccwO, _sbJk);;} }}} and {{{ *((P_)_cgnM) = (W_)&stg_MUT_ARR_PTRS_DIRTY_info; _cgnO = (_cgnP+12) + (_cgnQ << 0x2U); _cgnN = _cgnK * 0x4U; if ((W_)(_cgnP == _cgnM)) goto _cgnR; memcpy((void *)(_cgnM+12), (void *)_cgnO, _cgnN); }}} Where _cd8l is of type {{{W_}}} and {{{EF_}}} is defined in {{{includes/Stg.h}}} as: {{{ #define EF_(f) extern StgFunPtr f(void) }}} with {{{ typedef void *(*(*StgFunPtr)(void))(void); }}} It seems that there are two ways of calling the external function, one with it having type StgFunPtr and coercing it before use, and one with assuming it to have the type it has. If both are used in the same file, things break. Maybe the first style comes from a standard FFI call, and the second style somehow from “more internal” code, as it works with MUT_ARR_PTRS? {{{doCopyMutableByteArrayOp}}} or a related function in source:compiler/codeGen/StgCmmPrim.hs is a hot candidate, as they call {{{emitMemcpyCall}}}. -- Ticket URL: <http://hackage.haskell.org/trac/ghc/ticket/5967#comment:1> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler _______________________________________________ Glasgow-haskell-bugs mailing list [hidden email] http://www.haskell.org/mailman/listinfo/glasgow-haskell-bugs |
|
In reply to this post by GHC
#5967: incompatible implicit declaration of function 'memcpy'
------------------------------+--------------------------------------------- Reporter: nomeata | Owner: Type: bug | Status: new Priority: normal | Component: Compiler Version: 7.4.1 | Keywords: Os: Unknown/Multiple | Architecture: Unknown/Multiple Failure: Other | Testcase: Blockedby: | Blocking: Related: | ------------------------------+--------------------------------------------- Comment(by nomeata): Ok, here is almost a minimal example: {{{ {-# LANGUAGE MagicHash, ForeignFunctionInterface #-} module Test where import GHC.Prim import Foreign.Ptr import Foreign.C foreign import ccall unsafe "memcpy" memcpy :: Ptr a -> Ptr a -> CSize -> IO (Ptr ()) test = copyByteArray# }}} Compiling this yields {{{ '/usr/bin/gcc' '-fno-stack-protector' '-Wl,--hash-size=31' '-Wl,--reduce- memory-overheads' '-x' 'c' '/tmp/ghc13588_0/ghc13588_0.hc' \ '-o' '/tmp/ghc13588_0/ghc13588_0.s' '-fwrapv' '-fno-strict-aliasing' '-S' '-Wimplicit' '-O' '-D__GLASGOW_HASKELL__=704'\ '-DNO_REGS' '-DUSE_MINIINTERPRETER' '-I' '.' '-I' '/usr/lib/ghc/base-4.5.0.0/include' '-I' '/usr/lib/ghc/include'\ /tmp/ghc13588_0/ghc13588_0.hc: In function ‘Test_test_entry’: /tmp/ghc13588_0/ghc13588_0.hc:29:1: warning: implicit declaration of function ‘memcpy’ [-Wimplicit- function-declaration] /tmp/ghc13588_0/ghc13588_0.hc:29:1: warning: incompatible implicit declaration of built-in function ‘memcpy’ [enabled by default] /tmp/ghc13588_0/ghc13588_0.hc: In function ‘Test_zdwccall_entry’: /tmp/ghc13588_0/ghc13588_0.hc:56:2: warning: conflicting types for built-in function ‘memcpy’ [enabled by default] }}} But if I then modify the .hc file and move the {{{memcpy((void *)_c19o, (void *)_c19n, _c19m);}}} call to the bottom of the file, after the {{{EF_(memcpy)}}}, then I get: {{{ /tmp/ghc13380_0/ghc13380_0.hc: In function ‘Test_zdwccall_entry’: /tmp/ghc13380_0/ghc13380_0.hc:43:2: warning: conflicting types for built- in function ‘memcpy’ [enabled by default] /tmp/ghc13380_0/ghc13380_0.hc: In function ‘Test_test_entry’: /tmp/ghc13380_0/ghc13380_0.hc:181:1: warning: implicit declaration of function ‘memcpy’ [-Wimplicit-function-declaration] /tmp/ghc13380_0/ghc13380_0.hc:74:2: note: previous declaration of ‘memcpy’ was here /tmp/ghc13380_0/ghc13380_0.hc:181:1: error: incompatible implicit declaration of function ‘memcpy’ /tmp/ghc13380_0/ghc13380_0.hc:74:2: note: previous implicit declaration of ‘memcpy’ was here }}} so the order of declarations gets important. So a solution seems to be to generate the {{{EF_(...)}}} style call also for memcpy (is there a runtime performance penalty)? The code to look at seems to be source:compiler/cmm/PprC.hs, especially {{{pprStmt}}}, where a memcpy can occur as a {{{CmmPrim MO_Memcpy}}} or as a {{{CmmCall}}} (which does the EF_ stuff). Commentary/Compiler/Backends/PprC#Prototypes seems to be related. -- Ticket URL: <http://hackage.haskell.org/trac/ghc/ticket/5967#comment:2> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler _______________________________________________ Glasgow-haskell-bugs mailing list [hidden email] http://www.haskell.org/mailman/listinfo/glasgow-haskell-bugs |
|
In reply to this post by GHC
#5967: incompatible implicit declaration of function 'memcpy'
------------------------------+--------------------------------------------- Reporter: nomeata | Owner: Type: bug | Status: new Priority: normal | Component: Compiler Version: 7.4.1 | Keywords: Os: Unknown/Multiple | Architecture: Unknown/Multiple Failure: Other | Testcase: Blockedby: | Blocking: Related: | ------------------------------+--------------------------------------------- Comment(by nomeata): A git blame reveals that the treatment of memcpy as a primop came in [log:1cf7994d1c0d1acfe90ab60a3d5c7ec76f13e813 this commit]: {{{ commit 1cf7994d1c0d1acfe90ab60a3d5c7ec76f13e813 Author: David Terei <[hidden email]> Date: Thu Jun 23 01:21:03 2011 -0700 Add support for new mem primops to C backend }}} -- Ticket URL: <http://hackage.haskell.org/trac/ghc/ticket/5967#comment:3> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler _______________________________________________ Glasgow-haskell-bugs mailing list [hidden email] http://www.haskell.org/mailman/listinfo/glasgow-haskell-bugs |
|
In reply to this post by GHC
#5967: incompatible implicit declaration of function 'memcpy'
---------------------------------+------------------------------------------ Reporter: nomeata | Owner: Type: bug | Status: new Priority: high | Milestone: 7.4.2 Component: Compiler | Version: 7.4.1 Keywords: | Os: Unknown/Multiple Architecture: Unknown/Multiple | Failure: Other Difficulty: Unknown | Testcase: Blockedby: | Blocking: Related: | ---------------------------------+------------------------------------------ Changes (by simonmar): * priority: normal => high * difficulty: => Unknown * milestone: => 7.4.2 Comment: As I recall it's hard to get rid of the warnings. But the error is a different matter. -- Ticket URL: <http://hackage.haskell.org/trac/ghc/ticket/5967#comment:4> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler _______________________________________________ Glasgow-haskell-bugs mailing list [hidden email] http://www.haskell.org/mailman/listinfo/glasgow-haskell-bugs |
|
In reply to this post by GHC
#5967: incompatible implicit declaration of function 'memcpy'
---------------------------------+------------------------------------------ Reporter: nomeata | Owner: Type: bug | Status: new Priority: high | Milestone: 7.4.2 Component: Compiler | Version: 7.4.1 Keywords: | Os: Unknown/Multiple Architecture: Unknown/Multiple | Failure: Other Difficulty: Unknown | Testcase: Blockedby: | Blocking: Related: | ---------------------------------+------------------------------------------ Changes (by PHO): * cc: pho@… (added) -- Ticket URL: <http://hackage.haskell.org/trac/ghc/ticket/5967#comment:5> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler _______________________________________________ Glasgow-haskell-bugs mailing list [hidden email] http://www.haskell.org/mailman/listinfo/glasgow-haskell-bugs |
|
In reply to this post by GHC
#5967: incompatible implicit declaration of function 'memcpy'
---------------------------------+------------------------------------------ Reporter: nomeata | Owner: Type: bug | Status: new Priority: high | Milestone: 7.4.2 Component: Compiler | Version: 7.4.1 Keywords: | Os: Unknown/Multiple Architecture: Unknown/Multiple | Failure: Other Difficulty: Unknown | Testcase: Blockedby: | Blocking: Related: | ---------------------------------+------------------------------------------ Comment(by nomeata): Here is a possible patch against ghc-7.4.1; maybe not the cleanest solution. Maybe the proper solution is to forbid Haskell code to foreign import memcpy and expect them to use the primop? -- Ticket URL: <http://hackage.haskell.org/trac/ghc/ticket/5967#comment:6> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler _______________________________________________ Glasgow-haskell-bugs mailing list [hidden email] http://www.haskell.org/mailman/listinfo/glasgow-haskell-bugs |
|
In reply to this post by GHC
#5967: incompatible implicit declaration of function 'memcpy'
---------------------------------+------------------------------------------ Reporter: nomeata | Owner: pcapriotti Type: bug | Status: new Priority: high | Milestone: 7.4.2 Component: Compiler | Version: 7.4.1 Keywords: | Os: Unknown/Multiple Architecture: Unknown/Multiple | Failure: Other Difficulty: Unknown | Testcase: Blockedby: | Blocking: Related: | ---------------------------------+------------------------------------------ Changes (by simonpj): * owner: => pcapriotti -- Ticket URL: <http://hackage.haskell.org/trac/ghc/ticket/5967#comment:7> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler _______________________________________________ Glasgow-haskell-bugs mailing list [hidden email] http://www.haskell.org/mailman/listinfo/glasgow-haskell-bugs |
|
In reply to this post by GHC
#5967: incompatible implicit declaration of function 'memcpy'
---------------------------------+------------------------------------------ Reporter: nomeata | Owner: pcapriotti Type: bug | Status: new Priority: high | Milestone: 7.4.2 Component: Compiler | Version: 7.4.1 Keywords: | Os: Unknown/Multiple Architecture: Unknown/Multiple | Failure: Other Difficulty: Unknown | Testcase: Blockedby: | Blocking: Related: | ---------------------------------+------------------------------------------ Comment(by pcapriotti): The attached 5967.patch seems a cleaner solutions to me. We can disable GCC builtins for mem* functions, and enable them selectively for primops. This gets also rid of the warning. Any comments before I push? -- Ticket URL: <http://hackage.haskell.org/trac/ghc/ticket/5967#comment:8> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler _______________________________________________ Glasgow-haskell-bugs mailing list [hidden email] http://www.haskell.org/mailman/listinfo/glasgow-haskell-bugs |
|
In reply to this post by GHC
#5967: incompatible implicit declaration of function 'memcpy'
---------------------------------+------------------------------------------ Reporter: nomeata | Owner: pcapriotti Type: bug | Status: patch Priority: high | Milestone: 7.4.2 Component: Compiler | Version: 7.4.1 Keywords: | Os: Unknown/Multiple Architecture: Unknown/Multiple | Failure: Other Difficulty: Unknown | Testcase: Blockedby: | Blocking: Related: | ---------------------------------+------------------------------------------ Changes (by pcapriotti): * status: new => patch -- Ticket URL: <http://hackage.haskell.org/trac/ghc/ticket/5967#comment:9> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler _______________________________________________ Glasgow-haskell-bugs mailing list [hidden email] http://www.haskell.org/mailman/listinfo/glasgow-haskell-bugs |
|
In reply to this post by GHC
#5967: incompatible implicit declaration of function 'memcpy'
---------------------------------+------------------------------------------ Reporter: nomeata | Owner: pcapriotti Type: bug | Status: patch Priority: high | Milestone: 7.4.2 Component: Compiler | Version: 7.4.1 Keywords: | Os: Unknown/Multiple Architecture: Unknown/Multiple | Failure: Other Difficulty: Unknown | Testcase: Blockedby: | Blocking: Related: | ---------------------------------+------------------------------------------ Comment(by simonmar): This does prevent `Foreign.coypBytes` from using the builtin `memcpy` in the C backend, for example. Also it's another gcc dependency. Do we need to worry about which gcc versions support `-fno-builtin-memcpy`? I think I thought that we could just get the C types right. But actually I don't care that much and I don't think it's worth spending a lot of time on - so go ahead and push as long as there's no issue with old gcc versions. -- Ticket URL: <http://hackage.haskell.org/trac/ghc/ticket/5967#comment:10> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler _______________________________________________ Glasgow-haskell-bugs mailing list [hidden email] http://www.haskell.org/mailman/listinfo/glasgow-haskell-bugs |
|
In reply to this post by GHC
#5967: incompatible implicit declaration of function 'memcpy'
---------------------------------+------------------------------------------ Reporter: nomeata | Owner: pcapriotti Type: bug | Status: patch Priority: high | Milestone: 7.4.2 Component: Compiler | Version: 7.4.1 Keywords: | Os: Unknown/Multiple Architecture: Unknown/Multiple | Failure: Other Difficulty: Unknown | Testcase: Blockedby: | Blocking: Related: | ---------------------------------+------------------------------------------ Comment(by pcapriotti): > This does prevent Foreign.coypBytes from using the builtin memcpy in the C backend, for example I thought that didn't matter, since functions using `memcpy` through the FFI call it through a function pointer, and I doubt that GCC would optimize that anyway. I might be wrong, though. > so go ahead and push as long as there's no issue with old gcc versions. The `memmove` builtin seems to have been introduced in GCC 4.1, is that enough? -- Ticket URL: <http://hackage.haskell.org/trac/ghc/ticket/5967#comment:11> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler _______________________________________________ Glasgow-haskell-bugs mailing list [hidden email] http://www.haskell.org/mailman/listinfo/glasgow-haskell-bugs |
|
In reply to this post by GHC
#5967: incompatible implicit declaration of function 'memcpy'
---------------------------------+------------------------------------------ Reporter: nomeata | Owner: pcapriotti Type: bug | Status: patch Priority: high | Milestone: 7.4.2 Component: Compiler | Version: 7.4.1 Keywords: | Os: Unknown/Multiple Architecture: Unknown/Multiple | Failure: Other Difficulty: Unknown | Testcase: Blockedby: | Blocking: Related: | ---------------------------------+------------------------------------------ Comment(by simonmar): The right thing to do would be to add the flags to the `FP_GCC_EXTRA_FLAGS` test in `aclocal.m4`. -- Ticket URL: <http://hackage.haskell.org/trac/ghc/ticket/5967#comment:12> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler _______________________________________________ Glasgow-haskell-bugs mailing list [hidden email] http://www.haskell.org/mailman/listinfo/glasgow-haskell-bugs |
|
In reply to this post by GHC
#5967: incompatible implicit declaration of function 'memcpy'
---------------------------------+------------------------------------------ Reporter: nomeata | Owner: pcapriotti Type: bug | Status: merge Priority: high | Milestone: 7.4.2 Component: Compiler | Version: 7.4.1 Keywords: | Os: Unknown/Multiple Architecture: Unknown/Multiple | Failure: Other Difficulty: Unknown | Testcase: Blockedby: | Blocking: Related: | ---------------------------------+------------------------------------------ Changes (by pcapriotti): * status: patch => merge Comment: I eventually went for the simpler change suggested by nomeata: {{{ commit 40c1106c338e209f07023d165f32bff0f75e2e54 Author: Paolo Capriotti <[hidden email]> Date: Wed May 2 15:24:46 2012 +0100 Cast memory primops in the C backend (#5976) To prevent conflicts with GCC builtins, generate identical code for calls to mem primos and FFI calls. Based on a patch by Joachim Breitner. }}} -- Ticket URL: <http://hackage.haskell.org/trac/ghc/ticket/5967#comment:13> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler _______________________________________________ Glasgow-haskell-bugs mailing list [hidden email] http://www.haskell.org/mailman/listinfo/glasgow-haskell-bugs |
|
In reply to this post by GHC
#5967: incompatible implicit declaration of function 'memcpy'
-------------------------------+-------------------------------------------- Reporter: nomeata | Owner: pcapriotti Type: bug | Status: closed Priority: high | Milestone: 7.4.2 Component: Compiler | Version: 7.4.1 Resolution: fixed | Keywords: Os: Unknown/Multiple | Architecture: Unknown/Multiple Failure: Other | Difficulty: Unknown Testcase: | Blockedby: Blocking: | Related: -------------------------------+-------------------------------------------- Changes (by pcapriotti): * status: merge => closed * resolution: => fixed Comment: Merged as 0e069310cec2ef3df1d1928fa7683a87aebd9eed. -- Ticket URL: <http://hackage.haskell.org/trac/ghc/ticket/5967#comment:14> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler _______________________________________________ Glasgow-haskell-bugs mailing list [hidden email] http://www.haskell.org/mailman/listinfo/glasgow-haskell-bugs |
|
In reply to this post by GHC
#5967: incompatible implicit declaration of function 'memcpy'
-------------------------------+-------------------------------------------- Reporter: nomeata | Owner: pcapriotti Type: bug | Status: closed Priority: high | Milestone: 7.4.2 Component: Compiler | Version: 7.4.1 Resolution: fixed | Keywords: Os: Unknown/Multiple | Architecture: Unknown/Multiple Failure: Other | Difficulty: Unknown Testcase: | Blockedby: Blocking: | Related: -------------------------------+-------------------------------------------- Comment(by nomeata): Thanks. I already put the patch to use in Debian, and everything looks great. -- Ticket URL: <http://hackage.haskell.org/trac/ghc/ticket/5967#comment:15> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler _______________________________________________ Glasgow-haskell-bugs mailing list [hidden email] http://www.haskell.org/mailman/listinfo/glasgow-haskell-bugs |
| Powered by Nabble | Edit this page |
