aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/ld/ldmacho.c
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-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>
2014-07-22cmd/ld: mark hostobj sections as containing no pointersDmitriy Vyukov
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-04-16liblink, cmd/ld: reenable nosplit checking and testRuss Cox
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-16liblink: fix incorrect hash collision in lookupRuss Cox
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-14liblink: remove arch-specific constants from file formatRuss Cox
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
2013-12-18cmd/6g, cmd/gc, cmd/ld: fix Plan 9 amd64 warningsDavid du Colombier
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-08liblink: create new library based on linker codeRuss Cox
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-09-18cmd/ld: handle duplicate static symbols in COFF and Mach-O files.Shenghou Ma
Fixes #5740. R=iant, rsc, luisbebop CC=gobot, golang-dev https://golang.org/cl/10345046
2013-07-10cmd/ld: correct assignment of sizes to mach-o symbolsRuss Cox
If you compute the size by subtraction from the address of the next symbol, it helps to wait until the symbols have been sorted by address. R=golang-dev, r CC=golang-dev https://golang.org/cl/11143043
2013-04-29cmd/ld: fix some 64-bit issuesRob Pike
A few places in the linker pushed 64-bit values through 32-bit holes, including in relocation. Clean them up, and check for a few other overflows as well. Tests to follow. R=dsymonds CC=gobot, golang-dev https://golang.org/cl/9032043
2013-03-10cmd/ld: replace dynimpname with extnameRuss Cox
Dynimpname was getting too confusing. Replace flag-like checks with tests of s->type. R=ken2 CC=golang-dev https://golang.org/cl/7594046
2013-03-07cmd/ld: host linking support for linux/amd64Russ Cox
Still to do: non-linux and non-amd64. It may work on other ELF-based amd64 systems too, but untested. "go test -ldflags -hostobj $GOROOT/misc/cgo/test" passes. Much may yet change, but this seems a reasonable checkpoint. R=iant CC=golang-dev https://golang.org/cl/7369057
2013-02-28cmd/ld: fix symbol table sortingRuss Cox
runtime: double-check that symbol table is sorted If the symbol table is unsorted, the binary search in findfunc will not find its func, which will make stack traces stop early. When the garbage collector starts using the stack tracer, that would be a serious problem. The unsorted symbol addresses came from from two things: 1. The symbols in an ELF object are not necessarily sorted, so sort them before adding them to the symbol list. 2. The __i686.get_pc_thunk.bx symbol is present in multiple object files and was having its address adjusted multiple times, producing an incorrect address in the symbol table. R=golang-dev, iant CC=golang-dev https://golang.org/cl/7440044
2012-09-20cmd/ld: consistent binary for cgo programsShenghou Ma
We use pkg path instead of file name (which contains $WORK) in section symbols names. R=golang-dev, fullung, rsc, iant CC=golang-dev https://golang.org/cl/6445085
2012-09-02cmd/ld: support zero-filled section for Mach-O filesShenghou Ma
R=golang-dev, r, dave, rsc CC=golang-dev https://golang.org/cl/6492069
2012-08-29cmd/ld: handle a special case of scattered relocation 2/1 on Darwin/386Shenghou Ma
Fixes #1635. R=golang-dev, dave, r CC=golang-dev https://golang.org/cl/6496043
2011-07-25ld: fix build on Plan 9Lucio De Re
ld/data.c: . Format specifier with corresponding cast to cater for all architectures (llux and vlong). ld/ldelf.c: ld/ldmacho.c: . Missing "pn" argument in diag() calls. ld/ldpe.c: . Dropped "sym->sectnum" in diag() call. . Typo in a comment. ld/lib.h: . Added varargck pragma for "O". R=rsc CC=golang-dev https://golang.org/cl/4749042
2011-06-218l: more fixes for Plan 9Lucio De Re
Once these changes are effected, it is possible to construct "8l" native on a (386?) Plan 9 system, albeit with assistance from modules such as mkfiles that are not (yet) included in any public patches. 8l/asm.c: . Corrected some format qualifiers. 8l/list.c: . Cast a print() argument to (int) to match the given format. It may be possible to change the format (%R), but I have not looked into it. 8l/obj.c: . Removed some unused code. 8l/span.c: . Removed unnecessary incrementation on "bp". . Corrected some format qualifiers. ld/data.c: . Corrected some format qualifiers. . Cast print argument to (int): used as field size. . Use braces to suppress warning about empty if() statements. ld/dwarf.c: . Trivial spelling mistake in comment. ld/ldelf.c: . Added USED() statements to silence warnings. . Dropped redundant address (&) operators. . corrected some format qualifiers. . Cast to (int) for switch selection variable. ld/macho.c: . Added USED() statements to silence warnings. ld/ldpe.c: . Added USED() statements to silence warnings. . More careful use of "sect" variable. . Corrected some format qualifiers. . Removed redundant assignments. . Minor fix dropped as it was submitted separately. ld/pe.c: . Dropped <time.h> which is now in <u.h>. . Dropped redundant address (&) operators. . Added a missing variable initialisation. ld/symtab.c: . Added USED() statements to silence warnings. . Removed redundant incrementation. . Corrected some format qualifiers. All the above have been tested against a (very) recent release and do not seem to trigger any regressions. All review suggestions have been incorporated. R=rsc CC=golang-dev https://golang.org/cl/4633043
2011-04-08ld: fix arm buildRuss Cox
R=ken2 CC=golang-dev, mikkel https://golang.org/cl/4384048
2011-04-07ld: fix Mach-O X86_64_RELOC_SIGNED relocationsMikkel Krautz
Fixes #1658. R=rsc CC=golang-dev https://golang.org/cl/4344066
2011-04-07ld: fix Mach-O bss bugMikkel Krautz
Fixes #1559. R=rsc CC=golang-dev, peterGo, rog https://golang.org/cl/4356046
2011-01-11ld: Permit an Mach-O symbol to be exported in the dynamic symbol table.Ian Lance Taylor
Submitting TBR to fix Darwin build. R=rsc TBR=rsc CC=golang-dev https://golang.org/cl/3912043
2010-12-17ld: ignore stab symbolsRuss Cox
Makes 6l work better on OS X 10.5. Fixes #1352. Fixes #1353. R=r CC=golang-dev https://golang.org/cl/3661042
2010-12-13ld: allow .o files with no symbolsRuss Cox
Don't crash in dwarf for foreign functions. R=ken2 CC=golang-dev https://golang.org/cl/3576043
2010-12-085l (and 6l, 8l, ld): more arm build fixesRuss Cox
R=ken2 CC=golang-dev https://golang.org/cl/3521041
2010-12-08ld: reading of Mach-O object filesRuss Cox
R=iant CC=golang-dev https://golang.org/cl/3431045