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

View as plain text