...
Source file src/pkg/cmd/link/internal/ld/link.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 package ld
32
33 import (
34 "bufio"
35 "cmd/internal/obj"
36 "cmd/internal/objabi"
37 "cmd/internal/sys"
38 "cmd/link/internal/sym"
39 "debug/elf"
40 "fmt"
41 )
42
43 type Shlib struct {
44 Path string
45 Hash []byte
46 Deps []string
47 File *elf.File
48 gcdataAddresses map[*sym.Symbol]uint64
49 }
50
51
52
53 type Link struct {
54 Out *OutBuf
55
56 Syms *sym.Symbols
57
58 Arch *sys.Arch
59 Debugvlog int
60 Bso *bufio.Writer
61
62 Loaded bool
63
64 IsELF bool
65 HeadType objabi.HeadType
66
67 linkShared bool
68 LinkMode LinkMode
69 BuildMode BuildMode
70 compressDWARF bool
71
72 Tlsg *sym.Symbol
73 Libdir []string
74 Library []*sym.Library
75 LibraryByPkg map[string]*sym.Library
76 Shlibs []Shlib
77 Tlsoffset int
78 Textp []*sym.Symbol
79 Filesyms []*sym.Symbol
80 Moduledata *sym.Symbol
81
82 PackageFile map[string]string
83 PackageShlib map[string]string
84
85 tramps []*sym.Symbol
86
87
88
89 unresolvedSymSet map[unresolvedSymKey]bool
90
91
92 Reachparent map[*sym.Symbol]*sym.Symbol
93
94 compUnits []*compilationUnit
95 compUnitByPackage map[*sym.Library]*compilationUnit
96
97 relocbuf []byte
98 }
99
100 type unresolvedSymKey struct {
101 from *sym.Symbol
102 to *sym.Symbol
103 }
104
105
106 func (ctxt *Link) ErrorUnresolved(s *sym.Symbol, r *sym.Reloc) {
107 if ctxt.unresolvedSymSet == nil {
108 ctxt.unresolvedSymSet = make(map[unresolvedSymKey]bool)
109 }
110
111 k := unresolvedSymKey{from: s, to: r.Sym}
112 if !ctxt.unresolvedSymSet[k] {
113 ctxt.unresolvedSymSet[k] = true
114
115
116 var reqABI, haveABI obj.ABI
117 haveABI = ^obj.ABI(0)
118 reqABI, ok := sym.VersionToABI(int(r.Sym.Version))
119 if ok {
120 for abi := obj.ABI(0); abi < obj.ABICount; abi++ {
121 v := sym.ABIToVersion(abi)
122 if v == -1 {
123 continue
124 }
125 if rs := ctxt.Syms.ROLookup(r.Sym.Name, v); rs != nil && rs.Type != sym.Sxxx {
126 haveABI = abi
127 }
128 }
129 }
130
131
132 if r.Sym.Name == "main.main" {
133 Errorf(s, "function main is undeclared in the main package")
134 } else if haveABI != ^obj.ABI(0) {
135 Errorf(s, "relocation target %s not defined for %s (but is defined for %s)", r.Sym.Name, reqABI, haveABI)
136 } else {
137 Errorf(s, "relocation target %s not defined", r.Sym.Name)
138 }
139 }
140 }
141
142
143
144
145
146 func (ctxt *Link) FixedFrameSize() int64 {
147 switch ctxt.Arch.Family {
148 case sys.AMD64, sys.I386:
149 return 0
150 case sys.PPC64:
151
152
153 return int64(4 * ctxt.Arch.PtrSize)
154 default:
155 return int64(ctxt.Arch.PtrSize)
156 }
157 }
158
159 func (ctxt *Link) Logf(format string, args ...interface{}) {
160 fmt.Fprintf(ctxt.Bso, format, args...)
161 ctxt.Bso.Flush()
162 }
163
164 func addImports(ctxt *Link, l *sym.Library, pn string) {
165 pkg := objabi.PathToPrefix(l.Pkg)
166 for _, importStr := range l.ImportStrings {
167 lib := addlib(ctxt, pkg, pn, importStr)
168 if lib != nil {
169 l.Imports = append(l.Imports, lib)
170 }
171 }
172 l.ImportStrings = nil
173 }
174
View as plain text