// Copyright 2013 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. // Package gccgoimporter implements Import for gccgo-generated object files. package gccgoimporter // import "llvm.org/llgo/third_party/gotools/go/gccgoimporter" import ( "bytes" "debug/elf" "fmt" "io" "io/ioutil" "os" "os/exec" "path/filepath" "strings" "llvm.org/llgo/third_party/gotools/go/importer" "llvm.org/llgo/third_party/gotools/go/types" ) // A PackageInit describes an imported package that needs initialization. type PackageInit struct { Name string // short package name InitFunc string // name of init function Priority int // priority of init function, see InitData.Priority } // The gccgo-specific init data for a package. type InitData struct { // Initialization priority of this package relative to other packages. // This is based on the maximum depth of the package's dependency graph; // it is guaranteed to be greater than that of its dependencies. Priority int // The list of packages which this package depends on to be initialized, // including itself if needed. This is the subset of the transitive closure of // the package's dependencies that need initialization. Inits []PackageInit } // Locate the file from which to read export data. // This is intended to replicate the logic in gofrontend. func findExportFile(searchpaths []string, pkgpath string) (string, error) { for _, spath := range searchpaths { pkgfullpath := filepath.Join(spath, pkgpath) pkgdir, name := filepath.Split(pkgfullpath) for _, filepath := range [...]string{ pkgfullpath, pkgfullpath + ".gox", pkgdir + "lib" + name + ".so", pkgdir + "lib" + name + ".a", pkgfullpath + ".o", } { fi, err := os.Stat(filepath) if err == nil && !fi.IsDir() { return filepath, nil } } } return "", fmt.Errorf("%s: could not find export data (tried %s)", pkgpath, strings.Join(searchpaths, ":")) } const ( gccgov1Magic = "v1;\n" goimporterMagic = "\n$$ " archiveMagic = "!