Libdw: Add libdw-based stack unwinding
ClosedPublic

Authored by bgamari on Sep 1 2015, 1:38 PM.

Details

Summary

This adds basic support to the RTS for DWARF-assisted unwinding of the Haskell
and C stack via libdw. This only adds the infrastructure; consumers of this
functionality will be introduced in future diffs.

This replaces D1156.

To do

  • More clean ups, fix failures when libdw is unavailable
  • Implement initial register code for ARM and i386
  • Push initial register code upstream to libdw
Test Plan

See future patches

Diff Detail

Repository
rGHC Glasgow Haskell Compiler
Lint
Automatic diff as part of commit; lint not applicable.
Unit
Automatic diff as part of commit; unit tests not applicable.
There are a very large number of changes, so older changes are hidden. Show Older Changes
  • Address comments from Simon
bgamari added a comment.EditedSep 2 2015, 3:12 AM

I've update the diff.

@simonmar, your mention of the missing Begin/EndPrivate #includes reminds me of an outstanding issue with this patch. For some reason the symbols defined in Libdw.c aren't visible for dynamic linking. This results in linker failures when producing dynamically-linked executables. For instance,

$ "inplace/bin/ghc-stage1" -o utils/dll-split/dist-install/build/tmp/dll-split -hisuf dyn_hi -osuf  dyn_o -hcsuf dyn_hc -fPIC -dynamic  -H32m -O -Wall -H64m -O0 -Werror    -hide-all-packages -i -iutils/dll-split/. -iutils/dll-split/dist-install/build -iutils/dll-split/dist-install/build/autogen -Iutils/dll-split/dist-install/build -Iutils/dll-split/dist-install/build/autogen     -optP-include -optPutils/dll-split/dist-install/build/autogen/cabal_macros.h -package-id base-4.8.2.0-inplace -package-id containers-0.5.6.2-inplace -package-id filepath-1.4.0.0-inplace -XHaskell2010  -no-user-package-db -rtsopts      -odir utils/dll-split/dist-install/build -hidir utils/dll-split/dist-install/build -stubdir utils/dll-split/dist-install/build   -optl-L'/mnt/work/ghc/ghc-testing/libraries/filepath/dist-install/build' -optl-L'/mnt/work/ghc/ghc-testing/libraries/containers/dist-install/build' -optl-L'/mnt/work/ghc/ghc-testing/libraries/deepseq/dist-install/build' -optl-L'/mnt/work/ghc/ghc-testing/libraries/array/dist-install/build' -optl-L'/mnt/work/ghc/ghc-testing/libraries/base/dist-install/build' -optl-L'/mnt/work/ghc/ghc-testing/libraries/integer-gmp/dist-install/build' -optl-L'/mnt/work/ghc/ghc-testing/libraries/ghc-prim/dist-install/build' -optl-L'/mnt/work/ghc/ghc-testing/rts/dist/build' -optl-lgmp -optl-lm -optl-lrt -optl-ldl -optl-lelf -optl-ldw -fPIC -dynamic  -H32m -O -Wall -H64m -O0 -Werror    -hide-all-packages -i -iutils/dll-split/. -iutils/dll-split/dist-install/build -iutils/dll-split/dist-install/build/autogen -Iutils/dll-split/dist-install/build -Iutils/dll-split/dist-install/build/autogen     -optP-include -optPutils/dll-split/dist-install/build/autogen/cabal_macros.h -package-id base-4.8.2.0-inplace -package-id containers-0.5.6.2-inplace -package-id filepath-1.4.0.0-inplace -XHaskell2010  -no-user-package-db -rtsopts      -fno-use-rpaths -optl-Wl,-rpath -optl-Wl,'$ORIGIN/../filepath-1.4.0.0-1JAITKvHpQMB1Z8MyW8f8Q' -optl-Wl,-rpath -optl-Wl,'$ORIGIN/../containers-0.5.6.2-0tT640fErehCGZtZRn6YbE' -optl-Wl,-rpath -optl-Wl,'$ORIGIN/../deepseq-1.4.1.1-GH35GlhX1q4FBP3fXBiuVd' -optl-Wl,-rpath -optl-Wl,'$ORIGIN/../array-0.5.1.0-I1wXYvK6TcFEGuLdlhmQmd' -optl-Wl,-rpath -optl-Wl,'$ORIGIN/../base-4.8.2.0-FkKrfrxMoa06H6w6uNoJiJ' -optl-Wl,-rpath -optl-Wl,'$ORIGIN/../integer-gmp-1.0.0.0-CFmMLlb2ZLuJHwRXOynyUL' -optl-Wl,-rpath -optl-Wl,'$ORIGIN/../ghc-prim-0.4.0.0-8TmvWUcS1U1IKHT0levwg3' -optl-Wl,-rpath -optl-Wl,'$ORIGIN/../rts' -optl-Wl,-zorigin utils/dll-split/dist-install/build/Main.dyn_o    -v
Glasgow Haskell Compiler, Version 7.11.20150902, stage 1 booted by GHC version 7.8.4
Using binary package database: /mnt/work/ghc/ghc-testing/inplace/lib/package.conf.d/package.cache
wired-in package ghc-prim mapped to ghc-prim-0.4.0.0-inplace
wired-in package integer-gmp mapped to integer-gmp-1.0.0.0-inplace
wired-in package base mapped to base-4.8.2.0-inplace
wired-in package rts mapped to builtin_rts
wired-in package template-haskell mapped to template-haskell-2.11.0.0-inplace
wired-in package ghc mapped to ghc-7.11.20150902-inplace
wired-in package dph-seq not found.
wired-in package dph-par not found.
Hsc static flags: 
Created temporary directory: /tmp/ghc26881_0
*** C Compiler:
/usr/bin/gcc -fno-stack-protector -DTABLES_NEXT_TO_CODE -c /tmp/ghc26881_0/ghc_1.c -o /tmp/ghc26881_0/ghc_2.o -I/mnt/work/ghc/ghc-testing/rts/dist/build -I/mnt/work/ghc/ghc-testing/includes -I/mnt/work/ghc/ghc-testing/includes/dist-derivedconstants/header -fPIC -U__PIC__ -D__PIC__
*** C Compiler:
/usr/bin/gcc -fno-stack-protector -DTABLES_NEXT_TO_CODE -c /tmp/ghc26881_0/ghc_3.s -o /tmp/ghc26881_0/ghc_4.o -I/mnt/work/ghc/ghc-testing/rts/dist/build -I/mnt/work/ghc/ghc-testing/includes -I/mnt/work/ghc/ghc-testing/includes/dist-derivedconstants/header -fPIC -U__PIC__ -D__PIC__
*** Linker:
/usr/bin/gcc -fno-stack-protector -DTABLES_NEXT_TO_CODE '-Wl,--hash-size=31' -Wl,--reduce-memory-overheads -Wl,--no-as-needed -L/mnt/work/ghc/ghc-testing/libraries/filepath/dist-install/build -L/mnt/work/ghc/ghc-testing/libraries/containers/dist-install/build -L/mnt/work/ghc/ghc-testing/libraries/deepseq/dist-install/build -L/mnt/work/ghc/ghc-testing/libraries/array/dist-install/build -L/mnt/work/ghc/ghc-testing/libraries/base/dist-install/build -L/mnt/work/ghc/ghc-testing/libraries/integer-gmp/dist-install/build -L/mnt/work/ghc/ghc-testing/libraries/ghc-prim/dist-install/build -L/mnt/work/ghc/ghc-testing/rts/dist/build -lgmp -lm -lrt -ldl -lelf -ldw -Wl,-rpath '-Wl,$ORIGIN/../filepath-1.4.0.0-1JAITKvHpQMB1Z8MyW8f8Q' -Wl,-rpath '-Wl,$ORIGIN/../containers-0.5.6.2-0tT640fErehCGZtZRn6YbE' -Wl,-rpath '-Wl,$ORIGIN/../deepseq-1.4.1.1-GH35GlhX1q4FBP3fXBiuVd' -Wl,-rpath '-Wl,$ORIGIN/../array-0.5.1.0-I1wXYvK6TcFEGuLdlhmQmd' -Wl,-rpath '-Wl,$ORIGIN/../base-4.8.2.0-FkKrfrxMoa06H6w6uNoJiJ' -Wl,-rpath '-Wl,$ORIGIN/../integer-gmp-1.0.0.0-CFmMLlb2ZLuJHwRXOynyUL' -Wl,-rpath '-Wl,$ORIGIN/../ghc-prim-0.4.0.0-8TmvWUcS1U1IKHT0levwg3' -Wl,-rpath '-Wl,$ORIGIN/../rts' -Wl,-zorigin -o utils/dll-split/dist-install/build/tmp/dll-split utils/dll-split/dist-install/build/Main.dyn_o -L/mnt/work/ghc/ghc-testing/libraries/filepath/dist-install/build -Wl,-rpath-link -Wl,/mnt/work/ghc/ghc-testing/libraries/filepath/dist-install/build -L/mnt/work/ghc/ghc-testing/libraries/containers/dist-install/build -Wl,-rpath-link -Wl,/mnt/work/ghc/ghc-testing/libraries/containers/dist-install/build -L/mnt/work/ghc/ghc-testing/libraries/deepseq/dist-install/build -Wl,-rpath-link -Wl,/mnt/work/ghc/ghc-testing/libraries/deepseq/dist-install/build -L/mnt/work/ghc/ghc-testing/libraries/array/dist-install/build -Wl,-rpath-link -Wl,/mnt/work/ghc/ghc-testing/libraries/array/dist-install/build -L/mnt/work/ghc/ghc-testing/libraries/base/dist-install/build -Wl,-rpath-link -Wl,/mnt/work/ghc/ghc-testing/libraries/base/dist-install/build -L/mnt/work/ghc/ghc-testing/libraries/integer-gmp/dist-install/build -Wl,-rpath-link -Wl,/mnt/work/ghc/ghc-testing/libraries/integer-gmp/dist-install/build -L/mnt/work/ghc/ghc-testing/libraries/ghc-prim/dist-install/build -Wl,-rpath-link -Wl,/mnt/work/ghc/ghc-testing/libraries/ghc-prim/dist-install/build -L/mnt/work/ghc/ghc-testing/rts/dist/build -Wl,-rpath-link -Wl,/mnt/work/ghc/ghc-testing/rts/dist/build /tmp/ghc26881_0/ghc_2.o /tmp/ghc26881_0/ghc_4.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 -lHSfilepath-1.4.0.0-1JAITKvHpQMB1Z8MyW8f8Q-ghc7.11.20150902 -lHScontainers-0.5.6.2-0tT640fErehCGZtZRn6YbE-ghc7.11.20150902 -lHSdeepseq-1.4.1.1-GH35GlhX1q4FBP3fXBiuVd-ghc7.11.20150902 -lHSarray-0.5.1.0-I1wXYvK6TcFEGuLdlhmQmd-ghc7.11.20150902 -lHSbase-4.8.2.0-FkKrfrxMoa06H6w6uNoJiJ-ghc7.11.20150902 -lHSinteger-gmp-1.0.0.0-CFmMLlb2ZLuJHwRXOynyUL-ghc7.11.20150902 -lHSghc-prim-0.4.0.0-8TmvWUcS1U1IKHT0levwg3-ghc7.11.20150902 -lHSrts-ghc7.11.20150902 -lffi -lgmp -lm -lrt -ldl -lelf -ldw
/mnt/work/ghc/ghc-testing/libraries/base/dist-install/build/libHSbase-4.8.2.0-FkKrfrxMoa06H6w6uNoJiJ-ghc7.11.20150902.so: undefined reference to `libdw_cap_lookup_location'
/mnt/work/ghc/ghc-testing/libraries/base/dist-install/build/libHSbase-4.8.2.0-FkKrfrxMoa06H6w6uNoJiJ-ghc7.11.20150902.so: undefined reference to `libdw_cap_get_backtrace'
/mnt/work/ghc/ghc-testing/libraries/base/dist-install/build/libHSbase-4.8.2.0-FkKrfrxMoa06H6w6uNoJiJ-ghc7.11.20150902.so: undefined reference to `libdw_cap_free'
/mnt/work/ghc/ghc-testing/libraries/base/dist-install/build/libHSbase-4.8.2.0-FkKrfrxMoa06H6w6uNoJiJ-ghc7.11.20150902.so: undefined reference to `backtrace_free'
collect2: error: ld returned 1 exit status
*** Deleting temp files:
Deleting: /tmp/ghc26881_0/ghc_4.o /tmp/ghc26881_0/ghc_3.s /tmp/ghc26881_0/ghc_2.o /tmp/ghc26881_0/ghc_1.c
*** Deleting temp dirs:
Deleting: /tmp/ghc26881_0

