1
0
mirror of https://github.com/golang/go synced 2024-10-03 09:31:23 -06:00
Commit Graph

3928 Commits

Author SHA1 Message Date
Rémy Oudompheng
80d2eac14d cmd/cgo: don't reimplement os/exec in util.go.
R=golang-dev, rsc
CC=golang-dev
https://golang.org/cl/7450049
2013-03-01 15:04:14 -05:00
Russ Cox
8d732368c2 cmd/ld: fix windows build
Fixes #4948.

R=golang-dev, alex.brainman
CC=golang-dev
https://golang.org/cl/7445045
2013-03-01 05:03:25 -08:00
Russ Cox
7556ccc7b1 cmd/cgo, cmd/ld: new cgo object file section
Switch to new pragma names, but leave old ones available for now.
Merge the three cgo-related sections in the .6 files into a single
cgo section.

R=golang-dev, iant, ality
CC=golang-dev
https://golang.org/cl/7424048
2013-03-01 00:27:57 -05:00
Russ Cox
40ed753ebd cmd/ld: fix symbol table sorting
runtime: double-check that symbol table is sorted

If the symbol table is unsorted, the binary search in findfunc
will not find its func, which will make stack traces stop early.
When the garbage collector starts using the stack tracer,
that would be a serious problem.

The unsorted symbol addresses came from from two things:

1. The symbols in an ELF object are not necessarily sorted,
   so sort them before adding them to the symbol list.

2. The __i686.get_pc_thunk.bx symbol is present in multiple
   object files and was having its address adjusted multiple
   times, producing an incorrect address in the symbol table.

R=golang-dev, iant
CC=golang-dev
https://golang.org/cl/7440044
2013-02-28 16:21:58 -05:00
Rob Pike
3dc7f17e89 cmd/vet: %b is a valid floating-point format.
Also add a report about "invalid type" from gotype, if -v is set.

R=golang-dev, bradfitz
CC=golang-dev
https://golang.org/cl/7420045
2013-02-28 11:32:53 -08:00
Robin Eklind
f82ea304f0 cgo: fix reference to puts in implementation comment.
R=golang-dev, r
CC=golang-dev
https://golang.org/cl/7431046
2013-02-28 11:31:52 -08:00
Russ Cox
b89000bcab cmd/cgo: extend implementation comment
This is the plan for how to make host linking work with
the rest of the system.

There are two complications:

1. It is a goal to preserve the property that pure Go programs
(even ones importing "net") can be compiled without needing
gcc, so that a Go toolchain download works out of the box.
This forces the support for two linking modes: with and without
gcc.

2. It is a goal to allow users with old copies of SWIG to continue
to use those copies. This forces the support for "internal only"
packages. Perhaps it is reasonable to require a new SWIG.
I don't know.

R=iant
CC=golang-dev
https://golang.org/cl/7433043
2013-02-28 10:44:29 -08:00
Shenghou Ma
6ecb39fce6 cmd/go: fix "go run" cgo source when cgo is disabled
also move a cgo-depend test to appropriate source file in runtime.

R=golang-dev, dave, adg, rsc
CC=golang-dev
https://golang.org/cl/7393063
2013-02-28 16:07:26 +08:00
Russ Cox
062a239046 cmd/cgo: add implementation comment
R=golang-dev, r, bradfitz, iant
CC=golang-dev
https://golang.org/cl/7407050
2013-02-27 20:55:01 -08:00
Rob Pike
9e19337de9 cmd/vet: continue past first error
Also delete bogus tests for f.pkg (does the file have a package) since all
files have a package attached. The tests for pkg.types and pkg.values
suffice.

R=golang-dev, adg
CC=golang-dev
https://golang.org/cl/7418043
2013-02-27 15:43:33 -08:00
Daniel Morsing
43c04ba1b8 cmd/gc: don't emit type instructions for nonexisting locals
If all locals are optimized away, the type instructions would stay in the instruction stream. Call fixautoused to scrub the output.

Fixes #4915.

