aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/ld/macho.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>
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>
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-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-08-07[dev.power64] cmd/ld: update for power64Shenghou Ma
LGTM=rsc R=rsc, iant CC=golang-codereviews https://golang.org/cl/121380043
2014-03-21cmd/ld: fix warnings on Plan 9David du Colombier
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-14cmd/gc: replace '·' as '.' in ELF/Mach-O symbol tablesShenghou Ma
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
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-03-19cmd/ld: generate relocated DWARF in hostobj modeRuss Cox
While we're here, downgrade DWARF to version 2. We're not using any version 3 features, and OS X gdb only supports version 2. Fixes #3436. R=golang-dev, minux.ma CC=golang-dev https://golang.org/cl/7891044
2013-03-11cmd/ld: darwin support for host linkingRuss Cox
R=ken2 CC=golang-dev https://golang.org/cl/7626045
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-10cmd/ld: include full symbol table in Mach-O outputRuss Cox
This makes binaries work with OS X nm. R=ken2 CC=golang-dev https://golang.org/cl/7558044
2013-03-10cmd/ld: make mach-o sections match internal sectionsRuss Cox
This brings Mach-O generation more in line with ELF generation. Having separate sections for the symtab and pclntab mean that we can find them that way, instead of using the deprecated debug segments. (And the host linker will keep separate sections for us, but probably not the debug segments.) R=ken2 CC=golang-dev https://golang.org/cl/7688043
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
2012-01-23ld: fix Mach-O code signing for non-cgo binariesMikkel Krautz
R=golang-dev, rsc CC=golang-dev https://golang.org/cl/5561060
2011-10-18ld: modify macho linkedit segment to enable OS X code signingMikkel Krautz
Move string table to the end of the __LINKEDIT segment. This change allows Apple's codesign(1) utility to successfully sign Go binaries, as long as they don't contain DWARF data (-w flag to 8l/6l). This is because codesign(1) expects the string table to be the last part of the file. R=golang-dev, rsc CC=golang-dev https://golang.org/cl/5271050
2011-10-186l, 8l: emit macho dwarf info before linkedit sectionMikkel Krautz
R=golang-dev, rsc CC=golang-dev https://golang.org/cl/5272050
2011-07-18ld: allow seek within write bufferRuss Cox
Reduces number of write+seek's from 88516 to 2080 when linking godoc with 6l. Thanks to Alex Brainman for pointing out the many small writes. R=golang-dev, r, alex.brainman, robert.hencke CC=golang-dev https://golang.org/cl/4743043
2011-05-246l, 8l: fix Mach-O binaries with many dynamic librariesRuss Cox
R=ken2 CC=golang-dev https://golang.org/cl/4529084
2011-04-25ld: fix 6l -d on Mac, diagnose invalid use of -dRuss Cox
R=r CC=golang-dev https://golang.org/cl/4430064
2011-04-20ld: remove MachoLoad limitRuss Cox
Fixes #1571. R=ken2 CC=golang-dev https://golang.org/cl/4443052
2011-02-18ld: drop rpathRuss Cox
Was required by old cgo but we don't generate stub .so files anymore. Update #1527. R=iant CC=golang-dev https://golang.org/cl/4168056
2011-01-11ld: Fix exported dynamic symbols on Mach-O.Ian Lance Taylor
* Avoid confusion between imported and exported symbols. * Record number of imported and exported symbols correctly. * Explictly relocate SMACHOSYM section, since it is not in datap. R=rsc CC=golang-dev https://golang.org/cl/3920042
2010-12-086l, 8l: support for linking ELF and Mach-O .o filesRuss Cox
More support for references to dynamic symbols, including full GOT and PLT for ELF objects. For Mach-O everything ends up in the GOT: dealing with the real lazy PLT is too hard for now so we punt. R=iant, iant2 CC=golang-dev https://golang.org/cl/3491042
2010-10-225l, 6l, 8l: introduce sub-symbolsRuss Cox
Sub-symbols are laid out inside a larger symbol but can be addressed directly. Use to make Mach-O pointer array not a special case. Will use later to describe ELF sections. Glimpses of the beginning of ELF loading. R=ken2 CC=golang-dev https://golang.org/cl/2623043
2010-10-195l, 6l, 8l: link pclntab and symtab as ordinary rodata symbolsRuss Cox
That is, move the pc/ln table and the symbol table into the read-only data segment. This eliminates the need for a special load command to map the symbol table into memory, which makes the information available on systems that couldn't handle the magic load to 0x99000000, like NaCl and ARM QEMU and Linux without config_highmem=y. It also eliminates an #ifdef and some clumsy code to find the symbol table on Windows. The bad news is that the binary appears to be bigger than it used to be. This is not actually the case, though: the same amount of data is being mapped into memory as before, and the tables are still read-only, so they're still shared across multiple instances of the binary as they were before. The difference is just that the tables aren't squirreled away in some section that "size" doesn't know to look at. This is a checkpoint. It probably breaks Windows and breaks NaCl more than it used to be broken, but those will be fixed. The logic involving -s needs to be revisited too. Fixes #871. R=ken2 CC=golang-dev https://golang.org/cl/2587041
2010-10-195l, 6l, 8l: separate pass to fix addressesRuss Cox
Lay out code before data. R=ken2 CC=golang-dev https://golang.org/cl/2490043
2010-10-145l, 6l, 8l: accumulate data image during importRuss Cox
Using explicit relocations internally, we can represent the data for a particular symbol as an initialized block of memory instead of a linked list of ADATA instructions. The real goal here is to be able to hand off some of the relocations to the dynamic linker when interacting with system libraries, but a pleasant side effect is that the memory image is much more compact than the ADATA list, so the linkers use less memory. R=ken2 CC=golang-dev https://golang.org/cl/2512041
2010-10-135l, 6l, 8l: first pass cleanupRuss Cox
* Maintain Sym* list for text with individual prog lists instead of using one huge list and overloading p->pcond. * Comment what each file is for. * Move some output code from span.c to asm.c. * Move profiling into prof.c, symbol table into symtab.c. * Move mkfwd to ld/lib.c. * Throw away dhog dynamic loading code. * Throw away Alef become. * Fix printing of WORD instructions in 5l -a. Goal here is to be able to handle each piece of text or data as a separate piece, both to make it easier to load the occasional .o file and also to make it possible to split the work across multiple threads. R=ken2, r, ken3 CC=golang-dev https://golang.org/cl/2335043
2010-10-126l: work with OS X nm/otoolJim McGrath
6l was skipping emitting the (2 byte) symbol table if there were no imported or exported symbols. You can't just drop the symbol table entirely - the linker dies if you have a linkedit section but no table. You can omit the linkedit section or both the linkedit and the dlyd parts in the right circumstances, but that seems much more risky to me. R=rsc CC=golang-dev https://golang.org/cl/2421042
2010-10-116l: correct offset for __nl_symbol_ptr in Mach-O.Jim McGrath
Fixes malformed object message from nm etc. Fixes #1180. R=golang-dev, rsc CC=golang-dev https://golang.org/cl/2390042
2010-10-116l: fix Mach-O LC_RPATHJim McGrath
Fixes #1177. R=golang-dev, rsc CC=golang-dev https://golang.org/cl/2387042
2010-09-28various: appease the ubuntu gcc monsterRuss Cox
Silence warnings about not checking return values from read and write system calls. R=r, r2 CC=golang-dev https://golang.org/cl/2258045
2010-09-14tabsRuss Cox
TBR=lvd CC=golang-dev https://golang.org/cl/2194041
2010-09-126g, 6l, 8g, 8l: move read-only data to text segmentRuss Cox
Changing 5g and 5l too, but it doesn't work yet. R=ken2 CC=golang-dev https://golang.org/cl/2136047
2010-09-016l/8l: emit DWARF in macho.Luuk van Dijk
R=rsc, r, ken2 CC=golang-dev https://golang.org/cl/2128041
2010-06-30cgo: use slash-free relative paths for .so referencesRuss Cox
The Makefile and cgo now rewrite / to _ when creating the path. The .so for gosqlite.googlecode.com/hg/sqlite is named cgo_gosqlite.googlecode.com_hg_sqlite.so, and then 6l and 8l both include a default rpath of $GOROOT/pkg/$GOOS_$GOARCH. This should make it easier to move binaries from one system to another. Fixes #857. R=iant, r CC=golang-dev https://golang.org/cl/1700048
2010-03-25Support #pragma dynexport on OS X.Ian Lance Taylor
R=rsc CC=golang-dev https://golang.org/cl/733041
2010-03-22Rename dynld to dynimport throughout.Ian Lance Taylor
Cgo users will need to rerun cgo. R=rsc CC=golang-dev https://golang.org/cl/692041
2009-10-07factor portable object+library bits out of 5l/6l/8l into ldRuss Cox
R=r DELTA=3214 (904 added, 2260 deleted, 50 changed) OCL=35425 CL=35427
2009-10-038c, 8l dynamic loading support.Russ Cox
better mach binaries. cgo working on darwin+linux amd64+386. eliminated context switches - pi is 30x faster. add libcgo to build. on snow leopard: - non-cgo binaries work; all tests pass. - cgo binaries work on amd64 but not 386. R=r DELTA=2031 (1316 added, 626 deleted, 89 changed) OCL=35264 CL=35304
2009-09-30step toward darwin ffi: factor out macho codeRuss Cox
R=r DELTA=771 (374 added, 287 deleted, 110 changed) OCL=35187 CL=35187