Do you see anything obviously missing from this patch to get dynamic linking working?

rts/Libdw.c
18

Shouldn't these go in the header file, not the source file?

20

Good catch.

38–40

Yeah, that's a fair point.

145–146

I've added a comment for this. libdwfl owns this memory and therefore we should not free it.

237

Right, I'll need to do some digging for this. I pretty much built this implementation by comparing the existing libdw implementation for ptrace'd processes. Ideally I would like to eliminate this code entire and push it upstream to libdw, but that will take some time.

scpmw edited edge metadata.Sep 2 2015, 12:24 PM

Comments.

rts/Libdw.c
39–41

Or link the list the other way around, and reverse it when decoding, see above.

rts/Libdw.h
25

Just as an aside - this actually looks remarkably similar to what we'd need for "chunked" exception handling with rethrows. Except that we would *really* want to link the list the other way around to avoid re-traversing the chunk list on every rethrow.

48

What does the "tied to a cap" comment mean? Does it need to be freed by that particular capability? Code doesn't really refer to it either?

simonmar added inline comments.Sep 2 2015, 12:54 PM
rts/Libdw.c
19

The #includes, you mean? I just took a look at the current style and it doesn't look very consistent, but it looks to be something like Rts.h always goes in the source file, but other dependencies can be in the .h file. We should probably figure out a good policy and use it consistently - perhaps every header file should include its own dependencies. But it's hard to do this well without something equivalent to -fwarn-unused-imports.

