Add loadNativeObj and unloadNativeObj

Summary:

(This change is originally written by niteria)

This adds two functions:
* `loadNativeObj`
* `unloadNativeObj`
and implements them for Linux.

They are useful if you want to load a shared object with Haskell code
using the system linker and have GHC call dlclose() after the
code is no longer referenced from the heap.

Using the system linker allows you to load the shared object
above outside the lowmem region. It also loads the DWARF sections
in a way that `perf` understands.

`dl_iterate_phdr` is what makes this implementation Linux specific.

NOTE: this should be replaceable by whatever D4263 becomes

Test Plan: manual testing

Reviewers: simonmar, Phyx, bgamari, erikd

Reviewed By: niteria

Subscribers: rwbarton, thomie, carter

Differential Revision: https://phabricator.haskell.org/D4263
23 jobs for !3671 with upstream-loadNativeObj in 2 minutes and 4 seconds (queued for 2 seconds)
latest detached
Status Job ID Name Coverage
  Lint
failed #390169
lint
ghc-linters

00:00:02

failed #390170
lint
lint-linters

00:00:02

failed #390173
lint allowed to fail
lint-submods-mr

00:00:00

failed #390171
lint
lint-testsuite

00:00:00

failed #390172
lint
typecheck-testsuite

00:00:00

 
  Quick Build
skipped #390174
x86_64-linux
hadrian-ghc-in-ghci
 
  Build
skipped #390175
x86_64-linux
validate-x86_64-linux-deb9-hadrian
 
  Full Build
skipped #390178
aarch64-linux allowed to fail
validate-aarch64-linux-deb9
skipped #390179
armv7-linux allowed to fail
validate-armv7-linux-deb9
skipped #390180
x86_64-linux
validate-i386-linux-deb9
skipped #390187
new-x86_64-windows test allowed to fail
validate-i386-windows
skipped #390177
x86_64-darwin
validate-x86_64-darwin
skipped #390181
x86_64-linux
validate-x86_64-linux-deb9-debug
skipped #390183
x86_64-linux
validate-x86_64-linux-deb9-dwarf
skipped #390182
x86_64-linux
validate-x86_64-linux-deb9-integer-simple
skipped #390176
x86_64-linux
validate-x86_64-linux-deb9-unreg-hadrian
skipped #390184
x86_64-linux
validate-x86_64-linux-fedora27
skipped #390186
new-x86_64-windows test allowed to fail
validate-x86_64-windows
skipped #390185
new-x86_64-windows test allowed to fail
validate-x86_64-windows-hadrian
 
  Cleanup
passed #390188
x86_64-darwin
cleanup-darwin

00:02:00

 
  Packaging
skipped #390189
x86_64-linux allowed to fail
doc-tarball
 
  Testing
skipped #390190
x86_64-linux allowed to fail manual
hackage
skipped #390191
x86_64-linux
perf-nofib
 
Name Stage Failure
failed
ghc-linters Lint
Running with gitlab-runner 12.7.0 (v12.7.0)
on ghc-ci-1-lint c400cf82
Using Docker executor with image registry.gitlab.haskell.org/ghc/ci-images/linters:408eff66aef6ca2b44446c694c5a56d6ca0460cc ...
Authenticating with credentials from job payload (GitLab Registry)
Pulling docker image registry.gitlab.haskell.org/ghc/ci-images/linters:408eff66aef6ca2b44446c694c5a56d6ca0460cc ...
ERROR: Job failed: Error response from daemon: manifest for registry.gitlab.haskell.org/ghc/ci-images/linters:408eff66aef6ca2b44446c694c5a56d6ca0460cc not found: manifest unknown: manifest unknown (executor_docker.go:188:0s)
failed
lint-linters Lint
Running with gitlab-runner 12.7.0 (v12.7.0)
on ghc-ci-1-lint c400cf82
Using Docker executor with image registry.gitlab.haskell.org/ghc/ci-images/linters:408eff66aef6ca2b44446c694c5a56d6ca0460cc ...
Authenticating with credentials from job payload (GitLab Registry)
Pulling docker image registry.gitlab.haskell.org/ghc/ci-images/linters:408eff66aef6ca2b44446c694c5a56d6ca0460cc ...
ERROR: Job failed: Error response from daemon: manifest for registry.gitlab.haskell.org/ghc/ci-images/linters:408eff66aef6ca2b44446c694c5a56d6ca0460cc not found: manifest unknown: manifest unknown (executor_docker.go:188:0s)
failed
typecheck-testsuite Lint
Running with gitlab-runner 12.7.0 (v12.7.0)
on ghc-ci-1-lint c400cf82
Using Docker executor with image registry.gitlab.haskell.org/ghc/ci-images/linters:408eff66aef6ca2b44446c694c5a56d6ca0460cc ...
Authenticating with credentials from job payload (GitLab Registry)
Pulling docker image registry.gitlab.haskell.org/ghc/ci-images/linters:408eff66aef6ca2b44446c694c5a56d6ca0460cc ...
ERROR: Job failed: Error response from daemon: manifest for registry.gitlab.haskell.org/ghc/ci-images/linters:408eff66aef6ca2b44446c694c5a56d6ca0460cc not found: manifest unknown: manifest unknown (executor_docker.go:188:0s)
failed
lint-testsuite Lint
Running with gitlab-runner 12.7.0 (v12.7.0)
on ghc-ci-1-lint c400cf82
Using Docker executor with image registry.gitlab.haskell.org/ghc/ci-images/x86_64-linux-deb9:408eff66aef6ca2b44446c694c5a56d6ca0460cc ...
Authenticating with credentials from job payload (GitLab Registry)
Pulling docker image registry.gitlab.haskell.org/ghc/ci-images/x86_64-linux-deb9:408eff66aef6ca2b44446c694c5a56d6ca0460cc ...
ERROR: Job failed: Error response from daemon: manifest for registry.gitlab.haskell.org/ghc/ci-images/x86_64-linux-deb9:408eff66aef6ca2b44446c694c5a56d6ca0460cc not found: manifest unknown: manifest unknown (executor_docker.go:188:0s)
failed
lint-submods-mr Lint
Running with gitlab-runner 12.7.0 (v12.7.0)
on ghc-ci-1-lint c400cf82
Using Docker executor with image registry.gitlab.haskell.org/ghc/ci-images/linters:408eff66aef6ca2b44446c694c5a56d6ca0460cc ...
Authenticating with credentials from job payload (GitLab Registry)
Pulling docker image registry.gitlab.haskell.org/ghc/ci-images/linters:408eff66aef6ca2b44446c694c5a56d6ca0460cc ...
ERROR: Job failed: Error response from daemon: manifest for registry.gitlab.haskell.org/ghc/ci-images/linters:408eff66aef6ca2b44446c694c5a56d6ca0460cc not found: manifest unknown: manifest unknown (executor_docker.go:188:0s)