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

500 Commits

Author SHA1 Message Date
Russ Cox
220a6de47e build: adjustments for move from src/pkg to src
This CL adjusts code referring to src/pkg to refer to src.

Immediately after submitting this CL, I will submit
a change doing 'hg mv src/pkg/* src'.
That change will be too large to review with Rietveld
but will contain only the 'hg mv'.

This CL will break the build.
The followup 'hg mv' will fix it.

For more about the move, see golang.org/s/go14nopkg.

LGTM=r
R=r
CC=golang-codereviews
https://golang.org/cl/134570043
2014-09-08 00:06:45 -04:00
Russ Cox
0bb14d74f1 cmd/ld: diagnose Go calling C
For example:
go build -ldflags -C cmd/go 2>&1 | awk '{print $NF}' | sort | uniq -c | sort -nr

LGTM=khr
R=khr, josharian
CC=golang-codereviews
https://golang.org/cl/135170044
2014-08-31 22:49:14 -04:00
Matthew Dempsky
2c110a11e0 cmd/{ld,link,objdump}, runtime, debug/gosym: move linker-defined symbols into runtime package
Fixes #8092.

LGTM=rsc
R=iant, rsc
CC=golang-codereviews
https://golang.org/cl/126790043
2014-08-27 20:15:05 -04:00
Dave Cheney
f129370b3e cmd/ld: fix undefined behaviour in pcln.c
Update #8527

Fixes, src/cmd/6l/../ld/pcln.c:93:18: runtime error: left shift of negative value -2

LGTM=r
R=golang-codereviews, r
CC=golang-codereviews
https://golang.org/cl/127440043
2014-08-22 09:10:33 +10:00
Russ Cox
ca85d572d6 liblink: use pc-relative addressing for all memory references in amd64 code
LGTM=rminnich, iant
R=golang-codereviews, rminnich, iant
CC=golang-codereviews, r
https://golang.org/cl/125140043
2014-08-18 21:06:56 -04:00
Dave Cheney
78cc89ce67 cmd/ld: fix operator precedence
Fixes #8480.

This CL reapplies CL 114420043. This attempt doesn't blow up when encountering hidden symbols.

LGTM=minux
R=minux
CC=golang-codereviews
https://golang.org/cl/128310043
2014-08-16 14:10:35 +10:00
Shenghou Ma
41d75933d7 cmd/ld: fix operator precedence
LGTM=rsc
R=gobot, dave
CC=golang-codereviews, iant, rsc
https://golang.org/cl/114420043
2014-08-16 14:04:15 +10:00
Russ Cox
9abf0b6e9f cmd/ld: handle large link base addresses
codeblk and datblk were truncating their
arguments to int32. Don't do that.

LGTM=dvyukov, rminnich
R=iant, dvyukov, rminnich
CC=golang-codereviews
https://golang.org/cl/126050043
2014-08-12 17:41:16 -04:00
Shenghou Ma
6503d40051 undo CL 114420043 / b613f2acdf69
Broke freebsd/amd64 due to exposure of a latent bug.

««« original CL description
cmd/ld: fix operator precedence

LGTM=rsc
R=rsc, iant
CC=golang-codereviews
https://golang.org/cl/114420043
»»»

TBR=dfc
R=dave
CC=golang-codereviews
https://golang.org/cl/120630043
2014-08-06 02:07:31 -04:00
Shenghou Ma
45bd2f8c45 cmd/5l, cmd/6l, cmd/8l, cmd/ld: remove unused code, consolidate enums
LGTM=rsc
R=rsc, iant
CC=golang-codereviews
https://golang.org/cl/120220043
2014-08-06 00:25:52 -04:00
Shenghou Ma
2c181f0355 cmd/ld: fix operator precedence
LGTM=rsc
R=rsc, iant
CC=golang-codereviews
https://golang.org/cl/114420043
2014-08-06 00:25:05 -04:00
Dmitriy Vyukov
81674f3135 runtime: remove type.go
We have an autogenerated version in zruntime_defs.
I am not sure what are the consequences as gdb never printed any values for me.
But it looks unnecessary to manually duplicate it.

LGTM=rsc
R=golang-codereviews, rsc
CC=golang-codereviews, iant, khr
https://golang.org/cl/115660043
2014-08-05 22:32:24 +04:00
Dmitriy Vyukov
9333fe8e92 cmd/ld: better diagnostics on unaligned symbols
Want to see why builders are failing.
Then decide whether to rollback or fix.

TBR=khr
R=khr
CC=golang-codereviews
https://golang.org/cl/114510043
2014-07-29 11:22:57 +04:00
Dmitriy Vyukov
cd17a717f9 runtime: simpler and faster GC
Implement the design described in:
https://docs.google.com/document/d/1v4Oqa0WwHunqlb8C3ObL_uNQw3DfSY-ztoA-4wWbKcg/pub

Summary of the changes:
GC uses "2-bits per word" pointer type info embed directly into bitmap.
Scanning of stacks/data/heap is unified.
The old spans types go away.
Compiler generates "sparse" 4-bits type info for GC (directly for GC bitmap).
Linker generates "dense" 2-bits type info for data/bss (the same as stacks use).

Summary of results:
-1680 lines of code total (-1000+ in mgc0.c only)
-25% memory consumption
-3-7% binary size
-15% GC pause reduction
-7% run time reduction

LGTM=khr
R=golang-codereviews, rsc, christoph, khr
CC=golang-codereviews, rlh
https://golang.org/cl/106260045
2014-07-29 11:01:02 +04:00
Shenghou Ma
faa223459a cmd/ld: remove duplicated nuxiinit() call.
It is already called by linknew().

LGTM=dave
R=rsc, dave
CC=golang-codereviews
https://golang.org/cl/120760043
2014-07-26 17:45:45 -04:00
Dmitriy Vyukov
65e2b6f847 cmd/ld: mark hostobj sections as containing no pointers
Currently they are scanned conservatively.
But there is no reason to scan them. C world must not contain
pointers into Go heap. Moreover, we don't have enough information
to emit write barriers nor update pointers there in future.
The immediate need is that it breaks the new GC because
these are weird symbols as if with pointers but not necessary
pointer aligned.

LGTM=rsc
R=golang-codereviews, rlh, rsc
CC=golang-codereviews, iant, khr
https://golang.org/cl/117000043
2014-07-22 12:10:18 +04:00
Keith Randall
0c6b55e76b runtime: convert map implementation to Go.
It's a bit slower, but not painfully so.  There is still room for
improvement (saving space so we can use nosplit, and removing the
requirement for hash/eq stubs).

benchmark                              old ns/op     new ns/op     delta
BenchmarkMegMap                        23.5          24.2          +2.98%
BenchmarkMegOneMap                     14.9          15.7          +5.37%
BenchmarkMegEqMap                      71668         72234         +0.79%
BenchmarkMegEmptyMap                   4.05          4.93          +21.73%
BenchmarkSmallStrMap                   21.9          22.5          +2.74%
BenchmarkMapStringKeysEight_16         23.1          26.3          +13.85%
BenchmarkMapStringKeysEight_32         21.9          25.0          +14.16%
BenchmarkMapStringKeysEight_64         21.9          25.1          +14.61%
BenchmarkMapStringKeysEight_1M         21.9          25.0          +14.16%
BenchmarkIntMap                        21.8          12.5          -42.66%
BenchmarkRepeatedLookupStrMapKey32     39.3          30.2          -23.16%
BenchmarkRepeatedLookupStrMapKey1M     322353        322675        +0.10%
BenchmarkNewEmptyMap                   129           136           +5.43%
BenchmarkMapIter                       137           107           -21.90%
BenchmarkMapIterEmpty                  7.14          8.71          +21.99%
BenchmarkSameLengthMap                 5.24          6.82          +30.15%
BenchmarkBigKeyMap                     34.5          35.3          +2.32%
BenchmarkBigValMap                     36.1          36.1          +0.00%
BenchmarkSmallKeyMap                   26.9          26.7          -0.74%

