agentm / project-m36

Project: M36 Relational Algebra Engine
The Unlicense
876 stars 47 forks source link

Problem loading precompiled functions #311

Closed farzadbekran closed 2 years ago

farzadbekran commented 2 years ago

I've made a few atom functions: Gist Link

I use stack to compile it from project root:

stack exec -- ghc src/DB/ConstraintFunctions.hs -package project-m36 -package text

which compile without errors. then I start project-m36-server and tutd from the project root and load the object file like this:

TutorialD (master/main): loadatomfunctions "DB.ConstraintFunctions" "atomFunctions" "src/DB/ConstraintFunctions.o"

no problem so far, but when I run :showatomfunctions in tutd, the server crashes with these errors:

project-m36-server: src/DB/ConstraintFunctions.o: unknown symbol `textzm1zi2zi4zi0_DataziText_lines_closure'
./start-db.sh: line 3: 219286 Segmentation fault      (core dumped) stack exec -- project-m36-server -n shopper-db -d shopper-db --fsync
farzadbekran commented 2 years ago

@agentm Sorry for some reason I cant connect to IRC. Text library version is set to : text >=0.11 && <2.0 and the stack resolver is: lts-16.31

Let me know if you need anything else.

agentm commented 2 years ago

I tried a stripped down example of this with just cabal:

Issue311.hs

{-# LANGUAGE OverloadedStrings #-}
module Issue311 where
import Data.Text
import ProjectM36.Base
import ProjectM36.AtomFunctionError

func :: [Atom] -> Either AtomFunctionError Atom
func (x:[]) = pure x
func _ = error "bad"

atomFunctions :: [AtomFunction]
atomFunctions =
  [ AtomFunction { atomFuncName = "func"
                 , atomFuncType = [ IntegerAtomType
                                  , IntegerAtomType]
                 , atomFuncBody = AtomFunctionBody Nothing func
                 }
  ]

built with:

cabal exec ghc Issue311.hs

tutd

TutorialD (master/main): loadatomfunctions "Issue311" "atomFunctions" "Issue311.o"
tutd: Issue311.o: unknown symbol `ghczmprim_GHCziCString_unpackCStringzh_closure'
tutd: Could not load Object Code Issue311.o.

Indeed, tutd does not include this symbol:

strings dist-newstyle/build/x86_64-linux/ghc-8.10.4/project-m36-0.9.3/x/tutd/build/tutd/tutd|grep ghczmprim_GHCziCString
ghczmprim_GHCziCString_unpackNByteszh_closure
ghczmprim_GHCziCString_unpackFoldrCStringzh_closure
ghczmprim_GHCziCString_unpackAppendCStringzh_closure
ghczmprim_GHCziCString_unpackCStringzh_info
ghczmprim_GHCziCString_unpackAppendCStringzh_info
ghczmprim_GHCziCString_unpackFoldrCStringzh_info
ghczmprim_GHCziCString_unpackCStringUtf8zh_info
ghczmprim_GHCziCString_unpackNByteszh_info

If I remove the error "bad", then I get a different missing symbol:

tutd: Issue311.o: unknown symbol `base_DataziEither_zdfApplicativeEither_closure'
tutd: Could not load Object Code Issue311.o.

I realized that ghc must be stripping these "unused" symbols and noticed that tutd is not built with -rdynamic which prevents this. Originally, I thought that -rdynamic at the library level would be sufficient, but apparently it is needed at the executable level, too.

Just for reference, there are two other ways to add new AtomFunctions to Project:M36: