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  	SMACHORELROSECT
    89  
    90  	// Part of .data.rel.ro if it exists, otherwise part of .rodata.
    91  	STYPELINK
    92  	SITABLINK
    93  	SSYMTAB
    94  	SPCLNTAB
    95  
    96  	// Writable sections.
    97  	SFirstWritable
    98  	SBUILDINFO
    99  	SFIPSINFO
   100  	SELFSECT
   101  	SMACHO
   102  	SMACHOGOT
   103  	SWINDOWS
   104  	SELFGOT
   105  	SNOPTRDATA
   106  	SNOPTRDATAFIPSSTART
   107  	SNOPTRDATAFIPS
   108  	SNOPTRDATAFIPSEND
   109  	SNOPTRDATAEND
   110  	SINITARR
   111  	SDATA
   112  	SDATAFIPSSTART
   113  	SDATAFIPS
   114  	SDATAFIPSEND
   115  	SDATAEND
   116  	SXCOFFTOC
   117  	SBSS
   118  	SNOPTRBSS
   119  	SLIBFUZZER_8BIT_COUNTER
   120  	SCOVERAGE_COUNTER
   121  	SCOVERAGE_AUXVAR
   122  	STLSBSS
   123  	SXREF
   124  	SMACHOSYMSTR
   125  	SMACHOSYMTAB
   126  	SMACHOINDIRECTPLT
   127  	SMACHOINDIRECTGOT
   128  	SFILEPATH
   129  	SDYNIMPORT
   130  	SHOSTOBJ
   131  	SUNDEFEXT // Undefined symbol for resolution by external linker
   132  
   133  	// Sections for debugging information
   134  	SDWARFSECT
   135  	// DWARF symbol types
   136  	SDWARFCUINFO
   137  	SDWARFCONST
   138  	SDWARFFCN
   139  	SDWARFABSFCN
   140  	SDWARFTYPE
   141  	SDWARFVAR
   142  	SDWARFRANGE
   143  	SDWARFLOC
   144  	SDWARFLINES
   145  	SDWARFADDR
   146  
   147  	// SEH symbol types
   148  	SSEHUNWINDINFO
   149  	SSEHSECT
   150  )
   151  
   152  // AbiSymKindToSymKind maps values read from object files (which are
   153  // of type cmd/internal/objabi.SymKind) to values of type SymKind.
   154  var AbiSymKindToSymKind = [...]SymKind{
   155  	objabi.Sxxx:                    Sxxx,
   156  	objabi.STEXT:                   STEXT,
   157  	objabi.STEXTFIPS:               STEXTFIPS,
   158  	objabi.SRODATA:                 SRODATA,
   159  	objabi.SRODATAFIPS:             SRODATAFIPS,
   160  	objabi.SNOPTRDATA:              SNOPTRDATA,
   161  	objabi.SNOPTRDATAFIPS:          SNOPTRDATAFIPS,
   162  	objabi.SDATA:                   SDATA,
   163  	objabi.SDATAFIPS:               SDATAFIPS,
   164  	objabi.SBSS:                    SBSS,
   165  	objabi.SNOPTRBSS:               SNOPTRBSS,
   166  	objabi.STLSBSS:                 STLSBSS,
   167  	objabi.SDWARFCUINFO:            SDWARFCUINFO,
   168  	objabi.SDWARFCONST:             SDWARFCONST,
   169  	objabi.SDWARFFCN:               SDWARFFCN,
   170  	objabi.SDWARFABSFCN:            SDWARFABSFCN,
   171  	objabi.SDWARFTYPE:              SDWARFTYPE,
   172  	objabi.SDWARFVAR:               SDWARFVAR,
   173  	objabi.SDWARFRANGE:             SDWARFRANGE,
   174  	objabi.SDWARFLOC:               SDWARFLOC,
   175  	objabi.SDWARFLINES:             SDWARFLINES,
   176  	objabi.SDWARFADDR:              SDWARFADDR,
   177  	objabi.SLIBFUZZER_8BIT_COUNTER: SLIBFUZZER_8BIT_COUNTER,
   178  	objabi.SCOVERAGE_COUNTER:       SCOVERAGE_COUNTER,
   179  	objabi.SCOVERAGE_AUXVAR:        SCOVERAGE_AUXVAR,
   180  	objabi.SSEHUNWINDINFO:          SSEHUNWINDINFO,
   181  }
   182  
   183  // ReadOnly are the symbol kinds that form read-only sections. In some
   184  // cases, if they will require relocations, they are transformed into
   185  // rel-ro sections using relROMap.
   186  var ReadOnly = []SymKind{
   187  	STYPE,
   188  	SSTRING,
   189  	SGOSTRING,
   190  	SGOFUNC,
   191  	SGCBITS,
   192  	SRODATA,
   193  	SRODATAFIPSSTART,
   194  	SRODATAFIPS,
   195  	SRODATAFIPSEND,
   196  	SRODATAEND,
   197  	SFUNCTAB,
   198  }
   199  
   200  // RelROMap describes the transformation of read-only symbols to rel-ro
   201  // symbols.
   202  var RelROMap = map[SymKind]SymKind{
   203  	STYPE:     STYPERELRO,
   204  	SSTRING:   SSTRINGRELRO,
   205  	SGOSTRING: SGOSTRINGRELRO,
   206  	SGOFUNC:   SGOFUNCRELRO,
   207  	SGCBITS:   SGCBITSRELRO,
   208  	SRODATA:   SRODATARELRO,
   209  	SFUNCTAB:  SFUNCTABRELRO,
   210  }
   211  
   212  // IsText returns true if t is a text type.
   213  func (t SymKind) IsText() bool {
   214  	return STEXT <= t && t <= STEXTEND
   215  }
   216  
   217  // IsData returns true if t is any kind of data type.
   218  func (t SymKind) IsData() bool {
   219  	return SNOPTRDATA <= t && t <= SNOPTRBSS
   220  }
   221  
   222  // IsDATA returns true if t is one of the SDATA types.
   223  func (t SymKind) IsDATA() bool {
   224  	return SDATA <= t && t <= SDATAEND
   225  }
   226  
   227  // IsRODATA returns true if t is one of the SRODATA types.
   228  func (t SymKind) IsRODATA() bool {
   229  	return SRODATA <= t && t <= SRODATAEND
   230  }
   231  
   232  // IsNOPTRDATA returns true if t is one of the SNOPTRDATA types.
   233  func (t SymKind) IsNOPTRDATA() bool {
   234  	return SNOPTRDATA <= t && t <= SNOPTRDATAEND
   235  }
   236  
   237  func (t SymKind) IsDWARF() bool {
   238  	return SDWARFSECT <= t && t <= SDWARFADDR
   239  }
   240  

View as plain text