bgamari updated this revision to Diff 4045.Sep 3 2015, 7:39 AM
bgamari edited edge metadata.

Address comments

bgamari updated this revision to Diff 4056.Sep 4 2015, 3:59 AM
bgamari edited edge metadata.

Another update

bgamari updated this revision to Diff 4071.Sep 4 2015, 9:47 AM
bgamari edited edge metadata.

Fix warning

bgamari updated this revision to Diff 4077.Sep 4 2015, 4:40 PM
bgamari marked 3 inline comments as done.
bgamari edited edge metadata.

Flip around stack frame list

I've flipped around the order of the chunk list to allow for O(1) appends.

bgamari marked 6 inline comments as done.Sep 5 2015, 10:01 AM
bgamari added inline comments.
rts/Libdw.c
91

It sets libelf's errno to ELF_E_UNKNOWN_VERSION in the event that it can't produce the requested version.

Finally had time to go through this in detail. It looks really good and exciting!

includes/rts/Libdw.h
14

Should there be a comment motivating this size? If it's arbitrarily picked, I think it's good to have a comment saying that it was arbitrarily picked.

39

Awesome with ascii-art in the note! :)

rts/Libdw.c
36

Make it void? You always return 0 and you never use the return value in any of the invocations anyway.

52

It feels weird to me to first free the outer structure. But it doesn't matter I suppose. :)

