Commit a9267db5 authored by Russ Cox's avatar Russ Cox

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/10703Reviewed-by: 's avatarIan Lance Taylor <iant@golang.org>
parent 09a3a092
......@@ -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)
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment