Ticket #8781: 0001-change-deriveConstants-to-use-nm-in-a-POSIX-way-fixe.patch

File 0001-change-deriveConstants-to-use-nm-in-a-POSIX-way-fixe.patch, 3.2 KB (added by kgardas, 17 months ago)
  • utils/deriveConstants/DeriveConstants.hs

    From 030f58f2ef62f8478bcd6342d2e204ad25f27c96 Mon Sep 17 00:00:00 2001
    From: Karel Gardas <[email protected]>
    Date: Sat, 22 Mar 2014 22:33:05 +0100
    Subject: [PATCH] change deriveConstants to use nm in a POSIX way (fixes
     #8781)
    
    The patch provided by Christian Maeder <[email protected]>
    
    Signed-off-by: Karel Gardas <[email protected]>
    ---
     utils/deriveConstants/DeriveConstants.hs |   30 ++++++++++--------------------
     1 file changed, 10 insertions(+), 20 deletions(-)
    
    diff --git a/utils/deriveConstants/DeriveConstants.hs b/utils/deriveConstants/DeriveConstants.hs
    index 293fe65..6344569 100644
    a b getWanted verbose tmpdir gccProgram gccFlags nmProgram 
    638638             oFile = tmpdir </> "tmp.o"
    639639         writeFile cFile cStuff
    640640         execute verbose gccProgram (gccFlags ++ ["-c", cFile, "-o", oFile])
    641          xs <- readProcess nmProgram [oFile] ""
     641         xs <- readProcess nmProgram ["-P", oFile] ""
    642642         let ls = lines xs
    643643             ms = map parseNmLine ls
    644644             m = Map.fromList $ catMaybes ms
    getWanted verbose tmpdir gccProgram gccFlags nmProgram 
    707707          doWanted (ClosurePayloadMacro {}) = []
    708708          doWanted (FieldTypeGcptrMacro {}) = []
    709709
    710           -- parseNmLine parses nm output that looks like
    711           -- "0000000b C derivedConstantMAX_Vanilla_REG"
     710          -- parseNmLine parses "nm -P" output that looks like
     711          -- "_derivedConstantMAX_Vanilla_REG C b 0" Mac OS X
     712          -- "derivedConstantMAX_Vanilla_REG C 0000000b 0000000b" GNU
     713          -- "derivedConstantMAX_Vanilla_REG D        1        b" Solaris
    712714          -- and returns ("MAX_Vanilla_REG", 11)
    713           parseNmLine xs0 = case break (' ' ==) xs0 of
    714                             (x1, ' ' : xs1) ->
    715                                 case break (' ' ==) xs1 of
    716                                 (x2, ' ' : x3) ->
    717                                     case readHex x1 of
    718                                     [(size, "")] ->
    719                                         case x2 of
    720                                         "C" ->
    721                                             let x3' = case x3 of
    722                                                       '_' : rest -> rest
    723                                                       _          -> x3
    724                                             in case stripPrefix prefix x3' of
    725                                                Just name ->
    726                                                    Just (name, size)
    727                                                _ -> Nothing
    728                                         _ -> Nothing
    729                                     _ -> Nothing
     715          parseNmLine xs0 = case words xs0 of
     716                            [x0, x1, x2, x3] -> case stripPrefix prefix $ dropWhile (== '_') x0 of
     717                              Just name -> case readHex $ if x1 == "C" then x2 else x3 of
     718                                [(size, "")] -> Just (name, size)
    730719                                _ -> Nothing
     720                              _ -> Nothing
    731721                            _ -> Nothing
    732722
    733723          -- If an Int value is larger than 2^28 or smaller