70

Should you perhaps start with a session == NULL check like you do in backtrace_free? I'm not sure of the conventions for C nor RTS code. But it seems inconsistent with backtrace_free now.

74

Should you also comment what value you return?

It seems to me that a LibDwSession contains the Backtrace value, does that mean that calling libdw_init() also reifies the stack? Will it reload all DWARF information if I call libdw_init() again?

112

This error message that tries to be more "human readable" might end up just being more confusing. Would it be better to "not try" and just say "dwfl_attach_state failed : %s" like we do for the other calls?

113

Maybe it's a bit to early to think about exceptional memory management. But if you return NULL here, will anyone be responsible of freeing the session variable?

228

Can you comment on the logic here? I'm not sure I understand what happens and why.

333

This won't work iirc because the stg stack is chunked. See the TRAVERSE_STACK macro I put in Stack.c in D963.

bgamari updated this revision to Diff 4096.Sep 6 2015, 12:10 PM
bgamari marked 6 inline comments as done.
bgamari edited edge metadata.

Handle feedback from Tarrasch

bgamari marked 3 inline comments as done.Sep 6 2015, 4:41 PM

Finally had time to go through this in detail. It looks really good and exciting!

Thanks for the review!

includes/rts/Libdw.h
15

Ahh, I missed this comment in my first pass. I'll add a comment.

