Skip to content
This repository has been archived by the owner on Aug 2, 2020. It is now read-only.

Cannot Build: compareSizes (rts missing _TRACE_gc and _TRACE_sched) #90

Closed
angerman opened this issue Jan 4, 2016 · 11 comments
Closed
Labels

Comments

@angerman
Copy link
Collaborator

angerman commented Jan 4, 2016

/----------
| Run Ghc Stage1 (package = compareSizes)
|     input: utils/compare_sizes/stage1/build/Main.o
| => output: utils/compare_sizes/stage1/build/tmp/compareSizes
\----------
Undefined symbols for architecture x86_64:
  "_TRACE_gc", referenced from:
      _traceEventHeapInfo in libHSrts.a(Storage.o)
      _traceEventGcStats in libHSrts.a(Stats.o)
  "_TRACE_sched", referenced from:
      _traceTaskCreate in libHSrts.a(Schedule.o)
      _traceTaskCreate in libHSrts.a(RtsAPI.o)
      _traceTaskDelete in libHSrts.a(RtsAPI.o)
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
`clang' failed in phase `Linker'. (Exit code: 1)
shakeArgsWith    0.002s    0%                           
Function shake   0.030s    0%                           
Database read    0.128s    0%                           
With database    0.012s    0%                           
Running rules  294.047s   99%  =========================
Total          294.219s  100%                           
Error when running Shake build system:
* utils/compare_sizes/stage1/build/tmp/compareSizes
user error (Development.Shake.cmd, system command failed
Command: inplace/bin/ghc-stage1 -hisuf hi -osuf o -hcsuf hc -static -hide-all-packages -no-user-package-db -package-id base-4.9.0.0 -package-id directory-1.2.5.0 -package-id filepath-1.4.1.0 -i -iutils/compare_sizes/stage1/build -iutils/compare_sizes/stage1/build/autogen -iutils/compare_sizes -Iutils/compare_sizes/stage1/build -Iutils/compare_sizes/stage1/build/autogen -I/Users/angerman/Projects/Haskell/ghc/libraries/directory/include -I/Users/angerman/Projects/Haskell/ghc/libraries/unix/include -I/Users/angerman/Projects/Haskell/ghc/libraries/time/lib/include -I/Users/angerman/Projects/Haskell/ghc/libraries/bytestring/include -I/Users/angerman/Projects/Haskell/ghc/libraries/base/include -I/Users/angerman/Projects/Haskell/ghc/libraries/integer-gmp/include -I/Users/angerman/Projects/Haskell/ghc/rts/dist/build -I/Users/angerman/Projects/Haskell/ghc/includes -I/Users/angerman/Projects/Haskell/ghc/includes/dist-derivedconstants/header -optP-include -optPutils/compare_sizes/stage1/build/autogen/cabal_macros.h -XHaskell2010 -odir utils/compare_sizes/stage1/build -hidir utils/compare_sizes/stage1/build -stubdir utils/compare_sizes/stage1/build -rtsopts -H32m -O2 -Wall -fwarn-tabs -no-auto-link-packages -optl-liconv -optl-lm -optl-ldl -optl-L/Users/angerman/Projects/Haskell/ghc/libraries/directory/stage1/build -optl-L/Users/angerman/Projects/Haskell/ghc/libraries/unix/stage1/build -optl-L/Users/angerman/Projects/Haskell/ghc/libraries/time/stage1/build -optl-L/Users/angerman/Projects/Haskell/ghc/libraries/filepath/stage1/build -optl-L/Users/angerman/Projects/Haskell/ghc/libraries/bytestring/stage1/build -optl-L/Users/angerman/Projects/Haskell/ghc/libraries/deepseq/stage1/build -optl-L/Users/angerman/Projects/Haskell/ghc/libraries/array/stage1/build -optl-L/Users/angerman/Projects/Haskell/ghc/libraries/base/stage1/build -optl-L/Users/angerman/Projects/Haskell/ghc/libraries/integer-gmp/stage1/build -optl-L/Users/angerman/Projects/Haskell/ghc/libraries/ghc-prim/stage1/build -optl-L/Users/angerman/Projects/Haskell/ghc/rts/dist/build utils/compare_sizes/stage1/build/Main.o -o utils/compare_sizes/stage1/build/tmp/compareSizes
Exit code: 1
Stderr:
Undefined symbols for architecture x86_64:
  "_TRACE_gc", referenced from:
      _traceEventHeapInfo in libHSrts.a(Storage.o)
      _traceEventGcStats in libHSrts.a(Stats.o)
  "_TRACE_sched", referenced from:
      _traceTaskCreate in libHSrts.a(Schedule.o)
      _traceTaskCreate in libHSrts.a(RtsAPI.o)
      _traceTaskDelete in libHSrts.a(RtsAPI.o)
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
`clang' failed in phase `Linker'. (Exit code: 1)
)
@angerman angerman added the bug label Jan 4, 2016
@angerman
Copy link
Collaborator Author

