Skip to content

Commit

Permalink
Update libc++ to latest
Browse files Browse the repository at this point in the history
  • Loading branch information
zcbenz committed Mar 1, 2023
1 parent 6291834 commit 3048d1f
Show file tree
Hide file tree
Showing 18 changed files with 269 additions and 46 deletions.
2 changes: 2 additions & 0 deletions buildtools/third_party/eu-strip/OWNERS
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
thestig@chromium.org
thomasanderson@chromium.org
12 changes: 12 additions & 0 deletions buildtools/third_party/eu-strip/README.chromium
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
Name: eu-strip
URL: https://sourceware.org/elfutils/
Version: 0.158
Security Critical: no
License: LGPL 3
License File: NOT_SHIPPED

Description:

Patched eu-strip from elfutils.

To build (on Trusty): ./build.sh in this directory.
Binary file added buildtools/third_party/eu-strip/bin/eu-strip
Binary file not shown.
19 changes: 19 additions & 0 deletions buildtools/third_party/eu-strip/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/bin/sh -xe

rm -rf elfutils
git clone git://sourceware.org/git/elfutils.git
cd elfutils
git checkout elfutils-0.170
autoheader
aclocal
autoconf
automake --add-missing
patch -p1 < ../fix-elf-size.patch
mkdir build
cd build
../configure --enable-maintainer-mode
make -j40
gcc -std=gnu99 -Wall -Wshadow -Wunused -Wextra -fgnu89-inline \
-Wformat=2 -Werror -g -O2 -Wl,-rpath-link,libelf:libdw -Wl,--build-id=none -o eu-strip \
src/strip.o libebl/libebl.a libelf/libelf.a lib/libeu.a libdw/libdw.a -ldl -lz
./eu-strip -o ../../bin/eu-strip eu-strip
61 changes: 61 additions & 0 deletions buildtools/third_party/eu-strip/fix-elf-size.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
diff --git a/libelf/elf32_updatenull.c b/libelf/elf32_updatenull.c
index d83c0b3f..507e707b 100644
--- a/libelf/elf32_updatenull.c
+++ b/libelf/elf32_updatenull.c
@@ -137,7 +137,7 @@ __elfw2(LIBELFBITS,updatenull_wrlock) (Elf *elf, int *change_bop, size_t shnum)
return -1;

/* At least the ELF header is there. */
- off_t size = elf_typesize (LIBELFBITS, ELF_T_EHDR, 1);
+ ElfW2(LIBELFBITS,Off) size = elf_typesize (LIBELFBITS, ELF_T_EHDR, 1);

