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

cmd/compile, cmd/cgo: cgo callback fails with MSAN when passing aggregate args with paddings #42820

Closed
cherrymui opened this issue Nov 25, 2020 · 2 comments

Comments

@cherrymui
Copy link
Member

What version of Go are you using (go version)?

tip (e8de596)

Does this issue reproduce with the latest release?

No. This starts to happen since cgo callback changes (CL 258938).

What operating system and processor architecture are you using (go env)?

linux/amd64

What did you do?

Build the following program using MSAN, where it calls from C to Go passing a C struct with padding.

x.go

package main

// Test passing C struct to exported Go function.

/*
#include <stdint.h>

typedef struct { uintptr_t x, y; char b; } T;

void CF(int x);
*/
import "C"

//export F
func F(t C.T) { println(t.x, t.y, t.b) }

func main() {
	C.CF(C.int(0))
}

x.c

#include <stdint.h>
#include <stdlib.h>

typedef struct { uintptr_t x, y; char b; } T;

extern void F(T);

void CF(int x) {
	T *t = malloc(sizeof(T));
	t->x = x;
	t->y = x;
	t->b = (char)x;
	F(*t);
}

What did you expect to see?

Program runs okay, prints 0 0 0.

What did you see instead?

$ CC=clang go build -msan .
$ ./x
Uninitialized bytes in __msan_check_mem_is_initialized at offset 17 inside [0x7fff51f33f00, 24)
==893435==WARNING: MemorySanitizer: use-of-uninitialized-value
    #0 0x4f5368 in msancall /usr/local/google/home/cherryyz/src/go-tip/src/runtime/msan_amd64.s:78

SUMMARY: MemorySanitizer: use-of-uninitialized-value /usr/local/google/home/cherryyz/src/go-tip/src/runtime/msan_amd64.s:78 in msancall
Exiting
@cherrymui cherrymui added this to the Go1.16 milestone Nov 25, 2020
@cherrymui cherrymui self-assigned this Nov 25, 2020
@gopherbot
Copy link

Change https://golang.org/cl/270859 mentions this issue: cmd/compile, runtime: use __msan_memmove for moving data

@aclements
Copy link
Member

Marking as a release blocker because this is a regression from 1.15.

@golang golang locked and limited conversation to collaborators Dec 3, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants