bazel-contrib / bazel-contrib/rules_go

Run-time dynamic link error after dlopen

Open
#1,003 0 comments 0 reactions 0 assignees View on GitHub
bug
Dominant language
Go
Stars
1.5k
Forks
760
Avg merge
1d 11h
Merged PRs (30d)
12

Description

```
$ git clone https://github.com/mindprince/gonvml.git
$ cd gonvml/
$ git checkout bazel # The BUILD files in this branch were generated by gazelle.

$ go build cmd/example/example.go
$ ./example #This works.

$ bazel build //cmd/example:example
$ bazel-bin/cmd/example/example #This doesn't work.
bazel-bin/cmd/example/example: symbol lookup error: bazel-bin/cmd/example/example: undefined symbol: nvmlInit_v2
```

`nvmlInit_v2` is a function which is declared, but not defined. The error occurs when the function is called, since the dynamic linker fails to resolve the symbol. The library opened with `dlopen` should provide that symbol, since it's opened with `RTLD_GLOBAL`. This works in the binary produced by go build, but not in the one produced by Bazel.

Note that this only builds on Linux, and it depends on run-time link behavior in ELF.

Contributor guide

Open the contributing guide

Research direction

Reproduce the Linux failure using cmd/example/example.go and the commands in the report, comparing the go build and Bazel outputs. Inspect the generated BUILD files and the dlopen/RTLD_GLOBAL behavior, then determine how Bazel's link setup differs. Done means the Bazel-built example resolves nvmlInit_v2 and runs successfully like the go-built binary.

Written by the indexing model from the issue text.

Assessment

Tech stack
go, linux
Domain
build-system, operating-systems
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
28/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.