1
0
mirror of https://github.com/golang/go synced 2024-10-04 12:31:21 -06:00
Commit Graph

5096 Commits

Author SHA1 Message Date
Alex Brainman
6e8c7f5bb2 cmd/nm: print symbol sizes for windows pe executables
Fixes #6973

LGTM=r
R=golang-codereviews, r
CC=golang-codereviews
https://golang.org/cl/88820043
2014-04-19 14:47:20 +10:00
Mike Andrews
7c7aaa4156 cmd/ld: don't delete output binary if not "ordinary" file (redux).
following on CL https://golang.org/cl/76810045 and
issue 7563, i now see there's another "remove(outfile)" a few
dozen lines down that also needs fixing.

LGTM=iant
R=golang-codereviews, iant
CC=0intro, golang-codereviews, r
https://golang.org/cl/89030043
2014-04-18 15:37:55 -07:00
Shenghou Ma
c7d864c4d0 cmd/go: support -ccflags in 'go test'
Fixes #7810.

LGTM=iant
R=golang-codereviews, iant
CC=golang-codereviews
https://golang.org/cl/89050043
2014-04-17 23:16:11 -04:00
Russ Cox
576318c7bd cmd/pack: avoid ./ import in test (fix Windows build)
It is possible to use ./ imports on Windows but it
requires some extra command-line work
('go build' does this automatically, but we can't use 'go build' here).

Instead, use an ordinary import and -I/-L, which are easier to use.

LGTM=iant
R=iant
CC=golang-codereviews
https://golang.org/cl/89040043
2014-04-17 16:25:38 -04:00
Ian Lance Taylor
6524310770 cmd/pack: handle very long lines in pkgdef
LGTM=rsc, bradfitz
R=golang-codereviews, rsc, bradfitz
CC=golang-codereviews
https://golang.org/cl/88170049
2014-04-17 11:47:12 -07:00
Ian Lance Taylor
827aab07b8 cmd/ld: don't pass -rdynamic to external linker if -static is used
Fixes #7800.

LGTM=rsc
R=rsc
CC=golang-codereviews
https://golang.org/cl/87790051
2014-04-16 20:28:53 -07:00
Shenghou Ma
32dffef098 cmd/gc: fix segfault in isgoconst.
Variables declared with 'var' have no sym->def.

Fixes #7794.

LGTM=rsc
R=golang-codereviews, bradfitz, rsc
CC=golang-codereviews
https://golang.org/cl/88360043
2014-04-16 23:12:06 -04:00
Jan Ziak
1d2b71ce83 cmd/gc: fewer errors for wrong argument count
Fixes #7675

LGTM=rsc
R=rsc
CC=golang-codereviews
https://golang.org/cl/85040044
2014-04-16 22:42:09 -04:00
Anthony Martin
1e2a61aee1 cmd/ld: restore the call graph dump
Before the switch to liblink, the linkers accepted the -c flag
to print the call graph. This change restores the functionality.

This came in handy when I was trying to audit the use of SSE
instructions inside the Plan 9 note handler.

LGTM=rsc
R=golang-codereviews, bradfitz, rsc
CC=golang-codereviews
https://golang.org/cl/73990043
2014-04-16 22:42:02 -04:00
Russ Cox
6f2d91a094 cmd/go: reapply doc change from CL 60590044.
https://golang.org/cl/60590044 edited
doc.go without editing the file it is generated from.
The edit was lost at the next mkdoc.sh.
Make the change in help.go and rerun mkdoc.sh.

Pointed out in the review of CL 68580043.

TBR=iant
CC=golang-codereviews
https://golang.org/cl/88760043
2014-04-16 22:30:10 -04:00
Alex Brainman
fce4f0484c cmd/ld: populate pe symbol table with Go symbols
Fixes #6936

LGTM=rsc
R=golang-codereviews, bradfitz, rsc
CC=golang-codereviews
https://golang.org/cl/87770048
2014-04-16 22:25:40 -04:00
Alex Brainman
06dc4e78c4 cmd/nm: windows pe handling fixes
- output absolute addresses, not relative;
- accept negative section numbers.

Update #6936
Fixes #7738

LGTM=rsc
R=golang-codereviews, bradfitz, ruiu, rsc
CC=golang-codereviews
https://golang.org/cl/85240046
2014-04-16 22:17:38 -04:00
Russ Cox
5e8c922625 liblink, cmd/ld: reenable nosplit checking and test
The new code is adapted from the Go 1.2 nosplit code,
but it does not have the bug reported in issue 7623:

g% go run nosplit.go
g% go1.2 run nosplit.go
BUG
rejected incorrectly:
        main 0 call f; f 120

        linker output:
        # _/tmp/go-test-nosplit021064539
        main.main: nosplit stack overflow
                120	guaranteed after split check in main.main
                112	on entry to main.f
                -8	after main.f uses 120

g%

Fixes #6931.
Fixes #7623.

LGTM=iant
R=golang-codereviews, iant, ality
CC=golang-codereviews, r
https://golang.org/cl/88190043
2014-04-16 22:08:00 -04:00
Ian Lance Taylor
58b86e5013 liblink, cmd/gc, cmd/{5,6,8}{a,c}: rename linkwriteobj to writeobj
The name linkwriteobj is misleading because it implies that
the function has something to do with the linker, which it
does not.  The name is historical: the function performs an
operation that was previously performed by the linker, but no
longer is.

LGTM=rsc
R=rsc, minux.ma
CC=golang-codereviews
https://golang.org/cl/88210045
2014-04-16 14:36:44 -07:00
Russ Cox
cc08d9232c liblink: add leaf bit to object file format
Without the leaf bit, the linker cannot record
the correct frame size in the symbol table, and
then stack traces get mangled. (Only for ARM.)

Fixes #7338.
Fixes #7347.

LGTM=iant
R=iant
CC=golang-codereviews
https://golang.org/cl/88550043
2014-04-16 17:11:44 -04:00
Russ Cox
0a8a719ded cmd/5g, cmd/6g, cmd/8g: preserve wide values in large functions
In large functions with many variables, the register optimizer
may give up and choose not to track certain variables at all.
In this case, the "nextinnode" information linking together
all the words from a given variable will be incomplete, and
the result may be that only some of a multiword value is
preserved across a call. That confuses the garbage collector,
so don't do that. Instead, mark those variables as having
their address taken, so that they will be preserved at all
calls. It's overkill, but correct.

Tested by hand using the 6g -S output to see that it does fix
the buggy generated code leading to the issue 7726 failure.

There is no automated test because I managed to break the
compiler while writing a test (see issue 7727). I will check
in a test along with the fix to issue 7727.

Fixes #7726.

LGTM=khr
R=khr, bradfitz, dave
CC=golang-codereviews
https://golang.org/cl/85200043
2014-04-16 13:59:42 -04:00
Russ Cox
468cf82780 liblink: fix incorrect hash collision in lookup
linklookup uses hash(name, v) as the hash table index but then
only compares name to find a symbol to return.
If hash(name, v1) == hash(name, v2) for v1 != v2, the lookup
for v2 will return the symbol with v1.

The input routines assume that each symbol is found only once,
and then each symbol is added to a linked list, with the list header
in the symbol. Adding a symbol to such a list multiple times
short-circuits the list the second time it is added, causing symbols
to be dropped.

The liblink rewrite introduced an elegant, if inefficient, handling
of duplicated symbols by creating a dummy symbol to read the
duplicate into. The dummy symbols are named .dup with
sequential version numbers. With many .dup symbols, eventually
there will be a conflict, causing a duplicate list add, causing elided
symbols, causing a crash when calling one of the elided symbols.

The bug is old (2011) but could not have manifested until the
liblink rewrite introduced this heavily duplicated symbol .dup.
(See History section below.)

1. Correct the lookup function.

2. Since we want all the .dup symbols to be different, there's no
point in inserting them into the table. Call linknewsym directly,
avoiding the lookup function entirely.

3. Since nothing can refer to the .dup symbols, do not bother
adding them to the list of functions (textp) at all.

4. In lieu of a unit test, introduce additional consistency checks to
detect adding a symbol to a list multiple times. This would have
caught the short-circuit more directly, and it will detect a variety
of double-use bugs, including the one arising from the bad lookup.

Fixes #7749.

History

On April 9, 2011, I submitted CL 4383047, making ld 25% faster.
Much of the focus was on the hash table lookup function, and
one of the changes was to remove the s->version == v comparison [1].

I don't know if this was a simple editing error or if I reasoned that
same name but different v would yield a different hash slot and
so the name test alone sufficed. It is tempting to claim the former,
but it was probably the latter.

Because the hash is an iterated multiply+add, the version ends up
adding v*3ⁿ to the hash, where n is the length of the name.
A collision would need x*3ⁿ ≡ y*3ⁿ (mod 2²⁴ mod 100003),
or equivalently x*3ⁿ ≡ x*3ⁿ + (y-x)*3ⁿ (mod 2²⁴ mod 100003),
so collisions will actually be periodic: versions x and y collide
when d = y-x satisfies d*3ⁿ ≡ 0 (mod 2²⁴ mod 100003).
Since we allocate version numbers sequentially, this is actually
about the best case one could imagine: the collision rate is
much lower than if the hash were more random.
http://play.golang.org/p/TScD41c_hA computes the collision
period for various name lengths.

The most common symbol in the new linker is .dup, and for n=4
the period is maximized: the 100004th symbol is the first collision.
Unfortunately, there are programs with more duplicated symbols
than that.

In Go 1.2 and before, duplicate symbols were handled without
creating a dummy symbol, so this particular case for generating
many duplicate symbols could not happen. Go does not use
versioned symbols. Only C does; each input file gives a different
version to its static declarations. There just aren't enough C files
for this to come up in that context.

So the bug is old but the realization of the bug is new.

[1] https://golang.org/cl/4383047/diff/5001/src/cmd/ld/lib.c

LGTM=minux.ma, iant, dave
R=golang-codereviews, minux.ma, bradfitz, iant, dave
CC=golang-codereviews, r
https://golang.org/cl/87910047
2014-04-16 11:53:14 -04:00
Shenghou Ma
d0d425a987 cmd/ld: cast PE32 absolute addend to int32.
Didn't manage to find a way to write test cases.

Fixes #7769.

LGTM=iant
R=iant
CC=golang-codereviews
https://golang.org/cl/88000045
2014-04-16 01:46:56 -04:00
Shenghou Ma
a4ff90df28 cmd/ld: correct comment.
LGTM=iant
R=golang-codereviews, iant
CC=golang-codereviews
https://golang.org/cl/88360044
2014-04-16 01:41:47 -04:00
Russ Cox
dacc020c00 cmd/ld: record complete runtime-gdb.py path again
This code never got updated after the liblink shuffle.
Tested by hand that it works and respects GOROOT_FINAL.

The discussion in issue 6963 suggests that perhaps we should
just drop runtime-gdb.py entirely, but I am not convinced
that is true. It was in Go 1.2 and I don't see a reason not to
keep it in Go 1.3. The fact that binaries have not been emitting
the reference was just a missed detail in the liblink conversion,
not part of a grand plan.

Fixes #7506.
Fixes #6963.

LGTM=bradfitz
R=golang-codereviews, bradfitz
CC=golang-codereviews, iant, r
https://golang.org/cl/87870048
2014-04-15 21:17:18 -04:00
Russ Cox
e97b3ab1f9 build: remove tmp dir names from objects, support GOROOT_FINAL again
If we compile a generated file stored in a temporary
directory - let's say /tmp/12345/work/x.c - then by default
6c stores the full path and then the pcln table in the
final binary includes the full path. This makes repeated builds
(using different temporary directories) produce different
binaries, even if the inputs are the same.

In the old 'go tool pack', the P flag specified a prefix to remove
from all stored paths (if present), and cmd/go invoked
'go tool pack grcP $WORK' to remove references to the
temporary work directory.

We've changed the build to avoid pack as much as possible,
under the theory that instead of making pack convert from
.6 to .a, the tools should just write the .a directly and save a
round of I/O.

Instead of going back to invoking pack always, define a common
flag -trimpath in the assemblers, C compilers, and Go compilers,
implemented in liblink, and arrange for cmd/go to use the flag.
Then the object files being written out have the shortened paths
from the start.

While we are here, reimplement pcln support for GOROOT_FINAL.
A build in /tmp/go uses GOROOT=/tmp/go, but if GOROOT_FINAL=/usr/local/go
is set, then a source file named /tmp/go/x.go is recorded instead as
/usr/local/go/x.go. We use this so that we can prepare distributions
to be installed in /usr/local/go without actually working in that
directory. The conversion to liblink deleted all the old file name
handling code, including the GOROOT_FINAL translation.
Bring the GOROOT_FINAL translation back.

Before this CL, using GOROOT_FINAL=/goroot make.bash:

        g% strings $(which go) | grep -c $TMPDIR
        6
        g% strings $(which go) | grep -c $GOROOT
        793
        g%

After this CL:

        g% strings $(which go) | grep -c $TMPDIR
        0
        g% strings $(which go) | grep -c $GOROOT
        0
        g%

(The references to $TMPDIR tend to be cgo-generated source files.)

Adding the -trimpath flag to the assemblers required converting
them to the new Go-semantics flag parser. The text in go1.3.html
is copied and adjusted from go1.1.html, which is when we applied
that conversion to the compilers and linkers.

Fixes #6989.

LGTM=iant
R=r, iant
CC=golang-codereviews
https://golang.org/cl/88300045
2014-04-15 20:46:46 -04:00
Russ Cox
44f96d4488 addr2line, objdump: write doc comments
LGTM=r
R=r
CC=golang-codereviews
https://golang.org/cl/88050046
2014-04-15 20:06:08 -04:00
Russ Cox
22505cd2a1 cmd/pack: print error along with usage
My cmd/go got in a weird state where it started invoking pack grcP.
Change pack to print a 1-line explanation of the usage problem
before the generic usage message.

LGTM=r
R=r
CC=golang-codereviews
https://golang.org/cl/87770047
2014-04-15 20:05:56 -04:00
Russ Cox
ed890e7414 cmd/ld: attempt at fixing openbsd build
OpenBSD is excluded from all the usual thread-local storage
code, not just emitting the tbss section in the external link .o
but emitting a PT_TLS section in an internally-linked executable.
I assume it just has no proper TLS support. Exclude it here too.

TBR=iant
CC=golang-codereviews
https://golang.org/cl/87900045
2014-04-15 15:52:23 -04:00
Russ Cox
6f8b120869 cmd/ld: use TLS relocations on ELF systems in external linking mode
Fixes #7719.

LGTM=iant
R=iant
CC=golang-codereviews
https://golang.org/cl/87760050
2014-04-15 12:13:52 -07:00
Russ Cox
90093f0634 liblink: introduce TLS register on 386 and amd64
When I did the original 386 ports on Linux and OS X, I chose to
define GS-relative expressions like 4(GS) as relative to the actual
thread-local storage base, which was usually GS but might not be
(it might be FS, or it might be a different constant offset from GS or FS).

The original scope was limited but since then the rewrites have
gotten out of control. Sometimes GS is rewritten, sometimes FS.
Some ports do other rewrites to enable shared libraries and
other linking. At no point in the code is it clear whether you are
looking at the real GS/FS or some synthesized thing that will be
rewritten. The code manipulating all these is duplicated in many
places.

The first step to fixing issue 7719 is to make the code intelligible
again.

This CL adds an explicit TLS pseudo-register to the 386 and amd64.
As a register, TLS refers to the thread-local storage base, and it
can only be loaded into another register:

        MOVQ TLS, AX

An offset from the thread-local storage base is written off(reg)(TLS*1).
Semantically it is off(reg), but the (TLS*1) annotation marks this as
indexing from the loaded TLS base. This emits a relocation so that
if the linker needs to adjust the offset, it can. For example:

        MOVQ TLS, AX
        MOVQ 8(AX)(TLS*1), CX // load m into CX

On systems that support direct access to the TLS memory, this
pair of instructions can be reduced to a direct TLS memory reference:

        MOVQ 8(TLS), CX // load m into CX

The 2-instruction and 1-instruction forms correspond roughly to
ELF TLS initial exec mode and ELF TLS local exec mode, respectively.

Liblink applies this rewrite on systems that support the 1-instruction form.
The decision is made using only the operating system (and probably
the -shared flag, eventually), not the link mode. If some link modes
on a particular operating system require the 2-instruction form,
then all builds for that operating system will use the 2-instruction
form, so that the link mode decision can be delayed to link time.

Obviously it is late to be making changes like this, but I despair
of correcting issue 7719 and issue 7164 without it. To make sure
I am not changing existing behavior, I built a "hello world" program
for every GOOS/GOARCH combination we have and then worked
to make sure that the rewrite generates exactly the same binaries,
byte for byte. There are a handful of TODOs in the code marking
kludges to get the byte-for-byte property, but at least now I can
explain exactly how each binary is handled.

The targets I tested this way are:

        darwin-386
        darwin-amd64
        dragonfly-386
        dragonfly-amd64
        freebsd-386
        freebsd-amd64
        freebsd-arm
        linux-386
        linux-amd64
        linux-arm
        nacl-386
        nacl-amd64p32
        netbsd-386
        netbsd-amd64
        openbsd-386
        openbsd-amd64
        plan9-386
        plan9-amd64
        solaris-amd64
        windows-386
        windows-amd64

There were four exceptions to the byte-for-byte goal:

windows-386 and windows-amd64 have a time stamp
at bytes 137 and 138 of the header.

darwin-386 and plan9-386 have five or six modified
bytes in the middle of the Go symbol table, caused by
editing comments in runtime/sys_{darwin,plan9}_386.s.

Fixes #7164.

LGTM=iant
R=iant, aram, minux.ma, dave
CC=golang-codereviews
https://golang.org/cl/87920043
2014-04-15 13:45:39 -04:00
Jan Ziak
d826b2ed98 cmd/dist: use GOHOSTARCH/GOHOSTOS instead of GOOS/GOARCH for host libraries and binaries
Fixes #6559

LGTM=rsc
R=rsc
CC=golang-codereviews
https://golang.org/cl/81330045
2014-04-15 08:46:21 +02:00
Andrew Gerrand
85ddc68921 undo CL 87300043 / 1dc800571456
This breaks "go get -d repo/path/...".

««« original CL description
cmd/go: do not miss an error if import path contains "cmd/something"

Fixes #7638

LGTM=rsc
R=rsc
CC=golang-codereviews
https://golang.org/cl/87300043
»»»

LGTM=bradfitz
R=golang-codereviews, bradfitz
CC=golang-codereviews
https://golang.org/cl/87890043
2014-04-15 10:20:04 +10:00
Jan Ziak
3f529f8e43 cmd/go: do not miss an error if import path contains "cmd/something"
Fixes #7638

LGTM=rsc
R=rsc
CC=golang-codereviews
https://golang.org/cl/87300043
2014-04-14 22:01:27 +02:00
Russ Cox
8d39e55c65 liblink: remove arch-specific constants from file format
The relocation and automatic variable types were using
arch-specific numbers. Introduce portable enumerations
instead.

To the best of my knowledge, these are the only arch-specific
bits left in the new object file format.

Remove now, before Go 1.3, because file formats are forever.

LGTM=iant
R=iant
CC=golang-codereviews
https://golang.org/cl/87670044
2014-04-14 15:54:20 -04:00
Russ Cox
0e8de61d73 liblink, cmd/link: add version number to object file
There are changes we know we want to make, but not before Go 1.3
Add a version number so that we can make them more easily later.

LGTM=iant
R=iant
CC=golang-codereviews
https://golang.org/cl/87670043
2014-04-14 13:20:51 -04:00
Russ Cox
41ff456f69 cmd/dist: mark cmd/link and debug/goobj as unreleased
These are not ready and will not be in Go 1.3.

Fixes #6932.

LGTM=bradfitz
R=golang-codereviews, bradfitz, minux.ma
CC=golang-codereviews, iant, r
https://golang.org/cl/87630043
2014-04-14 12:33:51 -04:00
Russ Cox
1d71816484 cmd/prof, libmach: delete
We have never released cmd/prof and don't plan to.
Now that nm, addr2line, and objdump have been rewritten in Go,
cmd/prof is the only thing keeping us from deleting libmach.

Delete cmd/prof, and then since nothing is using libmach, delete libmach.

13,000 lines of C deleted.

LGTM=minux.ma
R=golang-codereviews, minux.ma
CC=golang-codereviews, iant, r
https://golang.org/cl/87020044
2014-04-14 11:09:25 -04:00
Russ Cox
0d441a088d cmd/objdump: rewrite in Go
Update cmd/dist not to build the C version.
Update cmd/go to install the Go version to the tool directory.

Update #7452

This is the basic logic needed for objdump, and it works well enough
to support the pprof list and weblist commands. A real disassembler
needs to be added in order to support the pprof disasm command
and the per-line assembly displays in weblist. That's still to come.

Probably objdump will move to go.tools when the disassembler
is added, but it can stay here for now.

LGTM=minux.ma
R=golang-codereviews, minux.ma
CC=golang-codereviews, iant, r
https://golang.org/cl/87580043
2014-04-14 10:58:49 -04:00
Russ Cox
c48db9a473 undo CL 66510044 / 6c0339d94123
Broke other things - see issue 7522.

Fixes #7522.
Reopens issue 7363.

««« original CL description
cmd/gc: make embedded, unexported fields read-only.

Fixes #7363.

LGTM=gri
R=gri, rsc, bradfitz
CC=golang-codereviews
https://golang.org/cl/66510044
»»»

LGTM=r, mpvl
R=golang-codereviews, r
CC=golang-codereviews, iant, mpvl
https://golang.org/cl/85580046
2014-04-14 09:48:11 -04:00
Jan Ziak
a599b4890a cmd/gc: increase specificity of errors in function call context
Fixes #7129

LGTM=rsc
R=rsc
CC=golang-codereviews
https://golang.org/cl/86470044
2014-04-11 15:57:30 +02:00
Jan Ziak
f973d9460f cmd/gc: fix typo in ordermapassign
Fixes #7742

LGTM=dave, rsc
R=rsc, bradfitz, dave
CC=golang-codereviews
https://golang.org/cl/85580047
2014-04-11 15:28:37 +02:00
Keith Randall
bfbb2e827b cmd/6g: nacl: zero odd multiple of widthptr correctly
LGTM=iant
R=remyoudompheng, iant
CC=golang-codereviews
https://golang.org/cl/86270043
2014-04-10 07:59:46 -07:00
Alex Brainman
c8f90979ac cmd/go: always build package during "go test" command
even when there are no *_test.go files present.
rsc suggested this change

Fixes #7108

LGTM=r, adg
R=golang-codereviews, r, adg
CC=golang-codereviews
https://golang.org/cl/84300043
2014-04-10 14:02:24 +10:00
Rémy Oudompheng
f400d9aafc cmd/6g: relax constraint on variables that need zeroing.
On amd64p32 pointers are 32-bit-aligned and cannot be assumed to
have an offset multiple of widthreg. Instead check that they are
withptr-aligned.

Also change the threshold for region merging to 2*widthreg
instead of 2*widthptr because performance on amd64 and amd64p32
is expected to be the same.

Fixes #7712.

LGTM=khr
R=rsc, dave, khr, brad, bradfitz
CC=golang-codereviews
https://golang.org/cl/84690044
2014-04-09 21:23:36 +02:00
Jan Ziak
8f8ada008c cmd/gc: drop { } around single-line if-statement body
LGTM=rsc
R=rsc
CC=golang-codereviews
https://golang.org/cl/85890043
2014-04-09 15:39:28 +02:00
Jan Ziak
397f129daf cmd/gc: avoid confusing error message "ovf in mpaddxx"
Fixes #6889

LGTM=rsc
R=gri, rsc
CC=golang-codereviews
https://golang.org/cl/85080044
2014-04-09 08:36:27 +02:00
Jan Ziak
907736e2fe cmd/gc: ignore blank (_) labels in label declarations
Fixes #7538

LGTM=rsc
R=gri, rsc
CC=golang-codereviews
https://golang.org/cl/85040045
2014-04-09 08:34:17 +02:00
Rick Arnold
b3a33a654d cmd/go: allow use of Context in 'go list -f'
Add a $Context variable to the template so that the build.Context values
such as BuildTags can be accessed.

Fixes #6666.

LGTM=adg, rsc
R=golang-codereviews, gobot, adg, rsc
CC=golang-codereviews
https://golang.org/cl/72770043
2014-04-08 22:35:29 -04:00
Albert Strasheim
0b07effab1 cmd/go: Check error from SWIG link step.
LGTM=iant
R=iant
CC=golang-codereviews
https://golang.org/cl/85070043
2014-04-07 12:59:55 -07:00
Russ Cox
844ec6bbe3 cmd/8g: fix liveness for 387 build (including plan9)
TBR=khr
CC=golang-codereviews
https://golang.org/cl/84570045
2014-04-06 10:30:02 -04:00
Keith Randall
375b7bb767 cmd/gc: compute size of keys & values before making map bucket
Fixes #7547

LGTM=iant
R=iant, khr
CC=golang-codereviews
https://golang.org/cl/84470046
2014-04-04 12:58:19 -07:00
Jan Ziak
3072df5c1d cmd/gc: check duplicate keys in maps with interface{} key type
Fixes #7214

LGTM=rsc
R=golang-codereviews, bradfitz, rsc
CC=golang-codereviews, minux.ma
https://golang.org/cl/82080044
2014-04-04 16:46:23 +02:00
Rémy Oudompheng
c6a41a3559 cmd/6g, cmd/8g: disable Duff's device on NaCl.
Native Client forbids jumps/calls to arbitrary locations and
enforces a particular alignement, which makes the Duff's device
ineffective.

LGTM=khr
R=rsc, dave, khr
CC=golang-codereviews
https://golang.org/cl/84400043
2014-04-04 08:42:35 +02:00
Alex Brainman
df8ec65b3a os/exec: always try appropriate command extensions during Cmd.Start on windows
Update #7362
Fixes #7377
Fixes #7570

LGTM=rsc
R=golang-codereviews, rsc
CC=golang-codereviews
https://golang.org/cl/83020043
2014-04-04 16:26:15 +11:00
Mikio Hara
22bc710fe4 cmd/gc: fix build
LGTM=minux.ma
R=rsc, minux.ma
CC=golang-codereviews
https://golang.org/cl/84260043
2014-04-04 09:55:19 +09:00
Russ Cox
28f1868fed cmd/gc, runtime: make GODEBUG=gcdead=1 mode work with liveness
Trying to make GODEBUG=gcdead=1 work with liveness
and in particular ambiguously live variables.

1. In the liveness computation, mark all ambiguously live
variables as live for the entire function, except the entry.
They are zeroed directly after entry, and we need them not
to be poisoned thereafter.

2. In the liveness computation, compute liveness (and deadness)
for all parameters, not just pointer-containing parameters.
Otherwise gcdead poisons untracked scalar parameters and results.

3. Fix liveness debugging print for -live=2 to use correct bitmaps.
(Was not updated for compaction during compaction CL.)

4. Correct varkill during map literal initialization.
Was killing the map itself instead of the inserted value temp.

5. Disable aggressive varkill cleanup for call arguments if
the call appears in a defer or go statement.

6. In the garbage collector, avoid bug scanning empty
strings. An empty string is two zeros. The multiword
code only looked at the first zero and then interpreted
the next two bits in the bitmap as an ordinary word bitmap.
For a string the bits are 11 00, so if a live string was zero
length with a 0 base pointer, the poisoning code treated
the length as an ordinary word with code 00, meaning it
needed poisoning, turning the string into a poison-length
string with base pointer 0. By the same logic I believe that
a live nil slice (bits 11 01 00) will have its cap poisoned.
Always scan full multiword struct.

7. In the runtime, treat both poison words (PoisonGC and
PoisonStack) as invalid pointers that warrant crashes.

Manual testing as follows:

- Create a script called gcdead on your PATH containing:

        #!/bin/bash
        GODEBUG=gcdead=1 GOGC=10 GOTRACEBACK=2 exec "$@"
- Now you can build a test and then run 'gcdead ./foo.test'.
- More importantly, you can run 'go test -short -exec gcdead std'
   to run all the tests.

Fixes #7676.

While here, enable the precise scanning of slices, since that was
disabled due to bugs like these. That now works, both with and
without gcdead.

Fixes #7549.

LGTM=khr
R=khr
CC=golang-codereviews
https://golang.org/cl/83410044
2014-04-03 20:33:25 -04:00
Mike Andrews
43b3e6e02a cmd/dist: reflect local changes to tree in goversion
runtime.Version() requires a trailing "+" when
tree had local modifications at time of build.

Fixes #7701

LGTM=iant
R=golang-codereviews, iant
CC=golang-codereviews
https://golang.org/cl/84040045
2014-04-03 16:31:41 -07:00
Russ Cox
f5f5a8b620 cmd/gc, runtime: optimize map[string] lookup from []byte key
Brad has been asking for this for a while.
I have resisted because I wanted to find a more general way to
do this, one that would keep the performance of code introducing
variables the same as the performance of code that did not.
(See golang.org/issue/3512#c20).

I have not found the more general way, and recent changes to
remove ambiguously live temporaries have blown away the
property I was trying to preserve, so that's no longer a reason
not to make the change.

Fixes #3512.

LGTM=iant
R=iant
CC=bradfitz, golang-codereviews, khr, r
https://golang.org/cl/83740044
2014-04-03 19:05:17 -04:00
Russ Cox
f3ecb298ad cmd/gc: reject builtin function calls in len(fixed array) constants
Fixes #7385.

LGTM=iant
R=golang-codereviews, iant
CC=golang-codereviews
https://golang.org/cl/84010044
2014-04-03 19:04:33 -04:00
Russ Cox
a26c01ad44 cmd/cc: emit gc bitmaps in read-only memory
Cuts hello world by 70kB, because we don't write
those names into the symbol table.

Update #6853

LGTM=khr
R=khr
CC=golang-codereviews
https://golang.org/cl/80370045
2014-04-03 19:04:15 -04:00
Keith Randall
059c10b552 cmd/ld: get rid of map.bucket's data field from dwarf info.
The data field is the generic array that acts as a standin
for the keys and values arrays for the generic runtime code.
We want to substitute the keys and values arrays for the data
array, not just add keys and values in addition to it.

LGTM=iant
R=golang-codereviews, iant
CC=golang-codereviews
https://golang.org/cl/81160044
2014-04-02 19:46:47 -07:00
Dave Cheney
568f50e3fc cmd/gc: fix build
Darwin 10.6 (gcc 4.2) and some older versions of gcc default to C90 mode, not C99 mode. Silence the warning.

LGTM=aram, iant
R=golang-codereviews, aram, iant
CC=golang-codereviews
https://golang.org/cl/83090050
2014-04-03 11:34:31 +11:00
Dave Cheney
1aaea50c76 cmd/pack: fix format string error in log message
Fixes #7693.

pack.go:347: possible formatting directive in Fatal call

LGTM=iant
R=golang-codereviews, iant
CC=golang-codereviews
https://golang.org/cl/83310045
2014-04-03 09:58:10 +11:00
Russ Cox
4676fae525 cmd/gc, cmd/ld, runtime: compact liveness bitmaps
Reduce footprint of liveness bitmaps by about 5x.

1. Mark all liveness bitmap symbols as 4-byte aligned
(they were aligned to a larger size by default).

2. The bitmap data is a bitmap count n followed by n bitmaps.
Each bitmap begins with its own count m giving the number
of bits. All the m's are the same for the n bitmaps.
Emit this bitmap length once instead of n times.

3. Many bitmaps within a function have the same bit values,
but each call site was given a distinct bitmap. Merge duplicate
bitmaps so that no bitmap is written more than once.

4. Many functions end up with the same aggregate bitmap data.
We used to name the bitmap data funcname.gcargs and funcname.gclocals.
Instead, name it gclocals.<md5 of data> and mark it dupok so
that the linker coalesces duplicate sets. This cut the bitmap
data remaining after step 3 by 40%; I was not expecting it to
be quite so dramatic.

Applied to "go build -ldflags -w code.google.com/p/go.tools/cmd/godoc":

                bitmaps           pclntab           binary on disk
before this CL  1326600           1985854           12738268
4-byte align    1154288 (0.87x)   1985854 (1.00x)   12566236 (0.99x)
one bitmap len   782528 (0.54x)   1985854 (1.00x)   12193500 (0.96x)
dedup bitmap     414748 (0.31x)   1948478 (0.98x)   11787996 (0.93x)
dedup bitmap set 245580 (0.19x)   1948478 (0.98x)   11620060 (0.91x)

While here, remove various dead blocks of code from plive.c.

Fixes #6929.
Fixes #7568.

LGTM=khr
R=khr
CC=golang-codereviews
https://golang.org/cl/83630044
2014-04-02 16:49:27 -04:00
David du Colombier
9f9c9abb7e cmd/8g, cmd/gc: fix warnings on Plan 9
warning: src/cmd/8g/ggen.c:35 non-interruptable temporary
warning: src/cmd/gc/walk.c:656 set and not used: l
warning: src/cmd/gc/walk.c:658 set and not used: l

LGTM=minux.ma
R=golang-codereviews, minux.ma
CC=golang-codereviews
https://golang.org/cl/83660043
2014-04-02 21:33:50 +02:00
Russ Cox
96d90d0981 cmd/gc: shorten even more temporary lifetimes
1. Use n->alloc, not n->left, to hold the allocated temp being
passed from orderstmt/orderexpr to walk.

2. Treat method values the same as closures.

3. Use killed temporary for composite literal passed to
non-escaping function argument.

4. Clean temporaries promptly in if and for statements.

5. Clean temporaries promptly in select statements.
As part of this, move all the temporary-generating logic
out of select.c into order.c, so that the temporaries can
be reclaimed.

With the new temporaries, can re-enable the 1-entry
select optimization. Fixes issue 7672.

While we're here, fix a 1-line bug in select processing
turned up by the new liveness test (but unrelated; select.c:72).
Fixes #7686.

6. Clean temporaries (but not particularly promptly) in switch
and range statements.

7. Clean temporary used during convT2E/convT2I.

8. Clean temporaries promptly during && and || expressions.

---

CL 81940043 reduced the number of ambiguously live temps
in the godoc binary from 860 to 711.

CL 83090046 reduced the number from 711 to 121.

This CL reduces the number from 121 to 23.

15 the 23 that remain are in fact ambiguously live.
The final 8 could be fixed but are not trivial and
not common enough to warrant work at this point
in the release cycle.

These numbers only count ambiguously live temps,
not ambiguously live user-declared variables.
There are 18 such variables in the godoc binary after this CL,
so a total of 41 ambiguously live temps or user-declared
variables.

The net effect is that zeroing anything on entry to a function
should now be a rare event, whereas earlier it was the
common case.

This is good enough for Go 1.3, and probably good
enough for future releases too.

Fixes #7345.

LGTM=khr
R=khr
CC=golang-codereviews
https://golang.org/cl/83000048
2014-04-02 14:09:42 -04:00
Keith Randall
47acf16709 cmd/gc: Don't zero more than we need.
Don't merge with the zero range, we may
end up zeroing more than we need.

LGTM=rsc
R=rsc
CC=golang-codereviews
https://golang.org/cl/83430044
2014-04-02 09:17:42 -07:00
Keith Randall
383963b506 runtime: zero at start of frame more efficiently.
Use Duff's device for zeroing.  Combine adjacent regions.

Update #7680
Update #7624

LGTM=rsc
R=rsc
CC=golang-codereviews
https://golang.org/cl/83200045
2014-04-01 19:44:07 -07:00
Russ Cox
9c8f11ff96 cmd/5g, cmd/8g: fix build
Botched during CL 83090046.

TBR=khr
CC=golang-codereviews
https://golang.org/cl/83070046
2014-04-01 20:24:53 -04:00
Russ Cox
daca06f2e3 cmd/gc: shorten more temporary lifetimes
1. In functions with heap-allocated result variables or with
defer statements, the return sequence requires more than
just a single RET instruction. There is an optimization that
arranges for all returns to jump to a single copy of the return
epilogue in this case. Unfortunately, that optimization is
fundamentally incompatible with PC-based liveness information:
it takes PCs at many different points in the function and makes
them all land at one PC, making the combined liveness information
at that target PC a mess. Disable this optimization, so that each
return site gets its own copy of the 'call deferreturn' and the
copying of result variables back from the heap.
This removes quite a few spurious 'ambiguously live' variables.

2. Let orderexpr allocate temporaries that are passed by address
to a function call and then die on return, so that we can arrange
an appropriate VARKILL.

2a. Do this for ... slices.

2b. Do this for closure structs.

2c. Do this for runtime.concatstring, which is the implementation
of large string additions. Change representation of OADDSTR to
an explicit list in typecheck to avoid reconstructing list in both
walk and order.

3. Let orderexpr allocate the temporary variable copies used for
range loops, so that they can be killed when the loop is over.
Similarly, let it allocate the temporary holding the map iterator.

CL 81940043 reduced the number of ambiguously live temps
in the godoc binary from 860 to 711.

This CL reduces the number to 121. Still more to do, but another
good checkpoint.

Update #7345

LGTM=khr
R=khr
CC=golang-codereviews
https://golang.org/cl/83090046
2014-04-01 20:02:54 -04:00
Keith Randall
6c7cbf086c runtime: get rid of most uses of REP for copying/zeroing.
REP MOVSQ and REP STOSQ have a really high startup overhead.
Use a Duff's device to do the repetition instead.

benchmark                 old ns/op     new ns/op     delta
BenchmarkClearFat32       7.20          1.60          -77.78%
BenchmarkCopyFat32        6.88          2.38          -65.41%
BenchmarkClearFat64       7.15          3.20          -55.24%
BenchmarkCopyFat64        6.88          3.44          -50.00%
BenchmarkClearFat128      9.53          5.34          -43.97%
BenchmarkCopyFat128       9.27          5.56          -40.02%
BenchmarkClearFat256      13.8          9.53          -30.94%
BenchmarkCopyFat256       13.5          10.3          -23.70%
BenchmarkClearFat512      22.3          18.0          -19.28%
BenchmarkCopyFat512       22.0          19.7          -10.45%
BenchmarkCopyFat1024      36.5          38.4          +5.21%
BenchmarkClearFat1024     35.1          35.0          -0.28%

TODO: use for stack frame zeroing
TODO: REP prefixes are still used for "reverse" copying when src/dst
regions overlap.  Might be worth fixing.

LGTM=rsc
R=golang-codereviews, rsc
CC=golang-codereviews, r
https://golang.org/cl/81370046
2014-04-01 12:51:02 -07:00
Russ Cox
b700cb4974 cmd/gc: shorten temporary lifetimes when possible
The new channel and map runtime routines take pointers
to values, typically temporaries. Without help, the compiler
cannot tell when those temporaries stop being needed,
because it isn't sure what happened to the pointer.
Arrange to insert explicit VARKILL instructions for these
temporaries so that the liveness analysis can avoid seeing
them as "ambiguously live".

The change is made in order.c, which was already in charge of
introducing temporaries to preserve the order-of-evaluation
guarantees. Now its job has expanded to include introducing
temporaries as needed by runtime routines, and then also
inserting the VARKILL annotations for all these temporaries,
so that their lifetimes can be shortened.

In order to do its job for the map runtime routines, order.c arranges
that all map lookups or map assignments have the form:

        x = m[k]
        x, y = m[k]
        m[k] = x

where x, y, and k are simple variables (often temporaries).
Likewise, receiving from a channel is now always:

        x = <-c

In order to provide the map guarantee, order.c is responsible for
rewriting x op= y into x = x op y, so that m[k] += z becomes

        t = m[k]
        t2 = t + z
        m[k] = t2

While here, fix a few bugs in order.c's traversal: it was failing to
walk into select and switch case bodies, so order of evaluation
guarantees were not preserved in those situations.
Added tests to test/reorder2.go.

Fixes #7671.

In gc/popt's temporary-merging optimization, allow merging
of temporaries with their address taken as long as the liveness
ranges do not intersect. (There is a good chance of that now
that we have VARKILL annotations to limit the liveness range.)

Explicitly killing temporaries cuts the number of ambiguously
live temporaries that must be zeroed in the godoc binary from
860 to 711, or -17%. There is more work to be done, but this
is a good checkpoint.

Update #7345

LGTM=khr
R=khr
CC=golang-codereviews
https://golang.org/cl/81940043
2014-04-01 13:31:38 -04:00
Shenghou Ma
15bc7ab957 cmd/gc: fix spurious "bad negated constant" for complex constants.
Fixes #7648.

LGTM=r, remyoudompheng
R=golang-codereviews, r, remyoudompheng, jscrockett01
CC=golang-codereviews
https://golang.org/cl/80560045
2014-04-01 02:55:38 -04:00
Shenghou Ma
1b42d25ae3 cmd/ld: pass -Qunused-arguments to clang during host linking.
LGTM=iant
R=iant
CC=golang-codereviews
https://golang.org/cl/82140043
2014-03-29 17:10:25 -04:00
Mike Andrews
ece69f7c2b cmd/ld: don't delete output binary if not "ordinary" file.
e.g., don't delete /dev/null. this fix inspired by gnu libiberty,
unlink-if-ordinary.c.

Fixes #7563

LGTM=iant
R=golang-codereviews, iant, 0intro
CC=golang-codereviews, r
https://golang.org/cl/76810045
2014-03-29 09:50:49 -07:00
Jan Ziak
2ca99505f6 cmd/gc: suppress array index error caused by a previously reported error
Fixes #7153

LGTM=rsc
R=rsc
CC=golang-codereviews
https://golang.org/cl/82180043
2014-03-29 15:45:40 +01:00
Russ Cox
e150ca9c9a cmd/gc: never pass ptr to uninit temp to runtime
chanrecv now expects a pointer to the data to be filled in.
mapiterinit expects a pointer to the hash iterator to be filled in.
In both cases, the temporary being pointed at changes from
dead to alive during the call. In order to make sure it is
preserved if a garbage collection happens after that transition
but before the call returns, the temp must be marked as live
during the entire call.

But if it is live during the entire call, it needs to be safe for
the garbage collector to scan at the beginning of the call,
before the new data has been filled in. Therefore, it must be
zeroed by the caller, before the call. Do that.

My previous attempt waited to mark it live until after the
call returned, but that's unsafe (see first paragraph);
undo that change in plive.c.

This makes powser2 pass again reliably.

I looked at every call to temp in the compiler.
The vast majority are followed immediately by an
initialization of temp, so those are fine.
The only ones that needed changing were the ones
where the next operation is to pass the address of
the temp to a function call, and there aren't too many.

Maps are exempted from this because mapaccess
returns a pointer to the data and lets the caller make
the copy.

Fixes many builds.

TBR=khr
CC=golang-codereviews
https://golang.org/cl/80700046
2014-03-28 11:30:02 -04:00
Daniel Morsing
0f82cfd3f0 cmd/cgo: enforce typing of 0-sized types
cgo represents all 0-sized and unsized types internally as [0]byte. This means that pointers to incomplete types would be interchangable, even if given a name by typedef.

Fixes #7409.

LGTM=iant
R=golang-codereviews, bradfitz, iant
CC=golang-codereviews
https://golang.org/cl/76450043
2014-03-27 20:23:16 +00:00
Russ Cox
6722d45631 cmd/gc: liveness-related bug fixes
1. On entry to a function, only zero the ambiguously live stack variables.
Before, we were zeroing all stack variables containing pointers.
The zeroing is pretty inefficient right now (issue 7624), but there are also
too many stack variables detected as ambiguously live (issue 7345),
and that must be addressed before deciding how to improve the zeroing code.
(Changes in 5g/ggen.c, 6g/ggen.c, 8g/ggen.c, gc/pgen.c)

Fixes #7647.

2. Make the regopt word-based liveness analysis preserve the
whole-variable liveness property expected by the garbage collection
bitmap liveness analysis. That is, if the regopt liveness decides that
one word in a struct needs to be preserved, make sure it preserves
the entire struct. This is particularly important for multiword values
such as strings, slices, and interfaces, in which all the words need
to be present in order to understand the meaning.
(Changes in 5g/reg.c, 6g/reg.c, 8g/reg.c.)

Fixes #7591.

3. Make the regopt word-based liveness analysis treat a variable
as having its address taken - which makes it preserved across
all future calls - whenever n->addrtaken is set, for consistency
with the gc bitmap liveness analysis, even if there is no machine
instruction actually taking the address. In this case n->addrtaken
is incorrect (a nicer way to put it is overconservative), and ideally
there would be no such cases, but they can happen and the two
analyses need to agree.
(Changes in 5g/reg.c, 6g/reg.c, 8g/reg.c; test in bug484.go.)

Fixes crashes found by turning off "zero everything" in step 1.

4. Remove spurious VARDEF annotations. As the comment in
gc/pgen.c explains, the VARDEF must immediately precede
the initialization. It cannot be too early, and it cannot be too late.
In particular, if a function call sits between the VARDEF and the
actual machine instructions doing the initialization, the variable
will be treated as live during that function call even though it is
uninitialized, leading to problems.
(Changes in gc/gen.c; test in live.go.)

Fixes crashes found by turning off "zero everything" in step 1.

5. Do not treat loading the address of a wide value as a signal
that the value must be initialized. Instead depend on the existence
of a VARDEF or the first actual read/write of a word in the value.
If the load is in order to pass the address to a function that does
the actual initialization, treating the load as an implicit VARDEF
causes the same problems as described in step 4.
The alternative is to arrange to zero every such value before
passing it to the real initialization function, but this is a much
easier and more efficient change.
(Changes in gc/plive.c.)

Fixes crashes found by turning off "zero everything" in step 1.

6. Treat wide input parameters with their address taken as
initialized on entry to the function. Otherwise they look
"ambiguously live" and we will try to emit code to zero them.
(Changes in gc/plive.c.)

Fixes crashes found by turning off "zero everything" in step 1.

7. An array of length 0 has no pointers, even if the element type does.
Without this change, the zeroing code complains when asked to
clear a 0-length array.
(Changes in gc/reflect.c.)

LGTM=khr
R=khr
CC=golang-codereviews
https://golang.org/cl/80160044
2014-03-27 14:05:57 -04:00
Russ Cox
f94bff7935 cmd/dist: zero output variables on entry to goc2c functions
Zeroing the outputs makes sure that during function calls
in those functions we do not let the garbage collector
treat uninitialized values as pointers.

The garbage collector may still see uninitialized values
if a preemption occurs during the function prologue,
before the zeroing has had a chance to run.

This reduces the number of 'bad pointer' messages when
that runtime check is enabled, but it doesn't fix all of them,
so the check is still disabled.

It will also avoid leaks, although I doubt any of these were
particularly serious.

LGTM=iant, khr
R=iant, khr
CC=golang-codereviews
https://golang.org/cl/80850044
2014-03-27 14:05:31 -04:00
Jan Ziak
21b2e16842 cmd/gc: fix spurious 'use of untyped nil' error
Fixes #6402

LGTM=rsc
R=rsc
CC=golang-codereviews
https://golang.org/cl/81340044
2014-03-27 18:47:00 +01:00
Erik Westrup
881d693c86 cmd/go: Use exported CgoLDFlags when compiler=gccgo
If you compile a program that has cgo LDFLAGS directives, those are exported to an environment variable to be used by subsequent compiler tool invocations. The linking phase when using the gccgo toolchain did not consider the envvar CGO_LDFLAGS's linking directives resulting in undefined references when using cgo+gccgo.

Fixes #7573

LGTM=iant
R=golang-codereviews, iant
CC=golang-codereviews
https://golang.org/cl/80780043
2014-03-26 15:23:31 -07:00
Shenghou Ma
4271dd4550 cmd/dist: set -Wuninitialized only when -O is also set.
GCC on OS X 10.6 doesn't support -Wuninitialized without -O.
Fixes #7492.

LGTM=iant
R=golang-codereviews, dave, iant
CC=golang-codereviews
https://golang.org/cl/72360045
2014-03-26 14:20:18 -04:00
Rob Pike
61f2fabd38 cmd/go: fix typo in help doc
Fixes #7519.

LGTM=adg, mikioh.mikioh
R=golang-codereviews, adg, mikioh.mikioh
CC=golang-codereviews
https://golang.org/cl/80370043
2014-03-26 17:18:59 +11:00
Dave Cheney
3ce1677ad9 cmd/go: ensure external test files are presented to the linker first
Fixes #7627.

CL 61970044 changed the order in which .a files are passed to gccgo's link phase. However by reversing the order it caused gccgo to complain if both internal (liba.a) and external (liba_test.a) versions of a package were presented as the former would not contain all the necessary symbols, and the latter would duplicate symbols already defined.

This change ensures that all 'fake' targets remain at the top of the final link order which should be fine as a package compiled as an external test is a superset of its internal sibling.

Looking at how gcToolchain links tests I think this change now accurately mirrors those actions which present $WORK/_test before $WORK in the link order.

LGTM=iant
R=rsc, iant
CC=golang-codereviews, michael.hudson
https://golang.org/cl/80300043
2014-03-26 15:30:55 +11:00
Shenghou Ma
aa1391949c cmd/gc: add missing entries to lexn and yytfix.
Makes gc -x better.

LGTM=r
R=golang-codereviews, bradfitz, r
CC=golang-codereviews
https://golang.org/cl/73090043
2014-03-25 23:21:57 -04:00
Alex Brainman
a837347dd9 runtime: use VEH for windows/amd64 exception handling
Fixes windows/amd64 build.

LGTM=rsc
R=golang-codereviews, rsc
CC=golang-codereviews
https://golang.org/cl/79470046
2014-03-26 11:13:50 +11:00
Keith Randall
1b45cc45e3 runtime: redo stack map entries to avoid false retention
Change two-bit stack map entries to encode:
0 = dead
1 = scalar
2 = pointer
3 = multiword

If multiword, the two-bit entry for the following word encodes:
0 = string
1 = slice
2 = iface
3 = eface

That way, during stack scanning we can check if a string
is zero length or a slice has zero capacity.  We can avoid
following the contained pointer in those cases.  It is safe
to do so because it can never be dereferenced, and it is
desirable to do so because it may cause false retention
of the following block in memory.

Slice feature turned off until issue 7564 is fixed.

Update #7549

LGTM=rsc
R=golang-codereviews, bradfitz, rsc
CC=golang-codereviews
https://golang.org/cl/76380043
2014-03-25 14:11:34 -07:00
Jan Ziak
833dae6d26 cmd/gc: fix spurious 'const initializer is not a constant' error
Fixes #6403

LGTM=rsc
R=iant, rsc
CC=golang-codereviews
https://golang.org/cl/72840044
2014-03-24 20:36:42 +01:00
Jan Ziak
a43673cf8a cmd/gc: round floats with a large negative exponent towards zero
Fixes #6902

LGTM=iant
R=iant, rsc
CC=golang-codereviews
https://golang.org/cl/78730049
2014-03-24 10:10:29 -07:00
David du Colombier
dc008af94d cmd/ld: fix warnings on Plan 9
warning: src/cmd/ld/macho.c:595 sign-extended character constant
warning: src/cmd/ld/macho.c:595 sign-extended character constant
warning: src/cmd/ld/symtab.c:63 sign-extended character constant
warning: src/cmd/ld/symtab.c:63 sign-extended character constant

LGTM=iant
R=golang-codereviews, iant
CC=golang-codereviews
https://golang.org/cl/76580046
2014-03-21 19:26:47 +01:00
Rémy Oudompheng
0285d2b96b cmd/6g, cmd/8g: skip CONVNOP nodes in bgen.
Revision 3ae4607a43ff introduced CONVNOP layers
to fix type checking issues arising from comparisons.
The added complexity made 8g run out of registers
when compiling an equality function in go.net/ipv6.

A similar issue occurred in test/sizeof.go on
amd64p32 with 6g.

Fixes #7405.

LGTM=khr
R=rsc, dave, iant, khr
CC=golang-codereviews
https://golang.org/cl/78100044
2014-03-20 22:22:37 +01:00
Rémy Oudompheng
ceb346685d cmd/6g: make comment more consistent.
LGTM=dave, iant
R=iant, khr, rsc, dave
CC=golang-codereviews
https://golang.org/cl/77960044
2014-03-20 22:21:10 +01:00
Ian Lance Taylor
6ea340fd61 cmd/6g: remove unused stosptr variable
LGTM=bradfitz
R=golang-codereviews, bradfitz
CC=golang-codereviews
https://golang.org/cl/78030043
2014-03-19 17:18:25 -07:00
Keith Randall
14664050b9 cmd/6g: do small zeroings with straightline code.
Removes most uses of the REP prefix, which has a high startup cost.

LGTM=iant
R=golang-codereviews, iant, khr
CC=golang-codereviews
https://golang.org/cl/77920043
2014-03-19 15:41:34 -07:00
Jan Ziak
cb50277510 cmd/gc: check exponent overflow and underflow in mparith
A too large float constant is an error.
A too small float constant is rounded to zero.

Fixes #7419
Update #6902

LGTM=iant
R=golang-codereviews, iant
CC=golang-codereviews
https://golang.org/cl/76730046
2014-03-19 05:48:00 +01:00
Jan Ziak
f081e2b9f4 cmd/go: let build -x output describe CGO_LDFLAGS env variable
Fixes #7249

LGTM=iant
R=golang-codereviews, iant
CC=golang-codereviews
https://golang.org/cl/75820046
2014-03-18 21:47:21 +01:00
Rob Pike
108a4dcd75 cmd/go: make the default coverage mode -atomic if -race is set
Fixes #7013.

LGTM=adg
R=golang-codereviews, gobot, adg
CC=golang-codereviews
https://golang.org/cl/76370043
2014-03-18 14:38:40 +11:00
Ian Lance Taylor
e3609ca672 cmd/gc: fix comment about how GOEXPERIMENT works
LGTM=minux.ma
R=golang-codereviews, minux.ma
CC=golang-codereviews
https://golang.org/cl/76270043
2014-03-15 11:18:11 -07:00
Rémy Oudompheng
f210fd1fa9 cmd/6g, runtime: alignment fixes for amd64p32.
LGTM=rsc
R=rsc, dave, iant, khr
CC=golang-codereviews
https://golang.org/cl/75820044
2014-03-14 19:37:39 +01:00
Jan Ziak
22aa54965e cmd/go: fix invalid go pack command line in the output of go build -x
Fixes #7262

LGTM=iant
R=golang-codereviews, iant
CC=golang-codereviews
https://golang.org/cl/76110043
2014-03-14 16:44:54 +01:00
Jan Ziak
1483747f3c cmd/gc: fix spurious 'not enough arguments to return' error
Fixes #6405

LGTM=rsc
R=rsc, iant
CC=golang-codereviews
https://golang.org/cl/72920046
2014-03-14 16:42:42 +01:00
Shenghou Ma
cbe777b2c7 cmd/gc: replace '·' as '.' in ELF/Mach-O symbol tables
Old versions of DTrace (as those shipped in OS X and FreeBSD)
don't support unicode characters in symbol names.  Replace '·'
to '.' to make DTrace happy.

Fixes #7493

LGTM=aram, rsc
R=aram, rsc, gobot, iant
CC=golang-codereviews
https://golang.org/cl/72280043
2014-03-14 10:07:51 -04:00
Rémy Oudompheng
fcc10bc0f1 cmd/gc: fix spurious type errors in walkselect.
The lowering to runtime calls introduces hidden pointers to the
arguments of select clauses. When implicit conversions were
involved it could end up with incompatible pointers. Since the
pointed-to types have the same representation, we can introduce a
forced conversion.

Fixes #6847.

LGTM=rsc
R=rsc, iant, khr
CC=golang-codereviews
https://golang.org/cl/72380043
2014-03-13 08:14:05 +01:00
Rémy Oudompheng
741244e433 cmd/6g: fix stack zeroing preamble on amd64p32.
It was using a REP STOSQ but putting in CX the number of 32-bit
words to clear.

LGTM=dave
R=rsc, dave
CC=golang-codereviews
https://golang.org/cl/75240043
2014-03-13 08:12:38 +01:00
Michael Hudson-Doyle
12474d01c4 cmd/go: use correct libraries during gccgo link
Under some circumstances, gccgoToolchain's ld can pass the path of
build outputs that have been deleted to the link command.

Fixes #7303.

LGTM=rsc
R=golang-codereviews, dave, michael.hudson, rsc
CC=golang-codereviews
https://golang.org/cl/61970044
2014-03-12 23:05:54 -04:00
Anthony Martin
b53d2f5ba7 cmd/gc: make the fpu handle all exceptions on Plan 9
The compilers expect to not be interrupted by floating
point exceptions. On Plan 9, every process starts with
interrupts enabled for invalid operation, stack overflow,
and divide by zero exceptions.

LGTM=rsc
R=rsc, 0intro
CC=golang-codereviews
https://golang.org/cl/72750043
2014-03-12 19:41:36 -07:00
Anthony Martin
b67979320a cmd/ld: give acid a fighting chance at unwinding the stack
Acid can't produce a stack trace without .frame symbols.

Of course, it can only unwind through linear stacks but
this is still better than nothing. (I wrote an acid func
to do the full unwind a long time ago but lost it and
haven't worked up the courage to write it again).

Note that these will only be present in the native symbol
table for Plan 9 binaries.

LGTM=rsc
R=rsc
CC=golang-codereviews
https://golang.org/cl/72450045
2014-03-12 18:10:31 -07:00
Jan Ziak
b87c7729ba cmd/go: respect system CGO_CFLAGS and CGO_CXXFLAGS
Fixes #6882

LGTM=iant
R=rsc, iant
CC=golang-codereviews
https://golang.org/cl/72080043
2014-03-12 07:16:22 +01:00
Russ Cox
ab844022ee cmd/gc: fix crash in -live mode
debuglive >= 1 is not the condition under which we
start recording messages (we avoid printing for
init functions even if debuglive is set).

LGTM=bradfitz, iant
R=golang-codereviews, bradfitz
CC=golang-codereviews, iant, khr
https://golang.org/cl/74390043
2014-03-11 23:58:11 -04:00
Rémy Oudompheng
e09ac3cf2a cmd/gc: correct GOARCH in object files for amd64p32.
LGTM=dave
R=rsc, dave
CC=golang-codereviews
https://golang.org/cl/72260045
2014-03-07 23:18:07 +01:00
Rémy Oudompheng
3d5e219e02 cmd/gc: enforce register-width alignment for stack sizes.
This fixes the following amd64p32 issue:
    pkg/time/format.go:724: internal compiler error: twobitwalktype1: invalid initial alignment, Time

caused by the pointer zone ending on a 32-bit-aligned boundary.

LGTM=rsc
R=rsc, dave
CC=golang-codereviews
https://golang.org/cl/72270046
2014-03-07 20:28:18 +01:00
Dave Cheney
e509bbc943 cmd/6a: add support for nacl/amd64p32
Replaces CL 70000043.

Switch to the amd64p32 linker model if we are building under nacl/amd64p32.

No need to introduce linkarchinit() as 6a contains its own main() function.

LGTM=rsc
R=rsc, minux.ma
CC=golang-codereviews
https://golang.org/cl/72020043
2014-03-07 16:02:25 +11:00
Dave Cheney
e31a1ce109 cmd/gc, cmd/5g, cmd/6g, cmd/8g: introduce linkarchinit and add amd64p32 support
Replaces CL 70000043.

Introduce linkarchinit() from cmd/ld.

For cmd/6g, switch to the amd64p32 linker model if we are building under nacl/amd64p32.

LGTM=rsc
R=rsc
CC=golang-codereviews
https://golang.org/cl/71330045
2014-03-07 15:33:44 +11:00
Russ Cox
9abcd53eda cmd/go: add test case for cgo coverage
This is a test case for CL 34680044.

Fixes #6333.

LGTM=bradfitz
R=golang-codereviews, bradfitz, minux.ma
CC=golang-codereviews
https://golang.org/cl/71230049
2014-03-06 18:36:32 -05:00
Dave Cheney
1d2b7171d5 cmd/5c: fix arm build
cmd/5c/txt.c was missing from CL 72010043.

LGTM=bradfitz
R=rsc, bradfitz
CC=golang-codereviews
https://golang.org/cl/72220043
2014-03-07 10:13:00 +11:00
Dave Cheney
d4896fb876 cmd/cc, cmd/5c, cmd/6c, cmd/8c: introduce linkarchinit and add amd64p32 support
Replaces CL 70000043.

Introduce linkarchinit() from cmd/ld.

For cmd/6c, switch to the amd64p32 linker model if we are building under nacl/amd64p32.

LGTM=rsc
R=rsc
CC=golang-codereviews
https://golang.org/cl/72010043
2014-03-07 09:55:59 +11:00
Shenghou Ma
56e261ef2f cmd/dist: enable GOARM>5 on NetBSD/ARM.
Tested GOARM=6 on Raspberry Pi, and I found only a few tests that
use sub-normal numbers fails. I have a patch to NetBSD kernel pending
that fixes this issue (NetBSD kernel doesn't allow us to disable the
Flush-to-Zero feature).

LGTM=jsing
R=golang-codereviews, jsing
CC=golang-codereviews
https://golang.org/cl/70730043
2014-03-06 00:57:23 -05:00
Shenghou Ma
c887193382 cmd/dist: support building pkg/runtime/*.
Essentialy for running tests without a working cmd/go.
While we're at it, also fix a typo.

LGTM=rsc
R=golang-codereviews, rsc
CC=golang-codereviews
https://golang.org/cl/70640043
2014-03-05 14:57:17 -05:00
Shenghou Ma
37e195cf72 cmd/ld: don't include padding length in size of the note section
Recently NetBSD starts to enforce this, and refuses to execute
the program if n is larger than the sum of entry sizes.

Before:
$ readelf -n ../bin/go.old
Notes at offset 0x00000bd0 with length 0x00000019:
  Owner         Data size       Description
  NetBSD                0x00000004      NT_VERSION (version)
readelf: Warning: corrupt note found at offset 18 into core notes
readelf: Warning:  type: 0, namesize: 00000000, descsize: 00000000
$ readelf -n ../bin/go
Notes at offset 0x00000bd0 with length 0x00000018:
Owner         Data size       Description
NetBSD                0x00000004      NT_VERSION (version)

LGTM=iant
R=iant
CC=golang-codereviews
https://golang.org/cl/70710043
2014-03-05 14:40:55 -05:00
Alberto García Hierro
22705d0995 cmd/go: add support for coverage in CgoFiles
Add CgoFiles to the covered files when building
with cover support.

LGTM=rsc
R=golang-codereviews, gobot, r, rsc
CC=golang-codereviews
https://golang.org/cl/34680044
2014-03-05 14:28:11 -05:00
Russ Cox
3f1374fcf8 cmd/dist: use vfprintf on Windows, same as on Unix
Apparently, the Windows routines sometimes fail to generate output.
Copy the Unix stdio-based implementations instead.

Suggested by Pietro Gagliardi in CL 65280043 but that CL
seems to have been abandoned.

Fixes #7242.

LGTM=bradfitz
R=golang-codereviews, bradfitz
CC=golang-codereviews
https://golang.org/cl/71550044
2014-03-05 14:16:30 -05:00
Chris Manghane
671cc6efba cmd/gc: allow append and complex builtins to accept 2-result call expression as first argument.
Fixes #5793.

LGTM=rsc
R=rsc, adonovan, dave
CC=golang-codereviews
https://golang.org/cl/13367051
2014-03-05 14:16:21 -05:00
Jan Ziak
202e6153f5 cmd/dist: respect system CFLAGS/LDFLAGS
Update #6882.

LGTM=rsc
R=golang-codereviews, rsc
CC=golang-codereviews
https://golang.org/cl/69860055
2014-03-05 14:10:22 -05:00
Russ Cox
c2dd33a46f cmd/ld: clear unused ctxt before morestack
For non-closure functions, the context register is uninitialized
on entry and will not be used, but morestack saves it and then the
garbage collector treats it as live. This can be a source of memory
leaks if the context register points at otherwise dead memory.
Avoid this by introducing a parallel set of morestack functions
that clear the context register, and use those for the non-closure functions.

I hope this will help with some of the finalizer flakiness, but it probably won't.

Fixes #7244.

LGTM=dvyukov
R=khr, dvyukov
CC=golang-codereviews
https://golang.org/cl/71030044
2014-03-04 13:53:08 -05:00
Dmitriy Vyukov
d1c6c6004b cmd/go: fix data race on buildLdflags
Fixes #7438.

LGTM=rsc
R=golang-codereviews
CC=bradfitz, golang-codereviews, iant, rsc
https://golang.org/cl/70420044
2014-03-04 11:42:02 +04:00
Rémy Oudompheng
52e6d7c622 cmd/gc: use a register to checknil constants.
Fixes #7346.

LGTM=rsc
R=rsc, iant, khr
CC=golang-codereviews
https://golang.org/cl/69050044
2014-03-04 08:18:17 +01:00
Russ Cox
56b983c112 cmd/gc: fix internal crash
TBR=ken2
CC=golang-codereviews
https://golang.org/cl/70200053
2014-03-03 19:55:40 -05:00
Graham King
ebe1eb6537 cmd/ld: DWARF opcode base to 10
DWARF 2 has 9 standard opcodes, so dwarfdump expects us to use an
opcode base of at least 10. Previously we used 5.

Discussion:
https://groups.google.com/forum/#!topic/golang-dev/d-BqpPgalzc

LGTM=josharian, rsc
R=golang-codereviews, gobot, rsc, josharian, iant, bradfitz
CC=golang-codereviews
https://golang.org/cl/69320043
2014-03-03 11:11:04 -08:00
David du Colombier
f608806092 cmd/ld: fix warning on Plan 9
warning: src/cmd/ld/pcln.c:184 more arguments than format INT

LGTM=iant
R=golang-codereviews, iant
CC=golang-codereviews
https://golang.org/cl/69870047
2014-03-03 08:14:27 +01:00
Josh Bleecher Snyder
91e3681105 cmd/ld: fix misgenerated pcln file numbers
The pcln file number was being encoded incorrectly. The recorded delta was always against -1, not against the previous value.

Update #7369

This CL fixes the bad DWARF file numbers. It does not, however, fix the gdb continue-to-end bug.

LGTM=iant
R=rsc, minux.ma, iant
CC=golang-codereviews, graham
https://golang.org/cl/68960046
2014-02-28 11:08:32 -08:00
Dave Cheney
b3e0a8df24 cmd/dist: add missing Native Client bits
Some parts of CL 15400047 didn't survive the merge.

LGTM=rsc
R=rsc, iant
CC=golang-codereviews
https://golang.org/cl/69870044
2014-02-28 21:45:12 +11:00
Russ Cox
d9c6ae6ae8 all: final merge of NaCl tree
This CL replays the following one CL from the rsc-go13nacl repo.
This is the last replay CL: after this CL the main repo will have
everything the rsc-go13nacl repo did. Changes made to the main
repo after the rsc-go13nacl repo branched off probably mean that
NaCl doesn't actually work after this CL, but all the code is now moved
over and just needs to be redebugged.

---
cmd/6l, cmd/8l, cmd/ld: support for Native Client

See golang.org/s/go13nacl for design overview.

This CL is publicly visible but not CC'ed to golang-dev,
to avoid distracting from the preparation of the Go 1.2
release.

This CL and the others will be checked into my rsc-go13nacl
clone repo for now, and I will send CLs against the main
repo early in the Go 1.3 development.

R≡khr
https://golang.org/cl/15750044
---

LGTM=bradfitz, dave, iant
R=dave, bradfitz, iant
CC=golang-codereviews
https://golang.org/cl/69040044
2014-02-27 20:37:00 -05:00
Robert Griesemer
e9ee0bf63c cmd/gofmt: minor internal cleanups
Reflect changes of reflect API.

LGTM=r
R=golang-codereviews, r
CC=golang-codereviews
https://golang.org/cl/69240044
2014-02-27 09:00:27 -08:00
Rémy Oudompheng
e5f01aee04 cmd/gc: do not nop-convert equivalent but different interface types.
The cached computed interface tables are indexed by the interface
types, not by the unnamed underlying interfaces

To preserve the invariants expected by interface comparison, an
itab generated for an interface type must not be used for a value
of a different interface type even if the representation is identical.

Fixes #7207.

LGTM=rsc
R=rsc, iant, khr
CC=golang-codereviews
https://golang.org/cl/69210044
2014-02-27 08:07:50 +01:00
Josh Bleecher Snyder
3081261b58 cmd/gc: fix bad checknil with ints on 32 bit compilers
Fixes #7413.

LGTM=rsc
R=remyoudompheng
CC=golang-codereviews, r, rsc
https://golang.org/cl/69180044
2014-02-26 12:25:13 -08:00
Dave Cheney
7954b2b90b cmd/5a, cmd/5c, cmd/6a, cmd/6c, cmd/8a, cmd/8c, cmd/cc: support for Native Client
From the original description in CL 15770043

The main change here is to consult $GOARCH.

In 6c, when GOOS=nacl, some of the more complex addressing modes must be disabled, and the BP and R15 registers must not be used.

See golang.org/s/go13nacl for design overview.

LGTM=rsc
R=golang-codereviews, gobot, rsc
CC=golang-codereviews
https://golang.org/cl/69020044
2014-02-27 06:57:06 +11:00
Ian Lance Taylor
77ac8ecbeb cmd/gc: minor code simplification
LGTM=r
R=golang-codereviews, r
CC=golang-codereviews
https://golang.org/cl/68980044
2014-02-26 10:51:00 -08:00
Ian Lance Taylor
fa6375ea47 cmd/6g, cmd/8g: simplify calls to gvardef
The gvardef function does nothing if n->class == PEXTERN, so
we don't need to test for that before calling it.  This makes
the 6g/8g code more like the 5g code and clarifies that the
cases that do not test for n->class != PEXTERN are not buggy.

LGTM=rsc
R=rsc
CC=golang-codereviews
https://golang.org/cl/68900044
2014-02-26 07:37:10 -08:00
Andrew Gerrand
66562b9698 cmd/go: remove 'go tool benchcmp' and corresponding special case
See the discussion on the original CL for context:
        https://golang.org/cl/60100043/

LGTM=josharian
R=r, josharian
CC=golang-codereviews
https://golang.org/cl/68890043
2014-02-26 13:04:39 +11:00
Josh Bleecher Snyder
d97d37188a 5g, 8g: remove dead code
maxstksize is superfluous and appears to be vestigial. 6g does not use it.

c >= 4 cannot occur; c = w % 4.

LGTM=rsc
R=rsc
CC=golang-codereviews
https://golang.org/cl/68750043
2014-02-25 14:43:53 -08:00
Russ Cox
4a000b9d51 all: nacl import round 2
These previously reviewed CLs are present in this CL.

---
changeset:   18445:436bb084caed
user:        Russ Cox <rsc@golang.org>
date:        Mon Nov 11 09:50:34 2013 -0500
description:
runtime: assembly and system calls for Native Client x86-64

See golang.org/s/go13nacl for design overview.

This CL is publicly visible but not CC'ed to golang-dev,
to avoid distracting from the preparation of the Go 1.2
release.

This CL and the others will be checked into my rsc-go13nacl
clone repo for now, and I will send CLs against the main
repo early in the Go 1.3 development.

R≡adg
https://golang.org/cl/15760044

---
changeset:   18448:90bd871b5994
user:        Russ Cox <rsc@golang.org>
date:        Mon Nov 11 09:51:36 2013 -0500
description:
runtime: amd64p32 and Native Client assembly bootstrap

See golang.org/s/go13nacl for design overview.

This CL is publicly visible but not CC'ed to golang-dev,
to avoid distracting from the preparation of the Go 1.2
release.

This CL and the others will be checked into my rsc-go13nacl
clone repo for now, and I will send CLs against the main
repo early in the Go 1.3 development.

R≡khr
https://golang.org/cl/15820043

---
changeset:   18449:b011c3dc687e
user:        Russ Cox <rsc@golang.org>
date:        Mon Nov 11 09:51:58 2013 -0500
description:
math: amd64p32 assembly routines

These routines only manipulate float64 values,
so the amd64 and amd64p32 can share assembly.

The large number of files is symptomatic of a problem
with package path: it is a Go package structured like a C library.
But that will need to wait for another day.

See golang.org/s/go13nacl for design overview.

This CL is publicly visible but not CC'ed to golang-dev,
to avoid distracting from the preparation of the Go 1.2
release.

This CL and the others will be checked into my rsc-go13nacl
clone repo for now, and I will send CLs against the main
repo early in the Go 1.3 development.

R≡bradfitz
https://golang.org/cl/15870043

---
changeset:   18450:43234f082eec
user:        Russ Cox <rsc@golang.org>
date:        Mon Nov 11 10:03:19 2013 -0500
description:
syscall: networking for Native Client

See golang.org/s/go13nacl for design overview.

This CL is publicly visible but not CC'ed to golang-dev,
to avoid distracting from the preparation of the Go 1.2
release.

This CL and the others will be checked into my rsc-go13nacl
clone repo for now, and I will send CLs against the main
repo early in the Go 1.3 development.

R≡rsc
https://golang.org/cl/15780043

---
changeset:   18451:9c8d1d890aaa
user:        Russ Cox <rsc@golang.org>
date:        Mon Nov 11 10:03:34 2013 -0500
description:
runtime: assembly and system calls for Native Client x86-32

See golang.org/s/go13nacl for design overview.

This CL is publicly visible but not CC'ed to golang-dev,
to avoid distracting from the preparation of the Go 1.2
release.

This CL and the others will be checked into my rsc-go13nacl
clone repo for now, and I will send CLs against the main
repo early in the Go 1.3 development.

R≡rsc
https://golang.org/cl/15800043

---
changeset:   18452:f90b1dd9228f
user:        Russ Cox <rsc@golang.org>
date:        Mon Nov 11 11:04:09 2013 -0500
description:
runtime: fix frame size for linux/amd64 runtime.raise

R≡rsc
https://golang.org/cl/24480043

---
changeset:   18445:436bb084caed
user:        Russ Cox <rsc@golang.org>
date:        Mon Nov 11 09:50:34 2013 -0500
description:
runtime: assembly and system calls for Native Client x86-64

See golang.org/s/go13nacl for design overview.

This CL is publicly visible but not CC'ed to golang-dev,
to avoid distracting from the preparation of the Go 1.2
release.

This CL and the others will be checked into my rsc-go13nacl
clone repo for now, and I will send CLs against the main
repo early in the Go 1.3 development.

R≡adg
https://golang.org/cl/15760044

---
changeset:   18455:53b06799a938
user:        Russ Cox <rsc@golang.org>
date:        Mon Nov 11 23:29:52 2013 -0500
description:
cmd/gc: add -nolocalimports flag

R≡dsymonds
https://golang.org/cl/24990043

---
changeset:   18456:24f64e1eaa8a
user:        Russ Cox <rsc@golang.org>
date:        Tue Nov 12 22:06:29 2013 -0500
description:
runtime: add comments for playback write

R≡adg
https://golang.org/cl/25190043

---
changeset:   18457:d1f615bbb6e4
user:        Russ Cox <rsc@golang.org>
date:        Wed Nov 13 17:03:52 2013 -0500
description:
runtime: write only to NaCl stdout, never to NaCl stderr

NaCl writes some other messages on standard error
that we would like to be able to squelch.

R≡adg
https://golang.org/cl/26240044

---
changeset:   18458:1f01be1a1dc2
tag:         tip
user:        Russ Cox <rsc@golang.org>
date:        Wed Nov 13 19:45:16 2013 -0500
description:
runtime: remove apparent debugging dreg

Setting timens to 0 turns off fake time.

TBR≡adg
https://golang.org/cl/26400043

LGTM=bradfitz
R=dave, bradfitz
CC=golang-codereviews
https://golang.org/cl/68730043
2014-02-25 17:00:08 -05:00
Russ Cox
441c4bb939 cmd/go: fix bug in remote package discovery
The parser was assuming it would find <body> or </head>.
If the entire response is just <meta> tags, it finds EOF and
treats that as an error. It's not.

LGTM=bradfitz
R=bradfitz
CC=golang-codereviews
https://golang.org/cl/68520044
2014-02-25 11:22:22 -05:00
Russ Cox
280d46b03b cmd/go: document new -exec flag on run/test
The new flag was added by CL 68150047 (part of the NaCl replay),
but the change, like the original, omitted documentation of the
new behavior.

LGTM=r
R=r
CC=golang-codereviews
https://golang.org/cl/68580043
2014-02-25 10:22:27 -05:00
Dave Cheney
7c8280c9ef all: merge NaCl branch (part 1)
See golang.org/s/go13nacl for design overview.

This CL is the mostly mechanical changes from rsc's Go 1.2 based NaCl branch, specifically 39cb35750369 to 500771b477cf from https://code.google.com/r/rsc-go13nacl. This CL does not include working NaCl support, there are probably two or three more large merges to come.

CL 15750044 is not included as it involves more invasive changes to the linker which will need to be merged separately.

The exact change lists included are

15050047: syscall: support for Native Client
15360044: syscall: unzip implementation for Native Client
15370044: syscall: Native Client SRPC implementation
15400047: cmd/dist, cmd/go, go/build, test: support for Native Client
15410048: runtime: support for Native Client
15410049: syscall: file descriptor table for Native Client
15410050: syscall: in-memory file system for Native Client
15440048: all: update +build lines for Native Client port
15540045: cmd/6g, cmd/8g, cmd/gc: support for Native Client
15570045: os: support for Native Client
15680044: crypto/..., hash/crc32, reflect, sync/atomic: support for amd64p32
15690044: net: support for Native Client
15690048: runtime: support for fake time like on Go Playground
15690051: build: disable various tests on Native Client

LGTM=rsc
R=rsc
CC=golang-codereviews
https://golang.org/cl/68150047
2014-02-25 09:47:42 -05:00
Shenghou Ma
e2fe968d5f cmd/ld: fix build for ARMv5.
Credit goes to Dave Cheney for debugging the issue.

LGTM=dave, rsc
R=dave, rsc
CC=golang-codereviews
https://golang.org/cl/67820043
2014-02-25 06:53:17 +11:00
Rémy Oudompheng
14b0af4272 cmd/gc: fix walkcompare bugs.
Revision c0e0467635ec (cmd/gc: return canonical Node* from temp)
exposed original nodes of temporaries, allowing callers to mutate
their types.

In walkcompare a temporary could be typed as ideal because of
this. Additionnally, assignment of a comparison result to
a custom boolean type was broken.

Fixes #7366.

LGTM=rsc
R=rsc, iant, khr
CC=golang-codereviews
https://golang.org/cl/66930044
2014-02-24 19:51:59 +01:00
Lucio De Re
ff15e5c00f cmd/go: Plan 9 compatible "env" output
Fixes the output of go env so that variables can be set
more accurately when using Plan 9's rc shell. Specifically,
GOPATH may have multiple components and the current
representation is plain wrong. In practice, we probably
ought to change os. Getenv to produce the right result, but
that requires considerably more thought.

LGTM=rsc
R=golang-codereviews, gobot, rsc
CC=golang-codereviews
https://golang.org/cl/66600043
2014-02-24 19:48:06 +01:00
Shenghou Ma
e33e47e844 cmd/gc: diagnose "make([]T, non-integer)" correctly.
Fixes #7223.

LGTM=rsc
R=golang-codereviews, gobot, rsc
CC=golang-codereviews
https://golang.org/cl/63040043
2014-02-23 16:31:48 -05:00
Shenghou Ma
d4a9bbef51 cmd/ld: don't emit unreachable dynimport symbols in ELF symtab.
Fix build for Dragonfly BSD.
Fixes #7318.
Fixes #7367.

LGTM=jsing, iant
R=jsing, iant, mikioh.mikioh
CC=golang-codereviews
https://golang.org/cl/64340043
2014-02-23 16:20:40 -05:00
Russ Cox
67c83db60d runtime: use goc2c as much as possible
Package runtime's C functions written to be called from Go
started out written in C using carefully constructed argument
lists and the FLUSH macro to write a result back to memory.

For some functions, the appropriate parameter list ended up
being architecture-dependent due to differences in alignment,
so we added 'goc2c', which takes a .goc file containing Go func
declarations but C bodies, rewrites the Go func declaration to
equivalent C declarations for the target architecture, adds the
needed FLUSH statements, and writes out an equivalent C file.
That C file is compiled as part of package runtime.

Native Client's x86-64 support introduces the most complex
alignment rules yet, breaking many functions that could until
now be portably written in C. Using goc2c for those avoids the
breakage.

Separately, Keith's work on emitting stack information from
the C compiler would require the hand-written functions
to add #pragmas specifying how many arguments are result
parameters. Using goc2c for those avoids maintaining #pragmas.

For both reasons, use goc2c for as many Go-called C functions
as possible.

This CL is a replay of the bulk of CL 15400047 and CL 15790043,
both of which were reviewed as part of the NaCl port and are
checked in to the NaCl branch. This CL is part of bringing the
NaCl code into the main tree.

No new code here, just reformatting and occasional movement
into .h files.

LGTM=r
R=dave, alex.brainman, r
CC=golang-codereviews
https://golang.org/cl/65220044
2014-02-20 15:58:47 -05:00
Russ Cox
258c278e12 cmd/pack: fix match
Match used len(ar.files) == 0 to mean "match everything"
but it also deleted matched things from the list, so once you
had matched everything you asked for, match returned true
for whatever was left in the archive too.

Concretely, if you have an archive containing f1, f2, then
        pack t foo.a f1
would match f1 and then, because len(ar.files) == 0 after
deleting f1 from the match list, also match f2.

Avoid the problem by recording explicitly whether match
matches everything.

LGTM=r, dsymonds
R=r, dsymonds
CC=golang-codereviews
https://golang.org/cl/65630046
2014-02-20 15:50:30 -05:00
Russ Cox
574e0f9a48 cmd/gc: explain 'nointerface' method failure
The message used to say that there was a type
mismatch, which is not necessarily true.

TBR=ken2
CC=golang-codereviews
https://golang.org/cl/66600044
2014-02-20 15:42:08 -05:00
Chris Manghane
a8a7f18aea cmd/gc: make embedded, unexported fields read-only.
Fixes #7363.

LGTM=gri
R=gri, rsc, bradfitz
CC=golang-codereviews
https://golang.org/cl/66510044
2014-02-20 11:32:55 -08:00
Josh Bleecher Snyder
15ec569ba9 cmd/ld: fix off-by-one error in DWARF .debug_line transcription
The liblink refactor changed the DWARF .debug_line flow control. The mapping was off by one pcline entry. The fix here preserves pc until it can be compared to pcline.pc.

Sample dwarfdump .debug_line output for main.main from the program in issue 7351, before liblink (correct):

0x0000003c: 00 Extended: <9> 02 DW_LNE_set_address( 0x0000000000002000 )
0x00000047: 03 DW_LNS_advance_line( 6 )
0x00000049: 01 DW_LNS_copy
            0x0000000000002000      1      7      0 is_stmt

0x0000004a: 8b address += 21,  line += 1
            0x0000000000002021      1      8      0 is_stmt

0x0000004b: 02 DW_LNS_advance_pc( 153 )
0x0000004e: 03 DW_LNS_advance_line( 1 )
0x00000050: 01 DW_LNS_copy
            0x00000000000020ba      1      9      0 is_stmt

After liblink (off by one entry):

0x00001bbf: 00 Extended: <9> 02 DW_LNE_set_address( 0x0000000000002000 )
0x00001bca: 02 DW_LNS_advance_pc( 33 )
0x00001bcc: 03 DW_LNS_advance_line( 6 )
0x00001bce: 01 DW_LNS_copy
            0x0000000000002021      1      7      0 is_stmt

0x00001bcf: 02 DW_LNS_advance_pc( 153 )
0x00001bd2: 03 DW_LNS_advance_line( 1 )
0x00001bd4: 01 DW_LNS_copy
            0x00000000000020ba      1      8      0 is_stmt

0x00001bd5: 02 DW_LNS_advance_pc( 153 )
0x00001bd8: 03 DW_LNS_advance_line( 1 )
0x00001bda: 01 DW_LNS_copy
            0x0000000000002153      1      9      0 is_stmt

After this CL (the line 9 pc offset changed due to intervening compiler changes):

0x00001d07: 00 Extended: <9> 02 DW_LNE_set_address( 0x0000000000002000 )
0x00001d12: 03 DW_LNS_advance_line( 6 )
0x00001d14: 01 DW_LNS_copy
            0x0000000000002000      1      7      0 is_stmt

0x00001d15: 8b address += 21,  line += 1
            0x0000000000002021      1      8      0 is_stmt

0x00001d16: 02 DW_LNS_advance_pc( 189 )
0x00001d19: 03 DW_LNS_advance_line( 1 )
0x00001d1b: 01 DW_LNS_copy
            0x00000000000020de      1      9      0 is_stmt

Fixes #7351.

LGTM=rsc
R=rsc
CC=golang-codereviews
https://golang.org/cl/66290043
2014-02-20 09:06:32 -08:00
Alex Brainman
0d11cd1b6e cmd/pack: provide executable name in TestHello
otherwise go build command adds .exe suffix

Fixes #7362

LGTM=bradfitz
R=golang-codereviews, bradfitz
CC=golang-codereviews
https://golang.org/cl/66250043
2014-02-20 11:29:37 +11:00
Rob Pike
00b76713a7 cmd/pack: another attempt to fix the build for TestHello
Plan 9 uses single quotes, not double quotes. I should have known.

LGTM=bradfitz
R=bradfitz
CC=golang-codereviews
https://golang.org/cl/66240043
2014-02-19 16:12:05 -08:00
Rob Pike
2037756fcc cmd/pack: don't look for " in output from go env
Windows at least doesn't emit one.
Maybe fix Windows build.

LGTM=bradfitz
R=bradfitz
CC=golang-codereviews
https://golang.org/cl/66120046
2014-02-19 15:33:47 -08:00
Rob Pike
8ac499916e cmd/pack: dump output of command of "go env" command in test
Get more information to help understand build failure on Plan 9.
Also Windows.
(TestHello is failing because GOCHAR does not appear in output.
What does?)

Update #7362

LGTM=bradfitz
R=rsc, bradfitz
CC=golang-codereviews
https://golang.org/cl/66070044
2014-02-19 15:01:50 -08:00
Russ Cox
53061193f1 cmd/gc, runtime: enable precisestack by default
[Repeat of CL 64100044, after 32-bit fix in CL 66170043.]

Precisestack makes stack collection completely precise,
in the sense that there are no "used and not set" errors
in the collection of stack frames, no times where the collector
reads a pointer from a stack word that has not actually been
initialized with a pointer (possibly a nil pointer) in that function.

The most important part is interfaces: precisestack means
that if reading an interface value, the interface value is guaranteed
to be initialized, meaning that the type word can be relied
upon to be either nil or a valid interface type word describing
the data word.

This requires additional zeroing of certain values on the stack
on entry, which right now costs about 5% overall execution
time in all.bash. That cost will come down before Go 1.3
(issue 7345).

There are at least two known garbage collector bugs right now,
issues 7343 and 7344. The first happens even without precisestack.
The second I have only seen with precisestack, but that does not
mean that precisestack is what causes it. In fact it is very difficult
to explain by what precisestack does directly. Precisestack may
be exacerbating an existing problem. Both of those issues are
marked for Go 1.3 as well.

The reasons for enabling precisestack now are to give it more
time to soak and because the copying stack work depends on it.

LGTM=r
R=r
CC=golang-codereviews
https://golang.org/cl/65820044
2014-02-19 17:09:08 -05:00
Russ Cox
1ca1cbea65 cmd/5g, cmd/8g: zero ambiguously live values on entry
The code here is being restored after its deletion in CL 14430048.

I restored the copy in cmd/6g in CL 56430043 but neglected the
other two.

This is the reason that enabling precisestack only worked on amd64.

LGTM=r
R=r
CC=golang-codereviews
https://golang.org/cl/66170043
2014-02-19 17:08:55 -05:00
Russ Cox
0649a73606 cmd/pack: add 'c' command to create archive
When Go 1.3 is released, this will keep existing
Go 1.2 build scripts that use 'go tool pack grc' working.
For efficiency, such scripts should be changed to
use 6g -pack instead, but keeping the old behavior
available enables a more graceful transition.

LGTM=r
R=r
CC=golang-codereviews
https://golang.org/cl/66130043
2014-02-19 17:08:44 -05:00
Rob Pike
78404dfb84 cmd/gc: fix printf format in typecheck.c
There are probably more of these, but bound and len are 64 bits so use %lld
in message about array index out of bounds.
Fixes the 386 build.

LGTM=bradfitz, rsc
R=rsc, bradfitz
CC=golang-codereviews, rickarnoldjr
https://golang.org/cl/66110043
2014-02-19 15:50:50 -05:00
Rob Pike
e6f5debd0c cmd/pack: use log.SetPrefix to make log calls more compact and consistent
Taking my own advice from a review of addr2line.

LGTM=rsc
R=rsc
CC=golang-codereviews
https://golang.org/cl/65950044
2014-02-19 11:42:34 -08:00
Russ Cox
8efb5e7d63 cmd/addr2line: reimplement in Go
We never updated libmach for the new object file format,
so it the existing 'go tool addr2line' is broken.
Reimplement in Go to fix.

LGTM=r
R=golang-codereviews, r
CC=golang-codereviews
https://golang.org/cl/66020043
2014-02-19 14:33:11 -05:00
Rick Arnold
8eec4ebd7d cmd/gc: fix array index out of bounds error message
The error message was previously off by one in all cases.

Fixes #7150.

LGTM=r
R=golang-codereviews, r
CC=golang-codereviews
https://golang.org/cl/65850043
2014-02-19 11:29:36 -08:00
Russ Cox
ae38b03f6c cmd/go: skip writing dwarf debug info for ephemeral binaries
Update #6853

For an ephemeral binary - one created, run, and then deleted -
there is no need to write dwarf debug information, since the
binary will not be used with gdb. In this case, instruct the linker
not to spend time and disk space generating the debug information
by passing the -w flag to the linker.

Omitting dwarf information reduces the size of most binaries by 25%.
We may be more aggressive about this in the future.

LGTM=bradfitz, r
R=r, bradfitz
CC=golang-codereviews
https://golang.org/cl/65890043
2014-02-19 10:01:15 -05:00
Russ Cox
2541cc8197 cmd/ld: drop gcargs, gclocals symbols from symbol table
Update #6853

Every function now has a gcargs and gclocals symbol
holding associated garbage collection information.
Put them all in the same meta-symbol as the go.func data
and then drop individual entries from symbol table.

Removing gcargs and gclocals reduces the size of a
typical binary by 10%.

LGTM=r
R=r
CC=golang-codereviews
https://golang.org/cl/65870044
2014-02-19 10:00:44 -05:00
Rémy Oudompheng
475e7d0372 cmd/gc: fix handling of append with -race.
Also re-enable race tests in run.bash.

Fixes #7334.

LGTM=rsc
R=rsc, dvyukov, iant, bradfitz, dave
CC=golang-codereviews
https://golang.org/cl/65740043
2014-02-19 08:19:27 +01:00
Rémy Oudompheng
96678f9dc0 cmd/gc: reject incorrect use of fallthrough.
Fixes #6500.

LGTM=rsc
R=golang-codereviews, rsc
CC=golang-codereviews
https://golang.org/cl/14920053
2014-02-19 07:55:03 +01:00
Russ Cox
964f6d3ec4 cmd/ld: remove Plan 9 symbol table
Update #6853

Nothing reads the Plan 9 symbol table anymore.
The last holdout was 'go tool nm', but since being rewritten in Go
it uses the standard symbol table for the binary format
(ELF, Mach-O, PE) instead.

Removing the Plan 9 symbol table saves ~15% disk space
on most binaries.

Two supporting changes included in this CL:

debug/gosym: use Go 1.2 pclntab to synthesize func-only
symbol table when there is no Plan 9 symbol table

debug/elf, debug/macho, debug/pe: ignore final EOF from ReadAt

LGTM=r
R=r, bradfitz
CC=golang-codereviews
https://golang.org/cl/65740045
2014-02-18 23:41:15 -05:00
Rick Arnold
86ac618145 cmd/link: change cloneProg to return the cloned value
The code was returning the original value rather than the cloned value
resulting in the tests not being repeatable.

Fixes #7111.

LGTM=bradfitz
R=golang-codereviews, bradfitz
CC=golang-codereviews
https://golang.org/cl/65720045
2014-02-18 17:59:44 -08:00
Russ Cox
aad23e708c undo CL 64100044 / 04d062c2e81c
broke 32-bit builds

««« original CL description
cmd/gc, runtime: enable precisestack by default

Precisestack makes stack collection completely precise,
in the sense that there are no "used and not set" errors
in the collection of stack frames, no times where the collector
reads a pointer from a stack word that has not actually been
initialized with a pointer (possibly a nil pointer) in that function.

The most important part is interfaces: precisestack means
that if reading an interface value, the interface value is guaranteed
to be initialized, meaning that the type word can be relied
upon to be either nil or a valid interface type word describing
the data word.

This requires additional zeroing of certain values on the stack
on entry, which right now costs about 5% overall execution
time in all.bash. That cost will come down before Go 1.3
(issue 7345).

There are at least two known garbage collector bugs right now,
issues 7343 and 7344. The first happens even without precisestack.
The second I have only seen with precisestack, but that does not
mean that precisestack is what causes it. In fact it is very difficult
to explain by what precisestack does directly. Precisestack may
be exacerbating an existing problem. Both of those issues are
marked for Go 1.3 as well.

The reasons for enabling precisestack now are to give it more
time to soak and because the copying stack work depends on it.

LGTM=r
R=r
CC=golang-codereviews, iant, khr
https://golang.org/cl/64100044
»»»

TBR=r
CC=golang-codereviews
https://golang.org/cl/65230043
2014-02-17 21:34:58 -05:00
Nigel Tao
d2f61cc660 cmd/link: fix comment typo.
LGTM=dsymonds
R=dsymonds
CC=golang-codereviews
https://golang.org/cl/64100045
2014-02-18 13:04:59 +11:00
Russ Cox
ecf700b5ee cmd/gc, runtime: enable precisestack by default
Precisestack makes stack collection completely precise,
in the sense that there are no "used and not set" errors
in the collection of stack frames, no times where the collector
reads a pointer from a stack word that has not actually been
initialized with a pointer (possibly a nil pointer) in that function.

The most important part is interfaces: precisestack means
that if reading an interface value, the interface value is guaranteed
to be initialized, meaning that the type word can be relied
upon to be either nil or a valid interface type word describing
the data word.

This requires additional zeroing of certain values on the stack
on entry, which right now costs about 5% overall execution
time in all.bash. That cost will come down before Go 1.3
(issue 7345).

There are at least two known garbage collector bugs right now,
issues 7343 and 7344. The first happens even without precisestack.
The second I have only seen with precisestack, but that does not
mean that precisestack is what causes it. In fact it is very difficult
to explain by what precisestack does directly. Precisestack may
be exacerbating an existing problem. Both of those issues are
marked for Go 1.3 as well.

The reasons for enabling precisestack now are to give it more
time to soak and because the copying stack work depends on it.

LGTM=r
R=r
CC=golang-codereviews, iant, khr
https://golang.org/cl/64100044
2014-02-17 20:12:40 -05:00
Ian Lance Taylor
637e1f7da0 cmd/gc: correct function name in internal error messages
LGTM=r
R=golang-codereviews, r
CC=golang-codereviews
https://golang.org/cl/64090043
2014-02-16 19:14:06 -08:00
Russ Cox
1a3ee6794c cmd/gc: record &x[0] as taking address of x, if x is an array
Not recording the address being taken was causing
the liveness analysis not to preserve x in the absence
of direct references to x, which in turn was making the
net test fail with GOGC=0.

In addition to the test, this fixes a bug wherein
        GOGC=0 go test -short net
crashed if liveness analysis was in use (like at tip, not like Go 1.2).

TBR=ken2
CC=golang-codereviews
https://golang.org/cl/64470043
2014-02-15 20:01:15 -05:00
Russ Cox
8b6ef69e23 cmd/gc: avoid pointer beyond array in range loop
This problem was discovered by reading the code.
I have not seen it in practice, nor do I have any ideas
on how to trigger it reliably in a test. But it's still worth
fixing.

TBR=ken2
CC=golang-codereviews
https://golang.org/cl/64370046
2014-02-15 20:00:57 -05:00
Russ Cox
7a7c0ffb47 cmd/gc: correct liveness for fat variables
The VARDEF placement must be before the initialization
but after any final use. If you have something like s = ... using s ...
the rhs must be evaluated, then the VARDEF, then the lhs
assigned.

There is a large comment in pgen.c on gvardef explaining
this in more detail.

This CL also includes Ian's suggestions from earlier CLs,
namely commenting the use of mode in link.h and fixing
the precedence of the ~r check in dcl.c.

This CL enables the check that if liveness analysis decides
a variable is live on entry to the function, that variable must
be a function parameter (not a result, and not a local variable).
If this check fails, it indicates a bug in the liveness analysis or
in the generated code being analyzed.

The race detector generates invalid code for append(x, y...).
The code declares a temporary t and then uses cap(t) before
initializing t. The new liveness check catches this bug and
stops the compiler from writing out the buggy code.
Consequently, this CL disables the race detector tests in
run.bash until the race detector bug can be fixed
(golang.org/issue/7334).

Except for the race detector bug, the liveness analysis check
does not detect any problems (this CL and the previous CLs
fixed all the detected problems).

The net test still fails with GOGC=0 but the rest of the tests
now pass or time out (because GOGC=0 is so slow).

TBR=iant
CC=golang-codereviews
https://golang.org/cl/64170043
2014-02-15 10:58:55 -05:00
Rémy Oudompheng
15d294991f cmd/gc: do not lower copy to a value node in go/defer.
The existing tests issue4463.go and issue4654.go had failures at
typechecking and did not test walking the AST.

Fixes #7272.

LGTM=khr
R=khr, rsc, iant
CC=golang-codereviews
https://golang.org/cl/60550044
2014-02-15 16:39:04 +01:00
Elias Naur
9b0736fc58 cmd/go: remove cross compiling restriction on cgo
A previous CL added support for cross compiling with cgo, but
missed the GOOS check in cmd/go. Remove it.

Update #4714

LGTM=iant
R=iant
CC=golang-codereviews
https://golang.org/cl/57210046
2014-02-14 11:36:52 -08:00
Russ Cox
f0023cf1d5 cmd/gc: fix build for 'default unsigned char' compilers
TBR=iant
CC=golang-codereviews
https://golang.org/cl/63680045
2014-02-14 00:43:43 -05:00
Shenghou Ma
6a9b98888e cmd/go: hide the "TERM" environment variable from "go env"
It's implementation detail.

LGTM=rsc
R=rsc
CC=golang-codereviews
https://golang.org/cl/63690043
2014-02-14 00:38:55 -05:00
Russ Cox
af545660d5 cmd/gc: correct liveness for various non-returning functions
When the liveness code doesn't know a function doesn't return
(but the generated code understands that), the liveness analysis
invents a control flow edge that is not really there, which can cause
variables to seem spuriously live. This is particularly bad when the
variables are uninitialized.

TBR=iant
CC=golang-codereviews
https://golang.org/cl/63720043
2014-02-14 00:38:24 -05:00
Russ Cox
ab9e8d068a cmd/gc: correct liveness for func ending in panic
The registerization code needs the function to end in a RET,
even if that RET is actually unreachable.

The liveness code needs to avoid such unreachable RETs.
It had a special case for final RET after JMP, but no case
for final RET after UNDEF. Instead of expanding the special
cases, let fixjmp - which already knows what is and is not
reachable definitively - mark the unreachable RET so that
the liveness code can identify it.

TBR=iant
CC=golang-codereviews
https://golang.org/cl/63680043
2014-02-13 23:56:53 -05:00
Russ Cox
02ae91f342 cmd/gc: correct liveness for wrappers containing tail jumps
A normal RET is treated as using the return values,
but a tail jump RET does not - it is jumping to the
function that is going to fill in the return values.
If a tail jump RET is recorded as using the return values,
since nothing initializes them they will be marked as
live on entry to the function, which is clearly wrong.

Found and tested by the new code in plive.c that looks
for variables that are incorrectly live on entry.
That code is disabled for now because there are other
cases remaining to be fixed. But once it is enabled,
test/live1.go becomes a real test of this CL.

TBR=iant
CC=golang-codereviews
https://golang.org/cl/63570045
2014-02-13 23:33:20 -05:00
Russ Cox
91b1f7cb15 cmd/gc: handle variable initialization by block move in liveness
Any initialization of a variable by a block copy or block zeroing
or by multiple assignments (componentwise copying or zeroing
of a multiword variable) needs to emit a VARDEF. These cases were not.

Fixes #7205.

TBR=iant
CC=golang-codereviews
https://golang.org/cl/63650044
2014-02-13 22:45:16 -05:00
Russ Cox
7addda685d cmd/5g, cmd/8g: fix build
The test added in CL 63630043 fails on 5g and 8g because they
were not emitting the VARDEF instruction when clearing a fat
value by clearing the components. 6g had the call in the right place.

Hooray tests.

TBR=iant
CC=golang-codereviews
https://golang.org/cl/63660043
2014-02-13 22:30:35 -05:00
Russ Cox
801e40a0a4 cmd/gc: rename AFATVARDEF to AVARDEF
The "fat" referred to being used for multiword values only.
We're going to use it for non-fat values sometimes too.

No change other than the renaming.

TBR=iant
CC=golang-codereviews
https://golang.org/cl/63650043
2014-02-13 22:17:22 -05:00
Russ Cox
824e918ca4 cmd/gc: fix liveness for addressed results
Was spuriously marking results live on entry to function.

TBR=iant
CC=golang-codereviews
https://golang.org/cl/63640043
2014-02-13 21:11:50 -05:00
Shenghou Ma
656a402545 cmd/gc: rephrase the invalid indexing operation error message
Old:
prog.go:9: invalid operation: this[i] (index of type int)
New:
prog.go:9: invalid operation: this[i] (type int does not support indexing)

LGTM=r
R=golang-codereviews, r
CC=golang-codereviews
https://golang.org/cl/52540043
2014-02-13 21:01:33 -05:00
Russ Cox
a069cf048d cmd/gc: distinguish unnamed vs blank-named return variables better
Before, an unnamed return value turned into an ONAME node n with n->sym
named ~anon%d, and n->orig == n.

A blank-named return value turned into an ONAME node n with n->sym
named ~anon%d but n->orig == the original blank n. Code generation and
printing uses n->orig, so that this node formatted as _.

But some code does not use n->orig. In particular the liveness code does
not know about the n->orig convention and so mishandles blank identifiers.
It is possible to fix but seemed better to avoid the confusion entirely.

Now the first kind of node is named ~r%d and the second ~b%d; both have
n->orig == n, so that it doesn't matter whether code uses n or n->orig.

After this change the ->orig field is only used for other kinds of expressions,
not for ONAME nodes.

This requires distinguishing ~b from ~r names in a few places that care.
It fixes a liveness analysis bug without actually changing the liveness code.

TBR=ken2
CC=golang-codereviews
https://golang.org/cl/63630043
2014-02-13 20:59:39 -05:00
Russ Cox
e5d742fcad cmd/gc: relax address-of escape analysis
Make the loop nesting depth of &x depend on where x is declared,
not on where the &x appears. The latter is only a conservative
estimate of the former. Being more careful can avoid some
variables escaping, and it is easier to reason about.

It would have avoided issue 7313, although that was still a bug
worth fixing.

Not much effect in the tree: one variable in the whole tree
is saved from a heap allocation (something in x509 parsing).

LGTM=daniel.morsing
R=daniel.morsing
CC=golang-codereviews
https://golang.org/cl/62380043
2014-02-13 19:59:09 -05:00
Shenghou Ma
c36dd4abdc cmd/go: fix cgo error output rewrite
for example, we now rewrite *_Ctype_int to *C.int.
Fixes #6781.

LGTM=iant
R=golang-codereviews, rsc, iant
CC=golang-codereviews
https://golang.org/cl/36860043
2014-02-13 15:55:14 -05:00
David du Colombier
174b8c95f5 lib9: enable on Plan 9
This change depends on CL 57170052.

LGTM=rsc
R=rsc, bradfitz
CC=golang-codereviews
https://golang.org/cl/60840049
2014-02-13 20:06:41 +01:00
Daniel Morsing
e0a55a6c98 cmd/gc: for loop init statement misanalyzed by escape analysis
Logically, the init statement is in the enclosing scopes loopdepth, not inside the for loop.

Fixes #7313.

LGTM=rsc
R=golang-codereviews, gobot, rsc
CC=golang-codereviews
https://golang.org/cl/62430043
2014-02-13 19:04:43 +00:00
Carlos Castillo
7861cd6082 cmd/go, go/build: support .m files
go/build is changed to list the .m files in a package, and match them for build constraints, adding them to a new field: Package.MFiles.

The go tool is changed to support building .m files and linking in the results during CGO and SWIG builds. This means packages that create a C interface to calls Objective-C code from go are now go-gettable without producing and distributing .syso files. This change is analogous to the one in Go 1.2 made to support C++ built code.

This change doesn't support .mm files (Objective C++).

Also added support for these MFiles to go list's -json mode.

Fixes #6536.

LGTM=iant
R=golang-codereviews, iant
CC=golang-codereviews
https://golang.org/cl/60590044
2014-02-13 10:11:44 -08:00
Dmitriy Vyukov
e0dee49688 cmd/gc: fix windows build
c:\src\go\pkg\obj\windows_amd64\libgc.a(lex.o): In function `catcher':
c:/src/go/src/cmd/gc/lex.c:181: undefined reference to `noted'

LGTM=0intro
R=0intro
CC=golang-codereviews
https://golang.org/cl/63270043
2014-02-13 20:15:19 +04:00
David du Colombier
9c767b64ee cmd/gc: catch notes on Plan 9
LGTM=rsc
R=rsc, jas, gobot
CC=ality, golang-codereviews
https://golang.org/cl/51650051
2014-02-13 16:35:51 +01:00
Shenghou Ma
ca6186aa26 cmd/6c, cmd/8c, cmd/8g: fix print of pc (which is vlong).
While we're at it, fix a wrong for statement in cmd/8g.

LGTM=rsc
R=rsc, golang-codereviews
CC=golang-codereviews
https://golang.org/cl/62700044
2014-02-13 03:09:03 -05:00
David du Colombier
a3e3b8e9db cmd/gc: fix warnings on Plan 9
warning: src/cmd/gc/popt.c:700 format mismatch d VLONG, arg 4
warning: src/cmd/gc/popt.c:700 format mismatch d VLONG, arg 5

LGTM=rsc
R=rsc
CC=golang-codereviews
https://golang.org/cl/62910043
2014-02-13 07:28:22 +01:00
Russ Cox
684332f47c cmd/5g: fix regopt bug in copyprop
copyau1 was assuming that it could deduce the type of the
middle register p->reg from the type of the left or right
argument: in CMPF F1, F2, the p->reg==2 must be a D_FREG
because p->from is F1, and in CMP R1, R2, the p->reg==2 must
be a D_REG because p->from is R1.

This heuristic fails for CMP $0, R2, which was causing copyau1
not to recognize p->reg==2 as a reference to R2, which was
keeping it from properly renaming the register use when
substituting registers.

cmd/5c has the right approach: look at the opcode p->as to
decide the kind of register. It is unclear where 5g's copyau1
came from; perhaps it was an attempt to avoid expanding 5c's
a2type to include new instructions used only by 5g.

Copy a2type from cmd/5c, expand to include additional instructions,
and make it crash the compiler if asked about an instruction
it does not understand (avoid silent bugs in the future if new
instructions are added).

Should fix current arm build breakage.

While we're here, fix the print statements dumping the pred and
succ info in the asm listing to pass an int arg to %.4ud
(Prog.pc is a vlong now, due to the liblink merge).

TBR=ken2
CC=golang-codereviews
https://golang.org/cl/62730043
2014-02-13 03:54:55 +00:00
Anthony Martin
27cb59fdad cmd/5g: fix print format in peephole debugging
Fixes #7294.

LGTM=minux.ma, dave, bradfitz
R=golang-codereviews, minux.ma, dave, bradfitz
CC=golang-codereviews
https://golang.org/cl/61370043
2014-02-12 17:03:21 -08:00
Anthony Martin
2cae0591cd cmd/cc, cmd/gc, cmd/ld: consolidate print format routines
We now use the %A, %D, %P, and %R routines from liblink
across the board.

Fixes #7178.
Fixes #7055.

LGTM=iant
R=golang-codereviews, gobot, rsc, dave, iant, remyoudompheng
CC=golang-codereviews
https://golang.org/cl/49170043
2014-02-12 14:29:11 -05:00
Shenghou Ma
4687b54147 cmd/ld, cmd/6l: part 2 of solaris/amd64 linker changes.
Second part of the solaris/amd64 linker changes: relocation and symbol table.

LGTM=iant
R=golang-codereviews, iant
CC=golang-codereviews
https://golang.org/cl/61330043
2014-02-11 18:43:05 -05:00
Daniel Morsing
85e4cb2f10 cmd/6g, cmd/8g, cmd/5g: make the undefined instruction have no successors
The UNDEF instruction was listed in the instruction data as having the next instruction in the stream as its successor. This confused the optimizer into adding a load where it wasn't needed, in turn confusing the liveness analysis pass for GC bitmaps into thinking that the variable was live.

Fixes #7229.

LGTM=iant, rsc
R=golang-codereviews, bradfitz, iant, dave, rsc
CC=golang-codereviews
https://golang.org/cl/56910045
2014-02-11 20:25:40 +00:00
Brendan Daniel Tracey
d30949693c cmd/gc: change compile error to "use of package %S without selector"
At present, when a package identifier is used outside of a selector expression, gc gives the error "use of package %S outside selector". However, in the selector expression x.f, the spec defines f as the selector. This change makes the error clearer.

Fixes #7133.

LGTM=rsc
R=golang-codereviews, rsc
CC=golang-codereviews
https://golang.org/cl/50060047
2014-02-10 20:27:31 -05:00
Dmitriy Vyukov
db9fb7b9ab cmd/go: fix comment
R=r
CC=golang-codereviews
https://golang.org/cl/61650044
2014-02-10 21:48:43 +04:00
Dmitriy Vyukov
e56e4e0193 cmd/go: better advice for heap profiling
R=golang-codereviews, bradfitz
CC=golang-codereviews
https://golang.org/cl/60760048
2014-02-10 18:59:07 +04:00
Dave Cheney
ff5f9bbf6a cmd/go: skip $ORIGIN test on darwin systems
Fixes #7293.

Update #7261

The bsd ld(1) does not understand $ORIGIN and has restrictions on using -rpath when using clang(1), the default compiler on darwin.

LGTM=iant
R=iant
CC=golang-codereviews
https://golang.org/cl/58480045
2014-02-10 13:35:39 +11:00
Dave Cheney
414b45d91a cmd/go: fix test.bash
Fixes #7260.

Fix three broken tests in test.bash

The test for issue 4568 was confused by go $ACTION . producing a package root of "", avoiding this mode fixes the test but weakens the test.

The test for issue 4773 was broken on linux because math/Rand would fail to resolve as a package causing the test for duplicates to be skipped.

Finally, the last breakage was a small change in the error message.

Also, add test for foldDup.

LGTM=iant
R=iant, rsc
CC=golang-codereviews
https://golang.org/cl/61070044
2014-02-10 10:41:47 +11:00
Shenghou Ma
6ebf59b953 include, linlink, cmd/6l, cmd/ld: part 1 of solaris/amd64 linker changes.
rsc suggested that we split the whole linker changes into three parts.
This is the first one, mostly dealing with adding Hsolaris.

LGTM=iant
R=golang-codereviews, iant, dave
CC=golang-codereviews
https://golang.org/cl/54210050
2014-02-09 16:45:38 -05:00
Rémy Oudompheng
2b93c4dd06 cmd/6g: faster memmove/memset-like code using unaligned load/stores.
This changes makes sgen and clearfat use unaligned instructions for
the trailing bytes, like the runtime memmove does, resulting in faster
code when manipulating types whose size is not a multiple of 8.

LGTM=khr
R=khr, iant, rsc
CC=golang-codereviews
https://golang.org/cl/51740044
2014-02-07 23:58:21 +01:00
David du Colombier
d0591d5ebd cmd/gc: revert CL 60740044
LGTM=iant
R=iant
CC=golang-codereviews
https://golang.org/cl/60590047
2014-02-07 17:05:16 +01:00
David du Colombier
f95a311c9b cmd/gc: fix nil pointer dereference
LGTM=iant
R=golang-codereviews, dave, iant
CC=golang-codereviews
https://golang.org/cl/60740044
2014-02-07 15:43:40 +01:00
Keith Randall
da7cf0ba5d runtime: faster memclr on x86.
Use explicit SSE writes instead of REP STOSQ.

benchmark               old ns/op    new ns/op    delta
BenchmarkMemclr5               22            5  -73.62%
BenchmarkMemclr16              27            5  -78.49%
BenchmarkMemclr64              28            6  -76.43%
BenchmarkMemclr256             34            8  -74.94%
BenchmarkMemclr4096           112           84  -24.73%
BenchmarkMemclr65536         1902         1920   +0.95%

LGTM=dvyukov
R=golang-codereviews, dvyukov
CC=golang-codereviews
https://golang.org/cl/60090044
2014-02-06 17:43:22 -08:00
Shenghou Ma
c66956cdb1 cmd/go: do not create world-writable files.
Fixes #7240.

LGTM=tommi.virtanen, bradfitz
R=golang-codereviews, tommi.virtanen, bradfitz
CC=golang-codereviews
https://golang.org/cl/60480045
2014-02-06 17:54:33 -05:00
Elias Naur
2dc759d7c6 cmd/go, cmd/cgo, make.bash: cross compiling with cgo enabled
Introduce two new environment variables, CC_FOR_TARGET and CXX_FOR_TARGET.
CC_FOR_TARGET defaults to CC and is used when compiling for GOARCH, while
CC remains for compiling for GOHOSTARCH.
CXX_FOR_TARGET defaults to CXX and is used when compiling C++ code for
GOARCH.

CGO_ENABLED defaults to disabled when cross compiling and has to be
explicitly enabled.

Update #4714

LGTM=minux.ma, iant
R=golang-codereviews, minux.ma, iant, rsc, dominik.honnef
CC=golang-codereviews
https://golang.org/cl/57100043
2014-02-06 09:11:00 -08:00
Josh Bleecher Snyder
57bc80b5e8 cmd/go, doc/go1.3.txt: misc/benchcmp has been replaced by go tool benchcmp
Fixes #7016.

LGTM=r
R=r
CC=adg, bradfitz, dave, golang-codereviews
https://golang.org/cl/60100043
2014-02-04 11:53:13 -08:00
Elias Naur
9ed5995cfe liblink, cmd/5l: restore flag_shared
CL 56120043 fixed and cleaned up TLS on ARM after introducing liblink, but
left flag_shared broken. This CL restores the (unsupported) flag_shared
behaviour by simply rewriting access to $runtime.tlsgm(SB) with
runtime.tlsgm(SB), to compensate for the extra indirection when going from
the R_ARM_TLS_LE32 relocation to the R_ARM_TLS_IE32 relocation.

Also, remove unnecessary symbol lookup left after 56120043.

LGTM=iant
R=iant, rsc
CC=golang-codereviews
https://golang.org/cl/57000043
2014-02-03 14:49:57 -08:00
Elias Naur
1dd4da1459 liblink, cmd/5a, cmd/5l: restore cgo on older ARM processors
CL 56120043 fixed TLS handling on ARM after the introduction of
liblink but left older ARM processors broken.

Before liblink, the MRC instruction was replaced with a fallback
on older ARMs. CL 56120043 removed that, because the rewrite matched
bit patterns on the AWORD pseudo-instruction and could therefore change
unrelated AWORDs that happened to match.

This CL adds an AMRC instruction to encode both MRC and MCR previously
encoded as AWORDs. Then, in liblink, the AMRC instructions are either
rewritten to AWORD, or, on goarm < 7, replaced with a branch to the
fallback.

./all.bash completes successfully on an ARMv7 with either GOARM=7 or
GOARM=5. I have verified that the fallback is indeed present in both
runtime.save_gm and runtime.load_gm when GOARM=5 but not when GOARM=7.

If all goes well, this should fix the armv5 builders.

LGTM=iant
R=iant, rsc
CC=golang-codereviews
https://golang.org/cl/55540044
2014-02-03 14:07:54 -08:00
Rémy Oudompheng
502958ffa6 cmd/gc: do not consider length zero arrays as comparable.
Array values are comparable if values of the array element type
are comparable.

Fixes #6526.

LGTM=khr
R=rsc, bradfitz, khr
CC=golang-codereviews
https://golang.org/cl/58580043
2014-01-31 00:30:56 +01:00
Ian Lance Taylor
1683dab725 cmd/ld: fix bug with "runtime/cgo" in external link mode
In external link mode the linker explicitly adds the string
constant "runtime/cgo".  It adds the string constant using the
same symbol name as the compiler, but a different format.  The
compiler assumes that the string data immediately follows the
string header, but the linker puts the two in different
sections.  The result is bad string data when the compiler
sees "runtime/cgo" used as a string constant.

The compiler assumption is in datastring in [568]g/gobj.c.
The linker layout is in addstrdata in ld/data.c.  The compiler
assumption is valid for string literals.  The linker is not
creating a string literal, so its assumption is also valid.

There are a few ways to avoid this problem.  This patch fixes
it by only doing the fake import of runtime/cgo if necessary,
and by only creating the string symbol if necessary.

Fixes #7234.

LGTM=dvyukov
R=golang-codereviews, dvyukov, bradfitz
CC=golang-codereviews
https://golang.org/cl/58410043
2014-01-30 09:25:47 -08:00
Rob Pike
289d46399b cmd/8g: don't crash if Prog->u.branch is nil
The code is copied from cmd/6g.
Empirically, all branch targets are nil in this code so
something is still wrong, but at least this stops 8g -S
from crashing.

Update #7178

LGTM=dave, iant
R=iant, dave
CC=golang-codereviews
https://golang.org/cl/58400043
2014-01-29 16:14:45 -08:00
Michael Hudson-Doyle
9f8f0a1bfa cmd/go: When linking with gccgo pass .a files in the order they are discovered
Under some circumstances linking a test binary with gccgo can fail, because
the installed version of the library ends up before the version built for the
test on the linker command line.

This admittedly slightly hackish fix fixes this by putting the library archives
on the linker command line in the order that a pre-order depth first traversal
of the dependencies gives them, which has the side effect of always putting the
version of the library built for the test first.

Fixes #6768

LGTM=rsc
R=golang-codereviews, minux.ma, gobot, rsc, dave
CC=golang-codereviews
https://golang.org/cl/28050043
2014-01-28 16:47:09 +11:00
Keith Randall
28479f2c32 cmd/gc: liveness: don't add fallthough edge after panic
update #7205

LGTM=iant
R=golang-codereviews, iant
CC=golang-codereviews
https://golang.org/cl/50730044
2014-01-27 18:04:34 -08:00
Keith Randall
ea86752206 cmd/6a: include MOVQL opcode.
LGTM=r
R=golang-codereviews, r
CC=golang-codereviews
https://golang.org/cl/54660046
2014-01-27 11:17:12 -08:00
Russ Cox
a81692e265 cmd/gc: add zeroing to enable precise stack accounting
There is more zeroing than I would like right now -
temporaries used for the new map and channel runtime
calls need to be eliminated - but it will do for now.

This CL only has an effect if you are building with

        GOEXPERIMENT=precisestack ./all.bash

(or make.bash). It costs about 5% in the overall time
spent in all.bash. That number will come down before
we make it on by default, but this should be enough for
Keith to try using the precise maps for copying stacks.

amd64 only (and it's not really great generated code).

TBR=khr, iant
CC=golang-codereviews
https://golang.org/cl/56430043
2014-01-23 23:11:04 -05:00
Russ Cox
b377c9c6a9 liblink, runtime: fix cgo on arm
The addition of TLS to ARM rewrote the MRC instruction
differently depending on whether we were using internal
or external linking mode. That's clearly not okay, since we
don't know that during compilation, which is when we now
generate the code. Also, because the change did not introduce
a real MRC instruction but instead just macro-expanded it
in the assembler, liblink is rewriting a WORD instruction that
may actually be looking for that specific constant, which would
lead to very unexpected results. It was also using one value
that happened to be 8 where a different value that also
happened to be 8 belonged. So the code was correct for those
values but not correct in general, and very confusing.

Throw it all away.

Replace with the following. There is a linker-provided symbol
runtime.tlsgm with a value (address) set to the offset from the
hardware-provided TLS base register to the g and m storage.
Any reference to that name emits an appropriate TLS relocation
to be resolved by either the internal linker or the external linker,
depending on the link mode. The relocation has exactly the
semantics of the R_ARM_TLS_LE32 relocation, which is what
the external linker provides.

This symbol is only used in two routines, runtime.load_gm and
runtime.save_gm. In both cases it is now used like this:

        MRC		15, 0, R0, C13, C0, 3 // fetch TLS base pointer
        MOVW	$runtime·tlsgm(SB), R2
        ADD	R2, R0 // now R0 points at thread-local g+m storage

It is likely that this change breaks the generation of shared libraries
on ARM, because the MOVW needs to be rewritten to use the global
offset table and a different relocation type. But let's get the supported
functionality working again before we worry about unsupported
functionality.

LGTM=dave, iant
R=iant, dave
CC=golang-codereviews
https://golang.org/cl/56120043
2014-01-23 22:51:39 -05:00
Rob Pike
d07d08e60f cmd/gc: add the word 'archive' to the documentation for -pack
The term "package file" is unclear.

R=iant, dave
CC=golang-codereviews
https://golang.org/cl/54760044
2014-01-22 15:55:56 -08:00
David du Colombier
021c11683c debug/plan9obj: implement parsing of Plan 9 a.out executables
It implements parsing of the header and symbol table for both
32-bit and 64-bit Plan 9 binaries. The nm tool was updated to
use this package.

R=rsc, aram
CC=golang-codereviews
https://golang.org/cl/49970044
2014-01-22 23:30:52 +01:00
David du Colombier
1351638314 cmd/gc, cmd/ld: fix Plan 9 warnings
warning: /usr/go/src/cmd/gc/obj.c:23 format mismatch -10d VLONG, arg 9
warning: /usr/go/src/cmd/gc/plive.c:1680 set and not used: printed
warning: /usr/go/src/cmd/ld/lib.c:332 non-interruptable temporary
warning: /usr/go/src/cmd/ld/lib.c:338 non-interruptable temporary

R=rsc
CC=golang-codereviews
https://golang.org/cl/53820046
2014-01-22 21:21:18 +01:00
Rémy Oudompheng
20137eb4b9 cmd/gc: preserve qualified names of unexported methods in imports.
Fixes #6295.

LGTM=rsc
R=golang-codereviews, rsc
CC=golang-codereviews
https://golang.org/cl/20850043
2014-01-21 22:55:50 -05:00
Dominik Honnef
062ae45711 cmd/gc: do not typecheck nil types in multiple assignment
Fixes #6572.

LGTM=rsc, daniel.morsing, rsc
R=golang-codereviews, bradfitz, minux.ma, iant, rsc, gobot, daniel.morsing
CC=golang-codereviews
https://golang.org/cl/14516055
2014-01-21 22:44:54 -05:00
Dave Cheney
db37050f21 cmd/go: do not require a valid archChar when using -compiler gccgo
Fixes #7152.

R=iant, rsc, gobot
CC=golang-codereviews
https://golang.org/cl/54790044
2014-01-22 12:19:11 +11:00
Russ Cox
dab127baf5 liblink: remove use of linkmode on ARM
Now that liblink is compiled into the compilers and assemblers,
it must not refer to the "linkmode", since that is not known until
link time. This CL makes the ARM support no longer use linkmode,
which fixes a bug with cgo binaries that contain their own TLS
variables.

The x86 code must also remove linkmode; that is issue 7164.

Fixes #6992.

R=golang-codereviews, iant
CC=golang-codereviews
https://golang.org/cl/55160043
2014-01-21 19:46:34 -05:00
Russ Cox
2a2a3baac4 cmd/link: add testdata/pclntab.6 (fix build)
Sorry, "hg status" hides .6 files by default.
We should probably fix that.

TBR=iant
CC=golang-codereviews
https://golang.org/cl/55290043
2014-01-21 17:12:30 -05:00
Ian Lance Taylor
bec1a3e258 cmd/gc: document -pack flag
R=golang-codereviews, r
CC=golang-codereviews
https://golang.org/cl/55140044
2014-01-21 11:54:21 -08:00
Russ Cox
a453f28c70 cmd/link: pclntab generation
R=iant
CC=golang-codereviews
https://golang.org/cl/53820043
2014-01-21 13:47:47 -05:00
Russ Cox
0dd26f276d cmd/gc: fix build
The AKILL stuff is not ready yet and
was not meant to be in the last CL.

R=iant
CC=golang-codereviews
https://golang.org/cl/55170043
2014-01-21 13:46:14 -05:00
Russ Cox
eb592d8289 cmd/gc: do not follow uintptr passed as function argument
The escape analysis works by tracing assignment paths from
variables that start with pointer type, or addresses of variables
(addresses are always pointers).  It does allow non-pointers
in the path, so that in this code it sees x's value escape into y:

        var x *[10]int
        y := (*int)(unsafe.Pointer(uintptr(unsafe.Pointer(x))+32))

It must allow uintptr in order to see through this kind of
"pointer arithmetic".

It also traces such values if they end up as uintptrs passed to
functions. This used to be important because packages like
encoding/gob passed around uintptrs holding real pointers.

The introduction of precise collection of stacks has forced
code to be more honest about which declared stack variables
hold pointers and which do not. In particular, the garbage
collector no longer sees pointers stored in uintptr variables.
Because of this, packages like encoding/gob have been fixed.

There is not much point in the escape analysis accepting
uintptrs as holding pointers at call boundaries if the garbage
collector does not.

Excluding uintptr-valued arguments brings the escape
analysis in line with the garbage collector and has the
useful side effect of making arguments to syscall.Syscall
not appear to escape.

That is, this CL should yield the same benefits as
CL 45930043 (rolled back in CL 53870043), but it does
so by making uintptrs less special, not more.

R=golang-codereviews, iant
CC=golang-codereviews
https://golang.org/cl/53940043
2014-01-21 13:31:34 -05:00
Russ Cox
8027660abc cmd/gc: fix crash in -live debugging output
R=golang-codereviews, iant
CC=golang-codereviews
https://golang.org/cl/53930043
2014-01-21 13:31:22 -05:00
Ian Lance Taylor
cdc556556c cmd/ld: support archives larger than 2G
R=golang-codereviews, gobot, rsc
CC=golang-codereviews
https://golang.org/cl/53950043
2014-01-21 09:29:19 -08:00
Keith Randall
6f6a9445c9 runtime, cmd/gc: Get rid of vararg channel calls.
Vararg C calls present a problem for the GC because the
argument types are not derivable from the signature.  Remove
them by passing pointers to channel elements instead of the
channel elements directly.

R=golang-codereviews, gobot, rsc, dvyukov
CC=golang-codereviews
https://golang.org/cl/53430043
2014-01-17 14:48:45 -08:00
Russ Cox
5c9585953f undo CL 45930043 / c22889382a17
The compiler change is an ugly hack.
We can do better.

««« original CL description
syscall: mark arguments to Syscall as noescape
Heap arguments to "async" syscalls will break when/if we have moving GC anyway.
With this change is must not break until moving GC, because a user must
reference the object in Go to preserve liveness. Otherwise the code is broken already.
Reduces number of leaked params from 125 to 36 on linux.

R=golang-codereviews, mikioh.mikioh, bradfitz
CC=cshapiro, golang-codereviews, khr, rsc
https://golang.org/cl/45930043
»»»

R=golang-codereviews, r
CC=bradfitz, dvyukov, golang-codereviews
https://golang.org/cl/53870043
2014-01-17 16:58:14 -05:00
Dmitriy Vyukov
fc37eba149 syscall: mark arguments to Syscall as noescape
Heap arguments to "async" syscalls will break when/if we have moving GC anyway.
With this change is must not break until moving GC, because a user must
reference the object in Go to preserve liveness. Otherwise the code is broken already.
Reduces number of leaked params from 125 to 36 on linux.

R=golang-codereviews, mikioh.mikioh, bradfitz
CC=cshapiro, golang-codereviews, khr, rsc
https://golang.org/cl/45930043
2014-01-17 20:18:37 +04:00
Aram Hăvărneanu
a46b434931 runtime: add support for GOOS=solaris
R=alex.brainman, dave, jsing, gobot, rsc
CC=golang-codereviews
https://golang.org/cl/35990043
2014-01-17 17:58:10 +13:00
Russ Cox
ca9975a45e cmd/gc: handle non-escaping address-taken variables better
This CL makes the bitmaps a little more precise about variables
that have their address taken but for which the address does not
escape to the heap, so that the variables are kept in the stack frame
rather than allocated on the heap.

The code before this CL handled these variables by treating every
return statement as using every such variable and depending on
liveness analysis to essentially treat the variable as live during the
entire function. That approach has false positives and (worse) false
negatives. That is, it's both sloppy and buggy:

        func f(b1, b2 bool) {	// x live here! (sloppy)
                if b2 {
                        print(0) // x live here! (sloppy)
                        return
                }
                var z **int
                x := new(int)
                *x = 42
                z = &x
                print(**z) // x live here (conservative)
                if b2 {
                        print(1) // x live here (conservative)
                        return
                }
                for {
                        print(**z) // x not live here (buggy)
                }
        }

The first two liveness annotations (marked sloppy) are clearly
wrong: x cannot be live if it has not yet been declared.

The last liveness annotation (marked buggy) is also wrong:
x is live here as *z, but because there is no return statement
reachable from this point in the code, the analysis treats x as dead.

This CL changes the liveness calculation to mark such variables
live exactly at points in the code reachable from the variable
declaration. This keeps the conservative decisions but fixes
the sloppy and buggy ones.

The CL also detects ambiguously live variables, those that are
being marked live but may not actually have been initialized,
such as in this example:

        func f(b1 bool) {
                var z **int
                if b1 {
                        x := new(int)
                        *x = 42
                        z = &x
                } else {
                        y := new(int)
                        *y = 54
                        z = &y
                }
                print(**z) // x, y live here (conservative)
        }

Since the print statement is reachable from the declaration of x,
x must conservatively be marked live. The same goes for y.
Although both x and y are marked live at the print statement,
clearly only one of them has been initialized. They are both
"ambiguously live".

These ambiguously live variables cause problems for garbage
collection: the collector cannot ignore them but also cannot
depend on them to be initialized to valid pointer values.

Ambiguously live variables do not come up too often in real code,
but recent changes to the way map and interface runtime functions
are invoked has created a large number of ambiguously live
compiler-generated temporary variables. The next CL will adjust
the analysis to understand these temporaries better, to make
ambiguously live variables fairly rare.

Once ambiguously live variables are rare enough, another CL will
introduce code at the beginning of a function to zero those
slots on the stack. At that point the garbage collector and the
stack copying routines will be able to depend on the guarantee that
if a slot is marked as live in a liveness bitmap, it is initialized.

R=khr
CC=golang-codereviews, iant
https://golang.org/cl/51810043
2014-01-16 10:32:30 -05:00
Russ Cox
fbfb9430dc cmd/gc: fix race build
Missed this case in CL 51010045.

TBR=khr
CC=golang-codereviews
https://golang.org/cl/53200043
2014-01-16 10:11:06 -05:00
Rob Pike
fdbf3d901b cmd/pack: rewrite in Go
Replace the pack command, a C program, with a clean reimplementation in Go.
It does not need to reproduce the full feature set and it is no longer used by
the build chain, but has a role in looking inside archives created by the build
chain directly.

Since it's not in C, it is no longer build by dist, so remove it from cmd/dist and
make it a "tool" in cmd/go terminology.

Fixes #2705

R=rsc, dave, minux.ma, josharian
CC=golang-codereviews
https://golang.org/cl/52310044
2014-01-15 09:13:52 -08:00
Rob Pike
71377d3cd3 cmd/ld: document the -w flag, which disables DWARF generation
R=golang-codereviews, iant
CC=golang-codereviews
https://golang.org/cl/52360044
2014-01-14 15:34:27 -08:00
Josh Bleecher Snyder
3be4d95731 runtime: change map iteration randomization to use intra-bucket offset
Map iteration previously started from a random bucket, but walked each
bucket from the beginning. Now, iteration always starts from the first
bucket and walks each bucket starting at a random offset. For
performance, the random offset is selected at the start of iteration
and reused for each bucket.

Iteration over a map with 8 or fewer elements--a single bucket--will
now be non-deterministic. There will now be only 8 different possible
map iterations.

Significant benchmark changes, on my OS X laptop (rough but consistent):

benchmark                              old ns/op     new ns/op     delta
BenchmarkMapIter                       128           121           -5.47%
BenchmarkMapIterEmpty                  4.26          4.45          +4.46%
BenchmarkNewEmptyMap                   114           111           -2.63%

Fixes #6719.

R=khr, bradfitz
CC=golang-codereviews
https://golang.org/cl/47370043
2014-01-14 12:54:05 -08:00
Brad Fitzpatrick
014f3dcc83 cmd/gofmt: remove -tabwidth and -tabs flags
Having these flags misleads people into thinking they're acceptable
for code that "must be gofmt'd".

If an organization wishes to use gofmt internally with
different settings, they can fork gofmt trivially. But "gofmt"
as used by the community with open source Go code should not
support these old knobs.

Also removes the -comments flag.

Fixes #7101

R=r, gri
CC=golang-codereviews
https://golang.org/cl/52170043
2014-01-14 11:10:56 -08:00
Russ Cox
334056a7bc cmd/gc: return canonical Node* from temp
For historical reasons, temp was returning a copy
of the created Node*, not the original Node*.
This meant that if analysis recorded information in the
returned node (for example, n->addrtaken = 1), the
analysis would not show up on the original Node*, the
one kept in fn->dcl and consulted during liveness
bitmap creation.

Correct this, and watch for it when setting addrtaken.

Fixes #7083.

R=khr, dave, minux.ma
CC=golang-codereviews
https://golang.org/cl/51010045
2014-01-14 10:43:13 -05:00
Russ Cox
8bd8cede03 cmd/gc: add -live flag for debugging liveness maps
R=khr
CC=golang-codereviews
https://golang.org/cl/51820043
2014-01-14 10:40:16 -05:00
Alex Brainman
fa6ffc6c9b cmd/api: ensure GOPATH always points to the correct go.tools
R=golang-codereviews, dave, bradfitz
CC=golang-codereviews
https://golang.org/cl/51000043
2014-01-14 16:56:22 +11:00
Russ Cox
6e8b4920c1 cmd/link: fix build
The golden file for link.hello.darwin.amd64
was a little ahead of the checked-in code.

R=iant
TBR=iant
CC=golang-codereviews
https://golang.org/cl/51870043
2014-01-13 23:20:53 -05:00
Russ Cox
7dcc652f10 cmd/link: implement dead code removal
R=iant
CC=golang-codereviews
https://golang.org/cl/51470043
2014-01-13 23:08:10 -05:00
Russ Cox
7cecac3cbb cmd/link: implement and test automatic symbols
Related changes included in this CL:

 - Add explicit start symbol to Prog.
 - Add omitRuntime bool to Prog.
 - Introduce p.Packages[""] to hold automatic symbols
 - Add SymOrder to Prog to preserve symbol order.
 - Add layout test (and fix bug that was putting everything in text section).

R=iant
CC=golang-codereviews
https://golang.org/cl/51260045
2014-01-13 23:07:57 -05:00
Russ Cox
9c1aa658bf cmd/link: replace golden binary files with hex dumps
The hex dumps will diff better, and I hope they will avoid
a repeat of http://bugs.debian.org/716853.

The CL will probably show the testdata diffs as "binary",
but in fact the binary versions are being replaced by
textual hex dumps (output of hexdump -C).

R=iant
CC=golang-codereviews
https://golang.org/cl/51000044
2014-01-13 23:07:40 -05:00
Rémy Oudompheng
f739dae7db cmd/gc: mark OGOTO as a statement for formatters.
Nodes of goto statements were corrupted when written
to export data.

Fixes #7023.

R=rsc, dave, minux.ma
CC=golang-codereviews
https://golang.org/cl/46190043
2014-01-10 01:33:24 +01:00
Russ Cox
8449863d31 cmd/link: Mach-O (OS X) file formatter
See CL 48870044 for basic structure.

R=iant
CC=golang-codereviews
https://golang.org/cl/48910043
2014-01-09 19:29:29 -05:00
Russ Cox
146897b031 cmd/link: intial skeleton of linker written in Go
R=iant
CC=golang-codereviews
https://golang.org/cl/48870044
2014-01-09 19:29:10 -05:00
Russ Cox
06c0280440 libmach: use different names for different Ureg types
Everything was doing this already with #defines.
Do it right.

R=golang-codereviews, jsing, 0intro, iant
CC=golang-codereviews
https://golang.org/cl/49090043
2014-01-08 20:37:27 -05:00
Rob Pike
fca453e062 cmd/nm: add -sort=size
When printing the size, we often want to sort on that key.
Because it's used when looking for large things, make the
sort go from largest to smallest.

Perfect recreation of CL 45150044, which was lost to some blunder.

R=golang-codereviews, gobot, rsc
CC=golang-codereviews
https://golang.org/cl/48500044
2014-01-08 15:56:40 -08:00
Aram Hăvărneanu
f952d45508 all: add solaris build tags
R=golang-codereviews, minux.ma, gobot, rsc, dave
CC=golang-codereviews
https://golang.org/cl/36040043
2014-01-07 23:53:30 -05:00
Michael Hudson-Doyle
7178c05d05 cmd/go: test: do not put object files where later steps will find them
When recompiling a package whose basename is the name of a standard
package for testing with gccgo, a .o file with the basename of the
package being tested was being placed in the _test/ directory where the
compilation of the test binary then found it when looking for the
standard library package.

This change puts the object files in a separate directory.

Fixes #6793

R=golang-codereviews, dave, gobot, rsc, iant
CC=golang-codereviews
https://golang.org/cl/27650045
2014-01-07 23:53:16 -05:00
Rémy Oudompheng
095de8795a cmd/gc: add missing dupok flag for interface method wrappers.
R=rsc
CC=golang-codereviews
https://golang.org/cl/48420044
2014-01-07 18:25:11 +01:00
Rémy Oudompheng
f303921251 cmd/gc: do not omit wrapper for expression (interface{...}).F
Fixes #6723.

R=rsc
CC=golang-codereviews
https://golang.org/cl/41570047
2014-01-07 13:26:48 +01:00
Aram Hăvărneanu
901e7bfe53 lib9, libmach, cmd/dist, go/build: add support for GOOS=solaris
This change adds solaris to the list of supported operating
systems and allows cmd/dist to be built on Solaris.

This CL has to come first because we want the tools to ignore
solaris-specific files until the whole port is integrated.

R=golang-codereviews, jsing, rsc, minux.ma
CC=golang-codereviews
https://golang.org/cl/35900045
2014-01-07 23:12:12 +11:00
Russ Cox
d227d680ec cmd/gc: use 100x less memory for []byte("string")
[]byte("string") was simplifying to
[]byte{0: 0x73, 1: 0x74, 2: 0x72, 3: 0x69, 4: 0x6e, 5: 0x67},
but that latter form takes up much more memory in the compiler.
Preserve the string form and recognize it to turn global variables
initialized this way into linker-initialized data.

Reduces the compiler memory footprint for a large []byte initialized
this way from approximately 10 kB/B to under 100 B/B.

See also issue 6643.

R=golang-codereviews, r, iant, oleku.konko, dave, gobot, bradfitz
CC=golang-codereviews
https://golang.org/cl/15930045
2014-01-06 20:43:44 -05:00
Daniel Morsing
f2e94b58a0 cmd/gc: silence assignment errors to undefined symbols
Fixes #6406.

R=golang-codereviews, bradfitz
CC=golang-codereviews
https://golang.org/cl/46900043
2014-01-03 21:03:20 +01:00
Keith Randall
0ea20bc981 cmd/6g: inline copies of up to 4 words in length.
This change fixes a serious performance regression
with reflect.Value growing to 4 words instead of 3.
The json benchmark was ~50% slower, with this change
it is ~5% slower (and the binary is 0.5% larger).

Longer term, we probably need to rethink our copy
generation.  Using REP is really expensive time-wise.
But inlining the copy grows the binary.

R=golang-codereviews, r
CC=golang-codereviews
https://golang.org/cl/44990043
2013-12-30 12:14:27 -08:00
Martin Olsson
5499034a71 all: fix a few spelling errors in source comments
R=golang-codereviews, dave, iant
CC=golang-codereviews
https://golang.org/cl/45750044
2013-12-27 08:59:02 -08:00
Russ Cox
145edc283f cmd/gc: do not compute dead value maps if they will not be used
Reduces 6g big.go memory usage from 251 MB to 242 MB.
Reduces 6g slow.go memory usage from 529 MB to 453 MB.

Mostly a memory savings; 6g slow.go is only about 5% faster.

The test programs are at
https://rsc.googlecode.com/hg/testdata/big.go (36k lines, 276kB)
https://rsc.googlecode.com/hg/testdata/slow.go (7k lines, 352kB)

R=golang-codereviews, bradfitz, iant
CC=golang-codereviews
https://golang.org/cl/42280045
2013-12-20 19:14:42 -05:00
Russ Cox
0e97f4187e cmd/gc: address 1½ liveness bottlenecks
As much as 7x speedup on some programs, cuts all.bash time by 20%.

Change splicebefore function from O(n) to O(1).
The approach was suggested by Carl during the code's review
but apparently did not make it into the tree.
It makes a huge difference on huge programs.

Make twobitwalktype1 slightly faster by using & instead of %.
Really it needs to be cached; left a note to that effect.
(Not a complete fix, hence the ½.)

big.go (output of test/chan/select5.go)
 47.53u   0.50s  48.14r before this CL
  7.09u   0.47s   7.59r with splicebefore change (6.7x speedup)
  6.15u   0.42s   6.59r with twobitwalktype1 change (1.15x speedup; total 7.7x)

slow.go (variant of program in go.text, by mpvl)
 77.75u   2.11s  80.03r before this CL
 24.40u   1.97s  26.44r with splicebefore change (3.2x speedup)
 18.12u   2.19s  20.38r with twobitwalktype1 change (1.35x speedup; total 4.3x)

test/run
150.63u  49.57s  81.08r before this CL
 88.01u  45.60s  46.65r after this CL (1.7x speedup)

all.bash
369.70u 115.64s 256.21r before this CL
298.52u 110.35s 214.67r after this CL (1.24x speedup)

The test programs are at
https://rsc.googlecode.com/hg/testdata/big.go (36k lines, 276kB)
https://rsc.googlecode.com/hg/testdata/slow.go (7k lines, 352kB)

R=golang-codereviews, gobot, r
CC=cshapiro, golang-codereviews
https://golang.org/cl/43210045
2013-12-20 14:24:48 -05:00
Russ Cox
4acb70d377 cmd/gc: bypass DATA instruction for data initialized to integer constant
Eventually we will want to bypass DATA for everything,
but the relocations are not standardized well enough across
architectures to make that possible.

This did not help as much as I expected, but it is definitely better.
It shaves maybe 1-2% off all.bash depending on how much you
trust the timings of a single run:

Before: 241.139r 362.702u 112.967s
After:  234.339r 359.623u 111.045s

R=golang-codereviews, gobot, r, iant
CC=golang-codereviews
https://golang.org/cl/44650043
2013-12-20 14:24:39 -05:00
Russ Cox
1334b794b7 libmach: remove old object file readers
These no longer work; removing them makes other refactoring easier.
The code for pack P being deleted in this CL does not work either.
I created issue 6989 to track restoring this functionality (probably not
until pack is written in Go).

R=golang-codereviews, bradfitz
CC=golang-codereviews
https://golang.org/cl/44300043
2013-12-20 12:10:53 -05:00
Rob Pike
6f6ff95183 go/build: mention 'tag' as an alias for 'build constraint'
The code is all about tags, and the cmd/go documentation
said to look in the go/build documentation for information
about tags, but the documentation said nothing about tags,
only build constraints. Make things clearer.

R=golang-dev, adg, rsc
CC=golang-dev
https://golang.org/cl/44100043
2013-12-19 11:43:34 -08:00
ChaiShushan
0b26ba8af3 cmd/yacc: expr example support windows
1. expr append executable extension.
2. support '\r' character.

Fixes #6851.

R=golang-dev, rsc
CC=golang-dev
https://golang.org/cl/35330043
2013-12-19 12:14:07 -05:00
Joel Sing
0eaabf6452 cmd/ld: make hostobj work on newer openbsd
Make hostobj work on OpenBSD 5.3/5.4/-current - these have PIE
enabled by default and linking fails since the Go linker generates
objects that are neither PIC nor PIE.

Fixes #5067

R=golang-dev, rsc
CC=golang-dev
https://golang.org/cl/7572049
2013-12-20 03:58:27 +11:00
Russ Cox
2404b7f168 debug/goobj: expand package prefix correctly
R=r, bradfitz
CC=golang-dev
https://golang.org/cl/43480049
2013-12-18 19:00:52 -05:00
Dave Cheney
3f6dbfc44c liblink, cmd/gc: resolve several shift warnings
Address several warnings generated by clang -fsanitize=undefined

R=golang-dev, iant
CC=golang-dev
https://golang.org/cl/43050043
2013-12-19 10:34:33 +11:00
Shenghou Ma
8606b97690 cmd/go: show testflag help for "go test -h"
Fixes #6576.

R=golang-dev, rsc
CC=golang-dev
https://golang.org/cl/14502065
2013-12-18 17:40:31 -05:00
ChaiShushan
3d2c4df983 cmd/yacc: gofmt y.go
R=golang-dev, adg, rsc
CC=golang-dev
https://golang.org/cl/36950043
2013-12-18 15:17:08 -05:00
David du Colombier
9607255760 cmd/6g, cmd/gc, cmd/ld: fix Plan 9 amd64 warnings
warning: src/cmd/6g/reg.c:671 format mismatch d VLONG, arg 4
warning: src/cmd/gc/pgen.c:230 set and not used: oldstksize
warning: src/cmd/gc/plive.c:877 format mismatch lx UVLONG, arg 2
warning: src/cmd/gc/walk.c:2878 set and not used: cbv
warning: src/cmd/gc/walk.c:2885 set and not used: hbv
warning: src/cmd/ld/data.c:198 format mismatch s IND FUNC(IND CHAR) INT, arg 2
warning: src/cmd/ld/data.c:230 format mismatch s IND FUNC(IND CHAR) INT, arg 2
warning: src/cmd/ld/dwarf.c:1517 set and not used: pc
warning: src/cmd/ld/elf.c:1507 format mismatch d VLONG, arg 2
warning: src/cmd/ld/ldmacho.c:509 set and not used: dsymtab

R=golang-dev, gobot, rsc
CC=golang-dev
https://golang.org/cl/36740045
2013-12-18 20:20:46 +01:00
David du Colombier
ef0100c7d7 libmach, cmd/8l: fix Plan 9 warnings
warning: src/libmach/sym.c:1861 non-interruptable temporary
warning: src/cmd/8l/../ld/pcln.c:29 set and not used: p

R=golang-dev, gobot, rsc
CC=golang-dev
https://golang.org/cl/40500043
2013-12-18 20:19:59 +01:00
Russ Cox
f48120ef51 cmd/nm: minor cleanup from previous CL
I forgot to apply Ian's suggestions before submitting CL 40600043.

R=iant
CC=golang-dev
https://golang.org/cl/43560045
2013-12-18 13:29:40 -05:00
Russ Cox
c86fc68ac6 cmd/go: avoid use of 'go tool pack'
All packages now use the -pack option to the compiler.
For a pure Go package, that's enough.
For a package with additional C and assembly files, the extra
archive entries can be added directly (by concatenation)
instead of by invoking go tool pack.

These changes make it possible to rewrite cmd/pack in Go.

R=iant, r
CC=golang-dev
https://golang.org/cl/42910043
2013-12-17 21:44:36 -05:00
Russ Cox
b2d43caa7a cmd/dist: avoid use of 'go tool pack'
All packages now use the -pack option to the compiler.
For a pure Go package, that's enough.
For a package with additional C and assembly files, the extra
archive entries can be added directly (by concatenation)
instead of by invoking go tool pack.

These changes make it possible to rewrite cmd/pack in Go.

R=iant, r
CC=golang-dev
https://golang.org/cl/42890043
2013-12-17 21:44:18 -05:00
Russ Cox
b022334029 cmd/gc: implement -pack flag
The -pack flag causes 5g, 6g, 8g to write a Go archive directly,
instead of requiring the use of 'go tool pack' to convert the .5/.6/.8
to .a format.

Writing directly avoids the copy and also avoids having the
export data stored twice in the archive (once in __.PKGDEF,
once in .5/.6/.8).

A separate CL will enable the use of this flag by cmd/go.

Other build systems that do not know about -pack will be unaffected.

The changes to cmd/ld handle a minor simplification to the format:
an unused section is removed.

R=iant, r
CC=golang-dev
https://golang.org/cl/42880043
2013-12-17 21:43:33 -05:00
Keith Randall
deb554934c runtime, gc: call interface conversion routines by reference.
Part of getting rid of vararg C calls.

R=golang-dev, bradfitz
CC=golang-dev
https://golang.org/cl/23310043
2013-12-17 16:55:06 -08:00
David du Colombier
2784a3ea85 ld: fix Plan 9 build
R=golang-dev, jas, bradfitz
CC=golang-dev
https://golang.org/cl/43420043
2013-12-17 08:46:07 -08:00
Shenghou Ma
d35b22d128 cmd/ld: maintain correct headstring needed by windows port.
Fixes build for go_bootstrap.
Fixes #6971.

R=alex.brainman, mattn.jp, rsc
CC=golang-dev
https://golang.org/cl/43130043
2013-12-17 07:36:01 -05:00
Andrew Gerrand
1561230ca0 cmd/go: set GOROOT when testing "go install cmd/fix"
This particular test would never pass unless you had GOROOT set in your
environment. This changes makes the test use the baked-in GOROOT, as it
does with GOOS and GOARCH.

R=golang-dev, dave, iant
CC=golang-dev
https://golang.org/cl/43080043
2013-12-17 12:17:56 +11:00
Shenghou Ma
f85ba7d50a cmd/gc: fix comparison order of parameters in mpcmpfltc(a, b)
It should compare a - b to 0, not b - a to 0.
Fixes #6964.

R=golang-dev, r
CC=golang-dev
https://golang.org/cl/39020044
2013-12-16 16:54:10 -05:00
Russ Cox
500547f28b cmd/nm: reimplement in Go
The immediate goal is to support the new object file format,
which libmach (nm's support library) does not understand.
Rather than add code to libmach or reengineer liblink to
support this new use, just write it in Go.

The C version of nm reads the Plan 9 symbol table stored in
Go binaries, now otherwise unused.

This reimplementation uses the standard symbol table for
the corresponding file format instead, bringing us one step
closer to removing the Plan 9 symbol table from Go binaries.

Tell cmd/dist not to build cmd/nm anymore.
Tell cmd/go to install cmd/nm in the tool directory.

R=golang-dev, r, iant, alex.brainman
CC=golang-dev
https://golang.org/cl/40600043
2013-12-16 12:52:11 -05:00
Russ Cox
a9f6db58ce cmd/ld: move instruction selection + layout into compilers, assemblers
- new object file reader/writer (liblink/objfile.c)
- remove old object file writing routines
- add pcdata iterator
- remove all trace of "line number stack" and "path fragments" from
  object files, linker (!!!)
- dwarf now writes a single "compilation unit" instead of one per package

This CL disables the check for chains of no-split functions that
could overflow the stack red zone. A future CL will attack the problem
of reenabling that check (issue 6931).

This CL is just the liblink and cmd/ld changes.
There are minor associated adjustments in CL 37030045.
Each depends on the other.

R=golang-dev, dave, iant
CC=golang-dev
https://golang.org/cl/39680043
2013-12-16 12:51:58 -05:00
Russ Cox
870e821ded cmd/cc, cmd/gc: update compilers, assemblers for liblink changes
- add buffered stdout to all tools and provide to link ctxt.
- avoid extra \n before ! in .6 files written by assemblers
  (makes them match the C compilers).
- use linkwriteobj instead of linkouthist+linkwritefuncs.
- in assemblers and C compilers, record pc explicitly in Prog,
  for use by liblink.
- in C compilers, preserve jump target links.
- in Go compilers (gsubr.c) attach gotype directly to
  corresponding LSym* instead of rederiving from instruction stream.
- in Go compilers, emit just one definition for runtime.zerovalue
  from each compilation.

This CL consists entirely of small adjustments.
The heavy lifting is in CL 39680043.
Each depends on the other.

R=golang-dev, dave, iant
CC=golang-dev
https://golang.org/cl/37030045
2013-12-16 12:51:38 -05:00
Russ Cox
426b48a775 cmd/5a, cmd/6a, cmd/8a: fix .y files to match y.tab.[ch]
When I renamed LAddr back to Addr (before sending the
original linker CLs), I missed the .y files in my global substitute.
Since the .y files are only processed when running make in
one of those directories (not during all.bash), they were
behind the generated files.

R=golang-dev, iant
CC=golang-dev
https://golang.org/cl/40770044
2013-12-11 12:11:37 -05:00
David du Colombier
4321beba85 liblink, cmd/gc: fix incompatible type signatures on Plan 9
R=ality, golang-dev, r, rsc
CC=golang-dev
https://golang.org/cl/39640043
2013-12-10 08:42:41 -05:00
Russ Cox
4c01a23cf1 cmd/pack: stop parsing object files to generate __.SYMDEF
Nothing looks at __.SYMDEF, and the object file format is changing.

R=golang-dev, r
CC=golang-dev
https://golang.org/cl/39580044
2013-12-09 19:35:17 -05:00
Russ Cox
4230044bb8 runtime: remove non-extern decls of runtime.goarm
The linker is in charge of providing the one true declaration.

R=golang-dev, dave, r
CC=golang-dev
https://golang.org/cl/39560043
2013-12-09 19:35:07 -05:00
Alex Brainman
6795687427 cmd/cgo: use __gcc_struct__ for go exported functions
Fixes #6833

R=minux.ma, iant
CC=golang-dev
https://golang.org/cl/35790045
2013-12-10 11:30:12 +11:00
David du Colombier
58005207d2 cmd/8c, cmd/8g, cmd/8l: fix Plan 9 warnings
warning: src/cmd/8c/list.c:124 format mismatch d VLONG, arg 3
warning: src/cmd/8c/list.c:134 format mismatch d VLONG, arg 3
warning: src/cmd/8c/list.c:142 format mismatch d VLONG, arg 3
warning: src/cmd/8c/list.c:152 format mismatch d VLONG, arg 3
warning: src/cmd/8c/list.c:156 format mismatch d VLONG, arg 4
warning: src/cmd/8c/list.c:160 format mismatch d VLONG, arg 4
warning: src/cmd/8c/list.c:165 format mismatch d VLONG, arg 4
warning: src/cmd/8c/list.c:167 format mismatch d VLONG, arg 3
warning: src/cmd/8c/list.c:172 format mismatch d VLONG, arg 4
warning: src/cmd/8c/list.c:174 format mismatch d VLONG, arg 3
warning: src/cmd/8c/list.c:178 format mismatch d VLONG, arg 3
warning: src/cmd/8c/list.c:184 format mismatch d VLONG, arg 3

warning: src/cmd/8g/list.c:91 format mismatch d VLONG, arg 4
warning: src/cmd/8g/list.c:100 format mismatch d VLONG, arg 4
warning: src/cmd/8g/list.c:114 format mismatch d VLONG, arg 5
warning: src/cmd/8g/list.c:118 format mismatch d VLONG, arg 5
warning: src/cmd/8g/list.c:122 format mismatch d VLONG, arg 5
warning: src/cmd/8g/list.c:126 format mismatch d VLONG, arg 5
warning: src/cmd/8g/list.c:136 format mismatch d VLONG, arg 4

warning: src/cmd/8l/list.c:107 format mismatch d VLONG, arg 4
warning: src/cmd/8l/list.c:125 format mismatch ux VLONG, arg 4
warning: src/cmd/8l/list.c:128 format mismatch ux VLONG, arg 4
warning: src/cmd/8l/list.c:130 format mismatch d VLONG, arg 4
warning: src/cmd/8l/list.c:134 format mismatch d VLONG, arg 5
warning: src/cmd/8l/list.c:138 format mismatch d VLONG, arg 6
warning: src/cmd/8l/list.c:143 format mismatch d VLONG, arg 5
warning: src/cmd/8l/list.c:148 format mismatch d VLONG, arg 5
warning: src/cmd/8l/list.c:150 format mismatch d VLONG, arg 4
warning: src/cmd/8l/list.c:154 format mismatch d VLONG, arg 4
warning: src/cmd/8l/list.c:158 format mismatch d VLONG, arg 4
warning: src/cmd/8l/obj.c:132 format mismatch ux VLONG, arg 2

R=golang-dev, rsc
CC=golang-dev
https://golang.org/cl/39710043
2013-12-09 18:47:22 -05:00
Anthony Martin
66c32384dd build: do not use the host's libbio on Plan 9
R=jas, lucio.dere, rsc
CC=golang-dev
https://golang.org/cl/14604047
2013-12-09 18:39:58 -05:00
Carl Shapiro
bc9691c465 cmd/gc, runtime: correct a misnomer regarding dead value maps
The funcdata symbol incorrectly named the dead value map the
dead pointer map.  The dead value map identifies all dead
values, including pointers and non-pointers, in a stack frame.
The purpose of this map is to allow the runtime to poison
locations of dead data to catch lost invariants.

R=golang-dev, iant
CC=golang-dev
https://golang.org/cl/38670043
2013-12-09 14:45:10 -08:00
Russ Cox
9a53fb571d cmd/gc: fix windows build, probably
TBR=iant
CC=golang-dev
https://golang.org/cl/39540043
2013-12-09 13:02:56 -05:00
Russ Cox
1eac128d64 cmd/6l: fix linux/amd64
TBR=iant
CC=golang-dev
https://golang.org/cl/39530043
2013-12-09 09:58:35 -08:00
Russ Cox
65a643ba47 cmd/dist, cmd/go: pass -fmessage-length always
R=golang-dev, iant
CC=golang-dev
https://golang.org/cl/36300044
2013-12-09 12:56:23 -05:00
Russ Cox
295e73e13f cmd/gc: print more information for windows failure
TBR=iant
CC=golang-dev
https://golang.org/cl/39510043
2013-12-09 12:55:25 -05:00
Russ Cox
0c0589ec42 cmd/ld: fix linux/386 build
TBR=iant
CC=golang-dev
https://golang.org/cl/39400044
2013-12-09 07:42:55 -08:00
Russ Cox
79479ac486 cmd/dist, cmd/go: pass -fmessage-length=0 when using clang
That option turns off word wrapping of individual
error messages generated by clang. The wrapping
makes the errors harder to read and conflicts with the
idea of a terminal window that can be resized.

R=golang-dev, r
CC=golang-dev
https://golang.org/cl/35810043
2013-12-09 10:33:27 -05:00
Russ Cox
f606c1be80 cmd/5g, cmd/6g, cmd/8g: use liblink
Preparation for golang.org/s/go13linker work.

This CL does not build by itself. It depends on 35740044
and 35790044 and will be submitted at the same time.

R=iant
CC=golang-dev
https://golang.org/cl/34590045
2013-12-08 22:51:55 -05:00
Russ Cox
76a8c873cf cmd/5c, cmd/6c, cmd/8c: use liblink
Preparation for golang.org/s/go13linker work.

This CL does not build by itself. It depends on 35740044
and 35790044 and will be submitted at the same time.

R=iant
CC=golang-dev
https://golang.org/cl/34580044
2013-12-08 22:51:31 -05:00
Russ Cox
f7aaa553da cmd/5a, cmd/6a, cmd/8a: use liblink
Preparation for golang.org/s/go13linker work.

This CL does not build by itself. It depends on 35740044
and 35790044 and will be submitted at the same time.

R=iant
CC=golang-dev
https://golang.org/cl/35830043
2013-12-08 22:49:56 -05:00
Russ Cox
7d507dc6e6 liblink: create new library based on linker code
There is an enormous amount of code moving around in this CL,
but the code is the same, and it is invoked in the same ways.
This CL is preparation for the new linker structure, not the new
structure itself.

The new library's definition is in include/link.h.

The main change is the use of a Link structure to hold all the
linker-relevant state, replacing the smattering of global variables.
The Link structure should both make it clearer which state must
be carried around and make it possible to parallelize more easily
later.

The main body of the linker has moved into the architecture-independent
cmd/ld directory. That includes the list of known header types, so the
distinction between Hplan9x32 and Hplan9x64 is removed (no other
header type distinguished 32- and 64-bit formats), and code for unused
formats such as ipaq kernels has been deleted.

The code being deleted from 5l, 6l, and 8l reappears in liblink or in ld.
Because multiple files are being merged in the liblink directory,
it is not possible to show the diffs nicely in hg.

The Prog and Addr structures have been unified into an
architecture-independent form and moved to link.h, where they will
be shared by all tools: the assemblers, the compilers, and the linkers.
The unification makes it possible to write architecture-independent
traversal of Prog lists, among other benefits.

The Sym structures cannot be unified: they are too fundamentally
different between the linker and the compilers. Instead, liblink defines
an LSym - a linker Sym - to be used in the Prog and Addr structures,
and the linker now refers exclusively to LSyms. The compilers will
keep using their own syms but will fill out the corresponding LSyms in
the Prog and Addr structures.

Although code from 5l, 6l, and 8l is now in a single library, the
code has been arranged so that only one architecture needs to
be linked into a particular program: 5l will not contain the code
needed for x86 instruction layout, for example.

The object file writing code in liblink/obj.c is from cmd/gc/obj.c.

Preparation for golang.org/s/go13linker work.

This CL does not build by itself. It depends on 35740044
and will be submitted at the same time.

R=iant
CC=golang-dev
https://golang.org/cl/35790044
2013-12-08 22:49:37 -05:00
Russ Cox
8642cbd660 cmd/dist: add liblink build information
In addition to adding the library, change the way the anames array is created.
Previously, it was written to src/cmd/6l/enam.c (and similarly for 5l and 8l)
and each of the other tools (6g, 6c, 6a) compiled the 6l/enam.c file in addition
to their own sources.

Now that there is a library shared by all these programs, move the anames
array into that library. To eliminate name conflicts, name the array after
the architecture letter: anames5, anames6, anames8.

First step to linker cleanup (golang.org/s/go13linker).

This CL does not build by itself. It depends on the CLs introducing
liblink and changing commands to use it.

R=iant
CC=golang-dev
https://golang.org/cl/35740044
2013-12-08 22:48:11 -05:00
Carl Shapiro
6965a752a7 cmd/gc: do not generate dead value maps yet
We are not clearing dead values in the garbage collector so it
is not worth the RSS cost to materialize the data and write it
out to the binary.

R=golang-dev, iant, cshapiro
CC=golang-dev
https://golang.org/cl/38650043
2013-12-06 15:49:47 -08:00
Carl Shapiro
d4f68f2892 cmd/gc: clarify a TODO regarding variables used in liveness analysis
R=golang-dev, iant
CC=golang-dev
https://golang.org/cl/38640043
2013-12-06 15:36:54 -08:00
Carl Shapiro
f1e726e311 cmd/dist: revert an accidental change to the optimization setting
R=golang-dev
CC=golang-dev
https://golang.org/cl/38130043
2013-12-05 17:49:34 -08:00
Carl Shapiro
f056daf075 cmd/5g, cmd/5l, cmd/6g, cmd/6l, cmd/8g, cmd/8l, cmd/gc, runtime: generate pointer maps by liveness analysis
This change allows the garbage collector to examine stack
slots that are determined as live and containing a pointer
value by the garbage collector.  This results in a mean
reduction of 65% in the number of stack slots scanned during
an invocation of "GOGC=1 all.bash".

Unfortunately, this does not yet allow garbage collection to
be precise for the stack slots computed as live.  Pointers
confound the determination of what definitions reach a given
instruction.  In general, this problem is not solvable without
runtime cost but some advanced cooperation from the compiler
might mitigate common cases.

R=golang-dev, rsc, cshapiro
CC=golang-dev
https://golang.org/cl/14430048
2013-12-05 17:35:22 -08:00
Keith Randall
f238049a00 cmd/gc: fix special-casing of the printed names of map internal structures.
Shaves 1% off of binary size.

update #6853

R=golang-dev, rsc
CC=golang-dev
https://golang.org/cl/35940047
2013-12-03 14:27:08 -08:00
Keith Randall
24699fb05c runtime: get rid of concatstring's vararg C argument.
Pass as a slice of strings instead.  For 2-5 strings, implement
dedicated routines so no slices are needed.

static call counts in the go binary:
 2 strings: 342 occurrences
 3 strings:  98
 4 strings:  30
 5 strings:  13
6+ strings:  14

Why?  C varags, bad for stack scanning and copying.

R=golang-dev, iant
CC=golang-dev
https://golang.org/cl/36380043
2013-12-03 10:39:19 -08:00
Keith Randall
c792bde9ef runtime: don't use ... formal argument to deferreturn.
R=golang-dev, rsc
CC=golang-dev
https://golang.org/cl/28860043
2013-12-02 13:07:15 -08:00
Keith Randall
3278dc158e runtime: pass key/value to map accessors by reference, not by value.
This change is part of the plan to get rid of all vararg C calls
which are a pain for getting exact stack scanning.

We allocate a chunk of zero memory to return a pointer to when a
map access doesn't find the key.  This is simpler than returning nil
and fixing things up in the caller.  Linker magic allocates a single
zero memory area that is shared by all (non-reflect-generated) map
types.

Passing things by reference gets rid of some copies, so it speeds
up code with big keys/values.

benchmark             old ns/op    new ns/op    delta
BenchmarkBigKeyMap           34           31   -8.48%
BenchmarkBigValMap           37           30  -18.62%
BenchmarkSmallKeyMap         26           23  -11.28%

R=golang-dev, dvyukov, khr, rsc
CC=golang-dev
https://golang.org/cl/14794043
2013-12-02 13:05:04 -08:00
Russ Cox
a664b49457 doc/asm: more about SP, ARM R11
Also rename URL to /doc/asm.

R=golang-dev, minux.ma, r
CC=golang-dev
https://golang.org/cl/26170043
2013-11-13 21:29:34 -05:00
Rob Pike
0bdd90bc0a src/cmd/?a: link to new assembler document
Blocked on 20930043, the CL the new text references.

R=golang-dev, bradfitz
CC=golang-dev
https://golang.org/cl/18430044
2013-11-12 20:07:08 -08:00
Russ Cox
6be1cb8c7a cmd/cgo: fix handling of array of pointers when using clang
Clang does not record the "size" field for pointer types,
so we must insert the size ourselves. We were already
doing this, but only for the case of pointer types.
For an array of pointer types, the setting of the size for
the nested pointer type was happening after the computation
of the size of the array type, meaning that the array type
was always computed as 0 bytes. Delay the size computation.

This bug happens on all Clang systems, not just FreeBSD.
Our test checked that cgo wrote something, not that it was correct.
FreeBSD's default clang rejects array[0] as a C struct field,
so it noticed the incorrect sizes. But the sizes were incorrect
everywhere.

Update testcdefs to check the output has the right semantics.

Fixes #6292.

R=golang-dev, iant
CC=golang-dev
https://golang.org/cl/22840043
2013-11-07 15:24:51 -05:00
Russ Cox
2c98a3bc2e cmd/5l, runtime: fix divide for profiling tracebacks on ARM
Two bugs:
1. The first iteration of the traceback always uses LR when provided,
which it is (only) during a profiling signal, but in fact LR is correct
only if the stack frame has not been allocated yet. Otherwise an
intervening call may have changed LR, and the saved copy in the stack
frame should be used. Fix in traceback_arm.c.

2. The division runtime call adds 8 bytes to the stack. In order to
keep the traceback routines happy, it must copy the saved LR into
the new 0(SP). Change

        SUB $8, SP

into

        MOVW    0(SP), R11 // r11 is temporary, for use by linker
        MOVW.W  R11, -8(SP)

to update SP and 0(SP) atomically, so that the traceback always
sees a saved LR at 0(SP).

Fixes #6681.

R=golang-dev, r
CC=golang-dev
https://golang.org/cl/19910044
2013-10-31 18:15:55 +00:00
Russ Cox
b88148b9a0 undo CL 19810043 / 352f3b7c9664
The CL causes misc/cgo/test to fail randomly.
I suspect that the problem is the use of a division instruction
in usleep, which can be called while trying to acquire an m
and therefore cannot store the denominator in m.
The solution to that would be to rewrite the code to use a
magic multiply instead of a divide, but now we're getting
pretty far off the original code.

Go back to the original in preparation for a different,
less efficient but simpler fix.

««« original CL description
cmd/5l, runtime: make ARM integer division profiler-friendly

The implementation of division constructed non-standard
stack frames that could not be handled by the traceback
routines.

CL 13239052 left the frames non-standard but fixed them
for the specific case of a divide-by-zero panic.
A profiling signal can arrive at any time, so that fix
is not sufficient.

Change the division to store the extra argument in the M struct
instead of in a new stack slot. That keeps the frames bog standard
at all times.

Also fix a related bug in the traceback code: when starting
a traceback, the LR register should be ignored if the current
function has already allocated its stack frame and saved the
original LR on the stack. The stack copy should be used, as the
LR register may have been modified.

Combined, these make the torture test from issue 6681 pass.

Fixes #6681.

R=golang-dev, r, josharian
CC=golang-dev
https://golang.org/cl/19810043
»»»

TBR=r
CC=golang-dev
https://golang.org/cl/20350043
2013-10-31 17:18:57 +00:00
Russ Cox
b0db472ea2 cmd/5l, runtime: make ARM integer division profiler-friendly
The implementation of division constructed non-standard
stack frames that could not be handled by the traceback
routines.

CL 13239052 left the frames non-standard but fixed them
for the specific case of a divide-by-zero panic.
A profiling signal can arrive at any time, so that fix
is not sufficient.

Change the division to store the extra argument in the M struct
instead of in a new stack slot. That keeps the frames bog standard
at all times.

Also fix a related bug in the traceback code: when starting
a traceback, the LR register should be ignored if the current
function has already allocated its stack frame and saved the
original LR on the stack. The stack copy should be used, as the
LR register may have been modified.

Combined, these make the torture test from issue 6681 pass.

Fixes #6681.

R=golang-dev, r, josharian
CC=golang-dev
https://golang.org/cl/19810043
2013-10-30 18:50:34 +00:00
Russ Cox
797d1bac0d cmd/cgo: accept extra leading _ on __cgodebug_data for all object formats
The current Windows build breakage appears to be because
the Windows code should be looking for __cgodebug_data
not ___cgodebug_data. Dodge the question everywhere by
accepting both.

R=golang-dev, iant
CC=golang-dev
https://golang.org/cl/19780043
2013-10-30 10:24:42 -04:00
Russ Cox
b8be100d35 cmd/gc: silence clang warning
This code is only built when you run 'make' in cmd/gc,
not in all.bash.

R=golang-dev, jsing, iant
CC=golang-dev
https://golang.org/cl/19160043
2013-10-29 11:50:18 -04:00
Russ Cox
adda33483d cmd/cgo: stop using -fno-eliminate-unused-debug-types
This flag was added in January 2010, in CL 181102, to fix issue 497.
(Numbers were just shorter back then.) The fix was for OS X machines
and the llvm-gcc frontend.

In July 2011 we had to change the way we get enum values, because
there were no flags available to force Xcode's llvm-gcc to include the
enum names and values in DWARF debug output.

We now use clang, not llvm-gcc, on OS X machines.
Earlier versions of clang printed a warning about not knowing the flag.
Newer versions of clang now make that an error.

That is:
 - The flag was added for OS X machines.
 - The flag is no longer necessary on OS X machines.
 - The flag now breaks some OS X machines.

Remove it.

I have run the original program from issue 497 successfully
without the flag on both OS X and Linux machines.

Fixes #6678.

R=golang-dev, minux.ma
CC=golang-dev
https://golang.org/cl/18850043
2013-10-28 22:21:26 -04:00
Russ Cox
c8ddfd9ad1 cmd/cgo: use __typeof__, -w instead of typeof, -Wno-all
Suggested by iant in earlier CL.

R=golang-dev, bradfitz, iant
CC=golang-dev
https://golang.org/cl/14920052
2013-10-22 18:33:23 -04:00
Shenghou Ma
be1a94b401 cmd/yacc: fix stderr on Windows.
Fixes #6620.

R=golang-dev, dave, r
CC=golang-dev
https://golang.org/cl/15330043
2013-10-19 23:07:20 -04:00
Russ Cox
dbe2eacf04 cmd/cgo: fix line number in an error message
Fixes #6563.

R=golang-dev, iant
CC=golang-dev
https://golang.org/cl/14870046
2013-10-18 16:52:44 -04:00
Russ Cox
06ad3b2de1 cmd/cgo: stop using compiler error message text to analyze C names
The old approach to determining whether "name" was a type, constant,
or expression was to compile the C program

        name;

and scan the errors and warnings generated by the compiler.
This requires looking for specific substrings in the errors and warnings,
which ties the implementation to specific compiler versions.
As compilers change their errors or drop warnings, cgo breaks.
This happens slowly but it does happen.
Clang in particular (now required on OS X) has a significant churn rate.

The new approach compiles a slightly more complex program
that is either valid C or not valid C depending on what kind of
thing "name" is. It uses only the presence or absence of an error
message on a particular line, not the error text itself. The program is:

        // error if and only if name is undeclared
        void f1(void) { typeof(name) *x; }

        // error if and only if name is not a type
        void f2(void) { name *x; }

        // error if and only if name is not an integer constant
        void f3(void) { enum { x = (name)*1 }; }

I had not been planning to do this until Go 1.3, because it is a
non-trivial change, but it fixes a real Xcode 5 problem in Go 1.2,
and the new code is easier to understand than the old code.
It should be significantly more robust.

Fixes #6596.
Fixes #6612.

R=golang-dev, r, james, iant
CC=golang-dev
https://golang.org/cl/15070043
2013-10-18 15:56:25 -04:00
Russ Cox
20f99ffa3e cmd/gc: shorten name used for map bucket type
Before:
type.struct { buckets *struct { overflow *struct { overflow *struct { overflow *struct { overflow *struct { overflow *<...>; keys [8]string; values [8]*"".RangeTable }; keys [8]string; values [8]*"".RangeTable }; keys [8]string; values [8]*"".RangeTable }; keys [8]string; values [8]*"".RangeTable }; keys [8]string; values [8]*"".RangeTable }; oldbuckets *struct { overflow *struct { overflow *struct { overflow *struct { overflow *struct { overflow *<...>; keys [8]string; values [8]*"".RangeTable }; keys [8]string; values [8]*"".RangeTable }; keys [8]string; values [8]*"".RangeTable }; keys [8]string; values [8]*"".RangeTable }; keys [8]string; values [8]*"".RangeTable } }

After:
type.map.bucket[string]*"".RangeTable

This makes debugging maps a little nicer, and it takes up less space in the binary.

R=golang-dev, r
CC=golang-dev, khr
https://golang.org/cl/15110044
2013-10-18 15:56:07 -04:00
Andrew Gerrand
04e95a1a56 api: add go1.2.txt, use in tests
R=golang-dev, iant
CC=golang-dev
https://golang.org/cl/14860043
2013-10-18 13:36:59 +09:00
Shenghou Ma
4d38d1260e cmd/cgo: simpler fix for issue 6506.
Replaces CL 14682044.
Fixes #6506.

R=rsc, iant, dave
CC=golang-dev
https://golang.org/cl/14717043
2013-10-15 21:35:52 -04:00
Russ Cox
5feb15508e cmd/cgo: print the builtin prolog after the per-file preamble
The preamble may want to #define some special symbols
and then #include <sys/types.h> itself. The builtin prolog
also #includes <sys/types.h>, which would break such a
preamble (because the second #include will be a no-op).

The use of sys/types.h in the builtin prolog is new since Go 1.1,
so this should preserve the semantics of more existing cgo
code than we would otherwise.

It also fixes src/pkg/syscall/mkall.sh's use of go tool cgo -godefs
on some Linux systems.

Thanks to fullung@ for identifying the problem.

Fixes #6558.

R=golang-dev, iant
CC=golang-dev
https://golang.org/cl/14684044
2013-10-15 15:00:48 -04:00
Russ Cox
043ace1213 cmd/cgo: fix Xcode 5 incompatibility for #defined expressions
Ensure that clang always exits with a non-zero status by
giving it something that it always warns about (the statement "1;").

Fixes #6128.

R=golang-dev, iant, minux.ma
CC=golang-dev
https://golang.org/cl/14702043
2013-10-15 14:34:46 -04:00
Russ Cox
56aeec31c6 cmd/cgo: work around bug in clang debug info for builtins like memset
Fixes #6506.

R=golang-dev, r
CC=golang-dev
https://golang.org/cl/14682044
2013-10-15 12:46:14 -04:00
Keith Randall
2acb80b5e5 cmd/gc: fix comment about performing indexing at compile time.
R=golang-dev, r
CC=golang-dev
https://golang.org/cl/14441070
2013-10-14 14:26:52 -07:00
Shenghou Ma
89ebc28b58 cmd/api: make it work even when cgo is disabled
make use of $USER or %USERNAME% to determine the current user.
Fixes #6578.

R=golang-dev, bradfitz, alex.brainman
CC=golang-dev
https://golang.org/cl/14649043
2013-10-14 00:18:46 -04:00
Shenghou Ma
7dba510c7b cmd/gc: re-word some error messages
Fixes #6557.

R=golang-dev, rsc, tracey.brendan
CC=golang-dev
https://golang.org/cl/14432053
2013-10-10 22:43:34 -04:00
Ian Lance Taylor
c774e90208 cmd/go: add any .c/.cc files to the SWIG shared library
Also add the action's object directory to the list of
directories we use to find SWIG shared libraries.

Fixes #6521.

R=golang-dev, minux.ma
CC=golang-dev
https://golang.org/cl/14369043
2013-10-09 10:35:46 -07:00
Carl Shapiro
254dc5fdbe cmd/go, runtime: express armv5t architecture constraint differently
Instead of adding an -march=armv5t flag to the gcc command
line, the same effect is obtained with an ".arch armv5t"
pseudo op in the assembly file that uses armv5t instructions.

R=golang-dev, iant, dave
CC=golang-dev
https://golang.org/cl/14511044
2013-10-08 10:40:51 -07:00
Robert Hencke
a51b8cf870 gofmt: explain why lower bounds aren't automatically simplified
Full credit goes to gri and rsc for their explanations.

R=golang-dev, r
CC=golang-dev
https://golang.org/cl/14229043
2013-10-03 10:55:17 -07:00
Dave Day
0a033a18ad cmd/gc: support -installsuffix in the compiler and builder
Add the -installsuffix flag to gc and {5,6,8}l, which overrides -race
for the suffix if both are supplied.
Pass this flag from the go tool for build and install.

R=rsc
CC=golang-dev
https://golang.org/cl/14246044
2013-10-03 13:48:47 +10:00
Russ Cox
e0867738fc cmd/go: document relative imports
Fixes #3524.

R=golang-dev, iant, r
CC=golang-dev
https://golang.org/cl/14296043
2013-10-02 21:42:23 -04:00
Rémy Oudompheng
8d6bc666fb cmd/gc: qualified embedded fields with owner package.
R=rsc
CC=golang-dev
https://golang.org/cl/14188044
2013-10-02 12:27:33 -04:00