mirror of
https://github.com/golang/go
synced 2024-11-22 09:54:40 -07:00
cmd/ld: handle a special case of scattered relocation 2/1 on Darwin/386
Fixes #1635. R=golang-dev, dave, r CC=golang-dev https://golang.org/cl/6496043
This commit is contained in:
parent
f78ead3ca4
commit
e607380ff6
@ -28,5 +28,6 @@ func TestParallelSleep(t *testing.T) { testParallelSleep(t) }
|
|||||||
func TestSetEnv(t *testing.T) { testSetEnv(t) }
|
func TestSetEnv(t *testing.T) { testSetEnv(t) }
|
||||||
func TestHelpers(t *testing.T) { testHelpers(t) }
|
func TestHelpers(t *testing.T) { testHelpers(t) }
|
||||||
func TestLibgcc(t *testing.T) { testLibgcc(t) }
|
func TestLibgcc(t *testing.T) { testLibgcc(t) }
|
||||||
|
func Test1635(t *testing.T) { test1635(t) }
|
||||||
|
|
||||||
func BenchmarkCgoCall(b *testing.B) { benchCgoCall(b) }
|
func BenchmarkCgoCall(b *testing.B) { benchCgoCall(b) }
|
||||||
|
33
misc/cgo/test/issue1635.go
Normal file
33
misc/cgo/test/issue1635.go
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
// Copyright 2012 The Go Authors. All rights reserved.
|
||||||
|
// Use of this source code is governed by a BSD-style
|
||||||
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
|
package cgotest
|
||||||
|
|
||||||
|
/*
|
||||||
|
// Mac OS X's gcc will generate scattered relocation 2/1 for
|
||||||
|
// this function on Darwin/386, and 8l couldn't handle it.
|
||||||
|
// this example is in issue 1635
|
||||||
|
#include <stdio.h>
|
||||||
|
void scatter() {
|
||||||
|
void *p = scatter;
|
||||||
|
printf("scatter = %p\n", p);
|
||||||
|
}
|
||||||
|
|
||||||
|
// this example is in issue 3253
|
||||||
|
int hola = 0;
|
||||||
|
int testHola() { return hola; }
|
||||||
|
*/
|
||||||
|
import "C"
|
||||||
|
|
||||||
|
import "testing"
|
||||||
|
|
||||||
|
func test1635(t *testing.T) {
|
||||||
|
C.scatter()
|
||||||
|
if v := C.hola; v != 0 {
|
||||||
|
t.Fatalf("C.hola is %d, should be 0", v)
|
||||||
|
}
|
||||||
|
if v := C.testHola(); v != 0 {
|
||||||
|
t.Fatalf("C.testHola() is %d, should be 0", v)
|
||||||
|
}
|
||||||
|
}
|
@ -680,19 +680,28 @@ ldmacho(Biobuf *f, char *pkg, int64 len, char *pn)
|
|||||||
int k;
|
int k;
|
||||||
MachoSect *ks;
|
MachoSect *ks;
|
||||||
|
|
||||||
if(thechar != '8')
|
if(thechar != '8') {
|
||||||
|
// mach-o only uses scattered relocation on 32-bit platforms
|
||||||
diag("unexpected scattered relocation");
|
diag("unexpected scattered relocation");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
// on 386, rewrite scattered 4/1 relocation into
|
// on 386, rewrite scattered 4/1 relocation and some
|
||||||
// the pseudo-pc-relative reference that it is.
|
// scattered 2/1 relocation into the pseudo-pc-relative
|
||||||
|
// reference that it is.
|
||||||
// assume that the second in the pair is in this section
|
// assume that the second in the pair is in this section
|
||||||
// and use that as the pc-relative base.
|
// and use that as the pc-relative base.
|
||||||
if(thechar != '8' || rel->type != 4 || j+1 >= sect->nreloc ||
|
if(j+1 >= sect->nreloc) {
|
||||||
!(rel+1)->scattered || (rel+1)->type != 1 ||
|
werrstr("unsupported scattered relocation %d", (int)rel->type);
|
||||||
|
goto bad;
|
||||||
|
}
|
||||||
|
if(!(rel+1)->scattered || (rel+1)->type != 1 ||
|
||||||
|
(rel->type != 4 && rel->type != 2) ||
|
||||||
(rel+1)->value < sect->addr || (rel+1)->value >= sect->addr+sect->size) {
|
(rel+1)->value < sect->addr || (rel+1)->value >= sect->addr+sect->size) {
|
||||||
werrstr("unsupported scattered relocation %d/%d", (int)rel->type, (int)(rel+1)->type);
|
werrstr("unsupported scattered relocation %d/%d", (int)rel->type, (int)(rel+1)->type);
|
||||||
goto bad;
|
goto bad;
|
||||||
}
|
}
|
||||||
|
|
||||||
rp->siz = rel->length;
|
rp->siz = rel->length;
|
||||||
rp->off = rel->addr;
|
rp->off = rel->addr;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user