Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[nanoMIPS] Add eh_frame start and end symbols #8

Open
wants to merge 1 commit into
base: nmips/gold_v7
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 74 additions & 0 deletions gold/nanomips.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2141,6 +2141,11 @@ class Target_nanomips : public Sized_target<size, big_endian>
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
Expand Down Expand Up @@ -2342,6 +2347,12 @@ class Target_nanomips : public Sized_target<size, big_endian>
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;
Expand Down Expand Up @@ -6643,6 +6654,69 @@ Target_nanomips<size, big_endian>::do_finalize_sections(
this->rel_dyn_, true, false);
}

template <int size, bool big_endian>
void
Target_nanomips<size, big_endian>::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",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

indentation

"__eh_frame_hdr_end",
symtab,
eh_frame_hdr_section);
}
}

template <int size, bool big_endian>
void
Target_nanomips<size, big_endian>::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<int size, bool big_endian>
Expand Down
32 changes: 32 additions & 0 deletions gold/testsuite/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -4927,6 +4927,38 @@ nanomips_fix_hw110880.o: nanomips_fix_hw110880.s

MOSTLYCLEANFILES += nanomips_fix_hw110880

# Test that the eh_frame start/end symbols are properly created
check_SCRIPTS += nanomips_eh_frame_start_end_syms.sh
check_DATA += nanomips_eh_frame_start_end_syms_1.stdout \
nanomips_eh_frame_start_end_syms_2.stdout

nanomips_eh_frame_start_end_syms_2.stdout: nanomips_eh_frame_start_end_syms_2
$(TEST_READELF) -Ss $< > $@

nanomips_eh_frame_start_end_syms_1.stdout: nanomips_eh_frame_start_end_syms_1
$(TEST_READELF) -Ss $< > $@

nanomips_eh_frame_start_end_syms_2: nanomips_eh_frame_start_end_syms_2.o \
../ld-new
../ld-new --section-start .eh_frame=0x1000 --section-start \
.eh_frame_hdr=0x2000 --section-start .text=0x3000 \
--eh-frame-hdr \
nanomips_eh_frame_start_end_syms_2.o -o $@

nanomips_eh_frame_start_end_syms_1: nanomips_eh_frame_start_end_syms_1.o \
../ld-new
../ld-new --section-start .eh_frame=0x1000 --section-start .text=0x2000 \
nanomips_eh_frame_start_end_syms_1.o -o $@

nanomips_eh_frame_start_end_syms_2.o: nanomips_eh_frame_start_end_syms.s
$(TEST_AS) -EL -march=32r6 -m32 --defsym hdr=1 -o $@ $<

nanomips_eh_frame_start_end_syms_1.o: nanomips_eh_frame_start_end_syms.s
$(TEST_AS) -EL -march=32r6 -m32 -o $@ $<

MOSTLYCLEANFILES += nanomips_eh_frame_start_end_syms_1 \
nanomips_eh_frame_start_end_syms_2

endif DEFAULT_TARGET_NANOMIPS

endif NATIVE_OR_CROSS_LINKER
Expand Down
39 changes: 36 additions & 3 deletions gold/testsuite/Makefile.in
Original file line number Diff line number Diff line change
Expand Up @@ -1114,6 +1114,8 @@ check_PROGRAMS = $(am__EXEEXT_1) $(am__EXEEXT_2) $(am__EXEEXT_3) \
# Not nanoMIPS specific, but we only run these tests on host.

# Test that the -fix-nmips-hw110880 performs transformations

