mirror of
https://github.com/golang/go
synced 2024-11-23 12:50:12 -07:00
cmd/go: simplify ELF note reading and enable during bootstrap
The bootstrap restriction is to avoid needing cgo for package net. There's no problem with building debug/elf and debug/dwarf, so do that. An upcoming CL is going to add more note processing code, and it simplifies things not to have to think about the code being missing half the time. Change-Id: I0e2f120ac23f14db6ecfcec7bfe254a69abcf7b6 Reviewed-on: https://go-review.googlesource.com/10703 Reviewed-by: Ian Lance Taylor <iant@golang.org>
This commit is contained in:
parent
09a3a092af
commit
a9267db56a
2
src/cmd/dist/build.go
vendored
2
src/cmd/dist/build.go
vendored
@ -891,6 +891,8 @@ var buildorder = []string{
|
||||
"hash",
|
||||
"crypto",
|
||||
"crypto/sha1",
|
||||
"debug/dwarf",
|
||||
"debug/elf",
|
||||
"cmd/go",
|
||||
}
|
||||
|
||||
|
@ -36,7 +36,3 @@ func httpsOrHTTP(importPath string) (string, io.ReadCloser, error) {
|
||||
func parseMetaGoImports(r io.Reader) ([]metaImport, error) {
|
||||
panic("unreachable")
|
||||
}
|
||||
|
||||
func readnote(a, b string, t int32) ([]byte, error) {
|
||||
return nil, nil
|
||||
}
|
||||
|
@ -751,9 +751,9 @@ func goFilesPackage(gofiles []string) *Package {
|
||||
}
|
||||
|
||||
func readpkglist(shlibpath string) []*Package {
|
||||
pkglistbytes, err := readnote(shlibpath, "GO\x00\x00", 1)
|
||||
pkglistbytes, err := readELFNote(shlibpath, "GO\x00\x00", 1)
|
||||
if err != nil {
|
||||
fatalf("readnote failed: %v", err)
|
||||
fatalf("readELFNote failed: %v", err)
|
||||
}
|
||||
scanner := bufio.NewScanner(bytes.NewBuffer(pkglistbytes))
|
||||
var pkgs []*Package
|
||||
|
@ -2,11 +2,6 @@
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
// +build !cmd_go_bootstrap
|
||||
|
||||
// This is not built when bootstrapping to avoid having go_bootstrap depend on
|
||||
// debug/elf.
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
@ -16,21 +11,8 @@ import (
|
||||
"io"
|
||||
)
|
||||
|
||||
func rnd(v int32, r int32) int32 {
|
||||
if r <= 0 {
|
||||
return v
|
||||
}
|
||||
v += r - 1
|
||||
c := v % r
|
||||
if c < 0 {
|
||||
c += r
|
||||
}
|
||||
v -= c
|
||||
return v
|
||||
}
|
||||
|
||||
func readwithpad(r io.Reader, sz int32) ([]byte, error) {
|
||||
full := rnd(sz, 4)
|
||||
func readAligned4(r io.Reader, sz int32) ([]byte, error) {
|
||||
full := (sz + 3) &^ 3
|
||||
data := make([]byte, full)
|
||||
_, err := io.ReadFull(r, data)
|
||||
if err != nil {
|
||||
@ -40,7 +22,7 @@ func readwithpad(r io.Reader, sz int32) ([]byte, error) {
|
||||
return data, nil
|
||||
}
|
||||
|
||||
func readnote(filename, name string, typ int32) ([]byte, error) {
|
||||
func readELFNote(filename, name string, typ int32) ([]byte, error) {
|
||||
f, err := elf.Open(filename)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@ -67,11 +49,11 @@ func readnote(filename, name string, typ int32) ([]byte, error) {
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("read type failed: %v", err)
|
||||
}
|
||||
noteName, err := readwithpad(r, namesize)
|
||||
noteName, err := readAligned4(r, namesize)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("read name failed: %v", err)
|
||||
}
|
||||
desc, err := readwithpad(r, descsize)
|
||||
desc, err := readAligned4(r, descsize)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("read desc failed: %v", err)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user