/* Set the program header position. */
if (elf->state.ELFW(elf,LIBELFBITS).phdr == NULL)
@@ -152,7 +152,7 @@ __elfw2(LIBELFBITS,updatenull_wrlock) (Elf *elf, int *change_bop, size_t shnum)
{
/* The user is supposed to fill out e_phoff. Use it and
e_phnum to determine the maximum extend. */
- size = MAX ((size_t) size,
+ size = MAX (size,
ehdr->e_phoff
+ elf_typesize (LIBELFBITS, ELF_T_PHDR, phnum));
}
@@ -330,7 +330,7 @@ __elfw2(LIBELFBITS,updatenull_wrlock) (Elf *elf, int *change_bop, size_t shnum)

if (elf->flags & ELF_F_LAYOUT)
{
- size = MAX ((GElf_Word) size,
+ size = MAX (size,
(shdr->sh_type != SHT_NOBITS
? shdr->sh_offset + shdr->sh_size : 0));

@@ -352,9 +352,9 @@ __elfw2(LIBELFBITS,updatenull_wrlock) (Elf *elf, int *change_bop, size_t shnum)
update_if_changed (shdr->sh_addralign, sh_align,
scn->shdr_flags);

- size = (size + sh_align - 1) & ~(sh_align - 1);
+ size = (size + sh_align - 1) & ~(ElfW2(LIBELFBITS,Off))(sh_align - 1);
int offset_changed = 0;
- update_if_changed (shdr->sh_offset, (GElf_Word) size,
+ update_if_changed (shdr->sh_offset, size,
offset_changed);
changed |= offset_changed;

@@ -416,7 +416,7 @@ __elfw2(LIBELFBITS,updatenull_wrlock) (Elf *elf, int *change_bop, size_t shnum)
/* The user is supposed to fill out e_shoff. Use it and
e_shnum (or sh_size of the dummy, first section header)
to determine the maximum extend. */
- size = MAX ((GElf_Word) size,
+ size = MAX (size,
(ehdr->e_shoff
+ (elf_typesize (LIBELFBITS, ELF_T_SHDR, shnum))));
}
@@ -430,7 +430,7 @@ __elfw2(LIBELFBITS,updatenull_wrlock) (Elf *elf, int *change_bop, size_t shnum)
#define SHDR_ALIGN sizeof (ElfW2(LIBELFBITS,Off))
size = (size + SHDR_ALIGN - 1) & ~(SHDR_ALIGN - 1);

- update_if_changed (ehdr->e_shoff, (GElf_Word) size, elf->flags);
+ update_if_changed (ehdr->e_shoff, size, elf->flags);

/* Account for the section header size. */
size += elf_typesize (LIBELFBITS, ELF_T_SHDR, shnum);
76 changes: 55 additions & 21 deletions buildtools/third_party/libc++/BUILD.gn
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2015 The Chromium Authors. All rights reserved.
# Copyright 2015 The Chromium Authors
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

Expand All @@ -10,12 +10,24 @@ import("//build/toolchain/toolchain.gni")
config("config") {
cflags = [ "-fstrict-aliasing" ]
if (is_win) {
# libc++ wants to redefine the macros WIN32_LEAN_AND_MEAN and _CRT_RAND_S in
# its implementation.
cflags += [ "-Wno-macro-redefined" ]
cflags += [
# libc++ wants to redefine the macros WIN32_LEAN_AND_MEAN and _CRT_RAND_S
# in its implementation.
"-Wno-macro-redefined",
]

cflags_cc = [
# We want to use a uniform C++ version across all of chromium, but
# upstream libc++ requires C++20 so we have to make an exception here.
# No other target should override the default -std= flag.
"-std:c++20",
]
} else {
cflags += [ "-fPIC" ]
cflags_cc = [ "-std=c++20" ]
}

defines = [ "_LIBCPP_BUILDING_LIBRARY" ]
}

# Explicitly set version macros to Windows 7 to prevent libc++ from adding a
Expand Down Expand Up @@ -51,29 +63,44 @@ target(_libcxx_target_type, "libc++") {
if (libcxx_is_shared) {
no_default_deps = true
}

if (is_linux && !is_clang) {
libs = [ "atomic" ]
}

inputs = [ "__config_site" ]

sources = [
"trunk/src/algorithm.cpp",
"trunk/src/any.cpp",
"trunk/src/atomic.cpp",
"trunk/src/barrier.cpp",
"trunk/src/bind.cpp",
"trunk/src/charconv.cpp",
"trunk/src/chrono.cpp",
"trunk/src/condition_variable.cpp",
"trunk/src/condition_variable_destructor.cpp",
"trunk/src/debug.cpp",
"trunk/src/exception.cpp",
"trunk/src/format.cpp",
"trunk/src/functional.cpp",
"trunk/src/future.cpp",
"trunk/src/hash.cpp",
"trunk/src/ios.cpp",
"trunk/src/ios.instantiations.cpp",
"trunk/src/iostream.cpp",
"trunk/src/legacy_pointer_safety.cpp",
"trunk/src/locale.cpp",
"trunk/src/memory.cpp",
"trunk/src/mutex.cpp",
"trunk/src/mutex_destructor.cpp",
"trunk/src/new.cpp",
"trunk/src/optional.cpp",
"trunk/src/random.cpp",
"trunk/src/random_shuffle.cpp",
"trunk/src/regex.cpp",
"trunk/src/ryu/d2fixed.cpp",
"trunk/src/ryu/d2s.cpp",
"trunk/src/ryu/f2s.cpp",
"trunk/src/shared_mutex.cpp",
"trunk/src/stdexcept.cpp",
"trunk/src/string.cpp",
Expand All @@ -85,7 +112,17 @@ target(_libcxx_target_type, "libc++") {
"trunk/src/valarray.cpp",
"trunk/src/variant.cpp",
"trunk/src/vector.cpp",
"trunk/src/verbose_abort.cpp",
]

if (enable_iterator_debugging) {
sources += [
"trunk/src/debug.cpp",
"trunk/src/legacy_debug_handler.cpp",
]
}

include_dirs = [ "trunk/src" ]
if (is_win) {
sources += [
"trunk/src/support/win32/locale_win32.cpp",
Expand All @@ -95,7 +132,7 @@ target(_libcxx_target_type, "libc++") {
configs -= [ "//build/config/win:winver" ]
configs += [ ":winver" ]
if (libcxx_natvis_include) {
inputs = [
inputs += [
# libc++.natvis listed as an input here instead of in
# //build/config/c++:runtime_library to prevent unnecessary size
# increase in generated build files.
Expand All @@ -109,33 +146,30 @@ target(_libcxx_target_type, "libc++") {
"//build/config/compiler:no_rtti",
"//build/config/coverage:default_coverage",
]
if (is_android && libcxx_is_shared) {
configs -= [ "//build/config/android:hide_all_but_jni_onload" ]
if ((is_android || is_apple) && libcxx_is_shared) {
# Use libc++_chrome to avoid conflicting with system libc++
output_name = "libc++_chrome"
if (is_android) {
# See crbug.com/1076244#c11 for more detail.
configs -= [ "//build/config/android:hide_all_but_jni_onload" ]
}
}
configs += [
":config",
"//build/config/compiler:no_chromium_code",
"//build/config/compiler:exceptions",
"//build/config/compiler:rtti",
"//build/config/sanitizers:sanitizer_options_link_helper",
]

if (libcxx_is_shared && !is_win) {
configs -= [ "//build/config/gcc:symbol_visibility_hidden" ]
configs += [ "//build/config/gcc:symbol_visibility_default" ]
}

defines = [ "_LIBCPP_BUILDING_LIBRARY" ]
if (!is_clang && libcxx_is_shared) {
# This is a temporary workaround to get libc++ builds working with
# gcc. It can be removed with either
# https://reviews.llvm.org/D35326 or
# https://reviews.llvm.org/D35388 lands.
defines += [ "_LIBCPP_EXTERN_TEMPLATE_TYPE_VIS=__attribute__((__visibility__(\"default\")))" ]
}
defines = []

if (!libcxx_is_shared) {
# TODO(https://crbug.com/946629): Remove use_xcode_clang condition once
# XCode clang is updated to support -fvisibility-global-new-delete-hidden.
if ((is_mac || (is_ios && !use_xcode_clang)) && is_clang) {
if (is_apple && is_clang) {
# We want operator new/delete to be private on Mac, but these functions
# are implicitly created by the compiler for each translation unit, as
# specified in the C++ spec 3.7.4p2, which makes them always have default
Expand All @@ -162,7 +196,7 @@ target(_libcxx_target_type, "libc++") {
]
}
}
if (!is_mac && !is_ios && (is_asan || is_tsan || is_msan)) {
if (!is_apple && (is_asan || is_tsan || is_msan)) {
# In {a,t,m}san configurations, operator new and operator delete will be
# provided by the sanitizer runtime library. Since libc++ defines these
# symbols with weak linkage, and the *san runtime uses strong linkage, it
Expand Down
4 changes: 2 additions & 2 deletions buildtools/third_party/libc++/OWNERS
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
earthdok@chromium.org
glider@chromium.org
thakis@chromium.org
thomasanderson@chromium.org
53 changes: 53 additions & 0 deletions buildtools/third_party/libc++/__config_site
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
#ifndef _LIBCPP_CONFIG_SITE
#define _LIBCPP_CONFIG_SITE

// We set a custom _LIBCPP_ABI_NAMESPACE for the following reasons:
//
// 1. When libcxx_is_shared is true, symbols from libc++.so are exported for all
// DSOs to use. If the system libc++ gets loaded (indirectly through a
// a system library), then it will conflict with our libc++.so.
// 2. The default value of _LIBCPP_ABI_NAMESPACE is the string
// "_LIBCPP_ABI_NAMESPACE". This contributes to an increase in binary size;
// on Windows, the increase is great enough that we go above the 4GB size
// limit for PDBs (https://crbug.com/1327710#c5). To fix this, we set
// _LIBCPP_ABI_NAMESPACE to a shorter value.
#define _LIBCPP_ABI_NAMESPACE Cr
#define _LIBCPP_ABI_VERSION 2

/* #undef _LIBCPP_ABI_FORCE_ITANIUM */
/* #undef _LIBCPP_ABI_FORCE_MICROSOFT */
/* #undef _LIBCPP_HAS_NO_THREADS */
/* #undef _LIBCPP_HAS_NO_MONOTONIC_CLOCK */
/* #undef _LIBCPP_HAS_MUSL_LIBC */
/* #undef _LIBCPP_HAS_THREAD_API_PTHREAD */
/* #undef _LIBCPP_HAS_THREAD_API_EXTERNAL */
/* #undef _LIBCPP_HAS_THREAD_API_WIN32 */
/* #undef _LIBCPP_HAS_THREAD_LIBRARY_EXTERNAL */
/* #undef _LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS */
#define _LIBCPP_HAS_NO_VENDOR_AVAILABILITY_ANNOTATIONS
/* #undef _LIBCPP_NO_VCRUNTIME */
/* #undef _LIBCPP_TYPEINFO_COMPARISON_IMPLEMENTATION */
/* #undef _LIBCPP_HAS_NO_FILESYSTEM_LIBRARY */
/* #undef _LIBCPP_HAS_PARALLEL_ALGORITHMS */
/* #undef _LIBCPP_HAS_NO_RANDOM_DEVICE */
/* #undef _LIBCPP_HAS_NO_LOCALIZATION */
/* #undef _LIBCPP_HAS_NO_WIDE_CHARACTERS */

// Settings below aren't part of __config_site upstream.
// We set them here since we want them to take effect everywhere,
// unconditionally.

// Prevent libc++ from embedding linker flags to try to automatically link
// against its runtime library. This is unnecessary with our build system,
// and can also result in build failures if libc++'s name for a library
// does not match ours. Only has an effect on Windows.
#define _LIBCPP_NO_AUTO_LINK

#define _LIBCPP_REMOVE_TRANSITIVE_INCLUDES

// Explicitly define _LIBCPP_VERBOSE_ABORT(...) to call the termination
// function because by default, this macro will does not call the verbose
// termination function on Apple platforms.
#define _LIBCPP_VERBOSE_ABORT(...) ::std::__libcpp_verbose_abort(__VA_ARGS__)

#endif // _LIBCPP_CONFIG_SITE
2 changes: 1 addition & 1 deletion buildtools/third_party/libc++/trunk
Submodule trunk updated from d9040c to 6f4617
29 changes: 19 additions & 10 deletions buildtools/third_party/libc++abi/BUILD.gn
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2015 The Chromium Authors. All rights reserved.
# Copyright 2015 The Chromium Authors
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

Expand All @@ -12,9 +12,9 @@ source_set("libc++abi") {
}

# Fuchsia builds don't link against any libraries that provide stack
# unwinding symbols, unlike Linux does with glibc. Build and link against
# libunwind manually to get this functionality.
if (is_fuchsia) {
# unwinding symbols, unlike Linux does with glibc (same applies for Android).
# Build and link against libunwind manually to get this functionality.
if (is_fuchsia || is_android) {
deps = [ "//buildtools/third_party/libunwind" ]
}

Expand All @@ -30,7 +30,6 @@ source_set("libc++abi") {
# libc++abi. We build lib++/libc++abi with exceptions enabled.
#"trunk/src/cxa_noexception.cpp",
"trunk/src/cxa_personality.cpp",
"trunk/src/cxa_unexpected.cpp",
"trunk/src/cxa_vector.cpp",
"trunk/src/cxa_virtual.cpp",
"trunk/src/fallback_malloc.cpp",
Expand All @@ -46,20 +45,19 @@ source_set("libc++abi") {

# See the comment in cxa_demangle_stub.cc for why we don't use LLVM's
# demangler on android.
# TODO(thakis): Switch to building with LIBCXXABI_NON_DEMANGLING_TERMINATE
# defined instead.
if (is_android) {
sources += [ "cxa_demangle_stub.cc" ]
} else {
sources += [ "trunk/src/cxa_demangle.cpp" ]
}

if (is_fuchsia || (is_posix && !is_mac && !is_ios)) {
if (is_fuchsia || (is_posix && !is_apple)) {
sources += [ "trunk/src/cxa_thread_atexit.cpp" ]
}

defines = [
"LIBCXXABI_SILENT_TERMINATE",
"_LIBCPP_ENABLE_CXX17_REMOVED_UNEXPECTED_FUNCTIONS",
]
defines = [ "LIBCXXABI_SILENT_TERMINATE" ]

configs -= [
"//build/config/compiler:chromium_code",
Expand All @@ -74,8 +72,19 @@ source_set("libc++abi") {
"//buildtools/third_party/libc++:config",
]

# private_typeinfo.cpp implements __dynamic_cast(), which is the runtime
# bit that implements dynamic_cast<>(). But ubsan's vptr check inserts
# dynamic_cast<>()s, which leads to infinite recursion. So make sure we don't
# pass -fsanitize=vptr.
configs -= [ "//build/config/sanitizers:default_sanitizer_flags" ]
configs +=
[ "//build/config/sanitizers:default_sanitizer_flags_but_ubsan_vptr" ]

if (export_libcxxabi_from_executables || libcxx_is_shared) {
configs -= [ "//build/config/gcc:symbol_visibility_hidden" ]
configs += [ "//build/config/gcc:symbol_visibility_default" ]
}

# libc++abi depends on libc++ internals.
include_dirs = [ "../libc++/trunk/src" ]
}
4 changes: 2 additions & 2 deletions buildtools/third_party/libc++abi/OWNERS
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
earthdok@chromium.org
glider@chromium.org
thakis@chromium.org
thomasanderson@chromium.org
Loading

0 comments on commit 3048d1f

Please sign in to comment.