aboutsummaryrefslogtreecommitdiff
path: root/libgo/runtime
AgeCommit message (Collapse)AuthorFilesLines
2019-05-31runtime: drop unused C type reflection codeIan Lance Taylor3-170/+0
In particular, drop __go_type_descriptors_equal, which is no longer used, and will be made obsolete by CL 179598. Reviewed-on: https://go-review.googlesource.com/c/gofrontend/+/179858 From-SVN: r271823
2019-05-31compiler: optimize append of makeIan Lance Taylor1-9/+15
The gc compiler recognizes append(s, make([]T, n)...), and generates code to directly zero the tail instead of allocating a new slice and copying. This CL lets the Go frontend do basically the same. The difficulty is that at the point we handle append, there may already be temporaries introduced (e.g. in order_evaluations), which makes it hard to find the append-of-make pattern. The compiler could "see through" the value of a temporary, but it is only safe to do if the temporary is not assigned multiple times. For this, we add tracking of assignments and uses for temporaries. This also helps in optimizing non-escape slice make. We already optimize non-escape slice make with constant len/cap to stack allocation. But it failed to handle things like f(make([]T, n)) (where the slice doesn't escape and n is constant), because of the temporary. With tracking of temporary assignments and uses, it can handle this now as well. Reviewed-on: https://go-review.googlesource.com/c/gofrontend/+/179597 From-SVN: r271822
2019-05-31runtime: implement cheaper context switch on Linux/AMD64Ian Lance Taylor3-19/+103
Currently, goroutine switches are implemented with libc getcontext/setcontext functions, which saves/restores the machine register states and also the signal context. This does more than what we need, and performs an expensive syscall. This CL implements a simplified version of getcontext/setcontext, in assembly, that only saves/restores the necessary part, i.e. the callee-save registers, and the PC, SP. A simplified version of makecontext, written in C, is also added. Currently this is only implemented on Linux/AMD64. Reviewed-on: https://go-review.googlesource.com/c/gofrontend/+/178298 From-SVN: r271818
2019-05-14libgo: reduce overhead for memory/block/mutex profilingIan Lance Taylor3-7/+75
Revise the gccgo version of memory/block/mutex profiling to reduce runtime overhead. The main change is to collect raw stack traces while the profile is on line, then post-process the stacks just prior to the point where we are ready to use the final product. Memory profiling (at a very low sampling rate) is enabled by default, and the overhead of the symbolization / DWARF-reading from backtrace_full was slowing things down relative to the main Go runtime. Reviewed-on: https://go-review.googlesource.com/c/gofrontend/+/171497 From-SVN: r271172
2019-05-11runtime: set up g earlyIan Lance Taylor3-0/+4
runtime.throw needs a g to work properly. Set up g early, to ensure that if something goes wrong in the runtime startup (e.g. runtime.check fails), the program terminates in a reasonable way. Reviewed-on: https://go-review.googlesource.com/c/gofrontend/+/176657 From-SVN: r271088
2019-05-08runtime: use builtin memmove directlyCherry Zhang1-16/+0
We can use the intrinsic memmove directly, without going through C. Reviewed-on: https://go-review.googlesource.com/c/gofrontend/+/170004 * go-gcc.cc (Gcc_backend::Gcc_backend): Define memmove builtin. From-SVN: r271016
2019-05-01compiler,runtime: do more direct interfacesIan Lance Taylor1-1/+1
A direct interface is an interface whose data word contains the actual data value, instead of a pointer to it. The gc toolchain creates a direct interface if the value is pointer shaped, that includes pointers (including unsafe.Pointer), functions, channels, maps, and structs and arrays containing a single pointer-shaped field. In gccgo, we only do this for pointers. This CL unifies direct interface types with gc. This reduces allocations when converting such types to interfaces. Our method functions used to always take pointer receivers, to make interface calls easy. Now for direct interface types, their value methods will take value receivers. For a pointer to those types, when converted to interface, the interface data contains the pointer. For that interface to call a value method, it will need a wrapper method that dereference the pointer and invokes the value method. The wrapper method, instead of the actual one, is put into the itable of the pointer type. In the runtime, adjust funcPC for the new layout of interfaces of functions. Reviewed-on: https://go-review.googlesource.com/c/gofrontend/+/168409 From-SVN: r270779
2019-04-24re PR target/89093 (C++ exception handling clobbers d8 VFP register)Ian Lance Taylor1-1/+4
PR target/89093 runtime: mark unwind functions general-regs-only on ARM For https://gcc.gnu.org/PR89093. Change-Id: Ic426b43d633c77104bda01d4e7835bc9ab4695ef Reviewed-on: https://go-review.googlesource.com/c/gofrontend/+/173657 Reviewed-by: Ian Lance Taylor <iant@golang.org> From-SVN: r270542
2019-03-19libgo: fix build on AIXIan Lance Taylor1-0/+4
Since aix/ppc64 has been added to GC toolchain, a mix between new and old files were created in gcc toolchain. This commit corrects this merge for aix/ppc64 and aix/ppc. Reviewed-on: https://go-review.googlesource.com/c/gofrontend/+/167658 From-SVN: r269797
2019-02-19runtime: abort stack scan in cases that we cannot unwind the stackIan Lance Taylor1-16/+46
In signal-triggered stack scan, if the signal is delivered at certain bad time (e.g. in vdso, or in the middle of setcontext?), the unwinder may not be able to unwind the whole stack, while it still reports _URC_END_OF_STACK. So we cannot rely on _URC_END_OF_STACK to tell if it successfully scanned the stack. Instead, we check the last Go frame to see it actually reached the end of the stack. For Go-created stack, this is runtime.kickoff. For C-created stack, we need to record the outermost Go frame when it enters the Go side. Also we cannot unwind the stack if the signal is delivered in the middle of runtime.gogo, halfway through a goroutine switch, where the g and the stack don't match. Give up in this case as well. Reviewed-on: https://go-review.googlesource.com/c/159098 From-SVN: r269018
2019-02-15compiler,runtime: use __builtin_dwarf_cfa for getcallerspCherry Zhang1-1/+1
Currently, the compiler lowers runtime.getcallersp to __builtin_frame_address(1). In the C side of the runtime, getcallersp is defined as __builtin_frame_address(0). They don't match. Further, neither of them actually returns the caller's SP. On AMD64, __builtin_frame_address(0) just returns the frame pointer. __builtin_frame_address(1) returns the memory content where the frame pointer points to, which is typically the caller's frame pointer but can also be garbage if the frame pointer is not enabled. This CL changes it to use __builtin_dwarf_cfa(), which returns the caller's SP at the call site. This matches the SP we get from unwinding the stack. Currently getcallersp is not used for anything real. It will be used for precise stack scan (a new version of CL 159098). Reviewed-on: https://go-review.googlesource.com/c/162905 * go-gcc.cc (Gcc_backend::Gcc_backend): Define __builtin_dwarf_cfa instead of __builtin_frame_address. From-SVN: r268952
2019-02-15runtime: include <syscall.h> and <sys/syscall.h> if availableIan Lance Taylor1-0/+6
Fixes Solaris build. Reviewed-on: https://go-review.googlesource.com/c/162885 From-SVN: r268940
2019-02-15runtime: add type cast for non-split-stack calls to scanstackblockIan Lance Taylor1-4/+4
Reviewed-on: https://go-review.googlesource.com/c/162884 From-SVN: r268939
2019-02-15compiler, runtime: harmonize types referenced by both C and GoIan Lance Taylor9-15/+27
Compiling with LTO revealed a number of cases in the runtime and standard library where C and Go disagreed about the type of an object or function (or where Go and code generated by the compiler disagreed). In all cases the underlying representation was the same (e.g., uintptr vs. void*), so this wasn't causing actual problems, but it did result in a number of annoying warnings when compiling with LTO. Reviewed-on: https://go-review.googlesource.com/c/160700 From-SVN: r268923
2019-02-01runtime: add getproccount for hurdIan Lance Taylor1-0/+16
Patch by Svante Signell. Reviewed-on: https://go-review.googlesource.com/c/160825 From-SVN: r268463
2019-02-01libgo: add hurd build tagsIan Lance Taylor1-1/+1
Patch by Svante Signell. Reviewed-on: https://go-review.googlesource.com/c/160822 From-SVN: r268459
2019-02-01runtime, sync: use __atomic intrinsics instead of __syncIan Lance Taylor2-176/+1
GCC has supported the __atomic intrinsics since 4.7. They are better than the __sync intrinsics in that they specify a memory model and, more importantly for our purposes, they are reliably implemented either in the compiler or in libatomic. Fixes https://gcc.gnu.org/PR52084 Reviewed-on: https://go-review.googlesource.com/c/160820 From-SVN: r268458
2019-01-29runtime: use the call instruction's PC for panic-in-runtime detectionIan Lance Taylor1-1/+1
If a panic happens in the runtime we turn that into a fatal error. We use the caller's PC to determine if the panic call is inside the runtime. getcallerpc returns the PC immediately after the call instruction. If the call is the very last instruction of a function, it may not find this PC belong to a runtime function, giving false result. We need to back off the PC by 1 to the call instruction. The gc runtime doesn't do this because the gc compiler always emit an instruction following a panic call, presumably an UNDEF instruction which turns into an architecture-specific illegal instruction. Our compiler doesn't do this. Reviewed-on: https://go-review.googlesource.com/c/159437 From-SVN: r268358
2019-01-21libgo: fix building, and some testing, on SolarisIan Lance Taylor1-0/+122
Restore some of the fixes that were applied to golang_org/x/net/lif but were lost when 1.12 moved the directory to internal/x/net/lif. Add support for reading /proc to fetch argc/argv/env for c-archive mode. Reviewed-on: https://go-review.googlesource.com/c/158640 From-SVN: r268130
2019-01-18libgo: update to Go1.12beta2Ian Lance Taylor1-1/+1
Reviewed-on: https://go-review.googlesource.com/c/158019 gotools/: * Makefile.am (go_cmd_vet_files): Update for Go1.12beta2 release. (GOTOOLS_TEST_TIMEOUT): Increase to 600. (check-runtime): Export LD_LIBRARY_PATH before computing GOARCH and GOOS. (check-vet): Copy golang.org/x/tools into check-vet-dir. * Makefile.in: Regenerate. gcc/testsuite/: * go.go-torture/execute/names-1.go: Stop using debug/xcoff, which is no longer externally visible. From-SVN: r268084
2019-01-07runtime: in doscanstackswitch, set gp->m before gogoIan Lance Taylor1-6/+7
This is following CL 156038. doscanstackswitch uses the same mechanism of switching goroutines as getTraceback, and so has the same problem as described in issue golang/go#29448. This CL applies the same fix. Reviewed-on: https://go-review.googlesource.com/c/156697 From-SVN: r267661
2019-01-07runtime: in getTraceback, set gp->m before gogoIan Lance Taylor1-6/+7
Currently, when collecting a traceback for another goroutine, getTraceback calls gogo(gp) switching to gp, which will resume in mcall, which will call gtraceback, which will set up gp->m. There is a gap between setting the current running g to gp and setting gp->m. If a profiling signal arrives in between, sigtramp will see a non-nil gp with a nil m, and will seg fault. Fix this by setting up gp->m first. Fixes golang/go#29448. Reviewed-on: https://go-review.googlesource.com/c/156038 From-SVN: r267658
2019-01-05runtime: prevent deadlock when profiling signal arrives during tracebackIan Lance Taylor2-2/+9
Traceback routines, e.g. callers and funcentry, may call __go_get_backtrace_state. If a profiling signal arrives while we are in the critical section of __go_get_backtrace_state, it tries to do a traceback, which also calls __go_get_backtrace_state, which tries to enter the same critical section and will deadlock. Prevent this deadlock by setting up runtime_in_callers before calling __go_get_backtrace_state. Found while investigating golang/go#29448. Will add a test in the next CL. Updates golang/go#29448. Reviewed-on: https://go-review.googlesource.com/c/156037 From-SVN: r267590
2018-12-29runtime: prevent deadlock when profiling signal arrives in stack scanIan Lance Taylor3-4/+12
Precise stack scan needs to unwind the stack. When it is unwinding the stack, if a profiling signal arrives, which also does a traceback, it may deadlock in dl_iterate_phdr. Prevent this deadlock by setting up runtime_in_callers before traceback. Reviewed-on: https://go-review.googlesource.com/c/155766 From-SVN: r267457
2018-12-27runtime: let ARM32 EABI personality function continue unwind when called ↵Ian Lance Taylor1-0/+3
from traceback On ARM32 EABI, unlike other platforms, the personality function is called during _Unwind_Backtrace (libgcc/unwind-arm-common.inc:581). In this case, simply unwind the frame without returning any handlers. Otherwise traceback will loop if there is a frame with a defer on stack. Reviewed-on: https://go-review.googlesource.com/c/155759 From-SVN: r267434
2018-12-27runtime: on ARM32 EABI, don't get LSDA if compact model is usedIan Lance Taylor1-0/+11
On ARM32 EABI, when the "compact" unwinding model is used, it does not have standard LSDA and _Unwind_GetLanguageSpecificData will not return data that is parseable by us. Check this conditon before calling _Unwind_GetLanguageSpecificData. Fix ARM32 build. Reviewed-on: https://go-review.googlesource.com/c/155758 From-SVN: r267428
2018-12-12runtime: handle DW_EH_PE_absptr in type table encodingIan Lance Taylor1-0/+2
The type table encoding can be DW_EH_PE_absptr, but this case was missing, which was causing abort on ARM32 EABI. Add the missing case. Reviewed-on: https://go-review.googlesource.com/c/153857 From-SVN: r267070
2018-12-11runtime: use _URC_FAILURE on ARM32Ian Lance Taylor1-2/+8
ARM32 EABI unwinder does not define _URC_NORMAL_STOP. Instead, it has _URC_FAILURE. Use _URC_FAILURE there. Should fix ARM32 build. Reviewed-on: https://go-review.googlesource.com/c/153417 From-SVN: r267033
2018-12-05runtime: add precise stack scan supportIan Lance Taylor4-14/+355
This CL adds support of precise stack scan using stack maps to the runtime. The stack maps are generated by the compiler (if supported). Each safepoint is associated with a (real or dummy) landing pad, and its "type info" in the exception table is a pointer to the stack map. When a stack is scanned, the stack map is found by the stack unwinding code by inspecting the exception table (LSDA). For precise stack scan we need to unwind the stack. There are three cases: - If a goroutine is scanning its own stack, it can unwind the stack and scan the frames. - If a goroutine is scanning another, stopped, goroutine, it cannot directly unwind the target stack. We handle this by switching (runtime.gogo) to the target g, letting it unwind and scan the stack, and switch back. - If we are scanning a goroutine that is blocked in a syscall, we send a signal to the target goroutine's thread, and let the signal handler unwind and scan the stack. Extra care is needed as this races with enter/exit syscall. Currently this is only implemented on linux. Reviewed-on: https://go-review.googlesource.com/c/140518 From-SVN: r266832
2018-10-01runtime: add arm64 version of AES hash codeIan Lance Taylor1-2/+401
Rewrite the arm64 AES hashing code from gc assembler to C code using intrinsics. The resulting code generates the same hash code for the same input as the gc code--that doesn't matter as such, but testing it ensures that the C code does something useful. Reviewed-on: https://go-review.googlesource.com/138535 From-SVN: r264771
2018-09-24libgo: update to Go 1.11Ian Lance Taylor5-18/+47
Reviewed-on: https://go-review.googlesource.com/136435 gotools/: * Makefile.am (mostlyclean-local): Run chmod on check-go-dir to make sure it is writable. (check-go-tools): Likewise. (check-vet): Copy internal/objabi to check-vet-dir. * Makefile.in: Rebuild. From-SVN: r264546
2018-09-13runtime: avoid write barriers with traceback infoIan Lance Taylor1-5/+5
Unlike the gc runtime, libgo stores traceback information in location structs, which contain strings. Therefore, copying location structs around appears to require write barriers, although in fact write barriers are never important because the strings are never allocated in Go memory. They come from libbacktrace. Some of the generated write barriers come at times when write barriers are not permitted. For example, exitsyscall, marked nowritebarrierrec, calls exitsyscallfast which calls traceGoSysExit which calls traceEvent which calls traceStackID which calls trace.stackTab.put which copies location values into memory allocated by tab.newStack. This write barrier can be invoked when there is no p, causing a crash. This change fixes the problem by ensuring that location values are copied around in the tracing code with no write barriers. This was found by fixing the compiler to fully implement //go:nowritebarrierrec; CL to follow. Reviewed-on: https://go-review.googlesource.com/134226 From-SVN: r264282
2018-08-24runtime: remove the dummy arg of getcallerspIan Lance Taylor2-15/+13
This is a port of https://golang.org/cl/109596 to the gofrontend, in preparation for updating libgo to 1.11. Original CL description: getcallersp is intrinsified, and so the dummy arg is no longer needed. Remove it, as well as a few dummy args that are solely to feed getcallersp. Reviewed-on: https://go-review.googlesource.com/131116 From-SVN: r263840
2018-06-28runtime: don't stat a NULL filenameIan Lance Taylor1-1/+1
Noticed in https://gcc.gnu.org/PR86331. Reviewed-on: https://go-review.googlesource.com/121417 From-SVN: r262234
2018-06-23runtime: use #ifdef instead of #if for USING_SPLIT_STACKIan Lance Taylor1-3/+3
USING_SPLIT_STACK is configured as defined/undefined, not 0/1. Most of the places test USING_SPLIT_STACK with #ifdef, with a few exceptions. This CL fixes the exceptions. Reviewed-on: https://go-review.googlesource.com/120596 From-SVN: r261980
2018-05-04libgo: fix for unaligned read in go-unwind.c's read_encoded_value()Ian Lance Taylor1-11/+43
Change code to work properly reading unaligned data on architectures that don't support unaliged reads. This fixes a regression (broke Solaris/sparc) introduced in https://golang.org/cl/90235. Reviewed-on: https://go-review.googlesource.com/111296 From-SVN: r259935
2018-05-02libgo: break dependence on libgcc unwind-pe.hIan Lance Taylor1-2/+165
The C portion of the Go runtime includes the header "unwind-pe.h" from libgcc, which contains some constants and a few small routines for decoding pointer values within unwind info. This patch gets rid of that include and instead adds a re-implementation of that functionality in the single file that uses it. The intent is to allow the C runtime portion of libgo to be built without a companion GCC installation. Reviewed-on: https://go-review.googlesource.com/90235 From-SVN: r259861
2018-03-07runtime: use a fence instruction before rdtscIan Lance Taylor1-4/+55
This implements the same choices made in the gc runtime, except that for 32-bit x86 we only use the fence instruction if the processor supports SSE2. The code here is hacked up for speed; the gc runtime uses straight assembler. Reviewed-on: https://go-review.googlesource.com/97715 From-SVN: r258336
2018-02-22runtime: funcfileline: get missing function name from symbol tableIan Lance Taylor3-13/+23
Copy the idea of https://golang.org/cl/92756 to funcfileline, which is used by runtime.FuncForPC, runtime.(*Frames).Next, and others. Reviewed-on: https://go-review.googlesource.com/96175 From-SVN: r257913
2018-02-08runtime: get missing function name from symbol tableIan Lance Taylor1-2/+30
If we trace back through code that has no debug info, as when calling through C code compiled with -g0, we won't have a function name. Try to fetch the function name using the symbol table. Adding the test case revealed that gotest failed to use the gccgo tag when matching files, so add that. Reviewed-on: https://go-review.googlesource.com/92756 From-SVN: r257495
2018-02-02runtime: scan register backing store on ia64Ian Lance Taylor3-0/+39
On ia64, a separate stack is used for saving/restoring register frames, occupying the other end of the stack mapping. This must also be scanned for pointers into the heap. Reviewed-on: https://go-review.googlesource.com/85276 From-SVN: r257323
2018-01-31runtime: fix type descriptor name in C codeIan Lance Taylor1-3/+5
I forgot to update the name of the map[string]bool type descriptor used in go-fieldtrack.c. This didn't cause any errors because it's a weak symbol, and the current testsuite has no field tracking tests. Reviewed-on: https://go-review.googlesource.com/91096 From-SVN: r257249
2018-01-24compiler: rationalize external symbol namesIan Lance Taylor2-11/+12
Encode all external symbol names using only ASCII alphanumeric characters, underscore, and dot. Use a scheme that can be reliably demangled to a somewhat readable version as described in the long comment in names.cc. A minor cleanup discovered during this was that we were treating function types as different if one had a NULL parameters_ field and another has a non-NULL parameters_ field that has no parameters. This worked because we mangled them slightly differently. We now mangle them the same, so we treat them as equal, as we should anyhow. Reviewed-on: https://go-review.googlesource.com/89555 * go.go-torture/execute/names-1.go: New test. From-SVN: r257033
2018-01-10re PR c/82922 (Request: add -Wstrict-prototypes to -Wextra as K&R style is ↵Ian Lance Taylor4-9/+5
obsolescent) PR c/82922 runtime, syscall: use full prototypes in C code Based on patch by Martin Sebor. Reviewed-on: https://go-review.googlesource.com/86815 From-SVN: r256437
2018-01-10runtime: fix makemap calls in __go_construct_mapIan Lance Taylor1-3/+3
The signature of makemap changed with the update to 1.10beta1, but I forgot to update the call from C code. Reviewed-on: https://go-review.googlesource.com/87135 From-SVN: r256431
2018-01-09libgo: update to Go1.10beta1Ian Lance Taylor4-20/+61
Update the Go library to the 1.10beta1 release. Requires a few changes to the compiler for modifications to the map runtime code, and to handle some nowritebarrier cases in the runtime. Reviewed-on: https://go-review.googlesource.com/86455 gotools/: * Makefile.am (go_cmd_vet_files): New variable. (go_cmd_buildid_files, go_cmd_test2json_files): New variables. (s-zdefaultcc): Change from constants to functions. (noinst_PROGRAMS): Add vet, buildid, and test2json. (cgo$(EXEEXT)): Link against $(LIBGOTOOL). (vet$(EXEEXT)): New target. (buildid$(EXEEXT)): New target. (test2json$(EXEEXT)): New target. (install-exec-local): Install all $(noinst_PROGRAMS). (uninstall-local): Uninstasll all $(noinst_PROGRAMS). (check-go-tool): Depend on $(noinst_PROGRAMS). Copy down objabi.go. (check-runtime): Depend on $(noinst_PROGRAMS). (check-cgo-test, check-carchive-test): Likewise. (check-vet): New target. (check): Depend on check-vet. Look at cmd_vet-testlog. (.PHONY): Add check-vet. * Makefile.in: Rebuild. From-SVN: r256365
2017-11-09sync/atomic, runtime/internal/atomic: don't assume reads from 0 failIan Lance Taylor1-0/+2
For a misaligned address force a panic rather than assuming that reading from the address 0 will cause one. Reviewed-on: https://go-review.googlesource.com/69850 From-SVN: r254610
2017-10-11runtime: fix issues on AIX about uintptr(_t)Ian Lance Taylor2-2/+2
Reviewed-on: https://go-review.googlesource.com/69891 From-SVN: r253664
2017-09-18runtime: always initialize str field in __go_string_slice resultIan Lance Taylor1-4/+7
Reviewed-on: https://go-review.googlesource.com/64110 From-SVN: r252953
2017-09-14libgo: update to go1.9Ian Lance Taylor4-61/+37
Reviewed-on: https://go-review.googlesource.com/63753 From-SVN: r252767