summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRuss Cox <rsc@golang.org>2014-10-06 14:45:36 -0400
committerRuss Cox <rsc@golang.org>2014-10-06 14:45:36 -0400
commitdebf5b7b4fdf985bb292afea65ce6dba6cfaecbb (patch)
treed2ff694c0e7b60e139bda86fe0b00a502457ed7c
parentf85d9767d353a27de22f648b7bc6312b040c0c4e (diff)
parent7ad347e9e6e3bc5723b709768c87e87bd4c7493c (diff)
downloadgo-debf5b7b4fdf985bb292afea65ce6dba6cfaecbb.tar.gz
[dev.garbage] all: merge default into dev.garbage
This picks up the TestDualStackUDPListener fix. LGTM=rlh R=rlh CC=golang-codereviews https://codereview.appspot.com/147660044
-rw-r--r--AUTHORS1
-rw-r--r--CONTRIBUTORS1
-rw-r--r--src/cmd/8l/asm.c18
-rw-r--r--src/net/unicast_posix_test.go3
-rw-r--r--src/runtime/malloc.go37
-rw-r--r--src/runtime/mfinal_test.go13
6 files changed, 51 insertions, 22 deletions
diff --git a/AUTHORS b/AUTHORS
index f22fe4c98..a924ea965 100644
--- a/AUTHORS
+++ b/AUTHORS
@@ -214,6 +214,7 @@ Jeff Hodges <jeff@somethingsimilar.com>
Jeff R. Allen <jra@nella.org>
Jeff Sickel <jas@corpus-callosum.com>
Jeff Wendling <jeff@spacemonkey.com>
+Jens Frederich <jfrederich@gmail.com>
Jeremy Jackins <jeremyjackins@gmail.com>
Jim McGrath <jimmc2@gmail.com>
Jimmy Zelinskie <jimmyzelinskie@gmail.com>
diff --git a/CONTRIBUTORS b/CONTRIBUTORS
index 5dadda0ca..9dce23b2d 100644
--- a/CONTRIBUTORS
+++ b/CONTRIBUTORS
@@ -300,6 +300,7 @@ Jeff Hodges <jeff@somethingsimilar.com>
Jeff R. Allen <jra@nella.org> <jeff.allen@gmail.com>
Jeff Sickel <jas@corpus-callosum.com>
Jeff Wendling <jeff@spacemonkey.com>
+Jens Frederich <jfrederich@gmail.com>
Jeremiah Harmsen <jeremiah@google.com>
Jeremy Jackins <jeremyjackins@gmail.com>
Jeremy Schlatter <jeremy.schlatter@gmail.com>
diff --git a/src/cmd/8l/asm.c b/src/cmd/8l/asm.c
index c135dce70..98c042403 100644
--- a/src/cmd/8l/asm.c
+++ b/src/cmd/8l/asm.c
@@ -117,13 +117,21 @@ adddynrel(LSym *s, Reloc *r)
case 256 + R_386_GOT32:
if(targ->type != SDYNIMPORT) {
// have symbol
- // turn MOVL of GOT entry into LEAL of symbol itself
- if(r->off < 2 || s->p[r->off-2] != 0x8b) {
- diag("unexpected GOT reloc for non-dynamic symbol %s", targ->name);
+ if(r->off >= 2 && s->p[r->off-2] == 0x8b) {
+ // turn MOVL of GOT entry into LEAL of symbol address, relative to GOT.
+ s->p[r->off-2] = 0x8d;
+ r->type = R_GOTOFF;
return;
}
- s->p[r->off-2] = 0x8d;
- r->type = R_GOTOFF;
+ if(r->off >= 2 && s->p[r->off-2] == 0xff && s->p[r->off-1] == 0xb3) {
+ // turn PUSHL of GOT entry into PUSHL of symbol itself.
+ // use unnecessary SS prefix to keep instruction same length.
+ s->p[r->off-2] = 0x36;
+ s->p[r->off-1] = 0x68;
+ r->type = R_ADDR;
+ return;
+ }
+ diag("unexpected GOT reloc for non-dynamic symbol %s", targ->name);
return;
}
addgotsym(ctxt, targ);
diff --git a/src/net/unicast_posix_test.go b/src/net/unicast_posix_test.go
index 452ac9254..ab7ef40a7 100644
--- a/src/net/unicast_posix_test.go
+++ b/src/net/unicast_posix_test.go
@@ -204,6 +204,9 @@ func TestDualStackTCPListener(t *testing.T) {
// to a test listener with various address families, differnet
// listening address and same port.
func TestDualStackUDPListener(t *testing.T) {
+ if testing.Short() {
+ t.Skip("skipping in -short mode, see issue 5001")
+ }
switch runtime.GOOS {
case "plan9":
t.Skipf("skipping test on %q", runtime.GOOS)
diff --git a/src/runtime/malloc.go b/src/runtime/malloc.go
index fc22cc29e..99d14e314 100644
--- a/src/runtime/malloc.go
+++ b/src/runtime/malloc.go
@@ -488,6 +488,10 @@ func GC() {
gogc(2)
}
+// linker-provided
+var noptrdata struct{}
+var enoptrbss struct{}
+
// SetFinalizer sets the finalizer associated with x to f.
// When the garbage collector finds an unreachable block
// with an associated finalizer, it clears the association and runs
@@ -527,6 +531,10 @@ func GC() {
// It is not guaranteed that a finalizer will run if the size of *x is
// zero bytes.
//
+// It is not guaranteed that a finalizer will run for objects allocated
+// in initializers for package-level variables. Such objects may be
+// linker-allocated, not heap-allocated.
+//
// A single goroutine runs all finalizers for a program, sequentially.
// If a finalizer must run for a long time, it should do so by starting
// a new goroutine.
@@ -544,24 +552,25 @@ func SetFinalizer(obj interface{}, finalizer interface{}) {
gothrow("nil elem type!")
}
- // As an implementation detail we do not run finalizers for zero-sized objects,
- // because we use &runtime·zerobase for all such allocations.
- if ot.elem.size == 0 {
- return
- }
-
// find the containing object
_, base, _ := findObject(e.data)
- // The following check is required for cases when a user passes a pointer to composite
- // literal, but compiler makes it a pointer to global. For example:
- // var Foo = &Object{}
- // func main() {
- // runtime.SetFinalizer(Foo, nil)
- // }
- // See issue 7656.
if base == nil {
- return
+ // 0-length objects are okay.
+ if e.data == unsafe.Pointer(&zerobase) {
+ return
+ }
+
+ // Global initializers might be linker-allocated.
+ // var Foo = &Object{}
+ // func main() {
+ // runtime.SetFinalizer(Foo, nil)
+ // }
+ // The segments are, in order: text, rodata, noptrdata, data, bss, noptrbss.
+ if uintptr(unsafe.Pointer(&noptrdata)) <= uintptr(e.data) && uintptr(e.data) < uintptr(unsafe.Pointer(&enoptrbss)) {
+ return
+ }
+ gothrow("runtime.SetFinalizer: pointer not in allocated block")
}
if e.data != base {
diff --git a/src/runtime/mfinal_test.go b/src/runtime/mfinal_test.go
index 6b53888ab..d2cead287 100644
--- a/src/runtime/mfinal_test.go
+++ b/src/runtime/mfinal_test.go
@@ -44,10 +44,17 @@ func TestFinalizerType(t *testing.T) {
{func(x *int) interface{} { return (*Tint)(x) }, func(v Tinter) { finalize((*int)(v.(*Tint))) }},
}
- for _, tt := range finalizerTests {
+ for i, tt := range finalizerTests {
done := make(chan bool, 1)
go func() {
- v := new(int)
+ // allocate struct with pointer to avoid hitting tinyalloc.
+ // Otherwise we can't be sure when the allocation will
+ // be freed.
+ type T struct {
+ v int
+ p unsafe.Pointer
+ }
+ v := &new(T).v
*v = 97531
runtime.SetFinalizer(tt.convert(v), tt.finalizer)
v = nil
@@ -58,7 +65,7 @@ func TestFinalizerType(t *testing.T) {
select {
case <-ch:
case <-time.After(time.Second * 4):
- t.Errorf("finalizer for type %T didn't run", tt.finalizer)
+ t.Errorf("#%d: finalizer for type %T didn't run", i, tt.finalizer)
}
}
}