mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
[dev.link] cmd: support large function alignment
This ports CL 226997 to the dev.link branch. - The assembler part and old object file writing are unchanged. - Changes to cmd/link are applied to cmd/oldlink. - Add alignment field to new object files for the new linker. Change-Id: Id00f323ae5bdd86b2709a702ee28bcaa9ba962f8 Reviewed-on: https://go-review.googlesource.com/c/go/+/227025 Reviewed-by: Than McIntosh <thanm@google.com>
This commit is contained in:
parent
8cc515ad3f
commit
d92a5a80b5
12 changed files with 144 additions and 40 deletions
|
|
@ -471,3 +471,73 @@ func TestOldLink(t *testing.T) {
|
|||
t.Errorf("%v: %v:\n%s", cmd.Args, err, out)
|
||||
}
|
||||
}
|
||||
|
||||
const testFuncAlignSrc = `
|
||||
package main
|
||||
import (
|
||||
"fmt"
|
||||
"reflect"
|
||||
)
|
||||
func alignPc()
|
||||
|
||||
func main() {
|
||||
addr := reflect.ValueOf(alignPc).Pointer()
|
||||
if (addr % 512) != 0 {
|
||||
fmt.Printf("expected 512 bytes alignment, got %v\n", addr)
|
||||
} else {
|
||||
fmt.Printf("PASS")
|
||||
}
|
||||
}
|
||||
`
|
||||
|
||||
const testFuncAlignAsmSrc = `
|
||||
#include "textflag.h"
|
||||
|
||||
TEXT ·alignPc(SB),NOSPLIT, $0-0
|
||||
MOVD $2, R0
|
||||
PCALIGN $512
|
||||
MOVD $3, R1
|
||||
RET
|
||||
`
|
||||
|
||||
// TestFuncAlign verifies that the address of a function can be aligned
|
||||
// with a specfic value on arm64.
|
||||
func TestFuncAlign(t *testing.T) {
|
||||
if runtime.GOARCH != "arm64" || runtime.GOOS != "linux" {
|
||||
t.Skip("skipping on non-linux/arm64 platform")
|
||||
}
|
||||
testenv.MustHaveGoBuild(t)
|
||||
|
||||
tmpdir, err := ioutil.TempDir("", "TestFuncAlign")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer os.RemoveAll(tmpdir)
|
||||
|
||||
src := filepath.Join(tmpdir, "falign.go")
|
||||
err = ioutil.WriteFile(src, []byte(testFuncAlignSrc), 0666)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
src = filepath.Join(tmpdir, "falign.s")
|
||||
err = ioutil.WriteFile(src, []byte(testFuncAlignAsmSrc), 0666)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
// Build and run with old object file format.
|
||||
cmd := exec.Command(testenv.GoToolPath(t), "build", "-o", "falign")
|
||||
cmd.Dir = tmpdir
|
||||
out, err := cmd.CombinedOutput()
|
||||
if err != nil {
|
||||
t.Errorf("build failed: %v", err)
|
||||
}
|
||||
cmd = exec.Command(tmpdir + "/falign")
|
||||
out, err = cmd.CombinedOutput()
|
||||
if err != nil {
|
||||
t.Errorf("failed to run with err %v, output: %s", err, out)
|
||||
}
|
||||
if string(out) != "PASS" {
|
||||
t.Errorf("unexpected output: %s\n", out)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue