Sebastian Huber commented: 
https://gitlab.rtems.org/rtems/rtos/rtems/-/merge_requests/1505#note_159957


Thanks for looking into #5225. I think this change breaks the `R_ARM_PREL31` 
relocation, and I suggest that we do not merge it.

The caller stores the return value of `sign_extend31()` directly in the place, 
see lines 370 to 373 and 384 to 386. `R_ARM_PREL31` writes only bits 30:0 of 
the place. Bit 31 of the place has a meaning of its own. Binutils applies the 
relocation like this (`bfd/elf32-arm.c`):

```c
value &= 0x7fffffff;
value |= (bfd_get_32 (input_bfd, hit_data) & 0x80000000);
```

The current code masks the result to 31 bits and so writes the correct field. 
The addend is not sign-extended, but the error is a multiple of 2^31 and the 
mask removes it.

With this change, a negative offset sets bit 31 of the place. In the second 
word of an `.ARM.exidx` entry, bit 31 marks an inline compact unwind entry. The 
libgcc unwinder tests this bit before it reads the word as a PREL31 offset. A 
module with `.ARM.extab` below `.ARM.exidx` then gets unwind opcodes decoded 
from an offset. The EHABI also requires bit 31 of the first word to be zero.

Commit c6eead1353e0 moved the subtraction into the function (`tmp = 
sign_extend31(tmp - (Elf_Addr)where)`) in the same change. That commit added 
the C++ exception support and was tested on ARM. The mask looks deliberate to 
me.

The problem of #5225 is the name of the function, not its result. A fix could:

- rename the function, for example to `prel31_field()`, and remove the dead 
branch,
- preserve bit 31 of the place as binutils does,
- optionally check for overflow with `(value ^ (value >> 1)) & (1 << 30)`.

-- 
View it on GitLab: 
https://gitlab.rtems.org/rtems/rtos/rtems/-/merge_requests/1505#note_159957
You're receiving this email because of your account on gitlab.rtems.org. 
Unsubscribe from this thread: 
https://gitlab.rtems.org/-/namespace/49/sent_notifications/5-32hr9b0p924linermwnt91kvo-1d/unsubscribe
 | Manage all notifications: https://gitlab.rtems.org/-/profile/notifications | 
Help: https://gitlab.rtems.org/help


_______________________________________________
bugs mailing list
[email protected]
http://lists.rtems.org/mailman/listinfo/bugs

Reply via email to