R=rsc
CC=golang-dev
https://golang.org/cl/7385055
2013-02-27 19:47:14 +01:00
Russ Cox
56a06db360 cmd/ld: change GC_CALL to 32-bit relative address
The current code uses 64-bit pc-relative on 64-bit systems,
but in ELF linkers there is no such thing, so we cannot
express this in a .o file. Change to 32-bit.

R=golang-dev, iant
CC=golang-dev
https://golang.org/cl/7383055
2013-02-26 19:42:56 -08:00
Russ Cox
c8dcaeb25d cmd/ld, runtime: adjust symbol table representation
This CL changes the encoding used for the Go symbol table,
stored in the binary and used at run time. It does not change
any of the semantics or structure: the bits are just packed
a little differently.

The comment at the top of runtime/symtab.c describes the new format.

Compared to the Go 1.0 format, the main changes are:

* Store symbol addresses as full-pointer-sized host-endian values.
  (For 6g, this means addresses are 64-bit little-endian.)

* Store other values (frame sizes and so on) varint-encoded.

The second change more than compensates for the first:
for the godoc binary on OS X/amd64, the new symbol table
is 8% smaller than the old symbol table (1,425,668 down from 1,546,276).

This is a required step for allowing the host linker (gcc) to write
the final Go binary, since it will have to fill in the symbol address slots
(so the slots must be host-endian) and on 64-bit systems it may
choose addresses above 4 GB.

R=golang-dev, iant
CC=golang-dev
https://golang.org/cl/7403054
2013-02-26 22:38:14 -05:00
Rob Pike
6c2cbdb142 cmd/vet: fix printf test for unsafe Pointer
And fix test. Pointer to unsafe.Pointer tests nothing important...
Also identify the incorrect type: go/types.Type is a Stringer.

Also fix a couple of incorrect format verbs found by new printf checker,
now that we can run it on more files.

R=golang-dev, rsc
CC=golang-dev
https://golang.org/cl/7385051
2013-02-26 10:36:13 -08:00
Anthony Martin
2b39e418be all: clean up C function prototypes
R=minux.ma, rsc, akumar, bradfitz
CC=golang-dev
https://golang.org/cl/7313070
2013-02-26 09:51:33 -08:00
Anthony Martin
f08acae76e build: do not set GOBIN on Plan 9
Also, I synced the rc files with changes
that have been made to make.bash, etc.

R=seed, rminnich, r
CC=golang-dev
https://golang.org/cl/7389049
2013-02-26 09:25:46 -08:00
Anthony Martin
c14d255ac5 cmd/go: do not print GCC environment variables on Plan 9
R=seed, rminnich, r, minux.ma
CC=golang-dev
https://golang.org/cl/7397059
2013-02-26 08:34:47 -08:00
Cosmos Nicolaou
d6a057c90e cmd/godoc: add support for display Notes parsed by pkg/go/doc
pkg/go/doc: move BUG notes from Package.Bugs to the general Package.Notes field.
Removing .Bugs would break existing code so it's left in for now.

R=gri, gri, gary.burd, dsymonds, rsc, kevlar
CC=golang-dev
https://golang.org/cl/7341053
2013-02-25 20:34:09 -08:00
Rob Pike
78b3ef261d cmd/vet: silence error from type checker unless verbose is set.
Also restores the checking of _test.go files, which disappeared
as a result of the package-at-a-time change.
Fixes #4895.

R=golang-dev, rsc
CC=golang-dev
https://golang.org/cl/7399051
2013-02-25 16:29:09 -08:00
Rob Pike
31444a796a cmd/vet: move the tests into separate files
Then mark them with a build tag so they're not compiled into the binary.
They are called test_*.go rather than *_test.go because they are not
for go test. Use make test to test the command.

R=golang-dev, adg
CC=golang-dev
https://golang.org/cl/7377052
2013-02-25 16:25:34 -08:00
Rémy Oudompheng
71b3b46073 cmd/gc: accept cases with same value but different types in switch.
Fixes #4781.

