2015-02-27 22:57:28 -05:00
|
|
|
// Inferno utils/6l/span.c
|
2016-08-28 17:04:46 -07:00
|
|
|
// https://bitbucket.org/inferno-os/inferno-os/src/default/utils/6l/span.c
|
2015-02-27 22:57:28 -05: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.
|
2015-02-27 22:57:28 -05: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 ld
|
|
|
|
|
|
2015-04-19 19:33:58 -07:00
|
|
|
import (
|
2017-04-18 12:53:25 -07:00
|
|
|
"cmd/internal/objabi"
|
2016-04-06 12:01:40 -07:00
|
|
|
"cmd/internal/sys"
|
2017-10-04 17:54:04 -04:00
|
|
|
"cmd/link/internal/sym"
|
2015-04-11 12:05:21 +08:00
|
|
|
"fmt"
|
|
|
|
|
"path/filepath"
|
2015-04-19 19:33:58 -07:00
|
|
|
"strings"
|
|
|
|
|
)
|
2015-02-27 22:57:28 -05:00
|
|
|
|
|
|
|
|
// Symbol table.
|
|
|
|
|
|
|
|
|
|
func putelfstr(s string) int {
|
|
|
|
|
if len(Elfstrdat) == 0 && s != "" {
|
|
|
|
|
// first entry must be empty string
|
|
|
|
|
putelfstr("")
|
|
|
|
|
}
|
|
|
|
|
|
2015-03-02 12:35:15 -05:00
|
|
|
off := len(Elfstrdat)
|
2016-04-07 18:00:57 +03:00
|
|
|
Elfstrdat = append(Elfstrdat, s...)
|
|
|
|
|
Elfstrdat = append(Elfstrdat, 0)
|
2015-02-27 22:57:28 -05:00
|
|
|
return off
|
|
|
|
|
}
|
|
|
|
|
|
2017-10-01 02:37:20 +00:00
|
|
|
func putelfsyment(out *OutBuf, off int, addr int64, size int64, info int, shndx int, other int) {
|
2016-04-05 23:01:10 -07:00
|
|
|
if elf64 {
|
2017-10-01 02:37:20 +00:00
|
|
|
out.Write32(uint32(off))
|
|
|
|
|
out.Write8(uint8(info))
|
|
|
|
|
out.Write8(uint8(other))
|
|
|
|
|
out.Write16(uint16(shndx))
|
|
|
|
|
out.Write64(uint64(addr))
|
|
|
|
|
out.Write64(uint64(size))
|
2015-02-27 22:57:28 -05:00
|
|
|
Symsize += ELF64SYMSIZE
|
2016-04-05 23:01:10 -07:00
|
|
|
} else {
|
2017-10-01 02:37:20 +00:00
|
|
|
out.Write32(uint32(off))
|
|
|
|
|
out.Write32(uint32(addr))
|
|
|
|
|
out.Write32(uint32(size))
|
|
|
|
|
out.Write8(uint8(info))
|
|
|
|
|
out.Write8(uint8(other))
|
|
|
|
|
out.Write16(uint16(shndx))
|
2015-02-27 22:57:28 -05:00
|
|
|
Symsize += ELF32SYMSIZE
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-10-09 10:11:00 +01:00
|
|
|
var numelfsym = 1 // 0 is reserved
|
2015-02-27 22:57:28 -05:00
|
|
|
|
|
|
|
|
var elfbind int
|
|
|
|
|
|
2017-10-04 17:54:04 -04:00
|
|
|
func putelfsym(ctxt *Link, x *sym.Symbol, s string, t SymbolType, addr int64, go_ *sym.Symbol) {
|
2016-09-16 16:22:08 +12:00
|
|
|
var typ int
|
2015-02-27 22:57:28 -05:00
|
|
|
|
|
|
|
|
switch t {
|
|
|
|
|
default:
|
|
|
|
|
return
|
|
|
|
|
|
2016-09-16 16:22:08 +12:00
|
|
|
case TextSym:
|
|
|
|
|
typ = STT_FUNC
|
2015-02-27 22:57:28 -05:00
|
|
|
|
2016-09-16 16:22:08 +12:00
|
|
|
case DataSym, BSSSym:
|
|
|
|
|
typ = STT_OBJECT
|
2015-02-27 22:57:28 -05:00
|
|
|
|
2016-09-16 16:22:08 +12:00
|
|
|
case UndefinedSym:
|
2015-05-05 16:10:12 +12:00
|
|
|
// ElfType is only set for symbols read from Go shared libraries, but
|
|
|
|
|
// for other symbols it is left as STT_NOTYPE which is fine.
|
2018-07-18 10:19:35 -04:00
|
|
|
typ = int(x.ElfType())
|
2015-03-29 21:03:05 +00:00
|
|
|
|
2016-09-16 16:22:08 +12:00
|
|
|
case TLSSym:
|
|
|
|
|
typ = STT_TLS
|
2015-02-27 22:57:28 -05:00
|
|
|
}
|
|
|
|
|
|
2016-09-16 16:47:28 +12:00
|
|
|
size := x.Size
|
|
|
|
|
if t == UndefinedSym {
|
|
|
|
|
size = 0
|
|
|
|
|
}
|
|
|
|
|
|
2015-03-02 12:35:15 -05:00
|
|
|
xo := x
|
2015-02-27 22:57:28 -05:00
|
|
|
for xo.Outer != nil {
|
|
|
|
|
xo = xo.Outer
|
|
|
|
|
}
|
|
|
|
|
|
2015-03-29 21:03:05 +00:00
|
|
|
var elfshnum int
|
2017-10-04 17:54:04 -04:00
|
|
|
if xo.Type == sym.SDYNIMPORT || xo.Type == sym.SHOSTOBJ {
|
2015-03-29 21:03:05 +00:00
|
|
|
elfshnum = SHN_UNDEF
|
|
|
|
|
} else {
|
|
|
|
|
if xo.Sect == nil {
|
2016-09-17 09:39:33 -04:00
|
|
|
Errorf(x, "missing section in putelfsym")
|
2015-03-29 21:03:05 +00:00
|
|
|
return
|
|
|
|
|
}
|
2015-05-27 12:04:25 +12:00
|
|
|
if xo.Sect.Elfsect == nil {
|
2016-09-17 09:39:33 -04:00
|
|
|
Errorf(x, "missing ELF section in putelfsym")
|
2015-03-29 21:03:05 +00:00
|
|
|
return
|
|
|
|
|
}
|
2017-10-04 17:54:04 -04:00
|
|
|
elfshnum = xo.Sect.Elfsect.(*ElfShdr).shnum
|
2015-02-27 22:57:28 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// One pass for each binding: STB_LOCAL, STB_GLOBAL,
|
|
|
|
|
// maybe one day STB_WEAK.
|
2015-03-02 12:35:15 -05:00
|
|
|
bind := STB_GLOBAL
|
2015-02-27 22:57:28 -05:00
|
|
|
|
2018-10-19 17:42:11 -04:00
|
|
|
if x.IsFileLocal() || x.Attr.VisibilityHidden() || x.Attr.Local() {
|
2015-02-27 22:57:28 -05:00
|
|
|
bind = STB_LOCAL
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// In external linking mode, we have to invoke gcc with -rdynamic
|
|
|
|
|
// to get the exported symbols put into the dynamic symbol table.
|
|
|
|
|
// To avoid filling the dynamic table with lots of unnecessary symbols,
|
|
|
|
|
// mark all Go symbols local (not global) in the final executable.
|
2015-03-30 02:59:10 +00:00
|
|
|
// But when we're dynamically linking, we need all those global symbols.
|
2017-10-05 10:20:17 -04:00
|
|
|
if !ctxt.DynlinkingGo() && ctxt.LinkMode == LinkExternal && !x.Attr.CgoExportStatic() && elfshnum != SHN_UNDEF {
|
2015-02-27 22:57:28 -05:00
|
|
|
bind = STB_LOCAL
|
|
|
|
|
}
|
|
|
|
|
|
2017-10-05 10:20:17 -04:00
|
|
|
if ctxt.LinkMode == LinkExternal && elfshnum != SHN_UNDEF {
|
2015-05-27 12:04:25 +12:00
|
|
|
addr -= int64(xo.Sect.Vaddr)
|
2015-02-27 22:57:28 -05:00
|
|
|
}
|
2015-03-03 20:45:00 -05:00
|
|
|
other := STV_DEFAULT
|
2017-04-28 12:43:06 +12:00
|
|
|
if x.Attr.VisibilityHidden() {
|
|
|
|
|
// TODO(mwhudson): We only set AttrVisibilityHidden in ldelf, i.e. when
|
|
|
|
|
// internally linking. But STV_HIDDEN visibility only matters in object
|
|
|
|
|
// files and shared libraries, and as we are a long way from implementing
|
|
|
|
|
// internal linking for shared libraries and only create object files when
|
|
|
|
|
// externally linking, I don't think this makes a lot of sense.
|
2015-03-03 20:45:00 -05:00
|
|
|
other = STV_HIDDEN
|
2015-02-27 22:57:28 -05:00
|
|
|
}
|
2017-09-30 21:10:49 +00:00
|
|
|
if ctxt.Arch.Family == sys.PPC64 && typ == STT_FUNC && x.Attr.Shared() && x.Name != "runtime.duffzero" && x.Name != "runtime.duffcopy" {
|
cmd/compile, cmd/link, runtime: on ppc64x, maintain the TOC pointer in R2 when compiling PIC
The PowerPC ISA does not have a PC-relative load instruction, which poses
obvious challenges when generating position-independent code. The way the ELFv2
ABI addresses this is to specify that r2 points to a per "module" (shared
library or executable) TOC pointer. Maintaining this pointer requires
cooperation between codegen and the system linker:
* Non-leaf functions leave space on the stack at r1+24 to save the TOC pointer.
* A call to a function that *might* have to go via a PLT stub must be followed
by a nop instruction that the system linker can replace with "ld r1, 24(r1)"
to restore the TOC pointer (only when dynamically linking Go code).
* When calling a function via a function pointer, the address of the function
must be in r12, and the first couple of instructions (the "global entry
point") of the called function use this to derive the address of the TOC
for the module it is in.
* When calling a function that is implemented in the same module, the system
linker adjusts the call to skip over the instructions mentioned above (the
"local entry point"), assuming that r2 is already correctly set.
So this changeset adds the global entry point instructions, sets the metadata so
the system linker knows where the local entry point is, inserts code to save the
TOC pointer at 24(r1), adds a nop after any call not known to be local and copes
with the odd non-local code transfer in the runtime (e.g. the stuff around
jmpdefer). It does not actually compile PIC yet.
Change-Id: I7522e22bdfd2f891745a900c60254fe9e372c854
Reviewed-on: https://go-review.googlesource.com/15967
Reviewed-by: Russ Cox <rsc@golang.org>
2015-10-16 15:42:09 +13:00
|
|
|
// On ppc64 the top three bits of the st_other field indicate how
|
|
|
|
|
// many instructions separate the global and local entry points. In
|
|
|
|
|
// our case it is two instructions, indicated by the value 3.
|
2017-05-09 14:34:16 -07:00
|
|
|
// The conditions here match those in preprocess in
|
|
|
|
|
// cmd/internal/obj/ppc64/obj9.go, which is where the
|
|
|
|
|
// instructions are inserted.
|
cmd/compile, cmd/link, runtime: on ppc64x, maintain the TOC pointer in R2 when compiling PIC
The PowerPC ISA does not have a PC-relative load instruction, which poses
obvious challenges when generating position-independent code. The way the ELFv2
ABI addresses this is to specify that r2 points to a per "module" (shared
library or executable) TOC pointer. Maintaining this pointer requires
cooperation between codegen and the system linker:
* Non-leaf functions leave space on the stack at r1+24 to save the TOC pointer.
* A call to a function that *might* have to go via a PLT stub must be followed
by a nop instruction that the system linker can replace with "ld r1, 24(r1)"
to restore the TOC pointer (only when dynamically linking Go code).
* When calling a function via a function pointer, the address of the function
must be in r12, and the first couple of instructions (the "global entry
point") of the called function use this to derive the address of the TOC
for the module it is in.
* When calling a function that is implemented in the same module, the system
linker adjusts the call to skip over the instructions mentioned above (the
"local entry point"), assuming that r2 is already correctly set.
So this changeset adds the global entry point instructions, sets the metadata so
the system linker knows where the local entry point is, inserts code to save the
TOC pointer at 24(r1), adds a nop after any call not known to be local and copes
with the odd non-local code transfer in the runtime (e.g. the stuff around
jmpdefer). It does not actually compile PIC yet.
Change-Id: I7522e22bdfd2f891745a900c60254fe9e372c854
Reviewed-on: https://go-review.googlesource.com/15967
Reviewed-by: Russ Cox <rsc@golang.org>
2015-10-16 15:42:09 +13:00
|
|
|
other |= 3 << 5
|
|
|
|
|
}
|
2015-10-29 12:17:43 +13:00
|
|
|
|
2016-08-25 21:06:10 -04:00
|
|
|
// When dynamically linking, we create Symbols by reading the names from
|
|
|
|
|
// the symbol tables of the shared libraries and so the names need to
|
|
|
|
|
// match exactly. Tools like DTrace will have to wait for now.
|
|
|
|
|
if !ctxt.DynlinkingGo() {
|
|
|
|
|
// Rewrite · to . for ASCII-only tools like DTrace (sigh)
|
|
|
|
|
s = strings.Replace(s, "·", ".", -1)
|
|
|
|
|
}
|
|
|
|
|
|
2017-10-04 17:54:04 -04:00
|
|
|
if ctxt.DynlinkingGo() && bind == STB_GLOBAL && elfbind == STB_LOCAL && x.Type == sym.STEXT {
|
2015-10-29 12:17:43 +13:00
|
|
|
// When dynamically linking, we want references to functions defined
|
|
|
|
|
// in this module to always be to the function object, not to the
|
|
|
|
|
// PLT. We force this by writing an additional local symbol for every
|
|
|
|
|
// global function symbol and making all relocations against the
|
|
|
|
|
// global symbol refer to this local symbol instead (see
|
2017-10-04 17:54:04 -04:00
|
|
|
// (*sym.Symbol).ElfsymForReloc). This is approximately equivalent to the
|
2015-10-29 12:17:43 +13:00
|
|
|
// ELF linker -Bsymbolic-functions option, but that is buggy on
|
|
|
|
|
// several platforms.
|
2017-10-01 02:37:20 +00:00
|
|
|
putelfsyment(ctxt.Out, putelfstr("local."+s), addr, size, STB_LOCAL<<4|typ&0xf, elfshnum, other)
|
2015-10-29 12:17:43 +13:00
|
|
|
x.LocalElfsym = int32(numelfsym)
|
|
|
|
|
numelfsym++
|
2015-11-03 09:36:53 +13:00
|
|
|
return
|
2015-10-29 12:17:43 +13:00
|
|
|
} else if bind != elfbind {
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
2017-10-01 02:37:20 +00:00
|
|
|
putelfsyment(ctxt.Out, putelfstr(s), addr, size, bind<<4|typ&0xf, elfshnum, other)
|
2015-02-27 22:57:28 -05:00
|
|
|
x.Elfsym = int32(numelfsym)
|
|
|
|
|
numelfsym++
|
|
|
|
|
}
|
|
|
|
|
|
2017-10-04 17:54:04 -04:00
|
|
|
func putelfsectionsym(out *OutBuf, s *sym.Symbol, shndx int) {
|
2017-10-01 02:37:20 +00:00
|
|
|
putelfsyment(out, 0, 0, 0, STB_LOCAL<<4|STT_SECTION, shndx, 0)
|
2015-02-27 22:57:28 -05:00
|
|
|
s.Elfsym = int32(numelfsym)
|
|
|
|
|
numelfsym++
|
|
|
|
|
}
|
|
|
|
|
|
2016-08-19 22:40:38 -04:00
|
|
|
func Asmelfsym(ctxt *Link) {
|
2015-02-27 22:57:28 -05:00
|
|
|
// the first symbol entry is reserved
|
2017-10-01 02:37:20 +00:00
|
|
|
putelfsyment(ctxt.Out, 0, 0, 0, STB_LOCAL<<4|STT_NOTYPE, 0, 0)
|
2015-02-27 22:57:28 -05:00
|
|
|
|
2016-08-19 22:40:38 -04:00
|
|
|
dwarfaddelfsectionsyms(ctxt)
|
2015-02-27 22:57:28 -05:00
|
|
|
|
2016-02-08 17:20:59 -08:00
|
|
|
// Some linkers will add a FILE sym if one is not present.
|
|
|
|
|
// Avoid having the working directory inserted into the symbol table.
|
2016-04-07 15:26:57 -07:00
|
|
|
// It is added with a name to avoid problems with external linking
|
|
|
|
|
// encountered on some versions of Solaris. See issue #14957.
|
2017-10-01 02:37:20 +00:00
|
|
|
putelfsyment(ctxt.Out, putelfstr("go.go"), 0, 0, STB_LOCAL<<4|STT_FILE, SHN_ABS, 0)
|
2016-02-08 17:20:59 -08:00
|
|
|
numelfsym++
|
|
|
|
|
|
2015-02-27 22:57:28 -05:00
|
|
|
elfbind = STB_LOCAL
|
2016-08-19 22:40:38 -04:00
|
|
|
genasmsym(ctxt, putelfsym)
|
2015-02-27 22:57:28 -05:00
|
|
|
|
|
|
|
|
elfbind = STB_GLOBAL
|
|
|
|
|
elfglobalsymndx = numelfsym
|
2016-08-19 22:40:38 -04:00
|
|
|
genasmsym(ctxt, putelfsym)
|
2015-02-27 22:57:28 -05:00
|
|
|
}
|
|
|
|
|
|
2017-10-04 17:54:04 -04:00
|
|
|
func putplan9sym(ctxt *Link, x *sym.Symbol, s string, typ SymbolType, addr int64, go_ *sym.Symbol) {
|
2016-09-16 16:22:08 +12:00
|
|
|
t := int(typ)
|
|
|
|
|
switch typ {
|
|
|
|
|
case TextSym, DataSym, BSSSym:
|
2018-10-19 17:42:11 -04:00
|
|
|
if x.IsFileLocal() {
|
2015-02-27 22:57:28 -05:00
|
|
|
t += 'a' - 'A'
|
|
|
|
|
}
|
|
|
|
|
fallthrough
|
|
|
|
|
|
2017-08-28 17:49:37 -07:00
|
|
|
case AutoSym, ParamSym, FrameSym:
|
2015-03-02 12:35:15 -05:00
|
|
|
l := 4
|
2017-10-07 13:49:44 -04:00
|
|
|
if ctxt.HeadType == objabi.Hplan9 && ctxt.Arch.Family == sys.AMD64 && !Flag8 {
|
2017-10-01 02:37:20 +00:00
|
|
|
ctxt.Out.Write32b(uint32(addr >> 32))
|
2015-02-27 22:57:28 -05:00
|
|
|
l = 8
|
|
|
|
|
}
|
|
|
|
|
|
2017-10-01 02:37:20 +00:00
|
|
|
ctxt.Out.Write32b(uint32(addr))
|
|
|
|
|
ctxt.Out.Write8(uint8(t + 0x80)) /* 0x80 is variable length */
|
2015-02-27 22:57:28 -05:00
|
|
|
|
2017-10-01 02:37:20 +00:00
|
|
|
ctxt.Out.WriteString(s)
|
|
|
|
|
ctxt.Out.Write8(0)
|
2015-02-27 22:57:28 -05:00
|
|
|
|
2017-09-15 11:38:24 -07:00
|
|
|
Symsize += int32(l) + 1 + int32(len(s)) + 1
|
2015-02-27 22:57:28 -05:00
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-08-19 22:40:38 -04:00
|
|
|
func Asmplan9sym(ctxt *Link) {
|
|
|
|
|
genasmsym(ctxt, putplan9sym)
|
2015-02-27 22:57:28 -05:00
|
|
|
}
|
|
|
|
|
|
2017-10-04 17:54:04 -04:00
|
|
|
var symt *sym.Symbol
|
2015-02-27 22:57:28 -05:00
|
|
|
|
2017-10-04 18:13:35 -04:00
|
|
|
type byPkg []*sym.Library
|
2015-04-11 12:05:21 +08:00
|
|
|
|
|
|
|
|
func (libs byPkg) Len() int {
|
|
|
|
|
return len(libs)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (libs byPkg) Less(a, b int) bool {
|
|
|
|
|
return libs[a].Pkg < libs[b].Pkg
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (libs byPkg) Swap(a, b int) {
|
|
|
|
|
libs[a], libs[b] = libs[b], libs[a]
|
|
|
|
|
}
|
|
|
|
|
|
2016-08-25 11:07:33 -05:00
|
|
|
// Create a table with information on the text sections.
|
|
|
|
|
|
|
|
|
|
func textsectionmap(ctxt *Link) uint32 {
|
|
|
|
|
|
|
|
|
|
t := ctxt.Syms.Lookup("runtime.textsectionmap", 0)
|
2017-10-04 17:54:04 -04:00
|
|
|
t.Type = sym.SRODATA
|
|
|
|
|
t.Attr |= sym.AttrReachable
|
2016-08-25 11:07:33 -05:00
|
|
|
nsections := int64(0)
|
|
|
|
|
|
2017-04-18 21:52:06 +12:00
|
|
|
for _, sect := range Segtext.Sections {
|
2016-08-25 11:07:33 -05:00
|
|
|
if sect.Name == ".text" {
|
|
|
|
|
nsections++
|
|
|
|
|
} else {
|
|
|
|
|
break
|
|
|
|
|
}
|
|
|
|
|
}
|
2017-09-30 15:06:44 +00:00
|
|
|
t.Grow(3 * nsections * int64(ctxt.Arch.PtrSize))
|
2016-08-25 11:07:33 -05:00
|
|
|
|
|
|
|
|
off := int64(0)
|
|
|
|
|
n := 0
|
|
|
|
|
|
|
|
|
|
// The vaddr for each text section is the difference between the section's
|
|
|
|
|
// Vaddr and the Vaddr for the first text section as determined at compile
|
|
|
|
|
// time.
|
|
|
|
|
|
|
|
|
|
// The symbol for the first text section is named runtime.text as before.
|
|
|
|
|
// Additional text sections are named runtime.text.n where n is the
|
|
|
|
|
// order of creation starting with 1. These symbols provide the section's
|
|
|
|
|
// address after relocation by the linker.
|
|
|
|
|
|
2017-04-18 21:52:06 +12:00
|
|
|
textbase := Segtext.Sections[0].Vaddr
|
|
|
|
|
for _, sect := range Segtext.Sections {
|
2016-08-25 11:07:33 -05:00
|
|
|
if sect.Name != ".text" {
|
|
|
|
|
break
|
|
|
|
|
}
|
2017-09-30 15:06:44 +00:00
|
|
|
off = t.SetUint(ctxt.Arch, off, sect.Vaddr-textbase)
|
|
|
|
|
off = t.SetUint(ctxt.Arch, off, sect.Length)
|
2016-08-25 11:07:33 -05:00
|
|
|
if n == 0 {
|
|
|
|
|
s := ctxt.Syms.ROLookup("runtime.text", 0)
|
|
|
|
|
if s == nil {
|
|
|
|
|
Errorf(nil, "Unable to find symbol runtime.text\n")
|
|
|
|
|
}
|
2017-09-30 15:06:44 +00:00
|
|
|
off = t.SetAddr(ctxt.Arch, off, s)
|
2016-08-25 11:07:33 -05:00
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
s := ctxt.Syms.Lookup(fmt.Sprintf("runtime.text.%d", n), 0)
|
|
|
|
|
if s == nil {
|
|
|
|
|
Errorf(nil, "Unable to find symbol runtime.text.%d\n", n)
|
|
|
|
|
}
|
2017-09-30 15:06:44 +00:00
|
|
|
off = t.SetAddr(ctxt.Arch, off, s)
|
2016-08-25 11:07:33 -05:00
|
|
|
}
|
|
|
|
|
n++
|
|
|
|
|
}
|
|
|
|
|
return uint32(n)
|
|
|
|
|
}
|
|
|
|
|
|
2016-08-19 22:40:38 -04:00
|
|
|
func (ctxt *Link) symtab() {
|
2019-04-13 16:46:23 +03:00
|
|
|
switch ctxt.BuildMode {
|
|
|
|
|
case BuildModeCArchive, BuildModeCShared:
|
|
|
|
|
for _, s := range ctxt.Syms.Allsym {
|
|
|
|
|
// Create a new entry in the .init_array section that points to the
|
|
|
|
|
// library initializer function.
|
|
|
|
|
if s.Name == *flagEntrySymbol && ctxt.HeadType != objabi.Haix {
|
|
|
|
|
addinitarrdata(ctxt, s)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2015-02-27 22:57:28 -05:00
|
|
|
|
|
|
|
|
// Define these so that they'll get put into the symbol table.
|
|
|
|
|
// data.c:/^address will provide the actual values.
|
2017-10-04 17:54:04 -04:00
|
|
|
ctxt.xdefine("runtime.text", sym.STEXT, 0)
|
|
|
|
|
|
|
|
|
|
ctxt.xdefine("runtime.etext", sym.STEXT, 0)
|
|
|
|
|
ctxt.xdefine("runtime.itablink", sym.SRODATA, 0)
|
|
|
|
|
ctxt.xdefine("runtime.eitablink", sym.SRODATA, 0)
|
|
|
|
|
ctxt.xdefine("runtime.rodata", sym.SRODATA, 0)
|
|
|
|
|
ctxt.xdefine("runtime.erodata", sym.SRODATA, 0)
|
|
|
|
|
ctxt.xdefine("runtime.types", sym.SRODATA, 0)
|
|
|
|
|
ctxt.xdefine("runtime.etypes", sym.SRODATA, 0)
|
|
|
|
|
ctxt.xdefine("runtime.noptrdata", sym.SNOPTRDATA, 0)
|
|
|
|
|
ctxt.xdefine("runtime.enoptrdata", sym.SNOPTRDATA, 0)
|
|
|
|
|
ctxt.xdefine("runtime.data", sym.SDATA, 0)
|
|
|
|
|
ctxt.xdefine("runtime.edata", sym.SDATA, 0)
|
|
|
|
|
ctxt.xdefine("runtime.bss", sym.SBSS, 0)
|
|
|
|
|
ctxt.xdefine("runtime.ebss", sym.SBSS, 0)
|
|
|
|
|
ctxt.xdefine("runtime.noptrbss", sym.SNOPTRBSS, 0)
|
|
|
|
|
ctxt.xdefine("runtime.enoptrbss", sym.SNOPTRBSS, 0)
|
|
|
|
|
ctxt.xdefine("runtime.end", sym.SBSS, 0)
|
|
|
|
|
ctxt.xdefine("runtime.epclntab", sym.SRODATA, 0)
|
|
|
|
|
ctxt.xdefine("runtime.esymtab", sym.SRODATA, 0)
|
2015-02-27 22:57:28 -05:00
|
|
|
|
|
|
|
|
// garbage collection symbols
|
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
|
|
|
s := ctxt.Syms.Lookup("runtime.gcdata", 0)
|
2015-02-27 22:57:28 -05:00
|
|
|
|
2017-10-04 17:54:04 -04:00
|
|
|
s.Type = sym.SRODATA
|
2015-02-27 22:57:28 -05:00
|
|
|
s.Size = 0
|
2017-10-04 17:54:04 -04:00
|
|
|
s.Attr |= sym.AttrReachable
|
|
|
|
|
ctxt.xdefine("runtime.egcdata", sym.SRODATA, 0)
|
2015-02-27 22:57:28 -05:00
|
|
|
|
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
|
|
|
s = ctxt.Syms.Lookup("runtime.gcbss", 0)
|
2017-10-04 17:54:04 -04:00
|
|
|
s.Type = sym.SRODATA
|
2015-02-27 22:57:28 -05:00
|
|
|
s.Size = 0
|
2017-10-04 17:54:04 -04:00
|
|
|
s.Attr |= sym.AttrReachable
|
|
|
|
|
ctxt.xdefine("runtime.egcbss", sym.SRODATA, 0)
|
2015-02-27 22:57:28 -05:00
|
|
|
|
|
|
|
|
// pseudo-symbols to mark locations of type, string, and go string data.
|
2017-10-04 17:54:04 -04:00
|
|
|
var symtype *sym.Symbol
|
|
|
|
|
var symtyperel *sym.Symbol
|
2018-06-21 10:31:57 +12:00
|
|
|
if !ctxt.DynlinkingGo() {
|
|
|
|
|
if ctxt.UseRelro() && (ctxt.BuildMode == BuildModeCArchive || ctxt.BuildMode == BuildModeCShared || ctxt.BuildMode == BuildModePIE) {
|
|
|
|
|
s = ctxt.Syms.Lookup("type.*", 0)
|
2015-05-21 13:07:19 +12:00
|
|
|
|
2018-06-21 10:31:57 +12:00
|
|
|
s.Type = sym.STYPE
|
|
|
|
|
s.Size = 0
|
|
|
|
|
s.Attr |= sym.AttrReachable
|
|
|
|
|
symtype = s
|
2015-05-21 13:07:19 +12:00
|
|
|
|
2018-06-21 10:31:57 +12:00
|
|
|
s = ctxt.Syms.Lookup("typerel.*", 0)
|
2015-05-21 13:07:19 +12:00
|
|
|
|
2018-06-21 10:31:57 +12:00
|
|
|
s.Type = sym.STYPERELRO
|
|
|
|
|
s.Size = 0
|
|
|
|
|
s.Attr |= sym.AttrReachable
|
|
|
|
|
symtyperel = s
|
|
|
|
|
} else {
|
|
|
|
|
s = ctxt.Syms.Lookup("type.*", 0)
|
2015-03-30 02:59:10 +00:00
|
|
|
|
2018-06-21 10:31:57 +12:00
|
|
|
s.Type = sym.STYPE
|
|
|
|
|
s.Size = 0
|
|
|
|
|
s.Attr |= sym.AttrReachable
|
|
|
|
|
symtype = s
|
|
|
|
|
symtyperel = s
|
|
|
|
|
}
|
2015-03-30 02:59:10 +00:00
|
|
|
}
|
2015-02-27 22:57:28 -05:00
|
|
|
|
2017-10-04 17:54:04 -04:00
|
|
|
groupSym := func(name string, t sym.SymKind) *sym.Symbol {
|
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
|
|
|
s := ctxt.Syms.Lookup(name, 0)
|
2016-04-13 10:06:12 -04:00
|
|
|
s.Type = t
|
|
|
|
|
s.Size = 0
|
2017-10-04 17:54:04 -04:00
|
|
|
s.Attr |= sym.AttrLocal | sym.AttrReachable
|
2016-04-13 10:06:12 -04:00
|
|
|
return s
|
|
|
|
|
}
|
|
|
|
|
var (
|
2017-10-04 17:54:04 -04:00
|
|
|
symgostring = groupSym("go.string.*", sym.SGOSTRING)
|
|
|
|
|
symgofunc = groupSym("go.func.*", sym.SGOFUNC)
|
|
|
|
|
symgcbits = groupSym("runtime.gcbits.*", sym.SGCBITS)
|
2016-04-13 10:06:12 -04:00
|
|
|
)
|
2015-07-22 14:59:56 -04:00
|
|
|
|
2017-10-04 17:54:04 -04:00
|
|
|
var symgofuncrel *sym.Symbol
|
2016-08-25 21:06:10 -04:00
|
|
|
if !ctxt.DynlinkingGo() {
|
2017-10-05 10:20:17 -04:00
|
|
|
if ctxt.UseRelro() {
|
2017-10-04 17:54:04 -04:00
|
|
|
symgofuncrel = groupSym("go.funcrel.*", sym.SGOFUNCRELRO)
|
2016-08-26 12:15:00 +12:00
|
|
|
} else {
|
|
|
|
|
symgofuncrel = symgofunc
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
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
|
|
|
symitablink := ctxt.Syms.Lookup("runtime.itablink", 0)
|
2017-10-04 17:54:04 -04:00
|
|
|
symitablink.Type = sym.SITABLINK
|
2016-03-17 07:00:33 -07:00
|
|
|
|
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
|
|
|
symt = ctxt.Syms.Lookup("runtime.symtab", 0)
|
2017-10-04 17:54:04 -04:00
|
|
|
symt.Attr |= sym.AttrLocal
|
|
|
|
|
symt.Type = sym.SSYMTAB
|
2015-02-27 22:57:28 -05:00
|
|
|
symt.Size = 0
|
2017-10-04 17:54:04 -04:00
|
|
|
symt.Attr |= sym.AttrReachable
|
2015-02-27 22:57:28 -05:00
|
|
|
|
2016-03-17 07:00:33 -07:00
|
|
|
nitablinks := 0
|
2015-03-16 11:53:08 +13:00
|
|
|
|
2015-02-27 22:57:28 -05:00
|
|
|
// assign specific types so that they sort together.
|
|
|
|
|
// within a type they sort by size, so the .* symbols
|
|
|
|
|
// just defined above will be first.
|
|
|
|
|
// hide the specific symbols.
|
2016-09-20 14:59:39 +12:00
|
|
|
for _, s := range ctxt.Syms.Allsym {
|
2018-10-17 09:36:06 +02:00
|
|
|
if ctxt.LinkMode != LinkExternal && isStaticTemp(s.Name) {
|
|
|
|
|
s.Attr |= sym.AttrNotInSymbolTable
|
|
|
|
|
}
|
|
|
|
|
|
2017-10-04 17:54:04 -04:00
|
|
|
if !s.Attr.Reachable() || s.Attr.Special() || s.Type != sym.SRODATA {
|
2015-04-11 14:04:17 +12:00
|
|
|
continue
|
|
|
|
|
}
|
|
|
|
|
|
2016-04-13 10:06:12 -04:00
|
|
|
switch {
|
|
|
|
|
case strings.HasPrefix(s.Name, "type."):
|
2016-08-25 21:06:10 -04:00
|
|
|
if !ctxt.DynlinkingGo() {
|
2017-10-04 17:54:04 -04:00
|
|
|
s.Attr |= sym.AttrNotInSymbolTable
|
2016-04-01 10:55:21 -04:00
|
|
|
}
|
2017-10-05 10:20:17 -04:00
|
|
|
if ctxt.UseRelro() {
|
2017-10-04 17:54:04 -04:00
|
|
|
s.Type = sym.STYPERELRO
|
2015-05-21 13:07:19 +12:00
|
|
|
s.Outer = symtyperel
|
|
|
|
|
} else {
|
2017-10-04 17:54:04 -04:00
|
|
|
s.Type = sym.STYPE
|
2015-05-21 13:07:19 +12:00
|
|
|
s.Outer = symtype
|
|
|
|
|
}
|
2015-02-27 22:57:28 -05:00
|
|
|
|
2017-10-05 10:20:17 -04:00
|
|
|
case strings.HasPrefix(s.Name, "go.importpath.") && ctxt.UseRelro():
|
2016-04-07 21:37:45 -04:00
|
|
|
// Keep go.importpath symbols in the same section as types and
|
|
|
|
|
// names, as they can be referred to by a section offset.
|
2017-10-04 17:54:04 -04:00
|
|
|
s.Type = sym.STYPERELRO
|
2016-04-07 21:37:45 -04:00
|
|
|
|
2016-04-13 10:06:12 -04:00
|
|
|
case strings.HasPrefix(s.Name, "go.itablink."):
|
2016-03-17 07:00:33 -07:00
|
|
|
nitablinks++
|
2017-10-04 17:54:04 -04:00
|
|
|
s.Type = sym.SITABLINK
|
|
|
|
|
s.Attr |= sym.AttrNotInSymbolTable
|
2016-03-17 07:00:33 -07:00
|
|
|
s.Outer = symitablink
|
|
|
|
|
|
2016-04-13 10:06:12 -04:00
|
|
|
case strings.HasPrefix(s.Name, "go.string."):
|
2017-10-04 17:54:04 -04:00
|
|
|
s.Type = sym.SGOSTRING
|
|
|
|
|
s.Attr |= sym.AttrNotInSymbolTable
|
2015-02-27 22:57:28 -05:00
|
|
|
s.Outer = symgostring
|
|
|
|
|
|
2016-04-13 10:06:12 -04:00
|
|
|
case strings.HasPrefix(s.Name, "runtime.gcbits."):
|
2017-10-04 17:54:04 -04:00
|
|
|
s.Type = sym.SGCBITS
|
|
|
|
|
s.Attr |= sym.AttrNotInSymbolTable
|
2015-07-22 14:59:56 -04:00
|
|
|
s.Outer = symgcbits
|
|
|
|
|
|
2016-08-26 12:15:00 +12:00
|
|
|
case strings.HasSuffix(s.Name, "·f"):
|
2016-08-25 21:06:10 -04:00
|
|
|
if !ctxt.DynlinkingGo() {
|
2017-10-04 17:54:04 -04:00
|
|
|
s.Attr |= sym.AttrNotInSymbolTable
|
2016-08-26 12:15:00 +12:00
|
|
|
}
|
2017-10-05 10:20:17 -04:00
|
|
|
if ctxt.UseRelro() {
|
2017-10-04 17:54:04 -04:00
|
|
|
s.Type = sym.SGOFUNCRELRO
|
2016-08-26 12:15:00 +12:00
|
|
|
s.Outer = symgofuncrel
|
|
|
|
|
} else {
|
2017-10-04 17:54:04 -04:00
|
|
|
s.Type = sym.SGOFUNC
|
2016-08-26 12:15:00 +12:00
|
|
|
s.Outer = symgofunc
|
|
|
|
|
}
|
2015-02-27 22:57:28 -05:00
|
|
|
|
cmd/compile,link: generate PC-value tables with inlining information
In order to generate accurate tracebacks, the runtime needs to know the
inlined call stack for a given PC. This creates two tables per function
for this purpose. The first table is the inlining tree (stored in the
function's funcdata), which has a node containing the file, line, and
function name for every inlined call. The second table is a PC-value
table that maps each PC to a node in the inlining tree (or -1 if the PC
is not the result of inlining).
To give the appearance that inlining hasn't happened, the runtime also
needs the original source position information of inlined AST nodes.
Previously the compiler plastered over the line numbers of inlined AST
nodes with the line number of the call. This meant that the PC-line
table mapped each PC to line number of the outermost call in its inlined
call stack, with no way to access the innermost line number.
Now the compiler retains line numbers of inlined AST nodes and writes
the innermost source position information to the PC-line and PC-file
tables. Some tools and tests expect to see outermost line numbers, so we
provide the OutermostLine function for displaying line info.
To keep track of the inlined call stack for an AST node, we extend the
src.PosBase type with an index into a global inlining tree. Every time
the compiler inlines a call, it creates a node in the global inlining
tree for the call, and writes its index to the PosBase of every inlined
AST node. The parent of this node is the inlining tree index of the
call. -1 signifies no parent.
For each function, the compiler creates a local inlining tree and a
PC-value table mapping each PC to an index in the local tree. These are
written to an object file, which is read by the linker. The linker
re-encodes these tables compactly by deduplicating function names and
file names.
This change increases the size of binaries by 4-5%. For example, this is
how the go1 benchmark binary is impacted by this change:
section old bytes new bytes delta
.text 3.49M ± 0% 3.49M ± 0% +0.06%
.rodata 1.12M ± 0% 1.21M ± 0% +8.21%
.gopclntab 1.50M ± 0% 1.68M ± 0% +11.89%
.debug_line 338k ± 0% 435k ± 0% +28.78%
Total 9.21M ± 0% 9.58M ± 0% +4.01%
Updates #19348.
Change-Id: Ic4f180c3b516018138236b0c35e0218270d957d3
Reviewed-on: https://go-review.googlesource.com/37231
Run-TryBot: David Lazar <lazard@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Austin Clements <austin@google.com>
2017-02-17 12:28:05 -05:00
|
|
|
case strings.HasPrefix(s.Name, "gcargs."),
|
|
|
|
|
strings.HasPrefix(s.Name, "gclocals."),
|
|
|
|
|
strings.HasPrefix(s.Name, "gclocals·"),
|
|
|
|
|
strings.HasPrefix(s.Name, "inltree."):
|
2017-10-04 17:54:04 -04:00
|
|
|
s.Type = sym.SGOFUNC
|
|
|
|
|
s.Attr |= sym.AttrNotInSymbolTable
|
2015-02-27 22:57:28 -05:00
|
|
|
s.Outer = symgofunc
|
|
|
|
|
s.Align = 4
|
|
|
|
|
liveness += (s.Size + int64(s.Align) - 1) &^ (int64(s.Align) - 1)
|
|
|
|
|
}
|
|
|
|
|
}
|
2015-03-12 12:22:18 +13:00
|
|
|
|
2017-10-05 10:20:17 -04:00
|
|
|
if ctxt.BuildMode == BuildModeShared {
|
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
|
|
|
abihashgostr := ctxt.Syms.Lookup("go.link.abihash."+filepath.Base(*flagOutfile), 0)
|
2017-10-04 17:54:04 -04:00
|
|
|
abihashgostr.Attr |= sym.AttrReachable
|
|
|
|
|
abihashgostr.Type = sym.SRODATA
|
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
|
|
|
hashsym := ctxt.Syms.Lookup("go.link.abihashbytes", 0)
|
2017-09-30 15:06:44 +00:00
|
|
|
abihashgostr.AddAddr(ctxt.Arch, hashsym)
|
|
|
|
|
abihashgostr.AddUint(ctxt.Arch, uint64(hashsym.Size))
|
2015-04-11 12:05:21 +08:00
|
|
|
}
|
2018-11-01 12:30:23 -04:00
|
|
|
if ctxt.BuildMode == BuildModePlugin || ctxt.CanUsePlugins() {
|
2016-11-12 06:24:36 -05:00
|
|
|
for _, l := range ctxt.Library {
|
|
|
|
|
s := ctxt.Syms.Lookup("go.link.pkghashbytes."+l.Pkg, 0)
|
2017-10-04 17:54:04 -04:00
|
|
|
s.Attr |= sym.AttrReachable
|
|
|
|
|
s.Type = sym.SRODATA
|
2017-10-04 18:13:35 -04:00
|
|
|
s.Size = int64(len(l.Hash))
|
|
|
|
|
s.P = []byte(l.Hash)
|
2016-11-12 06:24:36 -05:00
|
|
|
str := ctxt.Syms.Lookup("go.link.pkghash."+l.Pkg, 0)
|
2017-10-04 17:54:04 -04:00
|
|
|
str.Attr |= sym.AttrReachable
|
|
|
|
|
str.Type = sym.SRODATA
|
2017-09-30 15:06:44 +00:00
|
|
|
str.AddAddr(ctxt.Arch, s)
|
2017-10-04 18:13:35 -04:00
|
|
|
str.AddUint(ctxt.Arch, uint64(len(l.Hash)))
|
2016-11-12 06:24:36 -05:00
|
|
|
}
|
|
|
|
|
}
|
2015-04-11 12:05:21 +08:00
|
|
|
|
2016-08-25 11:07:33 -05:00
|
|
|
nsections := textsectionmap(ctxt)
|
|
|
|
|
|
2015-03-12 12:22:18 +13:00
|
|
|
// Information about the layout of the executable image for the
|
|
|
|
|
// runtime to use. Any changes here must be matched by changes to
|
|
|
|
|
// the definition of moduledata in runtime/symtab.go.
|
2015-03-16 11:53:08 +13:00
|
|
|
// This code uses several global variables that are set by pcln.go:pclntab.
|
2016-08-19 22:40:38 -04:00
|
|
|
moduledata := ctxt.Moduledata
|
2015-03-16 11:53:08 +13:00
|
|
|
// The pclntab slice
|
2017-09-30 15:06:44 +00:00
|
|
|
moduledata.AddAddr(ctxt.Arch, ctxt.Syms.Lookup("runtime.pclntab", 0))
|
|
|
|
|
moduledata.AddUint(ctxt.Arch, uint64(ctxt.Syms.Lookup("runtime.pclntab", 0).Size))
|
|
|
|
|
moduledata.AddUint(ctxt.Arch, uint64(ctxt.Syms.Lookup("runtime.pclntab", 0).Size))
|
2015-03-16 11:53:08 +13:00
|
|
|
// The ftab slice
|
2017-09-30 15:06:44 +00:00
|
|
|
moduledata.AddAddrPlus(ctxt.Arch, ctxt.Syms.Lookup("runtime.pclntab", 0), int64(pclntabPclntabOffset))
|
|
|
|
|
moduledata.AddUint(ctxt.Arch, uint64(pclntabNfunc+1))
|
|
|
|
|
moduledata.AddUint(ctxt.Arch, uint64(pclntabNfunc+1))
|
2015-03-16 11:53:08 +13:00
|
|
|
// The filetab slice
|
2017-09-30 15:06:44 +00:00
|
|
|
moduledata.AddAddrPlus(ctxt.Arch, ctxt.Syms.Lookup("runtime.pclntab", 0), int64(pclntabFiletabOffset))
|
|
|
|
|
moduledata.AddUint(ctxt.Arch, uint64(len(ctxt.Filesyms))+1)
|
|
|
|
|
moduledata.AddUint(ctxt.Arch, uint64(len(ctxt.Filesyms))+1)
|
2015-03-16 11:53:08 +13:00
|
|
|
// findfunctab
|
2017-09-30 15:06:44 +00:00
|
|
|
moduledata.AddAddr(ctxt.Arch, ctxt.Syms.Lookup("runtime.findfunctab", 0))
|
2015-03-16 11:53:08 +13:00
|
|
|
// minpc, maxpc
|
2017-09-30 15:06:44 +00:00
|
|
|
moduledata.AddAddr(ctxt.Arch, pclntabFirstFunc)
|
|
|
|
|
moduledata.AddAddrPlus(ctxt.Arch, pclntabLastFunc, pclntabLastFunc.Size)
|
2015-03-16 11:53:08 +13:00
|
|
|
// pointers to specific parts of the module
|
2017-09-30 15:06:44 +00:00
|
|
|
moduledata.AddAddr(ctxt.Arch, ctxt.Syms.Lookup("runtime.text", 0))
|
|
|
|
|
moduledata.AddAddr(ctxt.Arch, ctxt.Syms.Lookup("runtime.etext", 0))
|
|
|
|
|
moduledata.AddAddr(ctxt.Arch, ctxt.Syms.Lookup("runtime.noptrdata", 0))
|
|
|
|
|
moduledata.AddAddr(ctxt.Arch, ctxt.Syms.Lookup("runtime.enoptrdata", 0))
|
|
|
|
|
moduledata.AddAddr(ctxt.Arch, ctxt.Syms.Lookup("runtime.data", 0))
|
|
|
|
|
moduledata.AddAddr(ctxt.Arch, ctxt.Syms.Lookup("runtime.edata", 0))
|
|
|
|
|
moduledata.AddAddr(ctxt.Arch, ctxt.Syms.Lookup("runtime.bss", 0))
|
|
|
|
|
moduledata.AddAddr(ctxt.Arch, ctxt.Syms.Lookup("runtime.ebss", 0))
|
|
|
|
|
moduledata.AddAddr(ctxt.Arch, ctxt.Syms.Lookup("runtime.noptrbss", 0))
|
|
|
|
|
moduledata.AddAddr(ctxt.Arch, ctxt.Syms.Lookup("runtime.enoptrbss", 0))
|
|
|
|
|
moduledata.AddAddr(ctxt.Arch, ctxt.Syms.Lookup("runtime.end", 0))
|
|
|
|
|
moduledata.AddAddr(ctxt.Arch, ctxt.Syms.Lookup("runtime.gcdata", 0))
|
|
|
|
|
moduledata.AddAddr(ctxt.Arch, ctxt.Syms.Lookup("runtime.gcbss", 0))
|
|
|
|
|
moduledata.AddAddr(ctxt.Arch, ctxt.Syms.Lookup("runtime.types", 0))
|
|
|
|
|
moduledata.AddAddr(ctxt.Arch, ctxt.Syms.Lookup("runtime.etypes", 0))
|
2016-08-25 11:07:33 -05:00
|
|
|
|
2019-02-20 16:20:56 +01:00
|
|
|
if ctxt.HeadType == objabi.Haix && ctxt.LinkMode == LinkExternal {
|
|
|
|
|
// Add R_REF relocation to prevent ld's garbage collection of
|
|
|
|
|
// runtime.rodata, runtime.erodata and runtime.epclntab.
|
|
|
|
|
addRef := func(name string) {
|
|
|
|
|
r := moduledata.AddRel()
|
|
|
|
|
r.Sym = ctxt.Syms.Lookup(name, 0)
|
|
|
|
|
r.Type = objabi.R_XCOFFREF
|
|
|
|
|
r.Siz = uint8(ctxt.Arch.PtrSize)
|
|
|
|
|
}
|
|
|
|
|
addRef("runtime.rodata")
|
|
|
|
|
addRef("runtime.erodata")
|
|
|
|
|
addRef("runtime.epclntab")
|
|
|
|
|
}
|
|
|
|
|
|
2016-08-25 11:07:33 -05:00
|
|
|
// text section information
|
2017-09-30 15:06:44 +00:00
|
|
|
moduledata.AddAddr(ctxt.Arch, ctxt.Syms.Lookup("runtime.textsectionmap", 0))
|
|
|
|
|
moduledata.AddUint(ctxt.Arch, uint64(nsections))
|
|
|
|
|
moduledata.AddUint(ctxt.Arch, uint64(nsections))
|
2016-08-25 11:07:33 -05:00
|
|
|
|
2015-03-16 11:53:08 +13:00
|
|
|
// The typelinks slice
|
2016-10-19 07:33:16 +03:00
|
|
|
typelinkSym := ctxt.Syms.Lookup("runtime.typelink", 0)
|
|
|
|
|
ntypelinks := uint64(typelinkSym.Size) / 4
|
2017-09-30 15:06:44 +00:00
|
|
|
moduledata.AddAddr(ctxt.Arch, typelinkSym)
|
|
|
|
|
moduledata.AddUint(ctxt.Arch, ntypelinks)
|
|
|
|
|
moduledata.AddUint(ctxt.Arch, ntypelinks)
|
2016-03-17 07:00:33 -07:00
|
|
|
// The itablinks slice
|
2017-09-30 15:06:44 +00:00
|
|
|
moduledata.AddAddr(ctxt.Arch, ctxt.Syms.Lookup("runtime.itablink", 0))
|
|
|
|
|
moduledata.AddUint(ctxt.Arch, uint64(nitablinks))
|
|
|
|
|
moduledata.AddUint(ctxt.Arch, uint64(nitablinks))
|
2016-08-25 21:58:45 -04:00
|
|
|
// The ptab slice
|
2016-12-09 08:49:23 +13:00
|
|
|
if ptab := ctxt.Syms.ROLookup("go.plugin.tabs", 0); ptab != nil && ptab.Attr.Reachable() {
|
2017-10-04 17:54:04 -04:00
|
|
|
ptab.Attr |= sym.AttrLocal
|
|
|
|
|
ptab.Type = sym.SRODATA
|
2016-08-25 21:58:45 -04:00
|
|
|
|
|
|
|
|
nentries := uint64(len(ptab.P) / 8) // sizeof(nameOff) + sizeof(typeOff)
|
2017-09-30 15:06:44 +00:00
|
|
|
moduledata.AddAddr(ctxt.Arch, ptab)
|
|
|
|
|
moduledata.AddUint(ctxt.Arch, nentries)
|
|
|
|
|
moduledata.AddUint(ctxt.Arch, nentries)
|
2016-08-25 21:58:45 -04:00
|
|
|
} else {
|
2017-09-30 15:06:44 +00:00
|
|
|
moduledata.AddUint(ctxt.Arch, 0)
|
|
|
|
|
moduledata.AddUint(ctxt.Arch, 0)
|
|
|
|
|
moduledata.AddUint(ctxt.Arch, 0)
|
2016-08-25 21:58:45 -04:00
|
|
|
}
|
2017-10-05 10:20:17 -04:00
|
|
|
if ctxt.BuildMode == BuildModePlugin {
|
2017-10-21 07:29:46 -04:00
|
|
|
addgostring(ctxt, moduledata, "go.link.thispluginpath", objabi.PathToPrefix(*flagPluginPath))
|
2016-11-12 06:24:36 -05:00
|
|
|
|
|
|
|
|
pkghashes := ctxt.Syms.Lookup("go.link.pkghashes", 0)
|
2017-10-04 17:54:04 -04:00
|
|
|
pkghashes.Attr |= sym.AttrReachable
|
|
|
|
|
pkghashes.Attr |= sym.AttrLocal
|
|
|
|
|
pkghashes.Type = sym.SRODATA
|
2016-11-12 06:24:36 -05:00
|
|
|
|
|
|
|
|
for i, l := range ctxt.Library {
|
|
|
|
|
// pkghashes[i].name
|
|
|
|
|
addgostring(ctxt, pkghashes, fmt.Sprintf("go.link.pkgname.%d", i), l.Pkg)
|
|
|
|
|
// pkghashes[i].linktimehash
|
2017-10-09 10:11:00 +01:00
|
|
|
addgostring(ctxt, pkghashes, fmt.Sprintf("go.link.pkglinkhash.%d", i), l.Hash)
|
2016-11-12 06:24:36 -05:00
|
|
|
// pkghashes[i].runtimehash
|
|
|
|
|
hash := ctxt.Syms.ROLookup("go.link.pkghash."+l.Pkg, 0)
|
2017-09-30 15:06:44 +00:00
|
|
|
pkghashes.AddAddr(ctxt.Arch, hash)
|
2016-11-12 06:24:36 -05:00
|
|
|
}
|
2017-09-30 15:06:44 +00:00
|
|
|
moduledata.AddAddr(ctxt.Arch, pkghashes)
|
|
|
|
|
moduledata.AddUint(ctxt.Arch, uint64(len(ctxt.Library)))
|
|
|
|
|
moduledata.AddUint(ctxt.Arch, uint64(len(ctxt.Library)))
|
2016-10-30 15:31:21 -04:00
|
|
|
} else {
|
2017-09-30 15:06:44 +00:00
|
|
|
moduledata.AddUint(ctxt.Arch, 0) // pluginpath
|
|
|
|
|
moduledata.AddUint(ctxt.Arch, 0)
|
|
|
|
|
moduledata.AddUint(ctxt.Arch, 0) // pkghashes slice
|
|
|
|
|
moduledata.AddUint(ctxt.Arch, 0)
|
|
|
|
|
moduledata.AddUint(ctxt.Arch, 0)
|
2016-10-30 15:31:21 -04:00
|
|
|
}
|
2016-08-19 22:40:38 -04:00
|
|
|
if len(ctxt.Shlibs) > 0 {
|
2016-08-21 18:34:24 -04:00
|
|
|
thismodulename := filepath.Base(*flagOutfile)
|
2017-10-05 10:20:17 -04:00
|
|
|
switch ctxt.BuildMode {
|
|
|
|
|
case BuildModeExe, BuildModePIE:
|
2015-04-11 12:05:21 +08:00
|
|
|
// When linking an executable, outfile is just "a.out". Make
|
|
|
|
|
// it something slightly more comprehensible.
|
|
|
|
|
thismodulename = "the executable"
|
|
|
|
|
}
|
2016-08-19 22:40:38 -04:00
|
|
|
addgostring(ctxt, moduledata, "go.link.thismodulename", thismodulename)
|
2015-04-11 12:05:21 +08:00
|
|
|
|
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
|
|
|
modulehashes := ctxt.Syms.Lookup("go.link.abihashes", 0)
|
2017-10-04 17:54:04 -04:00
|
|
|
modulehashes.Attr |= sym.AttrReachable
|
|
|
|
|
modulehashes.Attr |= sym.AttrLocal
|
|
|
|
|
modulehashes.Type = sym.SRODATA
|
2015-04-11 12:05:21 +08:00
|
|
|
|
2016-08-19 22:40:38 -04:00
|
|
|
for i, shlib := range ctxt.Shlibs {
|
2015-04-11 12:05:21 +08:00
|
|
|
// modulehashes[i].modulename
|
|
|
|
|
modulename := filepath.Base(shlib.Path)
|
2016-08-19 22:40:38 -04:00
|
|
|
addgostring(ctxt, modulehashes, fmt.Sprintf("go.link.libname.%d", i), modulename)
|
2015-04-11 12:05:21 +08:00
|
|
|
|
|
|
|
|
// modulehashes[i].linktimehash
|
2016-08-19 22:40:38 -04:00
|
|
|
addgostring(ctxt, modulehashes, fmt.Sprintf("go.link.linkhash.%d", i), string(shlib.Hash))
|
2015-04-11 12:05:21 +08:00
|
|
|
|
|
|
|
|
// modulehashes[i].runtimehash
|
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
|
|
|
abihash := ctxt.Syms.Lookup("go.link.abihash."+modulename, 0)
|
2017-10-04 17:54:04 -04:00
|
|
|
abihash.Attr |= sym.AttrReachable
|
2017-09-30 15:06:44 +00:00
|
|
|
modulehashes.AddAddr(ctxt.Arch, abihash)
|
2015-04-11 12:05:21 +08:00
|
|
|
}
|
|
|
|
|
|
2017-09-30 15:06:44 +00:00
|
|
|
moduledata.AddAddr(ctxt.Arch, modulehashes)
|
|
|
|
|
moduledata.AddUint(ctxt.Arch, uint64(len(ctxt.Shlibs)))
|
|
|
|
|
moduledata.AddUint(ctxt.Arch, uint64(len(ctxt.Shlibs)))
|
2017-10-13 12:41:09 -04:00
|
|
|
} else {
|
|
|
|
|
moduledata.AddUint(ctxt.Arch, 0) // modulename
|
|
|
|
|
moduledata.AddUint(ctxt.Arch, 0)
|
|
|
|
|
moduledata.AddUint(ctxt.Arch, 0) // moduleshashes slice
|
|
|
|
|
moduledata.AddUint(ctxt.Arch, 0)
|
|
|
|
|
moduledata.AddUint(ctxt.Arch, 0)
|
2015-04-11 12:05:21 +08:00
|
|
|
}
|
2016-03-18 16:57:54 -04:00
|
|
|
|
2017-10-09 16:04:44 -04:00
|
|
|
hasmain := ctxt.BuildMode == BuildModeExe || ctxt.BuildMode == BuildModePIE
|
|
|
|
|
if hasmain {
|
|
|
|
|
moduledata.AddUint8(1)
|
|
|
|
|
} else {
|
|
|
|
|
moduledata.AddUint8(0)
|
|
|
|
|
}
|
|
|
|
|
|
2015-03-29 21:59:00 +00:00
|
|
|
// The rest of moduledata is zero initialized.
|
2015-04-07 14:51:29 +12:00
|
|
|
// When linking an object that does not contain the runtime we are
|
|
|
|
|
// creating the moduledata from scratch and it does not have a
|
|
|
|
|
// compiler-provided size, so read it from the type data.
|
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
|
|
|
moduledatatype := ctxt.Syms.ROLookup("type.runtime.moduledata", 0)
|
2019-10-03 18:25:21 -04:00
|
|
|
moduledata.Size = decodetypeSize(ctxt.Arch, moduledatatype.P)
|
2017-09-30 15:06:44 +00:00
|
|
|
moduledata.Grow(moduledata.Size)
|
2015-04-01 14:17:43 +13:00
|
|
|
|
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
|
|
|
lastmoduledatap := ctxt.Syms.Lookup("runtime.lastmoduledatap", 0)
|
2017-10-04 17:54:04 -04:00
|
|
|
if lastmoduledatap.Type != sym.SDYNIMPORT {
|
|
|
|
|
lastmoduledatap.Type = sym.SNOPTRDATA
|
2015-04-01 14:17:43 +13:00
|
|
|
lastmoduledatap.Size = 0 // overwrite existing value
|
2017-09-30 15:06:44 +00:00
|
|
|
lastmoduledatap.AddAddr(ctxt.Arch, moduledata)
|
2015-04-01 14:17:43 +13:00
|
|
|
}
|
2015-02-27 22:57:28 -05:00
|
|
|
}
|
2018-10-17 09:36:06 +02:00
|
|
|
|
|
|
|
|
func isStaticTemp(name string) bool {
|
|
|
|
|
if i := strings.LastIndex(name, "/"); i >= 0 {
|
|
|
|
|
name = name[i:]
|
|
|
|
|
}
|
|
|
|
|
return strings.Contains(name, "..stmp_")
|
|
|
|
|
}
|