On Linux, glibc and musl disagree over the layout of the ucontext_t
structure. For more details, see the musl mailing list:
https://www.openwall.com/lists/musl/2018/02/22/1
Add conditionals to handle both the glibc and musl layout of the
structures.
Closes#709.
Signed-off-by: Ross Burton <ross.burton@arm.com>
As an ELF file can have multiple executable segments, `mapoff` refers to
the file offset of the segment containing the current `ip`. However,
`dwarf_find_unwind_table` was not using this information and instead
selected the *last* encountered executable `PT_LOAD` segment.
This causes `loadoff`, `load_base`, and finally `rti.segbase` to be
calculated incorrectly, resulting in the `.eh_frame_hdr` binary search
reading from invalid memory addresses and returning incorrect unwind
information.
Fix this by selecting the `PT_LOAD` segment whose file offset (`p_offset`)
matches `mapoff`, or the first executable segment if no match is found.
When configure is run with --enable-cxx-exceptions a stray `-lc` has
wandered into the execution path. While it doesn't hurt anything if
gives a disturbing error message.
The MUSL libc setjmp/longjmp handling differs from the GNU libc
setjmp/longjmp handling. It may not be possible to properly support
sigsetjmp/siglongjmp on MUSL libc.
When libunwind is configured to provide the Itanium Level 1 Exception
Support it needs to avoid linking in any compiler runtime libraries that
already provide that support (for example, libgcc_s.so) in order to
avoid duplicate symbols or ODR violations. This caused a problem on
more recent GCC editions because of some dark magic in which
libgcc_s.so is actually a linker script instead of a shared object so
the library will be underlinked on some platforms.
The use of `-nostdlib` should be limited to only the case in which the
optional exception support is selected at configure time. When that is
the case, we can assume the developer knows what they're doing (they're
writing their own exception handling stack) and can pass the right LDADD
explcitly as required.
This changes makes the use of `-nostdlib` and `-lc -lgcc_s` dependent on
the configure-time `--enable-cxx-exceptions=yes`, which is not the
default.
1. Add a configure option, --enable-cet, to compile libunwind with
"-mshstk -fcf-protection" and link with -Wl,-z,cet-report=error.
CET is always enabled if -fcf-protection is on by default.
2. Add a frames field to struct cursor and update unw_step to cont stack
frames to pop.
3. Update x86_64_sigreturn to pop 4 shadow stack frames.
4. Update x86_64_local_resume to pop the same number of shadow stack
frames as the regular stack frames.
5. Update _Ux86_64_setcontext to pop 2 shadow stack frames.
There are no failures with
$ ./configure --enable-cet
$ make -j12
$ GLIBC_TUNABLES=glibc.cpu.hwcaps=SHSTK make check
on Linux when shadow stack is enabled.
Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
Two tests were failing on QNX because they hard-code the syscall
function name for raising a signal and the hard-coded function name is
wrong for QNX OS.
Ran the relevant test code through clang-format and fixed additional
issues with Aarch64 scalable vector extension (SVE) on QNX.
Include <cet.h> when Intel Control-flow Enforcement Technology (CET)
is enabled. Both GCC and Clang provide <cet.h> which should be included
in assembly codes with .S suffix when -fcf-protection is used. It will
define _CET_ENDBR (endbr64) and the .note.gnu.property note section.
Fixes#644.
Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
endian.h on musl/mips can't be included in __ASSEMBLER__ mode,
so use the __BYTE_ORDER__ symbol instead.
Signed-off-by: Ross Burton <ross.burton@arm.com>
All segemnets in an ELF file are not guaranteed to have the same base
virtual address.
Adjusted the GNU hash table address based on the actual file offset of
the segment containing ir rather than the offset of the program table
header itself.
C89: 4.10.3.2 The free function.
The free function causes the space pointed to by ptr to be deallocated, that is, made available for further allocation. If ptr is a null pointer, no action occurs.
This test randomly fails on arm because depending on the place where the
signal is received, the backtrace can involve glibc functions such as
"__read", which do not have .EXIDX instructions.
This reverts commit a4014f3377. The
implementation of the pre-linking support is wrong. It assumes that only
pre-linked libraries will have the virtual address of the LOAD ELF section set
to non-zero.
On arm-linux-gnueabi, without pre-linking, we have:
LOAD 0x000000 0x00010000 0x00010000 0x267fc 0x267fc R E 0x10000
Which means that load_offset is set to 0x10000 and incorrectly substracted
from ip - ip_base. It also seems that pre-linking support is vastly
deprecated.
Reverting that one fixes .debug_frame based unwinding of arm-linux-gnueabi.
On an aarch64 system tdep_trace was returning `-UNW_ESTOPUNWIND`
a lot while profiling a Qt 6 / QML application with heaptrack.
I have not understood why exactly, but note that QML injects
JIT frames and more, which potentially lead to such failures?
Without the patch here, unwinding became excessively slow because
the `slow_backtrace` fallback continuously called `tdep_get_elf_image`
which is extremely slow for applications with many entries in their
`/proc/<pid>/maps` file.
With the patch here applied, I could use heaptrack again with
the expected bearable overhead. The backtraces still look fine,
so for me this patch here looks like a good workaround.
The function in this source file was never used anywhere
(`unw_tdep_getcontext()` is a macro generating inline asm for arm). It
also fails to build from source for any OS other than Linux and FreeBSD.
Removed the file and checks for the symbol.
When using .EXIDX based unwinding, some functions are flagged with the
.cantunwind directive. That causes unw_step to stop unwinding and to return
-UNW_ESTOPUNWIND.
Do not consider that as an error in the tests.
Change the autoconf rules so that
- docs are always built and installed unless
`--enable-documentation=no` is passed
- the documentation-build tools latex2man and pdflatex are
autodetected and, if not found, just issue a warning at configure
time and doc builds do nothing. Since built man pages are under
source control this should not have a dire effect.
Fixes#822