Commit Graph

230 Commits

Author SHA1 Message Date
Ryan Schmidt
5b3b0ed81c PR #1500: Define MAP_ANONYMOUS if not defined
Included are additional automated edits by clang-format on import.

Merge d74896699f into 22091f4c0d

Merging this change closes #1500

COPYBARA_INTEGRATE_REVIEW=https://github.com/abseil/abseil-cpp/pull/1500 from ryandesign:MAP_ANONYMOUS d74896699f
PiperOrigin-RevId: 552922776
Change-Id: I96a0395cb5e7156d7c7a889491c5d0b4cf755819
2023-08-01 14:27:32 -07:00
Tom Rybka
c26cd952ae symbolize_test: Add an indirection for getting the PC from function ptr.
Don't assume that function ptr == PC. Adds a redirection mechanism, GetPCFromFnPtr, and enables more test cases for Emscripten/Wasm.

On many (most?) platforms, the address of a function ptr is the same as its
Program Counter (PC) for the purpose of most things, including symbolization.

In Emscripten WebAssembly, the function ptr is just an index into a table of
functions. However, the name section maps function names to their literal
offsets into a Wasm binary. The WasmOffsetConverter is actually capable of both
indirections, so we can effectively go from function ptr to offset into the
binary (which is typically the "PC" for other Stack dumping things in Wasm,
including `emscripten_pc_get_function`).

More info: https://www.w3.org/TR/wasm-js-api-2/#exported-function-exotic-objects

Also fix Emscripten symbolize handling for `nullptr` now that we have tests for
that.

PiperOrigin-RevId: 546006678
Change-Id: I0d4015ca9035b004158451b36c933cad009184ba
2023-07-06 09:12:45 -07:00
Benjamin Barenblat
372bfc8610 Fix symbolization on PowerPC ELF v1
The big-endian PowerPC ELF ABI (ppc64 in Debian) relies on function
descriptors mapped in a non-executable segment. Make sure that segment
is scanned during symbolization. Also correct bounds computation for
that segment.

PiperOrigin-RevId: 544440302
Change-Id: Ic05532aa35ae9efa127028318640ee7cdeeecc5f
2023-06-29 13:06:45 -07:00
Abseil Team
4eaff9e61e Support Qualcomm Hexagon DSP targets.
PiperOrigin-RevId: 544438364
Change-Id: I22d461f2d0aa8638a0e640eebecdc7e5e2b49ea3
2023-06-29 12:59:30 -07:00
Derek Mauro
94d77fe360 Add missing #include <limits>
Fixes #1482

PiperOrigin-RevId: 542023050
Change-Id: Iba712083edc9a24732a71f51be22ea970115809c
2023-06-20 13:00:48 -07:00
Abseil Team
bf69aa3ca2 The current aarch64 large-stack frame error handling is unsophisticated,
which makes it give up in certain situations where the x86 handler works
fine

This change adopts x86's more sophisticated stack-bounds-checking
method for aarch64, and enables the HugeStack test to pass on aarch64.

PiperOrigin-RevId: 540655431
Change-Id: If7d816330327722bbe5c135abfa77fda5e7e452b
2023-06-15 12:20:04 -07:00
Abseil Team
04e0dcae14 Rename AsyncSignalSafeWriteToStderr to AsyncSignalSafeWriteError.
It no longer strictly writes to stderr, since Emscripten/WebAssembly now use _emscripten_err which might be replaced by something that is not the same as stderr by the host.

PiperOrigin-RevId: 540655336
Change-Id: Icc2a430a0db53a1282ef5558e9f3648db67e972c
2023-06-15 12:19:02 -07:00
Abseil Team
2b042424db Fix unwinding through nested signal frames on aarch64.
This fixes an endless loop in the absl Arm stack unwinder where encountering a
second signal return trampoline (as one has in nested signal frames), would restart
unwinding at the outermost signal, resulting in an endless loop.

This does not change any behavior in the non-nested signal case, so I believe
it is safe for any stack that hasn't encountered this bug already.

I would love to test this beyond the absl unwinding test cases and the
fingerprint_test included here, but I'm at a loss for other test cases.

