aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/ld/elf.h
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-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>
2014-02-09include, linlink, cmd/6l, cmd/ld: part 1 of solaris/amd64 linker changes.Shenghou Ma
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
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-08-24all: compiler/bootstrap for dragonfly/amd64Joel Sing
Add dragonfly/amd64 support to the Go compiler, bootstrap and GOOS list. R=devon.odell, bradfitz CC=golang-dev https://golang.org/cl/12796050
2013-08-14runtime.cmd/ld: Add ARM external linking and implement -shared in terms of ↵Elias Naur
external linking This CL is an aggregate of 10271047, 10499043, 9733044. Descriptions of each follow: 10499043 runtime,cmd/ld: Merge TLS symbols and teach 5l about ARM TLS This CL prepares for external linking support to ARM. The pseudo-symbols runtime.g and runtime.m are merged into a single runtime.tlsgm symbol. When external linking, the offset of a thread local variable is stored at a memory location instead of being embedded into a offset of a ldr instruction. With a single runtime.tlsgm symbol for both g and m, only one such offset is needed. The larger part of this CL moves TLS code from gcc compiled to internally compiled. The TLS code now uses the modern MRC instruction, and 5l is taught about TLS fallbacks in case the instruction is not available or appropriate. 10271047 This CL adds support for -linkmode external to 5l. For 5l itself, use addrel to allow for D_CALL relocations to be handled by the host linker. Of the cases listed in rsc's comment in issue 4069, only case 5 and 63 needed an update. One of the TODO: addrel cases was since replaced, and the rest of the cases are either covered by indirection through addpool (cases with LTO or LFROM flags) or stubs (case 74). The addpool cases are covered because addpool emits AWORD instructions, which in turn are handled by case 11. In the runtime, change the argv argument in the rt0* functions slightly to be a pointer to the argv list, instead of relying on a particular location of argv. 9733044 The -shared flag to 6l outputs a shared library, implemented in Go and callable from non-Go programs such as C. The main part of this CL change the thread local storage model. Go uses the fastest and least general mode, local exec. TLS data in shared libraries normally requires at least the local dynamic mode, however, this CL instead opts for using the initial exec mode. Initial exec mode is faster than local dynamic mode and can be used in linux since the linker has reserved a limited amount of TLS space for performance sensitive TLS code. Initial exec mode requires an extra load from the GOT table to determine the TLS offset. This penalty will not be paid if ld is not in -shared mode, since TLS accesses will be reduced to local exec. The elf sections .init_array and .rela.init_array are added to register the Go runtime entry with cgo at library load time. The "hidden" attribute is added to Cgo functions called from Go, since Go does not generate call through the GOT table, and adding non-GOT relocations for a global function is not supported by gcc. Cgo symbols don't need to be global and avoiding the GOT table is also faster. The changes to 8l are only removes code relevant to the old -shared mode where internal linking was used. This CL only address the low level linker work. It can be submitted by itself, but to be useful, the runtime changes in CL 9738047 is also needed. Design discussion at https://groups.google.com/forum/?fromgroups#!topic/golang-nuts/zmjXkGrEx6Q Fixes #5590. R=rsc CC=golang-dev https://golang.org/cl/12871044
2013-04-30cmd/ld: emit relocs for DWARF info when doing an external linkIan Lance Taylor
I would like opinions on whether this is a good idea for 1.1. On the one hand it's a moderately important issue. On the other hand this introduces at least the possibility of external linker errors due to the additional relocations and it may be better to wait. I'm fairly confident that the behaviour is unchanged when not using an external linker. Update #5221 This CL is tested lightly on 386 and amd64 and fixes the cases I tested. I have not tested it on Darwin or Windows. R=golang-dev, dave, daniel.morsing, rsc CC=golang-dev https://golang.org/cl/8858047
2013-03-10cmd/ld: avoid redundant external relocation calculationsRuss Cox
R=ken2, ken CC=golang-dev https://golang.org/cl/7483045
2013-01-31cmd/ld: support for linking with host linkerRuss Cox
A step toward a fix for issue 4069. To allow linking with arbitrary host object files, add a linker mode that can generate a host object file instead of an executable. Then the host linker can be invoked to generate the final executable. This CL adds a new -hostobj flag that instructs the linker to write a host object file instead of an executable. That is, this works: go tool 6g x.go go tool 6l -hostobj -o x.o x.6 ld -e _rt0_amd64_linux x.o ./a.out as does: go tool 8g x.go go tool 8l -hostld ignored -o x.o x.8 ld -m elf_i386 -e _rt0_386_linux x.o ./a.out Because 5l was never updated to use the standard relocation scheme, it will take more work to get this working on ARM. This is a checkpoint of the basic functionality. It does not work with cgo yet, and cgo is the main reason for the change. The command-line interface will likely change too. The gc linker has other information that needs to be returned to the caller for use when invoking the host linker besides the single object file. R=iant, iant CC=golang-dev https://golang.org/cl/7060044
2013-01-06cmd/ld: move symtab, ELF generation to portable codeRuss Cox
More cleanup in preparation for fixing issue 4069. This CL replaces the three nearly identical copies of the asmb ELF code with a single asmbelf function in elf.c. In addition to the ELF code movement, remove the elfstr array in favor of a simpler lookup, and identify sections by name throughout instead of computing fragile indices. The CL also replaces the three nearly identical copies of the genasmsym code with a single genasmsym function in lib.c. The ARM linker still compiles and generates binaries, but I haven't tested the binaries. They may not work. R=ken2 CC=golang-dev https://golang.org/cl/7062047
2012-10-09cmd/ld: add -B option to set build IDIan Lance Taylor
Background on build ID: http://fedoraproject.org/wiki/RolandMcGrath/BuildID R=rsc CC=golang-dev https://golang.org/cl/6625072
2012-10-08cmd/ld, cmd/5l: support R_ARM_PC24 and R_ARM_JUMP24, fix R_ARM_CALLShenghou Ma
1. R_ARM_CALL can also be used to call a PLT entry 2. add support for R_ARM_PC24 and R_ARM_JUMP24 3. refactor, remove D_PLT32 in favor of D_CALL Fixes #4006. R=rsc, dave CC=fullung, golang-dev https://golang.org/cl/6622057
2012-09-21cmd/{ld,5l,6l,8l}: add support for OpenBSD ELF signaturesJoel Sing
OpenBSD now requires ELF binaries to have a PT_NOTE that identifies it as an OpenBSD binary. Refactor the existing NetBSD ELF signature code and implement support for OpenBSD ELF signatures. R=golang-dev, rsc CC=golang-dev https://golang.org/cl/6489131
2012-08-03cmd/ld: add PT_PAX_FLAGS ELF headerRuss Cox
PAX systems are Linux systems that are more paranoid about memory permissions. These flags tell them to relax when running Go binaries. Fixes #47. R=iant CC=golang-dev https://golang.org/cl/6326054
2012-07-30cmd/5l, cmd/ld: add support for R_ARM_GOT_PRELShenghou Ma
Android NDK's gcc 4.6 generates this relocation for runtime/cgo. R=rsc CC=golang-dev https://golang.org/cl/6450056
2012-05-04cmd/5l, cmd/ld: dynamic linking library supportShenghou Ma
Part 1 of CL 5601044 (cgo: Linux/ARM support) Limitation: doesn't support thumb library yet. R=golang-dev, dave, rsc CC=golang-dev https://golang.org/cl/5991065
2011-12-205l/6l/8l: add support for netbsd signature note sectionJoel Sing
R=m4dh4tt3r, jsing, rsc CC=golang-dev https://golang.org/cl/5493068
2011-06-21nacl, tiny: remove vestigesRobert Hencke
R=golang-dev, r, rsc CC=golang-dev https://golang.org/cl/4635053
2011-06-14build: fix header files for Plan 9Lucio De Re
The "elf.h" header changes involve only comments, the released Plan 9 C preprocessing function does not cope with multiline comments following the #define keyword. All multiline comments have been moved to the line above the associated definition. Sigh! Fixing the Plan 9 compiler is not an option. <time.h> does not exist in the Plan 9 Native library. I have moved it from src/cmd/ld/pe.h to include/u.h. RSC correctly points out that this copy of <u.h> is not the one used to compile the Go release on Plan 9 platforms. R=golang-dev CC=golang-dev, rsc https://golang.org/cl/4574042
2011-05-115l, 8l: add ELF symbol table to binaryRuss Cox
Should have been added long ago. Thanks to Alex Brainman for noticing. R=ken2 CC=golang-dev https://golang.org/cl/4538046
2011-04-27cgo: handle versioned ELF symbolsRuss Cox
Fixes #1397. R=iant CC=golang-dev https://golang.org/cl/4444064
2011-04-12ld: ELF header function declarations.Lucio De Re
Added "void" inside "()" for two functions. R=golang-dev, r CC=golang-dev https://golang.org/cl/4381056
2010-12-086l, 8l: minor changes & cleanupRuss Cox
R=ken2, ken3 CC=golang-dev https://golang.org/cl/3505041
2010-10-246l/8l: global and local variables and type info.Luuk van Dijk
R=rsc CC=golang-dev https://golang.org/cl/2201044
2010-09-196l, 8l: clean up ELF code, fix NaClRuss Cox
R=r CC=golang-dev https://golang.org/cl/2221042
2010-03-23Add support for #pragma dynexport.Ian Lance Taylor
R=rsc CC=golang-dev https://golang.org/cl/661043
2010-01-13runtime: add demo running Go on raw (emulated) hwRuss Cox
8l: add GOOS=pchw, stop spelling out all the elf numbers. R=r CC=golang-dev https://golang.org/cl/186144
2009-11-18ld: move interpreter string into first block of ELF fileRuss Cox
necessary on freebsd. R=r, dho CC=golang-dev https://golang.org/cl/157069
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
2009-09-24convert 8l to new ELF code.Russ Cox
mostly cut and paste from 6l. R=r DELTA=930 (525 added, 182 deleted, 223 changed) OCL=34976 CL=34976
2009-08-23linker workRuss Cox
* more elf constants from FreeBSD * simple relocation demo R=r DELTA=410 (354 added, 49 deleted, 7 changed) OCL=33689 CL=33729
2009-08-21linker workRuss Cox
* remove now-unused D_SBIG (was for typestrings) * rename elf64.[ch] to elf.[ch] * pull in elf headers from FreeBSD instead of writing our own * emit non-header ELF data in data section * stub out a few more ELF sections needed for dynamic loading R=r DELTA=1928 (1237 added, 635 deleted, 56 changed) OCL=33642 CL=33658