github.com/Rookout/GoSDK@v0.1.48/pkg/services/assembler/internal/obj/ld.go (about) 1 // Derived from Inferno utils/6l/obj.c and utils/6l/span.c 2 // https://bitbucket.org/inferno-os/inferno-os/src/master/utils/6l/obj.c 3 // https://bitbucket.org/inferno-os/inferno-os/src/master/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 35 36 const ( 37 LOG = 5 38 ) 39 40 func mkfwd(sym *LSym) { 41 var dwn [LOG]int32 42 var cnt [LOG]int32 43 var lst [LOG]*Prog 44 45 for i := 0; i < LOG; i++ { 46 if i == 0 { 47 cnt[i] = 1 48 } else { 49 cnt[i] = LOG * cnt[i-1] 50 } 51 dwn[i] = 1 52 lst[i] = nil 53 } 54 55 i := 0 56 for p := sym.Func().Text; p != nil && p.Link != nil; p = p.Link { 57 i-- 58 if i < 0 { 59 i = LOG - 1 60 } 61 p.Forwd = nil 62 dwn[i]-- 63 if dwn[i] <= 0 { 64 dwn[i] = cnt[i] 65 if lst[i] != nil { 66 lst[i].Forwd = p 67 } 68 lst[i] = p 69 } 70 } 71 } 72 73 func Appendp(q *Prog, newprog ProgAlloc) *Prog { 74 p := newprog() 75 p.Link = q.Link 76 q.Link = p 77 p.Pos = q.Pos 78 return p 79 }