on master help sign in
Strip unreachable code/data
commitd13fa5cfb3a6107d08e160c3b95f6b2a5574c54e authorJorge Acereda <jacereda@gmail.com> dateTue 1 May 2018, 23:17 (8 years ago) parentfb1cc4e
3 files changed+14−6
config.mk+1−1 src/IRTS/CodegenC.hs+9−5 src/Util/System.hs+4
config.mk+1−1
@@ -14,7 +14,7 @@ RANLIB ?=ranlib
1414CABAL :=cabal
1515# IDRIS_ENABLE_STATS should not be set in final release
1616# Any flags defined here which alter the RTS API must also be added to src/IRTS/CodegenC.hs
17−CFLAGS :=-O2 -Wall -std=c99 -D_POSIX_C_SOURCE=200809L -DHAS_PTHREAD -DIDRIS_ENABLE_STATS $(CFLAGS)
17+CFLAGS :=-O2 -Wall -std=c99 -pipe -fdata-sections -ffunction-sections -D_POSIX_C_SOURCE=200809L -DHAS_PTHREAD -DIDRIS_ENABLE_STATS $(CFLAGS)
1818
1919# CABALFLAGS :=
2020CABALFLAGS += --enable-tests
src/IRTS/CodegenC.hs+9−5
@@ -79,18 +79,22 @@ codegenC' defs out exec incs objs libs flags exports iface dbg
7979 libFlags <- getLibFlags
8080 incFlags <- getIncFlags
8181 envFlags <- getEnvFlags
82− let stackFlag = if isWindows then ["-Wl,--stack,16777216"] else []
82+ let stripFlag = if isDarwin then "-dead_strip" else "-Wl,-gc-sections"
83+ let stackFlags = if isWindows then ["-Wl,--stack,16777216"] else []
84+ let linkFlags = stripFlag : stackFlags
8385 let args = gccDbg dbg ++
8486 gccFlags iface ++
8587 -- # Any flags defined here which alter the RTS API must also be added to config.mk
86− ["-std=c99", "-D_POSIX_C_SOURCE=200809L", "-DHAS_PTHREAD", "-DIDRIS_ENABLE_STATS",
87− "-I."] ++ objs ++ envFlags ++
88− (if (exec == Executable) then [] else ["-c"]) ++
88+ [ "-std=c99", "-pipe"
89+ , "-fdata-sections", "-ffunction-sections"
90+ , "-D_POSIX_C_SOURCE=200809L", "-DHAS_PTHREAD", "-DIDRIS_ENABLE_STATS"
91+ , "-I."] ++ objs ++ envFlags ++
92+ (if (exec == Executable) then linkFlags else ["-c"]) ++
8993 [tmpn] ++
9094 (if not iface then libFlags else []) ++
9195 incFlags ++
9296 (if not iface then libs else []) ++
93− flags ++ stackFlag ++
97+ flags ++
9498 ["-o", out]
9599-- putStrLn (show args)
96100 exit <- rawSystem comp args
src/Util/System.hs+4
@@ -10,6 +10,7 @@ module Util.System( tempfile
1010 , withTempdir
1111 , rmFile
1212 , catchIO
13+ , isDarwin
1314 , isWindows
1415 , writeSource
1516 , writeSourceText
@@ -50,6 +51,9 @@ catchIO = CE.catch
5051isWindows :: Bool
5152isWindows = os `elem` ["win32", "mingw32", "cygwin32"]
5253
54+isDarwin :: Bool
55+isDarwin = os == "darwin"
56+
5357-- | Create a temp file with the extensiom ext (in the format ".xxx")
5458tempfile :: String -> IO (FilePath, Handle)
5559tempfile ext = do dir <- getTemporaryDirectory