Ticket #11395: 0001-c-codegen-split-external-symbol-prototypes-EF_.patch

File 0001-c-codegen-split-external-symbol-prototypes-EF_.patch, 4.2 KB (added by slyfox, 16 months ago)

0001-c-codegen-split-external-symbol-prototypes-EF_.patch

  • compiler/cmm/CLabel.hs

    From 07c9005afd1acf42958e035dd0b1c6a8e8b495a7 Mon Sep 17 00:00:00 2001
    From: Sergei Trofimovich <siarheit@google.com>
    Date: Sat, 27 Feb 2016 13:45:55 +0000
    Subject: [PATCH] c codegen: split external symbol prototypes (EF_)
    
    Before the patch both Cmm and C symbols were declared
    with 'EF_' macro:
    
        #define EF_(f)    extern StgFunPtr f()
    
    but for Cmm symbols we known prototype exactly.
    
    The patch splits there prototypes in to:
    
        #define EFF_(f)   void f() /* See Note [External function prototypes] */
        #define EF_(f)    StgFunPtr f(void)
    
    Cmm functions are 'EF_' (External Functions),
    C functions are 'EFF_' (External Foreign Functions).
    
    While at it changed external C function prototype
    to return 'void' to workaround ghc bug on m68k.
    Described in detail in Trac #11395.
    
    Signed-off-by: Sergei Trofimovich <siarheit@google.com>
    ---
     compiler/cmm/CLabel.hs |  8 +++++++-
     compiler/cmm/PprC.hs   |  5 +++--
     includes/Stg.h         | 11 ++++++++---
     3 files changed, 18 insertions(+), 6 deletions(-)
    
    diff --git a/compiler/cmm/CLabel.hs b/compiler/cmm/CLabel.hs
    index 9304d66..15c5ff3 100644
    a b module CLabel ( 
    8888
    8989        mkForeignLabel,
    9090        addLabelSize,
    91         foreignLabelStdcallInfo,
    9291
     92        foreignLabelStdcallInfo,
     93        isForeignLabel,
    9394        mkCCLabel, mkCCSLabel,
    9495
    9596        DynamicLinkerLabelInfo(..),
    addLabelSize (ForeignLabel str _ src fod) sz 
    492493addLabelSize label _
    493494    = label
    494495
     496-- | Whether label is a non-haskell label (defined in C code)
     497isForeignLabel :: CLabel -> Bool
     498isForeignLabel (ForeignLabel _ _ _ _) = True
     499isForeignLabel _lbl = False
     500
    495501-- | Get the label size field from a ForeignLabel
    496502foreignLabelStdcallInfo :: CLabel -> Maybe Int
    497503foreignLabelStdcallInfo (ForeignLabel _ info _ _) = info
  • compiler/cmm/PprC.hs

    diff --git a/compiler/cmm/PprC.hs b/compiler/cmm/PprC.hs
    index e679d55..019b376 100644
    a b pprStmt stmt = 
    240240          -- We also need to cast mem primops to prevent conflicts with GCC
    241241          -- builtins (see bug #5967).
    242242          | Just _align <- machOpMemcpyishAlign op
    243           = (text ";EF_(" <> fn <> char ')' <> semi) $$
     243          = (text ";EFF_(" <> fn <> char ')' <> semi) $$
    244244            pprForeignCall fn cconv hresults hargs
    245245          | otherwise
    246246          = pprCall fn cconv hresults hargs
    pprExternDecl _in_srt lbl 
    981981        hcat [ visibility, label_type lbl,
    982982               lparen, ppr lbl, text ");" ]
    983983 where
    984   label_type lbl | isCFunctionLabel lbl = text "F_"
     984  label_type lbl | isForeignLabel lbl && isCFunctionLabel lbl = text "FF_"
     985                 | isCFunctionLabel lbl = text "F_"
    985986                 | otherwise            = text "I_"
    986987
    987988  visibility
  • includes/Stg.h

    diff --git a/includes/Stg.h b/includes/Stg.h
    index 899e685..1ff1d85 100644
    a b typedef StgFunPtr F_; 
    222222#define II_(X)          static StgWordArray (X) GNU_ATTRIBUTE(aligned (8))
    223223#define IF_(f)    static StgFunPtr GNUC3_ATTRIBUTE(used) f(void)
    224224#define FN_(f)    StgFunPtr f(void)
    225 #define EF_(f)    extern StgFunPtr f()   /* See Note [External function prototypes] */
     225#define EFF_(f)   void f() /* See Note [External function prototypes] */
     226#define EF_(f)    StgFunPtr f(void)
    226227
    227 /* Note [External function prototypes]  See Trac #8965
     228/* Note [External function prototypes]  See Trac #8965, #11395
    228229   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    229 The external-function macro EF_(F) used to be defined as
     230The external-function macro EFF_(F) used to be defined as
    230231    extern StgFunPtr f(void)
    231232i.e a function of zero arguments.  On most platforms this doesn't
    232233matter very much: calls to these functions put the parameters in the
    unspecified argument list rather than a void argument list. This is no 
    249250worse for platforms that don't care either way, and allows a successful
    250251bootstrap of GHC 7.8 on little-endian Linux ppc64 (which uses the ELFv2
    251252ABI).
     253
     254Another case is m68k ABI where 'void*' return type is returned by 'a0'
     255register while 'long' return type is returned by 'd0'. Thus we trick
     256external prototype return neither of these types to workaround #11395.
    252257*/
    253258
    254259