aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/8l/asm.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-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>
2014-12-22cmd/5l,6l,8l: remove bogus dynsym section indexesAustin Clements
Previously, this code generated bogus section indexes for dynamic symbols. It turns out this didn't matter, since we only emit these when generating an executable and in an executable it only matters whether a symbol is defined or undefined, but it leads to perplexing code full of mysterious constants. Unfortunately, this happens too early to put in real section indexes, so just use section index 1 to distinguish the symbol from an undefined symbol. Change-Id: I0e514604bf31f21683598ebd3e020b66acf767ef Reviewed-on: https://go-review.googlesource.com/1720 Reviewed-by: Russ Cox <rsc@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-10-06cmd/8l: accept R_386_GOT32 in push instructionRuss Cox
Fixes #8382. LGTM=iant R=iant CC=golang-codereviews https://golang.org/cl/149540045
2014-08-27cmd/5l, cmd/6l, cmd/8l: fix nacl binary corruption bugRuss Cox
NaCl requires the addition of a 32-byte "halt sled" at the end of the text segment. This means that segtext.len is actually 32 bytes shorter than reality. The computation of the file offset of the end of the data segment did not take this 32 bytes into account, so if len and len+32 rounded up (by 64k) to different values, the symbol table overwrote the last page of the data segment. The last page of the data segment is usually the C .string symbols, which contain the strings used in error prints by the runtime. So when this happens, your program probably crashes, and then when it does, you get binary garbage instead of all the usual prints. The chance of hitting this with a randomly sized text segment is 32 in 65536, or 1 in 2048. If you add or remove ANY code while trying to debug this problem, you're overwhelmingly likely to bump the text segment one way or the other and make the bug disappear. Correct all the computations to use segdata.fileoff+segdata.filelen instead of trying to rederive segdata.fileoff. This fixes the failure during the nacl/amd64p32 build. TBR=iant CC=golang-codereviews https://golang.org/cl/135050043
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-15cmd/ld: use TLS relocations on ELF systems in external linking modeRuss Cox
Fixes #7719. LGTM=iant R=iant CC=golang-codereviews https://golang.org/cl/87760050
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
2014-02-27all: final merge of NaCl treeRuss Cox
This CL replays the following one CL from the rsc-go13nacl repo. This is the last replay CL: after this CL the main repo will have everything the rsc-go13nacl repo did. Changes made to the main repo after the rsc-go13nacl repo branched off probably mean that NaCl doesn't actually work after this CL, but all the code is now moved over and just needs to be redebugged. --- cmd/6l, cmd/8l, cmd/ld: support for Native Client See golang.org/s/go13nacl for design overview. This CL is publicly visible but not CC'ed to golang-dev, to avoid distracting from the preparation of the Go 1.2 release. This CL and the others will be checked into my rsc-go13nacl clone repo for now, and I will send CLs against the main repo early in the Go 1.3 development. R≡khr https://golang.org/cl/15750044 --- LGTM=bradfitz, dave, iant R=dave, bradfitz, iant CC=golang-codereviews https://golang.org/cl/69040044
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-31cmd/8l: add support for dragonfly/386Joel Sing
R=golang-dev, iant CC=golang-dev https://golang.org/cl/13328045
2013-08-31cmd/5l,cmd/6l,cmd/8l: fix dragonflydynld pathJoel Sing
R=golang-dev, bradfitz, dave CC=golang-dev https://golang.org/cl/13225043
2013-08-24cmd/5l,cmd/8l: unbreak arm and 386 linkersJoel Sing
Add dragonflydynld to 5l and 8l so that they compile again. R=golang-dev, bradfitz CC=golang-dev https://golang.org/cl/12739048
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-07-11cmd/ld: place read-only data in non-executable segmentRuss Cox
R=golang-dev, dave, r CC=golang-dev, nigeltao https://golang.org/cl/10713043
2013-03-27cmd/ld: emit TLS relocations during external linkingIan Lance Taylor
This CL was written by rsc. I just tweaked 8l. This CL adds TLS relocation to the ELF .o file we write during external linking, so that the host linker (gcc) can decide the final location of m and g. Similar relocations are not necessary on OS X because we use an alternate program start-time mechanism to acquire thread-local storage. Similar relocations are not necessary on ARM or Plan 9 or Windows because external linking mode is not yet supported on those systems. On almost all ELF systems, the references we use are like %fs:-0x4 or %gs:-0x4, which we write in 6a/8a as -0x4(FS) or -0x4(GS). On Linux/ELF, however, Xen's lack of support for this mode forced us long ago to use a two-instruction sequence: first we load %gs:0x0 into a register r, and then we use -0x4(r). (The ELF program loader arranges that %gs:0x0 contains a regular pointer to that same memory location.) In order to relocate those -0x4(r) references, the linker must know where they are. This CL adds the equivalent notation -0x4(r)(GS*1) for this purpose: it assembles to the same encoding as -0x4(r) but the (GS*1) indicates to the linker that this is one of those thread-local references that needs relocation. Thanks to Elias Naur for reminding me about this missing piece and also for writing the test. R=r CC=golang-dev https://golang.org/cl/7891047
2013-03-19cmd/ld: replace -hostobj with -linkmodeRuss Cox
Still disabled. Need to fix TLS. R=golang-dev, minux.ma, bradfitz CC=golang-dev https://golang.org/cl/7783044
2013-03-11cmd/ld: darwin support for host linkingRuss Cox
R=ken2 CC=golang-dev https://golang.org/cl/7626045
2013-03-10cmd/ld: avoid redundant external relocation calculationsRuss Cox
R=ken2, ken CC=golang-dev https://golang.org/cl/7483045
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-07cmd/6l, cmd/8l: fix BSD buildsRuss Cox
Before this CL, running cd misc/cgo/test go test -c readelf --dyn-syms test.test | grep cgoexp turned up many UNDEF symbols corresponding to symbols actually in the binary but marked only cgo_export_static. Only symbols marked cgo_export_dynamic should be listed in this mode. And if the symbol is going to be listed, it should be listed with its actual address instead of UNDEF. The Linux dynamic linker didn't care about the seemingly missing symbols, but the BSD one did. This CL eliminates the symbols from the dyn-syms table. R=golang-dev TBR=golang-dev CC=golang-dev https://golang.org/cl/7624043
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-11cmd/8l/asm.c: Unused function arguments, suppress warnings.Lucio De Re
R=golang-dev, nigeltao CC=golang-dev https://golang.org/cl/7304069
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-306l/5l: PIC and shared library support for the linkers.Elias Naur
Added the -shared flag to 5l/6l to output a PIC executable with the required dynamic relocations and RIP-relative addressing in machine code. Added dummy support to 8l to avoid compilation errors See also: https://golang.org/cl/6822078 https://golang.org/cl/7064048 and https://groups.google.com/d/topic/golang-nuts/P05BDjLcQ5k/discussion R=rsc, iant CC=golang-dev https://golang.org/cl/6926049
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-12-21cmd/[568]l: do not generate PT_TLS on openbsdJoel Sing
The OpenBSD ld.so(1) does not currently support PT_TLS and refuses to load ELF binaries that contain PT_TLS sections. Do not emit PT_TLS sections - we will handle this appropriately in runtime/cgo instead. R=golang-dev, minux.ma, iant CC=golang-dev https://golang.org/cl/6846064
2012-12-18cmd/5l, cmd/6l, cmd/8l: fix function symbol generation from gcc compiled ↵Shenghou Ma
source code For CL 6853059. R=jsing, rsc CC=golang-dev https://golang.org/cl/6938076
2012-11-13cmd/ld: fix build on elf systemsRuss Cox
TBR=iant CC=golang-dev https://golang.org/cl/6843050
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-10cmd/ld, cmd/6l, cmd/8l: sort exported dynamic symbols for DarwinShenghou Ma
Also corrected cmd/8l's .dynsym handling (differentiate between exported symbols and imported symbols) Fixes #4029. R=golang-dev, rsc CC=golang-dev https://golang.org/cl/6620075
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-09-13ld: add .gcdata and .gcbss sectionsJan Ziak
R=rsc CC=golang-dev https://golang.org/cl/6281048
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-05-23cmd/ld, cmd/6l, cmd/8l, cmd/5l: fix hidden/local symbol import for ELF systemsShenghou Ma
Introduce a newsym() to cmd/lib.c to add a symbol but don't add them to hash table. Introduce a new bit flag SHIDDEN and bit mask SMASK to handle hidden and/or local symbols in ELF symbol tables. Though we still need to order the symbol table entries correctly. Fix for issue 3261 comment #9. For CL 5822049. R=iant, rsc CC=golang-dev https://golang.org/cl/5823055
2012-02-22ld: get symbol table letters rightRuss Cox
Have to assign them before we create the symbol table. ARM debugging. TBR=r CC=golang-dev https://golang.org/cl/5689067
2012-02-21ld: add NOPTRBSS for large, pointer-free uninitialized dataRuss Cox
cc: add #pragma textflag to set it runtime: mark mheap to go into noptr-bss. remove special case in garbage collector Remove the ARM from.flag field created by CL 5687044. The DUPOK flag was already in p->reg, so keep using that. Otherwise test/nilptr.go creates a very large binary. Should fix the arm build. Diagnosed by minux.ma; replacement for CL 5690044. R=golang-dev, minux.ma, r CC=golang-dev https://golang.org/cl/5686060
2012-02-196l, 8l: fix build for ELF systemsShenghou Ma
R=rsc CC=golang-dev https://golang.org/cl/5677095
2012-02-12gc, 8g, 8l: fix a handful of warningsAnthony Martin
8g/cgen.c print format type mismatch 8l/asm.c resoff set and not used gc/pgen.c misleading comparison INT > 0x80000000 gc/reflect.c dalgsym must be static to match forward declaration gc/subr.c assumed_equal set and not used hashmem's second argument is not used gc/walk.c duplicated (unreachable) code R=rsc CC=golang-dev https://golang.org/cl/5651079
2012-01-295l, 6l, 8l, ld: remove memory leaksShenghou Ma
R=golang-dev, rsc CC=golang-dev https://golang.org/cl/5569085
2012-01-226l, 8l: remove unused macro definitionShenghou Ma
Their last use is removed in rev 70ed048caad2. R=golang-dev, r CC=golang-dev https://golang.org/cl/5532115
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-12-12ld/6l/8l: First pass at changes to the linker to support NetBSD binaries.Christopher Nielsen
This will not currently create valid NetBSD binaries because NetBSD requires an ELF note section to run, otherwise the kernel will throw ENOEXEC. I was unable to determine an elegant way to add the section, so I am submitting what I have. References: http://www.netbsd.org/docs/kernel/elf-notes.html http://mail-index.netbsd.org/netbsd-bugs/2001/08/03/0012.html R=rsc CC=golang-dev https://golang.org/cl/5472049
2011-10-185l, 6l, 8l: correct ELFRESERVE diagnosticAnthony Martin
If the length of the interpreter string pushes us over the ELFRESERVE limit, the resulting error message will be comical. I was doing some ELF tinkering with a modified version of 8l when I hit this. To be clear, the stock linkers wouldn't hit this without adding about forty more section headers. We're safe for now. ;) Also, remove a redundant call to cflush. R=golang-dev, rsc CC=golang-dev https://golang.org/cl/5268044
2011-10-186l, 8l: emit macho dwarf info before linkedit sectionMikkel Krautz
R=golang-dev, rsc CC=golang-dev https://golang.org/cl/5272050