[packages/mold] upstream fix for crash on %{arm} when throwing cpp exception

atler atler at pld-linux.org
Sat Aug 20 16:00:34 CEST 2022


commit ccc1822574b47f438a3ca8ba8df32952b2bc9db6
Author: Jan Palus <atler at pld-linux.org>
Date:   Sat Aug 20 15:49:10 2022 +0200

    upstream fix for crash on %{arm} when throwing cpp exception
    
    see: https://github.com/rui314/mold/issues/646

 arm-exception-crash.patch | 86 +++++++++++++++++++++++++++++++++++++++++++++++
 mold.spec                 |  2 ++
 2 files changed, 88 insertions(+)
---
diff --git a/mold.spec b/mold.spec
index 6c7cdf5..7742129 100644
--- a/mold.spec
+++ b/mold.spec
@@ -10,6 +10,7 @@ License:	GPL v3+
 Group:		Development/Libraries
 Source0:	https://github.com/rui314/mold/archive/v%{version}/%{name}-%{version}.tar.gz
 # Source0-md5:	e21fff1962e98787ea0636d68d6369af
+Patch0:		arm-exception-crash.patch
 URL:		https://github.com/rui314/mold
 %{?with_tests:BuildRequires:	glibc-static}
 %ifarch %{armv6} riscv64
@@ -36,6 +37,7 @@ especially in rapid debug-edit-rebuild cycles.
 
 %prep
 %setup -q
+%patch0 -p1
 
 %{__rm} -r third-party/{mimalloc,tbb}
 
diff --git a/arm-exception-crash.patch b/arm-exception-crash.patch
new file mode 100644
index 0000000..e762e53
--- /dev/null
+++ b/arm-exception-crash.patch
@@ -0,0 +1,86 @@
+From 71daaa22dfaa3a99599c08b0d6681cb05b18e4ae Mon Sep 17 00:00:00 2001
+From: Rui Ueyama <ruiu at bluewhale.systems>
+Date: Sat, 20 Aug 2022 21:19:33 +0800
+Subject: [PATCH] [ELF] Fix ARM32 exception handling
+
+Fixes https://github.com/rui314/mold/issues/646
+---
+ elf/arch-arm32.cc    |  8 ++++----
+ test/elf/issue646.sh | 40 ++++++++++++++++++++++++++++++++++++++++
+ 2 files changed, 44 insertions(+), 4 deletions(-)
+ create mode 100755 test/elf/issue646.sh
+
+diff --git a/elf/arch-arm32.cc b/elf/arch-arm32.cc
+index a470136d..473f50e1 100644
+--- a/elf/arch-arm32.cc
++++ b/elf/arch-arm32.cc
+@@ -583,9 +583,9 @@ void sort_arm_exidx(Context<E> &ctx) {
+ 
+   tbb::parallel_for((i64)0, num_entries, [&](i64 i) {
+     i64 offset = sizeof(Entry) * i;
+-    ent[i].addr = sign_extend(ent[i].addr, 30) - offset;
++    ent[i].addr = sign_extend(ent[i].addr, 30) + offset;
+     if (is_relative(ent[i].val))
+-      ent[i].val = 0x7fff'ffff & (sign_extend(ent[i].val, 30) - offset);
++      ent[i].val = 0x7fff'ffff & (sign_extend(ent[i].val, 30) + offset);
+   });
+ 
+   tbb::parallel_sort(ent, ent + num_entries, [](const Entry &a, const Entry &b) {
+@@ -595,9 +595,9 @@ void sort_arm_exidx(Context<E> &ctx) {
+   // Write back the sorted records while adjusting relative addresses
+   tbb::parallel_for((i64)0, num_entries, [&](i64 i) {
+     i64 offset = sizeof(Entry) * i;
+-    ent[i].addr = 0x7fff'ffff & (ent[i].addr + offset);
++    ent[i].addr = 0x7fff'ffff & (ent[i].addr - offset);
+     if (is_relative(ent[i].val))
+-      ent[i].val = 0x7fff'ffff & (ent[i].val + offset);
++      ent[i].val = 0x7fff'ffff & (ent[i].val - offset);
+   });
+ }
+ 
+diff --git a/test/elf/issue646.sh b/test/elf/issue646.sh
+new file mode 100755
+index 00000000..816fca9b
+--- /dev/null
++++ b/test/elf/issue646.sh
+@@ -0,0 +1,40 @@
++#!/bin/bash
++export LC_ALL=C
++set -e
++CC="${TEST_CC:-cc}"
++CXX="${TEST_CXX:-c++}"
++GCC="${TEST_GCC:-gcc}"
++GXX="${TEST_GXX:-g++}"
++OBJDUMP="${OBJDUMP:-objdump}"
++MACHINE="${MACHINE:-$(uname -m)}"
++testname=$(basename "$0" .sh)
++echo -n "Testing $testname ... "
++t=out/test/elf/$MACHINE/$testname
++mkdir -p $t
++
++cat <<EOF | $CXX -o $t/a.o -c -xc++ -
++#include <iostream>
++#include <stdexcept>
++
++class Foo : public std::runtime_error {
++public:
++  using std::runtime_error::runtime_error;
++};
++
++static void do_throw() {
++  throw Foo("exception");
++}
++
++int main() {
++  try {
++    do_throw();
++  } catch (const Foo &e) {
++    std::cout << "error: " << e.what() << std::endl;
++  }
++}
++EOF
++
++$CXX -B. -o $t/exe $t/a.o
++$QEMU $t/exe | grep -q 'error: exception'
++
++echo OK
================================================================

---- gitweb:

http://git.pld-linux.org/gitweb.cgi/packages/mold.git/commitdiff/ccc1822574b47f438a3ca8ba8df32952b2bc9db6



More information about the pld-cvs-commit mailing list