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

View as plain text