...

Source file src/cmd/link/internal/sym/symkind.go

Documentation: cmd/link/internal/sym

     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  	SELFRELROSECT
    80  
    81  	// Part of .data.rel.ro if it exists, otherwise part of .rodata.
    82  	STYPELINK
    83  	SITABLINK
    84  	SSYMTAB
    85  	SPCLNTAB
    86  
    87  	// Writable sections.
    88  	SFirstWritable
    89  	SBUILDINFO
    90  	SELFSECT
    91  	SMACHO
    92  	SMACHOGOT
    93  	SWINDOWS
    94  	SELFGOT
    95  	SNOPTRDATA
    96  	SINITARR
    97  	SDATA
    98  	SXCOFFTOC
    99  	SBSS
   100  	SNOPTRBSS
   101  	SLIBFUZZER_8BIT_COUNTER
   102  	SCOVERAGE_COUNTER
   103  	SCOVERAGE_AUXVAR
   104  	STLSBSS
   105  	SXREF
   106  	SMACHOSYMSTR
   107  	SMACHOSYMTAB
   108  	SMACHOINDIRECTPLT
   109  	SMACHOINDIRECTGOT
   110  	SFILEPATH
   111  	SDYNIMPORT
   112  	SHOSTOBJ
   113  	SUNDEFEXT // Undefined symbol for resolution by external linker
   114  
   115  	// Sections for debugging information
   116  	SDWARFSECT
   117  	// DWARF symbol types
   118  	SDWARFCUINFO
   119  	SDWARFCONST
   120  	SDWARFFCN
   121  	SDWARFABSFCN
   122  	SDWARFTYPE
   123  	SDWARFVAR
   124  	SDWARFRANGE
   125  	SDWARFLOC
   126  	SDWARFLINES
   127  
   128  	// SEH symbol types
   129  	SSEHUNWINDINFO
   130  	SSEHSECT
   131  )
   132  
   133  // AbiSymKindToSymKind maps values read from object files (which are
   134  // of type cmd/internal/objabi.SymKind) to values of type SymKind.
   135  var AbiSymKindToSymKind = [...]SymKind{
   136  	objabi.Sxxx:                    Sxxx,
   137  	objabi.STEXT:                   STEXT,
   138  	objabi.SRODATA:                 SRODATA,
   139  	objabi.SNOPTRDATA:              SNOPTRDATA,
   140  	objabi.SDATA:                   SDATA,
   141  	objabi.SBSS:                    SBSS,
   142  	objabi.SNOPTRBSS:               SNOPTRBSS,
   143  	objabi.STLSBSS:                 STLSBSS,
   144  	objabi.SDWARFCUINFO:            SDWARFCUINFO,
   145  	objabi.SDWARFCONST:             SDWARFCONST,
   146  	objabi.SDWARFFCN:               SDWARFFCN,
   147  	objabi.SDWARFABSFCN:            SDWARFABSFCN,
   148  	objabi.SDWARFTYPE:              SDWARFTYPE,
   149  	objabi.SDWARFVAR:               SDWARFVAR,
   150  	objabi.SDWARFRANGE:             SDWARFRANGE,
   151  	objabi.SDWARFLOC:               SDWARFLOC,
   152  	objabi.SDWARFLINES:             SDWARFLINES,
   153  	objabi.SLIBFUZZER_8BIT_COUNTER: SLIBFUZZER_8BIT_COUNTER,
   154  	objabi.SCOVERAGE_COUNTER:       SCOVERAGE_COUNTER,
   155  	objabi.SCOVERAGE_AUXVAR:        SCOVERAGE_AUXVAR,
   156  	objabi.SSEHUNWINDINFO:          SSEHUNWINDINFO,
   157  }
   158  
   159  // ReadOnly are the symbol kinds that form read-only sections. In some
   160  // cases, if they will require relocations, they are transformed into
   161  // rel-ro sections using relROMap.
   162  var ReadOnly = []SymKind{
   163  	STYPE,
   164  	SSTRING,
   165  	SGOSTRING,
   166  	SGOFUNC,
   167  	SGCBITS,
   168  	SRODATA,
   169  	SFUNCTAB,
   170  }
   171  
   172  // RelROMap describes the transformation of read-only symbols to rel-ro
   173  // symbols.
   174  var RelROMap = map[SymKind]SymKind{
   175  	STYPE:     STYPERELRO,
   176  	SSTRING:   SSTRINGRELRO,
   177  	SGOSTRING: SGOSTRINGRELRO,
   178  	SGOFUNC:   SGOFUNCRELRO,
   179  	SGCBITS:   SGCBITSRELRO,
   180  	SRODATA:   SRODATARELRO,
   181  	SFUNCTAB:  SFUNCTABRELRO,
   182  }
   183  
   184  // IsData returns true if the type is a data type.
   185  func (t SymKind) IsData() bool {
   186  	return t == SDATA || t == SNOPTRDATA || t == SBSS || t == SNOPTRBSS
   187  }
   188  
   189  func (t SymKind) IsDWARF() bool {
   190  	return t >= SDWARFSECT && t <= SDWARFLINES
   191  }
   192  

View as plain text