R=golang-dev, rsc
CC=golang-dev
https://golang.org/cl/7365056
2013-02-26 00:45:43 +01:00
Rémy Oudompheng
9e66ee4562 cmd/gc: fix corruption in export of &T{} literals.
Composite literals using the &T{} form were incorrectly
exported, leading to weird errors at import time.

Fixes #4879.

R=golang-dev, rsc
CC=golang-dev
https://golang.org/cl/7395054
2013-02-26 00:43:31 +01:00
Rémy Oudompheng
9fe60801ae cmd/gc: apply escape analysis results to closures.
This avoids an allocation when closures are used
as "macros", in Walk idioms, or as argument to defer.

benchmark                old ns/op    new ns/op    delta
BenchmarkSearchWrappers       1171          354  -69.77%
BenchmarkCallClosure             3            3  -12.54%
BenchmarkCallClosure1          119            7  -93.95%
BenchmarkCallClosure2          183           74  -59.18%
BenchmarkCallClosure3          187           75  -59.57%
BenchmarkCallClosure4          187           76  -58.98%

Compared to Go 1:
benchmark                  old ns/op    new ns/op    delta
BenchmarkSearchWrappers         3208          354  -88.97%

Fixes #3520.

R=daniel.morsing, bradfitz, minux.ma, dave, rsc
CC=golang-dev
https://golang.org/cl/7397056
2013-02-26 00:40:28 +01:00
Shenghou Ma
8cdee79063 libmach, cmd/5a, cmd/5c, cmd/5g, cmd/5l: enable DWARF type info for Linux/ARM
Fixes #3747.

Update #4912
This CL adds gotype into .5 object file.

R=golang-dev, rsc
CC=golang-dev
https://golang.org/cl/7376054
2013-02-26 06:15:29 +08:00
Russ Cox
aa3efb28f0 cmd/gc: can stop tracking gotype in regopt
Now that the type information is in TYPE instructions
that are not rewritten by the optimization passes,
we don't have to try to preserve the type information
(no longer) attached to MOV instructions.

R=ken2
CC=golang-dev
https://golang.org/cl/7402054
2013-02-25 16:11:34 -05:00
Shenghou Ma
1a01ffd386 cmd/gc: fix mkbuiltin (gc -A always write all symbols to export section)
Regenerate cmd/gc/builtin.c.
Fixes #4908.

R=rsc
CC=golang-dev
https://golang.org/cl/7383053
2013-02-26 03:14:59 +08:00
Francisco Souza
f5afc7d44f cmd/go: fix vet
Now that vet does typechecking, it should use only pkg.gofiles, instead
of pkg.allgofiles. Ignored files should not be checked by vet, because
they wouldn't typecheck.

Fixes #4906.

R=rsc, r
CC=golang-dev
https://golang.org/cl/7401051
2013-02-25 10:43:04 -08:00
Russ Cox
f5dce6c853 cmd/5g: fix arm build
R=ken2
CC=golang-dev
https://golang.org/cl/7365057
2013-02-25 12:21:12 -05:00
Russ Cox
1d5dc4fd48 cmd/gc: emit explicit type information for local variables
The type information is (and for years has been) included
as an extra field in the address chunk of an instruction.
Unfortunately, suppose there is a string at a+24(FP) and
we have an instruction reading its length. It will say:

        MOVQ x+32(FP), AX

and the type of *that* argument is int (not slice), because
it is the length being read. This confuses the picture seen
by debuggers and now, worse, by the garbage collector.

Instead of attaching the type information to all uses,
emit an explicit list of TYPE instructions with the information.
The TYPE instructions are no-ops whose only role is to
provide an address to attach type information to.

For example, this function:

        func f(x, y, z int) (a, b string) {
                return
        }

