aboutsummaryrefslogtreecommitdiff
path: root/src/pkg/runtime
diff options
context:
space:
mode:
authorRuss Cox <rsc@golang.org>2010-12-13 16:22:19 -0500
committerRuss Cox <rsc@golang.org>2010-12-13 16:22:19 -0500
commitdc9a3b2791feb3aade3b8cf00891eddcb5b5ed90 (patch)
tree9e0716513b9c3ea0c15e64464149952daaf5c48d /src/pkg/runtime
parent287e45e2418fa2d22e1cea22b6f9a5b0e1659bb5 (diff)
downloadgo-dc9a3b2791feb3aade3b8cf00891eddcb5b5ed90.tar.xz
gc: align structs according to max alignment of fields
cc: same runtime: test cc alignment (required moving #define of offsetof to runtime.h) fix bug260 Fixes #482. Fixes #609. R=ken2, r CC=golang-dev https://golang.org/cl/3563042
Diffstat (limited to 'src/pkg/runtime')
-rw-r--r--src/pkg/runtime/debug.go11
-rw-r--r--src/pkg/runtime/hashmap.h1
-rw-r--r--src/pkg/runtime/malloc.goc2
-rw-r--r--src/pkg/runtime/runtime.c11
-rw-r--r--src/pkg/runtime/runtime.h1
5 files changed, 24 insertions, 2 deletions
diff --git a/src/pkg/runtime/debug.go b/src/pkg/runtime/debug.go
index 3cc5472f6b..3ce35cc5ba 100644
--- a/src/pkg/runtime/debug.go
+++ b/src/pkg/runtime/debug.go
@@ -4,6 +4,8 @@
package runtime
+import "unsafe"
+
// Breakpoint() executes a breakpoint trap.
func Breakpoint()
@@ -73,6 +75,15 @@ type MemStatsType struct {
}
}
+var sizeof_C_MStats int // filled in by malloc.goc
+
+func init() {
+ if sizeof_C_MStats != unsafe.Sizeof(MemStats) {
+ println(sizeof_C_MStats, unsafe.Sizeof(MemStats))
+ panic("MStats vs MemStatsType size mismatch")
+ }
+}
+
// MemStats holds statistics about the memory system.
// The statistics are only approximate, as they are not interlocked on update.
var MemStats MemStatsType
diff --git a/src/pkg/runtime/hashmap.h b/src/pkg/runtime/hashmap.h
index 40dac6e9bd..0737535b55 100644
--- a/src/pkg/runtime/hashmap.h
+++ b/src/pkg/runtime/hashmap.h
@@ -64,7 +64,6 @@
*/
#define malloc runtime·mal
-#define offsetof(s,m) (uint32)(&(((s*)0)->m))
#define memset(a,b,c) runtime·memclr((byte*)(a), (uint32)(c))
#define memcpy(a,b,c) runtime·mcpy((byte*)(a),(byte*)(b),(uint32)(c))
#define assert(a) if(!(a)) runtime·throw("assert")
diff --git a/src/pkg/runtime/malloc.goc b/src/pkg/runtime/malloc.goc
index 405b05ee96..f5ca9f9183 100644
--- a/src/pkg/runtime/malloc.goc
+++ b/src/pkg/runtime/malloc.goc
@@ -244,6 +244,8 @@ runtime·allocmcache(void)
return c;
}
+int32 runtime·sizeof_C_MStats = sizeof(MStats);
+
void
runtime·mallocinit(void)
{
diff --git a/src/pkg/runtime/runtime.c b/src/pkg/runtime/runtime.c
index f2b6c587e9..a2e31d806f 100644
--- a/src/pkg/runtime/runtime.c
+++ b/src/pkg/runtime/runtime.c
@@ -258,6 +258,13 @@ runtime·check(void)
float64 j;
void* k;
uint16* l;
+ struct x1 {
+ byte x;
+ };
+ struct y1 {
+ struct x1 x1;
+ byte y;
+ };
if(sizeof(a) != 1) runtime·throw("bad a");
if(sizeof(b) != 1) runtime·throw("bad b");
@@ -271,7 +278,9 @@ runtime·check(void)
if(sizeof(j) != 8) runtime·throw("bad j");
if(sizeof(k) != sizeof(uintptr)) runtime·throw("bad k");
if(sizeof(l) != sizeof(uintptr)) runtime·throw("bad l");
-// prints(1"check ok\n");
+ if(sizeof(struct x1) != 1) runtime·throw("bad sizeof x1");
+ if(offsetof(struct y1, y) != 1) runtime·throw("bad offsetof y1.y");
+ if(sizeof(struct y1) != 2) runtime·throw("bad sizeof y1");
uint32 z;
z = 1;
diff --git a/src/pkg/runtime/runtime.h b/src/pkg/runtime/runtime.h
index b0fa3891e6..37c8103f34 100644
--- a/src/pkg/runtime/runtime.h
+++ b/src/pkg/runtime/runtime.h
@@ -306,6 +306,7 @@ enum {
*/
#define nelem(x) (sizeof(x)/sizeof((x)[0]))
#define nil ((void*)0)
+#define offsetof(s,m) (uint32)(&(((s*)0)->m))
/*
* known to compiler