Since 8.4.1 GHC DTrace works are enabled on FreeBSD, 8.4.2 introduced a flag to turn off DTrace support since this interfered with GHC's ability to work as a bootstrap compiler. This patch enables GHC to have DTrace enabled as well as being able to function as a bootstrap compiler.
The objects are excluded from the big object file I generate to make the dtrace probes work (that one gets stored in the archive). The reason why I'm doing this is stated in this thread answered by one of the dtrace developers from over a decade ago https://thr3ads.net/dtrace-discuss/2005/08/384778-Problem-with-probes-defined-in-static-libraries. That poses a problem when trying to use it for linking the RTS for a compiler you are currently bootstrapping because now the hooks show up twice. I basically moved the hooks out of the object file I'm generating and put them into the archive separately. The hooks should have never been in the object file in the first place but I wasn't aware that they exist, let alone that it would cause any issues. The "EXCLUDED" variable gives a way to exclude files from the large object that I generate during linking (maybe one needs to exclude a couple more in the future, for yet unknown reasons). It basically allows for a bit more fine grained control when linking, which is currently only important for dtrace on FreeBSD and possibly other systems (apart from OSX) that have dtrace.
I've packed everything into a commented and extended the comment on the linking step for dtrace. I've added the only source of documentation I've found where the reason why I'm doing is is explained.
The objects are not being excluded from the archive they are being excluded from the RTS.o that I create (see line 278). The object files still end up in the archive. If I put these into the RTS.o (which needs to be created to make dtrace work on FreeBSD) this will result in linking errors when bootstrapping another compiler.
/usr/bin/ld: error: duplicate symbol: StackOverflowHook >>> defined at hschooks.c >>> ghc/stage1/build/hschooks.o:(StackOverflowHook) >>> defined at OSMem.c >>> RTS.o:(.text.StackOverflowHook+0x0) in archive /usr/local/lib/ghc-8.4.2/rts/libHSrts.a
I can put this information into the ticket and reference it in this comment.