now compiles into:

        --- prog list "f" ---
        0000 (/Users/rsc/x.go:3) TEXT    f+0(SB),$0-56
        0001 (/Users/rsc/x.go:3) LOCALS  ,
        0002 (/Users/rsc/x.go:3) TYPE    x+0(FP){int},$8
        0003 (/Users/rsc/x.go:3) TYPE    y+8(FP){int},$8
        0004 (/Users/rsc/x.go:3) TYPE    z+16(FP){int},$8
        0005 (/Users/rsc/x.go:3) TYPE    a+24(FP){string},$16
        0006 (/Users/rsc/x.go:3) TYPE    b+40(FP){string},$16
        0007 (/Users/rsc/x.go:3) MOVQ    $0,b+40(FP)
        0008 (/Users/rsc/x.go:3) MOVQ    $0,b+48(FP)
        0009 (/Users/rsc/x.go:3) MOVQ    $0,a+24(FP)
        0010 (/Users/rsc/x.go:3) MOVQ    $0,a+32(FP)
        0011 (/Users/rsc/x.go:4) RET     ,

The { } show the formerly hidden type information.
The { } syntax is used when printing from within the gc compiler.
It is not accepted by the assemblers.

The same type information is now included on global variables:

0055 (/Users/rsc/x.go:15) GLOBL   slice+0(SB){[]string},$24(AL*0)

This more accurate type information fixes a bug in the
garbage collector's precise heap collection.

The linker only cares about globals right now, but having the
local information should make things a little nicer for Carl
in the future.

Fixes #4907.

R=ken2
CC=golang-dev
https://golang.org/cl/7395056
2013-02-25 12:13:47 -05:00
Volker Dobler
d97b975d5c cmd/godoc: show examples in text mode
Added the command line flag -ex to godoc to print examples in
text output.

Samples from the generated output:

$ godoc -ex strings Index
...
func Index(s, sep string) int
    Index returns the index of the first instance of sep in s, or -1 if sep
    is not present in s.

    Example:
        fmt.Println(strings.Index("chicken", "ken"))
        fmt.Println(strings.Index("chicken", "dmr"))
        // Output:
        // 4
        // -1
...

