260 Commits

Author SHA1 Message Date
Milad Fa
d885e62bc8 PR #2051: Fix absl_stacktrace_test on s390x
Imported from GitHub PR https://github.com/abseil/abseil-cpp/pull/2051

Commit 33bbc26 made changes to stacktrace_emscripten-inl.inc but did not change the stacktrace_generic-inl.inc file. This caused `absl_stacktrace_test` to fail on s390x.
```
Expected: (results[i]) != (nullptr), actual: NULL vs (nullptr)
Unexpected nullptr found at index 14

[  FAILED  ] StackTrace.NoNullptrInPopulatedRange (0 ms)
```
This patch applies the same logic to stacktrace_generic-inl.inc.
Merge b2fef211b0 into 89203a0303

Merging this change closes #2051

COPYBARA_INTEGRATE_REVIEW=https://github.com/abseil/abseil-cpp/pull/2051 from miladfarca:fix-33bbc26 b2fef211b0
PiperOrigin-RevId: 915361786
Change-Id: Iafb02166414df57845410457796758a97bcc253a
2026-05-14 04:36:26 -07:00
Abseil Team
33bbc26609 Break on nullptr return address in UnwindImpl on RISC-V
PiperOrigin-RevId: 914222352
Change-Id: Iff9028a38e878465961f71e90484c2a62ed89132
2026-05-12 05:13:17 -07:00
Mike Kruskal
74b81df26c Fix aarch64 stacktrace unwinding.
PiperOrigin-RevId: 910322805
Change-Id: I7a4b80e306ebfe62f36098376c4e4df396ddb8dc
2026-05-04 17:02:17 -07:00
Abseil Team
852fc61f31 Remove more lingering C++17 type traits polyfill usages
This will let us deprecate the declarations without triggering warnings in Abseil itself.

PiperOrigin-RevId: 906360966
Change-Id: Iee362ac0eac647909ef38003280f1179813f764d
2026-04-27 08:03:53 -07:00
Chris Mihelich
4c5d34c1e5 Document that DemangleRustSymbolEncoding omits some details on purpose.
PiperOrigin-RevId: 888093923
Change-Id: If923d44a1c5c6f6668314499dedf7c52f08b9341
2026-03-23 07:55:14 -07:00
Abseil Team
88c0a25fde Remove the legacy stateless symbol decorator API.
PiperOrigin-RevId: 884958234
Change-Id: I288a4b143718a155663669b7d2e4a24a89d754ec
2026-03-17 05:11:13 -07:00
Abseil Team
842679cdbb Add a stateful version of the SymbolDecorator interface
This makes it possible to make decoration faster by caching some information between runs. Instead of a simple callback a decorator can be a class with a virtual function. This function will not be called concurrently, so it does not need to worry about locking, but it may be called from a signal handler so it must avoid any signal-unsafe operations. The decorator is registered via a factory function, which creates a new object.

Internally, the new decorators are stored inside the ObjFile object and initialized on the first use. If a different factory function is registered, the old decorators are destroyed on the next call to absl::Symbolize.

In order to make the state management simpler, we only support registering a single decorator.

The old interface is left in place to make the migration easier, but it will be removed soon.

PiperOrigin-RevId: 881284709
Change-Id: I25b9db656531fabebd1004f7ec298dc31613b8e3
2026-03-10 01:39:14 -07:00
Abseil Team
b6808e6f7c Remove stack trace fixup code from Abseil
PiperOrigin-RevId: 875236816
Change-Id: I88f7d894cc30d23c77b7d43953fe4d85deb65728
2026-02-25 10:48:11 -08:00
Abseil Team
6e0a3164d2 Update *SymbolizeURL APIs to add crash_pc parameter.
PiperOrigin-RevId: 855335009
Change-Id: I1632c5a89e91b857dc18ff9434abf22c3f622d8f
2026-01-12 12:21:10 -08:00
Abseil Team
bbb342c6de Introduce a legacy copy of GetDebugStackTraceHook API.
PiperOrigin-RevId: 852842182
Change-Id: Iadec9bb2fec60b9962a557f82ac998f3cf8d56fe
2026-01-06 10:37:18 -08:00
Abseil Team
88c48235c8 Search more aggressively for open slots in absl::internal_stacktrace::BorrowedFixupBuffer
This lets us avoid heap allocations in more situations than before.

