2016-03-19 00:23:17 -04:00
|
|
|
// Inferno utils/5l/asm.c
|
2016-08-28 17:04:46 -07:00
|
|
|
// https://bitbucket.org/inferno-os/inferno-os/src/default/utils/5l/asm.c
|
2016-03-19 00:23:17 -04:00
|
|
|
//
|
|
|
|
|
// Copyright © 1994-1999 Lucent Technologies Inc. All rights reserved.
|
|
|
|
|
// Portions Copyright © 1995-1997 C H Forsyth (forsyth@terzarima.net)
|
|
|
|
|
// Portions Copyright © 1997-1999 Vita Nuova Limited
|
|
|
|
|
// Portions Copyright © 2000-2007 Vita Nuova Holdings Limited (www.vitanuova.com)
|
|
|
|
|
// Portions Copyright © 2004,2006 Bruce Ellis
|
|
|
|
|
// Portions Copyright © 2005-2007 C H Forsyth (forsyth@terzarima.net)
|
|
|
|
|
// Revisions Copyright © 2000-2007 Lucent Technologies Inc. and others
|
2016-04-10 14:32:26 -07:00
|
|
|
// Portions Copyright © 2009 The Go Authors. All rights reserved.
|
2016-03-19 00:23:17 -04:00
|
|
|
//
|
|
|
|
|
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
|
// of this software and associated documentation files (the "Software"), to deal
|
|
|
|
|
// in the Software without restriction, including without limitation the rights
|
|
|
|
|
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
|
// copies of the Software, and to permit persons to whom the Software is
|
|
|
|
|
// furnished to do so, subject to the following conditions:
|
|
|
|
|
//
|
|
|
|
|
// The above copyright notice and this permission notice shall be included in
|
|
|
|
|
// all copies or substantial portions of the Software.
|
|
|
|
|
//
|
|
|
|
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
|
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
|
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
|
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
|
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
|
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
|
|
// THE SOFTWARE.
|
|
|
|
|
|
|
|
|
|
package s390x
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"cmd/internal/obj"
|
|
|
|
|
"cmd/link/internal/ld"
|
|
|
|
|
"debug/elf"
|
|
|
|
|
"fmt"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
// gentext generates assembly to append the local moduledata to the global
|
|
|
|
|
// moduledata linked list at initialization time. This is only done if the runtime
|
|
|
|
|
// is in a different module.
|
|
|
|
|
//
|
|
|
|
|
// <go.link.addmoduledata>:
|
|
|
|
|
// larl %r2, <local.moduledata>
|
|
|
|
|
// jg <runtime.addmoduledata@plt>
|
|
|
|
|
// undef
|
|
|
|
|
//
|
|
|
|
|
// The job of appending the moduledata is delegated to runtime.addmoduledata.
|
2016-08-21 13:52:23 -04:00
|
|
|
func gentext(ctxt *ld.Link) {
|
2016-08-25 21:06:10 -04:00
|
|
|
if !ctxt.DynlinkingGo() {
|
2016-03-19 00:23:17 -04:00
|
|
|
return
|
|
|
|
|
}
|
cmd/link: use ctxt.{Lookup,ROLookup} in favour of function versions of same
Done with two eg templates:
package p
import (
"cmd/link/internal/ld"
)
func before(ctxt *ld.Link, name string, v int) *ld.Symbol {
return ld.Linklookup(ctxt, name, v)
}
func after(ctxt *ld.Link, name string, v int) *ld.Symbol {
return ctxt.Syms.Lookup(name, v)
}
package p
import (
"cmd/link/internal/ld"
)
func before(ctxt *ld.Link, name string, v int) *ld.Symbol {
return ld.Linkrlookup(ctxt, name, v)
}
func after(ctxt *ld.Link, name string, v int) *ld.Symbol {
return ctxt.Syms.ROLookup(name, v)
}
Change-Id: I00647dbf62294557bd24c29ad1f108fc786335f1
Reviewed-on: https://go-review.googlesource.com/29343
Run-TryBot: Michael Hudson-Doyle <michael.hudson@canonical.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2016-09-20 15:06:08 +12:00
|
|
|
addmoduledata := ctxt.Syms.Lookup("runtime.addmoduledata", 0)
|
2016-03-19 00:23:17 -04:00
|
|
|
if addmoduledata.Type == obj.STEXT {
|
|
|
|
|
// we're linking a module containing the runtime -> no need for
|
|
|
|
|
// an init function
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
addmoduledata.Attr |= ld.AttrReachable
|
cmd/link: use ctxt.{Lookup,ROLookup} in favour of function versions of same
Done with two eg templates:
package p
import (
"cmd/link/internal/ld"
)
func before(ctxt *ld.Link, name string, v int) *ld.Symbol {
return ld.Linklookup(ctxt, name, v)
}
func after(ctxt *ld.Link, name string, v int) *ld.Symbol {
return ctxt.Syms.Lookup(name, v)
}
package p
import (
"cmd/link/internal/ld"
)
func before(ctxt *ld.Link, name string, v int) *ld.Symbol {
return ld.Linkrlookup(ctxt, name, v)
}
func after(ctxt *ld.Link, name string, v int) *ld.Symbol {
return ctxt.Syms.ROLookup(name, v)
}
Change-Id: I00647dbf62294557bd24c29ad1f108fc786335f1
Reviewed-on: https://go-review.googlesource.com/29343
Run-TryBot: Michael Hudson-Doyle <michael.hudson@canonical.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2016-09-20 15:06:08 +12:00
|
|
|
initfunc := ctxt.Syms.Lookup("go.link.addmoduledata", 0)
|
2016-03-19 00:23:17 -04:00
|
|
|
initfunc.Type = obj.STEXT
|
|
|
|
|
initfunc.Attr |= ld.AttrLocal
|
|
|
|
|
initfunc.Attr |= ld.AttrReachable
|
|
|
|
|
|
|
|
|
|
// larl %r2, <local.moduledata>
|
2016-08-21 13:52:23 -04:00
|
|
|
ld.Adduint8(ctxt, initfunc, 0xc0)
|
|
|
|
|
ld.Adduint8(ctxt, initfunc, 0x20)
|
2016-03-19 00:23:17 -04:00
|
|
|
lmd := ld.Addrel(initfunc)
|
|
|
|
|
lmd.Off = int32(initfunc.Size)
|
|
|
|
|
lmd.Siz = 4
|
2016-08-21 13:52:23 -04:00
|
|
|
lmd.Sym = ctxt.Moduledata
|
2016-03-19 00:23:17 -04:00
|
|
|
lmd.Type = obj.R_PCREL
|
|
|
|
|
lmd.Variant = ld.RV_390_DBL
|
|
|
|
|
lmd.Add = 2 + int64(lmd.Siz)
|
2016-08-21 13:52:23 -04:00
|
|
|
ld.Adduint32(ctxt, initfunc, 0)
|
2016-03-19 00:23:17 -04:00
|
|
|
|
|
|
|
|
// jg <runtime.addmoduledata[@plt]>
|
2016-08-21 13:52:23 -04:00
|
|
|
ld.Adduint8(ctxt, initfunc, 0xc0)
|
|
|
|
|
ld.Adduint8(ctxt, initfunc, 0xf4)
|
2016-03-19 00:23:17 -04:00
|
|
|
rel := ld.Addrel(initfunc)
|
|
|
|
|
rel.Off = int32(initfunc.Size)
|
|
|
|
|
rel.Siz = 4
|
cmd/link: use ctxt.{Lookup,ROLookup} in favour of function versions of same
Done with two eg templates:
package p
import (
"cmd/link/internal/ld"
)
func before(ctxt *ld.Link, name string, v int) *ld.Symbol {
return ld.Linklookup(ctxt, name, v)
}
func after(ctxt *ld.Link, name string, v int) *ld.Symbol {
return ctxt.Syms.Lookup(name, v)
}
package p
import (
"cmd/link/internal/ld"
)
func before(ctxt *ld.Link, name string, v int) *ld.Symbol {
return ld.Linkrlookup(ctxt, name, v)
}
func after(ctxt *ld.Link, name string, v int) *ld.Symbol {
return ctxt.Syms.ROLookup(name, v)
}
Change-Id: I00647dbf62294557bd24c29ad1f108fc786335f1
Reviewed-on: https://go-review.googlesource.com/29343
Run-TryBot: Michael Hudson-Doyle <michael.hudson@canonical.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2016-09-20 15:06:08 +12:00
|
|
|
rel.Sym = ctxt.Syms.Lookup("runtime.addmoduledata", 0)
|
2016-03-19 00:23:17 -04:00
|
|
|
rel.Type = obj.R_CALL
|
|
|
|
|
rel.Variant = ld.RV_390_DBL
|
|
|
|
|
rel.Add = 2 + int64(rel.Siz)
|
2016-08-21 13:52:23 -04:00
|
|
|
ld.Adduint32(ctxt, initfunc, 0)
|
2016-03-19 00:23:17 -04:00
|
|
|
|
|
|
|
|
// undef (for debugging)
|
2016-08-21 13:52:23 -04:00
|
|
|
ld.Adduint32(ctxt, initfunc, 0)
|
2016-03-19 00:23:17 -04:00
|
|
|
|
2016-08-21 13:52:23 -04:00
|
|
|
ctxt.Textp = append(ctxt.Textp, initfunc)
|
cmd/link: use ctxt.{Lookup,ROLookup} in favour of function versions of same
Done with two eg templates:
package p
import (
"cmd/link/internal/ld"
)
func before(ctxt *ld.Link, name string, v int) *ld.Symbol {
return ld.Linklookup(ctxt, name, v)
}
func after(ctxt *ld.Link, name string, v int) *ld.Symbol {
return ctxt.Syms.Lookup(name, v)
}
package p
import (
"cmd/link/internal/ld"
)
func before(ctxt *ld.Link, name string, v int) *ld.Symbol {
return ld.Linkrlookup(ctxt, name, v)
}
func after(ctxt *ld.Link, name string, v int) *ld.Symbol {
return ctxt.Syms.ROLookup(name, v)
}
Change-Id: I00647dbf62294557bd24c29ad1f108fc786335f1
Reviewed-on: https://go-review.googlesource.com/29343
Run-TryBot: Michael Hudson-Doyle <michael.hudson@canonical.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2016-09-20 15:06:08 +12:00
|
|
|
initarray_entry := ctxt.Syms.Lookup("go.link.addmoduledatainit", 0)
|
2016-03-19 00:23:17 -04:00
|
|
|
initarray_entry.Attr |= ld.AttrLocal
|
|
|
|
|
initarray_entry.Attr |= ld.AttrReachable
|
|
|
|
|
initarray_entry.Type = obj.SINITARR
|
2016-08-21 13:52:23 -04:00
|
|
|
ld.Addaddr(ctxt, initarray_entry, initfunc)
|
2016-03-19 00:23:17 -04:00
|
|
|
}
|
|
|
|
|
|
2016-09-05 23:49:53 -04:00
|
|
|
func adddynrel(ctxt *ld.Link, s *ld.Symbol, r *ld.Reloc) bool {
|
2016-03-19 00:23:17 -04:00
|
|
|
targ := r.Sym
|
|
|
|
|
|
|
|
|
|
switch r.Type {
|
|
|
|
|
default:
|
|
|
|
|
if r.Type >= 256 {
|
2016-09-17 09:39:33 -04:00
|
|
|
ld.Errorf(s, "unexpected relocation type %d", r.Type)
|
2016-09-05 23:49:53 -04:00
|
|
|
return false
|
2016-03-19 00:23:17 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Handle relocations found in ELF object files.
|
|
|
|
|
case 256 + ld.R_390_12,
|
|
|
|
|
256 + ld.R_390_GOT12:
|
2016-09-17 09:39:33 -04:00
|
|
|
ld.Errorf(s, "s390x 12-bit relocations have not been implemented (relocation type %d)", r.Type-256)
|
2016-09-05 23:49:53 -04:00
|
|
|
return false
|
2016-03-19 00:23:17 -04:00
|
|
|
|
|
|
|
|
case 256 + ld.R_390_8,
|
|
|
|
|
256 + ld.R_390_16,
|
|
|
|
|
256 + ld.R_390_32,
|
|
|
|
|
256 + ld.R_390_64:
|
|
|
|
|
if targ.Type == obj.SDYNIMPORT {
|
2016-09-17 09:39:33 -04:00
|
|
|
ld.Errorf(s, "unexpected R_390_nn relocation for dynamic symbol %s", targ.Name)
|
2016-03-19 00:23:17 -04:00
|
|
|
}
|
|
|
|
|
r.Type = obj.R_ADDR
|
2016-09-05 23:49:53 -04:00
|
|
|
return true
|
2016-03-19 00:23:17 -04:00
|
|
|
|
|
|
|
|
case 256 + ld.R_390_PC16,
|
|
|
|
|
256 + ld.R_390_PC32,
|
|
|
|
|
256 + ld.R_390_PC64:
|
|
|
|
|
if targ.Type == obj.SDYNIMPORT {
|
2016-09-17 09:39:33 -04:00
|
|
|
ld.Errorf(s, "unexpected R_390_PCnn relocation for dynamic symbol %s", targ.Name)
|
2016-03-19 00:23:17 -04:00
|
|
|
}
|
|
|
|
|
if targ.Type == 0 || targ.Type == obj.SXREF {
|
2016-09-17 09:39:33 -04:00
|
|
|
ld.Errorf(s, "unknown symbol %s in pcrel", targ.Name)
|
2016-03-19 00:23:17 -04:00
|
|
|
}
|
|
|
|
|
r.Type = obj.R_PCREL
|
|
|
|
|
r.Add += int64(r.Siz)
|
2016-09-05 23:49:53 -04:00
|
|
|
return true
|
2016-03-19 00:23:17 -04:00
|
|
|
|
|
|
|
|
case 256 + ld.R_390_GOT16,
|
|
|
|
|
256 + ld.R_390_GOT32,
|
|
|
|
|
256 + ld.R_390_GOT64:
|
2016-09-17 09:39:33 -04:00
|
|
|
ld.Errorf(s, "unimplemented S390x relocation: %v", r.Type-256)
|
2016-09-05 23:49:53 -04:00
|
|
|
return true
|
2016-03-19 00:23:17 -04:00
|
|
|
|
|
|
|
|
case 256 + ld.R_390_PLT16DBL,
|
|
|
|
|
256 + ld.R_390_PLT32DBL:
|
|
|
|
|
r.Type = obj.R_PCREL
|
|
|
|
|
r.Variant = ld.RV_390_DBL
|
|
|
|
|
r.Add += int64(r.Siz)
|
|
|
|
|
if targ.Type == obj.SDYNIMPORT {
|
2016-08-21 13:52:23 -04:00
|
|
|
addpltsym(ctxt, targ)
|
cmd/link: use ctxt.{Lookup,ROLookup} in favour of function versions of same
Done with two eg templates:
package p
import (
"cmd/link/internal/ld"
)
func before(ctxt *ld.Link, name string, v int) *ld.Symbol {
return ld.Linklookup(ctxt, name, v)
}
func after(ctxt *ld.Link, name string, v int) *ld.Symbol {
return ctxt.Syms.Lookup(name, v)
}
package p
import (
"cmd/link/internal/ld"
)
func before(ctxt *ld.Link, name string, v int) *ld.Symbol {
return ld.Linkrlookup(ctxt, name, v)
}
func after(ctxt *ld.Link, name string, v int) *ld.Symbol {
return ctxt.Syms.ROLookup(name, v)
}
Change-Id: I00647dbf62294557bd24c29ad1f108fc786335f1
Reviewed-on: https://go-review.googlesource.com/29343
Run-TryBot: Michael Hudson-Doyle <michael.hudson@canonical.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2016-09-20 15:06:08 +12:00
|
|
|
r.Sym = ctxt.Syms.Lookup(".plt", 0)
|
2016-03-19 00:23:17 -04:00
|
|
|
r.Add += int64(targ.Plt)
|
|
|
|
|
}
|
2016-09-05 23:49:53 -04:00
|
|
|
return true
|
2016-03-19 00:23:17 -04:00
|
|
|
|
|
|
|
|
case 256 + ld.R_390_PLT32,
|
|
|
|
|
256 + ld.R_390_PLT64:
|
|
|
|
|
r.Type = obj.R_PCREL
|
|
|
|
|
r.Add += int64(r.Siz)
|
|
|
|
|
if targ.Type == obj.SDYNIMPORT {
|
2016-08-21 13:52:23 -04:00
|
|
|
addpltsym(ctxt, targ)
|
cmd/link: use ctxt.{Lookup,ROLookup} in favour of function versions of same
Done with two eg templates:
package p
import (
"cmd/link/internal/ld"
)
func before(ctxt *ld.Link, name string, v int) *ld.Symbol {
return ld.Linklookup(ctxt, name, v)
}
func after(ctxt *ld.Link, name string, v int) *ld.Symbol {
return ctxt.Syms.Lookup(name, v)
}
package p
import (
"cmd/link/internal/ld"
)
func before(ctxt *ld.Link, name string, v int) *ld.Symbol {
return ld.Linkrlookup(ctxt, name, v)
}
func after(ctxt *ld.Link, name string, v int) *ld.Symbol {
return ctxt.Syms.ROLookup(name, v)
}
Change-Id: I00647dbf62294557bd24c29ad1f108fc786335f1
Reviewed-on: https://go-review.googlesource.com/29343
Run-TryBot: Michael Hudson-Doyle <michael.hudson@canonical.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2016-09-20 15:06:08 +12:00
|
|
|
r.Sym = ctxt.Syms.Lookup(".plt", 0)
|
2016-03-19 00:23:17 -04:00
|
|
|
r.Add += int64(targ.Plt)
|
|
|
|
|
}
|
2016-09-05 23:49:53 -04:00
|
|
|
return true
|
2016-03-19 00:23:17 -04:00
|
|
|
|
|
|
|
|
case 256 + ld.R_390_COPY:
|
2016-09-17 09:39:33 -04:00
|
|
|
ld.Errorf(s, "unimplemented S390x relocation: %v", r.Type-256)
|
2016-09-05 23:49:53 -04:00
|
|
|
return false
|
2016-03-19 00:23:17 -04:00
|
|
|
|
|
|
|
|
case 256 + ld.R_390_GLOB_DAT:
|
2016-09-17 09:39:33 -04:00
|
|
|
ld.Errorf(s, "unimplemented S390x relocation: %v", r.Type-256)
|
2016-09-05 23:49:53 -04:00
|
|
|
return false
|
2016-03-19 00:23:17 -04:00
|
|
|
|
|
|
|
|
case 256 + ld.R_390_JMP_SLOT:
|
2016-09-17 09:39:33 -04:00
|
|
|
ld.Errorf(s, "unimplemented S390x relocation: %v", r.Type-256)
|
2016-09-05 23:49:53 -04:00
|
|
|
return false
|
2016-03-19 00:23:17 -04:00
|
|
|
|
|
|
|
|
case 256 + ld.R_390_RELATIVE:
|
2016-09-17 09:39:33 -04:00
|
|
|
ld.Errorf(s, "unimplemented S390x relocation: %v", r.Type-256)
|
2016-09-05 23:49:53 -04:00
|
|
|
return false
|
2016-03-19 00:23:17 -04:00
|
|
|
|
|
|
|
|
case 256 + ld.R_390_GOTOFF:
|
|
|
|
|
if targ.Type == obj.SDYNIMPORT {
|
2016-09-17 09:39:33 -04:00
|
|
|
ld.Errorf(s, "unexpected R_390_GOTOFF relocation for dynamic symbol %s", targ.Name)
|
2016-03-19 00:23:17 -04:00
|
|
|
}
|
|
|
|
|
r.Type = obj.R_GOTOFF
|
2016-09-05 23:49:53 -04:00
|
|
|
return true
|
2016-03-19 00:23:17 -04:00
|
|
|
|
|
|
|
|
case 256 + ld.R_390_GOTPC:
|
|
|
|
|
r.Type = obj.R_PCREL
|
cmd/link: use ctxt.{Lookup,ROLookup} in favour of function versions of same
Done with two eg templates:
package p
import (
"cmd/link/internal/ld"
)
func before(ctxt *ld.Link, name string, v int) *ld.Symbol {
return ld.Linklookup(ctxt, name, v)
}
func after(ctxt *ld.Link, name string, v int) *ld.Symbol {
return ctxt.Syms.Lookup(name, v)
}
package p
import (
"cmd/link/internal/ld"
)
func before(ctxt *ld.Link, name string, v int) *ld.Symbol {
return ld.Linkrlookup(ctxt, name, v)
}
func after(ctxt *ld.Link, name string, v int) *ld.Symbol {
return ctxt.Syms.ROLookup(name, v)
}
Change-Id: I00647dbf62294557bd24c29ad1f108fc786335f1
Reviewed-on: https://go-review.googlesource.com/29343
Run-TryBot: Michael Hudson-Doyle <michael.hudson@canonical.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2016-09-20 15:06:08 +12:00
|
|
|
r.Sym = ctxt.Syms.Lookup(".got", 0)
|
2016-03-19 00:23:17 -04:00
|
|
|
r.Add += int64(r.Siz)
|
2016-09-05 23:49:53 -04:00
|
|
|
return true
|
2016-03-19 00:23:17 -04:00
|
|
|
|
|
|
|
|
case 256 + ld.R_390_PC16DBL,
|
|
|
|
|
256 + ld.R_390_PC32DBL:
|
|
|
|
|
r.Type = obj.R_PCREL
|
|
|
|
|
r.Variant = ld.RV_390_DBL
|
|
|
|
|
r.Add += int64(r.Siz)
|
|
|
|
|
if targ.Type == obj.SDYNIMPORT {
|
2016-09-17 09:39:33 -04:00
|
|
|
ld.Errorf(s, "unexpected R_390_PCnnDBL relocation for dynamic symbol %s", targ.Name)
|
2016-03-19 00:23:17 -04:00
|
|
|
}
|
2016-09-05 23:49:53 -04:00
|
|
|
return true
|
2016-03-19 00:23:17 -04:00
|
|
|
|
|
|
|
|
case 256 + ld.R_390_GOTPCDBL:
|
|
|
|
|
r.Type = obj.R_PCREL
|
|
|
|
|
r.Variant = ld.RV_390_DBL
|
cmd/link: use ctxt.{Lookup,ROLookup} in favour of function versions of same
Done with two eg templates:
package p
import (
"cmd/link/internal/ld"
)
func before(ctxt *ld.Link, name string, v int) *ld.Symbol {
return ld.Linklookup(ctxt, name, v)
}
func after(ctxt *ld.Link, name string, v int) *ld.Symbol {
return ctxt.Syms.Lookup(name, v)
}
package p
import (
"cmd/link/internal/ld"
)
func before(ctxt *ld.Link, name string, v int) *ld.Symbol {
return ld.Linkrlookup(ctxt, name, v)
}
func after(ctxt *ld.Link, name string, v int) *ld.Symbol {
return ctxt.Syms.ROLookup(name, v)
}
Change-Id: I00647dbf62294557bd24c29ad1f108fc786335f1
Reviewed-on: https://go-review.googlesource.com/29343
Run-TryBot: Michael Hudson-Doyle <michael.hudson@canonical.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2016-09-20 15:06:08 +12:00
|
|
|
r.Sym = ctxt.Syms.Lookup(".got", 0)
|
2016-03-19 00:23:17 -04:00
|
|
|
r.Add += int64(r.Siz)
|
2016-09-05 23:49:53 -04:00
|
|
|
return true
|
2016-03-19 00:23:17 -04:00
|
|
|
|
|
|
|
|
case 256 + ld.R_390_GOTENT:
|
2016-08-21 13:52:23 -04:00
|
|
|
addgotsym(ctxt, targ)
|
2016-03-19 00:23:17 -04:00
|
|
|
|
|
|
|
|
r.Type = obj.R_PCREL
|
|
|
|
|
r.Variant = ld.RV_390_DBL
|
cmd/link: use ctxt.{Lookup,ROLookup} in favour of function versions of same
Done with two eg templates:
package p
import (
"cmd/link/internal/ld"
)
func before(ctxt *ld.Link, name string, v int) *ld.Symbol {
return ld.Linklookup(ctxt, name, v)
}
func after(ctxt *ld.Link, name string, v int) *ld.Symbol {
return ctxt.Syms.Lookup(name, v)
}
package p
import (
"cmd/link/internal/ld"
)
func before(ctxt *ld.Link, name string, v int) *ld.Symbol {
return ld.Linkrlookup(ctxt, name, v)
}
func after(ctxt *ld.Link, name string, v int) *ld.Symbol {
return ctxt.Syms.ROLookup(name, v)
}
Change-Id: I00647dbf62294557bd24c29ad1f108fc786335f1
Reviewed-on: https://go-review.googlesource.com/29343
Run-TryBot: Michael Hudson-Doyle <michael.hudson@canonical.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2016-09-20 15:06:08 +12:00
|
|
|
r.Sym = ctxt.Syms.Lookup(".got", 0)
|
2016-03-19 00:23:17 -04:00
|
|
|
r.Add += int64(targ.Got)
|
|
|
|
|
r.Add += int64(r.Siz)
|
2016-09-05 23:49:53 -04:00
|
|
|
return true
|
2016-03-19 00:23:17 -04:00
|
|
|
}
|
|
|
|
|
// Handle references to ELF symbols from our own object files.
|
|
|
|
|
if targ.Type != obj.SDYNIMPORT {
|
2016-09-05 23:49:53 -04:00
|
|
|
return true
|
2016-03-19 00:23:17 -04:00
|
|
|
}
|
|
|
|
|
|
2016-09-05 23:49:53 -04:00
|
|
|
return false
|
2016-03-19 00:23:17 -04:00
|
|
|
}
|
|
|
|
|
|
2016-08-21 13:52:23 -04:00
|
|
|
func elfreloc1(ctxt *ld.Link, r *ld.Reloc, sectoff int64) int {
|
2016-03-19 00:23:17 -04:00
|
|
|
ld.Thearch.Vput(uint64(sectoff))
|
|
|
|
|
|
|
|
|
|
elfsym := r.Xsym.ElfsymForReloc()
|
|
|
|
|
switch r.Type {
|
|
|
|
|
default:
|
|
|
|
|
return -1
|
|
|
|
|
|
|
|
|
|
case obj.R_TLS_LE:
|
|
|
|
|
switch r.Siz {
|
|
|
|
|
default:
|
|
|
|
|
return -1
|
|
|
|
|
case 4:
|
|
|
|
|
// WARNING - silently ignored by linker in ELF64
|
|
|
|
|
ld.Thearch.Vput(ld.R_390_TLS_LE32 | uint64(elfsym)<<32)
|
|
|
|
|
case 8:
|
|
|
|
|
// WARNING - silently ignored by linker in ELF32
|
|
|
|
|
ld.Thearch.Vput(ld.R_390_TLS_LE64 | uint64(elfsym)<<32)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
case obj.R_TLS_IE:
|
|
|
|
|
switch r.Siz {
|
|
|
|
|
default:
|
|
|
|
|
return -1
|
|
|
|
|
case 4:
|
|
|
|
|
ld.Thearch.Vput(ld.R_390_TLS_IEENT | uint64(elfsym)<<32)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
case obj.R_ADDR:
|
|
|
|
|
switch r.Siz {
|
|
|
|
|
default:
|
|
|
|
|
return -1
|
|
|
|
|
case 4:
|
|
|
|
|
ld.Thearch.Vput(ld.R_390_32 | uint64(elfsym)<<32)
|
|
|
|
|
case 8:
|
|
|
|
|
ld.Thearch.Vput(ld.R_390_64 | uint64(elfsym)<<32)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
case obj.R_GOTPCREL:
|
|
|
|
|
if r.Siz == 4 {
|
|
|
|
|
ld.Thearch.Vput(ld.R_390_GOTENT | uint64(elfsym)<<32)
|
|
|
|
|
} else {
|
|
|
|
|
return -1
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
case obj.R_PCREL, obj.R_PCRELDBL, obj.R_CALL:
|
|
|
|
|
elfrel := ld.R_390_NONE
|
|
|
|
|
isdbl := r.Variant&ld.RV_TYPE_MASK == ld.RV_390_DBL
|
|
|
|
|
// TODO(mundaym): all DBL style relocations should be
|
|
|
|
|
// signalled using the variant - see issue 14218.
|
|
|
|
|
switch r.Type {
|
|
|
|
|
case obj.R_PCRELDBL, obj.R_CALL:
|
|
|
|
|
isdbl = true
|
|
|
|
|
}
|
|
|
|
|
if r.Xsym.Type == obj.SDYNIMPORT && (r.Xsym.ElfType == elf.STT_FUNC || r.Type == obj.R_CALL) {
|
|
|
|
|
if isdbl {
|
|
|
|
|
switch r.Siz {
|
|
|
|
|
case 2:
|
|
|
|
|
elfrel = ld.R_390_PLT16DBL
|
|
|
|
|
case 4:
|
|
|
|
|
elfrel = ld.R_390_PLT32DBL
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
switch r.Siz {
|
|
|
|
|
case 4:
|
|
|
|
|
elfrel = ld.R_390_PLT32
|
|
|
|
|
case 8:
|
|
|
|
|
elfrel = ld.R_390_PLT64
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
if isdbl {
|
|
|
|
|
switch r.Siz {
|
|
|
|
|
case 2:
|
|
|
|
|
elfrel = ld.R_390_PC16DBL
|
|
|
|
|
case 4:
|
|
|
|
|
elfrel = ld.R_390_PC32DBL
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
switch r.Siz {
|
|
|
|
|
case 2:
|
|
|
|
|
elfrel = ld.R_390_PC16
|
|
|
|
|
case 4:
|
|
|
|
|
elfrel = ld.R_390_PC32
|
|
|
|
|
case 8:
|
|
|
|
|
elfrel = ld.R_390_PC64
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if elfrel == ld.R_390_NONE {
|
|
|
|
|
return -1 // unsupported size/dbl combination
|
|
|
|
|
}
|
|
|
|
|
ld.Thearch.Vput(uint64(elfrel) | uint64(elfsym)<<32)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ld.Thearch.Vput(uint64(r.Xadd))
|
|
|
|
|
return 0
|
|
|
|
|
}
|
|
|
|
|
|
2016-08-21 13:52:23 -04:00
|
|
|
func elfsetupplt(ctxt *ld.Link) {
|
cmd/link: use ctxt.{Lookup,ROLookup} in favour of function versions of same
Done with two eg templates:
package p
import (
"cmd/link/internal/ld"
)
func before(ctxt *ld.Link, name string, v int) *ld.Symbol {
return ld.Linklookup(ctxt, name, v)
}
func after(ctxt *ld.Link, name string, v int) *ld.Symbol {
return ctxt.Syms.Lookup(name, v)
}
package p
import (
"cmd/link/internal/ld"
)
func before(ctxt *ld.Link, name string, v int) *ld.Symbol {
return ld.Linkrlookup(ctxt, name, v)
}
func after(ctxt *ld.Link, name string, v int) *ld.Symbol {
return ctxt.Syms.ROLookup(name, v)
}
Change-Id: I00647dbf62294557bd24c29ad1f108fc786335f1
Reviewed-on: https://go-review.googlesource.com/29343
Run-TryBot: Michael Hudson-Doyle <michael.hudson@canonical.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2016-09-20 15:06:08 +12:00
|
|
|
plt := ctxt.Syms.Lookup(".plt", 0)
|
|
|
|
|
got := ctxt.Syms.Lookup(".got", 0)
|
2016-03-19 00:23:17 -04:00
|
|
|
if plt.Size == 0 {
|
|
|
|
|
// stg %r1,56(%r15)
|
2016-08-21 13:52:23 -04:00
|
|
|
ld.Adduint8(ctxt, plt, 0xe3)
|
|
|
|
|
ld.Adduint8(ctxt, plt, 0x10)
|
|
|
|
|
ld.Adduint8(ctxt, plt, 0xf0)
|
|
|
|
|
ld.Adduint8(ctxt, plt, 0x38)
|
|
|
|
|
ld.Adduint8(ctxt, plt, 0x00)
|
|
|
|
|
ld.Adduint8(ctxt, plt, 0x24)
|
2016-03-19 00:23:17 -04:00
|
|
|
// larl %r1,_GLOBAL_OFFSET_TABLE_
|
2016-08-21 13:52:23 -04:00
|
|
|
ld.Adduint8(ctxt, plt, 0xc0)
|
|
|
|
|
ld.Adduint8(ctxt, plt, 0x10)
|
|
|
|
|
ld.Addpcrelplus(ctxt, plt, got, 6)
|
2016-03-19 00:23:17 -04:00
|
|
|
// mvc 48(8,%r15),8(%r1)
|
2016-08-21 13:52:23 -04:00
|
|
|
ld.Adduint8(ctxt, plt, 0xd2)
|
|
|
|
|
ld.Adduint8(ctxt, plt, 0x07)
|
|
|
|
|
ld.Adduint8(ctxt, plt, 0xf0)
|
|
|
|
|
ld.Adduint8(ctxt, plt, 0x30)
|
|
|
|
|
ld.Adduint8(ctxt, plt, 0x10)
|
|
|
|
|
ld.Adduint8(ctxt, plt, 0x08)
|
2016-03-19 00:23:17 -04:00
|
|
|
// lg %r1,16(%r1)
|
2016-08-21 13:52:23 -04:00
|
|
|
ld.Adduint8(ctxt, plt, 0xe3)
|
|
|
|
|
ld.Adduint8(ctxt, plt, 0x10)
|
|
|
|
|
ld.Adduint8(ctxt, plt, 0x10)
|
|
|
|
|
ld.Adduint8(ctxt, plt, 0x10)
|
|
|
|
|
ld.Adduint8(ctxt, plt, 0x00)
|
|
|
|
|
ld.Adduint8(ctxt, plt, 0x04)
|
2016-03-19 00:23:17 -04:00
|
|
|
// br %r1
|
2016-08-21 13:52:23 -04:00
|
|
|
ld.Adduint8(ctxt, plt, 0x07)
|
|
|
|
|
ld.Adduint8(ctxt, plt, 0xf1)
|
2016-03-19 00:23:17 -04:00
|
|
|
// nopr %r0
|
2016-08-21 13:52:23 -04:00
|
|
|
ld.Adduint8(ctxt, plt, 0x07)
|
|
|
|
|
ld.Adduint8(ctxt, plt, 0x00)
|
2016-03-19 00:23:17 -04:00
|
|
|
// nopr %r0
|
2016-08-21 13:52:23 -04:00
|
|
|
ld.Adduint8(ctxt, plt, 0x07)
|
|
|
|
|
ld.Adduint8(ctxt, plt, 0x00)
|
2016-03-19 00:23:17 -04:00
|
|
|
// nopr %r0
|
2016-08-21 13:52:23 -04:00
|
|
|
ld.Adduint8(ctxt, plt, 0x07)
|
|
|
|
|
ld.Adduint8(ctxt, plt, 0x00)
|
2016-03-19 00:23:17 -04:00
|
|
|
|
|
|
|
|
// assume got->size == 0 too
|
cmd/link: use ctxt.{Lookup,ROLookup} in favour of function versions of same
Done with two eg templates:
package p
import (
"cmd/link/internal/ld"
)
func before(ctxt *ld.Link, name string, v int) *ld.Symbol {
return ld.Linklookup(ctxt, name, v)
}
func after(ctxt *ld.Link, name string, v int) *ld.Symbol {
return ctxt.Syms.Lookup(name, v)
}
package p
import (
"cmd/link/internal/ld"
)
func before(ctxt *ld.Link, name string, v int) *ld.Symbol {
return ld.Linkrlookup(ctxt, name, v)
}
func after(ctxt *ld.Link, name string, v int) *ld.Symbol {
return ctxt.Syms.ROLookup(name, v)
}
Change-Id: I00647dbf62294557bd24c29ad1f108fc786335f1
Reviewed-on: https://go-review.googlesource.com/29343
Run-TryBot: Michael Hudson-Doyle <michael.hudson@canonical.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2016-09-20 15:06:08 +12:00
|
|
|
ld.Addaddrplus(ctxt, got, ctxt.Syms.Lookup(".dynamic", 0), 0)
|
2016-03-19 00:23:17 -04:00
|
|
|
|
2016-08-21 13:52:23 -04:00
|
|
|
ld.Adduint64(ctxt, got, 0)
|
|
|
|
|
ld.Adduint64(ctxt, got, 0)
|
2016-03-19 00:23:17 -04:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-09-17 09:39:33 -04:00
|
|
|
func machoreloc1(s *ld.Symbol, r *ld.Reloc, sectoff int64) int {
|
2016-03-19 00:23:17 -04:00
|
|
|
return -1
|
|
|
|
|
}
|
|
|
|
|
|
2016-08-21 13:52:23 -04:00
|
|
|
func archreloc(ctxt *ld.Link, r *ld.Reloc, s *ld.Symbol, val *int64) int {
|
2016-03-19 00:23:17 -04:00
|
|
|
if ld.Linkmode == ld.LinkExternal {
|
|
|
|
|
return -1
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
switch r.Type {
|
|
|
|
|
case obj.R_CONST:
|
|
|
|
|
*val = r.Add
|
|
|
|
|
return 0
|
|
|
|
|
|
|
|
|
|
case obj.R_GOTOFF:
|
cmd/link: use ctxt.{Lookup,ROLookup} in favour of function versions of same
Done with two eg templates:
package p
import (
"cmd/link/internal/ld"
)
func before(ctxt *ld.Link, name string, v int) *ld.Symbol {
return ld.Linklookup(ctxt, name, v)
}
func after(ctxt *ld.Link, name string, v int) *ld.Symbol {
return ctxt.Syms.Lookup(name, v)
}
package p
import (
"cmd/link/internal/ld"
)
func before(ctxt *ld.Link, name string, v int) *ld.Symbol {
return ld.Linkrlookup(ctxt, name, v)
}
func after(ctxt *ld.Link, name string, v int) *ld.Symbol {
return ctxt.Syms.ROLookup(name, v)
}
Change-Id: I00647dbf62294557bd24c29ad1f108fc786335f1
Reviewed-on: https://go-review.googlesource.com/29343
Run-TryBot: Michael Hudson-Doyle <michael.hudson@canonical.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2016-09-20 15:06:08 +12:00
|
|
|
*val = ld.Symaddr(r.Sym) + r.Add - ld.Symaddr(ctxt.Syms.Lookup(".got", 0))
|
2016-03-19 00:23:17 -04:00
|
|
|
return 0
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return -1
|
|
|
|
|
}
|
|
|
|
|
|
2016-08-21 13:52:23 -04:00
|
|
|
func archrelocvariant(ctxt *ld.Link, r *ld.Reloc, s *ld.Symbol, t int64) int64 {
|
2016-03-19 00:23:17 -04:00
|
|
|
switch r.Variant & ld.RV_TYPE_MASK {
|
|
|
|
|
default:
|
2016-09-17 09:39:33 -04:00
|
|
|
ld.Errorf(s, "unexpected relocation variant %d", r.Variant)
|
2016-03-19 00:23:17 -04:00
|
|
|
return t
|
|
|
|
|
|
|
|
|
|
case ld.RV_NONE:
|
|
|
|
|
return t
|
|
|
|
|
|
|
|
|
|
case ld.RV_390_DBL:
|
|
|
|
|
if (t & 1) != 0 {
|
2016-09-17 09:39:33 -04:00
|
|
|
ld.Errorf(s, "%s+%v is not 2-byte aligned", r.Sym.Name, r.Sym.Value)
|
2016-03-19 00:23:17 -04:00
|
|
|
}
|
|
|
|
|
return t >> 1
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-08-19 11:35:54 -04:00
|
|
|
func addpltsym(ctxt *ld.Link, s *ld.Symbol) {
|
2016-03-19 00:23:17 -04:00
|
|
|
if s.Plt >= 0 {
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ld.Adddynsym(ctxt, s)
|
|
|
|
|
|
|
|
|
|
if ld.Iself {
|
cmd/link: use ctxt.{Lookup,ROLookup} in favour of function versions of same
Done with two eg templates:
package p
import (
"cmd/link/internal/ld"
)
func before(ctxt *ld.Link, name string, v int) *ld.Symbol {
return ld.Linklookup(ctxt, name, v)
}
func after(ctxt *ld.Link, name string, v int) *ld.Symbol {
return ctxt.Syms.Lookup(name, v)
}
package p
import (
"cmd/link/internal/ld"
)
func before(ctxt *ld.Link, name string, v int) *ld.Symbol {
return ld.Linkrlookup(ctxt, name, v)
}
func after(ctxt *ld.Link, name string, v int) *ld.Symbol {
return ctxt.Syms.ROLookup(name, v)
}
Change-Id: I00647dbf62294557bd24c29ad1f108fc786335f1
Reviewed-on: https://go-review.googlesource.com/29343
Run-TryBot: Michael Hudson-Doyle <michael.hudson@canonical.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2016-09-20 15:06:08 +12:00
|
|
|
plt := ctxt.Syms.Lookup(".plt", 0)
|
|
|
|
|
got := ctxt.Syms.Lookup(".got", 0)
|
|
|
|
|
rela := ctxt.Syms.Lookup(".rela.plt", 0)
|
2016-03-19 00:23:17 -04:00
|
|
|
if plt.Size == 0 {
|
2016-08-21 13:52:23 -04:00
|
|
|
elfsetupplt(ctxt)
|
2016-03-19 00:23:17 -04:00
|
|
|
}
|
|
|
|
|
// larl %r1,_GLOBAL_OFFSET_TABLE_+index
|
|
|
|
|
|
|
|
|
|
ld.Adduint8(ctxt, plt, 0xc0)
|
|
|
|
|
ld.Adduint8(ctxt, plt, 0x10)
|
|
|
|
|
ld.Addpcrelplus(ctxt, plt, got, got.Size+6) // need variant?
|
|
|
|
|
|
|
|
|
|
// add to got: pointer to current pos in plt
|
|
|
|
|
ld.Addaddrplus(ctxt, got, plt, plt.Size+8) // weird but correct
|
|
|
|
|
// lg %r1,0(%r1)
|
|
|
|
|
ld.Adduint8(ctxt, plt, 0xe3)
|
|
|
|
|
ld.Adduint8(ctxt, plt, 0x10)
|
|
|
|
|
ld.Adduint8(ctxt, plt, 0x10)
|
|
|
|
|
ld.Adduint8(ctxt, plt, 0x00)
|
|
|
|
|
ld.Adduint8(ctxt, plt, 0x00)
|
|
|
|
|
ld.Adduint8(ctxt, plt, 0x04)
|
|
|
|
|
// br %r1
|
|
|
|
|
ld.Adduint8(ctxt, plt, 0x07)
|
|
|
|
|
ld.Adduint8(ctxt, plt, 0xf1)
|
|
|
|
|
// basr %r1,%r0
|
|
|
|
|
ld.Adduint8(ctxt, plt, 0x0d)
|
|
|
|
|
ld.Adduint8(ctxt, plt, 0x10)
|
|
|
|
|
// lgf %r1,12(%r1)
|
|
|
|
|
ld.Adduint8(ctxt, plt, 0xe3)
|
|
|
|
|
ld.Adduint8(ctxt, plt, 0x10)
|
|
|
|
|
ld.Adduint8(ctxt, plt, 0x10)
|
|
|
|
|
ld.Adduint8(ctxt, plt, 0x0c)
|
|
|
|
|
ld.Adduint8(ctxt, plt, 0x00)
|
|
|
|
|
ld.Adduint8(ctxt, plt, 0x14)
|
|
|
|
|
// jg .plt
|
|
|
|
|
ld.Adduint8(ctxt, plt, 0xc0)
|
|
|
|
|
ld.Adduint8(ctxt, plt, 0xf4)
|
|
|
|
|
|
|
|
|
|
ld.Adduint32(ctxt, plt, uint32(-((plt.Size - 2) >> 1))) // roll-your-own relocation
|
|
|
|
|
//.plt index
|
|
|
|
|
ld.Adduint32(ctxt, plt, uint32(rela.Size)) // rela size before current entry
|
|
|
|
|
|
|
|
|
|
// rela
|
|
|
|
|
ld.Addaddrplus(ctxt, rela, got, got.Size-8)
|
|
|
|
|
|
|
|
|
|
ld.Adduint64(ctxt, rela, ld.ELF64_R_INFO(uint32(s.Dynid), ld.R_390_JMP_SLOT))
|
|
|
|
|
ld.Adduint64(ctxt, rela, 0)
|
|
|
|
|
|
|
|
|
|
s.Plt = int32(plt.Size - 32)
|
|
|
|
|
|
|
|
|
|
} else {
|
2016-09-17 09:39:33 -04:00
|
|
|
ld.Errorf(s, "addpltsym: unsupported binary format")
|
2016-03-19 00:23:17 -04:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-08-21 13:52:23 -04:00
|
|
|
func addgotsym(ctxt *ld.Link, s *ld.Symbol) {
|
2016-03-19 00:23:17 -04:00
|
|
|
if s.Got >= 0 {
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
2016-08-21 13:52:23 -04:00
|
|
|
ld.Adddynsym(ctxt, s)
|
cmd/link: use ctxt.{Lookup,ROLookup} in favour of function versions of same
Done with two eg templates:
package p
import (
"cmd/link/internal/ld"
)
func before(ctxt *ld.Link, name string, v int) *ld.Symbol {
return ld.Linklookup(ctxt, name, v)
}
func after(ctxt *ld.Link, name string, v int) *ld.Symbol {
return ctxt.Syms.Lookup(name, v)
}
package p
import (
"cmd/link/internal/ld"
)
func before(ctxt *ld.Link, name string, v int) *ld.Symbol {
return ld.Linkrlookup(ctxt, name, v)
}
func after(ctxt *ld.Link, name string, v int) *ld.Symbol {
return ctxt.Syms.ROLookup(name, v)
}
Change-Id: I00647dbf62294557bd24c29ad1f108fc786335f1
Reviewed-on: https://go-review.googlesource.com/29343
Run-TryBot: Michael Hudson-Doyle <michael.hudson@canonical.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2016-09-20 15:06:08 +12:00
|
|
|
got := ctxt.Syms.Lookup(".got", 0)
|
2016-03-19 00:23:17 -04:00
|
|
|
s.Got = int32(got.Size)
|
2016-08-21 13:52:23 -04:00
|
|
|
ld.Adduint64(ctxt, got, 0)
|
2016-03-19 00:23:17 -04:00
|
|
|
|
|
|
|
|
if ld.Iself {
|
cmd/link: use ctxt.{Lookup,ROLookup} in favour of function versions of same
Done with two eg templates:
package p
import (
"cmd/link/internal/ld"
)
func before(ctxt *ld.Link, name string, v int) *ld.Symbol {
return ld.Linklookup(ctxt, name, v)
}
func after(ctxt *ld.Link, name string, v int) *ld.Symbol {
return ctxt.Syms.Lookup(name, v)
}
package p
import (
"cmd/link/internal/ld"
)
func before(ctxt *ld.Link, name string, v int) *ld.Symbol {
return ld.Linkrlookup(ctxt, name, v)
}
func after(ctxt *ld.Link, name string, v int) *ld.Symbol {
return ctxt.Syms.ROLookup(name, v)
}
Change-Id: I00647dbf62294557bd24c29ad1f108fc786335f1
Reviewed-on: https://go-review.googlesource.com/29343
Run-TryBot: Michael Hudson-Doyle <michael.hudson@canonical.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2016-09-20 15:06:08 +12:00
|
|
|
rela := ctxt.Syms.Lookup(".rela", 0)
|
2016-08-21 13:52:23 -04:00
|
|
|
ld.Addaddrplus(ctxt, rela, got, int64(s.Got))
|
|
|
|
|
ld.Adduint64(ctxt, rela, ld.ELF64_R_INFO(uint32(s.Dynid), ld.R_390_GLOB_DAT))
|
|
|
|
|
ld.Adduint64(ctxt, rela, 0)
|
2016-03-19 00:23:17 -04:00
|
|
|
} else {
|
2016-09-17 09:39:33 -04:00
|
|
|
ld.Errorf(s, "addgotsym: unsupported binary format")
|
2016-03-19 00:23:17 -04:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-08-19 22:40:38 -04:00
|
|
|
func asmb(ctxt *ld.Link) {
|
2016-08-21 18:25:28 -04:00
|
|
|
if ctxt.Debugvlog != 0 {
|
2016-08-25 12:32:42 +10:00
|
|
|
ctxt.Logf("%5.2f asmb\n", obj.Cputime())
|
2016-03-19 00:23:17 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ld.Iself {
|
2016-08-19 22:40:38 -04:00
|
|
|
ld.Asmbelfsetup(ctxt)
|
2016-03-19 00:23:17 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
sect := ld.Segtext.Sect
|
|
|
|
|
ld.Cseek(int64(sect.Vaddr - ld.Segtext.Vaddr + ld.Segtext.Fileoff))
|
2016-08-19 22:40:38 -04:00
|
|
|
ld.Codeblk(ctxt, int64(sect.Vaddr), int64(sect.Length))
|
2016-03-19 00:23:17 -04:00
|
|
|
for sect = sect.Next; sect != nil; sect = sect.Next {
|
|
|
|
|
ld.Cseek(int64(sect.Vaddr - ld.Segtext.Vaddr + ld.Segtext.Fileoff))
|
2016-08-19 22:40:38 -04:00
|
|
|
ld.Datblk(ctxt, int64(sect.Vaddr), int64(sect.Length))
|
2016-03-19 00:23:17 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ld.Segrodata.Filelen > 0 {
|
2016-08-21 18:25:28 -04:00
|
|
|
if ctxt.Debugvlog != 0 {
|
2016-08-25 12:32:42 +10:00
|
|
|
ctxt.Logf("%5.2f rodatblk\n", obj.Cputime())
|
2016-03-19 00:23:17 -04:00
|
|
|
}
|
|
|
|
|
ld.Cseek(int64(ld.Segrodata.Fileoff))
|
2016-08-19 22:40:38 -04:00
|
|
|
ld.Datblk(ctxt, int64(ld.Segrodata.Vaddr), int64(ld.Segrodata.Filelen))
|
2016-03-19 00:23:17 -04:00
|
|
|
}
|
2016-09-05 23:29:16 -04:00
|
|
|
if ld.Segrelrodata.Filelen > 0 {
|
|
|
|
|
if ctxt.Debugvlog != 0 {
|
|
|
|
|
ctxt.Logf("%5.2f rodatblk\n", obj.Cputime())
|
|
|
|
|
}
|
|
|
|
|
ld.Cseek(int64(ld.Segrelrodata.Fileoff))
|
|
|
|
|
ld.Datblk(ctxt, int64(ld.Segrelrodata.Vaddr), int64(ld.Segrelrodata.Filelen))
|
|
|
|
|
}
|
2016-03-19 00:23:17 -04:00
|
|
|
|
2016-08-21 18:25:28 -04:00
|
|
|
if ctxt.Debugvlog != 0 {
|
2016-08-25 12:32:42 +10:00
|
|
|
ctxt.Logf("%5.2f datblk\n", obj.Cputime())
|
2016-03-19 00:23:17 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ld.Cseek(int64(ld.Segdata.Fileoff))
|
2016-08-19 22:40:38 -04:00
|
|
|
ld.Datblk(ctxt, int64(ld.Segdata.Vaddr), int64(ld.Segdata.Filelen))
|
2016-03-19 00:23:17 -04:00
|
|
|
|
2016-03-14 09:23:04 -07:00
|
|
|
ld.Cseek(int64(ld.Segdwarf.Fileoff))
|
2016-08-19 22:40:38 -04:00
|
|
|
ld.Dwarfblk(ctxt, int64(ld.Segdwarf.Vaddr), int64(ld.Segdwarf.Filelen))
|
2016-03-14 09:23:04 -07:00
|
|
|
|
2016-03-19 00:23:17 -04:00
|
|
|
/* output symbol table */
|
|
|
|
|
ld.Symsize = 0
|
|
|
|
|
|
|
|
|
|
ld.Lcsize = 0
|
|
|
|
|
symo := uint32(0)
|
2016-08-21 18:34:24 -04:00
|
|
|
if !*ld.FlagS {
|
2016-03-19 00:23:17 -04:00
|
|
|
if !ld.Iself {
|
2016-09-17 09:39:33 -04:00
|
|
|
ld.Errorf(nil, "unsupported executable format")
|
2016-03-19 00:23:17 -04:00
|
|
|
}
|
2016-08-21 18:25:28 -04:00
|
|
|
if ctxt.Debugvlog != 0 {
|
2016-08-25 12:32:42 +10:00
|
|
|
ctxt.Logf("%5.2f sym\n", obj.Cputime())
|
2016-03-19 00:23:17 -04:00
|
|
|
}
|
2016-03-14 09:23:04 -07:00
|
|
|
symo = uint32(ld.Segdwarf.Fileoff + ld.Segdwarf.Filelen)
|
2016-08-21 18:34:24 -04:00
|
|
|
symo = uint32(ld.Rnd(int64(symo), int64(*ld.FlagRound)))
|
2016-03-19 00:23:17 -04:00
|
|
|
|
|
|
|
|
ld.Cseek(int64(symo))
|
2016-08-21 18:25:28 -04:00
|
|
|
if ctxt.Debugvlog != 0 {
|
2016-08-25 12:32:42 +10:00
|
|
|
ctxt.Logf("%5.2f elfsym\n", obj.Cputime())
|
2016-03-19 00:23:17 -04:00
|
|
|
}
|
2016-08-19 22:40:38 -04:00
|
|
|
ld.Asmelfsym(ctxt)
|
2016-03-19 00:23:17 -04:00
|
|
|
ld.Cflush()
|
|
|
|
|
ld.Cwrite(ld.Elfstrdat)
|
|
|
|
|
|
2016-08-21 18:25:28 -04:00
|
|
|
if ctxt.Debugvlog != 0 {
|
2016-08-25 12:32:42 +10:00
|
|
|
ctxt.Logf("%5.2f dwarf\n", obj.Cputime())
|
2016-03-19 00:23:17 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ld.Linkmode == ld.LinkExternal {
|
2016-08-19 22:40:38 -04:00
|
|
|
ld.Elfemitreloc(ctxt)
|
2016-03-19 00:23:17 -04:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-08-21 18:25:28 -04:00
|
|
|
if ctxt.Debugvlog != 0 {
|
2016-08-25 12:32:42 +10:00
|
|
|
ctxt.Logf("%5.2f header\n", obj.Cputime())
|
2016-03-19 00:23:17 -04:00
|
|
|
}
|
|
|
|
|
ld.Cseek(0)
|
2016-09-09 06:20:44 -04:00
|
|
|
switch ld.Headtype {
|
2016-03-19 00:23:17 -04:00
|
|
|
default:
|
2016-09-17 09:39:33 -04:00
|
|
|
ld.Errorf(nil, "unsupported operating system")
|
2016-03-19 00:23:17 -04:00
|
|
|
case obj.Hlinux:
|
2016-08-19 22:40:38 -04:00
|
|
|
ld.Asmbelf(ctxt, int64(symo))
|
2016-03-19 00:23:17 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ld.Cflush()
|
2016-08-21 18:34:24 -04:00
|
|
|
if *ld.FlagC {
|
2016-03-19 00:23:17 -04:00
|
|
|
fmt.Printf("textsize=%d\n", ld.Segtext.Filelen)
|
|
|
|
|
fmt.Printf("datsize=%d\n", ld.Segdata.Filelen)
|
|
|
|
|
fmt.Printf("bsssize=%d\n", ld.Segdata.Length-ld.Segdata.Filelen)
|
|
|
|
|
fmt.Printf("symsize=%d\n", ld.Symsize)
|
|
|
|
|
fmt.Printf("lcsize=%d\n", ld.Lcsize)
|
|
|
|
|
fmt.Printf("total=%d\n", ld.Segtext.Filelen+ld.Segdata.Length+uint64(ld.Symsize)+uint64(ld.Lcsize))
|
|
|
|
|
}
|
|
|
|
|
}
|