]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/go: simplify ELF note reading and enable during bootstrap
authorRuss Cox <rsc@golang.org>
Thu, 4 Jun 2015 18:17:51 +0000 (14:17 -0400)
committerRuss Cox <rsc@golang.org>
Fri, 5 Jun 2015 03:53:14 +0000 (03:53 +0000)
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>
src/cmd/dist/build.go
src/cmd/go/bootstrap.go
src/cmd/go/build.go
src/cmd/go/note.go

index fed3f6791c66f0c214bf9b0e61e1fd2aa97e8790..5da0b90e48c8de77928556a82dac5ceed9ab1a77 100644 (file)
@@ -891,6 +891,8 @@ var buildorder = []string{
        "hash",
        "crypto",
        "crypto/sha1",
+       "debug/dwarf",
+       "debug/elf",
        "cmd/go",
 }
 
index c6f569ed1c96c2bb48931ae51eaf5046f2a70e27..0c13380054847586e2fa943dbb467ff94bcd956a 100644 (file)
@@ -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
-}
index ec74ea41330c310371f20f6a1f32b44e69dbb3b9..030c73d46e827f0ba423ec9a62a5c81b82a318fa 100644 (file)
@@ -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
index 6da8a981cca8ca2dabe85392cb514eec7dadbded..9eb7b18a128bac2e1eacfa402a897860d5c1cb26 100644 (file)
@@ -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)
                        }