PiperOrigin-RevId: 539113007
Change-Id: I10037f9fa77b45cc4db61f89b9c6380ec3529113
2023-06-09 10:11:36 -07:00
Bin Lan
872d99b48d Add VxWorks support 2023-06-08 09:38:42 +08:00
Andy Getzendanner
4e4b48faad Note that AsyncSignalSafeWriteToStderr preserves errno, and inline one use of it into a lambda.
PiperOrigin-RevId: 535245982
Change-Id: I816f60c8b6476536df6836500f01c9a3ad88ddd4
2023-05-25 07:10:52 -07:00
Copybara-Service
d23adc1cfb Merge pull request #1455 from juergbi:solaris
PiperOrigin-RevId: 534619764
Change-Id: Ied99569176766f9708d5504eac9c7024cdcfd64b
2023-05-23 17:44:36 -07:00
Andy Getzendanner
5274782148 Migrate most RAW_LOGs and RAW_CHECKs in tests to regular LOG and CHECK.
The non-RAW_ versions provide better output but weren't available when most of these tests were written.

There are just a couple spots where RAW_ is actually needed, e.g. signal handlers and malloc hooks.

Also fix a couple warnings in layout_test.cc newly surfaced because the optimizer understands CHECK_XX differently than INTERNAL_CHECK.

PiperOrigin-RevId: 534584435
Change-Id: I8d36fa809ffdaae5a3813064bd602cb8611c1613
2023-05-23 15:47:23 -07:00
Jürg Billeter
962e8be180 absl/debugging: Fix build on Solaris 2023-05-23 12:11:07 +02:00
Abseil Team
2662ae4a29 Add missing dependency on dynamic_annotations to stacktrace, which is needed in some of the
builds.

PiperOrigin-RevId: 530308301
Change-Id: I7c885156e14d9c8c444c7c6f8d38e7aaac7c01a7
2023-05-08 08:25:35 -07:00
Vertexwahn
9c32e50df8 Fix spelling mistakes 2023-04-27 22:10:09 +02:00
Vertexwahn
421a74dce4 Fix some spelling mistakes 2023-04-24 21:25:50 +02:00
Abseil Team
3a46229c3c Name anonymous memory allocations on Linux.
Use Linux's prctl(PR_SET_VMA) system call to name memory arenas being
allocated using mmap(MAP_ANONYMOUS).

This change allows Abseil's memory arena(s) to be distinguished from
other uses of anonymous memory within a process, which in turn helps
investigations into the memory usage of applications.

The change adds a new prctl() system call to the code paths that call
mmap(). This is not expected to add significant overhead to applications.

The call to prctl(PR_SET_VMA, ...) can fail if the Linux kernel in use was
not configured with the CONFIG_ANON_VMA_NAME kernel option.  This should
be OK since the naming memory regions is primarily a debugging aid.

PiperOrigin-RevId: 523687348
Change-Id: Ie404e5eeef0a6da53330b3a56149c4f3bc6bf5c7
2023-04-12 06:55:11 -07:00
Abseil Team
2d31912897 Properly calculate frame sizes on Aarch64
For function N in the stack, the current code reports the size of
frame N - 1. Fix that.

PiperOrigin-RevId: 520688072
Change-Id: I984729f72f79aebae1b6997cb51d3ddef9199d1e
2023-03-30 11:01:12 -07:00
Abseil Team
cd43bea777 Fix //absl/{base,debugging:symbolize} build with Mingw
PiperOrigin-RevId: 512974770
Change-Id: If7a8128996d2a73ac566faaa676ddd3858d51af6
2023-02-28 10:34:04 -08:00
Copybara-Service
0ecfe2358a Merge pull request #1393 from AtariDreams:cpp
PiperOrigin-RevId: 511696041
Change-Id: I77a87c8721f64e0d9e9a70e08a7127312488ff21
2023-02-22 22:56:40 -08:00
Copybara-Service
c3b5022604 Merge pull request #1394 from AtariDreams:constructors
PiperOrigin-RevId: 511271203
Change-Id: I1ed352e06265b705b62d401a50b4699d01f7f1d7
2023-02-21 12:17:12 -08:00
Abseil Team
d9ae096e74 absl: fix potential int overflow in ELF reading
Both e_shentsize and e_shstrndx are uint16, so the product
  elf_header.e_shentsize * elf_header.e_shstrndx
