binutils-gdb/gold/gold.h

428 lines
12 KiB
C
Raw Normal View History

2006-08-05 01:10:59 +02:00
// gold.h -- general definitions for gold -*- C++ -*-
// Copyright 2006, 2007, 2008, 2009, 2010, 2011 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.
2006-08-05 01:10:59 +02:00
#ifndef GOLD_GOLD_H
#define GOLD_GOLD_H
2006-08-05 01:10:59 +02:00
#include "config.h"
#include "ansidecl.h"
#include <cstddef>
#include <cstdlib>
#include <cstring>
#include <stdint.h>
#include <sys/types.h>
#ifndef ENABLE_NLS
// The Solaris version of locale.h always includes libintl.h. If we
// have been configured with --disable-nls then ENABLE_NLS will not
// be defined and the dummy definitions of bindtextdomain (et al)
// below will conflict with the definitions in libintl.h. So we
// define these values to prevent the bogus inclusion of libintl.h.
# define _LIBINTL_H
# define _LIBGETTEXT_H
#endif
// Always include <clocale> first to avoid conflicts with the macros
// used when ENABLE_NLS is not defined.
#include <clocale>
2006-08-05 01:10:59 +02:00
#ifdef ENABLE_NLS
# include <libintl.h>
# define _(String) gettext (String)
# ifdef gettext_noop
# define N_(String) gettext_noop (String)
# else
# define N_(String) (String)
# endif
#else
# define gettext(Msgid) (Msgid)
# define dgettext(Domainname, Msgid) (Msgid)
# define dcgettext(Domainname, Msgid, Category) (Msgid)
# define textdomain(Domainname) while (0) /* nothing */
# define bindtextdomain(Domainname, Dirname) while (0) /* nothing */
# define _(String) (String)
# define N_(String) (String)
#endif
2006-09-26 23:00:34 +02:00
// Figure out how to get a hash set and a hash map.
#if defined(HAVE_TR1_UNORDERED_SET) && defined(HAVE_TR1_UNORDERED_MAP) \
&& defined(HAVE_TR1_UNORDERED_MAP_REHASH)
2006-08-05 01:10:59 +02:00
#include <tr1/unordered_set>
#include <tr1/unordered_map>
// We need a template typedef here.
#define Unordered_set std::tr1::unordered_set
#define Unordered_map std::tr1::unordered_map
2009-08-05 22:51:56 +02:00
#define Unordered_multimap std::tr1::unordered_multimap
2006-08-05 01:10:59 +02:00
#define reserve_unordered_map(map, n) ((map)->rehash(n))
2006-09-26 23:20:56 +02:00
#elif defined(HAVE_EXT_HASH_MAP) && defined(HAVE_EXT_HASH_SET)
2006-09-26 23:00:34 +02:00
#include <ext/hash_map>
#include <ext/hash_set>
2006-09-26 23:50:25 +02:00
#include <string>
2006-09-26 23:00:34 +02:00
#define Unordered_set __gnu_cxx::hash_set
#define Unordered_map __gnu_cxx::hash_map
2009-08-05 22:51:56 +02:00
#define Unordered_multimap __gnu_cxx::hash_multimap
2006-09-26 23:00:34 +02:00
2006-09-26 23:50:25 +02:00
namespace __gnu_cxx
{
template<>
struct hash<std::string>
{
size_t
operator()(std::string s) const
{ return __stl_hash_string(s.c_str()); }
};
template<typename T>
struct hash<T*>
{
size_t
operator()(T* p) const
{ return reinterpret_cast<size_t>(p); }
};
}
#define reserve_unordered_map(map, n) ((map)->resize(n))
2006-09-26 23:00:34 +02:00
#else
// The fallback is to just use set and map.
#include <set>
#include <map>
#define Unordered_set std::set
#define Unordered_map std::map
#define Unordered_multimap std::multimap
2006-09-26 23:00:34 +02:00
#define reserve_unordered_map(map, n)
2006-09-26 23:00:34 +02:00
#endif
#ifndef HAVE_PREAD
extern "C" ssize_t pread(int, void*, size_t, off_t);
#endif
#ifndef HAVE_FTRUNCATE
extern "C" int ftruncate(int, off_t);
#endif
#ifndef HAVE_FFSLL
extern "C" int ffsll(long long);
#endif
#if !HAVE_DECL_MEMMEM
extern "C" void *memmem(const void *, size_t, const void *, size_t);
#endif
#if !HAVE_DECL_STRNDUP
extern "C" char *strndup(const char *, size_t);
#endif
namespace gold
{
// General declarations.
2006-08-05 01:10:59 +02:00
class General_options;
class Command_line;
class Dirsearch;
class Input_objects;
* mapfile.cc: New file. * mapfile.h: New file. * options.h (class General_options): Add -M/--print-map and -Map. * options.cc (General_options::finalize): Make -M equivalent to -Map -. * main.cc: Include <cstdio> and "mapfile.h". (main): Open mapfile if requested. * gold.cc (class Middle_runner): Add mapfile_ field. Update constructor. Change caller. (queue_initial_tasks): Add mapfile parameter. Change caller. (queue_middle_tasks): Likewise. * gold.h (queue_initial_tasks, queue_middle_tasks): Update declarations. * archive.cc: Include "mapfile.h". (Archive::add_symbols): Add mapfile parameter. Change all callers. Pass mapfile, symbol, and reason to include_member. (Archive::include_all_members): Add mapfile parameter. Change all callers. (Archive::include_member): Add mapfile, sym, and why parameters. Change all callers. Report inclusion to map file. * archive.h: Include "fileread.h". (class Archive): Update declarations. (Archive::file): New const method. (class Add_archive_symbols): Add mapfile_ field. Update constructor. Change all callers. * readsyms.h (class Read_symbols): Likewise. (class Finish_group): Likewise. (class Read_script): Likewise. * common.cc: Include "mapfile.h". (Symbol_table::allocate_commons): Add mapfile parameter. Change all callers. (Symbol_table::do_allocate_commons): Likewise. (Symbol_table::do_allocate_commons_list): Likewise. Report common symbol allocation to mapfile. * common.h (class Allocate_commons_task): Add mapfile_ field. Update constructor. Change all callers. * symtab.h (class Symbol_table): Update declarations. * layout.cc: Include "mapfile.h". (Layout_task_runner::run): Print information to mapfile. (Layout::create_gold_note): Change Output_data_fixed_space to Output_data_zero_fill. (Layout::create_build_id): Likewise. (Layout::print_to_mapfile): New function. * layout.h (class Layout_task_runner): Add mapfile_ field. Update constructor. Change caller. (class Layout): Declare print_to_mapfile. * output.cc (Output_section::Input_section::print_to_mapfile): New function. (Output_section::add_input_section): If producing a map, always add to input_sections_ list. (Output_section::do_print_to_mapfile): New function. (Output_segment::print_sections_to_mapfile): New function. (Output_segment::print_section_list_to_mapfile): New function. * output.h: Include "mapfile.h". (Output_data::print_to_mapfile): New function. (Output_data::do_print_to_mapfile): New virtual function. (Output_segment_headers::do_print_to_mapfile): New function. (Output_file_header::do_print_to_mapfile): New function. (Output_data_const::do_print_to_mapfile): New function. (class Output_data_const_buffer): Add map_name_ field. Update constructor. Change all callers. Add do_print_to_mapfile function. (class Output_data_fixed_space): Likewise. (class Output_data_space): Likewise. (class Output_data_zero_fill): New class. (Output_data_strtab::do_print_to_mapfile): New function. (Output_data_reloc_base::do_print_to_mapfile): New function. (Output_relocatable_relocs::do_print_to_mapfile): New function. (Output_data_group::do_print_to_mapfile): New function. (Output_data_got::do_print_to_mapfile): New function. (Output_data_dynamic::do_print_to_mapfile): New function. (Output_symtab_xindex::do_print_to_mapfile): New function. (class Output_section): Declare do_print_to_mapflie. Declare print_to_mapfile in Input_section. (class Output_segment): Declare new functions. * object.h (Sized_relobj::symbol_count): New function. * script-sections.cc (Output_section_element_dot_assignment::set_section_addresses): Change Output_data_fixed_space to Output_data_zero_fill. (Output_data_expression::do_print_to_mapfile): New function. * script.cc (read_input_script): Add mapfile parameter. Change all callers. * script.h (read_input_script): Update declaration. * ehframe.h (Eh_frame_hdr::do_print_to_mapfile): New function. (Eh_frame::do_print_to_mapfile): New function. * merge.h (Output_merge_data::do_print_to_mapfile): New function. (Output_merge_string::do_print_to_mapfile): New function. * i386.cc (Output_data_plt_i386::do_print_to_mapfile): New function. * sparc.cc (Output_data_plt_sparc::do_print_to_mapfile): New function. * x86_64.cc (Output_data_plt_x86_64::do_print_to_mapfile): New function. * Makefile.am (CCFILES): Add mapfile.cc. (HFILES): Add mapfile.h. * Makefile.in: Rebuild.
2008-05-21 23:37:44 +02:00
class Mapfile;
class Symbol;
class Symbol_table;
class Layout;
class Task;
class Workqueue;
class Output_file;
template<int size, bool big_endian>
struct Relocate_info;
// Exit status codes.
enum Exit_status
{
GOLD_OK = EXIT_SUCCESS,
GOLD_ERR = EXIT_FAILURE,
GOLD_FALLBACK = EXIT_FAILURE + 1
};
// Some basic types. For these we use lower case initial letters.
// For an offset in an input or output file, use off_t. Note that
// this will often be a 64-bit type even for a 32-bit build.
// The size of a section if we are going to look at the contents.
typedef size_t section_size_type;
// An offset within a section when we are looking at the contents.
typedef ptrdiff_t section_offset_type;
2006-08-05 01:10:59 +02:00
// The name of the program as used in error messages.
extern const char* program_name;
// This function is called to exit the program. Status is true to
// exit success (0) and false to exit failure (1).
extern void
gold_exit(Exit_status status) ATTRIBUTE_NORETURN;
2006-08-05 01:10:59 +02:00
// This function is called to emit an error message and then
// immediately exit with failure.
extern void
gold_fatal(const char* format, ...) ATTRIBUTE_NORETURN ATTRIBUTE_PRINTF_1;
// This function is called to issue an error. This will cause gold to
// eventually exit with failure.
extern void
gold_error(const char* msg, ...) ATTRIBUTE_PRINTF_1;
// This function is called to issue a warning.
extern void
gold_warning(const char* msg, ...) ATTRIBUTE_PRINTF_1;
// This function is called to print an informational message.
extern void
gold_info(const char* msg, ...) ATTRIBUTE_PRINTF_1;
// This function is called to emit an error message and then
// immediately exit with fallback status (e.g., when
// --incremental-update fails and the link needs to be restarted
// with --incremental-full).
extern void
gold_fallback(const char* format, ...) ATTRIBUTE_NORETURN ATTRIBUTE_PRINTF_1;
// Work around a bug in gcc 4.3.0. http://gcc.gnu.org/PR35546 . This
// can probably be removed after the bug has been fixed for a while.
#ifdef HAVE_TEMPLATE_ATTRIBUTES
#define TEMPLATE_ATTRIBUTE_PRINTF_4 ATTRIBUTE_PRINTF_4
#else
#define TEMPLATE_ATTRIBUTE_PRINTF_4
#endif
// This function is called to issue an error at the location of a
// reloc.
template<int size, bool big_endian>
extern void
gold_error_at_location(const Relocate_info<size, big_endian>*,
size_t, off_t, const char* format, ...)
TEMPLATE_ATTRIBUTE_PRINTF_4;
// This function is called to issue a warning at the location of a
// reloc.
template<int size, bool big_endian>
extern void
gold_warning_at_location(const Relocate_info<size, big_endian>*,
size_t, off_t, const char* format, ...)
TEMPLATE_ATTRIBUTE_PRINTF_4;
// This function is called to report an undefined symbol without
// a relocation (e.g., referenced by a dynamic object). SYM is
// the undefined symbol. The file name associated with the SYM
// is used to print a location for the undefined symbol.
extern void
gold_undefined_symbol(const Symbol*);
// This function is called to report an undefined symbol resulting
// from a relocation. SYM is the undefined symbol. RELINFO is the
// general relocation info. RELNUM is the number of the reloc,
// and RELOFFSET is the reloc's offset.
template<int size, bool big_endian>
2006-08-05 01:10:59 +02:00
extern void
gold_undefined_symbol_at_location(const Symbol*,
const Relocate_info<size, big_endian>*,
size_t, off_t);
2006-08-05 01:10:59 +02:00
// This is function is called in some cases if we run out of memory.
extern void
gold_nomem() ATTRIBUTE_NORETURN;
// In versions of gcc before 4.3, using __FUNCTION__ in a template
// function can cause gcc to get confused about whether or not the
// function can return. See http://gcc.gnu.org/PR30988. Use a macro
// to avoid the problem. This can be removed when we no longer need
// to care about gcc versions before 4.3.
#if defined(__GNUC__) && GCC_VERSION < 4003
#define FUNCTION_NAME static_cast<const char*>(__FUNCTION__)
#else
#define FUNCTION_NAME __FUNCTION__
#endif
// This macro and function are used in cases which can not arise if
// the code is written correctly.
#define gold_unreachable() \
(gold::do_gold_unreachable(__FILE__, __LINE__, FUNCTION_NAME))
extern void do_gold_unreachable(const char*, int, const char*)
ATTRIBUTE_NORETURN;
// Assertion check.
#define gold_assert(expr) ((void)(!(expr) ? gold_unreachable(), 0 : 0))
2006-08-05 01:10:59 +02:00
2007-10-07 20:06:27 +02:00
// Print version information.
extern void
print_version(bool print_short);
// Get the version string.
extern const char*
get_version_string();
// Convert numeric types without unnoticed loss of precision.
template<typename To, typename From>
inline To
convert_types(const From from)
{
To to = from;
gold_assert(static_cast<From>(to) == from);
return to;
}
// A common case of convert_types<>: convert to section_size_type.
template<typename From>
inline section_size_type
convert_to_section_size_type(const From from)
{ return convert_types<section_size_type, From>(from); }
// Queue up the first set of tasks.
extern void
queue_initial_tasks(const General_options&,
Dirsearch&,
const Command_line&,
Workqueue*,
Input_objects*,
Symbol_table*,
* mapfile.cc: New file. * mapfile.h: New file. * options.h (class General_options): Add -M/--print-map and -Map. * options.cc (General_options::finalize): Make -M equivalent to -Map -. * main.cc: Include <cstdio> and "mapfile.h". (main): Open mapfile if requested. * gold.cc (class Middle_runner): Add mapfile_ field. Update constructor. Change caller. (queue_initial_tasks): Add mapfile parameter. Change caller. (queue_middle_tasks): Likewise. * gold.h (queue_initial_tasks, queue_middle_tasks): Update declarations. * archive.cc: Include "mapfile.h". (Archive::add_symbols): Add mapfile parameter. Change all callers. Pass mapfile, symbol, and reason to include_member. (Archive::include_all_members): Add mapfile parameter. Change all callers. (Archive::include_member): Add mapfile, sym, and why parameters. Change all callers. Report inclusion to map file. * archive.h: Include "fileread.h". (class Archive): Update declarations. (Archive::file): New const method. (class Add_archive_symbols): Add mapfile_ field. Update constructor. Change all callers. * readsyms.h (class Read_symbols): Likewise. (class Finish_group): Likewise. (class Read_script): Likewise. * common.cc: Include "mapfile.h". (Symbol_table::allocate_commons): Add mapfile parameter. Change all callers. (Symbol_table::do_allocate_commons): Likewise. (Symbol_table::do_allocate_commons_list): Likewise. Report common symbol allocation to mapfile. * common.h (class Allocate_commons_task): Add mapfile_ field. Update constructor. Change all callers. * symtab.h (class Symbol_table): Update declarations. * layout.cc: Include "mapfile.h". (Layout_task_runner::run): Print information to mapfile. (Layout::create_gold_note): Change Output_data_fixed_space to Output_data_zero_fill. (Layout::create_build_id): Likewise. (Layout::print_to_mapfile): New function. * layout.h (class Layout_task_runner): Add mapfile_ field. Update constructor. Change caller. (class Layout): Declare print_to_mapfile. * output.cc (Output_section::Input_section::print_to_mapfile): New function. (Output_section::add_input_section): If producing a map, always add to input_sections_ list. (Output_section::do_print_to_mapfile): New function. (Output_segment::print_sections_to_mapfile): New function. (Output_segment::print_section_list_to_mapfile): New function. * output.h: Include "mapfile.h". (Output_data::print_to_mapfile): New function. (Output_data::do_print_to_mapfile): New virtual function. (Output_segment_headers::do_print_to_mapfile): New function. (Output_file_header::do_print_to_mapfile): New function. (Output_data_const::do_print_to_mapfile): New function. (class Output_data_const_buffer): Add map_name_ field. Update constructor. Change all callers. Add do_print_to_mapfile function. (class Output_data_fixed_space): Likewise. (class Output_data_space): Likewise. (class Output_data_zero_fill): New class. (Output_data_strtab::do_print_to_mapfile): New function. (Output_data_reloc_base::do_print_to_mapfile): New function. (Output_relocatable_relocs::do_print_to_mapfile): New function. (Output_data_group::do_print_to_mapfile): New function. (Output_data_got::do_print_to_mapfile): New function. (Output_data_dynamic::do_print_to_mapfile): New function. (Output_symtab_xindex::do_print_to_mapfile): New function. (class Output_section): Declare do_print_to_mapflie. Declare print_to_mapfile in Input_section. (class Output_segment): Declare new functions. * object.h (Sized_relobj::symbol_count): New function. * script-sections.cc (Output_section_element_dot_assignment::set_section_addresses): Change Output_data_fixed_space to Output_data_zero_fill. (Output_data_expression::do_print_to_mapfile): New function. * script.cc (read_input_script): Add mapfile parameter. Change all callers. * script.h (read_input_script): Update declaration. * ehframe.h (Eh_frame_hdr::do_print_to_mapfile): New function. (Eh_frame::do_print_to_mapfile): New function. * merge.h (Output_merge_data::do_print_to_mapfile): New function. (Output_merge_string::do_print_to_mapfile): New function. * i386.cc (Output_data_plt_i386::do_print_to_mapfile): New function. * sparc.cc (Output_data_plt_sparc::do_print_to_mapfile): New function. * x86_64.cc (Output_data_plt_x86_64::do_print_to_mapfile): New function. * Makefile.am (CCFILES): Add mapfile.cc. (HFILES): Add mapfile.h. * Makefile.in: Rebuild.
2008-05-21 23:37:44 +02:00
Layout*,
Mapfile*);
2009-01-20 Sriraman Tallam <tmsriram@google.com> * Makefile.am (CCFILES): Add gc.cc. (HFILES): Add gc.h. * Makefile.in: Regenerate. * gold.cc (Gc_runner): New class. (queue_initial_tasks): Call garbage collection related tasks when corresponding options are invoked. (queue_middle_gc_tasks): New function. (queue_middle_tasks): Reorder tasks to allow relocs to be read and processed early before laying out sections during garbage collection. * gold.h (queue_middle_gc_tasks): New function. (is_prefix_of): Move from "layout.cc". * i386.cc (Target_i386::gc_process_relocs): New function. * layout.cc (is_prefix_of): Remove. Move to "gold.h" * main.cc (main): Create object of class "Garbage_collection". * object.cc (Relobj::copy_symbols_data): New function. (Relobj::is_section_name_included): New function. (Sized_relobj::do_layout): Allow this function to be called twice during garbage collection and defer layout of section during the first call. * object.h (Relobj::get_symbols_data): New function. (Relobj::is_section_name_included): New function. (Relobj::copy_symbols_data): New function. (Relobj::set_symbols_data): New function. (Relobj::get_relocs_data): New function. (Relobj::set_relocs_data): New function. (Relobj::is_output_section_offset_invalid): New pure virtual function. (Relobj::gc_process_relocs): New function. (Relobj::do_gc_process_relocs): New pure virtual function. (Relobj::sd_): New data member. (Sized_relobj::is_output_section_offset_invalid): New function. (Sized_relobj::do_gc_process_relocs): New function. * options.h (General_options::gc_sections): Modify to not be a no-op. (General_options::print_gc_sections): New option. * plugin.cc (Plugin_finish::run): Remove function call to Plugin_manager::layout_deferred_objects. Move it to "gold.cc". * powerpc.cc (Target_powerpc::gc_process_relocs): New function. * reloc.cc (Read_relocs::run): Add task to process relocs and determine unreferenced sections when doing garbage collection. (Gc_process_relocs): New class. (Sized_relobj::do_gc_process_relocs): New function. (Sized_relobj::do_scan_relocs): Don't try to scan the relocs for sections that are garbage collected. * reloc.h (Gc_process_relocs): New class. * sparc.cc (Target_sparc::gc_process_relocs): New function. * symtab.cc (Symbol::should_add_dynsym_entry): Do not add entries for symbols whose corresponding sections are garbage collected. (Symbol_table::Symbol_table): Add new parameter for the garbage collection object. (Symbol_table::gc_mark_undef_symbols): New function. (Symbol_table::gc_mark_symbol_for_shlib): New function. (Symbol_table::gc_mark_dyn_syms): New function. (Symbol_table::resolve): Do not treat symbols seen in dynamic objects as garbage. (Symbol_table::add_from_object): Likewise. (Symbol_table::add_from_relobj): When building shared objects, do not treat externally visible symbols as garbage. (Symbol_table::sized_finalize_symbol): Do not check dynamic symbol table information for static and relocatable links. * symtab.h (Symbol_table::set_gc): New function. (Symbol_table::gc): New function. (Symbol_table::gc_mark_undef_symbols): New function. (Symbol_table::gc_mark_symbol_for_shlib): New function. (Symbol_table::gc_mark_dyn_syms): New function. (Symbol_table::gc_): New data member. * target.h (Sized_target::gc_process_relocs): New pure virtual function. * x86_64.cc (Target_x86_64::gc_process_relocs): New function. * testsuite/testfile.cc (Target_test::gc_process_relocs): New function.
2009-01-28 03:25:33 +01:00
// Queue up the set of tasks to be done before
// the middle set of tasks. Only used when garbage
* gold.h (Incremental_argument_list): Remove (invalid) forward declaration. * incremental.cc (Incremental_inputs::report_achive): New method. (Incremental_inputs::report_object): New method. (Incremental_inputs::report_script): New method. (Incremental_inputs::finalize_inputs): New method. (Incremental_inputs::finalize): Call finalize_inputs(). (Incremental_inputs::sized_create_incremental_inputs_section_data): Create inputs entries. * incremental.h (Incremental_input_type): New enum. (Incremental_inputs::Incremental_input): Initialize new fields. (Incremental_inputs::report_inputs): New method. (Incremental_inputs::report_achive): New method. (Incremental_inputs::report_object): New method. (Incremental_inputs::report_script): New method. (Incremental_inputs::finalize_inputs): New method. (Incremental_inputs::Input_info): New struct. (Incremental_inputs::Input_info_map): New typedef. (Incremental_inputs::lock_): New field. (Incremental_inputs::Inputs_): New field. (Incremental_inputs::Inputs_map): New field. * main.cc (main): Call Incremental_input::report_inputs. * options.h (Input_argument_list): Typedef moved from Input_arguments. (Input_file_group::Files): Remove, use ::Input_argument_list. (Input_file_group::Input_argument_list): Remove, use ::Input_argument_list. * plugin.cc (Plugin_manager::add_input_file): Add error in incremental build. * read_syms.cc (do_read_syms): Call Incremental_input::report_* functions. * script.cc (read_input_script): Call Incremental_input::report_script. * script.h (Script_info): New class.
2009-05-15 19:01:04 +02:00
// collection is to be done.
2009-01-20 Sriraman Tallam <tmsriram@google.com> * Makefile.am (CCFILES): Add gc.cc. (HFILES): Add gc.h. * Makefile.in: Regenerate. * gold.cc (Gc_runner): New class. (queue_initial_tasks): Call garbage collection related tasks when corresponding options are invoked. (queue_middle_gc_tasks): New function. (queue_middle_tasks): Reorder tasks to allow relocs to be read and processed early before laying out sections during garbage collection. * gold.h (queue_middle_gc_tasks): New function. (is_prefix_of): Move from "layout.cc". * i386.cc (Target_i386::gc_process_relocs): New function. * layout.cc (is_prefix_of): Remove. Move to "gold.h" * main.cc (main): Create object of class "Garbage_collection". * object.cc (Relobj::copy_symbols_data): New function. (Relobj::is_section_name_included): New function. (Sized_relobj::do_layout): Allow this function to be called twice during garbage collection and defer layout of section during the first call. * object.h (Relobj::get_symbols_data): New function. (Relobj::is_section_name_included): New function. (Relobj::copy_symbols_data): New function. (Relobj::set_symbols_data): New function. (Relobj::get_relocs_data): New function. (Relobj::set_relocs_data): New function. (Relobj::is_output_section_offset_invalid): New pure virtual function. (Relobj::gc_process_relocs): New function. (Relobj::do_gc_process_relocs): New pure virtual function. (Relobj::sd_): New data member. (Sized_relobj::is_output_section_offset_invalid): New function. (Sized_relobj::do_gc_process_relocs): New function. * options.h (General_options::gc_sections): Modify to not be a no-op. (General_options::print_gc_sections): New option. * plugin.cc (Plugin_finish::run): Remove function call to Plugin_manager::layout_deferred_objects. Move it to "gold.cc". * powerpc.cc (Target_powerpc::gc_process_relocs): New function. * reloc.cc (Read_relocs::run): Add task to process relocs and determine unreferenced sections when doing garbage collection. (Gc_process_relocs): New class. (Sized_relobj::do_gc_process_relocs): New function. (Sized_relobj::do_scan_relocs): Don't try to scan the relocs for sections that are garbage collected. * reloc.h (Gc_process_relocs): New class. * sparc.cc (Target_sparc::gc_process_relocs): New function. * symtab.cc (Symbol::should_add_dynsym_entry): Do not add entries for symbols whose corresponding sections are garbage collected. (Symbol_table::Symbol_table): Add new parameter for the garbage collection object. (Symbol_table::gc_mark_undef_symbols): New function. (Symbol_table::gc_mark_symbol_for_shlib): New function. (Symbol_table::gc_mark_dyn_syms): New function. (Symbol_table::resolve): Do not treat symbols seen in dynamic objects as garbage. (Symbol_table::add_from_object): Likewise. (Symbol_table::add_from_relobj): When building shared objects, do not treat externally visible symbols as garbage. (Symbol_table::sized_finalize_symbol): Do not check dynamic symbol table information for static and relocatable links. * symtab.h (Symbol_table::set_gc): New function. (Symbol_table::gc): New function. (Symbol_table::gc_mark_undef_symbols): New function. (Symbol_table::gc_mark_symbol_for_shlib): New function. (Symbol_table::gc_mark_dyn_syms): New function. (Symbol_table::gc_): New data member. * target.h (Sized_target::gc_process_relocs): New pure virtual function. * x86_64.cc (Target_x86_64::gc_process_relocs): New function. * testsuite/testfile.cc (Target_test::gc_process_relocs): New function.
2009-01-28 03:25:33 +01:00
extern void
queue_middle_gc_tasks(const General_options&,
const Task*,
const Input_objects*,
Symbol_table*,
Layout*,
Workqueue*,
Mapfile*);
// Queue up the middle set of tasks.
extern void
queue_middle_tasks(const General_options&,
const Task*,
const Input_objects*,
Symbol_table*,
Layout*,
* mapfile.cc: New file. * mapfile.h: New file. * options.h (class General_options): Add -M/--print-map and -Map. * options.cc (General_options::finalize): Make -M equivalent to -Map -. * main.cc: Include <cstdio> and "mapfile.h". (main): Open mapfile if requested. * gold.cc (class Middle_runner): Add mapfile_ field. Update constructor. Change caller. (queue_initial_tasks): Add mapfile parameter. Change caller. (queue_middle_tasks): Likewise. * gold.h (queue_initial_tasks, queue_middle_tasks): Update declarations. * archive.cc: Include "mapfile.h". (Archive::add_symbols): Add mapfile parameter. Change all callers. Pass mapfile, symbol, and reason to include_member. (Archive::include_all_members): Add mapfile parameter. Change all callers. (Archive::include_member): Add mapfile, sym, and why parameters. Change all callers. Report inclusion to map file. * archive.h: Include "fileread.h". (class Archive): Update declarations. (Archive::file): New const method. (class Add_archive_symbols): Add mapfile_ field. Update constructor. Change all callers. * readsyms.h (class Read_symbols): Likewise. (class Finish_group): Likewise. (class Read_script): Likewise. * common.cc: Include "mapfile.h". (Symbol_table::allocate_commons): Add mapfile parameter. Change all callers. (Symbol_table::do_allocate_commons): Likewise. (Symbol_table::do_allocate_commons_list): Likewise. Report common symbol allocation to mapfile. * common.h (class Allocate_commons_task): Add mapfile_ field. Update constructor. Change all callers. * symtab.h (class Symbol_table): Update declarations. * layout.cc: Include "mapfile.h". (Layout_task_runner::run): Print information to mapfile. (Layout::create_gold_note): Change Output_data_fixed_space to Output_data_zero_fill. (Layout::create_build_id): Likewise. (Layout::print_to_mapfile): New function. * layout.h (class Layout_task_runner): Add mapfile_ field. Update constructor. Change caller. (class Layout): Declare print_to_mapfile. * output.cc (Output_section::Input_section::print_to_mapfile): New function. (Output_section::add_input_section): If producing a map, always add to input_sections_ list. (Output_section::do_print_to_mapfile): New function. (Output_segment::print_sections_to_mapfile): New function. (Output_segment::print_section_list_to_mapfile): New function. * output.h: Include "mapfile.h". (Output_data::print_to_mapfile): New function. (Output_data::do_print_to_mapfile): New virtual function. (Output_segment_headers::do_print_to_mapfile): New function. (Output_file_header::do_print_to_mapfile): New function. (Output_data_const::do_print_to_mapfile): New function. (class Output_data_const_buffer): Add map_name_ field. Update constructor. Change all callers. Add do_print_to_mapfile function. (class Output_data_fixed_space): Likewise. (class Output_data_space): Likewise. (class Output_data_zero_fill): New class. (Output_data_strtab::do_print_to_mapfile): New function. (Output_data_reloc_base::do_print_to_mapfile): New function. (Output_relocatable_relocs::do_print_to_mapfile): New function. (Output_data_group::do_print_to_mapfile): New function. (Output_data_got::do_print_to_mapfile): New function. (Output_data_dynamic::do_print_to_mapfile): New function. (Output_symtab_xindex::do_print_to_mapfile): New function. (class Output_section): Declare do_print_to_mapflie. Declare print_to_mapfile in Input_section. (class Output_segment): Declare new functions. * object.h (Sized_relobj::symbol_count): New function. * script-sections.cc (Output_section_element_dot_assignment::set_section_addresses): Change Output_data_fixed_space to Output_data_zero_fill. (Output_data_expression::do_print_to_mapfile): New function. * script.cc (read_input_script): Add mapfile parameter. Change all callers. * script.h (read_input_script): Update declaration. * ehframe.h (Eh_frame_hdr::do_print_to_mapfile): New function. (Eh_frame::do_print_to_mapfile): New function. * merge.h (Output_merge_data::do_print_to_mapfile): New function. (Output_merge_string::do_print_to_mapfile): New function. * i386.cc (Output_data_plt_i386::do_print_to_mapfile): New function. * sparc.cc (Output_data_plt_sparc::do_print_to_mapfile): New function. * x86_64.cc (Output_data_plt_x86_64::do_print_to_mapfile): New function. * Makefile.am (CCFILES): Add mapfile.cc. (HFILES): Add mapfile.h. * Makefile.in: Rebuild.
2008-05-21 23:37:44 +02:00
Workqueue*,
Mapfile*);
// Queue up the final set of tasks.
extern void
queue_final_tasks(const General_options&,
const Input_objects*,
const Symbol_table*,
Layout*,
Workqueue*,
Output_file* of);
2009-01-20 Sriraman Tallam <tmsriram@google.com> * Makefile.am (CCFILES): Add gc.cc. (HFILES): Add gc.h. * Makefile.in: Regenerate. * gold.cc (Gc_runner): New class. (queue_initial_tasks): Call garbage collection related tasks when corresponding options are invoked. (queue_middle_gc_tasks): New function. (queue_middle_tasks): Reorder tasks to allow relocs to be read and processed early before laying out sections during garbage collection. * gold.h (queue_middle_gc_tasks): New function. (is_prefix_of): Move from "layout.cc". * i386.cc (Target_i386::gc_process_relocs): New function. * layout.cc (is_prefix_of): Remove. Move to "gold.h" * main.cc (main): Create object of class "Garbage_collection". * object.cc (Relobj::copy_symbols_data): New function. (Relobj::is_section_name_included): New function. (Sized_relobj::do_layout): Allow this function to be called twice during garbage collection and defer layout of section during the first call. * object.h (Relobj::get_symbols_data): New function. (Relobj::is_section_name_included): New function. (Relobj::copy_symbols_data): New function. (Relobj::set_symbols_data): New function. (Relobj::get_relocs_data): New function. (Relobj::set_relocs_data): New function. (Relobj::is_output_section_offset_invalid): New pure virtual function. (Relobj::gc_process_relocs): New function. (Relobj::do_gc_process_relocs): New pure virtual function. (Relobj::sd_): New data member. (Sized_relobj::is_output_section_offset_invalid): New function. (Sized_relobj::do_gc_process_relocs): New function. * options.h (General_options::gc_sections): Modify to not be a no-op. (General_options::print_gc_sections): New option. * plugin.cc (Plugin_finish::run): Remove function call to Plugin_manager::layout_deferred_objects. Move it to "gold.cc". * powerpc.cc (Target_powerpc::gc_process_relocs): New function. * reloc.cc (Read_relocs::run): Add task to process relocs and determine unreferenced sections when doing garbage collection. (Gc_process_relocs): New class. (Sized_relobj::do_gc_process_relocs): New function. (Sized_relobj::do_scan_relocs): Don't try to scan the relocs for sections that are garbage collected. * reloc.h (Gc_process_relocs): New class. * sparc.cc (Target_sparc::gc_process_relocs): New function. * symtab.cc (Symbol::should_add_dynsym_entry): Do not add entries for symbols whose corresponding sections are garbage collected. (Symbol_table::Symbol_table): Add new parameter for the garbage collection object. (Symbol_table::gc_mark_undef_symbols): New function. (Symbol_table::gc_mark_symbol_for_shlib): New function. (Symbol_table::gc_mark_dyn_syms): New function. (Symbol_table::resolve): Do not treat symbols seen in dynamic objects as garbage. (Symbol_table::add_from_object): Likewise. (Symbol_table::add_from_relobj): When building shared objects, do not treat externally visible symbols as garbage. (Symbol_table::sized_finalize_symbol): Do not check dynamic symbol table information for static and relocatable links. * symtab.h (Symbol_table::set_gc): New function. (Symbol_table::gc): New function. (Symbol_table::gc_mark_undef_symbols): New function. (Symbol_table::gc_mark_symbol_for_shlib): New function. (Symbol_table::gc_mark_dyn_syms): New function. (Symbol_table::gc_): New data member. * target.h (Sized_target::gc_process_relocs): New pure virtual function. * x86_64.cc (Target_x86_64::gc_process_relocs): New function. * testsuite/testfile.cc (Target_test::gc_process_relocs): New function.
2009-01-28 03:25:33 +01:00
inline bool
is_prefix_of(const char* prefix, const char* str)
{
return strncmp(prefix, str, strlen(prefix)) == 0;
}
const char* const cident_section_start_prefix = "__start_";
const char* const cident_section_stop_prefix = "__stop_";
// Returns true if the name is a valid C identifier
inline bool
is_cident(const char* name)
{
return (name[strspn(name,
("0123456789"
"ABCDEFGHIJKLMNOPWRSTUVWXYZ"
"abcdefghijklmnopqrstuvwxyz"
"_"))]
== '\0');
}
// We sometimes need to hash strings. Ideally we should use std::tr1::hash or
// __gnu_cxx::hash on some systems but there is no guarantee that either
// one is available. For portability, we define simple string hash functions.
template<typename Char_type>
inline size_t
string_hash(const Char_type* s, size_t length)
{
// This is the hash function used by the dynamic linker for
// DT_GNU_HASH entries. I compared this to a Fowler/Noll/Vo hash
// for a C++ program with 385,775 global symbols. This hash
// function was very slightly worse. However, it is much faster to
// compute. Overall wall clock time was a win.
const unsigned char* p = reinterpret_cast<const unsigned char*>(s);
size_t h = 5381;
for (size_t i = 0; i < length * sizeof(Char_type); ++i)
h = h * 33 + *p++;
return h;
}
// Same as above except we expect the string to be zero terminated.
template<typename Char_type>
inline size_t
string_hash(const Char_type* s)
{
const unsigned char* p = reinterpret_cast<const unsigned char*>(s);
size_t h = 5381;
for (size_t i = 0; s[i] != 0; ++i)
{
for (size_t j = 0; j < sizeof(Char_type); j++)
h = h * 33 + *p++;
}
return h;
}
* gold.h (is_wildcard_string): New function. * layout.cc (Layout::layout): Pass this pointer to add_input_section. (Layout::layout_eh_frame): Ditto. (Layout::find_section_order_index): New method. (Layout::read_layout_from_file): New method. * layout.h (Layout::find_section_order_index): New method. (Layout::read_layout_from_file): New method. (Layout::input_section_position_): New private member. (Layout::input_section_glob_): New private member. * main.cc (main): Call read_layout_from_file here. * options.h (--section-ordering-file): New option. * output.cc (Output_section::input_section_order_specified_): New member. (Output_section::Output_section): Initialize new member. (Output_section::add_input_section): Add new parameter. Keep input sections when --section-ordering-file is used. (Output_section::set_final_data_size): Sort input sections when section ordering file is specified. (Output_section::Input_section_sort_entry): Add new parameter. Check sorting type. (Output_section::Input_section_sort_entry::compare_section_ordering): New method. (Output_section::Input_section_sort_compare::operator()): Change to consider section_order_index. (Output_section::Input_section_sort_init_fini_compare::operator()): Change to consider section_order_index. (Output_section::Input_section_sort_section_order_index_compare ::operator()): New method. (Output_section::sort_attached_input_sections): Change to sort according to section order when specified. (Output_section::add_input_section<32, true>): Add new parameter. (Output_section::add_input_section<64, true>): Add new parameter. (Output_section::add_input_section<32, false>): Add new parameter. (Output_section::add_input_section<64, false>): Add new parameter. * output.h (Output_section::add_input_section): Add new parameter. (Output_section::input_section_order_specified): New method. (Output_section::set_input_section_order_specified): New method. (Input_section::Input_section): Initialize section_order_index_. (Input_section::section_order_index): New method. (Input_section::set_section_order_index): New method. (Input_section::section_order_index_): New member. (Input_section::Input_section_sort_section_order_index_compare): New struct. (Output_section::input_section_order_specified_): New member. * script-sections.cc (is_wildcard_string): Delete and move modified method to gold.h. (Output_section_element_input::Output_section_element_input): Modify call to is_wildcard_string. (Output_section_element_input::Input_section_pattern ::Input_section_pattern): Ditto. (Output_section_element_input::Output_section_element_input): Ditto. * testsuite/Makefile.am (final_layout): New test case. * testsuite/Makefile.in: Regenerate. * testsuite/final_layout.cc: New file. * testsuite/final_layout.sh: New file.
2010-06-02 01:37:58 +02:00
// Return whether STRING contains a wildcard character. This is used
// to speed up matching.
inline bool
is_wildcard_string(const char* s)
{
return strpbrk(s, "?*[") != NULL;
}
2006-08-05 01:10:59 +02:00
} // End namespace gold.
#endif // !defined(GOLD_GOLD_H)