1 // Copyright 2020 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
10 "cmd/link/internal/loader"
14 func setUpContext(arch *sys.Arch, iself bool, ht objabi.HeadType, bm, lm string) *Link {
16 edummy := func(str string, off int) {}
18 er := loader.ErrorReporter{}
19 ctxt.loader = loader.NewLoader(0, edummy, &er)
20 ctxt.BuildMode.Set(bm)
23 ctxt.mustSetHeadType()
28 // Make sure the addgotsym properly increases the symbols.
29 func TestAddGotSym(t *testing.T) {
44 relsize: 2 * sys.Arch386.PtrSize,
45 gotsize: sys.Arch386.PtrSize,
53 relsize: 3 * sys.ArchAMD64.PtrSize,
54 gotsize: sys.ArchAMD64.PtrSize,
61 gotsize: sys.ArchAMD64.PtrSize,
65 // Save the architecture as we're going to set it on each test run.
66 origArch := objabi.GOARCH
68 objabi.GOARCH = origArch
71 for i, test := range tests {
72 iself := len(test.rel) != 0
73 objabi.GOARCH = test.arch.Name
74 ctxt := setUpContext(test.arch, iself, test.ht, test.bm, test.lm)
75 foo := ctxt.loader.CreateSymForUpdate("foo", 0)
76 ctxt.loader.CreateExtSym("bar", 0)
77 AddGotSym(&ctxt.Target, ctxt.loader, &ctxt.ArchSyms, foo.Sym(), 0)
80 rel := ctxt.loader.Lookup(test.rel, 0)
82 t.Fatalf("[%d] could not find symbol: %q", i, test.rel)
84 if s := ctxt.loader.SymSize(rel); s != int64(test.relsize) {
85 t.Fatalf("[%d] expected ldr.Size(%q) == %v, got %v", i, test.rel, test.relsize, s)
88 if s := ctxt.loader.SymSize(ctxt.loader.Lookup(".got", 0)); s != int64(test.gotsize) {
89 t.Fatalf(`[%d] expected ldr.Size(".got") == %v, got %v`, i, test.gotsize, s)