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
Contributor

@cherrymui cherrymui commented Nov 25, 2020

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

@gopherbot gopherbot commented Nov 30, 2020

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

Loading

@aclements
Copy link
Member

@aclements aclements commented Dec 1, 2020

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

Loading

@gopherbot gopherbot closed this in 07cba70 Dec 3, 2020
@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
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
3 participants