[commit: ghc] master: Extract derived constants from nm output for various OSes differently. (3df1c51)

Simon Peyton Jones simonpj at microsoft.com
Mon May 19 07:32:39 UTC 2014


Christian (and all ghc-devs)

Thank you working so hard on this.   I really appreciate it.

But can I beg you to add a Note to explain the issue, and to refer directly to Trac #8783. The ticket has a string of forty-four comments, so presumably it's not a simple, obvious typo.  What I fear is that in 5 yrs time someone will say "oh, there's a simpler way of doing this" and will un-do all your good work.  

Everyone: I'm know I get repetitive about this, but please always think about whether your change will seem as limpidly clear and obvious in five years time as it does now.  ALWAYS add a reference to the ticket, unless you are simply fixing a totally stupid typo that nobody could possibly un-fix.  

(Stuff in the commit message is not enough, because you don't see it when you are looking at the source code.  I enthusiastically encourage you to use the "Note" style, which you will see littered all over the compiler these days.)

Pretty much any bug-fix is fixing something that wasn't obvious to the original author!

Thank you all for making GHC so good.

Simon

| -----Original Message-----
| From: ghc-commits [mailto:ghc-commits-bounces at haskell.org] On Behalf Of
| git at git.haskell.org
| Sent: 19 May 2014 06:11
| To: ghc-commits at haskell.org
| Subject: [commit: ghc] master: Extract derived constants from nm output
| for various OSes differently. (3df1c51)
| 
| Repository : ssh://git@git.haskell.org/ghc
| 
| On branch  : master
| Link       :
| http://ghc.haskell.org/trac/ghc/changeset/3df1c5109a6bd2a522717e524c10d8
| 42d4cd8ab8/ghc
| 
| >---------------------------------------------------------------
| 
| commit 3df1c5109a6bd2a522717e524c10d842d4cd8ab8
| Author: Christian Maeder <Christian.Maeder at dfki.de>
| Date:   Thu Apr 3 10:00:07 2014 +0200
| 
|     Extract derived constants from nm output for various OSes
| differently.
| 
|     Fixes #8783.
| 
|     In order to avoid querying the nm version that does not work on Mac
| OS X
|     we use the "nm -P" output that is supposed to produce (more
| portable)
|     POSIX output and works on all tested OSes (MinGW, Mac OS X, Solaris
| and
|     Linux using GNU nm) although slightly different (as documented). The
| "nm
|     -P" output is actually only needed to recognize the output of a non-
| GNU
|     Solaris nm (all other OSes produce sane outut using "nm" only).
| 
|     Signed-off-by: Austin Seipp <austin at well-typed.com>
| 
| 
| >---------------------------------------------------------------
| 
| 3df1c5109a6bd2a522717e524c10d842d4cd8ab8
|  utils/deriveConstants/DeriveConstants.hs | 37 +++++++++++++------------
| -------
|  1 file changed, 15 insertions(+), 22 deletions(-)
| 
| diff --git a/utils/deriveConstants/DeriveConstants.hs
| b/utils/deriveConstants/DeriveConstants.hs
| index 8c943f0..6bfce24 100644
| --- a/utils/deriveConstants/DeriveConstants.hs
| +++ b/utils/deriveConstants/DeriveConstants.hs
| @@ -641,7 +641,7 @@ getWanted verbose tmpdir gccProgram gccFlags
| nmProgram
|               oFile = tmpdir </> "tmp.o"
|           writeFile cFile cStuff
|           execute verbose gccProgram (gccFlags ++ ["-c", cFile, "-o",
| oFile])
| -         xs <- readProcess nmProgram [oFile] ""
| +         xs <- readProcess nmProgram ["-P", oFile] ""
|           let ls = lines xs
|               ms = map parseNmLine ls
|               m = Map.fromList $ catMaybes ms @@ -710,28 +710,21 @@
| getWanted verbose tmpdir gccProgram gccFlags nmProgram
|            doWanted (ClosurePayloadMacro {}) = []
|            doWanted (FieldTypeGcptrMacro {}) = []
| 
| -          -- parseNmLine parses nm output that looks like
| -          -- "0000000b C derivedConstantMAX_Vanilla_REG"
| +          -- parseNmLine parses "nm -P" output that looks like
| +          -- "derivedConstantMAX_Vanilla_REG C 0000000b 0000000b" (GNU
| nm)
| +          -- "_derivedConstantMAX_Vanilla_REG C b 0" (Mac OS X)
| +          -- "_derivedConstantMAX_Vanilla_REG C 000000b" (MinGW)
| +          -- "derivedConstantMAX_Vanilla_REG D        1        b"
| (Solaris)
|            -- and returns ("MAX_Vanilla_REG", 11)
| -          parseNmLine xs0 = case break (' ' ==) xs0 of
| -                            (x1, ' ' : xs1) ->
| -                                case break (' ' ==) xs1 of
| -                                (x2, ' ' : x3) ->
| -                                    case readHex x1 of
| -                                    [(size, "")] ->
| -                                        case x2 of
| -                                        "C" ->
| -                                            let x3' = case x3 of
| -                                                      '_' : rest ->
| rest
| -                                                      _          -> x3
| -                                            in case stripPrefix prefix
| x3' of
| -                                               Just name ->
| -                                                   Just (name, size)
| -                                               _ -> Nothing
| -                                        _ -> Nothing
| -                                    _ -> Nothing
| -                                _ -> Nothing
| -                            _ -> Nothing
| +          parseNmLine line
| +              = case words line of
| +                ('_' : n) : "C" : s : _ -> mkP n s
| +                n : "C" : s : _ -> mkP n s
| +                [n, "D", _, s] -> mkP n s
| +                _ -> Nothing
| +              where mkP r s = case (stripPrefix prefix r, readHex s) of
| +                        (Just name, [(size, "")]) -> Just (name, size)
| +                        _ -> Nothing
| 
|            -- If an Int value is larger than 2^28 or smaller
|            -- than -2^28, then fail.
| 
| _______________________________________________
| ghc-commits mailing list
| ghc-commits at haskell.org
| http://www.haskell.org/mailman/listinfo/ghc-commits


More information about the ghc-devs mailing list