github.com/sanprasirt/go@v0.0.0-20170607001320-a027466e4b6d/src/cmd/link/internal/ld/sym.go (about) 1 // Derived from Inferno utils/6l/obj.c and utils/6l/span.c 2 // https://bitbucket.org/inferno-os/inferno-os/src/default/utils/6l/obj.c 3 // https://bitbucket.org/inferno-os/inferno-os/src/default/utils/6l/span.c 4 // 5 // Copyright © 1994-1999 Lucent Technologies Inc. All rights reserved. 6 // Portions Copyright © 1995-1997 C H Forsyth (forsyth@terzarima.net) 7 // Portions Copyright © 1997-1999 Vita Nuova Limited 8 // Portions Copyright © 2000-2007 Vita Nuova Holdings Limited (www.vitanuova.com) 9 // Portions Copyright © 2004,2006 Bruce Ellis 10 // Portions Copyright © 2005-2007 C H Forsyth (forsyth@terzarima.net) 11 // Revisions Copyright © 2000-2007 Lucent Technologies Inc. and others 12 // Portions Copyright © 2009 The Go Authors. All rights reserved. 13 // 14 // Permission is hereby granted, free of charge, to any person obtaining a copy 15 // of this software and associated documentation files (the "Software"), to deal 16 // in the Software without restriction, including without limitation the rights 17 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 18 // copies of the Software, and to permit persons to whom the Software is 19 // furnished to do so, subject to the following conditions: 20 // 21 // The above copyright notice and this permission notice shall be included in 22 // all copies or substantial portions of the Software. 23 // 24 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 25 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 26 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 27 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 28 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 29 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 30 // THE SOFTWARE. 31 32 package ld 33 34 import ( 35 "cmd/internal/objabi" 36 "cmd/internal/sys" 37 "log" 38 ) 39 40 func linknew(arch *sys.Arch) *Link { 41 ctxt := &Link{ 42 Syms: &Symbols{ 43 hash: []map[string]*Symbol{ 44 // preallocate about 2mb for hash of 45 // non static symbols 46 make(map[string]*Symbol, 100000), 47 }, 48 Allsym: make([]*Symbol, 0, 100000), 49 }, 50 Arch: arch, 51 LibraryByPkg: make(map[string]*Library), 52 } 53 54 if objabi.GOARCH != arch.Name { 55 log.Fatalf("invalid objabi.GOARCH %s (want %s)", objabi.GOARCH, arch.Name) 56 } 57 58 return ctxt 59 } 60 61 // computeTLSOffset records the thread-local storage offset. 62 func (ctxt *Link) computeTLSOffset() { 63 switch Headtype { 64 default: 65 log.Fatalf("unknown thread-local storage offset for %v", Headtype) 66 67 case objabi.Hplan9, objabi.Hwindows: 68 break 69 70 /* 71 * ELF uses TLS offset negative from FS. 72 * Translate 0(FS) and 8(FS) into -16(FS) and -8(FS). 73 * Known to low-level assembly in package runtime and runtime/cgo. 74 */ 75 case objabi.Hlinux, 76 objabi.Hfreebsd, 77 objabi.Hnetbsd, 78 objabi.Hopenbsd, 79 objabi.Hdragonfly, 80 objabi.Hsolaris: 81 if objabi.GOOS == "android" { 82 switch ctxt.Arch.Family { 83 case sys.AMD64: 84 // Android/amd64 constant - offset from 0(FS) to our TLS slot. 85 // Explained in src/runtime/cgo/gcc_android_*.c 86 ctxt.Tlsoffset = 0x1d0 87 case sys.I386: 88 // Android/386 constant - offset from 0(GS) to our TLS slot. 89 ctxt.Tlsoffset = 0xf8 90 default: 91 ctxt.Tlsoffset = -1 * ctxt.Arch.PtrSize 92 } 93 } else { 94 ctxt.Tlsoffset = -1 * ctxt.Arch.PtrSize 95 } 96 97 case objabi.Hnacl: 98 switch ctxt.Arch.Family { 99 default: 100 log.Fatalf("unknown thread-local storage offset for nacl/%s", ctxt.Arch.Name) 101 102 case sys.ARM: 103 ctxt.Tlsoffset = 0 104 105 case sys.AMD64: 106 ctxt.Tlsoffset = 0 107 108 case sys.I386: 109 ctxt.Tlsoffset = -8 110 } 111 112 /* 113 * OS X system constants - offset from 0(GS) to our TLS. 114 * Explained in src/runtime/cgo/gcc_darwin_*.c. 115 */ 116 case objabi.Hdarwin: 117 switch ctxt.Arch.Family { 118 default: 119 log.Fatalf("unknown thread-local storage offset for darwin/%s", ctxt.Arch.Name) 120 121 case sys.ARM: 122 ctxt.Tlsoffset = 0 // dummy value, not needed 123 124 case sys.AMD64: 125 ctxt.Tlsoffset = 0x8a0 126 127 case sys.ARM64: 128 ctxt.Tlsoffset = 0 // dummy value, not needed 129 130 case sys.I386: 131 ctxt.Tlsoffset = 0x468 132 } 133 } 134 135 }