]> git.pld-linux.org Git - packages/mold.git/commitdiff
upstream fix for crash on %{arm} when throwing cpp exception
authorJan Palus <atler@pld-linux.org>
Sat, 20 Aug 2022 13:49:10 +0000 (15:49 +0200)
committerJan Palus <atler@pld-linux.org>
Sat, 20 Aug 2022 13:49:10 +0000 (15:49 +0200)
see: https://github.com/rui314/mold/issues/646

arm-exception-crash.patch [new file with mode: 0644]
mold.spec

diff --git a/arm-exception-crash.patch b/arm-exception-crash.patch
new file mode 100644 (file)
index 0000000..e762e53
--- /dev/null
@@ -0,0 +1,86 @@
+From 71daaa22dfaa3a99599c08b0d6681cb05b18e4ae Mon Sep 17 00:00:00 2001
+From: Rui Ueyama <ruiu@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
index 6c7cdf5df9741b5f7159ed51452b1abb91a0cd57..7742129ba38bef1a9951d4d11788966a09cb212e 100644 (file)
--- 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}
 
This page took 0.214263 seconds and 4 git commands to generate.