can overflow the promoted type int (MAX_UINT16 * MAX_UINT16 > MAX_INT),
which is undefined behavior. Not sure if it can affect any real cases
or not, though.

Cast e_shentsize to loff_t instead of e_shoff.
This makes both multiplication and addition to use loff_t type.

PiperOrigin-RevId: 511254775
Change-Id: I39c493bfb539cca6742aae807c50718d31e7c001
2023-02-21 11:20:22 -08:00
Rose
ab92654a37 Convert empty constructors to default ones
These make the changed constructors match closer to the other ones that are default.
2023-02-17 10:22:46 -05:00
Rose
fd02f6a4bd Prefer C++ notation over C
nullptr instead of 0 and nothing instead of void for function arguments is preferred.
2023-02-16 12:34:51 -05:00
Abseil Team
0c3df2f5a7 The type of MINSIGSTKSZ is not guaranteed; avoid potential implicit sign conversion.
On some glibcs, this is defined as a call to sysconf(), which returns a long.

PiperOrigin-RevId: 505380003
Change-Id: I53207846d733d3a529630a6aff9bca425cf90a21
2023-01-28 13:42:33 -08:00
Abseil Team
96355f50aa absl: harden stack bounds check
Ensure that we know both real low and high stack bounds
when relying on the stack bounds check.

PiperOrigin-RevId: 504003431
Change-Id: I8f6e6b75f5edff233d3cf80285f81b53f9080a0f
2023-01-23 09:11:40 -08:00
Abseil Team
c611e5ce1d absl: add a stack unwinding test
END_PUBLIC

absl: relax frame size check in x86 stack unwinding

Currently the unwinder stops whenever it sees a frame >100000 bytes.
There may be such legitimate frames, the default stack size is O(megabytes).
Only do this check if we are not within the thread stack bounds.
The thread stack is assumed to be readable, so the worst thing that can happen
if the large stack frame is actually bogus is that we will add one/few wrong frames and stop.

PiperOrigin-RevId: 503374764
Change-Id: Icabb55d6468b12a42bf026c37c98dbe84977e659
2023-01-20 00:48:32 -08:00
Abseil Team
de6fca2110 [NFC] fix typo in comment.
PiperOrigin-RevId: 498048994
Change-Id: Iee969b9171921e3ffdca2610f9b93b53678d0b9d
2022-12-27 16:04:44 -08:00
Derek Mauro
b4a4a6b01f Replace std::atomic_flag with std::atomic<bool> to avoid the C++20
deprecation of ATOMIC_FLAG_INIT.

Another option would have been to use macros to only initialize
std::atomic_flag before C++20, but I decided to use one compilation
path instead.

The major difference between std::atomic_flag and std::atomic<bool> is
that the former is guaranteed to be lock-free, but we already assume
std::atomic<bool> is lock-free in many places.

https://en.cppreference.com/w/cpp/atomic/atomic_flag

PiperOrigin-RevId: 487397075
Change-Id: I3f1c539ec8b2ca58547282e69ed73e93243e8efe
2022-11-09 18:06:53 -08:00
Russell Johnston
8bf19a07e0 Use the -l form for MinGW-specific link dependencies
This corrects the generated .pc files, so these libs match the other libs
already included there.
2022-10-15 11:14:56 -07:00
Abseil Team
f073fe8ee5 Fix "unsafe narrowing" warnings in absl, 12/12.
Addresses failures with the following, in some files:
-Wshorten-64-to-32
-Wimplicit-int-conversion
-Wsign-compare
-Wsign-conversion
-Wtautological-unsigned-zero-compare

(This specific CL enables these warnings and fixes the remaining known issues.)

