From a9267db56abaa2ee68a27d78a5b12083f2a25a49 Mon Sep 17 00:00:00 2001 From: Russ Cox Date: Thu, 4 Jun 2015 14:17:51 -0400 Subject: [PATCH] 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 --- src/cmd/dist/build.go | 2 ++ src/cmd/go/bootstrap.go | 4 ---- src/cmd/go/build.go | 4 ++-- src/cmd/go/note.go | 28 +++++----------------------- 4 files changed, 9 insertions(+), 29 deletions(-) diff --git a/src/cmd/dist/build.go b/src/cmd/dist/build.go index fed3f6791c6..5da0b90e48c 100644 --- a/src/cmd/dist/build.go +++ b/src/cmd/dist/build.go @@ -891,6 +891,8 @@ var buildorder = []string{ "hash", "crypto", "crypto/sha1", + "debug/dwarf", + "debug/elf", "cmd/go", } diff --git a/src/cmd/go/bootstrap.go b/src/cmd/go/bootstrap.go index c6f569ed1c9..0c133800548 100644 --- a/src/cmd/go/bootstrap.go +++ b/src/cmd/go/bootstrap.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 -} diff --git a/src/cmd/go/build.go b/src/cmd/go/build.go index ec74ea41330..030c73d46e8 100644 --- a/src/cmd/go/build.go +++ b/src/cmd/go/build.go @@ -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 diff --git a/src/cmd/go/note.go b/src/cmd/go/note.go index 6da8a981cca..9eb7b18a128 100644 --- a/src/cmd/go/note.go +++ b/src/cmd/go/note.go @@ -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) }