From 1ce4ceca2b2931bc4d7e470228c2dbb2f3dfea0f Mon Sep 17 00:00:00 2001 From: Abseil Team Date: Thu, 23 Sep 2021 13:21:54 -0700 Subject: Export of internal Abseil changes -- 1801102e11205861bc063e067e9fd4754b625c5a by Derek Mauro : Internal change PiperOrigin-RevId: 398562681 -- 485008445725d4013f60f4b2876f84b6b47932ec by Jorg Brown : Replace calls to std::isinf with comparison against max(). PiperOrigin-RevId: 398534255 -- 9b99d074d39ad677cf92f99549d22bb73f504f8f by Saleem Abdulrasool : debugging: add support for non-glibc targets for debugging This relaxes the ELF mem_image handling and subsequently enables the VDSO support for non-glibc targets. The primary need for the restriction was the use of the `__GLIBC_PREREQ` macro. If it is undefined, assume that the glibc pre-requisite is unavailable. This allows building the debugging_internal target on musl targets. PiperOrigin-RevId: 398499050 -- 3cc3630ef2226ae1981a944573f0f9c27a527ebf by Abseil Team : Replace usages of `auto` with proper typedefs. PiperOrigin-RevId: 398479551 GitOrigin-RevId: 1801102e11205861bc063e067e9fd4754b625c5a Change-Id: Ib13e8612d1b263b9c1ae7f56a9f394b24c3add2e --- absl/container/internal/inlined_vector.h | 10 +++++----- absl/debugging/internal/elf_mem_image.cc | 21 +++++++++++---------- absl/debugging/internal/elf_mem_image.h | 4 ++-- absl/debugging/internal/vdso_support.cc | 19 ++++++++++++++++--- absl/strings/numbers.cc | 2 +- 5 files changed, 35 insertions(+), 21 deletions(-) diff --git a/absl/container/internal/inlined_vector.h b/absl/container/internal/inlined_vector.h index bb365b80..e2ecf46c 100644 --- a/absl/container/internal/inlined_vector.h +++ b/absl/container/internal/inlined_vector.h @@ -98,7 +98,7 @@ template void DestroyElements(NoTypeDeduction& allocator, Pointer destroy_first, SizeType destroy_size) { if (destroy_first != nullptr) { - for (auto i = destroy_size; i != 0;) { + for (SizeType i = destroy_size; i != 0;) { --i; AllocatorTraits::destroy(allocator, destroy_first + i); } @@ -492,7 +492,7 @@ void Storage::DestroyContents() { template void Storage::InitFrom(const Storage& other) { - const auto n = other.GetSize(); + const SizeType n = other.GetSize(); assert(n > 0); // Empty sources handled handled in caller. ConstPointer src; Pointer dst; @@ -598,9 +598,9 @@ template auto Storage::Resize(ValueAdapter values, SizeType new_size) -> void { StorageView storage_view = MakeStorageView(); - auto* const base = storage_view.data; + Pointer const base = storage_view.data; const SizeType size = storage_view.size; - auto& alloc = GetAllocator(); + A& alloc = GetAllocator(); if (new_size <= size) { // Destroy extra old elements. DestroyElements(alloc, base + new_size, size - new_size); @@ -732,7 +732,7 @@ template template auto Storage::EmplaceBack(Args&&... args) -> Reference { StorageView storage_view = MakeStorageView(); - const auto n = storage_view.size; + const SizeType n = storage_view.size; if (ABSL_PREDICT_TRUE(n != storage_view.capacity)) { // Fast path; new element fits. Pointer last_ptr = storage_view.data + n; diff --git a/absl/debugging/internal/elf_mem_image.cc b/absl/debugging/internal/elf_mem_image.cc index 24cc0130..d6832eaf 100644 --- a/absl/debugging/internal/elf_mem_image.cc +++ b/absl/debugging/internal/elf_mem_image.cc @@ -22,6 +22,7 @@ #include #include #include +#include "absl/base/config.h" #include "absl/base/internal/raw_logging.h" // From binutils/include/elf/common.h (this doesn't appear to be documented @@ -43,11 +44,11 @@ namespace debugging_internal { namespace { -#if __WORDSIZE == 32 +#if __SIZEOF_POINTER__ == 4 const int kElfClass = ELFCLASS32; int ElfBind(const ElfW(Sym) *symbol) { return ELF32_ST_BIND(symbol->st_info); } int ElfType(const ElfW(Sym) *symbol) { return ELF32_ST_TYPE(symbol->st_info); } -#elif __WORDSIZE == 64 +#elif __SIZEOF_POINTER__ == 8 const int kElfClass = ELFCLASS64; int ElfBind(const ElfW(Sym) *symbol) { return ELF64_ST_BIND(symbol->st_info); } int ElfType(const ElfW(Sym) *symbol) { return ELF64_ST_TYPE(symbol->st_info); } @@ -175,17 +176,17 @@ void ElfMemImage::Init(const void *base) { } switch (base_as_char[EI_DATA]) { case ELFDATA2LSB: { - if (__LITTLE_ENDIAN != __BYTE_ORDER) { - assert(false); - return; - } +#ifndef ABSL_IS_LITTLE_ENDIAN + assert(false); + return; +#endif break; } case ELFDATA2MSB: { - if (__BIG_ENDIAN != __BYTE_ORDER) { - assert(false); - return; - } +#ifndef ABSL_IS_BIG_ENDIAN + assert(false); + return; +#endif break; } default: { diff --git a/absl/debugging/internal/elf_mem_image.h b/absl/debugging/internal/elf_mem_image.h index 46bfade3..86474819 100644 --- a/absl/debugging/internal/elf_mem_image.h +++ b/absl/debugging/internal/elf_mem_image.h @@ -31,8 +31,8 @@ #error ABSL_HAVE_ELF_MEM_IMAGE cannot be directly set #endif -#if defined(__ELF__) && defined(__GLIBC__) && !defined(__native_client__) && \ - !defined(__asmjs__) && !defined(__wasm__) +#if defined(__ELF__) && !defined(__native_client__) && !defined(__asmjs__) && \ + !defined(__wasm__) #define ABSL_HAVE_ELF_MEM_IMAGE 1 #endif diff --git a/absl/debugging/internal/vdso_support.cc b/absl/debugging/internal/vdso_support.cc index 6be16d90..0dfe9ca6 100644 --- a/absl/debugging/internal/vdso_support.cc +++ b/absl/debugging/internal/vdso_support.cc @@ -20,12 +20,25 @@ #ifdef ABSL_HAVE_VDSO_SUPPORT // defined in vdso_support.h +#if !defined(__has_include) +#define __has_include(header) 0 +#endif + #include #include +#if __has_include() +#include +#elif __has_include() #include +#endif #include -#if __GLIBC_PREREQ(2, 16) // GLIBC-2.16 implements getauxval. +#if defined(__GLIBC__) && \ + (__GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 16)) +#define ABSL_HAVE_GETAUXVAL +#endif + +#ifdef ABSL_HAVE_GETAUXVAL #include #endif @@ -65,7 +78,7 @@ VDSOSupport::VDSOSupport() // the operation should be idempotent. const void *VDSOSupport::Init() { const auto kInvalidBase = debugging_internal::ElfMemImage::kInvalidBase; -#if __GLIBC_PREREQ(2, 16) +#ifdef ABSL_HAVE_GETAUXVAL if (vdso_base_.load(std::memory_order_relaxed) == kInvalidBase) { errno = 0; const void *const sysinfo_ehdr = @@ -74,7 +87,7 @@ const void *VDSOSupport::Init() { vdso_base_.store(sysinfo_ehdr, std::memory_order_relaxed); } } -#endif // __GLIBC_PREREQ(2, 16) +#endif // ABSL_HAVE_GETAUXVAL if (vdso_base_.load(std::memory_order_relaxed) == kInvalidBase) { int fd = open("/proc/self/auxv", O_RDONLY); if (fd == -1) { diff --git a/absl/strings/numbers.cc b/absl/strings/numbers.cc index 966d94bd..cbd84c91 100644 --- a/absl/strings/numbers.cc +++ b/absl/strings/numbers.cc @@ -505,7 +505,7 @@ size_t numbers_internal::SixDigitsToBuffer(double d, char* const buffer) { *out++ = '-'; d = -d; } - if (std::isinf(d)) { + if (d > std::numeric_limits::max()) { strcpy(out, "inf"); // NOLINT(runtime/printf) return out + 3 - buffer; } -- cgit v1.2.3