rts/Libdw.c
36

Fair point.

53

Fixed.

70

That's a good point. free-type functions will typically behave as no-ops in the case of NULL arguments.

74

There is no global state; instead the state is held within LibDwSession. You create a session with libdw_init. This does not reify the stack; this is sonly done in libdw_get_backtrace. The Backtrace value in LibDwSession is merely a convenience for implementation. Otherwise I would need to allocate a new temporary structure in libdw_get_backtrace to bundle together the Dwfl and Backtrace being built.

Calling libdw_init will merely create a second independent session.

112

That's a good point.

113

Very good catch.

228

This is a special case I added to avoid entering an infinite loop after trying to unwind back into the C stack. I've undone this locally as it shouldn't be necessary after D1223 lands.

333

I think this function is going to be dropped anyways. I managed to get further with DWARF unwinding than I expected.

rts/Libdw.h
26

I think the current setup should work pretty much the way you want.

simonmar accepted this revision.Oct 12 2015, 10:03 AM
simonmar edited edge metadata.

Let's get this in!

includes/rts/Libdw.h
53

Is __attribute__((packed)) really necessary here? Everything looks to be word-sized.

82

What is the rationale for making this header public, when the only public API is backtrace_free? I'm guessing there should be more functions declared here.

rts/Libdw.c
123

stgFree, since we're using stgCalloc

austin requested changes to this revision.Oct 16 2015, 2:56 PM
austin edited edge metadata.

I was looking through this and I remembered something: libdw is GPL. What will the situation for binary distributions be here? Bumping off to dlopen(3) is really nebulous still; if you dlopen against a GPL'd library, and give the user control, which qualifies as linking, I don't even know who committed the license violation: us, or the user who enabled it by choice?

To be clear, I'm fine with this going in. We can test it and regress against it at least. But I don't think it can be enabled by default in any way, and will need an explicit opt-in when you build the source. And we can't build the binary distributions this way, nor can any package manager without a licensing shitshow...

This revision now requires changes to proceed.Oct 16 2015, 2:56 PM
bgamari marked 2 inline comments as done.Oct 16 2015, 3:15 PM
In D1196#38057, @austin wrote:

I was looking through this and I remembered something: libdw is GPL. What will the situation for binary distributions be here? Bumping off to dlopen(3) is really nebulous still; if you dlopen against a GPL'd library, and give the user control, which qualifies as linking, I don't even know who committed the license violation: us, or the user who enabled it by choice?

As far as I know elfutils is LGPL. To quote NEWS (as of the 0.154 release),

The license is now GPLv2/LGPLv3+ for the libraries and GPLv3+ for stand-alone
programs. There is now also a formal CONTRIBUTING document describing how to
submit patches.

includes/rts/Libdw.h
53

Great point.

austin accepted this revision.Oct 16 2015, 3:18 PM
austin edited edge metadata.

Right, I was looking at an old copy of the source code. OK then, this otherwise looks good to me too.

This revision is now accepted and ready to land.Oct 16 2015, 3:18 PM
bgamari updated this revision to Diff 4537.Oct 17 2015, 9:33 AM
bgamari edited edge metadata.

Update

This revision was automatically updated to reflect the committed changes.

Wohoo! Great job @bgamari!!!

I've pushed 52c6e3d608ee3d010337d4405df86c2620d24887 which renames the symbols introduced in this patch to conform with the RTS's CamelCase style.

I encountered following errors when building rts/Libdw.c in i686 environment:

/usr/bin/make --no-print-directory -f ghc.mk phase=final all
"inplace/bin/ghc-stage1" -optc-U__i686 -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/dist/build -optc-DCOMPILING_RTS -optc-fno-strict-aliasing -optc-fno-common -optc-DUSE_LIBDW -optc-Irts/dist/build/autogen -optc-Werror=unused-but-set-variable -optc-Wno-error=inline -optc-O2 -optc-fomit-frame-pointer -optc-g -optc-DRtsWay=\"rts_v\" -static  -H32m -O -Wall -Iincludes -Iincludes/dist -Iincludes/dist-derivedconstants/header -Iincludes/dist-ghcconstants/header -Irts -Irts/dist/build -DCOMPILING_RTS -this-package-key rts -dcmm-lint      -i -irts -irts/dist/build -irts/dist/build/autogen -Irts/dist/build -Irts/dist/build/autogen           -O2    -c rts/Libdw.c -o rts/dist/build/Libdw.o
rts/Libdw.c: In function ‘libdwLookupLocation’:

