Skip to content

internal/fuzz: odr-violation error #66966

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

Closed
n-bes opened this issue Apr 22, 2024 · 5 comments
Closed

internal/fuzz: odr-violation error #66966

n-bes opened this issue Apr 22, 2024 · 5 comments
Labels
arch-amd64 fuzz Issues related to native fuzzing support NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone

Comments

@n-bes
Copy link

n-bes commented Apr 22, 2024

Go version

go1.22.2 linux/amd64

Output of go env in your module/workspace:

GO111MODULE=''
GOARCH='amd64'
GOBIN=''
GOCACHE='/root/.cache/go-build'
GOENV='/root/.config/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFLAGS=''
GOHOSTARCH='amd64'
GOHOSTOS='linux'
GOINSECURE=''
GOMODCACHE='/go/pkg/mod'
GONOPROXY=''
GONOSUMDB=''
GOOS='linux'
GOPATH='/go'
GOPRIVATE=''
GOPROXY='https://proxy.golang.org,direct'
GOROOT='/usr/local/go'
GOSUMDB='sum.golang.org'
GOTMPDIR=''
GOTOOLCHAIN='local'
GOTOOLDIR='/usr/local/go/pkg/tool/linux_amd64'
GOVCS=''
GOVERSION='go1.22.2'
GCCGO='gccgo'
GOAMD64='v1'
AR='ar'
CC='clang'
CXX='g++'
CGO_ENABLED='1'
GOMOD='/src/go.mod'
GOWORK=''
CGO_CFLAGS='-O2 -g'
CGO_CPPFLAGS=''
CGO_CXXFLAGS='-O2 -g'
CGO_FFLAGS='-O2 -g'
CGO_LDFLAGS='-O2 -g'
PKG_CONFIG='pkg-config'
GOGCCFLAGS='-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -Wl,--no-gc-sections -fmessage-length=0 -ffile-prefix-map=/tmp/go-build3964025102=/tmp/go-build -gno-record-gcc-switches'

What did you do?

I ran this code on MacBook M3-chip with Docker Desktop and used latest official docker images (debian / alpine).

func FuzzParser(f *testing.F) {
	f.Fuzz(func(t *testing.T, data string) {
	})
}

What did you see happen?

# go test -fuzz=Fuzz -asan .

==40621==The following global variable is not properly aligned.
==40621==This may happen if another global with the same name
==40621==resides in another non-instrumented module.
==40621==Or the global comes from a C file built w/o -fno-common.
==40621==In either case this is likely an ODR violation bug,
==40621==but AddressSanitizer can not provide more details.
=================================================================
==40621==ERROR: AddressSanitizer: odr-violation (0x000005fecce3):
  [1] size=0 'internal/fuzz._ecounters' /usr/local/go/src/internal/fuzz/coverage.go:106:13
  [2] size=0 'internal/fuzz._ecounters' /usr/local/go/src/internal/fuzz/coverage.go:106:13
These globals were registered at these points:
  [1]:
    #0 0x2aaaab3211b8 in __asan_register_globals ../../../../src/libsanitizer/asan/asan_globals.cpp:341
    #1 0x183858c  (/tmp/go-build3032263961/b001/scan.test+0x183858c)

  [2]:
    #0 0x2aaaab3211b8 in __asan_register_globals ../../../../src/libsanitizer/asan/asan_globals.cpp:341
    #1 0x183858c  (/tmp/go-build3032263961/b001/scan.test+0x183858c)

==40621==HINT: if you don't care about these errors you may set ASAN_OPTIONS=detect_odr_violation=0
SUMMARY: AddressSanitizer: odr-violation: global 'internal/fuzz._ecounters' at /usr/local/go/src/internal/fuzz/coverage.go:106:13
==40621==ABORTING
# go test -asan -fuzz=Fuzz .

==20374==The following global variable is not properly aligned.
==20374==This may happen if another global with the same name
==20374==resides in another non-instrumented module.
==20374==Or the global comes from a C file built w/o -fno-common.
==20374==In either case this is likely an ODR violation bug,
==20374==but AddressSanitizer can not provide more details.
=================================================================
==20374==ERROR: AddressSanitizer: odr-violation (0x000006b0c2c3):
  [1] size=0 'internal/fuzz._ecounters' /usr/local/go/src/internal/fuzz/coverage.go:106:13
  [2] size=0 'internal/fuzz._ecounters' /usr/local/go/src/internal/fuzz/coverage.go:106:13
These globals were registered at these points:
  [1]:
    #0 0x17ef29b  (/tmp/go-build585142908/b001/scan.test+0x17ef29b) (BuildId: 367c8411fdfbdc6ab6efe02464d6626ff04f1a3c)
    #1 0x191956c  (/tmp/go-build585142908/b001/scan.test+0x191956c) (BuildId: 367c8411fdfbdc6ab6efe02464d6626ff04f1a3c)

  [2]:
    #0 0x17ef29b  (/tmp/go-build585142908/b001/scan.test+0x17ef29b) (BuildId: 367c8411fdfbdc6ab6efe02464d6626ff04f1a3c)
    #1 0x191956c  (/tmp/go-build585142908/b001/scan.test+0x191956c) (BuildId: 367c8411fdfbdc6ab6efe02464d6626ff04f1a3c)