LGTM=rsc
R=golang-codereviews, dave, dvyukov, rsc, gobot, khr
CC=golang-codereviews
https://golang.org/cl/99380043
2014-07-16 14:16:19 -07:00
Rob Pike
74c9cc8394 cmd/ld: use count, not upper bound, in type of array
DWARF says only one is necessary.
The count is preferable because it admits 0-length arrays.
Update debug/dwarf to handle either form.

LGTM=rsc
R=rsc
CC=golang-codereviews
https://golang.org/cl/111230044
2014-07-16 18:26:50 +00:00
Rob Pike
cddad8affe cmd/ld: change DWARF encoding for array lengths
They can be large, so use a varint encoding rather than only one byte.

LGTM=iant, rsc
R=rsc, iant
CC=golang-codereviews
https://golang.org/cl/113180043
2014-07-15 21:18:18 +00:00
Matthew Dempsky
6012ac9b79 cmd/ld: consistently document flags that expect values
LGTM=minux, rsc
R=golang-codereviews, minux, rsc
CC=golang-codereviews
https://golang.org/cl/113970044
2014-07-15 17:05:35 -04:00
Rob Pike
79b106ec62 cmd/ld: generate correct upper bound value for array types.
LGTM=rsc
R=rsc
CC=golang-codereviews
https://golang.org/cl/115820043
2014-07-15 01:38:05 +00:00
Russ Cox
e1821692ca cmd/ld: add go-specific dwarf type information
LGTM=r
R=r
CC=golang-codereviews
https://golang.org/cl/116720043
2014-07-11 23:10:00 -04:00
Rob Pike
125d1e9269 ld: change DWARF output for structs
The debug/dwarf package cannot parse the format generated here,
but the format can be changed so it does.
After this edit, tweaking the expression defining the offset
of a struct field, the dwarf package can parse the tables (again?).

LGTM=rsc
R=rsc
CC=golang-codereviews
https://golang.org/cl/105710043
2014-07-11 15:16:00 +00:00
Rob Pike
7b0ee53429 cmd/ld: fix off-by-one in DWARF frame tables
The code generating the .debug_frame section emits pairs of "advance PC",
"set SP offset" pseudo-instructions. Before the fix, the PC advance comes
out before the SP setting, which means the emitted offset for a block is
actually the value at the end of the block, which is incorrect for the
block itself.

The easiest way to fix this problem is to emit the SP offset before the
PC advance.

One delicate point: the last instruction to come out is now an
"advance PC", which means that if there are padding intsructions after
the final RET, they will appear to have a non-zero offset. This is odd
but harmless because there is no legal way to have a PC in that range,
or to put it another way, if you get here the SP is certainly screwed up
so getting the wrong (virtual) frame pointer is the least of your worries.

LGTM=iant
R=rsc, iant, lvd
CC=golang-codereviews
https://golang.org/cl/112750043
2014-07-07 16:07:24 -07:00
David Crawshaw
12b990ba7d cmd/go, cmd/ld, runtime, os/user: TLS emulation for android
Based on cl/69170045 by Elias Naur.

There are currently several schemes for acquiring a TLS
slot to save the g register. None of them appear to work
for android. The closest are linux and darwin.

Linux uses a linker TLS relocation. This is not supported
by the android linker.

Darwin uses a fixed offset, and calls pthread_key_create
until it gets the slot it wants. As the runtime loads
late in the android process lifecycle, after an
arbitrary number of other libraries, we cannot rely on
any particular slot being available.

So we call pthread_key_create, take the first slot we are
given, and put it in runtime.tlsg, which we turn into a
regular variable in cmd/ld.

Makes android/arm cgo binaries work.

