Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unexpected Relocation Error for Dynamic Symbol __CFConstantStringClassReference When Running Unit Tests #3000

Open
juri-t opened this issue Nov 29, 2024 · 1 comment

Comments

@juri-t
Copy link

juri-t commented Nov 29, 2024

After updating dd-trace-go, I encountered an issue where running unit tests outputs the following error log:

github.com/shoenig/go-m1cpu(__DATA/__cfstring): unexpected reloc for dynamic symbol __CFConstantStringClassReference

This appears to have been introduced in this PR, where the library github.com/shoenig/go-m1cpu was added as a dependency.

While the tests continue to work as expected, this log is very noisy and clutters the output, making debugging other issues difficult.

Could you provide guidance on how to suppress or resolve this error log?

Any help would be greatly appreciated!

@github-actions github-actions bot added the needs-triage New issues that have not yet been triaged label Nov 29, 2024
@darccio darccio removed the needs-triage New issues that have not yet been triaged label Nov 29, 2024
@darccio
Copy link
Member

darccio commented Nov 29, 2024

Hi @juri-t, thanks for reaching to us. It's possible that you are forcing internal linking mode, which it isn't well supported when compiling with CGO enabled.

We were able to reproduce it. Assuming a simple program like this one:

package main

import (
	"fmt"
	"net/http"

	"gopkg.in/DataDog/dd-trace-go.v1/ddtrace/tracer"
)

func main() {
	tracer.Start(tracer.WithServiceName("hello-world"))
	defer tracer.Stop()

	http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
		span, _ := tracer.StartSpanFromContext(r.Context(), "greeting")
		defer span.Finish()

		fmt.Fprintf(w, "Hello world!")
	})
	http.ListenAndServe(":3000", nil)
}

Compiled as is, it doesn't complain. If we set GOFLAGS='-ldflags=-linkmode=internal' we get the warnings you see:

❯ export GOFLAGS='-ldflags=-linkmode=internal'
❯ go clean && go build .
# go-http-puppy
github.com/shoenig/go-m1cpu(__DATA/__cfstring): unexpected reloc for dynamic symbol __CFConstantStringClassReference
github.com/shoenig/go-m1cpu(__DATA/__cfstring): unexpected reloc for dynamic symbol __CFConstantStringClassReference
github.com/shirou/gopsutil/v3/cpu._Cvar_mach_task_self_: relocation target mach_task_self_ not defined

If we set CGO_ENABLED=0, the warnings go away:

❯ export CGO_ENABLED=0
❯ go clean && go build .
❯ echo $?
0

Make sure you don't use internal linking mode unless strictly required. In that case, if you can work with CGO_ENABLED=0, that will get rid of the warnings.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants