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 (a] 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 (a] 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 "log" 36 "os" 37 "path/filepath" 38 ) 39 40 func Linknew(arch *LinkArch) *Link { 41 ctxt := new(Link) 42 ctxt.Hash = make(map[SymVer]*LSym) 43 ctxt.Arch = arch 44 ctxt.Version = HistVersion 45 46 var buf string 47 buf, _ = os.Getwd() 48 if buf == "" { 49 buf = "/???" 50 } 51 buf = filepath.ToSlash(buf) 52 ctxt.Pathname = buf 53 54 ctxt.LineHist.GOROOT = GOROOT 55 ctxt.LineHist.Dir = ctxt.Pathname 56 57 ctxt.Headtype.Set(GOOS) 58 if ctxt.Headtype < 0 { 59 log.Fatalf("unknown goos %s", GOOS) 60 } 61 62 ctxt.Flag_optimize = true 63 ctxt.Framepointer_enabled = Framepointer_enabled(GOOS, arch.Name) 64 return ctxt 65 } 66 67 func Linklookup(ctxt *Link, name string, v int) *LSym { 68 s := ctxt.Hash[SymVer{name, v}] 69 if s != nil { 70 return s 71 } 72 73 s = &LSym{ 74 Name: name, 75 Type: 0, 76 Version: int16(v), 77 Size: 0, 78 } 79 ctxt.Hash[SymVer{name, v}] = s 80 return s 81 } 82 83 func Linksymfmt(s *LSym) string { 84 if s == nil { 85 return "<nil>" 86 } 87 return s.Name 88 } 89