LGTM=minux
R=elias.naur, minux, dave, josharian
CC=golang-codereviews
https://golang.org/cl/106380043
2014-07-03 16:14:34 -04:00
Russ Cox
ebce79446d build: annotations and modifications for c2go
The main changes fall into a few patterns:

1. Replace #define with enum.

2. Add /*c2go */ comment giving effect of #define.
This is necessary for function-like #defines and
non-enum-able #defined constants.
(Not all compilers handle negative or large enums.)

3. Add extra braces in struct initializer.
(c2go does not implement the full rules.)

This is enough to let c2go typecheck the source tree.
There may be more changes once it is doing
other semantic analyses.

LGTM=minux, iant
R=minux, dave, iant
CC=golang-codereviews
https://golang.org/cl/106860045
2014-07-02 15:41:29 -04:00
Russ Cox
89f185fe8a all: remove 'extern register M *m' from runtime
The runtime has historically held two dedicated values g (current goroutine)
and m (current thread) in 'extern register' slots (TLS on x86, real registers
backed by TLS on ARM).

This CL removes the extern register m; code now uses g->m.

On ARM, this frees up the register that formerly held m (R9).
This is important for NaCl, because NaCl ARM code cannot use R9 at all.

The Go 1 macrobenchmarks (those with per-op times >= 10 µs) are unaffected:

BenchmarkBinaryTree17              5491374955     5471024381     -0.37%
BenchmarkFannkuch11                4357101311     4275174828     -1.88%
BenchmarkGobDecode                 11029957       11364184       +3.03%
BenchmarkGobEncode                 6852205        6784822        -0.98%
BenchmarkGzip                      650795967      650152275      -0.10%
BenchmarkGunzip                    140962363      141041670      +0.06%
BenchmarkHTTPClientServer          71581          73081          +2.10%
BenchmarkJSONEncode                31928079       31913356       -0.05%
BenchmarkJSONDecode                117470065      113689916      -3.22%
BenchmarkMandelbrot200             6008923        5998712        -0.17%
BenchmarkGoParse                   6310917        6327487        +0.26%
BenchmarkRegexpMatchMedium_1K      114568         114763         +0.17%
BenchmarkRegexpMatchHard_1K        168977         169244         +0.16%
BenchmarkRevcomp                   935294971      914060918      -2.27%
BenchmarkTemplate                  145917123      148186096      +1.55%

Minux previous reported larger variations, but these were caused by
run-to-run noise, not repeatable slowdowns.

Actual code changes by Minux.
I only did the docs and the benchmarking.

LGTM=dvyukov, iant, minux
R=minux, josharian, iant, dave, bradfitz, dvyukov
CC=golang-codereviews
https://golang.org/cl/109050043
2014-06-26 11:54:39 -04:00
Ian Lance Taylor
507afa68c5 cmd/ld: fix PC deltas in DWARF line number table
The putpclcdelta function set the DWARF line number PC to
s->value + pcline->pc, which is correct, but the code then set
the local variable pc to epc, which can be a different value.
This caused the next delta in the DWARF table to be wrong.

Fixes #8098.

LGTM=rsc
R=rsc
CC=golang-codereviews
https://golang.org/cl/104950045
2014-06-10 14:11:39 -07:00
Benny Siegert
775719c600 cmd/ld: correctly compute note size on NetBSD.
Patch from http://gnats.NetBSD.org/48811.

LGTM=iant
R=golang-codereviews, minux.ma, iant
CC=golang-codereviews, tk
https://golang.org/cl/94670047
2014-05-21 06:18:45 -07:00
Ian Lance Taylor
f85600859d cmd/ld: really import runtime/cgo for external link
Fixes #8032.

LGTM=rsc
R=rsc
CC=golang-codereviews
https://golang.org/cl/95580043
2014-05-20 21:36:50 -07:00
Russ Cox
a4a1fadfa2 cmd/ld: make lldb happy with Mach-O 6.out files
Apparently all the __DWARF sections need addresses
even though they are marked as "do not load from disk".
Continue the address numbering from the data segment.

