Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[libunwind] Add v1.8.1 #7959

Merged
merged 12 commits into from
Jun 13, 2024
78 changes: 78 additions & 0 deletions L/LibUnwind/LibUnwind@1.8.0/build_tarballs.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
using BinaryBuilder

name = "LibUnwind"
version = v"1.8.0"

# Collection of sources required to build libunwind
sources = [
ArchiveSource("https://github.com/libunwind/libunwind/releases/download/v$(version)/libunwind-$(version).tar.gz",
"b6b3df40a0970c8f2865fb39aa2af7b5d6f12ad6c5774e266ccca4d6b8b72268"),
DirectorySource("./bundled"),
]

# Bash recipe for building across all platforms
script = raw"""
cd $WORKSPACE/srcdir/libunwind*/

atomic_patch -p0 ${WORKSPACE}/srcdir/patches/libunwind-configure-static-lzma.patch
if [[ ${target} == aarch64-linux-musl ]]; then
# https://github.com/checkpoint-restore/criu/issues/934, fixed by
# https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit?id=9966a05c7b80f075f2bc7e48dbb108d3f2927234
pushd /opt/aarch64-linux-musl/aarch64-linux-musl/sys-root/usr/include
atomic_patch -p5 ${WORKSPACE}/srcdir/patches/linux-disentangle_sigcontext.patch
popd
fi
# https://github.com/JuliaLang/julia/issues/51467, and
# https://github.com/JuliaLang/julia/issues/51465, caused by
# https://github.com/libunwind/libunwind/pull/203
atomic_patch -p1 ${WORKSPACE}/srcdir/patches/libunwind-revert_prelink_unwind.patch

if [[ ${bb_full_target} == *-sanitize+memory* ]]; then
# Install msan runtime (for clang)
cp -rL ${libdir}/linux/* /opt/x86_64-linux-musl/lib/clang/*/lib/linux/
fi

export CFLAGS="-DPI -fPIC"
./configure \
--prefix=${prefix} \
--build=${MACHTYPE} \
--host=${target} \
--libdir=${libdir} \
--enable-minidebuginfo \
--enable-zlibdebuginfo \
--disable-tests \
--disable-conservative-checks
make -j${nproc}
make install

# Shoe-horn liblzma.a into libunwind.a
mkdir -p unpacked/{liblzma,libunwind}
(cd unpacked/liblzma; ar -x ${prefix}/lib/liblzma.a)
(cd unpacked/libunwind; ar -x ${prefix}/lib/libunwind.a)
rm -f ${prefix}/lib/libunwind.a
ar -qc ${prefix}/lib/libunwind.a unpacked/**/*
"""

# These are the platforms we will build for by default, unless further
# platforms are passed in on the command line. libunwind is only used
# on Linux or FreeBSD (e.g. ELF systems)
platforms = filter(p -> Sys.islinux(p) || Sys.isfreebsd(p), supported_platforms())
push!(platforms, Platform("x86_64", "linux"; sanitize="memory"))

# The products that we will ensure are always built
products = [
LibraryProduct("libunwind", :libunwind),
]

# Dependencies that must be installed before this package can be built
dependencies = [
BuildDependency("XZ_jll"),
Dependency("Zlib_jll"),
BuildDependency("LLVMCompilerRT_jll"; platforms=[Platform("x86_64", "linux"; sanitize="memory")]),
]

# Build the tarballs. Note that libunwind started using `stdatomic.h`, which is only
# available with GCC version 4.9 or later, so we need to set a higher preferred version
# than the default.
build_tarballs(ARGS, name, version, sources, script, platforms, products, dependencies;
julia_compat="1.10", preferred_gcc_version=v"5")
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
--- configure.orig 2023-06-04 05:19:04
+++ configure 2023-06-07 08:35:11
@@ -18117,7 +18117,7 @@
$as_echo_n "(cached) " >&6
else
ac_check_lib_save_LIBS=$LIBS
-LIBS="-llzma $LIBS"
+LIBS="-L/workspace/destdir/lib -l:liblzma.a $LIBS"
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h. */

@@ -18148,7 +18148,7 @@
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_lzma_lzma_mf_is_supported" >&5
$as_echo "$ac_cv_lib_lzma_lzma_mf_is_supported" >&6; }
if test "x$ac_cv_lib_lzma_lzma_mf_is_supported" = xyes; then :
- LIBLZMA=-llzma
+ LIBLZMA="-L/workspace/destdir/lib -l:liblzma.a"

