Skip to content

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

@cherrymui

Description

@cherrymui

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions