Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Include cmm-sources when linking shared objects #7252

Merged
merged 2 commits into from
Apr 14, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions Cabal/src/Distribution/Simple/GHC.hs
Original file line number Diff line number Diff line change
Expand Up @@ -780,9 +780,9 @@ buildOrReplLib mReplFlags verbosity numJobs pkg_descr lbi lib clbi = do
when has_code . unless forRepl $ do
info verbosity "Linking..."
let cProfObjs = map (`replaceExtension` ("p_" ++ objExtension))
(cSources libBi ++ cxxSources libBi)
cLikeFiles
cSharedObjs = map (`replaceExtension` ("dyn_" ++ objExtension))
(cSources libBi ++ cxxSources libBi)
cLikeFiles
compiler_id = compilerId (compiler lbi)
vanillaLibFilePath = libTargetDir </> mkLibName uid
profileLibFilePath = libTargetDir </> mkProfLibName uid
Expand Down Expand Up @@ -1365,7 +1365,9 @@ gbuild verbosity numJobs pkg_descr lbi bm clbi = do
[tmpDir </> x | x <- cObjs ++ cxxObjs]
}
dynLinkerOpts = mempty {
ghcOptRPaths = rpaths
ghcOptRPaths = rpaths,
ghcOptInputFiles = toNubListR
[tmpDir </> x | x <- cObjs ++ cxxObjs]
Comment on lines -1368 to +1370
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

echoing @phadej's question:

This change is something else? We don't need cmmObjs nor asmObjs however?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't really understand the question. Before the files weren't even passed the the linker, now they are. It is possible that these other files are also needed but this patch fixes the issue for cxxObjs, as claimed, and other files types are out-of-scope.

Copy link
Member

@fgaz fgaz Mar 29, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't really understand the question.

Rephrasing as I understand it: Is this part of the "Include cmm-sources and asm-sources when linking shared objects" goal? If yes, why aren't cmmObjs and asmObjs included here too (as in cProfObjs/cSharedObjs)?

this patch fixes the issue for cxxObjs

wasn't it cmm and asm?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cObjs contains all the objs you list as it is constructed from cLikeFiles (which contains asm, cmm, c etc).

let cLikeFiles = fromNubListR $ mconcat

}
replOpts = baseOpts {
ghcOptExtra = Internal.filterGhciFlags
Expand Down
13 changes: 13 additions & 0 deletions cabal-testsuite/PackageTests/CmmSourcesDyn/cabal.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# cabal v2-run
Resolving dependencies...
Build profile: -w ghc-<GHCVER> -O1
In order, the following will be built:
- cmmexperiment-0 (lib) (first run)
- cmmexperiment-0 (exe:demo) (first run)
Configuring library for cmmexperiment-0..
Preprocessing library for cmmexperiment-0..
Building library for cmmexperiment-0..
Configuring executable 'demo' for cmmexperiment-0..
Warning: The package has an extraneous version range for a dependency on an internal library: cmmexperiment >=0 && ==0. This version range includes the current package but isn't needed as the current package's library will always be used.
Preprocessing executable 'demo' for cmmexperiment-0..
Building executable 'demo' for cmmexperiment-0..
2 changes: 2 additions & 0 deletions cabal-testsuite/PackageTests/CmmSourcesDyn/cabal.project
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
packages: .
executable-dynamic: True
7 changes: 7 additions & 0 deletions cabal-testsuite/PackageTests/CmmSourcesDyn/cabal.test.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import Test.Cabal.Prelude

main = cabalTest $ do
skipIfWindows
res <- cabal' "v2-run" ["demo"]
assertOutputContains "= Post common block elimination =" res
assertOutputContains "In Box we have 0x" res
6 changes: 6 additions & 0 deletions cabal-testsuite/PackageTests/CmmSourcesDyn/cbits/HeapPrim.cmm
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#include "Cmm.h"

aToMyWordzh (P_ clos)
{
return (clos);
}
27 changes: 27 additions & 0 deletions cabal-testsuite/PackageTests/CmmSourcesDyn/cmmexperiment.cabal
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
cabal-version: 3.0
name: cmmexperiment
version: 0
build-type: Simple

-- This code is extracted form ghc-heap
-- Copyright (c) 2012-2013, Joachim Breitner
-- (and probably -2020 GHC Team)
-- Under BSD-3-Clause

library
default-language: Haskell2010
hs-source-dirs: src
build-depends: base
exposed-modules: Demo

cmm-sources: cbits/HeapPrim.cmm
if impl(ghc >=8.2)
cmm-options: -ddump-cmm-verbose
else
cmm-options: -ddump-cmm

executable demo
default-language: Haskell2010
main-is: Main.hs
hs-source-dirs: demo
build-depends: base, cmmexperiment
2 changes: 2 additions & 0 deletions cabal-testsuite/PackageTests/CmmSourcesDyn/demo/Main.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
module Main (main) where
import Demo (main)
7 changes: 7 additions & 0 deletions cabal-testsuite/PackageTests/CmmSourcesDyn/setup.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Setup configure
Configuring cmmexperiment-0...
# Setup build
Preprocessing library for cmmexperiment-0..
Building library for cmmexperiment-0..
Preprocessing executable 'demo' for cmmexperiment-0..
Building executable 'demo' for cmmexperiment-0..
7 changes: 7 additions & 0 deletions cabal-testsuite/PackageTests/CmmSourcesDyn/setup.test.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import Test.Cabal.Prelude

main = setupTest $ do
skipIf "ghc < 7.8" =<< ghcVersionIs (< mkVersion [7,8])
setup "configure" []
res <- setup' "build" []
assertOutputContains "= Post common block elimination =" res
37 changes: 37 additions & 0 deletions cabal-testsuite/PackageTests/CmmSourcesDyn/src/Demo.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
{-# LANGUAGE CPP #-}
{-# LANGUAGE ForeignFunctionInterface #-}
{-# LANGUAGE GHCForeignImportPrim #-}
{-# LANGUAGE MagicHash #-}
{-# LANGUAGE UnliftedFFITypes #-}
module Demo (main) where

#include "MachDeps.h"

import Data.Bits
import GHC.Exts
import Numeric (showHex)

foreign import prim "aToMyWordzh" aToWord# :: Any -> Word#

tAG_MASK :: Int
tAG_MASK = (1 `shift` TAG_BITS) - 1

data Box = Box Any

instance Show Box where
showsPrec _ (Box a) rs =
-- unsafePerformIO (print "↓" >> pClosure a) `seq`
pad_out (showHex addr "") ++ (if tag>0 then "/" ++ show tag else "") ++ rs
where
ptr = W# (aToWord# a)
tag = ptr .&. fromIntegral tAG_MASK -- ((1 `shiftL` TAG_BITS) -1)
addr = ptr - tag
pad_out ls = '0':'x':ls

asBox :: a -> Box
asBox x = Box (unsafeCoerce# x)

main :: IO ()
main = do
let box = asBox "foobar"
putStrLn $ "In Box we have " ++ show box