Source file src/cmd/link/internal/sym/symkind.go
1 // Derived from Inferno utils/6l/l.h and related files. 2 // https://bitbucket.org/inferno-os/inferno-os/src/master/utils/6l/l.h 3 // 4 // Copyright © 1994-1999 Lucent Technologies Inc. All rights reserved. 5 // Portions Copyright © 1995-1997 C H Forsyth (forsyth@terzarima.net) 6 // Portions Copyright © 1997-1999 Vita Nuova Limited 7 // Portions Copyright © 2000-2007 Vita Nuova Holdings Limited (www.vitanuova.com) 8 // Portions Copyright © 2004,2006 Bruce Ellis 9 // Portions Copyright © 2005-2007 C H Forsyth (forsyth@terzarima.net) 10 // Revisions Copyright © 2000-2007 Lucent Technologies Inc. and others 11 // Portions Copyright © 2009 The Go Authors. All rights reserved. 12 // 13 // Permission is hereby granted, free of charge, to any person obtaining a copy 14 // of this software and associated documentation files (the "Software"), to deal 15 // in the Software without restriction, including without limitation the rights 16 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 17 // copies of the Software, and to permit persons to whom the Software is 18 // furnished to do so, subject to the following conditions: 19 // 20 // The above copyright notice and this permission notice shall be included in 21 // all copies or substantial portions of the Software. 22 // 23 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 24 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 25 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 26 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 27 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 28 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 29 // THE SOFTWARE. 30 31 package sym 32 33 import "cmd/internal/objabi" 34 35 // A SymKind describes the kind of memory represented by a symbol. 36 type SymKind uint8 37 38 // Defined SymKind values. 39 // 40 // TODO(rsc): Give idiomatic Go names. 41 // 42 //go:generate stringer -type=SymKind 43 const ( 44 // An otherwise invalid zero value for the type. 45 Sxxx SymKind = iota 46 // The text segment, containing executable instructions. 47 STEXT // General executable code. 48 STEXTFIPSSTART // Start of FIPS text section. 49 STEXTFIPS // Instructions hashed for FIPS checks. 50 STEXTFIPSEND // End of FIPS text section. 51 STEXTEND // End of text section. 52 SELFRXSECT // Executable PLT; PPC64 .glink. 53 SMACHOPLT // Mach-O PLT. 54 55 // Read-only, non-executable, unrelocated segment. 56 SSTRING // Used only for XCOFF runtime.rodata symbol? 57 SGOSTRING // Go string constants. 58 SGCBITS // GC bit masks and programs. 59 SRODATA // General read-only data. 60 SRODATAFIPSSTART // Start of FIPS read-only data. 61 SRODATAFIPS // FIPS read-only data. 62 SRODATAFIPSEND // End of FIPS read-only data. 63 SRODATAEND // End of read-only data. 64 SPCLNTAB // Pclntab data. 65 SELFROSECT // ELF read-only data: relocs, dynamic linking info. 66 67 // Read-only, non-executable, dynamically relocatable segment. 68 // 69 // This segment holds read-only data that contains pointers to 70 // other parts of the program. When generating a position 71 // independent executable or a shared library, these sections 72 // are "relro", meaning that they start as writable, and are 73 // changed to be read-only after dynamic relocations are applied. 74 // 75 // When no dynamic relocations are required, as when generating 76 // an executable that is not position independent, this is just 77 // part of the normal read-only segment. 78 SRODATARELRO 79 STYPE 80 SGOFUNC 81 SELFRELROSECT // ELF-specific read-only relocatable: PLT, etc. 82 SMACHORELROSECT // Mach-O specific read-only relocatable. 83 84 // Allocated writable segment. 85 SFirstWritable 86 SBUILDINFO // debug/buildinfo data (why is this writable?). 87 SFIPSINFO // go:fipsinfo aka crypto/internal/fips140/check.Linkinfo (why is this writable)? 88 SELFSECT // .got.plt, .plt, .dynamic where appropriate. 89 SMACHO // Used only for .llvmasm? 90 SWINDOWS // Windows dynamic symbols. 91 SMODULEDATA // Linker generated moduledata struct. 92 SELFGOT // Writable ELF GOT section. 93 SMACHOGOT // Mach-O GOT. 94 SNOPTRDATA // Data with no heap pointers. 95 SNOPTRDATAFIPSSTART // Start of FIPS non-pointer writable data. 96 SNOPTRDATAFIPS // FIPS non-pointer writable data. 97 SNOPTRDATAFIPSEND // End of FIPS non-pointer writable data. 98 SNOPTRDATAEND // End of data with no heap pointers. 99 SINITARR // ELF .init_array section. 100 SDATA // Data that may have heap pointers. 101 SDATAFIPSSTART // Start of FIPS writable data. 102 SDATAFIPS // FIPS writable data. 103 SDATAFIPSEND // End of FIPS writable data. 104 SDATAEND // End of data that may have heap pointers. 105 SXCOFFTOC // AIX TOC entries. 106 107 // Allocated zero-initialized segment. 108 SBSS // Zeroed data that may have heap pointers. 109 SNOPTRBSS // Zeroed data with no heap pointers. 110 SGCMASK // Pointers to generated GC masks. 111 SLIBFUZZER_8BIT_COUNTER // Fuzzer counters. 112 SCOVERAGE_COUNTER // Coverage counters. 113 SCOVERAGE_AUXVAR // Compiler generated coverage symbols. 114 STLSBSS // Thread-local zeroed data. 115 116 // Unallocated segment. 117 SFirstUnallocated 118 SXREF // Reference from non-Go object file. 119 SMACHOSYMSTR // Mach-O string table. 120 SMACHOSYMTAB // Mach-O symbol table. 121 SMACHOINDIRECTPLT // Mach-O indirect PLT. 122 SMACHOINDIRECTGOT // Mach-O indirect GOT. 123 SDYNIMPORT // Reference to symbol defined in shared library. 124 SHOSTOBJ // Symbol defined in non-Go object file. 125 SUNDEFEXT // Undefined symbol for resolution by external linker. 126 127 // Unallocated DWARF debugging segment. 128 SDWARFSECT 129 // DWARF symbol types created by compiler or linker. 130 SDWARFCUINFO 131 SDWARFCONST 132 SDWARFFCN 133 SDWARFABSFCN 134 SDWARFTYPE 135 SDWARFVAR 136 SDWARFRANGE 137 SDWARFLOC 138 SDWARFLINES 139 SDWARFADDR 140 141 // SEH symbol types. These are probably allocated at run time. 142 SSEHUNWINDINFO // Compiler generated Windows SEH info. 143 SSEHSECT // Windows SEH data. 144 ) 145 146 // AbiSymKindToSymKind maps values read from object files (which are 147 // of type cmd/internal/objabi.SymKind) to values of type SymKind. 148 var AbiSymKindToSymKind = [...]SymKind{ 149 objabi.Sxxx: Sxxx, 150 objabi.STEXT: STEXT, 151 objabi.STEXTFIPS: STEXTFIPS, 152 objabi.SRODATA: SRODATA, 153 objabi.SRODATAFIPS: SRODATAFIPS, 154 objabi.SNOPTRDATA: SNOPTRDATA, 155 objabi.SNOPTRDATAFIPS: SNOPTRDATAFIPS, 156 objabi.SDATA: SDATA, 157 objabi.SDATAFIPS: SDATAFIPS, 158 objabi.SBSS: SBSS, 159 objabi.SNOPTRBSS: SNOPTRBSS, 160 objabi.STLSBSS: STLSBSS, 161 objabi.SDWARFCUINFO: SDWARFCUINFO, 162 objabi.SDWARFCONST: SDWARFCONST, 163 objabi.SDWARFFCN: SDWARFFCN, 164 objabi.SDWARFABSFCN: SDWARFABSFCN, 165 objabi.SDWARFTYPE: SDWARFTYPE, 166 objabi.SDWARFVAR: SDWARFVAR, 167 objabi.SDWARFRANGE: SDWARFRANGE, 168 objabi.SDWARFLOC: SDWARFLOC, 169 objabi.SDWARFLINES: SDWARFLINES, 170 objabi.SDWARFADDR: SDWARFADDR, 171 objabi.SLIBFUZZER_8BIT_COUNTER: SLIBFUZZER_8BIT_COUNTER, 172 objabi.SCOVERAGE_COUNTER: SCOVERAGE_COUNTER, 173 objabi.SCOVERAGE_AUXVAR: SCOVERAGE_AUXVAR, 174 objabi.SSEHUNWINDINFO: SSEHUNWINDINFO, 175 } 176 177 // ReadOnly are the symbol kinds that form read-only sections 178 // that never require runtime relocations. 179 var ReadOnly = []SymKind{ 180 SSTRING, 181 SGOSTRING, 182 SGCBITS, 183 SRODATA, 184 SRODATAFIPSSTART, 185 SRODATAFIPS, 186 SRODATAFIPSEND, 187 SRODATAEND, 188 } 189 190 // IsText returns true if t is a text type. 191 func (t SymKind) IsText() bool { 192 return STEXT <= t && t <= STEXTEND 193 } 194 195 // IsData returns true if t is any kind of data type. 196 func (t SymKind) IsData() bool { 197 return SNOPTRDATA <= t && t <= SNOPTRBSS 198 } 199 200 // IsDATA returns true if t is one of the SDATA types. 201 func (t SymKind) IsDATA() bool { 202 return SDATA <= t && t <= SDATAEND 203 } 204 205 // IsRODATA returns true if t is one of the SRODATA types. 206 func (t SymKind) IsRODATA() bool { 207 return SRODATA <= t && t <= SRODATAEND 208 } 209 210 // IsNOPTRDATA returns true if t is one of the SNOPTRDATA types. 211 func (t SymKind) IsNOPTRDATA() bool { 212 return SNOPTRDATA <= t && t <= SNOPTRDATAEND 213 } 214 215 func (t SymKind) IsDWARF() bool { 216 return SDWARFSECT <= t && t <= SDWARFADDR 217 } 218