Bug: chromium:1292951
PiperOrigin-RevId: 480981210
Change-Id: I92d5023c6833e24d6aa29b10d433116329972f41
2022-10-13 14:13:57 -07:00
Abseil Team
2d80dec405 Improve failure message: tell the values we don't like.
PiperOrigin-RevId: 474043469
Change-Id: I9ea33a8bf026263c9e10d2a183014a5ee8df1306
2022-09-13 09:49:03 -07:00
Abseil Team
bf9c19e545 Increase the number of per-ObjFile program headers we can expect.
PiperOrigin-RevId: 474017481
Change-Id: I1be222fa38ad01f6ddbcddd610f9629fd4888777
2022-09-13 07:51:20 -07:00
Derek Mauro
0a066f31d9 Fix format string error with an explicit cast
PiperOrigin-RevId: 473088472
Change-Id: If4fb8354490821cbaf53743f51bf0b0d2ba85895
2022-09-08 14:41:38 -07:00
Abseil Team
69199fcebe Fix "unsafe narrowing" warnings in absl, 9/n.
Addresses failures with the following, in some files:
-Wshorten-64-to-32
-Wimplicit-int-conversion
-Wsign-compare
-Wsign-conversion
-Wtautological-unsigned-zero-compare

(This specific CL focuses on miscellaneous non-test source files.)

Bug: chromium:1292951
PiperOrigin-RevId: 473054605
Change-Id: Ifd7b24966613ca915511a3a607095508068200b8
2022-09-08 12:22:28 -07:00
Derek Mauro
518984e432 Fix stacktrace header includes
Fixes #1275

PiperOrigin-RevId: 472990940
Change-Id: I1251b01b09e6a9baac52ae4df443714432115e90
2022-09-08 08:07:48 -07:00
Abseil Team
f753eb27d0 Add a missing dependency on :raw_logging_internal
internal/stacktrace_x86-inl.inc includes internal/raw_logging.h and therefore needs
a direct dependency to satisfy Bazel layering_check (Clang -fmodules-strict-decluse).
Clang before https://reviews.llvm.org/D132779 does not report the issue becasue:

* internal/stacktrace_x86-inl.inc is an .inc file and is not checked as a main file
* internal/stacktrace_x86-inl.inc is a textual header and older Clang incorrectly
  considers there is no requesting module and suppresses the error.

PiperOrigin-RevId: 472795469
Change-Id: Ia4ad667ea80b2590cef1adfd22af025c8df826ac
2022-09-07 13:12:14 -07:00
Abseil Team
d9382f7290 Fix "unsafe narrowing" warnings in absl, 7/n.
Addresses failures with the following, in some files:
-Wshorten-64-to-32
-Wimplicit-int-conversion
-Wsign-compare
-Wsign-conversion
-Wtautological-unsigned-zero-compare

(This specific CL focuses on .cc files in debugging/internal/.)

Bug: chromium:1292951
PiperOrigin-RevId: 470812243
Change-Id: I5578030bb42ba73cb83d4df84f89e431ceac8992
2022-08-29 14:15:52 -07:00
Saleem Abdulrasool
9ab9e487a6 debugging: handle alternate signal stacks better on RISCV
In the case that we are unwinding with context, if the retreived frame pointer
matches the signal context, assume that the value is valid and do not perform
confidence checks.  In any other case, continue to perform some validation to
avoid returning an incorrect frame pointer.

Given that the VDSO path is currently untested, remove the code to simplify the
logic in the frame walking.

PiperOrigin-RevId: 465360612
Change-Id: Iac656012182a12814bafecf20225ba68b90b4db1
2022-08-04 11:20:44 -07:00
Abseil Team
16af2bbcb9 Fix "unsafe narrowing" warnings in absl, 2/n.
Addresses failures with the following, in some files:
-Wshorten-64-to-32
-Wimplicit-int-conversion
-Wsign-compare
-Wsign-conversion
-Wtautological-unsigned-zero-compare

(This specific CL focuses on .cc files in dirs a-h.)

Bug: chromium:1292951
PiperOrigin-RevId: 464541951
Change-Id: If23b63ccea8e9b730159ff1c7288e9300a40b6bd
2022-08-01 08:30:25 -07:00
Saleem Abdulrasool
dc370a8246 debugging: honour STRICT_UNWINDING in RISCV path
The changes in d6f96eda14 enabled handling cases
where the stack may be non-contiguous or not fully symbolicated (e.g. in cases
of alternate signal stacks).  However, it did not properly honour the requests
from the caller to perform a strict unwinding where such frames are terminated
upon the discontinuity.  This repairs that condition.

