aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/ld
AgeCommit message (Collapse)Author
2015-03-01cmd/5l etc: replace C code with Go codeRuss Cox
mv cmd/new5l cmd/5l and so on. Minimal changes to cmd/dist and cmd/go to keep things building. More can be deleted in followup CLs. Change-Id: I1449eca7654ce2580d1f413a56dc4a75f3d4618b Reviewed-on: https://go-review.googlesource.com/6361 Reviewed-by: Rob Pike <r@golang.org>
2015-03-01cmd/ld: clean for c2goRuss Cox
Change-Id: Iaab2be9a1919f2fa9dbc61a5b7fbf99bcd0712a9 Reviewed-on: https://go-review.googlesource.com/6332 Reviewed-by: Rob Pike <r@golang.org> Reviewed-by: Minux Ma <minux@golang.org>
2015-02-26liblink: delete unused codeRuss Cox
Liblink is still needed for the linker (for a bit longer) but mostly not. Delete the unused parts. Change-Id: Ie63a7c1520dee52b17425b384943cd16262d36e3 Reviewed-on: https://go-review.googlesource.com/6110 Reviewed-by: Rob Pike <r@golang.org> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2015-02-23[dev.cc] all: merge master (48469a2) into dev.ccRuss Cox
Change-Id: I10f7950d173b302151f2a31daebce297b4306ebe
2015-02-23cmd/ld: fix warning on Plan 9David du Colombier
cpp: src/cmd/ld/lib.h:349 No newline at end of file Change-Id: Id21851963f7778364ba9337da3bacd312443f51f Reviewed-on: https://go-review.googlesource.com/5520 Reviewed-by: Minux Ma <minux@golang.org>
2015-02-20[dev.cc] all: merge master (5868ce3) into dev.ccRuss Cox
This time for sure! Change-Id: I7e7ea24edb7c2f711489e162fb97237a87533089
2015-02-17[dev.cc] cmd/gc, cmd/ld, runtime: minor tweaks for c2goRuss Cox
Change-Id: I3be69a4ebf300ad24b55b5f43fd7ad1f001c762e Reviewed-on: https://go-review.googlesource.com/4838 Reviewed-by: Rob Pike <r@golang.org>
2015-02-13cmd/ld: always mark tlsg STLSBSSDavid Crawshaw
Android apps build again. Defining TLSG in runtime/tls_arm.s gives it the type SNOPTRBSS, so its type was never being set when GOOS=android. I considered modifying the if statement, but I no longer understand the intention of the original change (in d738c6b0cad). We were always setting it before, what platform is this not valid for? Fixes #9829 Change-Id: I3eaa4a9590893eff67695797eb22547a170cdbcd Reviewed-on: https://go-review.googlesource.com/4834 Reviewed-by: Minux Ma <minux@golang.org> Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com> Run-TryBot: David Crawshaw <crawshaw@golang.org>
2015-02-13cmd/ld: set alignment for the .rel.plt section on 32-bit architecturesShenghou Ma
Fixes #9802. Change-Id: I22c52a37bdb23a14cc4615c9519431bb14ca81ca Reviewed-on: https://go-review.googlesource.com/4170 Reviewed-by: Ian Lance Taylor <iant@golang.org>
2015-02-13cmd/ld: make cmd/ld a real libraryRuss Cox
Make cmd/ld a real library invoked by the individual linkers. There are no reverse symbol references anymore (symbols referred to in cmd/ld but defined in cmd/5l etc). This means that in principle we could do an automatic conversion of these to Go, as a stopgap until cmd/link is done or as a replacement for cmd/link. Change-Id: I4a94570257a3a7acc31601bfe0fad9dea0aea054 Reviewed-on: https://go-review.googlesource.com/4649 Reviewed-by: Rob Pike <r@golang.org>
2015-02-10runtime: don't put container symbols in functabKeith Randall
Container symbols shouldn't be considered as functions in the functab. Having them present probably messes up function lookup, as you might get the descriptor of the container instead of the descriptor of the actual function on the stack. It also messed up the findfunctab because these entries caused off-by-one errors in how functab entries were counted. Normal code is not affected - it only changes (& hopefully fixes) the behavior for libraries linked as a unit, like: net runtime/cgo runtime/race Fixes #9804 Change-Id: I81e036e897571ac96567d59e1f1d7f058ca75e85 Reviewed-on: https://go-review.googlesource.com/4290 Reviewed-by: Russ Cox <rsc@golang.org>
2015-02-06cmd/ld: restore .debug_gdb_script section after runtime reorganizationShenghou Ma
On some systems, gdb refuses to load Python plugin from arbitrary paths, so we have to add $GOROOT/src/runtime to auto-load-safe-path in the gdb script test. Change-Id: Icc44baab8d04a65bd21ceac2ab8ddb13c8d083e8 Reviewed-on: https://go-review.googlesource.com/2905 Reviewed-by: Ian Lance Taylor <iant@golang.org> Reviewed-by: Josh Bleecher Snyder <josharian@gmail.com>
2015-02-06liblink, cmd/ld, cmd/5l: darwin/arm supportShenghou Ma
liblink: - set dummy value for ctxt->tlsoffset. cmd/ld: - always do external linking when using cgo on darwin/arm, as our linker might not generate codesign-compatible binary. cmd/5l: - support generate ARM Mach-O binaries - add machoreloc1() that translate our internal relocation to macho relocations used by external linking. Change-Id: Ic5454aeb87009aaf8f1453ec7fe33e6da55d5f06 Reviewed-on: https://go-review.googlesource.com/3273 Reviewed-by: David Crawshaw <crawshaw@golang.org>
2015-02-06liblink, cmd/ld, runtime: set the type of runtime.tlsg in runtimeShenghou Ma
In the old code, liblink, cmd/ld and runtime all have code determine whether runtime.tlsg is an actual variable or a placeholder for TLS relocation. This change consolidate them into one: the runtime/tls_arm.s will ultimately determine the type of that variable. Change-Id: I3b3f80791a1db4c2b7318f81a115972cd2237e43 Reviewed-on: https://go-review.googlesource.com/2118 Reviewed-by: David Crawshaw <crawshaw@golang.org> Reviewed-by: Dave Cheney <dave@cheney.net>
2015-02-05cmd/ld: always set timestamp in PE header to 0Shenghou Ma
Fixes #9756. Change-Id: If4ee6fe10f8f90294ff9c5e7480371494094b111 Signed-off-by: Shenghou Ma <minux@golang.org> Reviewed-on: https://go-review.googlesource.com/3740 Reviewed-by: Ian Lance Taylor <iant@golang.org> Reviewed-by: Alex Brainman <alex.brainman@gmail.com>
2015-01-30cmd/gc, cmd/ld, liblink: update for portable Prog, Addr changesRuss Cox
Change-Id: Ia6f8badca56565b9df80c8dbe28c47f6cf7e653f Reviewed-on: https://go-review.googlesource.com/3515 Reviewed-by: Austin Clements <austin@google.com> Reviewed-by: Aram Hăvărneanu <aram@mgk.ro>
2015-01-22cmd/ld: s/specificaly/specifically/ in commentMichael Matloob
Change-Id: I849b8046daaec97ae631d59f1870cd5f1cd72f22 Reviewed-on: https://go-review.googlesource.com/3176 Reviewed-by: Minux Ma <minux@golang.org>
2015-01-07runtime: faster version of findfuncKeith Randall
Use a lookup table to find the function which contains a pc. It is faster than the old binary search. findfunc is used primarily for stack copying and garbage collection. benchmark old ns/op new ns/op delta BenchmarkStackCopy 294746596 255400980 -13.35% (findfunc is one of several tasks done by stack copy, the findfunc time itself is about 2.5x faster.) The lookup table is built at link time. The table grows the binary size by about 0.5% of the text segment. We impose a lower limit of 16 bytes on any function, which should not have much of an impact. (The real constraint required is <=256 functions in every 4096 bytes, but 16 bytes/function is easier to implement.) Change-Id: Ic315b7a2c83e1f7203cd2a50e5d21a822e18fdca Reviewed-on: https://go-review.googlesource.com/2097 Reviewed-by: Russ Cox <rsc@golang.org>
2015-01-07cmd/9l: support internal linkingAustin Clements
This implements the ELF relocations and dynamic linking tables necessary to support internal linking on ppc64. It also marks ppc64le ELF files as ABI v2; failing to do this doesn't seem to confuse the loader, but it does confuse libbfd (and hence gdb, objdump, etc). Change-Id: I559dddf89b39052e1b6288a4dd5e72693b5355e4 Reviewed-on: https://go-review.googlesource.com/2006 Reviewed-by: Russ Cox <rsc@golang.org>
2015-01-07cmd/ld: support for relocation variantsAustin Clements
Most ppc64 relocations come in six or more variants where the basic relocation formula is the same, but which bits of the computed value are installed where changes. Introduce the concept of "variants" for internal relocations to support this. Since this applies to architecture-independent relocation types like R_PCREL, we do this in relocsym. Currently there is only an identity variant. A later CL that adds support for ppc64 ELF relocations will introduce more. Change-Id: I0c5f0e7dbe5beece79cd24fe36267d37c52f1a0c Reviewed-on: https://go-review.googlesource.com/2005 Reviewed-by: Russ Cox <rsc@golang.org>
2015-01-07cmd/ld: support 2 byte relocationsAustin Clements
ppc64 has a bunch of these. Change-Id: I3b93ed2bae378322a8dec036b1681e520b56ff53 Reviewed-on: https://go-review.googlesource.com/2003 Reviewed-by: Russ Cox <rsc@golang.org> Reviewed-by: Minux Ma <minux@golang.org>
2015-01-07cmd/ld: decode local entry offset from ppc64 symbolsAustin Clements
ppc64 function symbols have both a global entry point and a local entry point, where the difference is stashed in sym.other. We'll need this information to generate calls to ELF ABI functions. Change-Id: Ibe343923f56801de7ebec29946c79690a9ffde57 Reviewed-on: https://go-review.googlesource.com/2002 Reviewed-by: Russ Cox <rsc@golang.org> Reviewed-by: Minux Ma <minux@golang.org>
2015-01-05Revert "liblink, cmd/ld, runtime: remove stackguard1"Russ Cox
This reverts commit ab0535ae3fb45ba734d47542cc4845f27f708d1b. I think it will remain useful to distinguish code that must run on a system stack from code that can run on either stack, even if that distinction is no longer based on the implementation language. That is, I expect to add a //go:systemstack comment that, in terms of the old implementation, tells the compiler, to pretend this function was written in C. Change-Id: I33d2ebb2f99ae12496484c6ec8ed07233d693275 Reviewed-on: https://go-review.googlesource.com/2275 Reviewed-by: Russ Cox <rsc@golang.org>
2014-12-29liblink, cmd/ld, runtime: remove stackguard1Shenghou Ma
Now that we've removed all the C code in runtime and the C compilers, there is no need to have a separate stackguard field to check for C code on Go stack. Remove field g.stackguard1 and rename g.stackguard0 to g.stackguard. Adjust liblink and cmd/ld as necessary. Change-Id: I54e75db5a93d783e86af5ff1a6cd497d669d8d33 Reviewed-on: https://go-review.googlesource.com/2144 Reviewed-by: Keith Randall <khr@golang.org>
2014-12-26cmd/ld: put .bss from external objects into real .bss sectionShenghou Ma
Fixes #9359. Change-Id: Iba62935b5a14de23d914f433a09a40417d7e88ed Signed-off-by: Shenghou Ma <minux@golang.org> Reviewed-on: https://go-review.googlesource.com/1889 Reviewed-by: Russ Cox <rsc@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org>
2014-12-22cmd/ld: add a text generation passAustin Clements
This will be used by ppc64 to add call stubs to the .text section. ARM needs a similar pass to generate veneers for arm->thumb transitions. Change-Id: Iaee74036e60643a56fab15b564718f359c5910eb Reviewed-on: https://go-review.googlesource.com/2004 Reviewed-by: Russ Cox <rsc@golang.org>
2014-12-22runtime: hashmap: move overflow pointer to end of bucketKeith Randall
Pointers to zero-sized values may end up pointing to the next object in memory, and possibly off the end of a span. This can cause memory leaks and/or confuse the garbage collector. By putting the overflow pointer at the end of the bucket, we make sure that pointers to any zero-sized keys or values don't accidentally point to the next object in memory. fixes #9384 Change-Id: I5d434df176984cb0210b4d0195dd106d6eb28f73 Reviewed-on: https://go-review.googlesource.com/1869 Reviewed-by: Russ Cox <rsc@golang.org>
2014-12-22cmd/ld: clean up nested if when loading bind local symsAustin Clements
Change-Id: I15269722ca3d2654a9dd7a3f8a89ad375dc9bee0 Reviewed-on: https://go-review.googlesource.com/1759 Reviewed-by: Russ Cox <rsc@golang.org>
2014-12-18cmd/ld: add fallthrough commentAustin Clements
Change-Id: Ia6739c164575751a63cc0d4d41d1f6887fbbaee3 Reviewed-on: https://go-review.googlesource.com/1803 Reviewed-by: Minux Ma <minux@golang.org>
2014-12-18cmd/ld: set ELF ABI version for ppc64xAustin Clements
On ppc64, there are three ELF ABI versions an ELF file can request. Previously, we used 0, which means "unspecified". On our test machines, this meant to use the default (v1 for big endian and v2 for little endian), but apparently some systems can pick the wrong ABI if neither is requested. Leaving this as 0 also confuses libbfd, which confuses gdb, objdump, etc. Fix these problems by specifying ABI v1 for big endian and v2 for little endian. Change-Id: I4d3d5478f37f11baab3681a07daff3da55802322 Reviewed-on: https://go-review.googlesource.com/1800 Reviewed-by: Minux Ma <minux@golang.org>
2014-12-05all: power64 is now ppc64Russ Cox
Fixes #8654. LGTM=austin R=austin CC=golang-codereviews https://golang.org/cl/180600043
2014-12-05[dev.cc] cmd/ld: finalize linkmode before determining whether to import ↵Shenghou Ma
runtime/cgo Frankly, I don't understand how the current code could possibly work except when every android program is using cgo. Discovered this while working on the iOS port. LGTM=crawshaw, rsc R=rsc, crawshaw CC=golang-codereviews https://golang.org/cl/177470043
2014-10-22[dev.power64] all: merge default into dev.power64Austin Clements
This brings dev.power64 up-to-date with the current tip of default. go_bootstrap is still panicking with a bad defer when initializing the runtime (even on amd64). LGTM=rsc R=rsc CC=golang-codereviews https://golang.org/cl/152570049
2014-10-22build: merge the great pkg/ rename into dev.power64Austin Clements
This also removes pkg/runtime/traceback_lr.c, which was ported to Go in an earlier commit and then moved to runtime/traceback.go. Reviewer: rsc@golang.org rsc: LGTM
2014-10-22[dev.power64] build: merge default into dev.power64Austin Clements
LGTM=rsc R=rsc CC=golang-codereviews https://golang.org/cl/160200044
2014-10-21cmd/ld: fix addstrdata for big-endian systemsIan Lance Taylor
LGTM=rsc R=minux, rsc CC=golang-codereviews https://golang.org/cl/158280043
2014-10-20cmd/cgo: disable clang's integrated assemblerDave Cheney
Fixes #8348. Clang's internal assembler (introduced by default in clang 3.4) understands the .arch directive, but doesn't change the default value of -march. This causes the build to fail when we use BLX (armv5 and above) when clang is compiled for the default armv4t architecture (which appears to be the default on all the distros I've used). This is probably a clang bug, so work around it for the time being by disabling the integrated assembler when compiling the cgo assembly shim. This CL also includes a small change to ldelf.c which was required as clang 3.4 and above generate more weird symtab entries. LGTM=iant R=golang-codereviews, iant CC=golang-codereviews https://golang.org/cl/156430044
2014-10-11cmd/ld: do not assume that only pe section names start with '.'Alex Brainman
Our current pe object reader assumes that every symbol starting with '.' is section. It appeared to be true, until now gcc 4.9.1 generates some symbols with '.' at the front. Change that logic to check other symbol fields in addition to checking for '.'. I am not an expert here, but it seems reasonable to me. Added test, but it is only good, if tested with gcc 4.9.1. Otherwise the test PASSes regardless. Fixes #8811. Fixes #8856. LGTM=jfrederich, iant, stephen.gutekanst R=golang-codereviews, jfrederich, stephen.gutekanst, iant CC=alex.brainman, golang-codereviews https://golang.org/cl/152410043
2014-10-11cmd/ld: correct pe section names if longer then 8 charsAlex Brainman
gcc 4.9.1 generates pe sections with names longer then 8 charters. From IMAGE_SECTION_HEADER definition: Name An 8-byte, null-padded UTF-8 string. There is no terminating null character if the string is exactly eight characters long. For longer names, this member contains a forward slash (/) followed by an ASCII representation of a decimal number that is an offset into the string table. Our current pe object file reader does not read string table when section names starts with /. Do that, so (issue 8811 example) c:\go\path\src\isssue8811>go build # isssue8811 isssue8811/glfw(.text): isssue8811/glfw(/76): not defined isssue8811/glfw(.text): undefined: isssue8811/glfw(/76) becomes c:\go\path\src\isssue8811>go build # isssue8811 isssue8811/glfw(.text): isssue8811/glfw(.rdata$.refptr._glfwInitialized): not defined isssue8811/glfw(.text): undefined: isssue8811/glfw(.rdata$.refptr._glfwInitialized) Small progress to Update #8811 LGTM=iant, jfrederich R=golang-codereviews, iant, jfrederich CC=golang-codereviews https://golang.org/cl/154210044
2014-10-10cmd/ld: fix off-by-one error when emitting symbol namesShenghou Ma
I diffed the output of `nm -n gofmt' before and after this change, and verified that all changes are correct and all corrupted symbol names are fixed. Fixes #8906. LGTM=iant, cookieo9 R=golang-codereviews, iant, cookieo9 CC=golang-codereviews https://golang.org/cl/159750043
2014-10-08cmd/ld: don't add line number info for the final address of an FDEIan Lance Taylor
This makes dwardump --verify happy. Update #8846 LGTM=r R=golang-codereviews, r CC=golang-codereviews https://golang.org/cl/150370043
2014-10-07runtime: remove type-punning for Type.gc[0], gc[1]Russ Cox
Depending on flags&KindGCProg, gc[0] and gc[1] are either pointers or inlined bitmap bits. That's not compatible with a precise garbage collector: it needs to be always pointers or never pointers. Change the inlined bitmap case to store a pointer to an out-of-line bitmap in gc[0]. The out-of-line bitmaps are dedup'ed, so that for example all pointer types share the same out-of-line bitmap. Fixes #8864. LGTM=r R=golang-codereviews, dvyukov, r CC=golang-codereviews, iant, khr, rlh https://golang.org/cl/155820043
2014-10-06cmd/ld: ignore .Linfo_stringNN variables in clang .o filesRuss Cox
http://build.golang.org/log/c7a91b6eac8f8daa2bd17801be273e58403a15f2 # cmd/pprof /linux-386-clang-9115aad1dc4a/go/pkg/linux_386/net.a(_all.o): sym#16: ignoring .Linfo_string0 in section 16 (type 0) /linux-386-clang-9115aad1dc4a/go/pkg/linux_386/net.a(_all.o): sym#17: ignoring .Linfo_string1 in section 16 (type 0) /linux-386-clang-9115aad1dc4a/go/pkg/linux_386/net.a(_all.o): sym#18: ignoring .Linfo_string2 in section 16 (type 0) /linux-386-clang-9115aad1dc4a/go/pkg/linux_386/net.a(_all.o): sym#20: ignoring .Linfo_string0 in section 16 (type 0) /linux-386-clang-9115aad1dc4a/go/pkg/linux_386/net.a(_all.o): sym#21: ignoring .Linfo_string1 in section 16 (type 0) ... I don't know what these are. Let's ignore them and see if we get any further. TBR=iant CC=golang-codereviews https://golang.org/cl/155030043
2014-09-29undo CL 141840043 / 65e21380cb2aBrad Fitzpatrick
Unnecessary; covered by https://golang.org/cl/141690043 Verified by jonathan@titanous.com on golang-dev. ««« original CL description cmd/ld: close outfile before cleanup This prevents the temporary directory from being leaked when the linker is run on a FUSE filesystem. Fixes #8684. LGTM=bradfitz R=golang-codereviews, rsc, bradfitz CC=golang-codereviews https://golang.org/cl/141840043 »»» LGTM=jonathan, iant R=iant, jonathan CC=golang-codereviews https://golang.org/cl/150250045
2014-09-29cmd/ld: close outfile before cleanupJonathan Rudenberg
This prevents the temporary directory from being leaked when the linker is run on a FUSE filesystem. Fixes #8684. LGTM=bradfitz R=golang-codereviews, rsc, bradfitz CC=golang-codereviews https://golang.org/cl/141840043
2014-09-28cmd/ld: don't automatically mark symbols created by -X as reachableIan Lance Taylor
This fixes the bug in which the linker reports "missing Go type information" when a -X option refers to a symbol that is not used. Fixes #8821. LGTM=rsc R=rsc, r CC=golang-codereviews https://golang.org/cl/151000043
2014-09-26cmd/go: display program name when reporting crashRuss Cox
Fix by atom (from CL 89190044), comment and test by me. Fixes #6823. LGTM=crawshaw R=golang-codereviews, crawshaw CC=0xe2.0x9a.0x9b, adg, golang-codereviews, iant, r https://golang.org/cl/148180043
2014-09-24build: fix elf buildsRuss Cox
Corrections due to new strict type rules for data+bss. Also disable misc/cgo/cdefstest since you can't compile C code anymore. TBR=iant CC=golang-codereviews https://golang.org/cl/148050044
2014-09-24cmd/cc, cmd/ld, runtime: disallow conservative data/bss objectsRuss Cox
In linker, refuse to write conservative (array of pointers) as the garbage collection type for any variable in the data/bss GC program. In the linker, attach the Go type to an already-read C declaration during dedup. This gives us Go types for C globals for free as long as the cmd/dist-generated Go code contains the declaration. (Most runtime C declarations have a corresponding Go declaration. Both are bss declarations and so the linker dedups them.) In cmd/dist, add a few more C files to the auto-Go-declaration list in order to get Go type information for the C declarations into the linker. In C compiler, mark all non-pointer-containing global declarations and all string data as NOPTR. This allows them to exist in C files without any corresponding Go declaration. Count C function pointers as "non-pointer-containing", since we have no heap-allocated C functions. In runtime, add NOPTR to the remaining pointer-containing declarations, none of which refer to Go heap objects. In runtime, also move os.Args and syscall.envs data into runtime-owned variables. Otherwise, in programs that do not import os or syscall, the runtime variables named os.Args and syscall.envs will be missing type information. I believe that this CL eliminates the final source of conservative GC scanning in non-SWIG Go programs, and therefore... Fixes #909. LGTM=iant R=iant CC=golang-codereviews https://golang.org/cl/149770043
2014-09-18lib9, cmd/ld: fixes for cross-linking on a Windows hostIan Lance Taylor
This fixes a couple of problems that occur when the linker removes its temporary directory on Windows. The linker only creates and removes a temporary directory when doing external linking. Windows does not yet support external linking. Therefore, these problems are only seen when using a cross-compiler hosted on Windows. In lib9, FindFirstFileW returns just the file name, not the full path name. Don't assume that we will find a slash. Changed the code to work either way just in case. In ld, Windows requires that files be closed before they are removed, so close the output file before we might try to remove it. Fixes #8723. LGTM=alex.brainman R=golang-codereviews, alex.brainman CC=golang-codereviews https://golang.org/cl/141690043