$as_echo "#define HAVE_LZMA 1" >>confdefs.h

Original file line number Diff line number Diff line change
@@ -0,0 +1,187 @@
From 3af39d34f576890e7f1f3e97cc1cb45b4b76aa47 Mon Sep 17 00:00:00 2001
From: Tim Besard <tim.besard@gmail.com>
Date: Tue, 16 Jan 2024 09:49:21 -0800
Subject: [PATCH] Revert "Fix unwinding of pre-linked libraries"

This reverts commit a4014f33775321b4106a1134b89020a7774902dd,
which regresses unwinding on FreeBSD (JuliaLang/julia#51467).
---
include/dwarf.h | 2 --
include/libunwind-dynamic.h | 1 -
src/dwarf/Gfind_proc_info-lsb.c | 42 +++++++--------------------------
src/dwarf/Gfind_unwind_table.c | 1 -
4 files changed, 8 insertions(+), 38 deletions(-)

diff --git a/include/dwarf.h b/include/dwarf.h
index 4fd1dba0..3fc6bce2 100644
--- a/include/dwarf.h
+++ b/include/dwarf.h
@@ -371,8 +371,6 @@ struct unw_debug_frame_list
/* The start (inclusive) and end (exclusive) of the described region. */
unw_word_t start;
unw_word_t end;
- /* ELF load offset */
- unw_word_t load_offset;
/* The debug frame itself. */
char *debug_frame;
size_t debug_frame_size;
diff --git a/include/libunwind-dynamic.h b/include/libunwind-dynamic.h
index a26f2c99..c902ccd9 100644
--- a/include/libunwind-dynamic.h
+++ b/include/libunwind-dynamic.h
@@ -141,7 +141,6 @@ typedef struct unw_dyn_info
unw_word_t gp; /* global-pointer in effect for this entry */
int32_t format; /* real type: unw_dyn_info_format_t */
int32_t pad;
- unw_word_t load_offset; /* ELF load offset */
union
{
unw_dyn_proc_info_t pi;
diff --git a/src/dwarf/Gfind_proc_info-lsb.c b/src/dwarf/Gfind_proc_info-lsb.c
index c11345e8..c701ccfb 100644
--- a/src/dwarf/Gfind_proc_info-lsb.c
+++ b/src/dwarf/Gfind_proc_info-lsb.c
@@ -108,17 +108,13 @@ linear_search (unw_addr_space_t as, unw_word_t ip,

static int
load_debug_frame (const char *file, char **buf, size_t *bufsize, int is_local,
- unw_word_t segbase, unw_word_t *load_offset)
+ unw_word_t segbase)
{
struct elf_image ei;
- Elf_W (Ehdr) *ehdr;
- Elf_W (Phdr) *phdr;
Elf_W (Shdr) *shdr;
- int i;
int ret;

ei.image = NULL;
- *load_offset = 0;

ret = elf_w (load_debuginfo) (file, &ei, is_local);
if (ret != 0)
@@ -193,20 +189,6 @@ load_debug_frame (const char *file, char **buf, size_t *bufsize, int is_local,
#if defined(SHF_COMPRESSED)
}
#endif
-
- ehdr = ei.image;
- phdr = (Elf_W (Phdr) *) ((char *) ei.image + ehdr->e_phoff);
-
- for (i = 0; i < ehdr->e_phnum; ++i)
- if (phdr[i].p_type == PT_LOAD)
- {
- *load_offset = segbase - phdr[i].p_vaddr;
-
- Debug (4, "%s load offset is 0x%zx\n", file, *load_offset);
-
- break;
- }
-
mi_munmap(ei.image, ei.size);
return 0;
}
@@ -259,7 +241,6 @@ locate_debug_info (unw_addr_space_t as, unw_word_t addr, unw_word_t segbase,
int err;
char *buf;
size_t bufsize;
- unw_word_t load_offset;

/* First, see if we loaded this frame already. */

@@ -287,7 +268,7 @@ locate_debug_info (unw_addr_space_t as, unw_word_t addr, unw_word_t segbase,
name = (char*) dlname;

err = load_debug_frame (name, &buf, &bufsize, as == unw_local_addr_space,
- segbase, &load_offset);
+ segbase);

if (!err)
{
@@ -300,7 +281,6 @@ locate_debug_info (unw_addr_space_t as, unw_word_t addr, unw_word_t segbase,

fdesc->start = start;
fdesc->end = end;
- fdesc->load_offset = load_offset;
fdesc->debug_frame = buf;
fdesc->debug_frame_size = bufsize;
fdesc->index = NULL;
@@ -497,7 +477,6 @@ dwarf_find_debug_frame (int found, unw_dyn_info_t *di_debug, unw_word_t ip,
di->format = UNW_INFO_FORMAT_TABLE;
di->start_ip = fdesc->start;
di->end_ip = fdesc->end;
- di->load_offset = fdesc->load_offset;
di->u.ti.name_ptr = (unw_word_t) (uintptr_t) obj_name;
di->u.ti.table_data = (unw_word_t *) fdesc;
di->u.ti.table_len = sizeof (*fdesc) / sizeof (unw_word_t);
@@ -960,14 +939,12 @@ dwarf_search_unwind_table (unw_addr_space_t as, unw_word_t ip,
ip_base = segbase;
}

- Debug (6, "lookup IP 0x%lx\n", (long) (ip - ip_base - di->load_offset));
-
#ifndef UNW_REMOTE_ONLY
if (as == unw_local_addr_space)
{
- e = lookup (table, table_len, ip - ip_base - di->load_offset);
+ e = lookup (table, table_len, ip - ip_base);
if (e && &e[1] < &table[table_len / sizeof (struct table_entry)])
- last_ip = e[1].start_ip_offset + ip_base + di->load_offset;
+ last_ip = e[1].start_ip_offset + ip_base;
else
last_ip = di->end_ip;
}
@@ -975,7 +952,7 @@ dwarf_search_unwind_table (unw_addr_space_t as, unw_word_t ip,
#endif
{
#ifndef UNW_LOCAL_ONLY
- int32_t last_ip_offset = di->end_ip - ip_base - di->load_offset;
+ int32_t last_ip_offset = di->end_ip - ip_base;
segbase = di->u.rti.segbase;
if ((ret = remote_lookup (as, (uintptr_t) table, table_len,
ip - ip_base, &ent, &last_ip_offset, arg)) < 0)
@@ -983,7 +960,7 @@ dwarf_search_unwind_table (unw_addr_space_t as, unw_word_t ip,
if (ret)
{
e = &ent;
- last_ip = last_ip_offset + ip_base + di->load_offset;
+ last_ip = last_ip_offset + ip_base;
}
else
e = NULL; /* no info found */
@@ -997,8 +974,8 @@ dwarf_search_unwind_table (unw_addr_space_t as, unw_word_t ip,
unwind info. */
return -UNW_ENOINFO;
}
- Debug (15, "ip=0x%lx, load_offset=0x%lx, start_ip=0x%lx\n",
- (long) ip, (long) di->load_offset, (long) (e->start_ip_offset));
+ Debug (15, "ip=0x%lx, start_ip=0x%lx\n",
+ (long) ip, (long) (e->start_ip_offset));
if (debug_frame_base)
fde_addr = e->fde_offset + debug_frame_base;
else
@@ -1022,9 +999,6 @@ dwarf_search_unwind_table (unw_addr_space_t as, unw_word_t ip,
pi->flags = UNW_PI_FLAG_DEBUG_FRAME;
}

- pi->start_ip += di->load_offset;
- pi->end_ip += di->load_offset;
-
#if defined(NEED_LAST_IP)
pi->last_ip = last_ip;
#else
diff --git a/src/dwarf/Gfind_unwind_table.c b/src/dwarf/Gfind_unwind_table.c
index a7c4dfd3..2b503ea9 100644
--- a/src/dwarf/Gfind_unwind_table.c
+++ b/src/dwarf/Gfind_unwind_table.c
@@ -197,7 +197,6 @@ dwarf_find_unwind_table (struct elf_dyn_info *edi,

edi->di_cache.start_ip = start_ip;
edi->di_cache.end_ip = end_ip;
- edi->di_cache.load_offset = 0;
edi->di_cache.format = UNW_INFO_FORMAT_REMOTE_TABLE;
edi->di_cache.u.rti.name_ptr = 0;
/* two 32-bit values (ip_offset/fde_offset) per table-entry: */
--
2.43.0

Loading