deriveConstants: Verify sanity of nm
authorHerbert Valerio Riedel <hvr@gnu.org>
Sat, 16 Apr 2016 13:25:07 +0000 (15:25 +0200)
committerBen Gamari <ben@smart-cactus.org>
Sat, 16 Apr 2016 13:34:30 +0000 (15:34 +0200)
Add a sanity check ensuring that nm emits valid hexadecimal output, as
required by POSIX. See #11744 for motivation.

Reviewers: austin, bgamari

Subscribers: thomie

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

GHC Trac Issues: #11744

utils/deriveConstants/Main.hs

index 6a88ac2..96da166 100644 (file)
@@ -296,8 +296,12 @@ haskellise "" = ""
 
 wanteds :: String -> Wanteds
 wanteds os = concat
-          [-- Closure header sizes.
-           constantWord Both "STD_HDR_SIZE"
+          [-- Control group constant for integrity check; this
+           -- round-tripped constant is used for testing that
+           -- derivedConstant works as expected
+           constantWord Both "CONTROL_GROUP_CONST_291" "0x123"
+           -- Closure header sizes.
+          ,constantWord Both "STD_HDR_SIZE"
                              -- grrr.. PROFILING is on so we need to
                              -- subtract sizeofW(StgProfHeader)
                              "sizeofW(StgHeader) - sizeofW(StgProfHeader)"
@@ -682,6 +686,14 @@ getWanted verbose os tmpdir gccProgram gccFlags nmProgram mobjdumpProgram
              m = Map.fromList $ case os of
                  "aix" -> parseAixObjdump ls
                  _     -> catMaybes $ map parseNmLine ls
+
+         case Map.lookup "CONTROL_GROUP_CONST_291" m of
+             Just 292   -> return () -- OK
+             Nothing    -> die "CONTROL_GROUP_CONST_291 missing!"
+             Just 0x292 -> die $ "broken 'nm' detected, see https://ghc.haskell.org/ticket/11744.\n"
+                              ++ "Workaround: You may want to pass '--with-nm=nm-classic' to 'configure'."
+             Just x     -> die ("unexpected value round-tripped for CONTROL_GROUP_CONST_291: " ++ show x)
+
          rs <- mapM (lookupResult m) (wanteds os)
          return rs
     where headers = ["#define IN_STG_CODE 0",