Age | Commit message (Collapse) | Author | Files | Lines |
|
We experience CLR crash on some architectures (at least on x86) in case
of unhandled managed exception. libunwind steps to the very end of a
stack, and if .eh_frame info is correct, it returns with retcode 0 and
ip=0 from unw_step, then PAL calls unw_is_signal_frame with
c->validate==0 which in turn dereferences zeroed ip in access_mem.
libunwind spec says that retcode 0 from unw_step means very end of a
stack, so PAL should not expect any frames, signal or not. It should
convert cursor back to SEH representation and return with TRUE.
corresponding PR to dotnet/runtime on upstream:
https://github.com/dotnet/runtime/pull/42620
|
|
* Declare throw only when compiling for c++
Prevent the definition from getting defined multiple times and
map it to throw() only when compiling c++ code.
* Suppress warnings for tests
Suppress:
-Wno-write-strings
-Wno-sign-compare
-Wno-narrowing
-fpermissive
-Wno-int-to-pointer-cast
to allow tests to compile
* Add gcc option to build.sh script
Following clangx.y model add -gccx.y command line
arguments with gcc5 and gcc7 being the currnetly supported
options.
* Allow environment variable to be used for TOOLCHAIN
Remove CLANG specific compiler options as well.
* Hide non-GNU compiler options
* Do not include local directory if cross compiling
[ 0%] Building CXX object src/pal/src/eventprovider/tracepointprovider/CMakeFiles/coreclrtraceptprovider.dir/__/lttng/traceptprovdotnetruntime.cpp.o
cc1plus: error: include location "/usr/local/include" is unsafe for cross-compilation [-Werror=poison-system-directories]
* Suppress unknown pragma warnings
src/pal/src/exception/seh-unwind.cpp:37:0:
warning: ignoring #pragma clang diagnostic [-Wunknown-pragmas]
#pragma clang diagnostic pop
Removing these cause compilation error on clang7 and arm as follows:
In file included from /bin/obj/Linux.arm.Debug/src/pal/src/libunwind/include/libunwind.h:9:
/src/pal/src/libunwind/include/libunwind-arm.h:247:9: error: empty struct has size 0 in C, size 1 in C++ [-Werror,-Wextern-c-compat]
typedef struct unw_tdep_save_loc
^
/src/pal/src/libunwind/include/libunwind-arm.h:288:9: error: empty struct has size 0 in C, size 1 in C++ [-Werror,-Wextern-c-compat]
typedef struct
* plt not useful for GNU and ARM64/ARM
src/pal/src/arch/arm64/callsignalhandlerwrapper.S: Assembler messages:
src/pal/src/arch/arm64/callsignalhandlerwrapper.S:31: Error: unexpected characters following instruction at operand 1 -- `bl signal_handler_worker@plt'
src/pal/src/arch/arm64/callsignalhandlerwrapper.S:32: Error: unexpected characters following instruction at operand 1 -- `bl signal_handler_worker@plt'
* Remove double const from argv in PAL_Initialize
Seeing compilation error with GNU for C source files as follows:
if (PAL_Initialize(argc, argv) != 0)
^
src/pal/tests/palsuite/common/palsuite.h:21:0,
from src/pal/tests/palsuite/c_runtime/asinhf/test1/test1.c:18:
src/pal/inc/pal.h:374:1: note: expected ‘const char * const*’ but argument is of type ‘char **’
* Suppress format warnings using GNU for libunwind
warning: format ‘%li’ expects argument of type ‘long int’, but argument 3 has type ‘int’ [-Wformat=]
Debug (4, " aligned frame, offset %li\n", f->cfa_reg_offset);
* Fix -fpermissive warnings for GNU
* Suppress unused variable warning in libunwind
src/pal/src/libunwind/include/libunwind-aarch64.h:201:5: warning: right-hand operand of comma expression has no effect [-Wunused-value]
#define unw_tdep_getcontext(uc) (({ \
~~~~~~~~~
unw_tdep_context_t *unw_ctx = (uc); \
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
register uint64_t *unw_base asm ("x0") = (uint64_t*) unw_ctx->uc_mcontext.regs; \
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
__asm__ __volatile__ ( \
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
"stp x0, x1, [%[base], #0]\n" \
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
"stp x2, x3, [%[base], #16]\n" \
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
"stp x4, x5, [%[base], #32]\n" \
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
"stp x6, x7, [%[base], #48]\n" \
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
"stp x8, x9, [%[base], #64]\n" \
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
"stp x10, x11, [%[base], #80]\n" \
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
"stp x12, x13, [%[base], #96]\n" \
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
"stp x14, x13, [%[base], #112]\n" \
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
"stp x16, x17, [%[base], #128]\n" \
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
"stp x18, x19, [%[base], #144]\n" \
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
"stp x20, x21, [%[base], #160]\n" \
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
"stp x22, x23, [%[base], #176]\n" \
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
"stp x24, x25, [%[base], #192]\n" \
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
"stp x26, x27, [%[base], #208]\n" \
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
"stp x28, x29, [%[base], #224]\n" \
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
"str x30, [%[base], #240]\n" \
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
"mov x1, sp\n" \
~~~~~~~~~~~~~~~~
"stp x1, x30, [%[base], #248]\n" \
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
: [base] "+r" (unw_base) : : "x1", "memory"); \
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
}), 0)
* Fix warning: ‘memset’ used with length equal to number of elements warning
Fix similar warnings to these by including the element size into total size
calculation.
src/pal/tests/palsuite/miscellaneous/SetEnvironmentVariableW/test1/test.cpp: In function ‘int main(int, char**)’:
src/pal/tests/palsuite/miscellaneous/SetEnvironmentVariableW/test1/test.cpp:89:31: warning: ‘memset’ used with length equal to number of elements without multiplication by element size [-Wmemset-elt-size]
memset(NewValue,0,BUF_SIZE);
* Define CLR specific compiler option CLR_CMAKE_COMPILER
By the time toolchain.cmake is called, the compiler detection from
cmake is not active. We need an intermediate definition to pass
to compiler detection.
|
|
* Abstract away NOINLINE statement
MSVC and GNU compilers use different attributes for noinline.
Abstract away compiler differences.
* Replace __sync_swap with __atomic_exchange_n
__sync_swap doesn't exist on GNU. Replacing with __atomic_exchange_n
which is universally available.
* Define CDECL for GNUC
__cdecl is not defined by default on GNU compilers.
* Define gcc version of __declspec(thread)
* Correct pointer casting
A pointer value is usually unsigned long on most platforms.
Casting it to integer causes signedness issues. Use size_t
to be efficient on all 32 and 64 bit architectures.
* Put quotes around the error string
Correct error statement. GNU G++ is picky about the string
following the error statement with ' character in it. It needs
to be enclosed with double quotes.
* Fix casting problem
Seeing these warnings with GNU G++ compiler
src/pal/src/sync/cs.cpp: In function ‘void CorUnix::InternalInitializeCriticalSectionAndSpinCount(PCRITICAL_SECTION, DWORD, bool)’:
src/pal/src/sync/cs.cpp:630:48: warning: converting to non-pointer type ‘SIZE_T {aka long unsigned int}’ from NULL [-Wconversion-null]
pPalCriticalSection->OwningThread = NULL;
^
src/pal/src/sync/cs.cpp: In function ‘void CorUnix::InternalLeaveCriticalSection(CorUnix::CPalThread*, _CRITICAL_SECTION*)’:
src/pal/src/sync/cs.cpp:880:43: warning: converting to non-pointer type ‘SIZE_T {aka long unsigned int}’ from NULL [-Wconversion-null]
pPalCriticalSection->OwningThread = NULL;
^
* Abstract optnone compiler attribute
GNU compiler doesn't support optnone attribute.
pal/src/exception/seh-unwind.cpp:449:77: warning: ‘optnone’ attribute directive ignored [-Wattributes]
* Set the aligned attribute for GNU compiler
* Make __rotl and __rotr functions portable
GNU compiler doesn't have an intrinsic for these. Open code them
using the provided implementation.
* Define deprecated attribute for gcc
* Add throw specifier for GCC
/usr/include/string.h:43:28: error: declaration of ‘void* memcpy(void*, const void*, size_t) throw ()’ has a different exception specifier
size_t __n) __THROW __nonnull ((1, 2));
|
|
The libunwind cannot unwind from `__libc_start_main` to `_start` on
Linux ARM64 with glibc <= 2.27, because the `__libc_start_main` is
missing unwind info. While we already have a way to detect such case
when the same issue happens for `_start`, we were triggering it only in
case unw_step returned 0. For this case, it returns 1 though, which is
also a valid success indicator.
The result is that .NET core starts spinning infinitely in case an
unhandled exception happens on ARM64.
The fix is to update the check to test for the return value being >= 0.
|
|
* Fix build without libunwind installed
I have removed libunwind dependency in a recent commit, but
it turns out that the build was using incorrect include
paths and it was still depending on the libunwind installation
for the libunwind.h header.
This change fixes it.
* Fix clang warning
The libunwind headers contain two empty structs and clang
issues a warning since the size of such structs is
0 in C and 1 in C++.
This is benign for our purposes, since the affected
structs are not directly used by our code.
|
|
* Add original source of libunwind 1.3-stable
Taken from:
https://github.com/libunwind/libunwind/tree/v1.3-stable
* Enable building of libunwind
This change enables building libunwind and removes
dependency on the libunwind package for all Unixes
except OSX. In OSX the libunwind is part of the OS
and also has support for compact unwind info that
is OSX specific, so we keep using that one.
* Disable warnings in code we don't execute
|
|
Implement out of context stack unwinder
Decode the eh frame info found in the in-memory module image
and pass it back to the remote libunwind8 to do the unwind.
Added remote-unwind.cpp for all the out of context unwind code.
Added an all managed threads option -all the "clrstack" (sos ClrStack).
The IDebugDataTarget4 feature needs to be enabled for OS X.
Add libunwind license notice to third party notices file.
|
|
There is an issue when hardware exception occurs while handling another hardware exception. In such case,
the exception unwinding ends up in an infinite loop. It is caused by the kernel reusing the same location
for signal handler context.
The fix is to use a windows style context local variable in the common_signal_handler that contains
the right context - it is the original signal context converted to windows style context.
|
|
There is an issue when hardware exception occurs while handling another hardware exception. In such case,
the exception unwinding ends up in an infinite loop. It is caused by the kernel reusing the same location
for signal handler context.
The fix is to use the windows style context local variable in the common_signal_handler that contains
the right context - it is the original signal context converted to windows style context.
|
|
|
|
* [Arm64/Unix] Update arm64 *.S files to match *.asm
* [Arm64/Unix] Fix CONTEXTToNativeContext()
* [Arm64/Unix] ThrowExceptionFromContextInternal
* [Arm64/Unix] Preserve x8 argument register
* [ARM64/Unix] Add CFI directives
Add native unwind info
* [Arm64/Unix] Fix RtlRestoreContext
* [Arm64/Unix] Restore FP from CurrentContextPointers
* [Arm64/Unix] fix pointer math
* [Arm64/Unix] Fix CallDescrWorkerInternal personality
* [Arm64/Unix] More Fp fixups
* [Arm64/Unix] CallEHFunclet machine state
Restore non-volatile machine state in CallEHFunclet
* [Arm64/Unix] CallDescrWorkerInternal
Use empty stack slot to save argument
* [Arm64/Unix] RtlVirtualUnwind update pointers
* [Arm64] LazyMachState fixes
* [Arm64/Unix] disable USE_REDIRECT_FOR_GCSTRESS
When FEATURE_PAL is enableds USE_REDIRECT_FOR_GCSTRESS
is not supported
* [Arm64] ClearRegDisplayArgumentAndScratchRegisters()
* [Arm64] Remove unnecesary copy in TransitionFrame
* [Arm64/Unix] Fix comment per review
* [Arm64/Unix] move constants per review
* [Arm64/Unix] Use ldp per review
Also fix indentation
* [Arm64/Unix] Fix indentation per review
* [Arm64/Unix] Remove m_Unwound per review comments
* [Arm64/Unix] Use PREPARE_EXTERNAL_VAR to access globals
* [Arm64/Unix] Fix more whitespace per earlier review comments
|
|
* [x86/Linux] Fix GetCallerSp
* Do NOT pop stack argument for TransitionFrame
* Add ResumeEsp to CONTEXT
|
|
|
|
Fix compile error for x86/Linux
- add ASSIGN_UNWIND_REGS in seh-unwind.cpp for x86
- add CONTEXT_EXCEPTION_ACTIVE in pal.h for x86
- add CONTEXT_XSTATE in pal.h for x86
|
|
This change enables build of CoreCLR on Alpine Linux. Here is the list
of changes:
- Disable asserts checking RSP in arbitrary threads against cached stack limit
for the respective thread. The stack on Alpine obviously grows over the limit
reported by the pthread functions.
- Disable using XSTATE. This should be re-enabled after MUSL gets the _xstate,
_fpx_sw_bytes and related data structures added to the signal.h header.
- Disable setting rlimit of RLIMIT_NOFILE to the max value, since it breaks
debugging for some reason.
- Add skipping over the hardware signal trampoline in the PAL_VirtualUnwind.
While we were not trying to walk over it in a simple case, in a case where
an exception was thrown from a catch handler of a hardware exception, we
still attempted to walk over it and it fails on Alpine.
- Fix detection of Alpine Linux in the PAL's CMakeLists.txt so that it works
in Docker containers too.
- Modified PAL_VirtualUnwind to make the check for unwinding past the bottom
of the stack unconditional. We had a long list of platforms where we were
doing this check and it doesn't hurt to do it on platforms where it is not
needed. I have done that rather than adding a check for Alpine Linux as
another platform that needs it.
|
|
In my previous change that made exceptions smaller, I had `#include <utility>`
and I haven't realized that it pulls in some stl headers. That breaks build
on ARM.
The fix is to replace that include by defining just the std::move that's
all that was needed from the header.
|
|
The PAL_SEHException is quite large due to the fact that it contains context
and exception records. This causes a problem when we try to throw it and
system gets out of memory. The C++ runtime can throw exceptions even in that
case, but only if they are smaller than certain threshold. So in our case,
it just aborts the process.
This change separates the context and exception records from the exception,
which ensures that the above mentioned mechanism in the C++ runtime can
kick in and the exception can be thrown even when malloc fails to allocate
it.
I have also modified HandleHardwareException to return BOOL indicating whether
the execution should continue at the possibly modified exception context
instead of using RtlRestoreContext. In that case, we return all the way back
to the signal handler, update the ucontext in there and return from it.
|
|
This patch fixes regression caused by 597e160 commit.
Previous PAL_VirtualUnwind does not set CONTEXT_UNWOUND_TO_CALL
properly. In this patch, the flag is added for non-signaled exception.
|
|
With recent concrete unwinding/exception handling routines
of coreclr-arm-linux, we no longer need this workaround.
Signed-off-by: MyungJoo Ham <myungjoo.ham@samsung.com>
|
|
This fixes hangs in the runtime observed while running CoreFX managed tests.
Thanks @janvorli and @myungjoo
Fix #4380
|
|
Ranames UpdateUnwindContextWithWinContext as WinContextToUnwindContext,
and revises to invoke WinContextToUnwindContext always.
|
|
There was an unnecessary break between two #ifdef blocks.
This commit merges these blocks into one block.
|
|
Fix #4404
|
|
Libunwind-arm unw_step returns 0 with unchanged PC
if it hits the bottom of the stack.
Thus, seh-unwind.cpp::PAL_VirtualUnwind should
explicitly mark that it has reached the bottom
as it does with ARM64, FreeBSD, or APPLE for
ARM/Linux.
Fix #3859
Signed-off-by: MyungJoo Ham <myungjoo.ham@samsung.com>
|
|
According to https://sourceforge.net/p/predef/wiki/OperatingSystems/
(Pre-defined Compiler Macros) and http://www.faqs.org/docs/Linux-HOWTO/GCC-HOWTO.html
(Porting and compiling:Automatically defined symbols), the __linux__ marcro is the
right way to detect systems based on the Linux kernel and is the POSIX compliant.
Signed-off-by: Geunsik Lim <geunsik.lim@samsung.com>
Signed-off-by: MyungJoo Ham <myungjoo.ham@samsung.com>
|
|
Libunwind-ARM recommends to read LR to get value of PC
while unwinding stack, which often causes the caller
(PAL_VirtualUnwind) to have LSB of PC set.
Such behavior incurs errornous behavior of PAL_VirtualUnwind
if the output is fed back to PAL_VirtualUnwind as the input,
which is observed with VirtualUnwindToFirstManagedCallFrame().
This commit clears LSB of PC in WinContext to prevent it.
Note that this is a partial fix for the issue #3462.
(this does not fix assembly stacks)
Fix #3462
Signed-off-by: MyungJoo Ham <myungjoo.ham@samsung.com>
|
|
Make context information compatible with libunwind-arm.
In Linux/ARM, seh-unwind.cpp has been updating unw_cursor_t
to point another stack by updating the cursor's register
entries. However, that does not work in libunwind-arm in
Linux, which breaks PAL_VirtualUnwind() functions.
Getting the stack information from the cursor had
a compatibility issue as well.
This patch make both "context->cursor" and "cursor->context"
methods compatible with ARM/Linux.
Fix #3312
Signed-off-by: MyungJoo Ham <myungjoo.ham@samsung.com>
|
|
|
|
|
|
ucontext_t
|
|
Enable the module load notification when no module or methods are found.
setclrpath/setsostid print the current path/tid if no arguments. "setsostid -clear"
now clears the tid/os id mapping.
Added better exception hook to sos plugin to catch special CLRN exception. Before
multiple lldb "Exception breakpoints" where set each time bpmd added a new bp. Added
a "DoNotDeleteOrDisable" message to the exception breakpoint created.
Fix bpmd on release builds. RtlpRaiseException was being inlined and the ExceptionRecord
parameter was being optimized away causing the GetLastEventInformation api to failed
and the special CLRN exception to be ignored.
Add sos help support. "soshelp" displays help about a command.
|
|
|
|
|
|
In my recent change that has added the runtime suspension for OSX,
I have also added a fix for the unwind info of the PAL_DispatchExceptionWrapper
function. It turns out that I've made a mistake in the offset in the set_cfa_register
and it has broken hardware exception handling on OSX since the unwinder was not
able to unwind correctly through the wrapper.
It also turns out that the same wrong offset in set_cfa_register is in the
ActivationHelperWrapper.S, but in that function, the unwinding still works correctly.
I've actually verified that with both the wrong and the correct offset, the unwinder
gets the same correct RSP / RBP at the time of the exception. So I believe linked ignored
the DWARF unwind info and used compact unwind info instead that it was able to
derive correctly on its own.
Also, the allocate_stack was incorrectly placed before the set_cfa_register, which again
didn't cause a problem due to the DWARF info being ignored. The issue with this one was
that it updates the CFA, but the CFA offset is relative to RBP at that point and
RBP didn't change.
As an additional fix, there was a problem in PAL_VirtualUnwind that @sergiy-k has
spotted. The return value of the recently added unw_is_signal_frame call was
overwriting the status code returned by the unw_step that we use on OSX to
detect walking out of stack.
|
|
|
|
|
|
Implementation of PAL_VirtualUnwindOutOfProc that uses ptrace libunwind
to be able to unwind native stack in debugee. This allows to get valid managed
stack for threads that passed HelperMethodFrames.
|
|
This change fixes an issue when a null reference exception happens in the first
instruction of the JIT_WriteBarrier. There were two problems.
First problem was that the native unwinder didn't know that it is unwinding a
frame where the PC is an address of a failing instruction instead of the next
address after a call instruction. So it decremented the PC before looking up the
unwind info. Unfortunately, that means that if the hardware exception happens
in the first instruction, the unwind info is not found and the unwinder resorts
to RBP chain unwinding, which effectively skips one managed frame.
The second problem was that the FaultingExceptionFrame we create when handling
the hardware exception had context pointing to the JIT_WriteBarrier. But that
breaks the stack walker. When it arrives at the FaultingExceptionFrame, it
calls its ReturnAddress method and expects to get a managed code address.
However, in this case, it was getting the address of the JIT_WriteBarrier instead
and that made the stack walker to skip to the next explicit frame, effectively
skipping multiple managed frames that it should have reported.
|
|
|
|
|
|
Add unwinding for the ARM Linux platform
|
|
Use PAL_VirtualUnwind on Linux ARM
Add assembler annotation for unwinding
|
|
|
|
c_runtime/vprintf/test1 is disabled as casting NULL to va_list is
against the C specification.
Fix SetFilePointer tests on 32 bit platforms.
Define _FILE_OFFSET_BITS=64 so that we have long file support on 32 bit
platforms.
Implement context capture/restore for ARM.
Link libgcc_s before libunwind on ARM so C++ exceptions work.
Translate armasm to gas syntax.
Specify Thumb, VFPv3, ARMv7 for the ARM target.
Add ARM configuration to mscorlib build
Implement GetLogicalProcessorCacheSizeFromOS in PAL.
Set UNWIND_CONTEXT_IS_UCONTEXT_T from configure check.
|
|
Preallocate JIT notification table on VM side (since ICLRDataTarget2->AllocVirtual isn't implemented under lldb) and implement WriteVirtual on debugger side to allow DAC to write entries.
Used the special set breakpoint on exception throw lldb command to catch the special exception the VM throws when some
thing is jitted. The debugger side finds the exception record by searching for the RtlpRaiseException function on the stack
when the bp is hit. It also assumes that the local variable is called ExceptionRecord.
Fix all the file path separators to use the platform independent defines.
Ifdef all the "/d" options in the supported commands because the / char isn't supported as a command line option and /d is always the DML option that isn't supported either.
Fix problem Prem run into running sos after the process stops.
|
|
Fix error in stack unwinding on FreeBSD as discovered by @saper.
This closes #1102 and #1113
|
|
This change refactors the native context register access to use the
MCREG_xxx macros so that it can compile on FreeBSD too.
|
|
When reaching the bottom of the real stack, OSX does not change the $pc
to 0x0, like llvm libunwind. It returns 0 from unw_step, and leaves the
$pc unchanged, so we will track cur and prev pc and guard for this as well
Fixes Localloc codegen test, and also verified a simple throw from main
works as expected.
|
|
On OSX, the libunwind doesn't have support for getting context pointers.
This change modifies the way GC handles object pointers in registers
so that when the context pointer cannot be obtained, the object is
pinned so that GC doesn't move it and thus doesn't need to update
the object reference in the register value stored on the stack.
|
|
|