mirror of
https://github.com/golang/go
synced 2024-11-14 13:30:30 -07:00
321a220d50
On AIX when external linking, for some symbols we need to add dummy references to prevent the external linker from discarding them. Currently we add the reference unconditionally. But if the symbol doesn't exist, the linking fails in a later stage for generating external relocation of a nonexistent symbol. The symbols are special symbols that almost always exist, except that go:buildid may not exist if the linker is invoked without the -buildid flag. The go command invokes the linker with the flag, so this can only happen with manual linker invocation. Specifically, test/run.go does this in some cases. Fix this by checking the symbol existence before adding the reference. Re-enable tests on AIX. Perhaps the linker should always emit a dummy buildid even if the flag is not set... Fixes #54814. Change-Id: I43d81587151595309e189e38960cbda9a1c5ca32 Reviewed-on: https://go-review.googlesource.com/c/go/+/427620 Run-TryBot: Cherry Mui <cherryyz@google.com> Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Than McIntosh <thanm@google.com>
41 lines
874 B
Go
41 lines
874 B
Go
// run
|
|
|
|
// Copyright 2020 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.
|
|
|
|
//go:build cgo
|
|
|
|
package main
|
|
|
|
import (
|
|
"runtime/cgo"
|
|
"unsafe"
|
|
)
|
|
|
|
type S struct {
|
|
_ cgo.Incomplete
|
|
x int
|
|
}
|
|
|
|
func main() {
|
|
var i int
|
|
p := (*S)(unsafe.Pointer(uintptr(unsafe.Pointer(&i))))
|
|
v := uintptr(unsafe.Pointer(p))
|
|
// p is a pointer to a not-in-heap type. Like some C libraries,
|
|
// we stored an integer in that pointer. That integer just happens
|
|
// to be the address of i.
|
|
// v is also the address of i.
|
|
// p has a base type which is marked not-in-heap, so it
|
|
// should not be adjusted when the stack is copied.
|
|
recurse(100, p, v)
|
|
}
|
|
func recurse(n int, p *S, v uintptr) {
|
|
if n > 0 {
|
|
recurse(n-1, p, v)
|
|
}
|
|
if uintptr(unsafe.Pointer(p)) != v {
|
|
panic("adjusted notinheap pointer")
|
|
}
|
|
}
|