diff options
author | Moritz Angermann <moritz@lichtzwerge.de> | 2014-11-19 16:38:22 -0600 |
---|---|---|
committer | Austin Seipp <austin@well-typed.com> | 2014-11-19 17:03:06 -0600 |
commit | 53a4742d037da2bfd00d1d34a8ea0d49d4cdb490 (patch) | |
tree | 1922721e21e3b6618ff9b7184d9dc96e9145e535 /compiler | |
parent | 146dd138e2c3b4ec9b211dcbcedf752aeb79d3d1 (diff) | |
download | haskell-53a4742d037da2bfd00d1d34a8ea0d49d4cdb490.tar.gz |
Allow -dead_strip linking on platforms with .subsections_via_symbols
Summary:
This allows to link objects produced with the llvm code generator to be linked with -dead_strip. This applies to at least the iOS cross compiler and OS X compiler.
Signed-off-by: Moritz Angermann <moritz@lichtzwerge.de>
Test Plan: Create a ffi library and link it with -dead_strip. If the resulting binary does not crash, the patch works as advertised.
Reviewers: rwbarton, simonmar, hvr, dterei, mzero, ezyang, austin
Reviewed By: dterei, ezyang, austin
Subscribers: thomie, mzero, simonmar, ezyang, carter
Differential Revision: https://phabricator.haskell.org/D206
Diffstat (limited to 'compiler')
-rw-r--r-- | compiler/NOTES | 16 | ||||
-rw-r--r-- | compiler/llvmGen/LlvmCodeGen/Ppr.hs | 8 | ||||
-rw-r--r-- | compiler/nativeGen/PPC/Ppr.hs | 7 | ||||
-rw-r--r-- | compiler/nativeGen/SPARC/Ppr.hs | 7 | ||||
-rw-r--r-- | compiler/nativeGen/X86/Ppr.hs | 7 |
5 files changed, 26 insertions, 19 deletions
diff --git a/compiler/NOTES b/compiler/NOTES new file mode 100644 index 0000000000..14a1f80b41 --- /dev/null +++ b/compiler/NOTES @@ -0,0 +1,16 @@ +Note [Subsections Via Symbols] + +If we are using the .subsections_via_symbols directive +(available on recent versions of Darwin), +we have to make sure that there is some kind of reference +from the entry code to a label on the _top_ of of the info table, +so that the linker will not think it is unreferenced and dead-strip +it. That's why the label is called a DeadStripPreventer (_dsp). + +The LLVM code gen already creates `iTableSuf` symbols, where +the X86 would generate the DeadStripPreventer (_dsp) symbol. +Therefore all that is left for llvm code gen, is to ensure +that all the `iTableSuf` symbols are marked as used. +As of this writing the documentation regarding the +.subsections_via_symbols and -dead_stip can be found at +<https://developer.apple.com/library/mac/documentation/DeveloperTools/Reference/Assembler/040-Assembler_Directives/asm_directives.html#//apple_ref/doc/uid/TP30000823-TPXREF101>
\ No newline at end of file diff --git a/compiler/llvmGen/LlvmCodeGen/Ppr.hs b/compiler/llvmGen/LlvmCodeGen/Ppr.hs index 9c6a719613..80e8949ac8 100644 --- a/compiler/llvmGen/LlvmCodeGen/Ppr.hs +++ b/compiler/llvmGen/LlvmCodeGen/Ppr.hs @@ -114,12 +114,18 @@ pprInfoTable count info_lbl stat = do (ldata, ltypes) <- genLlvmData (Text, stat) dflags <- getDynFlags + platform <- getLlvmPlatform let setSection (LMGlobal (LMGlobalVar _ ty l _ _ c) d) = do lbl <- strCLabel_llvm info_lbl let sec = mkLayoutSection count ilabel = lbl `appendFS` fsLit iTableSuf gv = LMGlobalVar ilabel ty l sec (llvmInfAlign dflags) c - v = if l == Internal then [gv] else [] + -- See Note [Subsections Via Symbols] + v = if (platformHasSubsectionsViaSymbols platform + && l == ExternallyVisible) + || l == Internal + then [gv] + else [] funInsert ilabel ty return (LMGlobal gv d, v) setSection v = return (v,[]) diff --git a/compiler/nativeGen/PPC/Ppr.hs b/compiler/nativeGen/PPC/Ppr.hs index e62a1c4557..6851769132 100644 --- a/compiler/nativeGen/PPC/Ppr.hs +++ b/compiler/nativeGen/PPC/Ppr.hs @@ -73,12 +73,7 @@ pprNatCmmDecl proc@(CmmProc top_info lbl _ (ListGraph blocks)) = -- elimination, it might be the target of a goto. (if platformHasSubsectionsViaSymbols platform then - -- If we are using the .subsections_via_symbols directive - -- (available on recent versions of Darwin), - -- we have to make sure that there is some kind of reference - -- from the entry code to a label on the _top_ of of the info table, - -- so that the linker will not think it is unreferenced and dead-strip - -- it. That's why the label is called a DeadStripPreventer (_dsp). + -- See Note [Subsections Via Symbols] text "\t.long " <+> ppr info_lbl <+> char '-' diff --git a/compiler/nativeGen/SPARC/Ppr.hs b/compiler/nativeGen/SPARC/Ppr.hs index c734687420..e9941b81ff 100644 --- a/compiler/nativeGen/SPARC/Ppr.hs +++ b/compiler/nativeGen/SPARC/Ppr.hs @@ -77,12 +77,7 @@ pprNatCmmDecl proc@(CmmProc top_info lbl _ (ListGraph blocks)) = -- elimination, it might be the target of a goto. (if platformHasSubsectionsViaSymbols platform then - -- If we are using the .subsections_via_symbols directive - -- (available on recent versions of Darwin), - -- we have to make sure that there is some kind of reference - -- from the entry code to a label on the _top_ of of the info table, - -- so that the linker will not think it is unreferenced and dead-strip - -- it. That's why the label is called a DeadStripPreventer (_dsp). + -- See Note [Subsections Via Symbols] text "\t.long " <+> ppr info_lbl <+> char '-' diff --git a/compiler/nativeGen/X86/Ppr.hs b/compiler/nativeGen/X86/Ppr.hs index 2b3711751c..ddd75c83f6 100644 --- a/compiler/nativeGen/X86/Ppr.hs +++ b/compiler/nativeGen/X86/Ppr.hs @@ -78,12 +78,7 @@ pprNatCmmDecl proc@(CmmProc top_info lbl _ (ListGraph blocks)) = -- elimination, it might be the target of a goto. (if platformHasSubsectionsViaSymbols platform then - -- If we are using the .subsections_via_symbols directive - -- (available on recent versions of Darwin), - -- we have to make sure that there is some kind of reference - -- from the entry code to a label on the _top_ of of the info table, - -- so that the linker will not think it is unreferenced and dead-strip - -- it. That's why the label is called a DeadStripPreventer (_dsp). + -- See Note [Subsections Via Symbols] text "\t.long " <+> ppr info_lbl <+> char '-' |