==20374==HINT: if you don't care about these errors you may set ASAN_OPTIONS=detect_odr_violation=0
SUMMARY: AddressSanitizer: odr-violation: global 'internal/fuzz._ecounters' at /usr/local/go/src/internal/fuzz/coverage.go:106:13
==20374==ABORTING
exit status 1

What did you expect to see?

I've tried to set ASAN_OPTIONS=detect_odr_violation=0 without success:

  • before build
  • after build
  • testing.F.Setenv
@mauri870 mauri870 added NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. arch-arm64 arch-amd64 and removed arch-arm64 labels Apr 22, 2024
@n-bes
Copy link
Author

n-bes commented Apr 23, 2024

MRE:
go.mod:

module hello

go 1.22.2

main_test.go:

package hello

import (
	"testing"
	"unicode/utf8"
)

func Reverse(s string) string {
	b := []byte(s)
	for i, j := 0, len(b)-1; i < len(b)/2; i, j = i+1, j-1 {
		b[i], b[j] = b[j], b[i]
	}
	return string(b)
}

func FuzzReverse(f *testing.F) {
	testcases := []string{"Hello, world", " ", "!12345"}
	for _, tc := range testcases {
		f.Add(tc) // Use f.Add to provide a seed corpus
	}
	f.Fuzz(func(t *testing.T, orig string) {
		rev := Reverse(orig)
		doubleRev := Reverse(rev)
		if orig != doubleRev {
			t.Errorf("Before: %q, after: %q", orig, doubleRev)
		}
		if utf8.ValidString(orig) && !utf8.ValidString(rev) {
			t.Errorf("Reverse produced invalid UTF-8 string %q", rev)
		}
	})
}
docker run --rm -it -v $PWD:/src golang

@n-bes
Copy link
Author

n-bes commented Oct 24, 2024

Still crashes

$ go version
go version go1.23.2 linux/amd64
$ cat /etc/os-release
PRETTY_NAME="Ubuntu 22.04.3 LTS"
package main

import (
        "path"
        "testing"
)

func FuzzPathClean(f *testing.F) {
        f.Fuzz(func(t *testing.T, data string) {
                res := path.Clean(data)

                t.Log("in:", data)
                t.Log("out:", res)
        })
}
$ go test -asan -fuzz=FuzzPathClean ./main_test.go

==199089==The following global variable is not properly aligned.
==199089==This may happen if another global with the same name
==199089==resides in another non-instrumented module.
==199089==Or the global comes from a C file built w/o -fno-common.
==199089==In either case this is likely an ODR violation bug,
==199089==but AddressSanitizer can not provide more details.
=================================================================
==199089==ERROR: AddressSanitizer: odr-violation (0x00000097588d):
  [1] size=0 'internal/fuzz._ecounters' /usr/local/go/src/internal/fuzz/coverage.go:104:13
  [2] size=0 'internal/fuzz._ecounters' /usr/local/go/src/internal/fuzz/coverage.go:104:13
These globals were registered at these points:
  [1]:
    #0 0x7f53f7a4b928 in __asan_register_globals ../../../../src/libsanitizer/asan/asan_globals.cpp:341
    #1 0x477f4c  (/tmp/go-build1051884221/b001/main.test+0x477f4c)

  [2]:
    #0 0x7f53f7a4b928 in __asan_register_globals ../../../../src/libsanitizer/asan/asan_globals.cpp:341
    #1 0x477f4c  (/tmp/go-build1051884221/b001/main.test+0x477f4c)

==199089==HINT: if you don't care about these errors you may set ASAN_OPTIONS=detect_odr_violation=0
SUMMARY: AddressSanitizer: odr-violation: global 'internal/fuzz._ecounters' at /usr/local/go/src/internal/fuzz/coverage.go:104:13
==199089==ABORTING
exit status 1
FAIL    command-line-arguments  0.014s

@randall77
Copy link
Contributor

Looks like fuzz and asan are not playing nicely together. Asan is unhappy with us writing the counter array which tracks coverage.

fuzz and race play nicely together though. Not sure what the difference is.

Setting ASAN_OPTIONS=detect_odr_violation=0 doesn't seem to make the error go away, not sure why it is suggested.

This would be nice if it worked, but I'm not sure it ever did. Marking for 1.24 is case someone knows an easy fix for it.

@randall77 randall77 added this to the Go1.24 milestone Oct 24, 2024
@randall77 randall77 added the fuzz Issues related to native fuzzing support label Oct 24, 2024
@randall77
Copy link
Contributor

@kyakdan

@gopherbot
Copy link
Contributor

Change https://go.dev/cl/622477 mentions this issue: cmd/link: for asan align coverage counters to 8 bytes

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
arch-amd64 fuzz Issues related to native fuzzing support NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Projects
None yet
Development

No branches or pull requests

4 participants