...

Source file src/pkg/cmd/link/internal/ld/sym.go

     1	// Derived from Inferno utils/6l/obj.c and utils/6l/span.c
     2	// https://bitbucket.org/inferno-os/inferno-os/src/default/utils/6l/obj.c
     3	// https://bitbucket.org/inferno-os/inferno-os/src/default/utils/6l/span.c
     4	//
     5	//	Copyright © 1994-1999 Lucent Technologies Inc.  All rights reserved.
     6	//	Portions Copyright © 1995-1997 C H Forsyth (forsyth@terzarima.net)
     7	//	Portions Copyright © 1997-1999 Vita Nuova Limited
     8	//	Portions Copyright © 2000-2007 Vita Nuova Holdings Limited (www.vitanuova.com)
     9	//	Portions Copyright © 2004,2006 Bruce Ellis
    10	//	Portions Copyright © 2005-2007 C H Forsyth (forsyth@terzarima.net)
    11	//	Revisions Copyright © 2000-2007 Lucent Technologies Inc. and others
    12	//	Portions Copyright © 2009 The Go Authors. All rights reserved.
    13	//
    14	// Permission is hereby granted, free of charge, to any person obtaining a copy
    15	// of this software and associated documentation files (the "Software"), to deal
    16	// in the Software without restriction, including without limitation the rights
    17	// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
    18	// copies of the Software, and to permit persons to whom the Software is
    19	// furnished to do so, subject to the following conditions:
    20	//
    21	// The above copyright notice and this permission notice shall be included in
    22	// all copies or substantial portions of the Software.
    23	//
    24	// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
    25	// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
    26	// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
    27	// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
    28	// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
    29	// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
    30	// THE SOFTWARE.
    31	
    32	package ld
    33	
    34	import (
    35		"cmd/internal/objabi"
    36		"cmd/internal/sys"
    37		"cmd/link/internal/sym"
    38		"log"
    39	)
    40	
    41	func linknew(arch *sys.Arch) *Link {
    42		ctxt := &Link{
    43			Syms:         sym.NewSymbols(),
    44			Out:          &OutBuf{arch: arch},
    45			Arch:         arch,
    46			LibraryByPkg: make(map[string]*sym.Library),
    47		}
    48	
    49		if objabi.GOARCH != arch.Name {
    50			log.Fatalf("invalid objabi.GOARCH %s (want %s)", objabi.GOARCH, arch.Name)
    51		}
    52	
    53		AtExit(func() {
    54			if nerrors > 0 && ctxt.Out.f != nil {
    55				ctxt.Out.f.Close()
    56				mayberemoveoutfile()
    57			}
    58		})
    59	
    60		return ctxt
    61	}
    62	
    63	// computeTLSOffset records the thread-local storage offset.
    64	// Not used for Android where the TLS offset is determined at runtime.
    65	func (ctxt *Link) computeTLSOffset() {
    66		switch ctxt.HeadType {
    67		default:
    68			log.Fatalf("unknown thread-local storage offset for %v", ctxt.HeadType)
    69	
    70		case objabi.Hplan9, objabi.Hwindows, objabi.Hjs, objabi.Haix:
    71			break
    72	
    73			/*
    74			 * ELF uses TLS offset negative from FS.
    75			 * Translate 0(FS) and 8(FS) into -16(FS) and -8(FS).
    76			 * Known to low-level assembly in package runtime and runtime/cgo.
    77			 */
    78		case objabi.Hlinux,
    79			objabi.Hfreebsd,
    80			objabi.Hnetbsd,
    81			objabi.Hopenbsd,
    82			objabi.Hdragonfly,
    83			objabi.Hsolaris:
    84			ctxt.Tlsoffset = -1 * ctxt.Arch.PtrSize
    85	
    86		case objabi.Hnacl:
    87			switch ctxt.Arch.Family {
    88			default:
    89				log.Fatalf("unknown thread-local storage offset for nacl/%s", ctxt.Arch.Name)
    90	
    91			case sys.ARM:
    92				ctxt.Tlsoffset = 0
    93	
    94			case sys.AMD64:
    95				ctxt.Tlsoffset = 0
    96	
    97			case sys.I386:
    98				ctxt.Tlsoffset = -8
    99			}
   100	
   101			/*
   102			 * OS X system constants - offset from 0(GS) to our TLS.
   103			 */
   104		case objabi.Hdarwin:
   105			switch ctxt.Arch.Family {
   106			default:
   107				log.Fatalf("unknown thread-local storage offset for darwin/%s", ctxt.Arch.Name)
   108	
   109				/*
   110				 * For x86, Apple has reserved a slot in the TLS for Go. See issue 23617.
   111				 * That slot is at offset 0x30 on amd64, and 0x18 on 386.
   112				 * The slot will hold the G pointer.
   113				 * These constants should match those in runtime/sys_darwin_{386,amd64}.s
   114				 * and runtime/cgo/gcc_darwin_{386,amd64}.c.
   115				 */
   116			case sys.I386:
   117				ctxt.Tlsoffset = 0x18
   118	
   119			case sys.AMD64:
   120				ctxt.Tlsoffset = 0x30
   121	
   122			case sys.ARM:
   123				ctxt.Tlsoffset = 0 // dummy value, not needed
   124	
   125			case sys.ARM64:
   126				ctxt.Tlsoffset = 0 // dummy value, not needed
   127			}
   128		}
   129	
   130	}
   131	

View as plain text