# Test that the eh_frame start/end symbols are properly created
@DEFAULT_TARGET_NANOMIPS_TRUE@@NATIVE_OR_CROSS_LINKER_TRUE@am__append_106 = nanomips_pcrel_out_of_range.sh \
@DEFAULT_TARGET_NANOMIPS_TRUE@@NATIVE_OR_CROSS_LINKER_TRUE@ nanomips_gprel_out_of_range.sh \
@DEFAULT_TARGET_NANOMIPS_TRUE@@NATIVE_OR_CROSS_LINKER_TRUE@ nanomips_sort_by_ref.sh \
Expand All @@ -1127,7 +1129,8 @@ check_PROGRAMS = $(am__EXEEXT_1) $(am__EXEEXT_2) $(am__EXEEXT_3) \
@DEFAULT_TARGET_NANOMIPS_TRUE@@NATIVE_OR_CROSS_LINKER_TRUE@ nanomips_saverestore_relax.sh \
@DEFAULT_TARGET_NANOMIPS_TRUE@@NATIVE_OR_CROSS_LINKER_TRUE@ nanomips_bxxzc32_relax.sh \
@DEFAULT_TARGET_NANOMIPS_TRUE@@NATIVE_OR_CROSS_LINKER_TRUE@ nanomips_emit_relocs.sh \
@DEFAULT_TARGET_NANOMIPS_TRUE@@NATIVE_OR_CROSS_LINKER_TRUE@ nanomips_fix_hw110880.sh
@DEFAULT_TARGET_NANOMIPS_TRUE@@NATIVE_OR_CROSS_LINKER_TRUE@ nanomips_fix_hw110880.sh \
@DEFAULT_TARGET_NANOMIPS_TRUE@@NATIVE_OR_CROSS_LINKER_TRUE@ nanomips_eh_frame_start_end_syms.sh
@DEFAULT_TARGET_NANOMIPS_TRUE@@NATIVE_OR_CROSS_LINKER_TRUE@am__append_107 = nanomips_b_out_of_range_pcrel.stdout \
@DEFAULT_TARGET_NANOMIPS_TRUE@@NATIVE_OR_CROSS_LINKER_TRUE@ nanomips_b_out_of_range_insn32_pcrel.stdout \
@DEFAULT_TARGET_NANOMIPS_TRUE@@NATIVE_OR_CROSS_LINKER_TRUE@ nanomips_b_out_of_range_nmf_pcrel.stdout \
Expand Down Expand Up @@ -1191,7 +1194,9 @@ check_PROGRAMS = $(am__EXEEXT_1) $(am__EXEEXT_2) $(am__EXEEXT_3) \
@DEFAULT_TARGET_NANOMIPS_TRUE@@NATIVE_OR_CROSS_LINKER_TRUE@ nanomips_saverestore_relax.stdout \
@DEFAULT_TARGET_NANOMIPS_TRUE@@NATIVE_OR_CROSS_LINKER_TRUE@ nanomips_bxxzc32_relax.stdout \
@DEFAULT_TARGET_NANOMIPS_TRUE@@NATIVE_OR_CROSS_LINKER_TRUE@ nanomips_emit_relocs.stdout \
@DEFAULT_TARGET_NANOMIPS_TRUE@@NATIVE_OR_CROSS_LINKER_TRUE@ nanomips_fix_hw110880.stdout
@DEFAULT_TARGET_NANOMIPS_TRUE@@NATIVE_OR_CROSS_LINKER_TRUE@ nanomips_fix_hw110880.stdout \
@DEFAULT_TARGET_NANOMIPS_TRUE@@NATIVE_OR_CROSS_LINKER_TRUE@ nanomips_eh_frame_start_end_syms_1.stdout \
@DEFAULT_TARGET_NANOMIPS_TRUE@@NATIVE_OR_CROSS_LINKER_TRUE@ nanomips_eh_frame_start_end_syms_2.stdout
@DEFAULT_TARGET_NANOMIPS_TRUE@@NATIVE_OR_CROSS_LINKER_TRUE@am__append_108 = nanomips_b_out_of_range_pcrel \
@DEFAULT_TARGET_NANOMIPS_TRUE@@NATIVE_OR_CROSS_LINKER_TRUE@ nanomips_b_out_of_range_insn32_pcrel \
@DEFAULT_TARGET_NANOMIPS_TRUE@@NATIVE_OR_CROSS_LINKER_TRUE@ nanomips_b_out_of_range_nmf_pcrel \
Expand Down Expand Up @@ -1249,7 +1254,9 @@ check_PROGRAMS = $(am__EXEEXT_1) $(am__EXEEXT_2) $(am__EXEEXT_3) \
@DEFAULT_TARGET_NANOMIPS_TRUE@@NATIVE_OR_CROSS_LINKER_TRUE@ nanomips_saverestore_relax \
@DEFAULT_TARGET_NANOMIPS_TRUE@@NATIVE_OR_CROSS_LINKER_TRUE@ nanomips_bxxzc32_relax \
@DEFAULT_TARGET_NANOMIPS_TRUE@@NATIVE_OR_CROSS_LINKER_TRUE@ nanomips_emit_relocs \
@DEFAULT_TARGET_NANOMIPS_TRUE@@NATIVE_OR_CROSS_LINKER_TRUE@ nanomips_fix_hw110880
@DEFAULT_TARGET_NANOMIPS_TRUE@@NATIVE_OR_CROSS_LINKER_TRUE@ nanomips_fix_hw110880 \
@DEFAULT_TARGET_NANOMIPS_TRUE@@NATIVE_OR_CROSS_LINKER_TRUE@ nanomips_eh_frame_start_end_syms_1 \
@DEFAULT_TARGET_NANOMIPS_TRUE@@NATIVE_OR_CROSS_LINKER_TRUE@ nanomips_eh_frame_start_end_syms_2
@DEFAULT_TARGET_X86_64_TRUE@am__append_109 = *.dwo *.dwp
@DEFAULT_TARGET_X86_64_TRUE@am__append_110 = dwp_test_1.sh \
@DEFAULT_TARGET_X86_64_TRUE@ dwp_test_2.sh
Expand Down Expand Up @@ -5685,6 +5692,8 @@ nanomips_emit_relocs.sh.log: nanomips_emit_relocs.sh
@p='nanomips_emit_relocs.sh'; $(am__check_pre) $(LOG_COMPILE) "$$tst" $(am__check_post)
nanomips_fix_hw110880.sh.log: nanomips_fix_hw110880.sh
@p='nanomips_fix_hw110880.sh'; $(am__check_pre) $(LOG_COMPILE) "$$tst" $(am__check_post)
nanomips_eh_frame_start_end_syms.sh.log: nanomips_eh_frame_start_end_syms.sh
@p='nanomips_eh_frame_start_end_syms.sh'; $(am__check_pre) $(LOG_COMPILE) "$$tst" $(am__check_post)
dwp_test_1.sh.log: dwp_test_1.sh
@p='dwp_test_1.sh'; $(am__check_pre) $(LOG_COMPILE) "$$tst" $(am__check_post)
dwp_test_2.sh.log: dwp_test_2.sh
Expand Down Expand Up @@ -9086,6 +9095,30 @@ uninstall-am:
@DEFAULT_TARGET_NANOMIPS_TRUE@@NATIVE_OR_CROSS_LINKER_TRUE@nanomips_fix_hw110880.o: nanomips_fix_hw110880.s
@DEFAULT_TARGET_NANOMIPS_TRUE@@NATIVE_OR_CROSS_LINKER_TRUE@ $(TEST_AS) -EL -march=32r6 -m32 -o $@ $<

