[commit: ghc] master: LlvmMangler: Be more selective when mangling object types (5895f2b)
git at git.haskell.org
git at git.haskell.org
Fri Aug 15 15:56:14 UTC 2014
Repository : ssh://git@git.haskell.org/ghc
On branch : master
Link : http://ghc.haskell.org/trac/ghc/changeset/5895f2b8ffba72a8393e9f712461e6e5ed7ceced/ghc
>---------------------------------------------------------------
commit 5895f2b8ffba72a8393e9f712461e6e5ed7ceced
Author: Ben Gamari <bgamari.foss at gmail.com>
Date: Fri Aug 15 11:11:17 2014 -0400
LlvmMangler: Be more selective when mangling object types
Summary:
We previously did a wholesale replace of `%function` to `%object` to
mangle object `.type` annotations. This is bad as it can end up
replacing appearances of `"%function"` in the user's code. We now look
for a proper `.type` keyword before performing the replacement.
Thanks to @rwbarton for pointing out the bug.
Test Plan:
Previously,
$ echo 'main = putStrLn "@function"' > test.hs
$ ghc -fllvm test.hs
$ ./test
@object
Now,
$ echo 'main = putStrLn "@function"' > test.hs
$ ghc -fllvm test.hs
$ ./test
@function
Reviewers: rwbarton, austin
Reviewed By: rwbarton, austin
Subscribers: phaskell, simonmar, relrod, ezyang, carter
Differential Revision: https://phabricator.haskell.org/D150
GHC Trac Issues: #9439
>---------------------------------------------------------------
5895f2b8ffba72a8393e9f712461e6e5ed7ceced
compiler/llvmGen/LlvmMangler.hs | 18 ++++++++++++++----
1 file changed, 14 insertions(+), 4 deletions(-)
diff --git a/compiler/llvmGen/LlvmMangler.hs b/compiler/llvmGen/LlvmMangler.hs
index 7084a2e..8652a89 100644
--- a/compiler/llvmGen/LlvmMangler.hs
+++ b/compiler/llvmGen/LlvmMangler.hs
@@ -58,13 +58,23 @@ llvmFixupAsm dflags f1 f2 = {-# SCC "llvm_mangler" #-} do
hClose w
return ()
+-- | This rewrites @.type@ annotations of function symbols to @%object at .
+-- This is done as the linker can relocate @%functions@ through the
+-- Procedure Linking Table (PLT). This is bad since we expect that the
+-- info table will appear directly before the symbol's location. In the
+-- case that the PLT is used, this will be not an info table but instead
+-- some random PLT garbage.
rewriteSymType :: B.ByteString -> B.ByteString
rewriteSymType s =
- foldl (\s' (typeFunc,typeObj)->replace typeFunc typeObj s') s types
+ B.unlines $ map (rewrite '@' . rewrite '%') $ B.lines s
where
- types = [ (B.pack "@function", B.pack "@object")
- , (B.pack "%function", B.pack "%object")
- ]
+ rewrite :: Char -> B.ByteString -> B.ByteString
+ rewrite prefix x
+ | isType x = replace funcType objType x
+ | otherwise = x
+ where
+ funcType = prefix `B.cons` B.pack "function"
+ objType = prefix `B.cons` B.pack "object"
-- | Splits the file contents into its sections
readSections :: Handle -> Handle -> IO [Section]
More information about the ghc-commits
mailing list