github.com/slayercat/go@v0.0.0-20170428012452-c51559813f61/src/cmd/internal/objabi/doc.go (about) 1 // Copyright 2013 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 // NOTE: There are *three* independent implementations of this object 6 // file format in the Go source tree: 7 // 8 // - cmd/internal/goobj/read.go (used by cmd/addr2line, cmd/nm, cmd/objdump, cmd/pprof) 9 // - cmd/internal/obj/objfile.go (used by cmd/asm and cmd/compile) 10 // - cmd/link/internal/objfile.go (used by cmd/link) 11 // 12 // When changing the object file format, remember to change all three. 13 14 // Originally, Go object files were Plan 9 object files, but no longer. 15 // Now they are more like standard object files, in that each symbol is defined 16 // by an associated memory image (bytes) and a list of relocations to apply 17 // during linking. We do not (yet?) use a standard file format, however. 18 // For now, the format is chosen to be as simple as possible to read and write. 19 // It may change for reasons of efficiency, or we may even switch to a 20 // standard file format if there are compelling benefits to doing so. 21 // See golang.org/s/go13linker for more background. 22 // 23 // The file format is: 24 // 25 // - magic header: "\x00\x00go19ld" 26 // - byte 1 - version number 27 // - sequence of strings giving dependencies (imported packages) 28 // - empty string (marks end of sequence) 29 // - sequence of symbol references used by the defined symbols 30 // - byte 0xff (marks end of sequence) 31 // - sequence of integer lengths: 32 // - total data length 33 // - total number of relocations 34 // - total number of pcdata 35 // - total number of automatics 36 // - total number of funcdata 37 // - total number of files 38 // - data, the content of the defined symbols 39 // - sequence of defined symbols 40 // - byte 0xff (marks end of sequence) 41 // - magic footer: "\xff\xffgo19ld" 42 // 43 // All integers are stored in a zigzag varint format. 44 // See golang.org/s/go12symtab for a definition. 45 // 46 // Data blocks and strings are both stored as an integer 47 // followed by that many bytes. 48 // 49 // A symbol reference is a string name followed by a version. 50 // 51 // A symbol points to other symbols using an index into the symbol 52 // reference sequence. Index 0 corresponds to a nil symbol pointer. 53 // In the symbol layout described below "symref index" stands for this 54 // index. 55 // 56 // Each symbol is laid out as the following fields: 57 // 58 // - byte 0xfe (sanity check for synchronization) 59 // - type [int] 60 // - name & version [symref index] 61 // - flags [int] 62 // 1<<0 dupok 63 // 1<<1 local 64 // 1<<2 add to typelink table 65 // - size [int] 66 // - gotype [symref index] 67 // - p [data block] 68 // - nr [int] 69 // - r [nr relocations, sorted by off] 70 // 71 // If type == STEXT, there are a few more fields: 72 // 73 // - args [int] 74 // - locals [int] 75 // - nosplit [int] 76 // - flags [int] 77 // 1<<0 leaf 78 // 1<<1 C function 79 // 1<<2 function may call reflect.Type.Method 80 // - nlocal [int] 81 // - local [nlocal automatics] 82 // - pcln [pcln table] 83 // 84 // Each relocation has the encoding: 85 // 86 // - off [int] 87 // - siz [int] 88 // - type [int] 89 // - add [int] 90 // - sym [symref index] 91 // 92 // Each local has the encoding: 93 // 94 // - asym [symref index] 95 // - offset [int] 96 // - type [int] 97 // - gotype [symref index] 98 // 99 // The pcln table has the encoding: 100 // 101 // - pcsp [data block] 102 // - pcfile [data block] 103 // - pcline [data block] 104 // - pcinline [data block] 105 // - npcdata [int] 106 // - pcdata [npcdata data blocks] 107 // - nfuncdata [int] 108 // - funcdata [nfuncdata symref index] 109 // - funcdatasym [nfuncdata ints] 110 // - nfile [int] 111 // - file [nfile symref index] 112 // - ninlinedcall [int] 113 // - inlinedcall [ninlinedcall int symref int symref] 114 // 115 // The file layout and meaning of type integers are architecture-independent. 116 // 117 // TODO(rsc): The file format is good for a first pass but needs work. 118 // - There are SymID in the object file that should really just be strings. 119 package objabi