angerman commented Jan 4, 2016

This happens when we link rts/dist to rts/stage1, and copy libffi into place. (e.g. cp libffi/build/inst/lib/libffi.a rts/dist/build/libCffi.a)

@angerman
Copy link
Collaborator Author

angerman commented Jan 4, 2016

Running the command by hand with -verbose yields:

inplace/bin/ghc-stage1 -hisuf hi -osuf o -hcsuf hc -static -hide-all-packages -no-user-package-db -package-id base-4.9.0.0 -package-id directory-1.2.5.0 -package-id filepath-1.4.1.0 -i -iutils/compare_sizes/stage1/build -iutils/compare_sizes/stage1/build/autogen -iutils/compare_sizes -Iutils/compare_sizes/stage1/build -Iutils/compare_sizes/stage1/build/autogen -I/Users/angerman/Projects/Haskell/ghc/libraries/directory/include -I/Users/angerman/Projects/Haskell/ghc/libraries/unix/include -I/Users/angerman/Projects/Haskell/ghc/libraries/time/lib/include -I/Users/angerman/Projects/Haskell/ghc/libraries/bytestring/include -I/Users/angerman/Projects/Haskell/ghc/libraries/base/include -I/Users/angerman/Projects/Haskell/ghc/libraries/integer-gmp/include -I/Users/angerman/Projects/Haskell/ghc/rts/stage1/build -I/Users/angerman/Projects/Haskell/ghc/includes -I/Users/angerman/Projects/Haskell/ghc/includes/dist-derivedconstants/header -optP-include -optPutils/compare_sizes/stage1/build/autogen/cabal_macros.h -XHaskell2010 -odir utils/compare_sizes/stage1/build -hidir utils/compare_sizes/stage1/build -stubdir utils/compare_sizes/stage1/build -rtsopts -H32m -O2 -Wall -fwarn-tabs -no-auto-link-packages -optl-liconv -optl-lm -optl-ldl -optl-L/Users/angerman/Projects/Haskell/ghc/libraries/directory/stage1/build -optl-L/Users/angerman/Projects/Haskell/ghc/libraries/unix/stage1/build -optl-L/Users/angerman/Projects/Haskell/ghc/libraries/time/stage1/build -optl-L/Users/angerman/Projects/Haskell/ghc/libraries/filepath/stage1/build -optl-L/Users/angerman/Projects/Haskell/ghc/libraries/bytestring/stage1/build -optl-L/Users/angerman/Projects/Haskell/ghc/libraries/deepseq/stage1/build -optl-L/Users/angerman/Projects/Haskell/ghc/libraries/array/stage1/build -optl-L/Users/angerman/Projects/Haskell/ghc/libraries/base/stage1/build -optl-L/Users/angerman/Projects/Haskell/ghc/libraries/integer-gmp/stage1/build -optl-L/Users/angerman/Projects/Haskell/ghc/libraries/ghc-prim/stage1/build -optl-L/Users/angerman/Projects/Haskell/ghc/rts/stage1/build utils/compare_sizes/stage1/build/Main.o -o utils/compare_sizes/stage1/build/tmp/compareSizes -v      
Glasgow Haskell Compiler, Version 7.11.20151228, stage 1 booted by GHC version 7.10.2
Using binary package database: /Users/angerman/Projects/Haskell/ghc/inplace/lib/package.conf.d/package.cache
loading package database /Users/angerman/Projects/Haskell/ghc/inplace/lib/package.conf.d
wired-in package ghc-prim mapped to ghc-prim-0.5.0.0
wired-in package integer-gmp mapped to integer-gmp-1.0.0.0
wired-in package base mapped to base-4.9.0.0
wired-in package rts mapped to rts
wired-in package template-haskell not found.
wired-in package ghc not found.
wired-in package dph-seq not found.
wired-in package dph-par not found.
Hsc static flags: 
Created temporary directory: /var/folders/fv/xqjrpfj516n5xq_m_ljpsjx00000gn/T/ghc21085_0
*** C Compiler:
/usr/bin/clang -m64 -fno-stack-protector -DTABLES_NEXT_TO_CODE -c /var/folders/fv/xqjrpfj516n5xq_m_ljpsjx00000gn/T/ghc21085_0/ghc_1.c -o /var/folders/fv/xqjrpfj516n5xq_m_ljpsjx00000gn/T/ghc21085_0/ghc_2.o -I/Users/angerman/Projects/Haskell/ghc/rts/stage1/build -I/Users/angerman/Projects/Haskell/ghc/includes -I/Users/angerman/Projects/Haskell/ghc/includes/dist-derivedconstants/header -fno-common -U__PIC__ -D__PIC__
*** Linker:
/usr/bin/clang -m64 -fno-stack-protector -DTABLES_NEXT_TO_CODE -m64 -liconv -lm -ldl -L/Users/angerman/Projects/Haskell/ghc/libraries/directory/stage1/build -L/Users/angerman/Projects/Haskell/ghc/libraries/unix/stage1/build -L/Users/angerman/Projects/Haskell/ghc/libraries/time/stage1/build -L/Users/angerman/Projects/Haskell/ghc/libraries/filepath/stage1/build -L/Users/angerman/Projects/Haskell/ghc/libraries/bytestring/stage1/build -L/Users/angerman/Projects/Haskell/ghc/libraries/deepseq/stage1/build -L/Users/angerman/Projects/Haskell/ghc/libraries/array/stage1/build -L/Users/angerman/Projects/Haskell/ghc/libraries/base/stage1/build -L/Users/angerman/Projects/Haskell/ghc/libraries/integer-gmp/stage1/build -L/Users/angerman/Projects/Haskell/ghc/libraries/ghc-prim/stage1/build -L/Users/angerman/Projects/Haskell/ghc/rts/stage1/build -o utils/compare_sizes/stage1/build/tmp/compareSizes -Wl,-no_compact_unwind utils/compare_sizes/stage1/build/Main.o -L/Users/angerman/Projects/Haskell/ghc/libraries/directory/stage1/build -L/Users/angerman/Projects/Haskell/ghc/libraries/unix/stage1/build -L/Users/angerman/Projects/Haskell/ghc/libraries/bytestring/stage1/build -L/Users/angerman/Projects/Haskell/ghc/libraries/time/stage1/build -L/Users/angerman/Projects/Haskell/ghc/libraries/deepseq/stage1/build -L/Users/angerman/Projects/Haskell/ghc/libraries/array/stage1/build -L/Users/angerman/Projects/Haskell/ghc/libraries/filepath/stage1/build -L/Users/angerman/Projects/Haskell/ghc/libraries/base/stage1/build -L/Users/angerman/Projects/Haskell/ghc/libraries/integer-gmp/stage1/build -L/Users/angerman/Projects/Haskell/ghc/libraries/ghc-prim/stage1/build -L/Users/angerman/Projects/Haskell/ghc/rts/stage1/build /var/folders/fv/xqjrpfj516n5xq_m_ljpsjx00000gn/T/ghc21085_0/ghc_2.o -Wl,-u,_ghczmprim_GHCziTypes_Izh_static_info -Wl,-u,_ghczmprim_GHCziTypes_Czh_static_info -Wl,-u,_ghczmprim_GHCziTypes_Fzh_static_info -Wl,-u,_ghczmprim_GHCziTypes_Dzh_static_info -Wl,-u,_base_GHCziPtr_Ptr_static_info -Wl,-u,_ghczmprim_GHCziTypes_Wzh_static_info -Wl,-u,_base_GHCziInt_I8zh_static_info -Wl,-u,_base_GHCziInt_I16zh_static_info -Wl,-u,_base_GHCziInt_I32zh_static_info -Wl,-u,_base_GHCziInt_I64zh_static_info -Wl,-u,_base_GHCziWord_W8zh_static_info -Wl,-u,_base_GHCziWord_W16zh_static_info -Wl,-u,_base_GHCziWord_W32zh_static_info -Wl,-u,_base_GHCziWord_W64zh_static_info -Wl,-u,_base_GHCziStable_StablePtr_static_info -Wl,-u,_ghczmprim_GHCziTypes_Izh_con_info -Wl,-u,_ghczmprim_GHCziTypes_Czh_con_info -Wl,-u,_ghczmprim_GHCziTypes_Fzh_con_info -Wl,-u,_ghczmprim_GHCziTypes_Dzh_con_info -Wl,-u,_base_GHCziPtr_Ptr_con_info -Wl,-u,_base_GHCziPtr_FunPtr_con_info -Wl,-u,_base_GHCziStable_StablePtr_con_info -Wl,-u,_ghczmprim_GHCziTypes_False_closure -Wl,-u,_ghczmprim_GHCziTypes_True_closure -Wl,-u,_base_GHCziPack_unpackCString_closure -Wl,-u,_base_GHCziIOziException_stackOverflow_closure -Wl,-u,_base_GHCziIOziException_heapOverflow_closure -Wl,-u,_base_ControlziExceptionziBase_nonTermination_closure -Wl,-u,_base_GHCziIOziException_blockedIndefinitelyOnMVar_closure -Wl,-u,_base_GHCziIOziException_blockedIndefinitelyOnSTM_closure -Wl,-u,_base_GHCziIOziException_allocationLimitExceeded_closure -Wl,-u,_base_ControlziExceptionziBase_nestedAtomically_closure -Wl,-u,_base_GHCziEventziThread_blockedOnBadFD_closure -Wl,-u,_base_GHCziWeak_runFinalizzerBatch_closure -Wl,-u,_base_GHCziTopHandler_flushStdHandles_closure -Wl,-u,_base_GHCziTopHandler_runIO_closure -Wl,-u,_base_GHCziTopHandler_runNonIO_closure -Wl,-u,_base_GHCziConcziIO_ensureIOManagerIsRunning_closure -Wl,-u,_base_GHCziConcziIO_ioManagerCapabilitiesChanged_closure -Wl,-u,_base_GHCziConcziSync_runSparks_closure -Wl,-u,_base_GHCziConcziSignal_runHandlersPtr_closure -Wl,-search_paths_first -lHSdirectory-1.2.5.0 -lHSunix-2.7.1.1 -lHSbytestring-0.10.7.0 -lHStime-1.6 -lHSdeepseq-1.4.2.0 -lHSarray-0.5.1.0 -lHSfilepath-1.4.1.0 -lHSbase-4.9.0.0 -lHSinteger-gmp-1.0.0.0 -lHSghc-prim-0.5.0.0 -lHSrts -lCffi -liconv -lm -ldl
Undefined symbols for architecture x86_64:
  "_TRACE_gc", referenced from:
      _traceEventHeapInfo in libHSrts.a(Storage.o)
      _traceEventGcStats in libHSrts.a(Stats.o)
  "_TRACE_sched", referenced from:
      _traceTaskCreate in libHSrts.a(Schedule.o)
      _traceTaskCreate in libHSrts.a(RtsAPI.o)
      _traceTaskDelete in libHSrts.a(RtsAPI.o)
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
*** Deleting temp files:
Deleting: /var/folders/fv/xqjrpfj516n5xq_m_ljpsjx00000gn/T/ghc21085_0/ghc_4.rsp /var/folders/fv/xqjrpfj516n5xq_m_ljpsjx00000gn/T/ghc21085_0/ghc_3.rsp /var/folders/fv/xqjrpfj516n5xq_m_ljpsjx00000gn/T/ghc21085_0/ghc_2.o /var/folders/fv/xqjrpfj516n5xq_m_ljpsjx00000gn/T/ghc21085_0/ghc_1.c
*** Deleting temp dirs:
Deleting: /var/folders/fv/xqjrpfj516n5xq_m_ljpsjx00000gn/T/ghc21085_0
`clang' failed in phase `Linker'. (Exit code: 1)

