-/* Copyright (C) 2001-2022 Free Software Foundation, Inc.
+/* Copyright (C) 2001-2024 Free Software Foundation, Inc.
Contributed by Jakub Jelinek <jakub@redhat.com>.
This file is part of GCC.
if (hdr->version != 1)
return NULL;
- p = read_encoded_value_with_base (hdr->eh_frame_ptr_enc,
- base_from_cb_data (hdr->eh_frame_ptr_enc,
- dbase),
- p, &eh_frame);
+ if (__builtin_expect (hdr->eh_frame_ptr_enc == (DW_EH_PE_sdata4
+ | DW_EH_PE_pcrel), 1))
+ {
+ /* Specialized version of read_encoded_value_with_base, based on what
+ BFD ld generates. */
+ signed value __attribute__ ((mode (SI)));
+ memcpy (&value, p, sizeof (value));
+ eh_frame = (_Unwind_Ptr) (p + value);
+ p += sizeof (value);
+ }
+ else
+ p = read_encoded_value_with_base (hdr->eh_frame_ptr_enc,
+ base_from_cb_data (hdr->eh_frame_ptr_enc,
+ dbase),
+ p, &eh_frame);
/* We require here specific table encoding to speed things up.
Also, DW_EH_PE_datarel here means using PT_GNU_EH_FRAME start
{
_Unwind_Ptr fde_count;
- p = read_encoded_value_with_base (hdr->fde_count_enc,
- base_from_cb_data (hdr->fde_count_enc,
- dbase),
- p, &fde_count);
+ if (__builtin_expect (hdr->fde_count_enc == DW_EH_PE_udata4, 1))
+ {
+ /* Specialized version of read_encoded_value_with_base, based on
+ what BFD ld generates. */
+ unsigned value __attribute__ ((mode (SI)));
+ memcpy (&value, p, sizeof (value));
+ p += sizeof (value);
+ fde_count = value;
+ }
+ else
+ p = read_encoded_value_with_base (hdr->fde_count_enc,
+ base_from_cb_data (hdr->fde_count_enc,
+ dbase),
+ p, &fde_count);
/* Shouldn't happen. */
if (fde_count == 0)
return NULL;
f = (fde *) (table[mid].fde + data_base);
f_enc = get_fde_encoding (f);
f_enc_size = size_of_encoded_value (f_enc);
- read_encoded_value_with_base (f_enc & 0x0f, 0,
- &f->pc_begin[f_enc_size], &range);
+
+ /* BFD ld uses DW_EH_PE_sdata4 | DW_EH_PE_pcrel on non-FDPIC targets,
+ so optimize for that.
+
+ This optimization is not valid for FDPIC targets. f_enc & 0x0f as
+ passed to read_encoded_value_with_base masks away the base flags,
+ but they are implicit for FDPIC. */
+#ifndef __FDPIC__
+ if (__builtin_expect (f_enc == (DW_EH_PE_sdata4 | DW_EH_PE_pcrel),
+ 1))
+ {
+ signed value __attribute__ ((mode (SI)));
+ memcpy (&value, &f->pc_begin[f_enc_size], sizeof (value));
+ range = value;
+ }
+ else
+#endif
+ read_encoded_value_with_base (f_enc & 0x0f, 0,
+ &f->pc_begin[f_enc_size], &range);
_Unwind_Ptr func = table[mid].initial_loc + data_base;
if (pc < table[mid].initial_loc + data_base + range)
{
return ret;
/* Use DLFO_STRUCT_HAS_EH_DBASE as a proxy for the existence of a glibc-style
- _dl_find_object function. */
-#ifdef DLFO_STRUCT_HAS_EH_DBASE
+ _dl_find_object function. However, do not use _dl_find_object on nios2,
+ which uses the GOT address as the base for DW_EH_PE_datarel instead. */
+#if defined(DLFO_STRUCT_HAS_EH_DBASE) && !defined(__nios2__)
{
struct dl_find_object dlfo;
if (_dl_find_object (pc, &dlfo) == 0 && dlfo.dlfo_eh_frame != NULL)
# if DLFO_STRUCT_HAS_EH_DBASE
(_Unwind_Ptr) dlfo.dlfo_eh_dbase,
# else
- NULL,
+ 0,
# endif
bases);
else