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 Sxxx SymKind = iota 45 STEXT 46 STEXTFIPSSTART 47 STEXTFIPS 48 STEXTFIPSEND 49 STEXTEND 50 SELFRXSECT 51 SMACHOPLT 52 53 // Read-only sections. 54 STYPE 55 SSTRING 56 SGOSTRING 57 SGOFUNC 58 SGCBITS 59 SRODATA 60 SRODATAFIPSSTART 61 SRODATAFIPS 62 SRODATAFIPSEND 63 SRODATAEND 64 SFUNCTAB 65 66 SELFROSECT 67 68 // Read-only sections with relocations. 69 // 70 // Types STYPE-SFUNCTAB above are written to the .rodata section by default. 71 // When linking a shared object, some conceptually "read only" types need to 72 // be written to by relocations and putting them in a section called 73 // ".rodata" interacts poorly with the system linkers. The GNU linkers 74 // support this situation by arranging for sections of the name 75 // ".data.rel.ro.XXX" to be mprotected read only by the dynamic linker after 76 // relocations have applied, so when the Go linker is creating a shared 77 // object it checks all objects of the above types and bumps any object that 78 // has a relocation to it to the corresponding type below, which are then 79 // written to sections with appropriate magic names. 80 STYPERELRO 81 SSTRINGRELRO 82 SGOSTRINGRELRO 83 SGOFUNCRELRO 84 SGCBITSRELRO 85 SRODATARELRO 86 SFUNCTABRELRO 87 SELFRELROSECT 88 89 // Part of .data.rel.ro if it exists, otherwise part of .rodata. 90 STYPELINK 91 SITABLINK 92 SSYMTAB 93 SPCLNTAB 94 95 // Writable sections. 96 SFirstWritable 97 SBUILDINFO 98 SFIPSINFO 99 SELFSECT 100 SMACHO 101 SMACHOGOT 102 SWINDOWS 103 SELFGOT 104 SNOPTRDATA 105 SNOPTRDATAFIPSSTART 106 SNOPTRDATAFIPS 107 SNOPTRDATAFIPSEND 108 SNOPTRDATAEND 109 SINITARR 110 SDATA 111 SDATAFIPSSTART 112 SDATAFIPS 113 SDATAFIPSEND 114 SDATAEND 115 SXCOFFTOC 116 SBSS 117 SNOPTRBSS 118 SLIBFUZZER_8BIT_COUNTER 119 SCOVERAGE_COUNTER 120 SCOVERAGE_AUXVAR 121 STLSBSS 122 SXREF 123 SMACHOSYMSTR 124 SMACHOSYMTAB 125 SMACHOINDIRECTPLT 126 SMACHOINDIRECTGOT 127 SFILEPATH 128 SDYNIMPORT 129 SHOSTOBJ 130 SUNDEFEXT // Undefined symbol for resolution by external linker 131 132 // Sections for debugging information 133 SDWARFSECT 134 // DWARF symbol types 135 SDWARFCUINFO 136 SDWARFCONST 137 SDWARFFCN 138 SDWARFABSFCN 139 SDWARFTYPE 140 SDWARFVAR 141 SDWARFRANGE 142 SDWARFLOC 143 SDWARFLINES 144 145 // SEH symbol types 146 SSEHUNWINDINFO 147 SSEHSECT 148 ) 149 150 // AbiSymKindToSymKind maps values read from object files (which are 151 // of type cmd/internal/objabi.SymKind) to values of type SymKind. 152 var AbiSymKindToSymKind = [...]SymKind{ 153 objabi.Sxxx: Sxxx, 154 objabi.STEXT: STEXT, 155 objabi.STEXTFIPS: STEXTFIPS, 156 objabi.SRODATA: SRODATA, 157 objabi.SRODATAFIPS: SRODATAFIPS, 158 objabi.SNOPTRDATA: SNOPTRDATA, 159 objabi.SNOPTRDATAFIPS: SNOPTRDATAFIPS, 160 objabi.SDATA: SDATA, 161 objabi.SDATAFIPS: SDATAFIPS, 162 objabi.SBSS: SBSS, 163 objabi.SNOPTRBSS: SNOPTRBSS, 164 objabi.STLSBSS: STLSBSS, 165 objabi.SDWARFCUINFO: SDWARFCUINFO, 166 objabi.SDWARFCONST: SDWARFCONST, 167 objabi.SDWARFFCN: SDWARFFCN, 168 objabi.SDWARFABSFCN: SDWARFABSFCN, 169 objabi.SDWARFTYPE: SDWARFTYPE, 170 objabi.SDWARFVAR: SDWARFVAR, 171 objabi.SDWARFRANGE: SDWARFRANGE, 172 objabi.SDWARFLOC: SDWARFLOC, 173 objabi.SDWARFLINES: SDWARFLINES, 174 objabi.SLIBFUZZER_8BIT_COUNTER: SLIBFUZZER_8BIT_COUNTER, 175 objabi.SCOVERAGE_COUNTER: SCOVERAGE_COUNTER, 176 objabi.SCOVERAGE_AUXVAR: SCOVERAGE_AUXVAR, 177 objabi.SSEHUNWINDINFO: SSEHUNWINDINFO, 178 } 179 180 // ReadOnly are the symbol kinds that form read-only sections. In some 181 // cases, if they will require relocations, they are transformed into 182 // rel-ro sections using relROMap. 183 var ReadOnly = []SymKind{ 184 STYPE, 185 SSTRING, 186 SGOSTRING, 187 SGOFUNC, 188 SGCBITS, 189 SRODATA, 190 SRODATAFIPSSTART, 191 SRODATAFIPS, 192 SRODATAFIPSEND, 193 SRODATAEND, 194 SFUNCTAB, 195 } 196 197 // RelROMap describes the transformation of read-only symbols to rel-ro 198 // symbols. 199 var RelROMap = map[SymKind]SymKind{ 200 STYPE: STYPERELRO, 201 SSTRING: SSTRINGRELRO, 202 SGOSTRING: SGOSTRINGRELRO, 203 SGOFUNC: SGOFUNCRELRO, 204 SGCBITS: SGCBITSRELRO, 205 SRODATA: SRODATARELRO, 206 SFUNCTAB: SFUNCTABRELRO, 207 } 208 209 // IsText returns true if t is a text type. 210 func (t SymKind) IsText() bool { 211 return STEXT <= t && t <= STEXTEND 212 } 213 214 // IsData returns true if t is any kind of data type. 215 func (t SymKind) IsData() bool { 216 return SNOPTRDATA <= t && t <= SNOPTRBSS 217 } 218 219 // IsDATA returns true if t is one of the SDATA types. 220 func (t SymKind) IsDATA() bool { 221 return SDATA <= t && t <= SDATAEND 222 } 223 224 // IsRODATA returns true if t is one of the SRODATA types. 225 func (t SymKind) IsRODATA() bool { 226 return SRODATA <= t && t <= SRODATAEND 227 } 228 229 // IsNOPTRDATA returns true if t is one of the SNOPTRDATA types. 230 func (t SymKind) IsNOPTRDATA() bool { 231 return SNOPTRDATA <= t && t <= SNOPTRDATAEND 232 } 233 234 func (t SymKind) IsDWARF() bool { 235 return SDWARFSECT <= t && t <= SDWARFLINES 236 } 237