diff --git a/compiler/GHC/Driver/Pipeline/Execute.hs b/compiler/GHC/Driver/Pipeline/Execute.hs
index fac2a595f22527087822cddfdd534d427828fbc6..f47d9672720c6c6a31a5d7e021f188018412da7b 100644
--- a/compiler/GHC/Driver/Pipeline/Execute.hs
+++ b/compiler/GHC/Driver/Pipeline/Execute.hs
@@ -534,6 +534,13 @@ runCcPhase cc_phase pipe_env hsc_env location input_fn = do
                     , not $ target32Bit (targetPlatform dflags)
                     ]
 
+                 -- if -fsplit-sections is enabled, we should also
+                 -- build with these flags.
+                 ++ (if gopt Opt_SplitSections dflags &&
+                      platformOS (targetPlatform dflags) /= OSDarwin
+                        then ["-ffunction-sections", "-fdata-sections"]
+                        else [])
+
           -- Stub files generated for foreign exports references the runIO_closure
           -- and runNonIO_closure symbols, which are defined in the base package.
           -- These symbols are imported into the stub.c file via RtsAPI.h, and the