PiperOrigin-RevId: 841851984
Change-Id: Ibd16b0b87c250c504c8d1119d9b9eb4031067c28
2025-12-08 11:39:05 -08:00
Abseil Team
0cc960ece0 Automated rollback of commit 9f40d6d6f3.
PiperOrigin-RevId: 838084272
Change-Id: I8b1b15618e12cc17d85a71b7f5062b66ceaaf04f
2025-11-29 05:02:02 -08:00
Abseil Team
9f40d6d6f3 Enable clang-specific warnings on the clang-cl build
instead of just trying to be MSVC

This also fixes the new warnings that are caught.
These include:
  * Unreachable code after GTEST_SKIP (this is kind of ugly)
  * Some -Wundef warnings
  * A -Wshadow warning in vlog_config.cc

PiperOrigin-RevId: 838046186
Change-Id: Ief48d6db2b8755d2173997d052560880593d5819
2025-11-29 01:22:25 -08:00
Derek Mauro
b20370e0d6 Enable clang-specific warnings on the clang-cl build
instead of just trying to be MSVC

This also fixes the new warnings that are caught.
These include:
  * Unreachable code after GTEST_SKIP (this is kind of ugly)
  * Some -Wundef warnings
  * A -Wshadow warning in vlog_config.cc

PiperOrigin-RevId: 838017208
Change-Id: I39373c0ccc57c8660c22815c51ac5b4180aec53c
2025-11-28 22:41:40 -08:00
Abseil Team
03cc841ff0 Use non-stack storage for stack trace buffers
Doing this opportunistically allows us to avoid performance overhead in the vast majority of calls (rare, non-reentrant ones) while simultaneously minimizing stack space usage.

PiperOrigin-RevId: 831560881
Change-Id: Idc6ba1dd0dcf1b4aaf3ee7cf468054bcfdcf90af
2025-11-12 15:23:29 -08:00
Milad Fa
1a259163cc PR #1961: Fix Clang warnings on powerpc
Imported from GitHub PR https://github.com/abseil/abseil-cpp/pull/1961

We maintain the V8 Js Compiler on IBM platforms which uses abseil as a dependency. We have recently switched to using Clang and need to create this patch to fix two warnings:
```
warning: implicit conversion changes signedness: 'uint64_t' (aka 'unsigned long') to 'int64_t' (aka 'long') [-Wsign-conversion]
warning: implicit conversion loses integer precision: 'uintptr_t' (aka 'unsigned long') to 'int' [-Wshorten-64-to-32]
```
Merge 2e972b5c72 into d71fcd13f6

Merging this change closes #1961

