From 9d9037deb2d0ae05e5e99f371a2ef97230895fcd Mon Sep 17 00:00:00 2001 From: Andrija Date: Thu, 24 Oct 2024 13:47:04 +0200 Subject: [PATCH] [nanoMIPS] Add eh_frame start and end symbols eh_frame start and end symbols need to be defined if there is an eh_frame section. Unwinding depends on these symbols. --- gold/nanomips.cc | 74 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 74 insertions(+) diff --git a/gold/nanomips.cc b/gold/nanomips.cc index 9bc47d5122ee..62bed7a58650 100644 --- a/gold/nanomips.cc +++ b/gold/nanomips.cc @@ -2141,6 +2141,11 @@ class Target_nanomips : public Sized_target sections.insert(".nanoMIPS.abiflags"); } + // Defines eh_frame and eh_frame_hdr start and end symbols if these + // sections are defined. + void + do_define_standard_symbols(Symbol_table*, Layout*); + private: // The class which scans relocations. class Scan @@ -2342,6 +2347,12 @@ class Target_nanomips : public Sized_target void set_gp(Layout*, Symbol_table*); + // Define start and end symbols, used to define eh_frame start and + // end + void + define_start_end_symbols(const char* start, const char* end, + Symbol_table*, Output_section*); + // Information about this specific target which we pass to the // general Target structure. static const Target::Target_info nanomips_info; @@ -6643,6 +6654,69 @@ Target_nanomips::do_finalize_sections( this->rel_dyn_, true, false); } +template +void +Target_nanomips::do_define_standard_symbols( + Symbol_table* symtab, + Layout* layout) +{ + Output_section* eh_frame_section = + layout->find_output_section(".eh_frame"); + + if (eh_frame_section != NULL) + { + this->define_start_end_symbols("__eh_frame_start", + "__eh_frame_end", + symtab, + eh_frame_section); + Output_section* eh_frame_hdr_section = + layout->find_output_section(".eh_frame_hdr"); + + if (eh_frame_hdr_section != NULL) + this->define_start_end_symbols("__eh_frame_hdr_start", + "__eh_frame_hdr_end", + symtab, + eh_frame_hdr_section); + } +} + +template +void +Target_nanomips::define_start_end_symbols( + const char* start, + const char* end, + Symbol_table* symtab, + Output_section* out_sec) +{ + gold_assert(out_sec != NULL); + + symtab->define_in_output_data(start, + NULL, // version + Symbol_table::PREDEFINED, + out_sec, + 0, // value + 0, // symsize + elfcpp::STT_NOTYPE, + elfcpp::STB_GLOBAL, + elfcpp::STV_HIDDEN, + 0, // nonvis + false, // offset_is_from_end + true); // only_if_ref + + symtab->define_in_output_data(end, + NULL, // version + Symbol_table::PREDEFINED, + out_sec, + 0, // value + 0, // symsize + elfcpp::STT_NOTYPE, + elfcpp::STB_GLOBAL, + elfcpp::STV_HIDDEN, + 0, // nonvis + true, // offset_is_from_end + true); // only_if_ref +} + // Relocate section data. template