aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/5l/span.c
AgeCommit message (Collapse)Author
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-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-08-08cmd/5c, cmd/5g, cmd/5l: introduce MOVBS and MOVHS instructions.Rémy Oudompheng
MOVBS and MOVHS are defined as duplicates of MOVB and MOVH, and perform sign-extension moving. No change is made to code generation. Update #1837 R=rsc, bradfitz CC=golang-dev https://golang.org/cl/12682043
2013-07-19runtime: use funcdata to supply garbage collection informationRuss Cox
This CL introduces a FUNCDATA number for runtime-specific garbage collection metadata, changes the C and Go compilers to emit that metadata, and changes the runtime to expect it. The old pseudo-instructions that carried this information are gone, as is the linker code to process them. R=golang-dev, dvyukov, cshapiro CC=golang-dev https://golang.org/cl/11406044
2013-07-16cmd/5l, cmd/6l, cmd/8l: accept PCDATA instruction in inputRuss Cox
The portable code in cmd/ld already knows how to process it, we just have to ignore it during code generation. R=ken2 CC=golang-dev https://golang.org/cl/11363043
2013-02-25cmd/gc: emit explicit type information for local variablesRuss Cox
The type information is (and for years has been) included as an extra field in the address chunk of an instruction. Unfortunately, suppose there is a string at a+24(FP) and we have an instruction reading its length. It will say: MOVQ x+32(FP), AX and the type of *that* argument is int (not slice), because it is the length being read. This confuses the picture seen by debuggers and now, worse, by the garbage collector. Instead of attaching the type information to all uses, emit an explicit list of TYPE instructions with the information. The TYPE instructions are no-ops whose only role is to provide an address to attach type information to. For example, this function: func f(x, y, z int) (a, b string) { return } now compiles into: --- prog list "f" --- 0000 (/Users/rsc/x.go:3) TEXT f+0(SB),$0-56 0001 (/Users/rsc/x.go:3) LOCALS , 0002 (/Users/rsc/x.go:3) TYPE x+0(FP){int},$8 0003 (/Users/rsc/x.go:3) TYPE y+8(FP){int},$8 0004 (/Users/rsc/x.go:3) TYPE z+16(FP){int},$8 0005 (/Users/rsc/x.go:3) TYPE a+24(FP){string},$16 0006 (/Users/rsc/x.go:3) TYPE b+40(FP){string},$16 0007 (/Users/rsc/x.go:3) MOVQ $0,b+40(FP) 0008 (/Users/rsc/x.go:3) MOVQ $0,b+48(FP) 0009 (/Users/rsc/x.go:3) MOVQ $0,a+24(FP) 0010 (/Users/rsc/x.go:3) MOVQ $0,a+32(FP) 0011 (/Users/rsc/x.go:4) RET , The { } show the formerly hidden type information. The { } syntax is used when printing from within the gc compiler. It is not accepted by the assemblers. The same type information is now included on global variables: 0055 (/Users/rsc/x.go:15) GLOBL slice+0(SB){[]string},$24(AL*0) This more accurate type information fixes a bug in the garbage collector's precise heap collection. The linker only cares about globals right now, but having the local information should make things a little nicer for Carl in the future. Fixes #4907. R=ken2 CC=golang-dev https://golang.org/cl/7395056
2013-02-21cmd/5g, cmd/5l, cmd/6l, cmd/8l, cmd/gc, cmd/ld, runtime: accurate args and ↵Carl Shapiro
locals information Previously, the func structure contained an inaccurate value for the args member and a 0 value for the locals member. This change populates the func structure with args and locals values computed by the compiler. The number of args was already available in the ATEXT instruction. The number of locals is now passed through in the new ALOCALS instruction. This change also switches the unit of args and locals to be bytes, just like the frame member, instead of 32-bit words. R=golang-dev, bradfitz, cshapiro, dave, rsc CC=golang-dev https://golang.org/cl/7399045
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-11-02cmd/gc, cmd/ld: struct field trackingRuss Cox
This is an experiment in static analysis of Go programs to understand which struct fields a program might use. It is not part of the Go language specification, it must be enabled explicitly when building the toolchain, and it may be removed at any time. After building the toolchain with GOEXPERIMENT=fieldtrack, a specific field can be marked for tracking by including `go:"track"` in the field tag: package pkg type T struct { F int `go:"track"` G int // untracked } To simplify usage, only named struct types can have tracked fields, and only exported fields can be tracked. The implementation works by making each function begin with a sequence of no-op USEFIELD instructions declaring which tracked fields are accessed by a specific function. After the linker's dead code elimination removes unused functions, the fields referred to by the remaining USEFIELD instructions are the ones reported as used by the binary. The -k option to the linker specifies the fully qualified symbol name (such as my/pkg.list) of a string variable that should be initialized with the field tracking information for the program. The field tracking string is a sequence of lines, each terminated by a \n and describing a single tracked field referred to by the program. Each line is made up of one or more tab-separated fields. The first field is the name of the tracked field, fully qualified, as in "my/pkg.T.F". Subsequent fields give a shortest path of reverse references from that field to a global variable or function, corresponding to one way in which the program might reach that field. A common source of false positives in field tracking is types with large method sets, because a reference to the type descriptor carries with it references to all methods. To address this problem, the CL also introduces a comment annotation //go:nointerface that marks an upcoming method declaration as unavailable for use in satisfying interfaces, both statically and dynamically. Such a method is also invisible to package reflect. Again, all of this is disabled by default. It only turns on if you have GOEXPERIMENT=fieldtrack set during make.bash. R=iant, ken CC=golang-dev https://golang.org/cl/6749064
2012-08-07cmd/5l: dwarf line number support for Linux/ARMShenghou Ma
Part of issue 3747. R=dave, lvd, rsc CC=golang-dev https://golang.org/cl/6084044
2012-08-035a, 5l, math: Add support for ABSD, ABSF floating point instructions.Michał Derkacz
R=golang-dev, dave, rsc, minux.ma CC=golang-dev https://golang.org/cl/6225051
2012-06-08cmd/5a, cmd/5l: add MULW{T,B} and MULAW{T,B} support for ARMShenghou Ma
Supported in ARMv5TE and above. Also corrected MULA disassembly listing. R=golang-dev, rsc CC=golang-dev https://golang.org/cl/6265045
2012-06-03cmd/5a, cmd/5l, math: add CLZ instruction for ARMShenghou Ma
Supported in ARMv5 and above. R=golang-dev, rsc CC=golang-dev https://golang.org/cl/6284043
2012-05-30cmd/6l, cmd/8l, cmd/5l: add AUNDEF instructionRuss Cox
On 6l and 8l, this is a real instruction, guaranteed to cause an 'undefined instruction' exception. On 5l, we simulate it as BL to address 0. The plan is to use it as a signal to the linker that this point in the instruction stream cannot be reached (hence the changes to nofollow). This will help the compiler explain that panicindex and friends do not return without having to put a list of these functions in the linker. R=ken2 CC=golang-dev https://golang.org/cl/6255064
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
2012-04-115a, 5l: add PLD (preload data) instructionShenghou Ma
Supported in ARMv5TE and above, excluding ARMv5TExP. For CL 5990066. R=golang-dev, rsc CC=golang-dev https://golang.org/cl/5999044
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
2011-07-20ld: remove overlap of ELF sections on dynamic binariesGustavo Niemeyer
The dynamic ELF sections were pointing to the proper data, but that data was already owned by the rodata and text sections. Some ELF references explicitly prohibit multiple sections from owning the same data, and strip behaves accordingly. The data for these sections was moved out and their ranges are now owned by their respective sections. This change makes strip happy both with and without -s being provided at link time. A test was added in debug/elf to ensure there are no regressions on this area in the future. Fixes #1242. Fixes #2022. NOTE: Tested on Linux amd64/386/arm only. R=rsc CC=golang-dev https://golang.org/cl/4808043
2011-07-195l: fix arm linker bug introduced by 4742041Rob Pike
Should fix the arm build. R=golang-dev, dsymonds, adg CC=golang-dev https://golang.org/cl/4777041
2011-07-155a, 5c, 5l: fix for Plan 9 buildLucio De Re
5a/a.h: . Removed <u.h> and <lib.h>. . Made definition of EOF conditional. 5a/a.y: . Added <u.h> and <lib.h>. 5a/lex.c: . Added <u.h> and <lib.h>. . Dropped <ctype.h> (now in <u.h>). 5c/peep.c: . Removed unnecessary "return 0" statement. 5c/reg.c: . Added compilation condition around unused code. 5c/swt.c: . Removed unused "thestring" argument from Bprint() calls. 5l/asm.c: . Added USED() statements as required. . Adjusted a few format specifications. . Added compilation condition around unused code. 5l/l.h: . Dropped directory prefix from <../5l/5.out.h>. . Added varargck pragma for "I" and "i". 5l/obj.c: . Cascaded consecutive "if" statements. . Dropped unnecessary incrementation and assignments. 5l/pass.c: . Dropped unnecessary assignment. 5l/prof.c: . #if 0 converted to #ifdef NOTDEF. 5l/span.c: . Dropped unnecessary incrementation and assignments. R=golang-dev CC=golang-dev, rsc https://golang.org/cl/4752041
2011-06-095l: delete dead codeRuss Cox
Thumb code and ARM pre-V4 code is unused, unmaintained, and almost certainly wrong by now. Every time I try to change 5l I have to sort out what's dead code and what's not. 30% of lines of code in this directory deleted. R=ken2 CC=golang-dev https://golang.org/cl/4601049
2011-06-09math: add sqrt_arm.s and sqrtGoC.go as fallback to soft fp emulationFan Hongjian
5a: add SQRTF and SQRTD 5l: add ASQRTF and ASQRTD Use ARMv7 VFP VSQRT instruction to speed up math.Sqrt R=rsc, dave, m CC=golang-dev https://golang.org/cl/4551082
2011-05-215l: fix set but not used warningsDave Cheney
R=rsc, iant CC=golang-dev https://golang.org/cl/4538083
2011-05-165l: delete pre-ARMv4 instruction implementationsRuss Cox
Add implementation for addr<->reg short moves. Align large data, for ARM. R=ken2 CC=golang-dev https://golang.org/cl/4545050
2011-02-255a, 5l: add LDREXD, STREXDRuss Cox
R=ken2 CC=golang-dev https://golang.org/cl/4239041
2011-01-13add TST op codeKen Thompson
R=r CC=golang-dev https://golang.org/cl/4000041
2010-11-11last of the arm conversionsKen Thompson
R=rsc CC=golang-dev https://golang.org/cl/3053041
2010-11-03add hardware floating point.Ken Thompson
currently, softfloat does not work and there are some unsigned-to-float conversion errors. R=rsc CC=golang-dev https://golang.org/cl/2886041
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-185l: data-relocatable code layoutRuss Cox
R=ken2 CC=golang-dev https://golang.org/cl/2479043
2010-10-175l: stop using R12 as SBRuss Cox
Because the SB is only good for 8k and Go programs tend to have much more data than that, SB doesn't save very much. A fmt.Printf-based hello world program has 360 kB text segment. Removing SB makes the text 500 bytes (0.14%) longer. R=ken2, r2, ken3 CC=golang-dev https://golang.org/cl/2487042
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-13various: avoid %ld etcRuss Cox
The Plan 9 tools assume that long is 32 bits. We converted all instances of long to int32 when importing the code but missed the print formats. Because int32 is always int on the compilers we use, it is never correct to use %lux, %ld, etc. Convert to %ux, %d, etc. (It matters because on 64-bit gcc, long is 64 bits, so we were printing 32-bit quantities with 64-bit formats.) R=ken2 CC=golang-dev https://golang.org/cl/2491041
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-135l, 6l, 8l: indent, outdentRuss Cox
This is entirely adding and removing tabs. It looks weird but will make the diffs for the next change easier to read. R=ken2 CC=golang-dev https://golang.org/cl/2490041
2010-04-275l, 6l, 8l, runtime: make -s binaries workRuss Cox
5l, 6l, 8l: change ELF header so that strip doesn't destroy binary Fixes #261. R=iant, r CC=golang-dev https://golang.org/cl/994044
2009-10-14LDREX and STREXKai Backman
R=rsc APPROVED=rsc DELTA=30 (30 added, 0 deleted, 0 changed) OCL=35751 CL=35756
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-07-02minor comment and debug flag for dumping all oplooks.Kai Backman
R=rsc APPROVED=rsc DELTA=4 (0 added, 0 deleted, 4 changed) OCL=31016 CL=31126
2009-06-26Adding more debug output when 5l encounters a bad opKai Backman
combination. R=rsc APPROVED=rsc DELTA=69 (68 added, 0 deleted, 1 changed) OCL=30798 CL=30801
2009-06-26more changes to make 5g code generation arm compatible.Kai Backman
R=rsc APPROVED=rsc DELTA=72 (12 added, 52 deleted, 8 changed) OCL=30748 CL=30793
2009-06-16grab bag of changes aimed at getting stack splitting to work:Kai Backman
- morestack support for 5l and arm runtime - argsize support in 5c, 5l, ar and nm. assembly code from 5a will break in interesting ways unless NOSPLIT is specified - explicit cond execution constants - fix 5l output to use %d instead of %ld so that negative values show. - added a lot of code to arm/asm.s. runtime entry code almost working currently aborts at gogo not implemented R=rsc APPROVED=rsc DELTA=305 (125 added, 29 deleted, 151 changed) OCL=30246 CL=30347
2009-03-25This is really two changes in one but given interdependenciesKai Backman
and expected review latency I needed to combine the CLs. 1. Made the 5* toolpath build using the go build system. Hooked the subdirectories to clean.bash but added a separate make5.bash for now. Minor massage to make the code more similar to the current structure of 6c/6a/6l. 2. Change all references from long to int32 in line with similar change for the other toolchains. The end result is that 5c, 5a and 5l can now be compiled and the executables start up properly. Haven't thrown any input at them yet. R=rsc APPROVED=rsc DELTA=1052 (392 added, 328 deleted, 332 changed) OCL=26757 CL=26761
2009-03-135a 5c 5l from inferno distributionKai Backman
R=rsc APPROVED=rsc DELTA=19042 (19042 added, 0 deleted, 0 changed) OCL=26268 CL=26270