blob: 4d2e4293aadd2a1323098cc5acca1b0052fa0dff [file] [log] [blame]
Russ Coxd6f6e422015-01-19 14:34:58 -05001// 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
32package obj
33
Russ Coxd6f6e422015-01-19 14:34:58 -050034/*
35 * add library to library list.
36 * srcref: src file referring to package
37 * objref: object file referring to package
38 * file: object file, e.g., /home/rsc/go/pkg/container/vector.a
39 * pkg: package import path, e.g. container/vector
40 */
Russ Coxd6f6e422015-01-19 14:34:58 -050041
42const (
43 LOG = 5
44)
45
46func mkfwd(sym *LSym) {
Russ Coxd6f6e422015-01-19 14:34:58 -050047 var dwn [LOG]int32
48 var cnt [LOG]int32
49 var lst [LOG]*Prog
50
Russ Cox382b44e2015-02-23 16:07:24 -050051 for i := 0; i < LOG; i++ {
Russ Coxd6f6e422015-01-19 14:34:58 -050052 if i == 0 {
53 cnt[i] = 1
54 } else {
Russ Coxd6f6e422015-01-19 14:34:58 -050055 cnt[i] = LOG * cnt[i-1]
56 }
57 dwn[i] = 1
58 lst[i] = nil
59 }
60
Russ Cox382b44e2015-02-23 16:07:24 -050061 i := 0
62 for p := sym.Text; p != nil && p.Link != nil; p = p.Link {
Russ Coxd6f6e422015-01-19 14:34:58 -050063 i--
64 if i < 0 {
65 i = LOG - 1
66 }
67 p.Forwd = nil
68 dwn[i]--
69 if dwn[i] <= 0 {
70 dwn[i] = cnt[i]
71 if lst[i] != nil {
72 lst[i].Forwd = p
73 }
74 lst[i] = p
75 }
76 }
77}
78
79func Copyp(ctxt *Link, q *Prog) *Prog {
Russ Cox382b44e2015-02-23 16:07:24 -050080 p := ctxt.NewProg()
Russ Coxd6f6e422015-01-19 14:34:58 -050081 *p = *q
82 return p
83}
84
85func Appendp(ctxt *Link, q *Prog) *Prog {
Russ Cox382b44e2015-02-23 16:07:24 -050086 p := ctxt.NewProg()
Russ Coxd6f6e422015-01-19 14:34:58 -050087 p.Link = q.Link
88 q.Link = p
89 p.Lineno = q.Lineno
90 p.Mode = q.Mode
91 return p
92}