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{ ...@@ -891,6 +891,8 @@ var buildorder = []string{
"hash", "hash",
"crypto", "crypto",
"crypto/sha1", "crypto/sha1",
"debug/dwarf",
"debug/elf",
"cmd/go", "cmd/go",
} }
......
...@@ -36,7 +36,3 @@ func httpsOrHTTP(importPath string) (string, io.ReadCloser, error) { ...@@ -36,7 +36,3 @@ func httpsOrHTTP(importPath string) (string, io.ReadCloser, error) {
func parseMetaGoImports(r io.Reader) ([]metaImport, error) { func parseMetaGoImports(r io.Reader) ([]metaImport, error) {
panic("unreachable") panic("unreachable")
} }
func readnote(a, b string, t int32) ([]byte, error) {
return nil, nil
}
...@@ -751,9 +751,9 @@ func goFilesPackage(gofiles []string) *Package { ...@@ -751,9 +751,9 @@ func goFilesPackage(gofiles []string) *Package {
} }
func readpkglist(shlibpath 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 { if err != nil {
fatalf("readnote failed: %v", err) fatalf("readELFNote failed: %v", err)
} }
scanner := bufio.NewScanner(bytes.NewBuffer(pkglistbytes)) scanner := bufio.NewScanner(bytes.NewBuffer(pkglistbytes))
var pkgs []*Package var pkgs []*Package
......
...@@ -2,11 +2,6 @@ ...@@ -2,11 +2,6 @@
// Use of this source code is governed by a BSD-style // Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file. // 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 package main
import ( import (
...@@ -16,21 +11,8 @@ import ( ...@@ -16,21 +11,8 @@ import (
"io" "io"
) )
func rnd(v int32, r int32) int32 { func readAligned4(r io.Reader, sz int32) ([]byte, error) {
if r <= 0 { full := (sz + 3) &^ 3
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)
data := make([]byte, full) data := make([]byte, full)
_, err := io.ReadFull(r, data) _, err := io.ReadFull(r, data)
if err != nil { if err != nil {
...@@ -40,7 +22,7 @@ func readwithpad(r io.Reader, sz int32) ([]byte, error) { ...@@ -40,7 +22,7 @@ func readwithpad(r io.Reader, sz int32) ([]byte, error) {
return data, nil 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) f, err := elf.Open(filename)
if err != nil { if err != nil {
return nil, err return nil, err
...@@ -67,11 +49,11 @@ func readnote(filename, name string, typ int32) ([]byte, error) { ...@@ -67,11 +49,11 @@ func readnote(filename, name string, typ int32) ([]byte, error) {
if err != nil { if err != nil {
return nil, fmt.Errorf("read type failed: %v", err) return nil, fmt.Errorf("read type failed: %v", err)
} }
noteName, err := readwithpad(r, namesize) noteName, err := readAligned4(r, namesize)
if err != nil { if err != nil {
return nil, fmt.Errorf("read name failed: %v", err) return nil, fmt.Errorf("read name failed: %v", err)
} }
desc, err := readwithpad(r, descsize) desc, err := readAligned4(r, descsize)
if err != nil { if err != nil {
return nil, fmt.Errorf("read desc failed: %v", err) 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