github.com/4ad/go@v0.0.0-20161219182952-69a12818b605/src/cmd/internal/obj/sym.go (about) 1 // Derived from Inferno utils/6l/obj.c and utils/6l/span.c 2 // http://code.google.com/p/inferno-os/source/browse/utils/6l/obj.c 3 // http://code.google.com/p/inferno-os/source/browse/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 obj 33 34 import ( 35 "cmd/internal/sys" 36 "log" 37 "os" 38 "path/filepath" 39 "strconv" 40 ) 41 42 var headers = []struct { 43 name string 44 val int 45 }{ 46 {"darwin", Hdarwin}, 47 {"dragonfly", Hdragonfly}, 48 {"freebsd", Hfreebsd}, 49 {"linux", Hlinux}, 50 {"android", Hlinux}, // must be after "linux" entry or else headstr(Hlinux) == "android" 51 {"nacl", Hnacl}, 52 {"netbsd", Hnetbsd}, 53 {"openbsd", Hopenbsd}, 54 {"plan9", Hplan9}, 55 {"solaris", Hsolaris}, 56 {"windows", Hwindows}, 57 {"windowsgui", Hwindows}, 58 } 59 60 func headtype(name string) int { 61 for i := 0; i < len(headers); i++ { 62 if name == headers[i].name { 63 return headers[i].val 64 } 65 } 66 return -1 67 } 68 69 func Headstr(v int) string { 70 for i := 0; i < len(headers); i++ { 71 if v == headers[i].val { 72 return headers[i].name 73 } 74 } 75 return strconv.Itoa(v) 76 } 77 78 func Linknew(arch *LinkArch) *Link { 79 ctxt := new(Link) 80 ctxt.Hash = make(map[SymVer]*LSym) 81 ctxt.Arch = arch 82 ctxt.Version = HistVersion 83 ctxt.Goroot = Getgoroot() 84 ctxt.Goroot_final = os.Getenv("GOROOT_FINAL") 85 86 var buf string 87 buf, _ = os.Getwd() 88 if buf == "" { 89 buf = "/???" 90 } 91 buf = filepath.ToSlash(buf) 92 ctxt.Pathname = buf 93 94 ctxt.LineHist.GOROOT = ctxt.Goroot 95 ctxt.LineHist.GOROOT_FINAL = ctxt.Goroot_final 96 ctxt.LineHist.Dir = ctxt.Pathname 97 98 ctxt.Headtype = headtype(Getgoos()) 99 if ctxt.Headtype < 0 { 100 log.Fatalf("unknown goos %s", Getgoos()) 101 } 102 103 // On arm, record goarm. 104 if ctxt.Arch.Family == sys.ARM { 105 ctxt.Goarm = Getgoarm() 106 } 107 108 ctxt.Flag_optimize = true 109 ctxt.Framepointer_enabled = Framepointer_enabled(Getgoos(), arch.Name) 110 return ctxt 111 } 112 113 func Linklookup(ctxt *Link, name string, v int) *LSym { 114 s := ctxt.Hash[SymVer{name, v}] 115 if s != nil { 116 return s 117 } 118 119 s = &LSym{ 120 Name: name, 121 Type: 0, 122 Version: int16(v), 123 Size: 0, 124 } 125 ctxt.Hash[SymVer{name, v}] = s 126 return s 127 } 128 129 func Linksymfmt(s *LSym) string { 130 if s == nil { 131 return "<nil>" 132 } 133 return s.Name 134 }