@angerman
Copy link
Collaborator Author

angerman commented Jan 4, 2016

Some more info

/----------
| Run Ar (stage = Stage1, package = rts)
|     input: rts/stage1/build/Adjustor.o (and 86 more)
| => output: rts/stage1/build/libHSrts.a
\----------
ar: creating archive rts/stage1/build/libHSrts.a
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ranlib: file: rts/stage1/build/libHSrts.a(Disassembler.o) has no symbols
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ranlib: file: rts/stage1/build/libHSrts.a(LdvProfile.o) has no symbols
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ranlib: file: rts/stage1/build/libHSrts.a(OldARMAtomic.o) has no symbols
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ranlib: file: rts/stage1/build/libHSrts.a(Profiling.o) has no symbols
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ranlib: file: rts/stage1/build/libHSrts.a(RetainerProfile.o) has no symbols
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ranlib: file: rts/stage1/build/libHSrts.a(RetainerSet.o) has no symbols
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ranlib: file: rts/stage1/build/libHSrts.a(RtsDllMain.o) has no symbols
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ranlib: file: rts/stage1/build/libHSrts.a(Trace.o) has no symbols
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ranlib: file: rts/stage1/build/libHSrts.a(EventLog.o) has no symbols
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ranlib: file: rts/stage1/build/libHSrts.a(Sanity.o) has no symbols

