Commit 01381101 authored by Facundo Domínguez's avatar Facundo Domínguez Committed by Austin Seipp
Browse files

Implement -rdynamic in Linux and Windows/MinGW32.

Summary:
In Linux, it is a synonym for -optl -rdynamic.
In Windows, it is a synonym for -optl -export-all-symbols.

Test Plan: validate

Reviewers: simonmar, austin

Reviewed By: simonmar, austin

Subscribers: mboes, phaskell, simonmar, relrod, ezyang, carter

Differential Revision: https://phabricator.haskell.org/D102

GHC Trac Issues: #9381
parent 9a708d38
......@@ -2175,8 +2175,15 @@ dynamic_flags = [
----- Linker --------------------------------------------------------
, Flag "static" (NoArg removeWayDyn)
, Flag "dynamic" (NoArg (addWay WayDyn))
, Flag "rdynamic" $ noArg $
#ifdef linux_HOST_OS
addOptl "-rdynamic"
#elif defined (mingw32_HOST_OS)
addOptl "-export-all-symbols"
#else
-- ignored for compat w/ gcc:
, Flag "rdynamic" (NoArg (return ()))
id
#endif
, Flag "relative-dynlib-paths" (NoArg (setGeneralFlag Opt_RelativeDynlibPaths))
------- Specific phases --------------------------------------------
......
......@@ -2429,6 +2429,15 @@
<entry>dynamic</entry>
<entry>-</entry>
</row>
<row>
<entry><option>-rdynamic</option></entry>
<entry>This instructs the linker to add all symbols, not only used ones, to the
dynamic symbol table. Currently Linux and Windows/MinGW32 only.
This is equivalent to using <literal>-optl -rdynamic</literal> in linux,
and <literal>-optl -export-all-symbols</literal> in Windows.</entry>
<entry>dynamic</entry>
<entry>-</entry>
</row>
</tbody>
</tgroup>
</informaltable>
......
......@@ -1230,6 +1230,21 @@ $ cat foo.hspp</screen>
platforms.</para>
</listitem>
</varlistentry>
<varlistentry>
<term>
<option>-rdynamic</option>
<indexterm><primary><option>-rdynamic</option></primary>
</indexterm>
</term>
<listitem>
<para>
This instructs the linker to add all symbols, not only used ones, to the
dynamic symbol table. Currently Linux and Windows/MinGW32 only.
This is equivalent to using <literal>-optl -rdynamic</literal> in linux,
and <literal>-optl -export-all-symbols</literal> in Windows.</para>
</listitem>
</varlistentry>
</variablelist>
</sect2>
......
......@@ -231,6 +231,11 @@ test('T9045', [ omit_ways(['ghci']), extra_run_opts('10000 +RTS -A8k -RTS') ], c
# with the non-threaded one.
test('T9078', [ omit_ways(threaded_ways) ], compile_and_run, ['-with-rtsopts="-DS" -debug'])
# -rdynamic is implemented in windows, but the RTS linker does
# not pickup yet the symbols exported in executables.
test('rdynamic', unless(opsys('linux'), skip),
compile_and_run, ['-rdynamic -package ghc'])
# 251 = RTS exit code for "out of memory"
test('overflow1', [ exit_code(251) ], compile_and_run, [''])
test('overflow2', [ exit_code(251) ], compile_and_run, [''])
......
-- | A test to load symbols exposed with @-rdynamic@.
--
-- Exporting 'f' from Main is important, otherwise, the corresponding symbol
-- wouldn't appear in symbol tables.
--
{-# LANGUAGE ForeignFunctionInterface #-}
{-# LANGUAGE MagicHash #-}
{-# LANGUAGE UnboxedTuples #-}
module Main(main, f) where
import Foreign.C.String ( withCString, CString )
import GHC.Exts ( addrToAny# )
import GHC.Ptr ( Ptr(..), nullPtr )
import System.Info ( os )
import Encoding
main = (loadFunction Nothing "Main" "f" :: IO (Maybe String)) >>= print
f :: String
f = "works"
-- loadFunction__ taken from
-- @plugins-1.5.4.0:System.Plugins.Load.loadFunction__@
loadFunction :: Maybe String
-> String
-> String
-> IO (Maybe a)
loadFunction mpkg m valsym = do
let symbol = prefixUnderscore
++ maybe "" (\p -> zEncodeString p ++ "_") mpkg
++ zEncodeString m ++ "_" ++ zEncodeString valsym
++ "_closure"
ptr@(Ptr addr) <- withCString symbol c_lookupSymbol
if (ptr == nullPtr)
then return Nothing
else case addrToAny# addr of
(# hval #) -> return ( Just hval )
where
prefixUnderscore = if elem os ["darwin","mingw32","cygwin"] then "_" else ""
foreign import ccall safe "lookupSymbol" c_lookupSymbol :: CString -> IO (Ptr a)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment