Skip to content

Commit 597411f

Browse files
authored
Merge pull request #4434 from jacereda/strip-dead
Strip unreachable code/data
2 parents fb1cc4e + d13fa5c commit 597411f

File tree

3 files changed

+14
-6
lines changed

3 files changed

+14
-6
lines changed

config.mk

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ RANLIB ?=ranlib
1414
CABAL :=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 :=
2020
CABALFLAGS += --enable-tests

src/IRTS/CodegenC.hs

+9-5
Original file line numberDiff line numberDiff line change
@@ -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
Original file line numberDiff line numberDiff line change
@@ -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
5051
isWindows :: Bool
5152
isWindows = 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")
5458
tempfile :: String -> IO (FilePath, Handle)
5559
tempfile ext = do dir <- getTemporaryDirectory

0 commit comments

Comments
 (0)