$ godoc -ex container/heap
...
package heap
    import "container/heap"

    Package heap provides heap operations for any type that implements
    heap.Interface. A heap is a tree with the property that each node is the
    minimum-valued node in its subtree.

    Example:
        // This example demonstrates an integer heap built using the heap interface.
        package heap_test

        import (
            "container/heap"
            "fmt"
        ...

    Example:
        // This example demonstrates a priority queue built using the heap interface.
        package heap_test

        import (
            "container/heap"
            "fmt"
        )
...

Fixes #3587.

R=golang-dev, minux.ma, adg, rsc, gri
CC=golang-dev
https://golang.org/cl/7356043
2013-02-25 10:37:17 +11:00
Rob Pike
1174a18c3d cmd/vet: fix up some nits in print.go found by kamil.kisiel@gmail.com
R=golang-dev, kamil.kisiel, bradfitz
CC=golang-dev
https://golang.org/cl/7369049
2013-02-24 13:18:36 -08:00
Rob Pike
83e22f1a47 cmd/vet: eliminate false positives for slices in untagged literal test
Made possible by go/types, as long as the package type-checks OK.

Fixes #4684.

R=golang-dev
CC=golang-dev
https://golang.org/cl/7407045
2013-02-24 13:18:21 -08:00
Shenghou Ma
89ec3a610d cmd/dist: avoid using %ebx on i386.
Or gcc (-fPIC) will complain:
cmd/dist/unix.c: In function ‘cansse2’
cmd/dist/unix.c:774: error: can't find a register in class ‘BREG’ while reloading ‘asm’
cmd/dist/unix.c:774: error: ‘asm’ operand has impossible constraints

This affects bootstrapping on native Darwin/386 where all code is
compiled with -fPIC.

R=golang-dev, iant
CC=golang-dev
https://golang.org/cl/7394047
2013-02-24 22:45:53 +08:00
Rob Pike
72b6daa3ba cmd/vet: check argument types in printf formats
Fixes #4404.

R=gri, rsc
CC=golang-dev
https://golang.org/cl/7378061
2013-02-23 15:08:36 -08:00
Shenghou Ma
eec961470f cmd/cgo, cmd/dist, cmd/go: cgo with clang fixes
1. Workaround the smart clang diagnostics with -Qunused-arguments:
clang: error: argument unused during compilation: '-XXX'
2. if "clang -print-libgcc-file-name" returns non-absolute path, don't
provide that on linker command line.
3. Fix dwarf.PtrType.Size() in cmd/cgo as clang doesn't generate
DW_AT_byte_size for pointer types.
4. Workaround warnings for -Wno-unneeded-internal-declaration with
-Wno-unknown-warning-option.
5. Add -Wno-unused-function.
6. enable race detector test on darwin with clang
(at least Apple clang version 1.7 (tags/Apple/clang-77) works).

Requires CL 7354043.

Update #4829
This should fix most parts of the problem, but one glitch still remains.
DWARF generated by newer clang doesn't differentiate these
two function types:
    void *malloc(size_t);
    void *malloc(unsigned long int);
so you might need to do this to make make.bash pass:
sed -i -e 's/C.malloc(C.size_t/C.malloc(C.ulong/' pkg/os/user/lookup_unix.go

R=golang-dev, dave, iant, rsc
CC=golang-dev
https://golang.org/cl/7351044
2013-02-23 20:24:38 +08:00
Rob Pike
4434212f15 cmd/vet: use types to test Error methods correctly.
We need go/types to discriminate the Error method from
the error interface and the Error method of the testing package.
Fixes #4753.

R=golang-dev, bradfitz, gri
CC=golang-dev
https://golang.org/cl/7396054
2013-02-22 17:16:31 -08:00
Carl Shapiro
66ba4a85e4 cmd/gc: mark LOCALS argument as a constant to print correctly
Fixes #4875.

R=golang-dev, rsc
CC=golang-dev
https://golang.org/cl/7376049
2013-02-22 15:32:54 -08:00
Rob Pike
48f79a95d0 cmd/vet: restructure to be package-driven
This is a simple refactoring of main.go that will enable the type checker
to be used during vetting.
The change has an unimportant effect on the arguments: it now assumes
that all files named explicitly on the command line belong to the same
package. When run by the go command, this was true already.

Also restore a missing parenthesis from an error message.

R=golang-dev, gri, bradfitz
CC=golang-dev
https://golang.org/cl/7393052
2013-02-22 13:32:43 -08:00
Russ Cox
9f647288ef cmd/gc: avoid runtime code generation for closures
Change ARM context register to R7, to get out of the way
of the register allocator during the compilation of the
prologue statements (it wants to use R0 as a temporary).

Step 2 of http://golang.org/s/go11func.

R=ken2
CC=golang-dev
https://golang.org/cl/7369048
2013-02-22 14:25:50 -05:00
Russ Cox
d57fcbf05c cmd/5l, cmd/6l, cmd/8l: accept CALL reg, reg
The new src argument is ignored during linking
(that is, CALL r1, r2 is identical to CALL r2 for linking),
but it serves as a hint to the 5g/6g/8g optimizer
that the src register is live on entry to the called
function and must be preserved.

It is possible to avoid exposing this fact to the rest of
the toolchain, keeping it entirely within 5g/6g/8g,
but I think it will help to be able to look in object files
and assembly listings and linker -a / -W output to
see CALL instructions are "Go func value" calls and
which are "C function pointer" calls.

R=ken2
CC=golang-dev
https://golang.org/cl/7364045
2013-02-22 14:23:21 -05:00
Russ Cox
6066fdcf38 cmd/6g, cmd/8g: switch to DX for indirect call block
runtime: add context argument to gogocall

Too many other things use AX, and at least one
(stack zeroing) cannot be moved onto a different
register. Use the less special DX instead.

Preparation for step 2 of http://golang.org/s/go11func.
Nothing interesting here, just split out so that we can
see it's correct before moving on.

R=ken2
CC=golang-dev
https://golang.org/cl/7395050
2013-02-22 10:47:54 -05:00
Anthony Martin
ed1ac05673 cmd/go: don't call ImportDir unnecessarily
This significantly speeds up the go tool on
slow file systems (or those with cold caches).

The following numbers were obtained using
an encrypted ext4 file system running on
Linux 3.7.9.

# Before
$ sudo sysctl -w 'vm.drop_caches=3'
$ time go list code.google.com/p/go.net/... | wc -l
9

real	0m16.921s
user	0m0.637s
sys	0m0.317s

# After
$ sudo sysctl -w 'vm.drop_caches=3'
$ time go list code.google.com/p/go.net/... | wc -l
9

real	0m8.175s
user	0m0.220s
sys	0m0.177s

R=rsc, r
CC=golang-dev
https://golang.org/cl/7369044
2013-02-21 20:09:31 -08:00
Dave Cheney
6138e368f8 cmd/gc: fix FreeBSD build
R=jsing, mikioh.mikioh, bradfitz
CC=golang-dev
https://golang.org/cl/7390048
2013-02-22 10:28:03 +11:00
Russ Cox
1903ad7189 cmd/gc, reflect, runtime: switch to indirect func value representation
Step 1 of http://golang.org/s/go11func.

R=golang-dev, r, daniel.morsing, remyoudompheng
CC=golang-dev
https://golang.org/cl/7393045
2013-02-21 17:01:13 -05:00
Carl Shapiro
f466617a62 cmd/5g, cmd/5l, cmd/6l, cmd/8l, cmd/gc, cmd/ld, runtime: accurate args and locals information
Previously, the func structure contained an inaccurate value for
the args member and a 0 value for the locals member.

This change populates the func structure with args and locals
values computed by the compiler.  The number of args was
already available in the ATEXT instruction.  The number of
locals is now passed through in the new ALOCALS instruction.

This change also switches the unit of args and locals to be
bytes, just like the frame member, instead of 32-bit words.

R=golang-dev, bradfitz, cshapiro, dave, rsc
CC=golang-dev
https://golang.org/cl/7399045
2013-02-21 12:52:26 -08:00
Russ Cox
0cdc0b3b78 cmd/5g, cmd/6g: fix node dump formats
lvd changed the old %N to %+hN and these
never got updated.

R=ken2
CC=golang-dev
https://golang.org/cl/7391045
2013-02-21 12:53:25 -05:00
Russ Cox
df93283d56 cmd/fix: delete pre-Go 1 fixes
Assume people who were going to update to Go 1 have done so.
Those with pre-Go 1 trees remaining will need to update first
to Go 1.0 (using its 'go fix') and then to Go 1.1.

Cuts the cmd/fix test time by 99% (3 seconds to 0.03 seconds).

R=golang-dev, bradfitz
CC=golang-dev
https://golang.org/cl/7402046
2013-02-21 12:19:54 -05:00
Robert Griesemer
9dcf3eee41 cmd/godoc: better console error message for example error
(per r's suggestion)

R=r
CC=golang-dev
https://golang.org/cl/7376045
2013-02-20 12:28:12 -08:00
Robert Griesemer
3ee87d02b0 cmd/godoc: use go/build to determine package and example files
Also:
- faster code for example extraction
- simplify handling of command documentation:
  all "main" packages are treated as commands
- various minor cleanups along the way

For commands written in Go, any doc.go file containing
documentation must now be part of package main (rather
then package documentation), otherwise the documentation
won't show up in godoc (it will still build, though).

For commands written in C, documentation may still be
in doc.go files defining package documentation, but the
recommended way is to explicitly ignore those files with
a +build ignore constraint to define package main.

Fixes #4806.

R=adg, rsc, dave, bradfitz
CC=golang-dev
https://golang.org/cl/7333046
2013-02-19 11:19:58 -08:00
Russ Cox
07e87885ad cmd/6c: fix build
copy+paste error while cleaning up CL 7303099 before submit

R=ken2
CC=golang-dev
https://golang.org/cl/7308104
2013-02-18 13:29:55 -05:00