rts/Libdw.c:127:55: error:
     warning: cast from pointer to integer of different size [-Wpointer-to-int-cast]
         Dwfl_Module *mod = dwfl_addrmodule(session->dwfl, (Dwarf_Addr) pc);
                                                           ^

rts/Libdw.c:134:49: error:
     warning: cast from pointer to integer of different size [-Wpointer-to-int-cast]
         frame->function = dwfl_module_addrname(mod, (Dwarf_Addr) pc);
                                                     ^

rts/Libdw.c:137:47: error:
     warning: cast from pointer to integer of different size [-Wpointer-to-int-cast]
         Dwfl_Line *line = dwfl_module_getsrc(mod, (Dwarf_Addr) pc);
                                                   ^
rts/Libdw.c: In function ‘getBacktraceFrameCb’:

rts/Libdw.c:230:40: error:
     warning: cast to pointer from integer of different size [-Wint-to-pointer-cast]
             backtracePush(session->cur_bt, (StgPtr) pc);
                                            ^
rts/Libdw.c: In function ‘memory_read’:

rts/Libdw.c:267:16: error:
     warning: cast to pointer from integer of different size [-Wint-to-pointer-cast]
         *result = *(Dwarf_Word *) addr;
                    ^
rts/Libdw.c: Assembler messages:

rts/Libdw.c:314:0: error:  Error: bad register name `%eip)'
`gcc' failed in phase `Assembler'. (Exit code: 1)
rts/ghc.mk:254: recipe for target 'rts/dist/build/Libdw.o' failed
make[1]: *** [rts/dist/build/Libdw.o] Error 1
Makefile:121: recipe for target 'all' failed
make: *** [all] Error 2

Here is some information about my building environment:

watashi % git rev-list HEAD --max-count=1                                                                              git master ~/gao/ghc
46a03fbec6a02761db079d1746532565f34c340f
watashi % gcc --version                                                                                                git master ~/gao/ghc
gcc (GCC) 5.2.0
Copyright (C) 2015 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

watashi % ghc --version                                                                                                git master ~/gao/ghc
The Glorious Glasgow Haskell Compilation System, version 7.10.2
watashi % uname -a                                                                                                     git master ~/gao/ghc
Linux watashi-laptop 4.1.6-1-ARCH #1 SMP PREEMPT Mon Aug 17 09:07:24 CEST 2015 i686 GNU/Linux
watashi % cat /proc/cpuinfo                                                                                            git master ~/gao/ghc
processor	: 0
vendor_id	: GenuineIntel
cpu family	: 6
model		: 23
model name	: Intel(R) Core(TM)2 Duo CPU     P8400  @ 2.26GHz
stepping	: 10
microcode	: 0xa0c
cpu MHz		: 800.000
cache size	: 3072 KB
physical id	: 0
siblings	: 2
core id		: 0
cpu cores	: 2
apicid		: 0
initial apicid	: 0
fdiv_bug	: no
f00f_bug	: no
coma_bug	: no
fpu		: yes
fpu_exception	: yes
cpuid level	: 13
wp		: yes
flags		: fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe nx lm constant_tsc arch_perfmon pebs bts aperfmperf pni dtes64 monitor ds_cpl vmx smx est tm2 ssse3 cx16 xtpr pdcm sse4_1 xsave lahf_lm ida dtherm tpr_shadow vnmi flexpriority
bugs		:
bogomips	: 4524.76
clflush size	: 64
cache_alignment	: 64
address sizes	: 36 bits physical, 48 bits virtual
power management:

I encountered following errors when building rts/Libdw.c in i686 environment:

Thanks for the report! I'll look into it tomorrow.

I encountered following errors when building rts/Libdw.c in i686 environment:

Thanks for the report! I'll look into it tomorrow.

By the way, I this was resolved with rGHCdbad0d5d8dc1fa616065a49f5175adafb4f36080.

To see the bigger picture of this changeset. Check out this wiki page: https://ghc.haskell.org/trac/ghc/wiki/DWARF/80Status