Hoist the alignment check since that is safe to perform early.

PiperOrigin-RevId: 464160529
Change-Id: Ic65645928ec60c2a3b4844f3abd4fed1b991edab
2022-07-29 14:39:07 -07:00
Abseil Team
7f51ef5ed2 Fix "unsafe narrowing" warnings in absl, 1/n.
Addresses failures with the following, in some files:
-Wshorten-64-to-32
-Wimplicit-int-conversion
-Wsign-compare
-Wsign-conversion
-Wtautological-unsigned-zero-compare

(This specific CL focuses on .h and win32 .inc files.)

Bug: chromium:1292951
PiperOrigin-RevId: 463835431
Change-Id: If8e5f7f651d5cd96035e23e4623bdb08a7fedabe
2022-07-28 07:46:07 -07:00
Abseil Team
b0787ae6bc Fix frame pointer alignment check.
The frame pointer sanity check in NextStackFrame() was more restrictive than it is necessary. The frame pointer is used to load the saved link-register and the address for the next stack frame. So it only needs to be 8-byte aligned. The aarch64 ABI does not specify an alignment requirement for the frame point.

PiperOrigin-RevId: 463368519
Change-Id: I473e05181603288f14734fe29013900c7505e201
2022-07-26 10:16:30 -07:00
David Majnemer
c1deed2f44 Do not re-close files on EINTR
POSIX is unclear what state a file descriptor is in after a signal is delivered in the middle of close. On Linux, the file is closed even if it returns -1 with errno=EINTR.

As such, do not use errno at all when closing files.

PiperOrigin-RevId: 462638735
Change-Id: Ie73da1f3c83b1099bef146e1ea32e9a4818597cf
2022-07-22 09:25:04 -07:00
Andy Getzendanner
2c489bb5f0 Renamespace absl::raw_logging_internal to absl::raw_log_internal to match (upcoming) non-raw logging namespace.
PiperOrigin-RevId: 462213222
Change-Id: I3b9371097b368d55cc86b6106d6dec24ce122762
2022-07-20 13:11:43 -07:00
David Majnemer
0c8bd82e90 Check for negative return values from ReadFromOffset
In some places, we check if the amount we read is a multiple of some amount we are interested in. However, ReadFromOffset returns -1 when it errors. Certain record sizes can cause ReadFromOffset to cause us to think that we succeeded when we did not.

It also results in confusing messages in logs.

PiperOrigin-RevId: 461798762
Change-Id: I8c9c7f2cea4d1789e95e50833d5405239a47f02e
2022-07-18 22:25:22 -07:00
Benjamin Barenblat
65ac1e611c Avoid signedness change when casting off_t
Some ABSL_RAW_LOG statements print off_t values by casting them to
uintmax_t. However, POSIX says off_t is signed [1], so intmax_t is more
appropriate. Replace casts and format specifiers as needed.

[1] https://pubs.opengroup.org/onlinepubs/009696899/basedefs/sys/types.h.html#:~:text=off_t%20shall,%20types%2e

PiperOrigin-RevId: 461684406
Change-Id: I09ec1a3ba49cd688670618797943a84bc48dba3e
2022-07-18 12:24:41 -07:00
Saleem Abdulrasool
d6f96eda14 debugging: add hooks for checking stack ranges
Add a hook to permit checking whether an address is in bounds for the stack.

PiperOrigin-RevId: 460997074
Change-Id: Ib3b4d0cf656e614aa083457abb079c40ef8db0ff
2022-07-14 10:35:00 -07:00
Abseil Team
305a0088ce Support [[gnu::abi_tag("xyz")]] demangling.
PiperOrigin-RevId: 460752575
Change-Id: I9629504b5c63dbfe367cd55e287a782cd8fa546c
2022-07-13 10:42:43 -07:00
Copybara-Service
3d0956d139 Merge pull request #1217 from anpol:macos-sigaltstack
PiperOrigin-RevId: 460713135
Change-Id: If7ea94f409edc1e4024d7eaa4ae025b0b258fc02
2022-07-13 07:47:44 -07:00