@DEFAULT_TARGET_NANOMIPS_TRUE@@NATIVE_OR_CROSS_LINKER_TRUE@nanomips_eh_frame_start_end_syms_2.stdout: nanomips_eh_frame_start_end_syms_2
@DEFAULT_TARGET_NANOMIPS_TRUE@@NATIVE_OR_CROSS_LINKER_TRUE@ $(TEST_READELF) -Ss $< > $@

@DEFAULT_TARGET_NANOMIPS_TRUE@@NATIVE_OR_CROSS_LINKER_TRUE@nanomips_eh_frame_start_end_syms_1.stdout: nanomips_eh_frame_start_end_syms_1
@DEFAULT_TARGET_NANOMIPS_TRUE@@NATIVE_OR_CROSS_LINKER_TRUE@ $(TEST_READELF) -Ss $< > $@

@DEFAULT_TARGET_NANOMIPS_TRUE@@NATIVE_OR_CROSS_LINKER_TRUE@nanomips_eh_frame_start_end_syms_2: nanomips_eh_frame_start_end_syms_2.o \
@DEFAULT_TARGET_NANOMIPS_TRUE@@NATIVE_OR_CROSS_LINKER_TRUE@ ../ld-new
@DEFAULT_TARGET_NANOMIPS_TRUE@@NATIVE_OR_CROSS_LINKER_TRUE@ ../ld-new --section-start .eh_frame=0x1000 --section-start \
@DEFAULT_TARGET_NANOMIPS_TRUE@@NATIVE_OR_CROSS_LINKER_TRUE@ .eh_frame_hdr=0x2000 --section-start .text=0x3000 \
@DEFAULT_TARGET_NANOMIPS_TRUE@@NATIVE_OR_CROSS_LINKER_TRUE@ --eh-frame-hdr \
@DEFAULT_TARGET_NANOMIPS_TRUE@@NATIVE_OR_CROSS_LINKER_TRUE@ nanomips_eh_frame_start_end_syms_2.o -o $@

