ghc-stage2 fails with ld: fatal: library -lrt: not found on topHandler02(profthreaded) test
On SmartOS ghc-stage2 crashes with an error when trying to run the topHandler02(dyn) test:
ld: fatal: library -lrt: not found
Tracing this with the following DTrace script to stop ghc-stage2 at the point of launching ld:
**\~/exit_on_ld.d**:
{{{
\#!/usr/sbin/dtrace -s
\#pragma D option destructive
syscall::exec\*:entry
/copyinstr(arg0) == "/usr/bin/ld"/
{
trace(pid);
stop();
system("pargs %d", pid);
> exit(0);
}
}}}
This let me observe the command-line arguments to ld:
In ssh session A I started DTrace:
```
chmod +x ~/exit_on_ld.d
~/exit_on_ld.d
```
In a ssh session B I started the topHandler02(dyn) test manually with no output redirection:
```
cd ~/ghc/libraries/base/tests && '/root/ghc/inplace/bin/ghc-stage2' -fforce-recomp -dcore-lint -dcmm-lint -dno-debug-output -no-user-package-db -rtsopts -fno-ghci-history -o topHandler02 topHandler02.hs -O -prof -static -auto-all -threaded
```
In ssh session A I observed the ld call (ghc-stage2 is now frozen by stop):
```
CPU ID FUNCTION:NAME
3 5167 exece:entry 9186691866: /opt/local/gcc47/libexec/gcc/x86_64-sun-solaris2.11/4.7.3/collect2 -R/opt/local
argv[0]: /opt/local/gcc47/libexec/gcc/x86_64-sun-solaris2.11/4.7.3/collect2
argv[1]: -R/opt/local/lib/
argv[2]: -Y
argv[3]: P,/lib/amd64:/usr/lib/amd64:/opt/local/lib/
argv[4]: -Qy
argv[5]: -o
argv[6]: topHandler02.o
argv[7]: -L/opt/local/gcc47/lib/gcc/x86_64-sun-solaris2.11/4.7.3
argv[8]: -L/opt/local/gcc47/lib/gcc/x86_64-sun-solaris2.11/4.7.3/../../../../x86_64-sun-solaris2.11/lib/amd64
argv[9]: -L/opt/local/gcc47/lib/gcc/x86_64-sun-solaris2.11/4.7.3/../../../amd64
argv[10]: -L/lib/amd64
argv[11]: -L/usr/lib/amd64
argv[12]: -L/opt/local/gcc47/lib/gcc/x86_64-sun-solaris2.11/4.7.3/../../../../x86_64-sun-solaris2.11/lib
argv[13]: -L/opt/local/gcc47/lib/gcc/x86_64-sun-solaris2.11/4.7.3/../../..
argv[14]: -R/opt/local/gcc47/x86_64-sun-solaris2.11/lib/amd64
argv[15]: -R/opt/local/gcc47/lib/amd64
argv[16]: -lrt
argv[17]: -r
argv[18]: /tmp/ghc91814_0/ghc91814_6.o
argv[19]: /tmp/ghc91814_0/ghc91814_5.o
```
I was then able to run them in isolation with GHC's temp files present on disk:
```
# /opt/local/gcc47/libexec/gcc/x86_64-sun-solaris2.11/4.7.3/collect2 -R/opt/local/lib/ -Y P,/lib/amd64:/usr/lib/amd64:/opt/local/lib/ -Qy -o topHandler02.o -L/opt/local/gcc47/lib/gcc/x86_64-sun-solaris2.11/4.7.3 -L/opt/local/gcc47/lib/gcc/x86_64-sun-solaris2.11/4.7.3/../../../../x86_64-sun-solaris2.11/lib/amd64 -L/opt/local/gcc47/lib/gcc/x86_64-sun-solaris2.11/4.7.3/../../../amd64 -L/lib/amd64 -L/usr/lib/amd64 -L/opt/local/gcc47/lib/gcc/x86_64-sun-solaris2.11/4.7.3/../../../../x86_64-sun-solaris2.11/lib -L/opt/local/gcc47/lib/gcc/x86_64-sun-solaris2.11/4.7.3/../../.. -R/opt/local/gcc47/x86_64-sun-solaris2.11/lib/amd64 -R/opt/local/gcc47/lib/amd64 -lrt -r /tmp/ghc91814_0/ghc91814_6.o /tmp/ghc91814_0/ghc91814_5.o
ld: fatal: library -lrt: not found
ld: fatal: file processing errors. No output written to topHandler02.o
collect2: error: ld returned 1 exit status
```
If I omit **-lrt** from the arguments it succeeds (on Illumos-based systems, including SmartOS, librt is a passthrough to libc):
```
# /opt/local/gcc47/libexec/gcc/x86_64-sun-solaris2.11/4.7.3/collect2 -R/opt/local/lib/ -Y P,/lib/amd64:/usr/lib/amd64:/opt/local/lib/ -Qy -o topHandler02.o -L/opt/local/gcc47/lib/gcc/x86_64-sun-solaris2.11/4.7.3 -L/opt/local/gcc47/lib/gcc/x86_64-sun-solaris2.11/4.7.3/../../../../x86_64-sun-solaris2.11/lib/amd64 -L/opt/local/gcc47/lib/gcc/x86_64-sun-solaris2.11/4.7.3/../../../amd64 -L/lib/amd64 -L/usr/lib/amd64 -L/opt/local/gcc47/lib/gcc/x86_64-sun-solaris2.11/4.7.3/../../../../x86_64-sun-solaris2.11/lib -L/opt/local/gcc47/lib/gcc/x86_64-sun-solaris2.11/4.7.3/../../.. -R/opt/local/gcc47/x86_64-sun-solaris2.11/lib/amd64 -R/opt/local/gcc47/lib/amd64 -r /tmp/ghc91814_0/ghc91814_6.o /tmp/ghc91814_0/ghc91814_5.o
# echo $?
0
```
No errors are emitted and the exit code is 0 (good).
I would like to conditionally omit **-lrt** from the ld arguments.
Where do I need to look for where ghc-stage2 populates the arguments to ld?
<details><summary>Trac metadata</summary>
| Trac field | Value |
| ---------------------- | ------------ |
| Version | 7.8.1-rc2 |
| Type | Bug |
| TypeOfFailure | OtherFailure |
| Priority | normal |
| Resolution | Unresolved |
| Component | Compiler |
| Test case | |
| Differential revisions | |
| BlockedBy | |
| Related | |
| Blocking | |
| CC | |
| Operating system | |
| Architecture | |
</details>
<!-- {"blocked_by":[],"summary":"ghc-stage2 fails with ld: fatal: library -lrt: not found on topHandler02(dyn) test","status":"New","operating_system":"","component":"Compiler","related":[],"milestone":"","resolution":"Unresolved","owner":{"tag":"Unowned"},"version":"7.8.1-rc2","keywords":[],"differentials":[],"test_case":"","architecture":"","cc":[""],"type":"Bug","description":"On SmartOS ghc-stage2 crashes with an error when trying to run the topHandler02(dyn) test:\r\nld: fatal: library -lrt: not found\r\n\r\nTracing this with the following DTrace script to stop ghc-stage2 at the point of launching ld:\r\n\r\n'''~/exit_on_ld.d''':\r\n{{{\r\n#!/usr/sbin/dtrace -s\r\n\r\n#pragma D option destructive\r\n\r\nsyscall::exec*:entry\r\n/copyinstr(arg0) == \"/usr/bin/ld\"/\r\n{\r\n trace(pid);\r\n stop(); \r\n system(\"pargs %d\", pid);\r\n exit(0);\r\n}\r\n}}}\r\n\r\nThis let me observe the command-line arguments to ld:\r\n\r\nIn ssh session A I started DTrace:\r\n\r\n{{{\r\nchmod +x ~/exit_on_ld.d\r\n~/exit_on_ld.d\r\n}}}\r\n\r\nIn a ssh session B I started the topHandler02(dyn) test manually with no output redirection:\r\n\r\n{{{\r\ncd ~/ghc/libraries/base/tests && '/root/ghc/inplace/bin/ghc-stage2' -fforce-recomp -dcore-lint -dcmm-lint -dno-debug-output -no-user-package-db -rtsopts -fno-ghci-history -o topHandler02 topHandler02.hs -O -prof -static -auto-all -threaded\r\n}}}\r\n\r\nIn ssh session A I observed the ld call (ghc-stage2 is now frozen by stop):\r\n{{{\r\nCPU ID FUNCTION:NAME\r\n 3 5167 exece:entry 9186691866: /opt/local/gcc47/libexec/gcc/x86_64-sun-solaris2.11/4.7.3/collect2 -R/opt/local\r\nargv[0]: /opt/local/gcc47/libexec/gcc/x86_64-sun-solaris2.11/4.7.3/collect2\r\nargv[1]: -R/opt/local/lib/\r\nargv[2]: -Y\r\nargv[3]: P,/lib/amd64:/usr/lib/amd64:/opt/local/lib/\r\nargv[4]: -Qy\r\nargv[5]: -o\r\nargv[6]: topHandler02.o\r\nargv[7]: -L/opt/local/gcc47/lib/gcc/x86_64-sun-solaris2.11/4.7.3\r\nargv[8]: -L/opt/local/gcc47/lib/gcc/x86_64-sun-solaris2.11/4.7.3/../../../../x86_64-sun-solaris2.11/lib/amd64\r\nargv[9]: -L/opt/local/gcc47/lib/gcc/x86_64-sun-solaris2.11/4.7.3/../../../amd64\r\nargv[10]: -L/lib/amd64\r\nargv[11]: -L/usr/lib/amd64\r\nargv[12]: -L/opt/local/gcc47/lib/gcc/x86_64-sun-solaris2.11/4.7.3/../../../../x86_64-sun-solaris2.11/lib\r\nargv[13]: -L/opt/local/gcc47/lib/gcc/x86_64-sun-solaris2.11/4.7.3/../../..\r\nargv[14]: -R/opt/local/gcc47/x86_64-sun-solaris2.11/lib/amd64\r\nargv[15]: -R/opt/local/gcc47/lib/amd64\r\nargv[16]: -lrt\r\nargv[17]: -r\r\nargv[18]: /tmp/ghc91814_0/ghc91814_6.o\r\nargv[19]: /tmp/ghc91814_0/ghc91814_5.o\r\n}}}\r\n\r\nI was then able to run them in isolation with GHC's temp files present on disk:\r\n\r\n{{{\r\n# /opt/local/gcc47/libexec/gcc/x86_64-sun-solaris2.11/4.7.3/collect2 -R/opt/local/lib/ -Y P,/lib/amd64:/usr/lib/amd64:/opt/local/lib/ -Qy -o topHandler02.o -L/opt/local/gcc47/lib/gcc/x86_64-sun-solaris2.11/4.7.3 -L/opt/local/gcc47/lib/gcc/x86_64-sun-solaris2.11/4.7.3/../../../../x86_64-sun-solaris2.11/lib/amd64 -L/opt/local/gcc47/lib/gcc/x86_64-sun-solaris2.11/4.7.3/../../../amd64 -L/lib/amd64 -L/usr/lib/amd64 -L/opt/local/gcc47/lib/gcc/x86_64-sun-solaris2.11/4.7.3/../../../../x86_64-sun-solaris2.11/lib -L/opt/local/gcc47/lib/gcc/x86_64-sun-solaris2.11/4.7.3/../../.. -R/opt/local/gcc47/x86_64-sun-solaris2.11/lib/amd64 -R/opt/local/gcc47/lib/amd64 -lrt -r /tmp/ghc91814_0/ghc91814_6.o /tmp/ghc91814_0/ghc91814_5.o\r\nld: fatal: library -lrt: not found\r\nld: fatal: file processing errors. No output written to topHandler02.o\r\ncollect2: error: ld returned 1 exit status\r\n}}}\r\n\r\nIf I omit '''-lrt''' from the arguments it succeeds (on Illumos-based systems, including SmartOS, librt is a passthrough to libc):\r\n\r\n{{{\r\n# /opt/local/gcc47/libexec/gcc/x86_64-sun-solaris2.11/4.7.3/collect2 -R/opt/local/lib/ -Y P,/lib/amd64:/usr/lib/amd64:/opt/local/lib/ -Qy -o topHandler02.o -L/opt/local/gcc47/lib/gcc/x86_64-sun-solaris2.11/4.7.3 -L/opt/local/gcc47/lib/gcc/x86_64-sun-solaris2.11/4.7.3/../../../../x86_64-sun-solaris2.11/lib/amd64 -L/opt/local/gcc47/lib/gcc/x86_64-sun-solaris2.11/4.7.3/../../../amd64 -L/lib/amd64 -L/usr/lib/amd64 -L/opt/local/gcc47/lib/gcc/x86_64-sun-solaris2.11/4.7.3/../../../../x86_64-sun-solaris2.11/lib -L/opt/local/gcc47/lib/gcc/x86_64-sun-solaris2.11/4.7.3/../../.. -R/opt/local/gcc47/x86_64-sun-solaris2.11/lib/amd64 -R/opt/local/gcc47/lib/amd64 -r /tmp/ghc91814_0/ghc91814_6.o /tmp/ghc91814_0/ghc91814_5.o\r\n# echo $?\r\n0\r\n}}}\r\n\r\nNo errors are emitted and the exit code is 0 (good).\r\n\r\nI would like to conditionally omit '''-lrt''' from the ld arguments.\r\n\r\nWhere do I need to look for where ghc-stage2 populates the arguments to ld?","type_of_failure":"OtherFailure","blocking":[]} -->
issue