diff options
author | Simon Brenner <olsner@gmail.com> | 2015-09-19 15:23:51 +0200 |
---|---|---|
committer | Thomas Miedema <thomasmiedema@gmail.com> | 2015-09-19 15:23:51 +0200 |
commit | bb0897f60abcce697a1038baba86923eb8baa971 (patch) | |
tree | 23e2b7e9ce92e0d8c6a641833264858aa0923862 /compiler/nativeGen/PprBase.hs | |
parent | c8d438fb027cbefa31941d8397539c481a03a74f (diff) | |
download | haskell-wip/D1242.tar.gz |
Implement function-sections for Haskell code, #8405wip/D1242
Summary:
This adds a flag -split-sections that does similar things to -split-objs, but
using sections in single object files instead of relying on the Satanic
Splitter and other abominations. This is very similar to the GCC flags
-ffunction-sections and -fdata-sections.
The --gc-sections linker flag, which allows unused sections to actually
be removed, is added to all link commands (if the linker supports it) so that
space savings from having base compiled with sections can be realized.
Supported both in LLVM and the native code-gen, in theory for all
architectures, but really tested on x86 only.
In the GHC build, a new SplitSections variable enables -split-sections for
relevant parts of the build.
Test Plan: validate with both settings of SplitSections
Reviewers: simonmar, austin, dterei, bgamari
Subscribers: erikd, kgardas, thomie
Differential Revision: https://phabricator.haskell.org/D1242
GHC Trac Issues: #8405
Diffstat (limited to 'compiler/nativeGen/PprBase.hs')
-rw-r--r-- | compiler/nativeGen/PprBase.hs | 51 |
1 files changed, 50 insertions, 1 deletions
diff --git a/compiler/nativeGen/PprBase.hs b/compiler/nativeGen/PprBase.hs index 90a3b303f4..44877d6372 100644 --- a/compiler/nativeGen/PprBase.hs +++ b/compiler/nativeGen/PprBase.hs @@ -10,11 +10,18 @@ module PprBase ( castFloatToWord8Array, castDoubleToWord8Array, floatToBytes, - doubleToBytes + doubleToBytes, + pprSectionHeader ) where +import CLabel +import Cmm +import DynFlags +import Outputable +import Platform + import qualified Data.Array.Unsafe as U ( castSTUArray ) import Data.Array.ST @@ -70,3 +77,45 @@ doubleToBytes d i7 <- readArray arr 7 return (map fromIntegral [i0,i1,i2,i3,i4,i5,i6,i7]) ) + +-- ---------------------------------------------------------------------------- +-- Printing section headers. +-- +-- If -split-section was specified, include the suffix label, otherwise just +-- print the section type. For Darwin, where subsections-for-symbols are +-- used instead, only print section type. + +pprSectionHeader :: Platform -> Section -> SDoc +pprSectionHeader platform (Section t suffix) = + case platformOS platform of + OSDarwin -> pprDarwinSectionHeader t + _ -> pprGNUSectionHeader t suffix + +pprGNUSectionHeader :: SectionType -> CLabel -> SDoc +pprGNUSectionHeader t suffix = sdocWithDynFlags $ \dflags -> + let splitSections = gopt Opt_SplitSections dflags + subsection | splitSections = text "." <> ppr suffix + | otherwise = text "" -- empty doc? + in text ".section " <> text header <> subsection + where + header = case t of + Text -> ".text" + Data -> ".data" + ReadOnlyData -> ".rodata" + RelocatableReadOnlyData -> ".data.rel.ro" + UninitialisedData -> ".bss" + ReadOnlyData16 -> ".rodata.cst16" + OtherSection _ -> + panic "PprBase.pprGNUSectionHeader: unknown section type" + +pprDarwinSectionHeader :: SectionType -> SDoc +pprDarwinSectionHeader t = + text $ case t of + Text -> ".text" + Data -> ".data" + ReadOnlyData -> ".const" + RelocatableReadOnlyData -> ".const_data" + UninitialisedData -> ".data" + ReadOnlyData16 -> ".const" + OtherSection _ -> + panic "PprBase.pprDarwinSectionHeader: unknown section type" |