...
Source file src/cmd/internal/obj/sym.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32 package obj
33
34 import (
35 "cmd/internal/objabi"
36 "fmt"
37 "log"
38 "math"
39 )
40
41 func Linknew(arch *LinkArch) *Link {
42 ctxt := new(Link)
43 ctxt.hash = make(map[string]*LSym)
44 ctxt.funchash = make(map[string]*LSym)
45 ctxt.statichash = make(map[string]*LSym)
46 ctxt.Arch = arch
47 ctxt.Pathname = objabi.WorkingDir()
48
49 if err := ctxt.Headtype.Set(objabi.GOOS); err != nil {
50 log.Fatalf("unknown goos %s", objabi.GOOS)
51 }
52
53 ctxt.Flag_optimize = true
54 ctxt.Framepointer_enabled = objabi.Framepointer_enabled(objabi.GOOS, arch.Name)
55 return ctxt
56 }
57
58
59
60 func (ctxt *Link) LookupDerived(s *LSym, name string) *LSym {
61 if s.Static() {
62 return ctxt.LookupStatic(name)
63 }
64 return ctxt.Lookup(name)
65 }
66
67
68
69 func (ctxt *Link) LookupStatic(name string) *LSym {
70 s := ctxt.statichash[name]
71 if s == nil {
72 s = &LSym{Name: name, Attribute: AttrStatic}
73 ctxt.statichash[name] = s
74 }
75 return s
76 }
77
78
79
80 func (ctxt *Link) LookupABI(name string, abi ABI) *LSym {
81 var hash map[string]*LSym
82 switch abi {
83 case ABI0:
84 hash = ctxt.hash
85 case ABIInternal:
86 hash = ctxt.funchash
87 default:
88 panic("unknown ABI")
89 }
90
91 ctxt.hashmu.Lock()
92 s := hash[name]
93 if s == nil {
94 s = &LSym{Name: name}
95 s.SetABI(abi)
96 hash[name] = s
97 }
98 ctxt.hashmu.Unlock()
99 return s
100 }
101
102
103
104 func (ctxt *Link) Lookup(name string) *LSym {
105 return ctxt.LookupInit(name, nil)
106 }
107
108
109
110
111 func (ctxt *Link) LookupInit(name string, init func(s *LSym)) *LSym {
112 ctxt.hashmu.Lock()
113 s := ctxt.hash[name]
114 if s == nil {
115 s = &LSym{Name: name}
116 ctxt.hash[name] = s
117 if init != nil {
118 init(s)
119 }
120 }
121 ctxt.hashmu.Unlock()
122 return s
123 }
124
125 func (ctxt *Link) Float32Sym(f float32) *LSym {
126 i := math.Float32bits(f)
127 name := fmt.Sprintf("$f32.%08x", i)
128 return ctxt.LookupInit(name, func(s *LSym) {
129 s.Size = 4
130 s.Set(AttrLocal, true)
131 })
132 }
133
134 func (ctxt *Link) Float64Sym(f float64) *LSym {
135 i := math.Float64bits(f)
136 name := fmt.Sprintf("$f64.%016x", i)
137 return ctxt.LookupInit(name, func(s *LSym) {
138 s.Size = 8
139 s.Set(AttrLocal, true)
140 })
141 }
142
143 func (ctxt *Link) Int64Sym(i int64) *LSym {
144 name := fmt.Sprintf("$i64.%016x", uint64(i))
145 return ctxt.LookupInit(name, func(s *LSym) {
146 s.Size = 8
147 s.Set(AttrLocal, true)
148 })
149 }
150
View as plain text