How to use addr method of proggen Package

Best Syzkaller code snippet using proggen.addr

data.go

Source:data.go Github

copy

Full Screen

...94}95func setuint32(ctxt *Link, s *LSym, r int64, v uint32) int64 {96 return setuintxx(ctxt, s, r, uint64(v), 4)97}98func Addaddrplus(ctxt *Link, s *LSym, t *LSym, add int64) int64 {99 if s.Type == 0 {100 s.Type = SDATA101 }102 s.Reachable = true103 i := s.Size104 s.Size += int64(ctxt.Arch.Ptrsize)105 Symgrow(ctxt, s, s.Size)106 r := Addrel(s)107 r.Sym = t108 r.Off = int32(i)109 r.Siz = uint8(ctxt.Arch.Ptrsize)110 r.Type = R_ADDR111 r.Add = add112 return i + int64(r.Siz)113}114func Addpcrelplus(ctxt *Link, s *LSym, t *LSym, add int64) int64 {115 if s.Type == 0 {116 s.Type = SDATA117 }118 s.Reachable = true119 i := s.Size120 s.Size += 4121 Symgrow(ctxt, s, s.Size)122 r := Addrel(s)123 r.Sym = t124 r.Off = int32(i)125 r.Add = add126 r.Type = R_PCREL127 r.Siz = 4128 return i + int64(r.Siz)129}130func Addaddr(ctxt *Link, s *LSym, t *LSym) int64 {131 return Addaddrplus(ctxt, s, t, 0)132}133func setaddrplus(ctxt *Link, s *LSym, off int64, t *LSym, add int64) int64 {134 if s.Type == 0 {135 s.Type = SDATA136 }137 s.Reachable = true138 if off+int64(ctxt.Arch.Ptrsize) > s.Size {139 s.Size = off + int64(ctxt.Arch.Ptrsize)140 Symgrow(ctxt, s, s.Size)141 }142 r := Addrel(s)143 r.Sym = t144 r.Off = int32(off)145 r.Siz = uint8(ctxt.Arch.Ptrsize)146 r.Type = R_ADDR147 r.Add = add148 return off + int64(r.Siz)149}150func setaddr(ctxt *Link, s *LSym, off int64, t *LSym) int64 {151 return setaddrplus(ctxt, s, off, t, 0)152}153func addsize(ctxt *Link, s *LSym, t *LSym) int64 {154 if s.Type == 0 {155 s.Type = SDATA156 }157 s.Reachable = true158 i := s.Size159 s.Size += int64(ctxt.Arch.Ptrsize)160 Symgrow(ctxt, s, s.Size)161 r := Addrel(s)162 r.Sym = t163 r.Off = int32(i)164 r.Siz = uint8(ctxt.Arch.Ptrsize)165 r.Type = R_SIZE166 return i + int64(r.Siz)167}168func addaddrplus4(ctxt *Link, s *LSym, t *LSym, add int64) int64 {169 if s.Type == 0 {170 s.Type = SDATA171 }172 s.Reachable = true173 i := s.Size174 s.Size += 4175 Symgrow(ctxt, s, s.Size)176 r := Addrel(s)177 r.Sym = t178 r.Off = int32(i)179 r.Siz = 4180 r.Type = R_ADDR181 r.Add = add182 return i + int64(r.Siz)183}184/*185 * divide-and-conquer list-link186 * sort of LSym* structures.187 * Used for the data block.188 */189func datcmp(s1 *LSym, s2 *LSym) int {190 if s1.Type != s2.Type {191 return int(s1.Type) - int(s2.Type)192 }193 // For ppc64, we want to interleave the .got and .toc sections194 // from input files. Both are type SELFGOT, so in that case195 // fall through to the name comparison (conveniently, .got196 // sorts before .toc).197 if s1.Type != SELFGOT && s1.Size != s2.Size {198 if s1.Size < s2.Size {199 return -1200 }201 return +1202 }203 return stringsCompare(s1.Name, s2.Name)204}205func listnextp(s *LSym) **LSym {206 return &s.Next207}208func listsubp(s *LSym) **LSym {209 return &s.Sub210}211func listsort(l *LSym, cmp func(*LSym, *LSym) int, nextp func(*LSym) **LSym) *LSym {212 if l == nil || *nextp(l) == nil {213 return l214 }215 l1 := l216 l2 := l217 for {218 l2 = *nextp(l2)219 if l2 == nil {220 break221 }222 l2 = *nextp(l2)223 if l2 == nil {224 break225 }226 l1 = *nextp(l1)227 }228 l2 = *nextp(l1)229 *nextp(l1) = nil230 l1 = listsort(l, cmp, nextp)231 l2 = listsort(l2, cmp, nextp)232 /* set up lead element */233 if cmp(l1, l2) < 0 {234 l = l1235 l1 = *nextp(l1)236 } else {237 l = l2238 l2 = *nextp(l2)239 }240 le := l241 for {242 if l1 == nil {243 for l2 != nil {244 *nextp(le) = l2245 le = l2246 l2 = *nextp(l2)247 }248 *nextp(le) = nil249 break250 }251 if l2 == nil {252 for l1 != nil {253 *nextp(le) = l1254 le = l1255 l1 = *nextp(l1)256 }257 break258 }259 if cmp(l1, l2) < 0 {260 *nextp(le) = l1261 le = l1262 l1 = *nextp(l1)263 } else {264 *nextp(le) = l2265 le = l2266 l2 = *nextp(l2)267 }268 }269 *nextp(le) = nil270 return l271}272func relocsym(s *LSym) {273 var r *Reloc274 var rs *LSym275 var i16 int16276 var off int32277 var siz int32278 var fl int32279 var o int64280 Ctxt.Cursym = s281 for ri := int32(0); ri < int32(len(s.R)); ri++ {282 r = &s.R[ri]283 r.Done = 1284 off = r.Off285 siz = int32(r.Siz)286 if off < 0 || off+siz > int32(len(s.P)) {287 Diag("%s: invalid relocation %d+%d not in [%d,%d)", s.Name, off, siz, 0, len(s.P))288 continue289 }290 if r.Sym != nil && (r.Sym.Type&(SMASK|SHIDDEN) == 0 || r.Sym.Type&SMASK == SXREF) {291 Diag("%s: not defined", r.Sym.Name)292 continue293 }294 if r.Type >= 256 {295 continue296 }297 if r.Siz == 0 { // informational relocation - no work to do298 continue299 }300 // Solaris needs the ability to reference dynimport symbols.301 if HEADTYPE != Hsolaris && r.Sym != nil && r.Sym.Type == SDYNIMPORT {302 Diag("unhandled relocation for %s (type %d rtype %d)", r.Sym.Name, r.Sym.Type, r.Type)303 }304 if r.Sym != nil && r.Sym.Type != STLSBSS && !r.Sym.Reachable {305 Diag("unreachable sym in relocation: %s %s", s.Name, r.Sym.Name)306 }307 // Android emulates run_time.tlsg as a regular variable.308 if r.Type == R_TLS && goos == "android" {309 r.Type = R_ADDR310 }311 switch r.Type {312 default:313 o = 0314 if Thearch.Archreloc(r, s, &o) < 0 {315 Diag("unknown reloc %d", r.Type)316 }317 case R_TLS:318 if Linkmode == LinkInternal && Iself && Thearch.Thechar == '5' {319 // On ELF ARM, the thread pointer is 8 bytes before320 // the start of the thread-local data block, so add 8321 // to the actual TLS offset (r->sym->value).322 // This 8 seems to be a fundamental constant of323 // ELF on ARM (or maybe Glibc on ARM); it is not324 // related to the fact that our own TLS storage happens325 // to take up 8 bytes.326 o = 8 + r.Sym.Value327 break328 }329 r.Done = 0330 o = 0331 if Thearch.Thechar != '6' {332 o = r.Add333 }334 case R_TLS_LE:335 if Linkmode == LinkExternal && Iself && HEADTYPE != Hopenbsd {336 r.Done = 0337 r.Sym = Ctxt.Tlsg338 r.Xsym = Ctxt.Tlsg339 r.Xadd = r.Add340 o = 0341 if Thearch.Thechar != '6' {342 o = r.Add343 }344 break345 }346 o = int64(Ctxt.Tlsoffset) + r.Add347 case R_TLS_IE:348 if Linkmode == LinkExternal && Iself && HEADTYPE != Hopenbsd {349 r.Done = 0350 r.Sym = Ctxt.Tlsg351 r.Xsym = Ctxt.Tlsg352 r.Xadd = r.Add353 o = 0354 if Thearch.Thechar != '6' {355 o = r.Add356 }357 break358 }359 if Iself || Ctxt.Headtype == Hplan9 {360 o = int64(Ctxt.Tlsoffset) + r.Add361 } else if Ctxt.Headtype == Hwindows {362 o = r.Add363 } else {364 log.Fatalf("unexpected R_TLS_IE relocation for %s", Headstr(Ctxt.Headtype))365 }366 case R_ADDR:367 if Linkmode == LinkExternal && r.Sym.Type != SCONST {368 r.Done = 0369 // set up addend for eventual relocation via outer symbol.370 rs = r.Sym371 r.Xadd = r.Add372 for rs.Outer != nil {373 r.Xadd += Symaddr(rs) - Symaddr(rs.Outer)374 rs = rs.Outer375 }376 if rs.Type != SHOSTOBJ && rs.Type != SDYNIMPORT && rs.Sect == nil {377 Diag("missing section for %s", rs.Name)378 }379 r.Xsym = rs380 o = r.Xadd381 if Iself {382 if Thearch.Thechar == '6' {383 o = 0384 }385 } else if HEADTYPE == Hdarwin {386 if rs.Type != SHOSTOBJ {387 o += Symaddr(rs)388 }389 } else if HEADTYPE == Hwindows {390 // nothing to do391 } else {392 Diag("unhandled pcrel relocation for %s", headstring)393 }394 break395 }396 o = Symaddr(r.Sym) + r.Add397 // On amd64, 4-byte offsets will be sign-extended, so it is impossible to398 // access more than 2GB of static data; fail at link time is better than399 // fail at run_time. See http://golang.org/issue/7980.400 // Instead of special casing only amd64, we treat this as an error on all401 // 64-bit architectures so as to be future-proof.402 if int32(o) < 0 && Thearch.Ptrsize > 4 && siz == 4 {403 Diag("non-pc-relative relocation address is too big: %#x (%#x + %#x)", uint64(o), Symaddr(r.Sym), r.Add)404 Errorexit()405 }406 // r->sym can be null when CALL $(constant) is transformed from absolute PC to relative PC call.407 case R_CALL,408 R_PCREL:409 if Linkmode == LinkExternal && r.Sym != nil && r.Sym.Type != SCONST && r.Sym.Sect != Ctxt.Cursym.Sect {410 r.Done = 0411 // set up addend for eventual relocation via outer symbol.412 rs = r.Sym413 r.Xadd = r.Add414 for rs.Outer != nil {415 r.Xadd += Symaddr(rs) - Symaddr(rs.Outer)416 rs = rs.Outer417 }418 r.Xadd -= int64(r.Siz) // relative to address after the relocated chunk419 if rs.Type != SHOSTOBJ && rs.Type != SDYNIMPORT && rs.Sect == nil {420 Diag("missing section for %s", rs.Name)421 }422 r.Xsym = rs423 o = r.Xadd424 if Iself {425 if Thearch.Thechar == '6' {426 o = 0427 }428 } else if HEADTYPE == Hdarwin {429 if r.Type == R_CALL {430 if rs.Type != SHOSTOBJ {431 o += int64(uint64(Symaddr(rs)) - (rs.Sect.(*Section)).Vaddr)432 }433 o -= int64(r.Off) // relative to section offset, not symbol434 } else {435 o += int64(r.Siz)436 }437 } else if HEADTYPE == Hwindows && Thearch.Thechar == '6' { // only amd64 needs PCREL438 // PE/COFF's PC32 relocation uses the address after the relocated439 // bytes as the base. Compensate by skewing the addend.440 o += int64(r.Siz)441 // GNU ld always add VirtualAddress of the .text section to the442 // relocated address, compensate that.443 o -= int64(s.Sect.(*Section).Vaddr - PEBASE)444 } else {445 Diag("unhandled pcrel relocation for %s", headstring)446 }447 break448 }449 o = 0450 if r.Sym != nil {451 o += Symaddr(r.Sym)452 }453 // NOTE: The (int32) cast on the next line works around a bug in Plan 9's 8c454 // compiler. The expression s->value + r->off + r->siz is int32 + int32 +455 // uchar, and Plan 9 8c incorrectly treats the expression as type uint32456 // instead of int32, causing incorrect values when sign extended for adding457 // to o. The bug only occurs on Plan 9, because this C program is compiled by458 // the standard host compiler (gcc on most other systems).459 o += r.Add - (s.Value + int64(r.Off) + int64(int32(r.Siz)))460 case R_SIZE:461 o = r.Sym.Size + r.Add462 }463 if r.Variant != RV_NONE {464 o = Thearch.Archrelocvariant(r, s, o)465 }466 if false {467 nam := "<nil>"468 if r.Sym != nil {469 nam = r.Sym.Name470 }471 fmt.Printf("relocate %s %#x (%#x+%#x, size %d) => %s %#x +%#x [type %d/%d, %x]\n", s.Name, s.Value+int64(off), s.Value, r.Off, r.Siz, nam, Symaddr(r.Sym), r.Add, r.Type, r.Variant, o)472 }473 switch siz {474 default:475 Ctxt.Cursym = s476 Diag("bad reloc size %#x for %s", uint32(siz), r.Sym.Name)477 fallthrough478 // TODO(rsc): Remove.479 case 1:480 s.P[off] = byte(int8(o))481 case 2:482 if o != int64(int16(o)) {483 Diag("relocation address is too big: %#x", o)484 }485 i16 = int16(o)486 Ctxt.Arch.ByteOrder.PutUint16(s.P[off:], uint16(i16))487 case 4:488 if r.Type == R_PCREL || r.Type == R_CALL {489 if o != int64(int32(o)) {490 Diag("pc-relative relocation address is too big: %#x", o)491 }492 } else {493 if o != int64(int32(o)) && o != int64(uint32(o)) {494 Diag("non-pc-relative relocation address is too big: %#x", uint64(o))495 }496 }497 fl = int32(o)498 Ctxt.Arch.ByteOrder.PutUint32(s.P[off:], uint32(fl))499 case 8:500 Ctxt.Arch.ByteOrder.PutUint64(s.P[off:], uint64(o))501 }502 }503}504func reloc() {505 if Debug['v'] != 0 {506 fmt.Fprintf(&Bso, "%5.2f reloc\n", obj.Cputime())507 }508 Bflush(&Bso)509 for s := Ctxt.Textp; s != nil; s = s.Next {510 relocsym(s)511 }512 for s := datap; s != nil; s = s.Next {513 relocsym(s)514 }515}516func dynrelocsym(s *LSym) {517 if HEADTYPE == Hwindows && Linkmode != LinkExternal {518 rel := Linklookup(Ctxt, ".rel", 0)519 if s == rel {520 return521 }522 var r *Reloc523 var targ *LSym524 for ri := 0; ri < len(s.R); ri++ {525 r = &s.R[ri]526 targ = r.Sym527 if targ == nil {528 continue529 }530 if !targ.Reachable {531 Diag("internal inconsistency: dynamic symbol %s is not reachable.", targ.Name)532 }533 if r.Sym.Plt == -2 && r.Sym.Got != -2 { // make dynimport JMP table for PE object files.534 targ.Plt = int32(rel.Size)535 r.Sym = rel536 r.Add = int64(targ.Plt)537 // jmp *addr538 if Thearch.Thechar == '8' {539 Adduint8(Ctxt, rel, 0xff)540 Adduint8(Ctxt, rel, 0x25)541 Addaddr(Ctxt, rel, targ)542 Adduint8(Ctxt, rel, 0x90)543 Adduint8(Ctxt, rel, 0x90)544 } else {545 Adduint8(Ctxt, rel, 0xff)546 Adduint8(Ctxt, rel, 0x24)547 Adduint8(Ctxt, rel, 0x25)548 addaddrplus4(Ctxt, rel, targ, 0)549 Adduint8(Ctxt, rel, 0x90)550 }551 } else if r.Sym.Plt >= 0 {552 r.Sym = rel553 r.Add = int64(targ.Plt)554 }555 }556 return557 }558 var r *Reloc559 for ri := 0; ri < len(s.R); ri++ {560 r = &s.R[ri]561 if r.Sym != nil && r.Sym.Type == SDYNIMPORT || r.Type >= 256 {562 if r.Sym != nil && !r.Sym.Reachable {563 Diag("internal inconsistency: dynamic symbol %s is not reachable.", r.Sym.Name)564 }565 Thearch.Adddynrel(s, r)566 }567 }568}569func dynreloc() {570 // -d suppresses dynamic loader format, so we may as well not571 // compute these sections or mark their symbols as reachable.572 if Debug['d'] != 0 && HEADTYPE != Hwindows {573 return574 }575 if Debug['v'] != 0 {576 fmt.Fprintf(&Bso, "%5.2f reloc\n", obj.Cputime())577 }578 Bflush(&Bso)579 for s := Ctxt.Textp; s != nil; s = s.Next {580 dynrelocsym(s)581 }582 for s := datap; s != nil; s = s.Next {583 dynrelocsym(s)584 }585 if Iself {586 elfdynhash()587 }588}589func blk(start *LSym, addr int64, size int64) {590 var sym *LSym591 for sym = start; sym != nil; sym = sym.Next {592 if sym.Type&SSUB == 0 && sym.Value >= addr {593 break594 }595 }596 eaddr := addr + size597 var ep []byte598 var p []byte599 for ; sym != nil; sym = sym.Next {600 if sym.Type&SSUB != 0 {601 continue602 }603 if sym.Value >= eaddr {604 break605 }606 Ctxt.Cursym = sym607 if sym.Value < addr {608 Diag("phase error: addr=%#x but sym=%#x type=%d", int64(addr), int64(sym.Value), sym.Type)609 Errorexit()610 }611 for ; addr < sym.Value; addr++ {612 Cput(0)613 }614 p = sym.P615 ep = p[len(sym.P):]616 for -cap(p) < -cap(ep) {617 Cput(uint8(p[0]))618 p = p[1:]619 }620 addr += int64(len(sym.P))621 for ; addr < sym.Value+sym.Size; addr++ {622 Cput(0)623 }624 if addr != sym.Value+sym.Size {625 Diag("phase error: addr=%#x value+size=%#x", int64(addr), int64(sym.Value)+sym.Size)626 Errorexit()627 }628 if sym.Value+sym.Size >= eaddr {629 break630 }631 }632 for ; addr < eaddr; addr++ {633 Cput(0)634 }635 Cflush()636}637func Codeblk(addr int64, size int64) {638 if Debug['a'] != 0 {639 fmt.Fprintf(&Bso, "codeblk [%#x,%#x) at offset %#x\n", addr, addr+size, Cpos())640 }641 blk(Ctxt.Textp, addr, size)642 /* again for printing */643 if Debug['a'] == 0 {644 return645 }646 var sym *LSym647 for sym = Ctxt.Textp; sym != nil; sym = sym.Next {648 if !sym.Reachable {649 continue650 }651 if sym.Value >= addr {652 break653 }654 }655 eaddr := addr + size656 var n int64657 var q []byte658 for ; sym != nil; sym = sym.Next {659 if !sym.Reachable {660 continue661 }662 if sym.Value >= eaddr {663 break664 }665 if addr < sym.Value {666 fmt.Fprintf(&Bso, "%-20s %.8x|", "_", uint64(int64(addr)))667 for ; addr < sym.Value; addr++ {668 fmt.Fprintf(&Bso, " %.2x", 0)669 }670 fmt.Fprintf(&Bso, "\n")671 }672 fmt.Fprintf(&Bso, "%.6x\t%-20s\n", uint64(int64(addr)), sym.Name)673 n = sym.Size674 q = sym.P675 for n >= 16 {676 fmt.Fprintf(&Bso, "%.6x\t%%-20.16I\n", uint64(addr), q)677 addr += 16678 q = q[16:]679 n -= 16680 }681 if n > 0 {682 fmt.Fprintf(&Bso, "%.6x\t%%-20.*I\n", uint64(addr), int(n), q)683 }684 addr += n685 }686 if addr < eaddr {687 fmt.Fprintf(&Bso, "%-20s %.8x|", "_", uint64(int64(addr)))688 for ; addr < eaddr; addr++ {689 fmt.Fprintf(&Bso, " %.2x", 0)690 }691 }692 Bflush(&Bso)693}694func Datblk(addr int64, size int64) {695 if Debug['a'] != 0 {696 fmt.Fprintf(&Bso, "datblk [%#x,%#x) at offset %#x\n", addr, addr+size, Cpos())697 }698 blk(datap, addr, size)699 /* again for printing */700 if Debug['a'] == 0 {701 return702 }703 var sym *LSym704 for sym = datap; sym != nil; sym = sym.Next {705 if sym.Value >= addr {706 break707 }708 }709 eaddr := addr + size710 var ep []byte711 var i int64712 var p []byte713 var r *Reloc714 var rsname string715 var typ string716 for ; sym != nil; sym = sym.Next {717 if sym.Value >= eaddr {718 break719 }720 if addr < sym.Value {721 fmt.Fprintf(&Bso, "\t%.8x| 00 ...\n", uint64(addr))722 addr = sym.Value723 }724 fmt.Fprintf(&Bso, "%s\n\t%.8x|", sym.Name, uint(addr))725 p = sym.P726 ep = p[len(sym.P):]727 for -cap(p) < -cap(ep) {728 if -cap(p) > -cap(sym.P) && int(-cap(p)+cap(sym.P))%16 == 0 {729 fmt.Fprintf(&Bso, "\n\t%.8x|", uint(addr+int64(-cap(p)+cap(sym.P))))730 }731 fmt.Fprintf(&Bso, " %.2x", p[0])732 p = p[1:]733 }734 addr += int64(len(sym.P))735 for ; addr < sym.Value+sym.Size; addr++ {736 fmt.Fprintf(&Bso, " %.2x", 0)737 }738 fmt.Fprintf(&Bso, "\n")739 if Linkmode == LinkExternal {740 for i = 0; i < int64(len(sym.R)); i++ {741 r = &sym.R[i]742 rsname = ""743 if r.Sym != nil {744 rsname = r.Sym.Name745 }746 typ = "?"747 switch r.Type {748 case R_ADDR:749 typ = "addr"750 case R_PCREL:751 typ = "pcrel"752 case R_CALL:753 typ = "call"754 }755 fmt.Fprintf(&Bso, "\treloc %.8x/%d %s %s+%#x [%#x]\n", uint(sym.Value+int64(r.Off)), r.Siz, typ, rsname, int64(r.Add), int64(r.Sym.Value+r.Add))756 }757 }758 }759 if addr < eaddr {760 fmt.Fprintf(&Bso, "\t%.8x| 00 ...\n", uint(addr))761 }762 fmt.Fprintf(&Bso, "\t%.8x|\n", uint(eaddr))763}764func strnput(s string, n int) {765 for ; n > 0 && s != ""; s = s[1:] {766 Cput(uint8(s[0]))767 n--768 }769 for n > 0 {770 Cput(0)771 n--772 }773}774var addstrdata_name string775func addstrdata1(arg string) {776 if strings.HasPrefix(arg, "VALUE:") {777 addstrdata(addstrdata_name, arg[6:])778 } else {779 addstrdata_name = arg780 }781}782func addstrdata(name string, value string) {783 p := fmt.Sprintf("%s.str", name)784 sp := Linklookup(Ctxt, p, 0)785 Addstring(sp, value)786 sp.Type = SRODATA787 s := Linklookup(Ctxt, name, 0)788 s.Size = 0789 s.Dupok = 1790 reachable := s.Reachable791 Addaddr(Ctxt, s, sp)792 adduintxx(Ctxt, s, uint64(len(value)), Thearch.Ptrsize)793 // addstring, addaddr, etc., mark the symbols as reachable.794 // In this case that is not necessarily true, so stick to what795 // we know before entering this function.796 s.Reachable = reachable797 sp.Reachable = reachable798}799func Addstring(s *LSym, str string) int64 {800 if s.Type == 0 {801 s.Type = SNOPTRDATA802 }803 s.Reachable = true804 r := int32(s.Size)805 n := len(str) + 1806 if s.Name == ".shstrtab" {807 elfsetstring(str, int(r))808 }809 Symgrow(Ctxt, s, int64(r)+int64(n))810 copy(s.P[r:], str)811 s.P[int(r)+len(str)] = 0812 s.Size += int64(n)813 return int64(r)814}815func dosymtype() {816 for s := Ctxt.Allsym; s != nil; s = s.Allsym {817 if len(s.P) > 0 {818 if s.Type == SBSS {819 s.Type = SDATA820 }821 if s.Type == SNOPTRBSS {822 s.Type = SNOPTRDATA823 }824 }825 }826}827func symalign(s *LSym) int32 {828 if s.Align != 0 {829 return s.Align830 }831 align := int32(Thearch.Maxalign)832 for int64(align) > s.Size && align > 1 {833 align >>= 1834 }835 if align < s.Align {836 align = s.Align837 }838 return align839}840func aligndatsize(datsize int64, s *LSym) int64 {841 return Rnd(datsize, int64(symalign(s)))842}843// maxalign returns the maximum required alignment for844// the list of symbols s; the list stops when s->type exceeds type.845func maxalign(s *LSym, type_ int) int32 {846 var align int32847 max := int32(0)848 for ; s != nil && int(s.Type) <= type_; s = s.Next {849 align = symalign(s)850 if max < align {851 max = align852 }853 }854 return max855}856// Helper object for building GC type programs.857type ProgGen struct {858 s *LSym859 datasize int32860 data [256 / obj.PointersPerByte]uint8861 pos int64862}863func proggeninit(g *ProgGen, s *LSym) {864 g.s = s865 g.datasize = 0866 g.pos = 0867 g.data = [256 / obj.PointersPerByte]uint8{}868}869func proggenemit(g *ProgGen, v uint8) {870 Adduint8(Ctxt, g.s, v)871}872// Writes insData block from g->data.873func proggendataflush(g *ProgGen) {874 if g.datasize == 0 {875 return876 }877 proggenemit(g, obj.InsData)878 proggenemit(g, uint8(g.datasize))879 s := (g.datasize + obj.PointersPerByte - 1) / obj.PointersPerByte880 for i := int32(0); i < s; i++ {881 proggenemit(g, g.data[i])882 }883 g.datasize = 0884 g.data = [256 / obj.PointersPerByte]uint8{}885}886func proggendata(g *ProgGen, d uint8) {887 g.data[g.datasize/obj.PointersPerByte] |= d << uint((g.datasize%obj.PointersPerByte)*obj.BitsPerPointer)888 g.datasize++889 if g.datasize == 255 {890 proggendataflush(g)891 }892}893// Skip v bytes due to alignment, etc.894func proggenskip(g *ProgGen, off int64, v int64) {895 for i := off; i < off+v; i++ {896 if (i % int64(Thearch.Ptrsize)) == 0 {897 proggendata(g, obj.BitsScalar)898 }899 }900}901// Emit insArray instruction.902func proggenarray(g *ProgGen, length int64) {903 var i int32904 proggendataflush(g)905 proggenemit(g, obj.InsArray)906 for i = 0; i < int32(Thearch.Ptrsize); i, length = i+1, length>>8 {907 proggenemit(g, uint8(length))908 }909}910func proggenarrayend(g *ProgGen) {911 proggendataflush(g)912 proggenemit(g, obj.InsArrayEnd)913}914func proggenfini(g *ProgGen, size int64) {915 proggenskip(g, g.pos, size-g.pos)916 proggendataflush(g)917 proggenemit(g, obj.InsEnd)918}919// This function generates GC pointer info for global variables.920func proggenaddsym(g *ProgGen, s *LSym) {921 if s.Size == 0 {922 return923 }924 // Skip alignment hole from the previous symbol.925 proggenskip(g, g.pos, s.Value-g.pos)926 g.pos += s.Value - g.pos927 // The test for names beginning with . here is meant928 // to keep .dynamic and .dynsym from turning up as929 // conservative symbols. They should be marked SELFSECT930 // and not SDATA, but sometimes that doesn't happen.931 // Leave debugging the SDATA issue for the Go rewrite.932 if s.Gotype == nil && s.Size >= int64(Thearch.Ptrsize) && s.Name[0] != '.' {933 // conservative scan934 Diag("missing Go type information for global symbol: %s size %d", s.Name, int(s.Size))935 if (s.Size%int64(Thearch.Ptrsize) != 0) || (g.pos%int64(Thearch.Ptrsize) != 0) {936 Diag("proggenaddsym: unaligned conservative symbol %s: size=%d pos=%d", s.Name, s.Size, g.pos)937 }938 size := (s.Size + int64(Thearch.Ptrsize) - 1) / int64(Thearch.Ptrsize) * int64(Thearch.Ptrsize)939 if size < int64(32*Thearch.Ptrsize) {940 // Emit small symbols as data.941 for i := int64(0); i < size/int64(Thearch.Ptrsize); i++ {942 proggendata(g, obj.BitsPointer)943 }944 } else {945 // Emit large symbols as array.946 proggenarray(g, size/int64(Thearch.Ptrsize))947 proggendata(g, obj.BitsPointer)948 proggenarrayend(g)949 }950 g.pos = s.Value + size951 } else if s.Gotype == nil || decodetype_noptr(s.Gotype) != 0 || s.Size < int64(Thearch.Ptrsize) || s.Name[0] == '.' {952 // no scan953 if s.Size < int64(32*Thearch.Ptrsize) {954 // Emit small symbols as data.955 // This case also handles unaligned and tiny symbols, so tread carefully.956 for i := s.Value; i < s.Value+s.Size; i++ {957 if (i % int64(Thearch.Ptrsize)) == 0 {958 proggendata(g, obj.BitsScalar)959 }960 }961 } else {962 // Emit large symbols as array.963 if (s.Size%int64(Thearch.Ptrsize) != 0) || (g.pos%int64(Thearch.Ptrsize) != 0) {964 Diag("proggenaddsym: unaligned noscan symbol %s: size=%d pos=%d", s.Name, s.Size, g.pos)965 }966 proggenarray(g, s.Size/int64(Thearch.Ptrsize))967 proggendata(g, obj.BitsScalar)968 proggenarrayend(g)969 }970 g.pos = s.Value + s.Size971 } else if decodetype_usegcprog(s.Gotype) != 0 {972 // gc program, copy directly973 proggendataflush(g)974 gcprog := decodetype_gcprog(s.Gotype)975 size := decodetype_size(s.Gotype)976 if (size%int64(Thearch.Ptrsize) != 0) || (g.pos%int64(Thearch.Ptrsize) != 0) {977 Diag("proggenaddsym: unaligned gcprog symbol %s: size=%d pos=%d", s.Name, s.Size, g.pos)978 }979 for i := int64(0); i < int64(len(gcprog.P)-1); i++ {980 proggenemit(g, uint8(gcprog.P[i]))981 }982 g.pos = s.Value + size983 } else {984 // gc mask, it's small so emit as data985 mask := decodetype_gcmask(s.Gotype)986 size := decodetype_size(s.Gotype)987 if (size%int64(Thearch.Ptrsize) != 0) || (g.pos%int64(Thearch.Ptrsize) != 0) {988 Diag("proggenaddsym: unaligned gcmask symbol %s: size=%d pos=%d", s.Name, s.Size, g.pos)989 }990 for i := int64(0); i < size; i += int64(Thearch.Ptrsize) {991 proggendata(g, uint8((mask[i/int64(Thearch.Ptrsize)/2]>>uint64((i/int64(Thearch.Ptrsize)%2)*4+2))&obj.BitsMask))992 }993 g.pos = s.Value + size994 }995}996func growdatsize(datsizep *int64, s *LSym) {997 datsize := *datsizep998 if s.Size < 0 {999 Diag("negative size (datsize = %d, s->size = %d)", datsize, s.Size)1000 }1001 if datsize+s.Size < datsize {1002 Diag("symbol too large (datsize = %d, s->size = %d)", datsize, s.Size)1003 }1004 *datsizep = datsize + s.Size1005}1006func dodata() {1007 if Debug['v'] != 0 {1008 fmt.Fprintf(&Bso, "%5.2f dodata\n", obj.Cputime())1009 }1010 Bflush(&Bso)1011 var last *LSym1012 datap = nil1013 for s := Ctxt.Allsym; s != nil; s = s.Allsym {1014 if !s.Reachable || s.Special != 0 {1015 continue1016 }1017 if STEXT < s.Type && s.Type < SXREF {1018 if s.Onlist != 0 {1019 log.Fatalf("symbol %s listed multiple times", s.Name)1020 }1021 s.Onlist = 11022 if last == nil {1023 datap = s1024 } else {1025 last.Next = s1026 }1027 s.Next = nil1028 last = s1029 }1030 }1031 for s := datap; s != nil; s = s.Next {1032 if int64(len(s.P)) > s.Size {1033 Diag("%s: initialize bounds (%d < %d)", s.Name, int64(s.Size), len(s.P))1034 }1035 }1036 /*1037 * now that we have the datap list, but before we start1038 * to assign addresses, record all the necessary1039 * dynamic relocations. these will grow the relocation1040 * symbol, which is itself data.1041 *1042 * on darwin, we need the symbol table numbers for dynreloc.1043 */1044 if HEADTYPE == Hdarwin {1045 machosymorder()1046 }1047 dynreloc()1048 /* some symbols may no longer belong in datap (Mach-O) */1049 var l **LSym1050 var s *LSym1051 for l = &datap; ; {1052 s = *l1053 if s == nil {1054 break1055 }1056 if s.Type <= STEXT || SXREF <= s.Type {1057 *l = s.Next1058 } else {1059 l = &s.Next1060 }1061 }1062 *l = nil1063 datap = listsort(datap, datcmp, listnextp)1064 /*1065 * allocate sections. list is sorted by type,1066 * so we can just walk it for each piece we want to emit.1067 * segdata is processed before segtext, because we need1068 * to see all symbols in the .data and .bss sections in order1069 * to generate garbage collection information.1070 */1071 /* begin segdata */1072 /* skip symbols belonging to segtext */1073 s = datap1074 for ; s != nil && s.Type < SELFSECT; s = s.Next {1075 }1076 /* writable ELF sections */1077 datsize := int64(0)1078 var sect *Section1079 for ; s != nil && s.Type < SELFGOT; s = s.Next {1080 sect = addsection(&Segdata, s.Name, 06)1081 sect.Align = symalign(s)1082 datsize = Rnd(datsize, int64(sect.Align))1083 sect.Vaddr = uint64(datsize)1084 s.Sect = sect1085 s.Type = SDATA1086 s.Value = int64(uint64(datsize) - sect.Vaddr)1087 growdatsize(&datsize, s)1088 sect.Length = uint64(datsize) - sect.Vaddr1089 }1090 /* .got (and .toc on ppc64) */1091 if s.Type == SELFGOT {1092 sect := addsection(&Segdata, ".got", 06)1093 sect.Align = maxalign(s, SELFGOT)1094 datsize = Rnd(datsize, int64(sect.Align))1095 sect.Vaddr = uint64(datsize)1096 var toc *LSym1097 for ; s != nil && s.Type == SELFGOT; s = s.Next {1098 datsize = aligndatsize(datsize, s)1099 s.Sect = sect1100 s.Type = SDATA1101 s.Value = int64(uint64(datsize) - sect.Vaddr)1102 // Resolve .TOC. symbol for this object file (ppc64)1103 toc = Linkrlookup(Ctxt, ".TOC.", int(s.Version))1104 if toc != nil {1105 toc.Sect = sect1106 toc.Outer = s1107 toc.Sub = s.Sub1108 s.Sub = toc1109 toc.Value = 0x80001110 }1111 growdatsize(&datsize, s)1112 }1113 sect.Length = uint64(datsize) - sect.Vaddr1114 }1115 /* pointer-free data */1116 sect = addsection(&Segdata, ".noptrdata", 06)1117 sect.Align = maxalign(s, SINITARR-1)1118 datsize = Rnd(datsize, int64(sect.Align))1119 sect.Vaddr = uint64(datsize)1120 Linklookup(Ctxt, "run_time.noptrdata", 0).Sect = sect1121 Linklookup(Ctxt, "run_time.enoptrdata", 0).Sect = sect1122 for ; s != nil && s.Type < SINITARR; s = s.Next {1123 datsize = aligndatsize(datsize, s)1124 s.Sect = sect1125 s.Type = SDATA1126 s.Value = int64(uint64(datsize) - sect.Vaddr)1127 growdatsize(&datsize, s)1128 }1129 sect.Length = uint64(datsize) - sect.Vaddr1130 /* shared library initializer */1131 if Flag_shared != 0 {1132 sect := addsection(&Segdata, ".init_array", 06)1133 sect.Align = maxalign(s, SINITARR)1134 datsize = Rnd(datsize, int64(sect.Align))1135 sect.Vaddr = uint64(datsize)1136 for ; s != nil && s.Type == SINITARR; s = s.Next {1137 datsize = aligndatsize(datsize, s)1138 s.Sect = sect1139 s.Value = int64(uint64(datsize) - sect.Vaddr)1140 growdatsize(&datsize, s)1141 }1142 sect.Length = uint64(datsize) - sect.Vaddr1143 }1144 /* data */1145 sect = addsection(&Segdata, ".data", 06)1146 sect.Align = maxalign(s, SBSS-1)1147 datsize = Rnd(datsize, int64(sect.Align))1148 sect.Vaddr = uint64(datsize)1149 Linklookup(Ctxt, "run_time.data", 0).Sect = sect1150 Linklookup(Ctxt, "run_time.edata", 0).Sect = sect1151 gcdata := Linklookup(Ctxt, "run_time.gcdata", 0)1152 var gen ProgGen1153 proggeninit(&gen, gcdata)1154 for ; s != nil && s.Type < SBSS; s = s.Next {1155 if s.Type == SINITARR {1156 Ctxt.Cursym = s1157 Diag("unexpected symbol type %d", s.Type)1158 }1159 s.Sect = sect1160 s.Type = SDATA1161 datsize = aligndatsize(datsize, s)1162 s.Value = int64(uint64(datsize) - sect.Vaddr)1163 proggenaddsym(&gen, s) // gc1164 growdatsize(&datsize, s)1165 }1166 sect.Length = uint64(datsize) - sect.Vaddr1167 proggenfini(&gen, int64(sect.Length)) // gc1168 /* bss */1169 sect = addsection(&Segdata, ".bss", 06)1170 sect.Align = maxalign(s, SNOPTRBSS-1)1171 datsize = Rnd(datsize, int64(sect.Align))1172 sect.Vaddr = uint64(datsize)1173 Linklookup(Ctxt, "run_time.bss", 0).Sect = sect1174 Linklookup(Ctxt, "run_time.ebss", 0).Sect = sect1175 gcbss := Linklookup(Ctxt, "run_time.gcbss", 0)1176 proggeninit(&gen, gcbss)1177 for ; s != nil && s.Type < SNOPTRBSS; s = s.Next {1178 s.Sect = sect1179 datsize = aligndatsize(datsize, s)1180 s.Value = int64(uint64(datsize) - sect.Vaddr)1181 proggenaddsym(&gen, s) // gc1182 growdatsize(&datsize, s)1183 }1184 sect.Length = uint64(datsize) - sect.Vaddr1185 proggenfini(&gen, int64(sect.Length)) // gc1186 /* pointer-free bss */1187 sect = addsection(&Segdata, ".noptrbss", 06)1188 sect.Align = maxalign(s, SNOPTRBSS)1189 datsize = Rnd(datsize, int64(sect.Align))1190 sect.Vaddr = uint64(datsize)1191 Linklookup(Ctxt, "run_time.noptrbss", 0).Sect = sect1192 Linklookup(Ctxt, "run_time.enoptrbss", 0).Sect = sect1193 for ; s != nil && s.Type == SNOPTRBSS; s = s.Next {1194 datsize = aligndatsize(datsize, s)1195 s.Sect = sect1196 s.Value = int64(uint64(datsize) - sect.Vaddr)1197 growdatsize(&datsize, s)1198 }1199 sect.Length = uint64(datsize) - sect.Vaddr1200 Linklookup(Ctxt, "run_time.end", 0).Sect = sect1201 // 6g uses 4-byte relocation offsets, so the entire segment must fit in 32 bits.1202 if datsize != int64(uint32(datsize)) {1203 Diag("data or bss segment too large")1204 }1205 if Iself && Linkmode == LinkExternal && s != nil && s.Type == STLSBSS && HEADTYPE != Hopenbsd {1206 sect := addsection(&Segdata, ".tbss", 06)1207 sect.Align = int32(Thearch.Ptrsize)1208 sect.Vaddr = 01209 datsize = 01210 for ; s != nil && s.Type == STLSBSS; s = s.Next {1211 datsize = aligndatsize(datsize, s)1212 s.Sect = sect1213 s.Value = int64(uint64(datsize) - sect.Vaddr)1214 growdatsize(&datsize, s)1215 }1216 sect.Length = uint64(datsize)1217 } else {1218 // Might be internal linking but still using cgo.1219 // In that case, the only possible STLSBSS symbol is run_time.tlsg.1220 // Give it offset 0, because it's the only thing here.1221 if s != nil && s.Type == STLSBSS && s.Name == "run_time.tlsg" {1222 s.Value = 01223 s = s.Next1224 }1225 }1226 if s != nil {1227 Ctxt.Cursym = nil1228 Diag("unexpected symbol type %d for %s", s.Type, s.Name)1229 }1230 /*1231 * We finished data, begin read-only data.1232 * Not all systems support a separate read-only non-executable data section.1233 * ELF systems do.1234 * OS X and Plan 9 do not.1235 * Windows PE may, but if so we have not implemented it.1236 * And if we're using external linking mode, the point is moot,1237 * since it's not our decision; that code expects the sections in1238 * segtext.1239 */1240 var segro *Segment1241 if Iself && Linkmode == LinkInternal {1242 segro = &Segrodata1243 } else {1244 segro = &Segtext1245 }1246 s = datap1247 datsize = 01248 /* read-only executable ELF, Mach-O sections */1249 for ; s != nil && s.Type < STYPE; s = s.Next {1250 sect = addsection(&Segtext, s.Name, 04)1251 sect.Align = symalign(s)1252 datsize = Rnd(datsize, int64(sect.Align))1253 sect.Vaddr = uint64(datsize)1254 s.Sect = sect1255 s.Type = SRODATA1256 s.Value = int64(uint64(datsize) - sect.Vaddr)1257 growdatsize(&datsize, s)1258 sect.Length = uint64(datsize) - sect.Vaddr1259 }1260 /* read-only data */1261 sect = addsection(segro, ".rodata", 04)1262 sect.Align = maxalign(s, STYPELINK-1)1263 datsize = Rnd(datsize, int64(sect.Align))1264 sect.Vaddr = 01265 Linklookup(Ctxt, "run_time.rodata", 0).Sect = sect1266 Linklookup(Ctxt, "run_time.erodata", 0).Sect = sect1267 for ; s != nil && s.Type < STYPELINK; s = s.Next {1268 datsize = aligndatsize(datsize, s)1269 s.Sect = sect1270 s.Type = SRODATA1271 s.Value = int64(uint64(datsize) - sect.Vaddr)1272 growdatsize(&datsize, s)1273 }1274 sect.Length = uint64(datsize) - sect.Vaddr1275 /* typelink */1276 sect = addsection(segro, ".typelink", 04)1277 sect.Align = maxalign(s, STYPELINK)1278 datsize = Rnd(datsize, int64(sect.Align))1279 sect.Vaddr = uint64(datsize)1280 Linklookup(Ctxt, "run_time.typelink", 0).Sect = sect1281 Linklookup(Ctxt, "run_time.etypelink", 0).Sect = sect1282 for ; s != nil && s.Type == STYPELINK; s = s.Next {1283 datsize = aligndatsize(datsize, s)1284 s.Sect = sect1285 s.Type = SRODATA1286 s.Value = int64(uint64(datsize) - sect.Vaddr)1287 growdatsize(&datsize, s)1288 }1289 sect.Length = uint64(datsize) - sect.Vaddr1290 /* gosymtab */1291 sect = addsection(segro, ".gosymtab", 04)1292 sect.Align = maxalign(s, SPCLNTAB-1)1293 datsize = Rnd(datsize, int64(sect.Align))1294 sect.Vaddr = uint64(datsize)1295 Linklookup(Ctxt, "run_time.symtab", 0).Sect = sect1296 Linklookup(Ctxt, "run_time.esymtab", 0).Sect = sect1297 for ; s != nil && s.Type < SPCLNTAB; s = s.Next {1298 datsize = aligndatsize(datsize, s)1299 s.Sect = sect1300 s.Type = SRODATA1301 s.Value = int64(uint64(datsize) - sect.Vaddr)1302 growdatsize(&datsize, s)1303 }1304 sect.Length = uint64(datsize) - sect.Vaddr1305 /* gopclntab */1306 sect = addsection(segro, ".gopclntab", 04)1307 sect.Align = maxalign(s, SELFROSECT-1)1308 datsize = Rnd(datsize, int64(sect.Align))1309 sect.Vaddr = uint64(datsize)1310 Linklookup(Ctxt, "run_time.pclntab", 0).Sect = sect1311 Linklookup(Ctxt, "run_time.epclntab", 0).Sect = sect1312 for ; s != nil && s.Type < SELFROSECT; s = s.Next {1313 datsize = aligndatsize(datsize, s)1314 s.Sect = sect1315 s.Type = SRODATA1316 s.Value = int64(uint64(datsize) - sect.Vaddr)1317 growdatsize(&datsize, s)1318 }1319 sect.Length = uint64(datsize) - sect.Vaddr1320 /* read-only ELF, Mach-O sections */1321 for ; s != nil && s.Type < SELFSECT; s = s.Next {1322 sect = addsection(segro, s.Name, 04)1323 sect.Align = symalign(s)1324 datsize = Rnd(datsize, int64(sect.Align))1325 sect.Vaddr = uint64(datsize)1326 s.Sect = sect1327 s.Type = SRODATA1328 s.Value = int64(uint64(datsize) - sect.Vaddr)1329 growdatsize(&datsize, s)1330 sect.Length = uint64(datsize) - sect.Vaddr1331 }1332 // 6g uses 4-byte relocation offsets, so the entire segment must fit in 32 bits.1333 if datsize != int64(uint32(datsize)) {1334 Diag("read-only data segment too large")1335 }1336 /* number the sections */1337 n := int32(1)1338 for sect := Segtext.Sect; sect != nil; sect = sect.Next {1339 sect.Extnum = int16(n)1340 n++1341 }1342 for sect := Segrodata.Sect; sect != nil; sect = sect.Next {1343 sect.Extnum = int16(n)1344 n++1345 }1346 for sect := Segdata.Sect; sect != nil; sect = sect.Next {1347 sect.Extnum = int16(n)1348 n++1349 }1350}1351// assign addresses to text1352func textaddress() {1353 var sub *LSym1354 addsection(&Segtext, ".text", 05)1355 // Assign PCs in text segment.1356 // Could parallelize, by assigning to text1357 // and then letting threads copy down, but probably not worth it.1358 sect := Segtext.Sect1359 sect.Align = int32(Funcalign)1360 Linklookup(Ctxt, "run_time.text", 0).Sect = sect1361 Linklookup(Ctxt, "run_time.etext", 0).Sect = sect1362 va := uint64(INITTEXT)1363 sect.Vaddr = va1364 for sym := Ctxt.Textp; sym != nil; sym = sym.Next {1365 sym.Sect = sect1366 if sym.Type&SSUB != 0 {1367 continue1368 }1369 if sym.Align != 0 {1370 va = uint64(Rnd(int64(va), int64(sym.Align)))1371 } else {1372 va = uint64(Rnd(int64(va), int64(Funcalign)))1373 }1374 sym.Value = 01375 for sub = sym; sub != nil; sub = sub.Sub {1376 sub.Value += int64(va)1377 }1378 if sym.Size == 0 && sym.Sub != nil {1379 Ctxt.Cursym = sym1380 }1381 if sym.Size < MINFUNC {1382 va += MINFUNC // spacing required for findfunctab1383 } else {1384 va += uint64(sym.Size)1385 }1386 }1387 sect.Length = va - sect.Vaddr1388}1389// assign addresses1390func address() {1391 va := uint64(INITTEXT)1392 Segtext.Rwx = 051393 Segtext.Vaddr = va1394 Segtext.Fileoff = uint64(HEADR)1395 for s := Segtext.Sect; s != nil; s = s.Next {1396 va = uint64(Rnd(int64(va), int64(s.Align)))1397 s.Vaddr = va1398 va += s.Length1399 }1400 Segtext.Length = va - uint64(INITTEXT)1401 Segtext.Filelen = Segtext.Length1402 if HEADTYPE == Hnacl {1403 va += 32 // room for the "halt sled"1404 }1405 if Segrodata.Sect != nil {1406 // align to page boundary so as not to mix1407 // rodata and executable text.1408 va = uint64(Rnd(int64(va), int64(INITRND)))1409 Segrodata.Rwx = 041410 Segrodata.Vaddr = va1411 Segrodata.Fileoff = va - Segtext.Vaddr + Segtext.Fileoff1412 Segrodata.Filelen = 01413 for s := Segrodata.Sect; s != nil; s = s.Next {1414 va = uint64(Rnd(int64(va), int64(s.Align)))1415 s.Vaddr = va1416 va += s.Length1417 }1418 Segrodata.Length = va - Segrodata.Vaddr1419 Segrodata.Filelen = Segrodata.Length1420 }1421 va = uint64(Rnd(int64(va), int64(INITRND)))1422 Segdata.Rwx = 061423 Segdata.Vaddr = va1424 Segdata.Fileoff = va - Segtext.Vaddr + Segtext.Fileoff1425 Segdata.Filelen = 01426 if HEADTYPE == Hwindows {1427 Segdata.Fileoff = Segtext.Fileoff + uint64(Rnd(int64(Segtext.Length), PEFILEALIGN))1428 }1429 if HEADTYPE == Hplan9 {1430 Segdata.Fileoff = Segtext.Fileoff + Segtext.Filelen1431 }1432 var data *Section1433 var noptr *Section1434 var bss *Section1435 var noptrbss *Section1436 var vlen int641437 for s := Segdata.Sect; s != nil; s = s.Next {1438 vlen = int64(s.Length)1439 if s.Next != nil {1440 vlen = int64(s.Next.Vaddr - s.Vaddr)1441 }1442 s.Vaddr = va1443 va += uint64(vlen)1444 Segdata.Length = va - Segdata.Vaddr1445 if s.Name == ".data" {1446 data = s1447 }1448 if s.Name == ".noptrdata" {1449 noptr = s1450 }1451 if s.Name == ".bss" {1452 bss = s1453 }1454 if s.Name == ".noptrbss" {1455 noptrbss = s1456 }1457 }1458 Segdata.Filelen = bss.Vaddr - Segdata.Vaddr1459 text := Segtext.Sect1460 var rodata *Section1461 if Segrodata.Sect != nil {1462 rodata = Segrodata.Sect1463 } else {1464 rodata = text.Next1465 }1466 typelink := rodata.Next1467 symtab := typelink.Next1468 pclntab := symtab.Next1469 var sub *LSym1470 for sym := datap; sym != nil; sym = sym.Next {1471 Ctxt.Cursym = sym1472 if sym.Sect != nil {1473 sym.Value += int64((sym.Sect.(*Section)).Vaddr)1474 }1475 for sub = sym.Sub; sub != nil; sub = sub.Sub {1476 sub.Value += sym.Value1477 }1478 }1479 xdefine("run_time.text", STEXT, int64(text.Vaddr))1480 xdefine("run_time.etext", STEXT, int64(text.Vaddr+text.Length))1481 xdefine("run_time.rodata", SRODATA, int64(rodata.Vaddr))1482 xdefine("run_time.erodata", SRODATA, int64(rodata.Vaddr+rodata.Length))1483 xdefine("run_time.typelink", SRODATA, int64(typelink.Vaddr))1484 xdefine("run_time.etypelink", SRODATA, int64(typelink.Vaddr+typelink.Length))1485 sym := Linklookup(Ctxt, "run_time.gcdata", 0)1486 xdefine("run_time.egcdata", SRODATA, Symaddr(sym)+sym.Size)1487 Linklookup(Ctxt, "run_time.egcdata", 0).Sect = sym.Sect1488 sym = Linklookup(Ctxt, "run_time.gcbss", 0)1489 xdefine("run_time.egcbss", SRODATA, Symaddr(sym)+sym.Size)1490 Linklookup(Ctxt, "run_time.egcbss", 0).Sect = sym.Sect1491 xdefine("run_time.symtab", SRODATA, int64(symtab.Vaddr))1492 xdefine("run_time.esymtab", SRODATA, int64(symtab.Vaddr+symtab.Length))1493 xdefine("run_time.pclntab", SRODATA, int64(pclntab.Vaddr))1494 xdefine("run_time.epclntab", SRODATA, int64(pclntab.Vaddr+pclntab.Length))1495 xdefine("run_time.noptrdata", SNOPTRDATA, int64(noptr.Vaddr))1496 xdefine("run_time.enoptrdata", SNOPTRDATA, int64(noptr.Vaddr+noptr.Length))1497 xdefine("run_time.bss", SBSS, int64(bss.Vaddr))1498 xdefine("run_time.ebss", SBSS, int64(bss.Vaddr+bss.Length))1499 xdefine("run_time.data", SDATA, int64(data.Vaddr))1500 xdefine("run_time.edata", SDATA, int64(data.Vaddr+data.Length))1501 xdefine("run_time.noptrbss", SNOPTRBSS, int64(noptrbss.Vaddr))1502 xdefine("run_time.enoptrbss", SNOPTRBSS, int64(noptrbss.Vaddr+noptrbss.Length))1503 xdefine("run_time.end", SBSS, int64(Segdata.Vaddr+Segdata.Length))1504}...

Full Screen

Full Screen

addr

Using AI Code Generation

copy

Full Screen

1import "fmt"2type proggen struct {3}4func (p proggen) addr() {5 fmt.Println("name:", p.name)6 fmt.Println("age:", p.age)7}8func main() {9 p1 := proggen{"james", 32}10 p1.addr()11}12import "fmt"13type proggen struct {14}15func (p *proggen) addr() {16}17func main() {18 p1 := proggen{"john", 25}19 p1.addr()20 fmt.Println("name:", p1.name)21 fmt.Println("age:", p1.age)22}23import "fmt"24type proggen struct {25}26func (p *proggen) addr() {27}28func main() {29 p1 := &proggen{"john", 25}30 p1.addr()31 fmt.Println("name:", p1.name)32 fmt.Println("age:", p1.age)33}34import "

Full Screen

Full Screen

addr

Using AI Code Generation

copy

Full Screen

1import "fmt"2func main() {3 p := proggen{1, 2}4 fmt.Println(p.addr())5}6import "fmt"7func main() {8 p := proggen{1, 2}9 fmt.Println(p.addr())10}11import "fmt"12func main() {13 p := proggen{1, 2}14 fmt.Println(p.addr())15}16import "fmt"17func main() {18 p := proggen{1, 2}19 fmt.Println(p.addr())20}21import "fmt"22func main() {23 p := proggen{1, 2}24 fmt.Println(p.addr())25}26import "fmt"27func main() {28 p := proggen{1, 2}29 fmt.Println(p.addr())30}31import "fmt"32func main() {33 p := proggen{1, 2}34 fmt.Println(p.addr())35}36import "fmt"37func main() {38 p := proggen{1, 2}39 fmt.Println(p.addr())40}41import "fmt"42func main() {43 p := proggen{1, 2}44 fmt.Println(p.addr())45}46import "fmt"47func main() {48 p := proggen{1, 2}49 fmt.Println(p.addr())50}51import "fmt"52func main() {53 p := proggen{1, 2}54 fmt.Println(p.addr())

Full Screen

Full Screen

addr

Using AI Code Generation

copy

Full Screen

1import "fmt"2func main(){3 p := new(proggen)4 fmt.Println(p.addr())5}6type proggen struct{}7func (pg *proggen) addr() string {8}9import "testing"10func TestAddr(t *testing.T) {11 p := new(proggen)12 a := p.addr()13 }14}15--- FAIL: TestAddr (0.00s)16--- FAIL: TestAddr (0.00s)

Full Screen

Full Screen

addr

Using AI Code Generation

copy

Full Screen

1import "fmt"2func main() {3 p := proggen{1,2,3}4 fmt.Println(p.addr())5}6import "fmt"7func main() {8 p := proggen{1,2,3}9 fmt.Println(p.addr())10}11import "fmt"12func main() {13 p := proggen{1,2,3}14 fmt.Println(p.addr())15}16import "fmt"17func main() {18 p := proggen{1,2,3}19 fmt.Println(p.addr())20}21import "fmt"22func main() {23 p := proggen{1,2,3}24 fmt.Println(p.addr())25}26import "fmt"27func main() {28 p := proggen{1,2,3}29 fmt.Println(p.addr())30}31import "fmt"32func main() {33 p := proggen{1,2,3}34 fmt.Println(p.addr())35}36import "fmt"37func main() {38 p := proggen{1,2,3}39 fmt.Println(p.addr())40}41import "fmt"42func main() {43 p := proggen{1,2,3}44 fmt.Println(p.addr())45}46import "fmt"47func main() {48 p := proggen{1,2,3}49 fmt.Println(p.addr())50}51import "fmt"52func main() {53 p := proggen{1

Full Screen

Full Screen

addr

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 var (4 a = p.Addr()5 fmt.Println(a)6}7import (8func main() {9 var (10 a = p.Addr()11 fmt.Println(a)12 p = proggen.New()13 fmt.Println(p.Addr())14}15import (16func main() {17 var (18 a = p.Addr()19 fmt.Println(a)20 p = proggen.New()21 fmt.Println(p.Addr())22 fmt.Println(p)23}24&{0x1b6f8c0 [] []}25import (26func main() {27 var (28 a = p.Addr()29 fmt.Println(a)30 p = proggen.New()31 fmt.Println(p.Addr())32 fmt.Println(p)33 p = proggen.New()34 fmt.Println(p.Addr())35 fmt.Println(p)36}37&{0x1b6f8c0 [] []}38&{0x1b6f8c0 [] []}

Full Screen

Full Screen

addr

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 fmt.Println(pg.Addr("Abhishek"))4}5import (6func main() {7 fmt.Println(pg.Addr("Abhishek"))8}9import (10func main() {11 fmt.Println(pg.Addr("Abhishek"))12}13import (14func main() {15 fmt.Println(pg.Addr("Abhishek"))16}17import (18func main() {19 fmt.Println(pg.Addr("Abhishek"))20}21import (22func main() {23 fmt.Println(pg.Addr("Abhishek"))24}25import (26func main() {27 fmt.Println(pg.Addr("Abhishek"))28}29import (30func main() {

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful