old-cross-binutils/gold/defstd.cc

275 lines
7.3 KiB
C++
Raw Normal View History

// defstd.cc -- define standard symbols for gold.
PR 10893 * i386.cc (class Output_data_plt_i386): Update declarations. Define Global_ifunc and Local_ifunc types. Add global_ifuncs_ and local_ifuncs_ fields. (Target_i386::do_plt_section_for_global): New function. (Target_i386::do_plt_section_for_local): New function. (Output_data_plt_i386::Output_data_plt_i386): Add symtab parameter; change all callers. Initialize global_ifuncs_ and local_ifuncs_. If doing a static link define __rel_iplt_start and __rel_iplt_end. (Output_data_plt_i386::add_entry): Handle IFUNC symbols. (Output_data_plt_i386::add_local_ifunc_entry): New function. (Output_data_plt_i386::do_write): Fix GOT entries for IFUNC symbols. (Target_i386::make_plt_section): New function, broken out of make_plt_entry. Set sh_info field of .rel.plt to point to .plt. (Target_i386::make_plt_entry): Call make_plt_section. (Target_i386::make_local_ifunc_plt_entry): New function. (Target_i386::Scan::reloc_needs_iplt_for_ifunc): New function. (Target_i386::Scan::local): Handle IFUNC symbols. Add R_386_IRELATIVE to switch. (Target_i386::Scan::global): Likewise. (Target_i386::Relocate::relocate): Likewise. (Target_i386::Relocatable_size_for_reloc): Add R_386_IRELATIVE to switch. * x86_64.cc (class Output_data_plt_x86_64): Update declarations. (Target_x86_64::do_plt_section_for_global): New function. (Target_x86_64::do_plt_section_for_local): New function. (Output_data_plt_x86_64::Output_data_plt_x86_64): Add symtab parameter; change all callers. If doing a static link define __rela_iplt_start and __rela_iplt_end. (Output_data_plt_x86_64::add_entry): Handle IFUNC symbols. (Output_data_plt_x86_64::add_local_ifunc_entry): New function. (Target_x86_64::make_plt_section): Set sh_info field of .rel.plt to point to .plt. (Target_x86_64::make_local_ifunc_plt_entry): New function. (Target_x86_64::Scan::check_non_pic): Add R_X86_64_IRELATIVE to switch. (Target_x86_64::Scan::reloc_needs_iplt_for_ifunc): New function. (Target_x86_64::Scan::local): Handle IFUNC symbols. Add R_X86_64_IRELATIVE to switch. (Target_x86_64::Scan::global): Likewise. (Target_x86_64::Relocate::relocate): Likewise. (Target_x86_64::Relocatable_size_for_reloc): Add R_X86_64_IRELATIVE to switch. * target.h (class Target): Add plt_section_for_global and plt_section_for_local functions. Add do_plt_section_for_global and do_plt_section_for_local virtual functions. * symtab.h (Symbol::needs_plt_entry): Handle IFUNC symbol. Add clarifying comments. (Symbol::use_plt_offset): Handle IFUNC symbol. * object.cc (Sized_relobj::Sized_relobj): Initialize local_plt_offsets_. (Sized_relobj::local_has_plt_offset): New function. (Sized_relobj::local_plt_offset): New function. (Sized_relobj::set_local_plt_offset): New function. (Sized_relobj::do_count): Handle IFUNC symbol. * object.h (class Symbol_value): Add is_ifunc_symbol_ field. Take a bit away from input_shndx_ field. Add set_is_func_symbol and is_ifunc_symbol functions. (class Sized_relobj): Update declarations. Remove Tls_got_entry and Local_tls_got_offsets. Define Local_plt_offsets. Add local_plt_offsets_ field. (Sized_relobj::clear_local_symbols): Clear local_plt_offsets_. * output.h (class Output_section_data): Add non-const output_section function. (class Output_data_got): Update declarations. (class Output_data_got::Got_entry): Add use_plt_offset_ field. Add use_plt_offset parameter to global and local constructors. Change all callers. Change local_sym_index_ field to 31 bits. Change GSYM_CODE and CONSTANT_CODE accordingly. * output.cc (Output_data_reloc_base::do_adjust_output_section): If doing a static link don't set sh_link field. (Output_data_got::Got_entry::write): Use PLT offset if appropriate. (Output_data_got::add_global_plt): New function. (Output_data_got::add_local_plt): New function. * target-reloc.h (relocate_section): Handle IFUNC symbol. * defstd.cc (in_section): Remove entries for __rel_iplt_start, __rel_iplt_end, __rela_iplt_start, and __rela_iplt_end. * configure.ac: Set IFUNC automake conditional for glibc >= 2.11. * testsuite/Makefile.am: Add a bunch of IFUNC tests, all within IFUNC conditional. * testsuite/ifunc-sel.h: New file. * testsuite/ifuncmain1.c: New file. * testsuite/ifuncmain1vis.c: New file. * testsuite/ifuncmod1.c: New file. * testsuite/ifuncdep2.c: New file. * testsuite/ifuncmain2.c: New file. * testsuite/ifuncmain3.c: New file. * testsuite/ifuncmod3.c: New file. * testsuite/ifuncmain4.c: New file. * testsuite/ifuncmain5.c: New file. * testsuite/ifuncmod5.c: New file. * testsuite/ifuncmain6pie.c: New file. * testsuite/ifuncmod6.c: New file. * testsuite/ifuncmain7.c: New file. * configure, testsuite/Makefile.in: Rebuild.
2010-08-19 22:50:16 +00:00
// Copyright 2006, 2007, 2008, 2009, 2010 Free Software Foundation, Inc.
// Written by Ian Lance Taylor <iant@google.com>.
// 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.
#include "gold.h"
#include "symtab.h"
2008-02-04 05:43:05 +00:00
#include "layout.h"
#include "defstd.h"
// This is a simple file which defines the standard symbols like
// "_end".
namespace
{
using namespace gold;
const Define_symbol_in_section in_section[] =
{
{
"__preinit_array_start", // name
".preinit_array", // output_section
0, // value
0, // size
elfcpp::STT_NOTYPE, // type
elfcpp::STB_GLOBAL, // binding
elfcpp::STV_HIDDEN, // visibility
0, // nonvis
false, // offset_is_from_end
true // only_if_ref
},
{
"__preinit_array_end", // name
".preinit_array", // output_section
0, // value
0, // size
elfcpp::STT_NOTYPE, // type
elfcpp::STB_GLOBAL, // binding
elfcpp::STV_HIDDEN, // visibility
0, // nonvis
true, // offset_is_from_end
true // only_if_ref
},
{
"__init_array_start", // name
".init_array", // output_section
0, // value
0, // size
elfcpp::STT_NOTYPE, // type
elfcpp::STB_GLOBAL, // binding
elfcpp::STV_HIDDEN, // visibility
0, // nonvis
false, // offset_is_from_end
true // only_if_ref
},
{
"__init_array_end", // name
".init_array", // output_section
0, // value
0, // size
elfcpp::STT_NOTYPE, // type
elfcpp::STB_GLOBAL, // binding
elfcpp::STV_HIDDEN, // visibility
0, // nonvis
true, // offset_is_from_end
true // only_if_ref
},
{
"__fini_array_start", // name
".fini_array", // output_section
0, // value
0, // size
elfcpp::STT_NOTYPE, // type
elfcpp::STB_GLOBAL, // binding
elfcpp::STV_HIDDEN, // visibility
0, // nonvis
false, // offset_is_from_end
true // only_if_ref
},
{
"__fini_array_end", // name
".fini_array", // output_section
0, // value
0, // size
elfcpp::STT_NOTYPE, // type
elfcpp::STB_GLOBAL, // binding
elfcpp::STV_HIDDEN, // visibility
0, // nonvis
true, // offset_is_from_end
true // only_if_ref
},
{
"__stack", // name
".stack", // output_section
0, // value
0, // size
elfcpp::STT_NOTYPE, // type
elfcpp::STB_GLOBAL, // binding
elfcpp::STV_DEFAULT, // visibility
0, // nonvis
false, // offset_is_from_end
true // only_if_ref
},
};
const int in_section_count = sizeof in_section / sizeof in_section[0];
const Define_symbol_in_segment in_segment[] =
{
{
"__executable_start", // name
elfcpp::PT_LOAD, // segment_type
elfcpp::PF(0), // segment_flags_set
elfcpp::PF(0), // segment_flags_clear
0, // value
0, // size
elfcpp::STT_NOTYPE, // type
elfcpp::STB_GLOBAL, // binding
elfcpp::STV_DEFAULT, // visibility
0, // nonvis
Symbol::SEGMENT_START, // offset_from_base
true // only_if_ref
},
{
"etext", // name
elfcpp::PT_LOAD, // segment_type
elfcpp::PF_X, // segment_flags_set
elfcpp::PF_W, // segment_flags_clear
0, // value
0, // size
elfcpp::STT_NOTYPE, // type
elfcpp::STB_GLOBAL, // binding
elfcpp::STV_DEFAULT, // visibility
0, // nonvis
Symbol::SEGMENT_END, // offset_from_base
true // only_if_ref
},
{
"_etext", // name
elfcpp::PT_LOAD, // segment_type
elfcpp::PF_X, // segment_flags_set
elfcpp::PF_W, // segment_flags_clear
0, // value
0, // size
elfcpp::STT_NOTYPE, // type
elfcpp::STB_GLOBAL, // binding
elfcpp::STV_DEFAULT, // visibility
0, // nonvis
Symbol::SEGMENT_END, // offset_from_base
true // only_if_ref
},
{
"__etext", // name
elfcpp::PT_LOAD, // segment_type
elfcpp::PF_X, // segment_flags_set
elfcpp::PF_W, // segment_flags_clear
0, // value
0, // size
elfcpp::STT_NOTYPE, // type
elfcpp::STB_GLOBAL, // binding
elfcpp::STV_DEFAULT, // visibility
0, // nonvis
Symbol::SEGMENT_END, // offset_from_base
true // only_if_ref
},
{
"_edata", // name
elfcpp::PT_LOAD, // segment_type
2007-09-22 04:38:13 +00:00
elfcpp::PF_W, // segment_flags_set
elfcpp::PF(0), // segment_flags_clear
0, // value
0, // size
elfcpp::STT_NOTYPE, // type
elfcpp::STB_GLOBAL, // binding
elfcpp::STV_DEFAULT, // visibility
0, // nonvis
Symbol::SEGMENT_BSS, // offset_from_base
false // only_if_ref
},
{
"edata", // name
elfcpp::PT_LOAD, // segment_type
2007-09-22 04:38:13 +00:00
elfcpp::PF_W, // segment_flags_set
elfcpp::PF(0), // segment_flags_clear
0, // value
0, // size
elfcpp::STT_NOTYPE, // type
elfcpp::STB_GLOBAL, // binding
elfcpp::STV_DEFAULT, // visibility
0, // nonvis
Symbol::SEGMENT_BSS, // offset_from_base
true // only_if_ref
},
{
"__bss_start", // name
elfcpp::PT_LOAD, // segment_type
2007-09-22 04:38:13 +00:00
elfcpp::PF_W, // segment_flags_set
elfcpp::PF(0), // segment_flags_clear
0, // value
0, // size
elfcpp::STT_NOTYPE, // type
elfcpp::STB_GLOBAL, // binding
elfcpp::STV_DEFAULT, // visibility
0, // nonvis
Symbol::SEGMENT_BSS, // offset_from_base
false // only_if_ref
},
{
"_end", // name
elfcpp::PT_LOAD, // segment_type
2007-09-22 04:38:13 +00:00
elfcpp::PF_W, // segment_flags_set
elfcpp::PF(0), // segment_flags_clear
0, // value
0, // size
elfcpp::STT_NOTYPE, // type
elfcpp::STB_GLOBAL, // binding
elfcpp::STV_DEFAULT, // visibility
0, // nonvis
2007-09-22 04:38:13 +00:00
Symbol::SEGMENT_END, // offset_from_base
false // only_if_ref
},
{
"end", // name
elfcpp::PT_LOAD, // segment_type
2007-09-22 04:38:13 +00:00
elfcpp::PF_W, // segment_flags_set
elfcpp::PF(0), // segment_flags_clear
0, // value
0, // size
elfcpp::STT_NOTYPE, // type
elfcpp::STB_GLOBAL, // binding
elfcpp::STV_DEFAULT, // visibility
0, // nonvis
2007-09-22 04:38:13 +00:00
Symbol::SEGMENT_END, // offset_from_base
true // only_if_ref
}
};
const int in_segment_count = sizeof in_segment / sizeof in_segment[0];
} // End anonymous namespace.
namespace gold
{
void
define_standard_symbols(Symbol_table* symtab, const Layout* layout)
{
2008-02-04 05:43:05 +00:00
bool saw_sections_clause = layout->script_options()->saw_sections_clause();
symtab->define_symbols(layout, in_section_count, in_section,
saw_sections_clause);
symtab->define_symbols(layout, in_segment_count, in_segment,
saw_sections_clause);
}
} // End namespace gold.