@angerman angerman changed the title Cannot Build: compareSizes Cannot Build: compareSizes (rts missing _TRACE_gc and _TRACE_sched) Jan 4, 2016
@snowleopard
Copy link
Owner

I am now stuck at this point too on Windows.

@snowleopard
Copy link
Owner

We are building C files in rts using a C compiler, however, the old build system is using GHC for this. I wonder whether this is relevant; I don't know why use GHC for compiling C files.

@snowleopard
Copy link
Owner

Here is the current command we use to produce Trace.o:

D:/msys/home/nam83/ghc/inplace/mingw/bin/gcc.exe 
-Iincludes 
-Iincludes/dist-derivedconstants/header 
-Irts/stage1/build 
-Irts/stage1/build/autogen 
-c rts/Trace.c 
-o rts/stage1/build/Trace.o 
-Irts 
-Irts/stage1/build
"-DRtsWay=\"rts_v\"" 
-DCOMPILING_RTS
"-DProjectVersion=\"8.1.20160104\""

Here is what the old system uses:

"inplace/bin/ghc-stage1.exe" 
-optc-fno-stack-protector 
-optc-Wall 
-optc-Wall 
-optc-Wextra 
-optc-Wstrict-prototypes 
-optc-Wmissing-prototypes 
-optc-Wmissing-declarations 
-optc-Winline 
-optc-Waggregate-return 
-optc-Wpointer-arith 
-optc-Wmissing-noreturn 
-optc-Wnested-externs 
-optc-Wredundant-decls 
-optc-Iincludes 
-optc-Iincludes/dist 
-optc-Iincludes/dist-derivedconstants/header 
-optc-Iincludes/dist-ghcconstants/header 
-optc-Irts 
-optc-Irts/stage1/build 
-optc-DCOMPILING_RTS 
-optc-fno-strict-aliasing 
-optc-fno-common 
-optc-Irts/stage1/build/autogen 
-optc-Wno-error=inline 
-optc-O2 
-optc-fomit-frame-pointer 
-optc-g 
-optc-DRtsWay=\"rts_v\" 
-optc-DWINVER=0x06000100 
-optc-DProjectVersion=\"8.1.20160104\" 
-static  
-H32m 
-O 
-Wall  
-Iincludes 
-Iincludes/dist 
-Iincludes/dist-derivedconstants/header 
-Iincludes/dist-ghcconstants/header 
-Irts 
-Irts/stage1/build 
-DCOMPILING_RTS 
-this-package-key rts 
-dcmm-lint      
-i 
-irts 
-irts/stage1/build 
-irts/stage1/build/autogen 
-Irts/stage1/build 
-Irts/stage1/build/autogen           
-O2     
-c rts/Trace.c 
-o rts/stage1/build/Trace.o

