github.com/rakyll/go@v0.0.0-20170216000551-64c02460d703/src/cmd/internal/obj/sym.go (about)

     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 obj
    33  
    34  import (
    35  	"log"
    36  	"os"
    37  	"path/filepath"
    38  )
    39  
    40  // WorkingDir returns the current working directory
    41  // (or "/???" if the directory cannot be identified),
    42  // with "/" as separator.
    43  func WorkingDir() string {
    44  	var path string
    45  	path, _ = os.Getwd()
    46  	if path == "" {
    47  		path = "/???"
    48  	}
    49  	return filepath.ToSlash(path)
    50  }
    51  
    52  func Linknew(arch *LinkArch) *Link {
    53  	ctxt := new(Link)
    54  	ctxt.Hash = make(map[SymVer]*LSym)
    55  	ctxt.Arch = arch
    56  	ctxt.Version = HistVersion
    57  	ctxt.Pathname = WorkingDir()
    58  
    59  	ctxt.Headtype.Set(GOOS)
    60  	if ctxt.Headtype < 0 {
    61  		log.Fatalf("unknown goos %s", GOOS)
    62  	}
    63  
    64  	ctxt.Flag_optimize = true
    65  	ctxt.Framepointer_enabled = Framepointer_enabled(GOOS, arch.Name)
    66  	return ctxt
    67  }
    68  
    69  func Linklookup(ctxt *Link, name string, v int) *LSym {
    70  	s := ctxt.Hash[SymVer{name, v}]
    71  	if s != nil {
    72  		return s
    73  	}
    74  
    75  	s = &LSym{
    76  		Name:    name,
    77  		Type:    0,
    78  		Version: int16(v),
    79  		Size:    0,
    80  	}
    81  	ctxt.Hash[SymVer{name, v}] = s
    82  	return s
    83  }
    84  
    85  func Linksymfmt(s *LSym) string {
    86  	if s == nil {
    87  		return "<nil>"
    88  	}
    89  	return s.Name
    90  }