With this change:

g% lldb helloworld
Current executable set to 'helloworld' (x86_64).
(lldb) b main.main
Breakpoint 1: where = helloworld`main.main + 25 at helloworld.go:12, address = 0x0000000000002019
(lldb) r
Process 68509 launched: '/Users/rsc/g/go/src/cmd/6l/helloworld' (x86_64)
1 location added to breakpoint 1
(lldb)
Process 68509 stopped
* thread #1: tid = 0x8b7a27, 0x0000000000002019 helloworld`main.main + 25 at helloworld.go:12, stop reason = breakpoint 1.2
    frame #0: 0x0000000000002019 helloworld`main.main + 25 at helloworld.go:12
   9   	package main
   10
   11  	func main() {
-> 12  		print("hello, world\n")
   13  	}
(lldb) bt
* thread #1: tid = 0x8b7a27, 0x0000000000002019 helloworld`main.main + 25 at helloworld.go:12, stop reason = breakpoint 1.2
  * frame #0: 0x0000000000002019 helloworld`main.main + 25 at helloworld.go:12
(lldb) disas
helloworld`main.main at helloworld.go:11:
   0x2000:  movq   %gs:0x8a0, %rcx
   0x2009:  cmpq   (%rcx), %rsp
   0x200c:  ja     0x2015                    ; main.main + 21 at helloworld.go:11
   0x200e:  callq  0x20da0                   ; runtime.morestack00_noctxt at atomic_amd64x.c:28
   0x2013:  jmp    0x2000                    ; main.main at helloworld.go:11
   0x2015:  subq   $0x10, %rsp
-> 0x2019:  leaq   0x2c2e0, %rbx
   0x2021:  leaq   (%rsp), %rbp
   0x2025:  movq   %rbp, %rdi
   0x2028:  movq   %rbx, %rsi
   0x202b:  movsq
   0x202d:  movsq
   0x202f:  callq  0x10300                   ; runtime.printstring at compiler.go:1
   0x2034:  addq   $0x10, %rsp
   0x2038:  ret
   0x2039:  addb   %al, (%rax)
   0x203b:  addb   %al, (%rax)
   0x203d:  addb   %al, (%rax)
(lldb) quit
Quitting LLDB will kill one or more processes. Do you really want to proceed: [Y/n] y
g%

Fixes #7070.

LGTM=iant
R=golang-codereviews, iant
CC=golang-codereviews
https://golang.org/cl/93510043
2014-05-20 11:35:20 -04:00
Shenghou Ma
661298358c cmd/ld: abort if (32-bit) address relocation is negative on amd64.
Update #7980
This CL make the linker abort for the example program. For Go 1.4,
we need to find a general way to handle large memory model programs.

LGTM=dave, josharian, iant
R=iant, dave, josharian
CC=golang-codereviews
https://golang.org/cl/91500046
2014-05-19 22:39:42 -04:00
Alex Brainman
cf78f96244 cmd/ld: correct pe section number in symbol table
Update #7899

LGTM=iant
R=golang-codereviews, rsc, iant
CC=golang-codereviews
https://golang.org/cl/97920044
2014-05-06 11:40:43 +10:00
Alex Brainman
80e7f97206 cmd/ld: correct addresses in windows pe symbol table
This should have been part of 36eb4a62fbb6,
but I later discovered that addresses are all wrong.
Appropriate test added now.

LGTM=r
R=golang-codereviews, r
CC=golang-codereviews
https://golang.org/cl/89470043
2014-04-21 19:28:02 +10:00
Shenghou Ma
d31d19765b runtime, cmd/ld, cmd/5l, run.bash: enable external linking on FreeBSD/ARM.
Update #7331

LGTM=dave, iant
R=golang-codereviews, dave, gobot, iant
CC=golang-codereviews
https://golang.org/cl/89520043
2014-04-21 00:08:59 -04: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
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
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
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
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
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
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
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
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
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