Quite a big difference, but I wonder which flag is crucial for this issue, and how the result is affected by the choice of builder (gcc vs ghc). I don't want to blindly reproduce all the options (yet).

The fact is, the resulting object files are different, in particular, the former doesn't contain TRACE_gc, while the latter does.

@angerman
Copy link
Collaborator Author

angerman commented Jan 5, 2016

Strangely enough, my make log, lists -DDTRACE. And otherwise the only difference in the built file is -g, which adds debug information. Without -DDTRACE I get a 1.4k object file that contains nothing but debug info. Without -g I obtain an empty 200 byte file.

For -DDTRACE to work, I would need RtsProbes.h, which doesn't exist.

@angerman
Copy link
Collaborator Author

angerman commented Jan 5, 2016

The big differences I see are:

-O2 -fomit-frame-pointer -fno-strict-aliasing -fno-common

-O2 being the most important here, as it forces the inlining (or at least that's what I think).

In Trace.h we find:

INLINE_HEADER void traceEventHeapInfo(...) { ... }

for which includes/Stg.h contains the definition:

134:# define INLINE_HEADER static inline
163:# define INLINE_HEADER __inline static

As far as I can tell, for llvm's clang, -inline comes with -O2. Then again, I'm not sure if inline is actually supposed to be a hint to the compiler, or force the compiler to actually inline a function. Experimental results (-O0 vs -O2), imply the compiler handles it as a suggestion.

Can anyone more knowledgeable support make any sense out of this?

@angerman
Copy link
Collaborator Author

angerman commented Jan 5, 2016

According to http://stackoverflow.com/questions/25602813/force-a-function-to-be-inline-in-clang-llvm/25623448#25623448, my suspicion is correct.

Now, I'm not sure if this should actually be considered a bug in Haskells RTS or not, at least it should be noted somewhere that rts needs to be compiled with optimizations. Maybe it is, and I just didn't find it though.

@snowleopard
Copy link
Owner

@angerman Awesome! Many thanks for finding the reason. I couldn't imagine -O2 affected linking... And I don't remember seeing any comments about this while looking through makefiles for a solution.

@angerman
Copy link
Collaborator Author

angerman commented Jan 5, 2016

@snowleopard I ended up comparing the symbols in the object files, and wondered why they were missing in one, but not the other... after looking for the symbols in the source I kept wondering what was different wrt the inlining. Then it dawned on me that it had to be an optimization pass.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

2 participants