@DEFAULT_TARGET_NANOMIPS_TRUE@@NATIVE_OR_CROSS_LINKER_TRUE@nanomips_eh_frame_start_end_syms_1: nanomips_eh_frame_start_end_syms_1.o \
@DEFAULT_TARGET_NANOMIPS_TRUE@@NATIVE_OR_CROSS_LINKER_TRUE@ ../ld-new
@DEFAULT_TARGET_NANOMIPS_TRUE@@NATIVE_OR_CROSS_LINKER_TRUE@ ../ld-new --section-start .eh_frame=0x1000 --section-start .text=0x2000 \
@DEFAULT_TARGET_NANOMIPS_TRUE@@NATIVE_OR_CROSS_LINKER_TRUE@ nanomips_eh_frame_start_end_syms_1.o -o $@

@DEFAULT_TARGET_NANOMIPS_TRUE@@NATIVE_OR_CROSS_LINKER_TRUE@nanomips_eh_frame_start_end_syms_2.o: nanomips_eh_frame_start_end_syms.s
@DEFAULT_TARGET_NANOMIPS_TRUE@@NATIVE_OR_CROSS_LINKER_TRUE@ $(TEST_AS) -EL -march=32r6 -m32 --defsym hdr=1 -o $@ $<

@DEFAULT_TARGET_NANOMIPS_TRUE@@NATIVE_OR_CROSS_LINKER_TRUE@nanomips_eh_frame_start_end_syms_1.o: nanomips_eh_frame_start_end_syms.s
@DEFAULT_TARGET_NANOMIPS_TRUE@@NATIVE_OR_CROSS_LINKER_TRUE@ $(TEST_AS) -EL -march=32r6 -m32 -o $@ $<

# Tests for the dwp tool.
# We don't want to rely yet on GCC support for -gsplit-dwarf,
# so we use (for now) test cases in x86 assembly language,
Expand Down
25 changes: 25 additions & 0 deletions gold/testsuite/nanomips_eh_frame_start_end_syms.s
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@

.section .text, "ax", @progbits
# Dummy function to generate eh frame
.cfi_startproc
.ent _start
_start:
addiu $a1, $a2, 1

.end _start
.cfi_endproc
.size _start, .-_start

.extern __eh_frame_start
.extern __eh_frame_end
# If not referenced, eh frame star/end symbols are not added
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/star/start

.section .reference_start_end, "aw", @progbits
.4byte __eh_frame_start
.4byte __eh_frame_end

.ifdef hdr
.4byte __eh_frame_hdr_start
.4byte __eh_frame_hdr_end
.endif


50 changes: 50 additions & 0 deletions gold/testsuite/nanomips_eh_frame_start_end_syms.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#!/bin/sh

# nanomips_eh_frame_start_end_syms.sh -- test generation of start/end eh_frame
# section symbols.

# Copyright (C) 2018 Free Software Foundation, Inc.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fix year

# Written by Andrija Jovanovic <[email protected]>.

# This file is part of gold.

# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.

# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.

# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
# MA 02110-1301, USA.

check()
{
file=$1
pattern=$2

found=`grep "$pattern" $file`
if test -z "$found"; then
echo "pattern \"$pattern\" not found in file $file."
exit 1
fi
}


check nanomips_eh_frame_start_end_syms_1.stdout ".eh_frame PROGBITS 00001000 001000 000028"
# Global hidden symbols may be demoted to local symbols, that's why that is
# not checked
check nanomips_eh_frame_start_end_syms_1.stdout "00001000 0 NOTYPE [A-Z ]* HIDDEN [0-9 ]* __eh_frame_start"
check nanomips_eh_frame_start_end_syms_1.stdout "00001028 0 NOTYPE [A-Z ]* HIDDEN [0-9 ]* __eh_frame_end"

check nanomips_eh_frame_start_end_syms_2.stdout ".eh_frame PROGBITS 00001000 001000 000028"
check nanomips_eh_frame_start_end_syms_2.stdout ".eh_frame_hdr PROGBITS 00002000 002000 000014"
check nanomips_eh_frame_start_end_syms_2.stdout "00001000 0 NOTYPE [A-Z ]* HIDDEN [0-9 ]* __eh_frame_start"
check nanomips_eh_frame_start_end_syms_2.stdout "00001028 0 NOTYPE [A-Z ]* HIDDEN [0-9 ]* __eh_frame_end"
check nanomips_eh_frame_start_end_syms_2.stdout "00002000 0 NOTYPE [A-Z ]* HIDDEN [0-9 ]* __eh_frame_hdr_start"
check nanomips_eh_frame_start_end_syms_2.stdout "00002014 0 NOTYPE [A-Z ]* HIDDEN [0-9 ]* __eh_frame_hdr_end"