#2767 closed defect (fixed)

libdl exceptions throw/catch (ARM PREL31 and TARGET2 relocation support)

Reported by: Patrick Gauvin Owned by: Chris Johns
Priority: normal Milestone:
Component: lib/dl Version: 4.11
Severity: normal Keywords:
Cc: Ryan Slabaugh Blocked By:
Blocking:

Description

The PREL31 and TARGET2 relocation types are used in exception tables on ARM. dlopen on C++ code often fails because the loader does not recognize them. From what I've seen, PREL31 relocations are generally present in C++ object files, but if exceptions are used both will be present.

Attached is a patch which implements them based on the references below. My understanding is not complete, however, so it may be incorrect. A test case which generates these relocations and uses libdl to load them is also attached. I have not been able to verify that the patch functions correctly because I am not sure how to trigger an operation that would fail if PREL31/TARGET2 relocations were not handled correctly.

Something to note about the patch; PREL31 is not present in 64 bit ARM, so it may be possible to optimize the sign extension code.

Expected outputs (with the patch applied to RTEMS):

$ qemu-system-arm -kernel libdl-prel31-target2-test.exe -m 256M -M xilinx-zynq-a9 -serial null -serial mon:stdio -nographic -no-reboot
TEST BEGIN
terminate called after throwing an instance of 'std::runtime_error'
  what():  func threw
$ qemu-system-arm -kernel libdl-prel31-target2-test-builtin.exe -m 256M -M xilinx-zynq-a9 -serial null -serial mon:stdio -nographic -no-reboot
TEST BEGIN
func: Caught exception, e.what: "func threw"
TEST END

Expected relocations:

$ arm-rtems4.11-objdump -r libfoo.o |env grep -e 'TARGET2\|PREL31' -a2
RELOCATION RECORDS FOR [.ARM.extab]:
OFFSET   TYPE              VALUE
00000000 R_ARM_PREL31      __gxx_personality_v0
00000040 R_ARM_TARGET2     _ZTISt13runtime_error


RELOCATION RECORDS FOR [.ARM.exidx]:
OFFSET   TYPE              VALUE
00000000 R_ARM_PREL31      .text
00000004 R_ARM_PREL31      .ARM.extab


References:

  • ELF for the ARM Architecture
  • Exception Handling ABI for the ARM Architecture

Development Environment:

arm-rtems4.11-gcc (GCC) 4.9.3 20150626 (RTEMS 4.11, RSB 1675a733536d1aec2020011e5e522497a442561a (HEAD, origin/4.11, 4.11), Newlib 2.2.0.20150423)

  • RTEMS Configure Options:

--target=arm-rtems4.11 --enable-rtemsbsp="xilinx_zynq_a9_qemu xilinx_zynq_zedboard xilinx_zynq_csp_cots xilinx_zynq_csp_hybrid" --enable-tests=samples --enable-posix --prefix=$HOME/development/rtems/4.11 --disable-networking

Attachments (2)

rtems-libdl-arm-prel31-target2.patch (2.4 KB) - added by Patrick Gauvin on Jul 29, 2016 at 5:12:39 AM.
libdl-prel31-target2-test.tar.gz (2.1 KB) - added by Patrick Gauvin on Jul 29, 2016 at 5:13:27 AM.

Download all attachments as: .zip

Change History (6)

Changed on Jul 29, 2016 at 5:12:39 AM by Patrick Gauvin

Changed on Jul 29, 2016 at 5:13:27 AM by Patrick Gauvin

comment:1 Changed on Sep 6, 2016 at 6:15:14 AM by Chris Johns

Yes a review of the ARM's Exception Handling ABi shows both relocation types are used. The patch looks fine.

comment:2 Changed on Sep 8, 2016 at 6:47:49 AM by Chris Johns

I have investigated the reason 'terminate' is called when the throw and catch happens in the dynamic module. Terminate is called because the exception processing code resident in the base image does not see the exception data in the dynamically loaded module, it only has access to the exception data in the base image.

The problem space is made more complex because each arch can have a specific way of handling exceptions. A possible solution for ARM may not be available for other architectures. A quick review of the libgcc code responsible for handling run-time exceptions shows a possible solution for ARM via a weak function and the other architectures are DWARF based.

comment:3 Changed on Oct 4, 2016 at 10:59:09 PM by Chris Johns

Status: newassigned
Summary: ARM PREL31 and TARGET2 relocation supportlibdl exceptions throw/catch (ARM PREL31 and TARGET2 relocation support)
Type: enhancementdefect

comment:4 Changed on Dec 13, 2016 at 10:34:16 PM by Chris Johns <chrisj@…>

Resolution: fixed
Status: assignedclosed

In c6eead1353e03542e5bad9efda3b6553125520d8/rtems:

libdl: Add C++ exception support to loaded modules.

This has been tested on SPARC, i386, PowerPC and ARM.

Closes #2767.

Note: See TracTickets for help on using tickets.