| 1 |
// Copyright 2019 The Go Authors. All rights reserved. |
| 2 |
// Use of this source code is governed by a BSD-style |
| 3 |
// license that can be found in the LICENSE file. |
| 4 |
|
| 5 |
package loader |
| 6 |
|
| 7 |
import ( |
| 8 |
"cmd/internal/goobj" |
| 9 |
"cmd/internal/objabi" |
| 10 |
"cmd/internal/sys" |
| 11 |
"cmd/link/internal/sym" |
| 12 |
"cmp" |
| 13 |
"slices" |
| 14 |
) |
| 15 |
|
| 16 |
// SymbolBuilder is a helper designed to help with the construction |
| 17 |
// of new symbol contents. |
| 18 |
type SymbolBuilder struct { |
| 19 |
*extSymPayload // points to payload being updated |
| 20 |
symIdx Sym // index of symbol being updated/constructed |
| 21 |
l *Loader // loader |
| 22 |
} |
| 23 |
|
| 24 |
// MakeSymbolBuilder creates a symbol builder for use in constructing |
| 25 |
// an entirely new symbol. |
| 26 |
func (l *Loader) MakeSymbolBuilder(name string) *SymbolBuilder { |
| 27 |
// for now assume that any new sym is intended to be static |
| 28 |
symIdx := l.CreateStaticSym(name) |
| 29 |
sb := &SymbolBuilder{l: l, symIdx: symIdx} |
| 30 |
sb.extSymPayload = l.getPayload(symIdx) |
| 31 |
return sb |
| 32 |
} |
| 33 |
|
| 34 |
// MakeSymbolUpdater creates a symbol builder helper for an existing |
| 35 |
// symbol 'symIdx'. If 'symIdx' is not an external symbol, then create |
| 36 |
// a clone of it (copy name, properties, etc) fix things up so that |
| 37 |
// the lookup tables and caches point to the new version, not the old |
| 38 |
// version. |
| 39 |
func (l *Loader) MakeSymbolUpdater(symIdx Sym) *SymbolBuilder { |
| 40 |
if symIdx == 0 { |
| 41 |
panic("can't update the null symbol") |
| 42 |
} |
| 43 |
if !l.IsExternal(symIdx) { |
| 44 |
// Create a clone with the same name/version/kind etc. |
| 45 |
l.cloneToExternal(symIdx) |
| 46 |
} |
| 47 |
|
| 48 |
// Construct updater and return. |
| 49 |
sb := &SymbolBuilder{l: l, symIdx: symIdx} |
| 50 |
sb.extSymPayload = l.getPayload(symIdx) |
| 51 |
return sb |
| 52 |
} |
| 53 |
|
| 54 |
// CreateSymForUpdate creates a symbol with given name and version, |
| 55 |
// returns a CreateSymForUpdate for update. If the symbol already |
| 56 |
// exists, it will update in-place. |
| 57 |
func (l *Loader) CreateSymForUpdate(name string, version int) *SymbolBuilder { |
| 58 |
s := l.LookupOrCreateSym(name, version) |
| 59 |
l.SetAttrReachable(s, true) |
| 60 |
return l.MakeSymbolUpdater(s) |
| 61 |
} |
| 62 |
|
| 63 |
// Getters for properties of the symbol we're working on. |
| 64 |
|
| 65 |
func (sb *SymbolBuilder) Sym() Sym { return sb.symIdx } |
| 66 |
func (sb *SymbolBuilder) Name() string { return sb.name } |
| 67 |
func (sb *SymbolBuilder) Version() int { return sb.ver } |
| 68 |
func (sb *SymbolBuilder) Type() sym.SymKind { return sb.kind } |
| 69 |
func (sb *SymbolBuilder) Size() int64 { return sb.size } |
| 70 |
func (sb *SymbolBuilder) Data() []byte { return sb.data } |
| 71 |
func (sb *SymbolBuilder) Value() int64 { return sb.l.SymValue(sb.symIdx) } |
| 72 |
func (sb *SymbolBuilder) Align() int32 { return sb.l.SymAlign(sb.symIdx) } |
| 73 |
func (sb *SymbolBuilder) Localentry() uint8 { return sb.l.SymLocalentry(sb.symIdx) } |
| 74 |
func (sb *SymbolBuilder) OnList() bool { return sb.l.AttrOnList(sb.symIdx) } |
| 75 |
func (sb *SymbolBuilder) External() bool { return sb.l.AttrExternal(sb.symIdx) } |
| 76 |
func (sb *SymbolBuilder) Extname() string { return sb.l.SymExtname(sb.symIdx) } |
| 77 |
func (sb *SymbolBuilder) CgoExportDynamic() bool { return sb.l.AttrCgoExportDynamic(sb.symIdx) } |
| 78 |
func (sb *SymbolBuilder) Dynimplib() string { return sb.l.SymDynimplib(sb.symIdx) } |
| 79 |
func (sb *SymbolBuilder) Dynimpvers() string { return sb.l.SymDynimpvers(sb.symIdx) } |
| 80 |
func (sb *SymbolBuilder) SubSym() Sym { return sb.l.SubSym(sb.symIdx) } |
| 81 |
func (sb *SymbolBuilder) GoType() Sym { return sb.l.SymGoType(sb.symIdx) } |
| 82 |
func (sb *SymbolBuilder) VisibilityHidden() bool { return sb.l.AttrVisibilityHidden(sb.symIdx) } |
| 83 |
func (sb *SymbolBuilder) Sect() *sym.Section { return sb.l.SymSect(sb.symIdx) } |
| 84 |
|
| 85 |
// Setters for symbol properties. |
| 86 |
|
| 87 |
func (sb *SymbolBuilder) SetType(kind sym.SymKind) { sb.kind = kind } |
| 88 |
func (sb *SymbolBuilder) SetSize(size int64) { sb.size = size } |
| 89 |
func (sb *SymbolBuilder) SetData(data []byte) { sb.data = data } |
| 90 |
func (sb *SymbolBuilder) SetOnList(v bool) { sb.l.SetAttrOnList(sb.symIdx, v) } |
| 91 |
func (sb *SymbolBuilder) SetExternal(v bool) { sb.l.SetAttrExternal(sb.symIdx, v) } |
| 92 |
func (sb *SymbolBuilder) SetValue(v int64) { sb.l.SetSymValue(sb.symIdx, v) } |
| 93 |
func (sb *SymbolBuilder) SetAlign(align int32) { sb.l.SetSymAlign(sb.symIdx, align) } |
| 94 |
func (sb *SymbolBuilder) SetLocalentry(value uint8) { sb.l.SetSymLocalentry(sb.symIdx, value) } |
| 95 |
func (sb *SymbolBuilder) SetExtname(value string) { sb.l.SetSymExtname(sb.symIdx, value) } |
| 96 |
func (sb *SymbolBuilder) SetDynimplib(value string) { sb.l.SetSymDynimplib(sb.symIdx, value) } |
| 97 |
func (sb *SymbolBuilder) SetDynimpvers(value string) { sb.l.SetSymDynimpvers(sb.symIdx, value) } |
| 98 |
func (sb *SymbolBuilder) SetPlt(value int32) { sb.l.SetPlt(sb.symIdx, value) } |
| 99 |
func (sb *SymbolBuilder) SetGot(value int32) { sb.l.SetGot(sb.symIdx, value) } |
| 100 |
func (sb *SymbolBuilder) SetSpecial(value bool) { sb.l.SetAttrSpecial(sb.symIdx, value) } |
| 101 |
func (sb *SymbolBuilder) SetLocal(value bool) { sb.l.SetAttrLocal(sb.symIdx, value) } |
| 102 |
func (sb *SymbolBuilder) SetVisibilityHidden(value bool) { |
| 103 |
sb.l.SetAttrVisibilityHidden(sb.symIdx, value) |
| 104 |
} |
| 105 |
func (sb *SymbolBuilder) SetNotInSymbolTable(value bool) { |
| 106 |
sb.l.SetAttrNotInSymbolTable(sb.symIdx, value) |
| 107 |
} |
| 108 |
func (sb *SymbolBuilder) SetSect(sect *sym.Section) { sb.l.SetSymSect(sb.symIdx, sect) } |
| 109 |
|
| 110 |
func (sb *SymbolBuilder) AddBytes(data []byte) { |
| 111 |
if sb.kind == 0 { |
| 112 |
sb.kind = sym.SDATA |
| 113 |
} |
| 114 |
sb.data = append(sb.data, data...) |
| 115 |
sb.size = int64(len(sb.data)) |
| 116 |
} |
| 117 |
|
| 118 |
func (sb *SymbolBuilder) Relocs() Relocs { |
| 119 |
return sb.l.Relocs(sb.symIdx) |
| 120 |
} |
| 121 |
|
| 122 |
// ResetRelocs removes all relocations on this symbol. |
| 123 |
func (sb *SymbolBuilder) ResetRelocs() { |
| 124 |
sb.relocs = sb.relocs[:0] |
| 125 |
} |
| 126 |
|
| 127 |
// SetRelocType sets the type of the 'i'-th relocation on this sym to 't' |
| 128 |
func (sb *SymbolBuilder) SetRelocType(i int, t objabi.RelocType) { |
| 129 |
sb.relocs[i].SetType(uint16(t)) |
| 130 |
} |
| 131 |
|
| 132 |
// SetRelocSym sets the target sym of the 'i'-th relocation on this sym to 's' |
| 133 |
func (sb *SymbolBuilder) SetRelocSym(i int, tgt Sym) { |
| 134 |
sb.relocs[i].SetSym(goobj.SymRef{PkgIdx: 0, SymIdx: uint32(tgt)}) |
| 135 |
} |
| 136 |
|
| 137 |
// SetRelocAdd sets the addend of the 'i'-th relocation on this sym to 'a' |
| 138 |
func (sb *SymbolBuilder) SetRelocAdd(i int, a int64) { |
| 139 |
sb.relocs[i].SetAdd(a) |
| 140 |
} |
| 141 |
|
| 142 |
// SetRelocSiz sets the size of the 'i'-th relocation on this sym to 'sz' |
| 143 |
func (sb *SymbolBuilder) SetRelocSiz(i int, sz uint8) { |
| 144 |
sb.relocs[i].SetSiz(sz) |
| 145 |
} |
| 146 |
|
| 147 |
// Add n relocations, return a handle to the relocations. |
| 148 |
func (sb *SymbolBuilder) AddRelocs(n int) Relocs { |
| 149 |
sb.relocs = append(sb.relocs, make([]goobj.Reloc, n)...) |
| 150 |
return sb.l.Relocs(sb.symIdx) |
| 151 |
} |
| 152 |
|
| 153 |
// Add a relocation with given type, return its handle and index |
| 154 |
// (to set other fields). |
| 155 |
func (sb *SymbolBuilder) AddRel(typ objabi.RelocType) (Reloc, int) { |
| 156 |
j := len(sb.relocs) |
| 157 |
sb.relocs = append(sb.relocs, goobj.Reloc{}) |
| 158 |
sb.relocs[j].SetType(uint16(typ)) |
| 159 |
relocs := sb.Relocs() |
| 160 |
return relocs.At(j), j |
| 161 |
} |
| 162 |
|
| 163 |
// SortRelocs Sort relocations by offset. |
| 164 |
func (sb *SymbolBuilder) SortRelocs() { |
| 165 |
slices.SortFunc(sb.extSymPayload.relocs, func(a, b goobj.Reloc) int { |
| 166 |
return cmp.Compare(a.Off(), b.Off()) |
| 167 |
}) |
| 168 |
} |
| 169 |
|
| 170 |
func (sb *SymbolBuilder) Reachable() bool { |
| 171 |
return sb.l.AttrReachable(sb.symIdx) |
| 172 |
} |
| 173 |
|
| 174 |
func (sb *SymbolBuilder) SetReachable(v bool) { |
| 175 |
sb.l.SetAttrReachable(sb.symIdx, v) |
| 176 |
} |
| 177 |
|
| 178 |
func (sb *SymbolBuilder) ReadOnly() bool { |
| 179 |
return sb.l.AttrReadOnly(sb.symIdx) |
| 180 |
} |
| 181 |
|
| 182 |
func (sb *SymbolBuilder) SetReadOnly(v bool) { |
| 183 |
sb.l.SetAttrReadOnly(sb.symIdx, v) |
| 184 |
} |
| 185 |
|
| 186 |
func (sb *SymbolBuilder) DuplicateOK() bool { |
| 187 |
return sb.l.AttrDuplicateOK(sb.symIdx) |
| 188 |
} |
| 189 |
|
| 190 |
func (sb *SymbolBuilder) SetDuplicateOK(v bool) { |
| 191 |
sb.l.SetAttrDuplicateOK(sb.symIdx, v) |
| 192 |
} |
| 193 |
|
| 194 |
func (sb *SymbolBuilder) Outer() Sym { |
| 195 |
return sb.l.OuterSym(sb.symIdx) |
| 196 |
} |
| 197 |
|
| 198 |
func (sb *SymbolBuilder) Sub() Sym { |
| 199 |
return sb.l.SubSym(sb.symIdx) |
| 200 |
} |
| 201 |
|
| 202 |
func (sb *SymbolBuilder) SortSub() { |
| 203 |
sb.l.SortSub(sb.symIdx) |
| 204 |
} |
| 205 |
|
| 206 |
func (sb *SymbolBuilder) AddInteriorSym(sub Sym) { |
| 207 |
sb.l.AddInteriorSym(sb.symIdx, sub) |
| 208 |
} |
| 209 |
|
| 210 |
func (sb *SymbolBuilder) AddUint8(v uint8) int64 { |
| 211 |
off := sb.size |
| 212 |
if sb.kind == 0 { |
| 213 |
sb.kind = sym.SDATA |
| 214 |
} |
| 215 |
sb.size++ |
| 216 |
sb.data = append(sb.data, v) |
| 217 |
return off |
| 218 |
} |
| 219 |
|
| 220 |
func (sb *SymbolBuilder) AddUintXX(arch *sys.Arch, v uint64, wid int) int64 { |
| 221 |
off := sb.size |
| 222 |
sb.setUintXX(arch, off, v, int64(wid)) |
| 223 |
return off |
| 224 |
} |
| 225 |
|
| 226 |
func (sb *SymbolBuilder) setUintXX(arch *sys.Arch, off int64, v uint64, wid int64) int64 { |
| 227 |
if sb.kind == 0 { |
| 228 |
sb.kind = sym.SDATA |
| 229 |
} |
| 230 |
if sb.size < off+wid { |
| 231 |
sb.size = off + wid |
| 232 |
sb.Grow(sb.size) |
| 233 |
} |
| 234 |
|
| 235 |
switch wid { |
| 236 |
case 1: |
| 237 |
sb.data[off] = uint8(v) |
| 238 |
case 2: |
| 239 |
arch.ByteOrder.PutUint16(sb.data[off:], uint16(v)) |
| 240 |
case 4: |
| 241 |
arch.ByteOrder.PutUint32(sb.data[off:], uint32(v)) |
| 242 |
case 8: |
| 243 |
arch.ByteOrder.PutUint64(sb.data[off:], v) |
| 244 |
} |
| 245 |
|
| 246 |
return off + wid |
| 247 |
} |
| 248 |
|
| 249 |
func (sb *SymbolBuilder) AddUint16(arch *sys.Arch, v uint16) int64 { |
| 250 |
return sb.AddUintXX(arch, uint64(v), 2) |
| 251 |
} |
| 252 |
|
| 253 |
func (sb *SymbolBuilder) AddUint32(arch *sys.Arch, v uint32) int64 { |
| 254 |
return sb.AddUintXX(arch, uint64(v), 4) |
| 255 |
} |
| 256 |
|
| 257 |
func (sb *SymbolBuilder) AddUint64(arch *sys.Arch, v uint64) int64 { |
| 258 |
return sb.AddUintXX(arch, v, 8) |
| 259 |
} |
| 260 |
|
| 261 |
func (sb *SymbolBuilder) AddUint(arch *sys.Arch, v uint64) int64 { |
| 262 |
return sb.AddUintXX(arch, v, arch.PtrSize) |
| 263 |
} |
| 264 |
|
| 265 |
func (sb *SymbolBuilder) SetUint8(arch *sys.Arch, r int64, v uint8) int64 { |
| 266 |
return sb.setUintXX(arch, r, uint64(v), 1) |
| 267 |
} |
| 268 |
|
| 269 |
func (sb *SymbolBuilder) SetUint16(arch *sys.Arch, r int64, v uint16) int64 { |
| 270 |
return sb.setUintXX(arch, r, uint64(v), 2) |
| 271 |
} |
| 272 |
|
| 273 |
func (sb *SymbolBuilder) SetUint32(arch *sys.Arch, r int64, v uint32) int64 { |
| 274 |
return sb.setUintXX(arch, r, uint64(v), 4) |
| 275 |
} |
| 276 |
|
| 277 |
func (sb *SymbolBuilder) SetUint(arch *sys.Arch, r int64, v uint64) int64 { |
| 278 |
return sb.setUintXX(arch, r, v, int64(arch.PtrSize)) |
| 279 |
} |
| 280 |
|
| 281 |
func (sb *SymbolBuilder) SetUintptr(arch *sys.Arch, r int64, v uintptr) int64 { |
| 282 |
return sb.setUintXX(arch, r, uint64(v), int64(arch.PtrSize)) |
| 283 |
} |
| 284 |
|
| 285 |
func (sb *SymbolBuilder) SetAddrPlus(arch *sys.Arch, off int64, tgt Sym, add int64) int64 { |
| 286 |
if sb.Type() == 0 { |
| 287 |
sb.SetType(sym.SDATA) |
| 288 |
} |
| 289 |
if off+int64(arch.PtrSize) > sb.size { |
| 290 |
sb.size = off + int64(arch.PtrSize) |
| 291 |
sb.Grow(sb.size) |
| 292 |
} |
| 293 |
r, _ := sb.AddRel(objabi.R_ADDR) |
| 294 |
r.SetSym(tgt) |
| 295 |
r.SetOff(int32(off)) |
| 296 |
r.SetSiz(uint8(arch.PtrSize)) |
| 297 |
r.SetAdd(add) |
| 298 |
return off + int64(r.Siz()) |
| 299 |
} |
| 300 |
|
| 301 |
func (sb *SymbolBuilder) SetAddr(arch *sys.Arch, off int64, tgt Sym) int64 { |
| 302 |
return sb.SetAddrPlus(arch, off, tgt, 0) |
| 303 |
} |
| 304 |
|
| 305 |
func (sb *SymbolBuilder) AddStringAt(off int64, str string) int64 { |
| 306 |
strLen := int64(len(str)) |
| 307 |
if off+strLen > int64(len(sb.data)) { |
| 308 |
panic("attempt to write past end of buffer") |
| 309 |
} |
| 310 |
copy(sb.data[off:off+strLen], str) |
| 311 |
return off + strLen |
| 312 |
} |
| 313 |
|
| 314 |
// AddCStringAt adds str plus a null terminating byte. |
| 315 |
func (sb *SymbolBuilder) AddCStringAt(off int64, str string) int64 { |
| 316 |
strLen := int64(len(str)) |
| 317 |
if off+strLen+1 > int64(len(sb.data)) { |
| 318 |
panic("attempt to write past end of buffer") |
| 319 |
} |
| 320 |
copy(sb.data[off:off+strLen], str) |
| 321 |
sb.data[off+strLen] = 0 |
| 322 |
return off + strLen + 1 |
| 323 |
} |
| 324 |
|
| 325 |
func (sb *SymbolBuilder) Addstring(str string) int64 { |
| 326 |
if sb.kind == 0 { |
| 327 |
sb.kind = sym.SNOPTRDATA |
| 328 |
} |
| 329 |
r := sb.size |
| 330 |
sb.data = append(sb.data, str...) |
| 331 |
sb.data = append(sb.data, 0) |
| 332 |
sb.size = int64(len(sb.data)) |
| 333 |
return r |
| 334 |
} |
| 335 |
|
| 336 |
func (sb *SymbolBuilder) SetBytesAt(off int64, b []byte) int64 { |
| 337 |
datLen := int64(len(b)) |
| 338 |
if off+datLen > int64(len(sb.data)) { |
| 339 |
panic("attempt to write past end of buffer") |
| 340 |
} |
| 341 |
copy(sb.data[off:off+datLen], b) |
| 342 |
return off + datLen |
| 343 |
} |
| 344 |
|
| 345 |
func (sb *SymbolBuilder) addSymRef(tgt Sym, add int64, typ objabi.RelocType, rsize int) int64 { |
| 346 |
if sb.kind == 0 { |
| 347 |
sb.kind = sym.SDATA |
| 348 |
} |
| 349 |
i := sb.size |
| 350 |
|
| 351 |
sb.size += int64(rsize) |
| 352 |
sb.Grow(sb.size) |
| 353 |
|
| 354 |
r, _ := sb.AddRel(typ) |
| 355 |
r.SetSym(tgt) |
| 356 |
r.SetOff(int32(i)) |
| 357 |
r.SetSiz(uint8(rsize)) |
| 358 |
r.SetAdd(add) |
| 359 |
|
| 360 |
return i + int64(rsize) |
| 361 |
} |
| 362 |
|
| 363 |
// Add a symbol reference (relocation) with given type, addend, and size |
| 364 |
// (the most generic form). |
| 365 |
func (sb *SymbolBuilder) AddSymRef(arch *sys.Arch, tgt Sym, add int64, typ objabi.RelocType, rsize int) int64 { |
| 366 |
return sb.addSymRef(tgt, add, typ, rsize) |
| 367 |
} |
| 368 |
|
| 369 |
func (sb *SymbolBuilder) AddAddrPlus(arch *sys.Arch, tgt Sym, add int64) int64 { |
| 370 |
return sb.addSymRef(tgt, add, objabi.R_ADDR, arch.PtrSize) |
| 371 |
} |
| 372 |
|
| 373 |
func (sb *SymbolBuilder) AddAddrPlus4(arch *sys.Arch, tgt Sym, add int64) int64 { |
| 374 |
return sb.addSymRef(tgt, add, objabi.R_ADDR, 4) |
| 375 |
} |
| 376 |
|
| 377 |
func (sb *SymbolBuilder) AddAddr(arch *sys.Arch, tgt Sym) int64 { |
| 378 |
return sb.AddAddrPlus(arch, tgt, 0) |
| 379 |
} |
| 380 |
|
| 381 |
func (sb *SymbolBuilder) AddPEImageRelativeAddrPlus(arch *sys.Arch, tgt Sym, add int64) int64 { |
| 382 |
return sb.addSymRef(tgt, add, objabi.R_PEIMAGEOFF, 4) |
| 383 |
} |
| 384 |
|
| 385 |
func (sb *SymbolBuilder) AddPCRelPlus(arch *sys.Arch, tgt Sym, add int64) int64 { |
| 386 |
return sb.addSymRef(tgt, add, objabi.R_PCREL, 4) |
| 387 |
} |
| 388 |
|
| 389 |
func (sb *SymbolBuilder) AddCURelativeAddrPlus(arch *sys.Arch, tgt Sym, add int64) int64 { |
| 390 |
return sb.addSymRef(tgt, add, objabi.R_ADDRCUOFF, arch.PtrSize) |
| 391 |
} |
| 392 |
|
| 393 |
func (sb *SymbolBuilder) AddSize(arch *sys.Arch, tgt Sym) int64 { |
| 394 |
return sb.addSymRef(tgt, 0, objabi.R_SIZE, arch.PtrSize) |
| 395 |
} |
| 396 |
|
| 397 |
// GenAddAddrPlusFunc returns a function to be called when capturing |
| 398 |
// a function symbol's address. In later stages of the link (when |
| 399 |
// address assignment is done) when doing internal linking and |
| 400 |
// targeting an executable, we can just emit the address of a function |
| 401 |
// directly instead of generating a relocation. Clients can call |
| 402 |
// this function (setting 'internalExec' based on build mode and target) |
| 403 |
// and then invoke the returned function in roughly the same way that |
| 404 |
// loader.*SymbolBuilder.AddAddrPlus would be used. |
| 405 |
func GenAddAddrPlusFunc(internalExec bool) func(s *SymbolBuilder, arch *sys.Arch, tgt Sym, add int64) int64 { |
| 406 |
if internalExec { |
| 407 |
return func(s *SymbolBuilder, arch *sys.Arch, tgt Sym, add int64) int64 { |
| 408 |
if v := s.l.SymValue(tgt); v != 0 { |
| 409 |
return s.AddUint(arch, uint64(v+add)) |
| 410 |
} |
| 411 |
return s.AddAddrPlus(arch, tgt, add) |
| 412 |
} |
| 413 |
} else { |
| 414 |
return (*SymbolBuilder).AddAddrPlus |
| 415 |
} |
| 416 |
} |
| 417 |
|
| 418 |
func (sb *SymbolBuilder) MakeWritable() { |
| 419 |
if sb.ReadOnly() { |
| 420 |
sb.data = append([]byte(nil), sb.data...) |
| 421 |
sb.l.SetAttrReadOnly(sb.symIdx, false) |
| 422 |
} |
| 423 |
} |
| 424 |
|
| 425 |
func (sb *SymbolBuilder) AddUleb(v uint64) { |
| 426 |
if v < 128 { // common case: 1 byte |
| 427 |
sb.AddUint8(uint8(v)) |
| 428 |
return |
| 429 |
} |
| 430 |
for { |
| 431 |
c := uint8(v & 0x7f) |
| 432 |
v >>= 7 |
| 433 |
if v != 0 { |
| 434 |
c |= 0x80 |
| 435 |
} |
| 436 |
sb.AddUint8(c) |
| 437 |
if c&0x80 == 0 { |
| 438 |
break |
| 439 |
} |
| 440 |
} |
| 441 |
} |