COPYBARA_INTEGRATE_REVIEW=https://github.com/abseil/abseil-cpp/pull/1961 from miladfarca:ppc-fix-clang-warn 2e972b5c72
PiperOrigin-RevId: 823581713
Change-Id: Icff10b99b3808f51866fb97576af405826742088
2025-10-24 10:30:43 -07:00
Abseil Team
f40a1cce40 Optimize stack unwinding by reducing AddressIsReadable calls.
PiperOrigin-RevId: 822738922
Change-Id: Ifd784d16ffb8ae810900b11e41a74ac1f263ed89
2025-10-22 14:22:01 -07:00
Tom Rybka
067246f7ba Remove usage of the WasmOffsetConverter for Wasm / Emscripten stack-traces.
It was removed in a recent version of [Emscripten](https://github.com/emscripten-core/emscripten/blob/main/ChangeLog.md#4014---090225).

This is unfortunate as there is no longer a way to map from function pointer
(index) back to file offset for PC get function name, however the only such uses I could find were the test itself.

Stack trace symbolization should still work.

PiperOrigin-RevId: 819879868
Change-Id: I5b41d5ebfe5e9f476972e44127bbeaaf2f864281
2025-10-15 13:03:07 -07:00
Abseil Team
26c9126028 Fix a corner case in the aarch64 unwinder
In case of two nested back-to-back signals (such as what happens in NestedSignal test) we could end up erroneously using the frame pointer from ucontext_t twice, leading to premature backtrace termination.

In the situation where this happens, the call stack looks like
#0 <unwinder frames>
#1 SigUsr2Handler
#2 __kernel_rt_sigreturn
#3 raise
#4 SigUsr1Handler
#5 __kernel_rt_sigreturn
#6 raise
#7 RaiseSignal
...

When unwinding from #2, we get the fp value from the ucontext (as we should). However, because raise does not modify the fp and because SigUsr1Handler is also a signal handler, when we try to unwind from #4 (#3 is skipped), NextStackFrame ends up looking at the ucontext fp again, and comparing it with the previous (identical) FP value. Non-strict equality accepts this as a valid frame, but the unwinder later bails out due to a zero-sized frame.

Using a strict equality causes NextStackFrame to reject the ucontext fp and use the FP from FP chain instead. This causes us to skip a few more frames, but at least we continue to unwind instead of giving up.

In this case, the computed backtrace skips functions #3, #4 and #6.

PiperOrigin-RevId: 804308754
Change-Id: I5d43e6bea80e4abff1075ada03782ae11c599161
2025-09-08 01:01:51 -07:00
Abseil Team
f8c283dabf Remove support for Native Client
Native Client has been fully removed from Chromium.

PiperOrigin-RevId: 803093147
Change-Id: I7fea87a8a66b35b2f0cc3d815c23f90e5e4d2043
2025-09-04 10:54:42 -07:00
Levi Zim
4dd0ffdf2a PR #1929: Fix shorten-64-to-32 warning in stacktrace_riscv-inl.inc
Imported from GitHub PR https://github.com/abseil/abseil-cpp/pull/1929

`ComputeStackFrameSize` returns `ptrdiff_t` which is `long` while `sizes[n]` is `int`.

This would become an error in chromium build as chromium enables warnings_as_error by default.

Merge ad1d6805b5 into f040e96b93

Merging this change closes #1929

COPYBARA_INTEGRATE_REVIEW=https://github.com/abseil/abseil-cpp/pull/1929 from kxxt:riscv-int-conversion ad1d6805b5
PiperOrigin-RevId: 802286490
Change-Id: I39526e7f9cc26302a18d329989a6b36ddd487f7c
2025-09-02 14:12:13 -07:00
Milad Fa
471b037ab3 PR #1911: Fix absl_demangle_test on ppc64
Imported from GitHub PR https://github.com/abseil/abseil-cpp/pull/1911

We have recently started experimenting with using Clang to compile abseil (instead of gcc) on ppc64 and this test started failing:
```
# ./bin/absl_demangle_test
abseil-cpp/absl/debugging/internal/demangle_test.cc:1996: Failure
Expected: (stack_consumed) < (kStackConsumptionUpperLimit), actual: 9668 vs 8192

[  FAILED  ] Demangle.DemangleStackConsumption (5 ms)
```
This PR increases the value of `kStackConsumptionUpperLimit` to accommodate higher stack usage.
Merge fb14c03227 into 7ece455c25

Merging this change closes #1911

COPYBARA_INTEGRATE_REVIEW=https://github.com/abseil/abseil-cpp/pull/1911 from miladfarca:ppc-fix-test fb14c03227
PiperOrigin-RevId: 787192848
Change-Id: I1343b9a22a92e5663e6e27e827c7b0584800ebbc
2025-07-25 12:04:17 -07:00
Krzysztof Kosiński
454205a618 Roll back NDK weak symbol mode for backtrace() due to internal test breakage
PiperOrigin-RevId: 784690676
Change-Id: Ief3ebd9f6850594b530992867a0642fca6525fdc
2025-07-18 13:53:18 -07:00
Krzysztof Kosiński
9f1244cb3f Support NDK weak symbol mode for backtrace() on Android.
Allows code compiled for API level 32 or lower to support backtrace() when it runs on API level 33 or higher.

PiperOrigin-RevId: 783954794
Change-Id: Ie3e2552d4625092fe5750f6d2d64ae78597d97c3
2025-07-16 17:24:19 -07:00
Krzysztof Kosiński
af00a9295f Only use generic stacktrace when ABSL_HAVE_THREAD_LOCAL.
The file uses __thread, so it should not be included when thread-local storage is not available.

PiperOrigin-RevId: 783193545
Change-Id: I64ca0fde08d2aa0e478d75f3d5fbb3a5bfcea452
2025-07-14 23:14:19 -07:00
Abseil Team
f8c9a088d6 Suppress CFI violation on VDSO call.
PiperOrigin-RevId: 767658852
Change-Id: I097433844dd6f4db0c9c0fdc0b3f5dd0dcc5ee63
2025-06-05 10:10:05 -07:00
Wiktor Garbacz
d55845e6c1 stacktrace_x86: Handle nested signals on altstack
PiperOrigin-RevId: 758147101
Change-Id: I569e095b4820862a7ebba68bd22ab205f43693e2
2025-05-13 03:49:25 -07:00
Peter Collingbourne
1b52dcb350 Stop being strict about validating the "clone" part of mangled names
Support for parsing mangled symbol names with a ".something" suffix
in the demangler was originally added because the compiler was using
that for function cloning, but since then the compiler has started
using ".something" suffixes in many other cases, such as function
renaming for ThinLTO and CFI. As a result, some symbols in binaries
built with these features would fail to demangle.

So instead of trying to validate what comes after the "." let's just
stop parsing when we see a ".", so that the symbols are demangled
correctly. This behavior is consistent with libc++.

PiperOrigin-RevId: 756054147
Change-Id: I01e9e97eee32bee05ba243b615ed26a36b59591d
2025-05-07 16:38:36 -07:00
Derek Mauro
668f174945 Fix new -Wnullability-completeness warnings found after upgrading
the Clang version used in the Linux ARM CI to Clang 19.

nullability-completeness is an all-or-nothing warning, and it is
enabled by default. If anything is annotated, everything has to be
annotated.

There are a few types of fixes in this change. The most common is just
to add missing annotations. In a few cases, some SFINAE methods are
changed not to use pointers at all. In some cases, like
cord_internal.h, I removed the single annotation as that is easier
than doing the entire complicated file for now. cordz_test_helpers.h
uses GoogleTest macros, which bring in pointers that can't easily be
annotated, so I removed the annotations from this file as well.
Tests are also opted-out of the warning.

I'm not sure why the x86 Clang version didn't pick these issues up.

PiperOrigin-RevId: 755844859
Change-Id: I7d7f4cc4f6d779f52c86a4d96e07880341244491
2025-05-07 07:28:51 -07:00
Abseil Team
a9a1b50468 Assume that frame pointers inside known stack bounds are readable.
AddressIsReadable is an expensive check, and in non-crash unwinding situations
always returns true. Avoid that cost.

This is less conservative than the current code. If the known stack
bounds (as returned by a different syscall) are unreadable, the new
code will double fault instead of truncating the returned stack. So some
really bad crash situations will double fault instead of truncating.
Normal stack unwinding will be considerably faster.

PiperOrigin-RevId: 753323325
Change-Id: I4ca90f261ecbe90a12823f832ee9de1bfabecd61
2025-04-30 14:56:20 -07:00
Michael Pratt
fe5a2a4414 Fix misplaced closing brace
6dda8e527f attempted to move this check from the
WITH_CONTEXT block to the main part of the function, but it mistakenly moved
the unrelated brace following the if block.

The result is that the `if (WITH_CONTEXT ...) { ... }` scope actually contains
the alignment and readable checks. When `WITH_CONTEXT` is false, those checks
never run.

PiperOrigin-RevId: 752400908
Change-Id: Ida50d613f4124bc187af1a301bd92439d07a56ee
2025-04-28 12:16:46 -07:00
Abseil Team
39bf411725 Exclude UnwindImpl etc. from thread sanitizer due to false positives.
PiperOrigin-RevId: 747180687
Change-Id: Ib3dcfe3b94acd626ee925aeb8213dcaf978a797d
2025-04-13 16:37:04 -07:00
Abseil Team
93c112c587 Fix "unsafe narrowing" in absl for Emscripten
Addresses failures with -Wsign-compare.

PiperOrigin-RevId: 745713553
Change-Id: I8053c3cc097355ce3606a30a7546d92594438d37
2025-04-09 13:33:35 -07:00
Abseil Team
d97663ee23 Automated Code Change
PiperOrigin-RevId: 744017203
Change-Id: I69b4418b306bdb5f89194bbcddaed9813e46ec6f
2025-04-04 11:43:03 -07:00
Chris Davis
7dca9dbe0c PR #1867: Remove global static in stacktrace_win32-inl.inc
Imported from GitHub PR https://github.com/abseil/abseil-cpp/pull/1867

Removes the global static RtlCaptureStackBackTrace_Function and the GetModuleHandle/GetProcAddress calls so they do not impact module load at startup.

Fixes https://github.com/abseil/abseil-cpp/issues/1866

Merge a5b6f2b026 into d04b964d82

Merging this change closes #1867

COPYBARA_INTEGRATE_REVIEW=https://github.com/abseil/abseil-cpp/pull/1867 from chrdavis:master a5b6f2b026
PiperOrigin-RevId: 743937398
Change-Id: I9a42b5f83ec3d22ac925b3885b1a99f1e98d7291
2025-04-04 07:34:05 -07:00
Abseil Team
3b1bb73373 Adds functionality to return stack frame pointers during stack walking, in addition to code addresses
Together with the frame sizes already being returned, this gives us the bounds on each stack frame.

Note that this may slightly affect MSVC in debug builds, as it does not respect ABSL_ATTRIBUTE_ALWAYS_INLINE without optimizations. To remedy this, either enable inlining (/Ob1 or higher), or write a wrapper that ensures any stack traces obtained are robust to frames being added (such as by manually filtering everything below the caller).

Do not depend on the new APIs publicly. They are subject to change or removal.

PiperOrigin-RevId: 740075920
Change-Id: I6cd0909e7be3af4c9f32d39633230f655946b6a8
2025-03-24 16:35:55 -07:00
Abseil Team
4d6cb98f27 Migrate ClearPacBits() to a more generic implementation and location
PiperOrigin-RevId: 736664098
Change-Id: Ic99ff4ebae02097b9f7691ebdcb2e10f7d255834
2025-03-13 15:44:42 -07:00
Derek Mauro
fd86aa79dd Fix buffer overflow the internal demangling function
The overflow can happen during rollback after a parsing
failure, where the null terminator is written without
verifying the buffer bounds.

Credit to www.code-intelligence.com for reporting this issue

PiperOrigin-RevId: 732995553
Change-Id: Ic5075f53e510d270e1784d593defcd53f9121d02
2025-03-03 11:28:06 -08:00
Derek Mauro
1af129f1c3 Use C++17 [[nodiscard]] instead of the deprecated ABSL_MUST_USE_RESULT
In this change, //absl/status is intentionally excluded because of
complication with SWIG compatibility. This may be handled separately.

PiperOrigin-RevId: 731387819
Change-Id: I71bf2e02f3a477d65575d467f5e5ab163846d31e
2025-02-26 11:16:38 -08:00
Derek Mauro
ea9951d3a9 MSVC: Fix warnings c4244 and c4267 in the main library code
These are integer-type shortening warnings.
These warnings are still disabled in tests.

c4244: conversion from 'type1' to 'type2', possible loss of data
https://learn.microsoft.com/en-us/cpp/error-messages/compiler-warnings/compiler-warning-levels-3-and-4-c4244?view=msvc-170
c4267: conversion from 'size_t' to 'type', possible loss of data
https://learn.microsoft.com/en-us/cpp/error-messages/compiler-warnings/compiler-warning-level-3-c4267?view=msvc-170

Fixes https://github.com/abseil/abseil-cpp/issues/1844

PiperOrigin-RevId: 730882892
Change-Id: Id6506d71846caf1a6a5be3375c34266299c221e1
2025-02-25 07:44:44 -08:00
Derek Mauro
5852b47a81 Actually use the hint space instruction to strip PAC bits for return
addresses in stack traces as the comment says

71f2c75111/src/hotspot/os_cpu/linux_aarch64/pauth_linux_aarch64.inline.hpp

PiperOrigin-RevId: 724360415
Change-Id: I691160e43354131a04919765ce283e07c3c933a9
2025-02-07 08:49:51 -08:00
Abseil Team
3de434ab4c Strip PAC bits for return addresses in stack traces
PiperOrigin-RevId: 705945725
Change-Id: I0a87d81244999849b163480758247b2e87c2d430
2024-12-13 11:26:23 -08:00
Lu Yahan
a3f7e9866c PR #1788: Fix warning for sign-conversion on riscv
Imported from GitHub PR https://github.com/abseil/abseil-cpp/pull/1788

```
error: operand of ? changes signedness: 'long' to 'uintptr_t' (aka 'unsigned long') [-Werror,-Wsign-conversion]
```

Merge 82deb4bbc4 into 95950b32c5

Merging this change closes #1788

COPYBARA_INTEGRATE_REVIEW=https://github.com/abseil/abseil-cpp/pull/1788 from luyahan:luyahan-patch-1 82deb4bbc4
PiperOrigin-RevId: 702375910
Change-Id: Ia95d342ddd277dcbde19008e31aaef09f3c3a282
2024-12-03 09:59:22 -08:00
Alexey Pavlyutkin
78ed38cf2c PR #1783: [riscv][debugging] Fix a few warnings in RISC-V inlines
Imported from GitHub PR https://github.com/abseil/abseil-cpp/pull/1783

Today we cannot build V8 (which uses the Abseil library) in strict mode for RISC-V due to a few warnings in debbugging inlines. All the warnings are about implicit signed to unsigned conversion and precision losses, nothing serious, but they are still very annoying.

Merge 7b2a865021 into 8596c6e7f5

Merging this change closes #1783

COPYBARA_INTEGRATE_REVIEW=https://github.com/abseil/abseil-cpp/pull/1783 from apavlyutkin:riscv-fix-warnings 7b2a865021
PiperOrigin-RevId: 693802454
Change-Id: Ibfefc9370606a6b8ec217ac6d87d7c6d70d1a3ce
2024-11-06 11:31:27 -08:00
Abseil Team
07fff76ed6 Disable Elf symbols for Xtensa
PiperOrigin-RevId: 689081310
Change-Id: I394b8eb6f87f3ea8e2ebce511baeef132b28d452
2024-10-23 13:23:56 -07:00
Francois Bleibel
40a975ff1e Add stacktrace config for android using the generic implementation
This change adds support for unwinding stack traces on supported android platforms (NDK 33+) to absl::GetStackTrace().

PiperOrigin-RevId: 668041186
Change-Id: Ie4c4c123686050c6b81683b71fe0246e8fa75f2b
2024-08-27 10:23:20 -07:00
Abseil Team
bd3ae17f02 Disable ABSL_INTERNAL_HAVE_DEBUGGING_STACK_CONSUMPTION for Fuchsia
The POSIX sigaltstack() function is not implemented on Fuchsia.

PiperOrigin-RevId: 656080882
Change-Id: Ibf4892df85f299b888eb7f0016c220f49f975b96
2024-07-25 14:00:10 -07:00
Fangrui Song
1278ee9bd9 vdso_support: support DT_GNU_HASH
This library provides `LookupSymbol` and `LookupSymbolByAddress`. The latter
needs `GetNumSymbols` support. An object file needs either .hash (DT_HASH) or
.gnu.hash (DT_GNU_HASH). This patch adds DT_GNU_HASH support.

Note: glibc has been supporting DT_GNU_HASH since 2006 and .hash has been quite
obsoleted in the Linux communities.
PiperOrigin-RevId: 648459622
Change-Id: I3aa1274cd4617990844258175715e3be2343afd2
2024-07-01 12:59:40 -07:00
Chris Mihelich
d4cf6b71af Declare Rust demangling feature-complete.
PiperOrigin-RevId: 647417773
Change-Id: I7d945ae27199262b3baf83b232d17c2f641a27ac
2024-06-27 12:59:04 -07:00
Chris Mihelich
4b9a55fd27 Decode Rust Punycode when it's not too long.
PiperOrigin-RevId: 647340145
Change-Id: I4b0076595dbda1f81ffdc32adad2dc1e35cb9e04
2024-06-27 09:13:53 -07:00