PR 11855
* script.cc (Script_options::Script_options): Initialize symbol_definitions_ and symbol_references_. (Script_options::add_symbol_assignment): Update symbol_definitions_ and symbol_references_. (Script_options::add_symbol_reference): New function. (script_symbol): New function. * script.h (class Script_options): Add symbol_definitions_ and symbol_references_ fields. (Script_options::referenced_const_iterator): New type. (Script_options::referenced_begin): New function. (Script_options::referenced_end): New function. (Script_options::is_referenced): New function. (Script_options::any_unreferenced): New function. * script-c.h (script_symbol): Declare. * yyscript.y (exp): Call script_symbol. * symtab.cc: Include "script.h". (Symbol_table::gc_mark_undef_symbols): Add layout parameter. Change all callers. Check symbols referenced by scripts. (Symbol_table::add_undefined_symbols_from_command_line): Add layout parameter. Change all callers. (Symbol_table::do_add_undefined_symbols_from_command_line): Likewise. Break out loop body. Check symbols referenced by scripts. (Symbol_table::add_undefined_symbol_from_command_line): New function broken out of do_add_undefined_symbols_from_command_line. * symtab.h (class Symbol_table): Update declarations. * archive.cc: Include "layout.h". (Archive::should_include_member): Add layout parameter. Change all callers. Check for symbol mentioned in expression. * archive.h (class Archive): Update declaration. * object.cc (Sized_relobj::do_should_include_member): Add layout parameter. * object.h (Object::should_include_member): Add layout parameter. Change all callers. (Object::do_should_include_member): Add layout parameter. (class Sized_relobj): Update declaration. * dynobj.cc (Sized_dynobj::do_should_include_member): Add layout parameter. * dynobj.h (class Sized_dynobj): Update declaration. * plugin.cc (Sized_pluginobj::do_should_include_member): Add layout parameter. * plugin.h (class Sized_pluginobj): Update declaration.
This commit is contained in:
parent
93d90f466b
commit
88a4108bde
16 changed files with 255 additions and 76 deletions
|
@ -1,3 +1,50 @@
|
||||||
|
2010-08-02 Ian Lance Taylor <iant@google.com>
|
||||||
|
|
||||||
|
PR 11855
|
||||||
|
* script.cc (Script_options::Script_options): Initialize
|
||||||
|
symbol_definitions_ and symbol_references_.
|
||||||
|
(Script_options::add_symbol_assignment): Update
|
||||||
|
symbol_definitions_ and symbol_references_.
|
||||||
|
(Script_options::add_symbol_reference): New function.
|
||||||
|
(script_symbol): New function.
|
||||||
|
* script.h (class Script_options): Add symbol_definitions_ and
|
||||||
|
symbol_references_ fields.
|
||||||
|
(Script_options::referenced_const_iterator): New type.
|
||||||
|
(Script_options::referenced_begin): New function.
|
||||||
|
(Script_options::referenced_end): New function.
|
||||||
|
(Script_options::is_referenced): New function.
|
||||||
|
(Script_options::any_unreferenced): New function.
|
||||||
|
* script-c.h (script_symbol): Declare.
|
||||||
|
* yyscript.y (exp): Call script_symbol.
|
||||||
|
* symtab.cc: Include "script.h".
|
||||||
|
(Symbol_table::gc_mark_undef_symbols): Add layout parameter.
|
||||||
|
Change all callers. Check symbols referenced by scripts.
|
||||||
|
(Symbol_table::add_undefined_symbols_from_command_line): Add
|
||||||
|
layout parameter. Change all callers.
|
||||||
|
(Symbol_table::do_add_undefined_symbols_from_command_line):
|
||||||
|
Likewise. Break out loop body. Check symbols referenced by
|
||||||
|
scripts.
|
||||||
|
(Symbol_table::add_undefined_symbol_from_command_line): New
|
||||||
|
function broken out of
|
||||||
|
do_add_undefined_symbols_from_command_line.
|
||||||
|
* symtab.h (class Symbol_table): Update declarations.
|
||||||
|
* archive.cc: Include "layout.h".
|
||||||
|
(Archive::should_include_member): Add layout parameter. Change
|
||||||
|
all callers. Check for symbol mentioned in expression.
|
||||||
|
* archive.h (class Archive): Update declaration.
|
||||||
|
* object.cc (Sized_relobj::do_should_include_member): Add layout
|
||||||
|
parameter.
|
||||||
|
* object.h (Object::should_include_member): Add layout parameter.
|
||||||
|
Change all callers.
|
||||||
|
(Object::do_should_include_member): Add layout parameter.
|
||||||
|
(class Sized_relobj): Update declaration.
|
||||||
|
* dynobj.cc (Sized_dynobj::do_should_include_member): Add layout
|
||||||
|
parameter.
|
||||||
|
* dynobj.h (class Sized_dynobj): Update declaration.
|
||||||
|
* plugin.cc (Sized_pluginobj::do_should_include_member): Add
|
||||||
|
layout parameter.
|
||||||
|
* plugin.h (class Sized_pluginobj): Update declaration.
|
||||||
|
|
||||||
2010-08-02 Ian Lance Taylor <iant@google.com>
|
2010-08-02 Ian Lance Taylor <iant@google.com>
|
||||||
|
|
||||||
PR 11866
|
PR 11866
|
||||||
|
|
|
@ -36,6 +36,7 @@
|
||||||
#include "readsyms.h"
|
#include "readsyms.h"
|
||||||
#include "symtab.h"
|
#include "symtab.h"
|
||||||
#include "object.h"
|
#include "object.h"
|
||||||
|
#include "layout.h"
|
||||||
#include "archive.h"
|
#include "archive.h"
|
||||||
#include "plugin.h"
|
#include "plugin.h"
|
||||||
|
|
||||||
|
@ -603,8 +604,9 @@ Archive::read_symbols(off_t off)
|
||||||
}
|
}
|
||||||
|
|
||||||
Archive::Should_include
|
Archive::Should_include
|
||||||
Archive::should_include_member(Symbol_table* symtab, const char* sym_name,
|
Archive::should_include_member(Symbol_table* symtab, Layout* layout,
|
||||||
Symbol** symp, std::string* why, char** tmpbufp,
|
const char* sym_name, Symbol** symp,
|
||||||
|
std::string* why, char** tmpbufp,
|
||||||
size_t* tmpbuflen)
|
size_t* tmpbuflen)
|
||||||
{
|
{
|
||||||
// In an object file, and therefore in an archive map, an
|
// In an object file, and therefore in an archive map, an
|
||||||
|
@ -648,13 +650,22 @@ Archive::should_include_member(Symbol_table* symtab, const char* sym_name,
|
||||||
if (sym == NULL)
|
if (sym == NULL)
|
||||||
{
|
{
|
||||||
// Check whether the symbol was named in a -u option.
|
// Check whether the symbol was named in a -u option.
|
||||||
if (!parameters->options().is_undefined(sym_name))
|
if (parameters->options().is_undefined(sym_name))
|
||||||
return Archive::SHOULD_INCLUDE_UNKNOWN;
|
|
||||||
else
|
|
||||||
{
|
{
|
||||||
*why = "-u ";
|
*why = "-u ";
|
||||||
*why += sym_name;
|
*why += sym_name;
|
||||||
}
|
}
|
||||||
|
else if (layout->script_options()->is_referenced(sym_name))
|
||||||
|
{
|
||||||
|
size_t alc = 100 + strlen(sym_name);
|
||||||
|
char* buf = new char[alc];
|
||||||
|
snprintf(buf, alc, _("script or expression reference to %s"),
|
||||||
|
sym_name);
|
||||||
|
*why = buf;
|
||||||
|
delete[] buf;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
return Archive::SHOULD_INCLUDE_UNKNOWN;
|
||||||
}
|
}
|
||||||
else if (!sym->is_undefined())
|
else if (!sym->is_undefined())
|
||||||
return Archive::SHOULD_INCLUDE_NO;
|
return Archive::SHOULD_INCLUDE_NO;
|
||||||
|
@ -726,8 +737,8 @@ Archive::add_symbols(Symbol_table* symtab, Layout* layout,
|
||||||
Symbol* sym;
|
Symbol* sym;
|
||||||
std::string why;
|
std::string why;
|
||||||
Archive::Should_include t =
|
Archive::Should_include t =
|
||||||
Archive::should_include_member(symtab, sym_name, &sym, &why,
|
Archive::should_include_member(symtab, layout, sym_name, &sym,
|
||||||
&tmpbuf, &tmpbuflen);
|
&why, &tmpbuf, &tmpbuflen);
|
||||||
|
|
||||||
if (t == Archive::SHOULD_INCLUDE_NO
|
if (t == Archive::SHOULD_INCLUDE_NO
|
||||||
|| t == Archive::SHOULD_INCLUDE_YES)
|
|| t == Archive::SHOULD_INCLUDE_YES)
|
||||||
|
@ -1015,6 +1026,7 @@ Lib_group::add_symbols(Symbol_table* symtab, Layout* layout,
|
||||||
&& (member.sd_ == NULL || member.sd_->symbol_names != NULL))
|
&& (member.sd_ == NULL || member.sd_->symbol_names != NULL))
|
||||||
{
|
{
|
||||||
Archive::Should_include t = obj->should_include_member(symtab,
|
Archive::Should_include t = obj->should_include_member(symtab,
|
||||||
|
layout,
|
||||||
member.sd_,
|
member.sd_,
|
||||||
&why);
|
&why);
|
||||||
|
|
||||||
|
|
|
@ -176,7 +176,7 @@ class Archive
|
||||||
};
|
};
|
||||||
|
|
||||||
static Should_include
|
static Should_include
|
||||||
should_include_member(Symbol_table* symtab, const char* sym_name,
|
should_include_member(Symbol_table* symtab, Layout*, const char* sym_name,
|
||||||
Symbol** symp, std::string* why, char** tmpbufp,
|
Symbol** symp, std::string* why, char** tmpbufp,
|
||||||
size_t* tmpbuflen);
|
size_t* tmpbuflen);
|
||||||
|
|
||||||
|
|
|
@ -753,8 +753,10 @@ Sized_dynobj<size, big_endian>::do_add_symbols(Symbol_table* symtab,
|
||||||
|
|
||||||
template<int size, bool big_endian>
|
template<int size, bool big_endian>
|
||||||
Archive::Should_include
|
Archive::Should_include
|
||||||
Sized_dynobj<size, big_endian>::do_should_include_member(
|
Sized_dynobj<size, big_endian>::do_should_include_member(Symbol_table*,
|
||||||
Symbol_table*, Read_symbols_data*, std::string*)
|
Layout*,
|
||||||
|
Read_symbols_data*,
|
||||||
|
std::string*)
|
||||||
{
|
{
|
||||||
return Archive::SHOULD_INCLUDE_YES;
|
return Archive::SHOULD_INCLUDE_YES;
|
||||||
}
|
}
|
||||||
|
|
|
@ -178,7 +178,7 @@ class Sized_dynobj : public Dynobj
|
||||||
do_add_symbols(Symbol_table*, Read_symbols_data*, Layout*);
|
do_add_symbols(Symbol_table*, Read_symbols_data*, Layout*);
|
||||||
|
|
||||||
Archive::Should_include
|
Archive::Should_include
|
||||||
do_should_include_member(Symbol_table* symtab, Read_symbols_data*,
|
do_should_include_member(Symbol_table* symtab, Layout*, Read_symbols_data*,
|
||||||
std::string* why);
|
std::string* why);
|
||||||
|
|
||||||
// Get the size of a section.
|
// Get the size of a section.
|
||||||
|
|
|
@ -309,7 +309,7 @@ queue_middle_tasks(const General_options& options,
|
||||||
Mapfile* mapfile)
|
Mapfile* mapfile)
|
||||||
{
|
{
|
||||||
// Add any symbols named with -u options to the symbol table.
|
// Add any symbols named with -u options to the symbol table.
|
||||||
symtab->add_undefined_symbols_from_command_line();
|
symtab->add_undefined_symbols_from_command_line(layout);
|
||||||
|
|
||||||
// If garbage collection was chosen, relocs have been read and processed
|
// If garbage collection was chosen, relocs have been read and processed
|
||||||
// at this point by pre_middle_tasks. Layout can then be done for all
|
// at this point by pre_middle_tasks. Layout can then be done for all
|
||||||
|
@ -333,7 +333,7 @@ queue_middle_tasks(const General_options& options,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Symbols named with -u should not be considered garbage.
|
// Symbols named with -u should not be considered garbage.
|
||||||
symtab->gc_mark_undef_symbols();
|
symtab->gc_mark_undef_symbols(layout);
|
||||||
gold_assert(symtab->gc() != NULL);
|
gold_assert(symtab->gc() != NULL);
|
||||||
// Do a transitive closure on all references to determine the worklist.
|
// Do a transitive closure on all references to determine the worklist.
|
||||||
symtab->gc()->do_transitive_closure();
|
symtab->gc()->do_transitive_closure();
|
||||||
|
|
|
@ -1614,6 +1614,7 @@ Sized_relobj<size, big_endian>::do_add_symbols(Symbol_table* symtab,
|
||||||
template<int size, bool big_endian>
|
template<int size, bool big_endian>
|
||||||
Archive::Should_include
|
Archive::Should_include
|
||||||
Sized_relobj<size, big_endian>::do_should_include_member(Symbol_table* symtab,
|
Sized_relobj<size, big_endian>::do_should_include_member(Symbol_table* symtab,
|
||||||
|
Layout* layout,
|
||||||
Read_symbols_data* sd,
|
Read_symbols_data* sd,
|
||||||
std::string* why)
|
std::string* why)
|
||||||
{
|
{
|
||||||
|
@ -1639,7 +1640,9 @@ Sized_relobj<size, big_endian>::do_should_include_member(Symbol_table* symtab,
|
||||||
unsigned int st_name = sym.get_st_name();
|
unsigned int st_name = sym.get_st_name();
|
||||||
const char* name = sym_names + st_name;
|
const char* name = sym_names + st_name;
|
||||||
Symbol* symbol;
|
Symbol* symbol;
|
||||||
Archive::Should_include t = Archive::should_include_member(symtab, name,
|
Archive::Should_include t = Archive::should_include_member(symtab,
|
||||||
|
layout,
|
||||||
|
name,
|
||||||
&symbol, why,
|
&symbol, why,
|
||||||
&tmpbuf,
|
&tmpbuf,
|
||||||
&tmpbuflen);
|
&tmpbuflen);
|
||||||
|
|
|
@ -405,9 +405,9 @@ class Object
|
||||||
|
|
||||||
// Add symbol information to the global symbol table.
|
// Add symbol information to the global symbol table.
|
||||||
Archive::Should_include
|
Archive::Should_include
|
||||||
should_include_member(Symbol_table* symtab, Read_symbols_data* sd,
|
should_include_member(Symbol_table* symtab, Layout* layout,
|
||||||
std::string* why)
|
Read_symbols_data* sd, std::string* why)
|
||||||
{ return this->do_should_include_member(symtab, sd, why); }
|
{ return this->do_should_include_member(symtab, layout, sd, why); }
|
||||||
|
|
||||||
// Functions and types for the elfcpp::Elf_file interface. This
|
// Functions and types for the elfcpp::Elf_file interface. This
|
||||||
// permit us to use Object as the File template parameter for
|
// permit us to use Object as the File template parameter for
|
||||||
|
@ -546,7 +546,7 @@ class Object
|
||||||
do_add_symbols(Symbol_table*, Read_symbols_data*, Layout*) = 0;
|
do_add_symbols(Symbol_table*, Read_symbols_data*, Layout*) = 0;
|
||||||
|
|
||||||
virtual Archive::Should_include
|
virtual Archive::Should_include
|
||||||
do_should_include_member(Symbol_table* symtab, Read_symbols_data*,
|
do_should_include_member(Symbol_table* symtab, Layout*, Read_symbols_data*,
|
||||||
std::string* why) = 0;
|
std::string* why) = 0;
|
||||||
|
|
||||||
// Return the location of the contents of a section. Implemented by
|
// Return the location of the contents of a section. Implemented by
|
||||||
|
@ -1623,7 +1623,7 @@ class Sized_relobj : public Relobj
|
||||||
do_add_symbols(Symbol_table*, Read_symbols_data*, Layout*);
|
do_add_symbols(Symbol_table*, Read_symbols_data*, Layout*);
|
||||||
|
|
||||||
Archive::Should_include
|
Archive::Should_include
|
||||||
do_should_include_member(Symbol_table* symtab, Read_symbols_data*,
|
do_should_include_member(Symbol_table* symtab, Layout*, Read_symbols_data*,
|
||||||
std::string* why);
|
std::string* why);
|
||||||
|
|
||||||
// Read the relocs.
|
// Read the relocs.
|
||||||
|
|
|
@ -705,16 +705,22 @@ Sized_pluginobj<size, big_endian>::do_add_symbols(Symbol_table* symtab,
|
||||||
template<int size, bool big_endian>
|
template<int size, bool big_endian>
|
||||||
Archive::Should_include
|
Archive::Should_include
|
||||||
Sized_pluginobj<size, big_endian>::do_should_include_member(
|
Sized_pluginobj<size, big_endian>::do_should_include_member(
|
||||||
Symbol_table* symtab, Read_symbols_data*, std::string* why)
|
Symbol_table* symtab,
|
||||||
|
Layout* layout,
|
||||||
|
Read_symbols_data*,
|
||||||
|
std::string* why)
|
||||||
{
|
{
|
||||||
char* tmpbuf = NULL;
|
char* tmpbuf = NULL;
|
||||||
size_t tmpbuflen = 0;
|
size_t tmpbuflen = 0;
|
||||||
|
|
||||||
for (int i = 0; i < this->nsyms_; ++i) {
|
for (int i = 0; i < this->nsyms_; ++i)
|
||||||
|
{
|
||||||
const struct ld_plugin_symbol& sym = this->syms_[i];
|
const struct ld_plugin_symbol& sym = this->syms_[i];
|
||||||
const char* name = sym.name;
|
const char* name = sym.name;
|
||||||
Symbol* symbol;
|
Symbol* symbol;
|
||||||
Archive::Should_include t = Archive::should_include_member(symtab, name,
|
Archive::Should_include t = Archive::should_include_member(symtab,
|
||||||
|
layout,
|
||||||
|
name,
|
||||||
&symbol, why,
|
&symbol, why,
|
||||||
&tmpbuf,
|
&tmpbuf,
|
||||||
&tmpbuflen);
|
&tmpbuflen);
|
||||||
|
|
|
@ -376,7 +376,7 @@ class Sized_pluginobj : public Pluginobj
|
||||||
do_add_symbols(Symbol_table*, Read_symbols_data*, Layout*);
|
do_add_symbols(Symbol_table*, Read_symbols_data*, Layout*);
|
||||||
|
|
||||||
Archive::Should_include
|
Archive::Should_include
|
||||||
do_should_include_member(Symbol_table* symtab, Read_symbols_data*,
|
do_should_include_member(Symbol_table* symtab, Layout*, Read_symbols_data*,
|
||||||
std::string* why);
|
std::string* why);
|
||||||
|
|
||||||
// Get the size of a section.
|
// Get the size of a section.
|
||||||
|
|
|
@ -303,6 +303,14 @@ script_push_lex_into_version_mode(void* closure);
|
||||||
extern void
|
extern void
|
||||||
script_pop_lex_mode(void* closure);
|
script_pop_lex_mode(void* closure);
|
||||||
|
|
||||||
|
/* Called by the bison parser to get the value of a symbol. This is
|
||||||
|
called for a reference to a symbol, but is not called for something
|
||||||
|
like "sym += 10". Uses of the special symbol "." can just call
|
||||||
|
script_exp_string. */
|
||||||
|
|
||||||
|
extern Expression_ptr
|
||||||
|
script_symbol(void* closure, const char*, size_t);
|
||||||
|
|
||||||
/* Called by the bison parser to set a symbol to a value. PROVIDE is
|
/* Called by the bison parser to set a symbol to a value. PROVIDE is
|
||||||
non-zero if the symbol should be provided--only defined if there is
|
non-zero if the symbol should be provided--only defined if there is
|
||||||
an undefined reference. HIDDEN is non-zero if the symbol should be
|
an undefined reference. HIDDEN is non-zero if the symbol should be
|
||||||
|
|
|
@ -1045,8 +1045,8 @@ Script_assertion::print(FILE* f) const
|
||||||
// Class Script_options.
|
// Class Script_options.
|
||||||
|
|
||||||
Script_options::Script_options()
|
Script_options::Script_options()
|
||||||
: entry_(), symbol_assignments_(), version_script_info_(),
|
: entry_(), symbol_assignments_(), symbol_definitions_(),
|
||||||
script_sections_()
|
symbol_references_(), version_script_info_(), script_sections_()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1071,6 +1071,13 @@ Script_options::add_symbol_assignment(const char* name, size_t length,
|
||||||
value, provide, hidden);
|
value, provide, hidden);
|
||||||
this->symbol_assignments_.push_back(p);
|
this->symbol_assignments_.push_back(p);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!provide)
|
||||||
|
{
|
||||||
|
std::string n(name, length);
|
||||||
|
this->symbol_definitions_.insert(n);
|
||||||
|
this->symbol_references_.erase(n);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -1084,6 +1091,19 @@ Script_options::add_symbol_assignment(const char* name, size_t length,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Add a reference to a symbol.
|
||||||
|
|
||||||
|
void
|
||||||
|
Script_options::add_symbol_reference(const char* name, size_t length)
|
||||||
|
{
|
||||||
|
if (length != 1 || name[0] != '.')
|
||||||
|
{
|
||||||
|
std::string n(name, length);
|
||||||
|
if (this->symbol_definitions_.find(n) == this->symbol_definitions_.end())
|
||||||
|
this->symbol_references_.insert(n);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Add an assertion.
|
// Add an assertion.
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -2679,6 +2699,17 @@ script_set_common_allocation(void* closurev, int set)
|
||||||
script_parse_option(closurev, arg, strlen(arg));
|
script_parse_option(closurev, arg, strlen(arg));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Called by the bison parser to refer to a symbol.
|
||||||
|
|
||||||
|
extern "C" Expression*
|
||||||
|
script_symbol(void *closurev, const char* name, size_t length)
|
||||||
|
{
|
||||||
|
Parser_closure* closure = static_cast<Parser_closure*>(closurev);
|
||||||
|
if (length != 1 || name[0] != '.')
|
||||||
|
closure->script_options()->add_symbol_reference(name, length);
|
||||||
|
return script_exp_string(name, length);
|
||||||
|
}
|
||||||
|
|
||||||
// Called by the bison parser to define a symbol.
|
// Called by the bison parser to define a symbol.
|
||||||
|
|
||||||
extern "C" void
|
extern "C" void
|
||||||
|
|
|
@ -423,6 +423,10 @@ class Script_options
|
||||||
add_symbol_assignment(const char* name, size_t length, bool is_defsym,
|
add_symbol_assignment(const char* name, size_t length, bool is_defsym,
|
||||||
Expression* value, bool provide, bool hidden);
|
Expression* value, bool provide, bool hidden);
|
||||||
|
|
||||||
|
// Add a reference to a symbol.
|
||||||
|
void
|
||||||
|
add_symbol_reference(const char* name, size_t length);
|
||||||
|
|
||||||
// Add an assertion.
|
// Add an assertion.
|
||||||
void
|
void
|
||||||
add_assertion(Expression* check, const char* message, size_t messagelen);
|
add_assertion(Expression* check, const char* message, size_t messagelen);
|
||||||
|
@ -439,6 +443,32 @@ class Script_options
|
||||||
void
|
void
|
||||||
add_symbols_to_table(Symbol_table*);
|
add_symbols_to_table(Symbol_table*);
|
||||||
|
|
||||||
|
// Used to iterate over symbols which are referenced in expressions
|
||||||
|
// but not defined.
|
||||||
|
typedef Unordered_set<std::string>::const_iterator referenced_const_iterator;
|
||||||
|
|
||||||
|
referenced_const_iterator
|
||||||
|
referenced_begin() const
|
||||||
|
{ return this->symbol_references_.begin(); }
|
||||||
|
|
||||||
|
referenced_const_iterator
|
||||||
|
referenced_end() const
|
||||||
|
{ return this->symbol_references_.end(); }
|
||||||
|
|
||||||
|
// Return whether a symbol is referenced but not defined.
|
||||||
|
bool
|
||||||
|
is_referenced(const std::string& name) const
|
||||||
|
{
|
||||||
|
return (this->symbol_references_.find(name)
|
||||||
|
!= this->symbol_references_.end());
|
||||||
|
}
|
||||||
|
|
||||||
|
// Return whether there are any symbols which were referenced but
|
||||||
|
// not defined.
|
||||||
|
bool
|
||||||
|
any_unreferenced() const
|
||||||
|
{ return !this->symbol_references_.empty(); }
|
||||||
|
|
||||||
// Finalize the symbol values. Also check assertions.
|
// Finalize the symbol values. Also check assertions.
|
||||||
void
|
void
|
||||||
finalize_symbols(Symbol_table*, const Layout*);
|
finalize_symbols(Symbol_table*, const Layout*);
|
||||||
|
@ -497,6 +527,10 @@ class Script_options
|
||||||
std::string entry_;
|
std::string entry_;
|
||||||
// Symbols to set.
|
// Symbols to set.
|
||||||
Symbol_assignments symbol_assignments_;
|
Symbol_assignments symbol_assignments_;
|
||||||
|
// Symbols defined in an expression, for faster lookup.
|
||||||
|
Unordered_set<std::string> symbol_definitions_;
|
||||||
|
// Symbols referenced in an expression.
|
||||||
|
Unordered_set<std::string> symbol_references_;
|
||||||
// Assertions to check.
|
// Assertions to check.
|
||||||
Assertions assertions_;
|
Assertions assertions_;
|
||||||
// Version information parsed from a version script.
|
// Version information parsed from a version script.
|
||||||
|
|
|
@ -38,7 +38,7 @@
|
||||||
#include "target.h"
|
#include "target.h"
|
||||||
#include "workqueue.h"
|
#include "workqueue.h"
|
||||||
#include "symtab.h"
|
#include "symtab.h"
|
||||||
#include "demangle.h" // needed for --dynamic-list-cpp-new
|
#include "script.h"
|
||||||
#include "plugin.h"
|
#include "plugin.h"
|
||||||
|
|
||||||
namespace gold
|
namespace gold
|
||||||
|
@ -530,7 +530,7 @@ Symbol_table::is_section_folded(Object* obj, unsigned int shndx) const
|
||||||
// work list to avoid gc'ing them.
|
// work list to avoid gc'ing them.
|
||||||
|
|
||||||
void
|
void
|
||||||
Symbol_table::gc_mark_undef_symbols()
|
Symbol_table::gc_mark_undef_symbols(Layout* layout)
|
||||||
{
|
{
|
||||||
for (options::String_set::const_iterator p =
|
for (options::String_set::const_iterator p =
|
||||||
parameters->options().undefined_begin();
|
parameters->options().undefined_begin();
|
||||||
|
@ -553,6 +553,27 @@ Symbol_table::gc_mark_undef_symbols()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for (Script_options::referenced_const_iterator p =
|
||||||
|
layout->script_options()->referenced_begin();
|
||||||
|
p != layout->script_options()->referenced_end();
|
||||||
|
++p)
|
||||||
|
{
|
||||||
|
Symbol* sym = this->lookup(p->c_str());
|
||||||
|
gold_assert(sym != NULL);
|
||||||
|
if (sym->source() == Symbol::FROM_OBJECT
|
||||||
|
&& !sym->object()->is_dynamic())
|
||||||
|
{
|
||||||
|
Relobj* obj = static_cast<Relobj*>(sym->object());
|
||||||
|
bool is_ordinary;
|
||||||
|
unsigned int shndx = sym->shndx(&is_ordinary);
|
||||||
|
if (is_ordinary)
|
||||||
|
{
|
||||||
|
gold_assert(this->gc_ != NULL);
|
||||||
|
this->gc_->worklist().push(Section_id(obj, shndx));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -2163,14 +2184,15 @@ Symbol_table::get_copy_source(const Symbol* sym) const
|
||||||
// Add any undefined symbols named on the command line.
|
// Add any undefined symbols named on the command line.
|
||||||
|
|
||||||
void
|
void
|
||||||
Symbol_table::add_undefined_symbols_from_command_line()
|
Symbol_table::add_undefined_symbols_from_command_line(Layout* layout)
|
||||||
{
|
{
|
||||||
if (parameters->options().any_undefined())
|
if (parameters->options().any_undefined()
|
||||||
|
|| layout->script_options()->any_unreferenced())
|
||||||
{
|
{
|
||||||
if (parameters->target().get_size() == 32)
|
if (parameters->target().get_size() == 32)
|
||||||
{
|
{
|
||||||
#if defined(HAVE_TARGET_32_LITTLE) || defined(HAVE_TARGET_32_BIG)
|
#if defined(HAVE_TARGET_32_LITTLE) || defined(HAVE_TARGET_32_BIG)
|
||||||
this->do_add_undefined_symbols_from_command_line<32>();
|
this->do_add_undefined_symbols_from_command_line<32>(layout);
|
||||||
#else
|
#else
|
||||||
gold_unreachable();
|
gold_unreachable();
|
||||||
#endif
|
#endif
|
||||||
|
@ -2178,7 +2200,7 @@ Symbol_table::add_undefined_symbols_from_command_line()
|
||||||
else if (parameters->target().get_size() == 64)
|
else if (parameters->target().get_size() == 64)
|
||||||
{
|
{
|
||||||
#if defined(HAVE_TARGET_64_LITTLE) || defined(HAVE_TARGET_64_BIG)
|
#if defined(HAVE_TARGET_64_LITTLE) || defined(HAVE_TARGET_64_BIG)
|
||||||
this->do_add_undefined_symbols_from_command_line<64>();
|
this->do_add_undefined_symbols_from_command_line<64>(layout);
|
||||||
#else
|
#else
|
||||||
gold_unreachable();
|
gold_unreachable();
|
||||||
#endif
|
#endif
|
||||||
|
@ -2190,17 +2212,27 @@ Symbol_table::add_undefined_symbols_from_command_line()
|
||||||
|
|
||||||
template<int size>
|
template<int size>
|
||||||
void
|
void
|
||||||
Symbol_table::do_add_undefined_symbols_from_command_line()
|
Symbol_table::do_add_undefined_symbols_from_command_line(Layout* layout)
|
||||||
{
|
{
|
||||||
for (options::String_set::const_iterator p =
|
for (options::String_set::const_iterator p =
|
||||||
parameters->options().undefined_begin();
|
parameters->options().undefined_begin();
|
||||||
p != parameters->options().undefined_end();
|
p != parameters->options().undefined_end();
|
||||||
++p)
|
++p)
|
||||||
{
|
this->add_undefined_symbol_from_command_line<size>(p->c_str());
|
||||||
const char* name = p->c_str();
|
|
||||||
|
|
||||||
|
for (Script_options::referenced_const_iterator p =
|
||||||
|
layout->script_options()->referenced_begin();
|
||||||
|
p != layout->script_options()->referenced_end();
|
||||||
|
++p)
|
||||||
|
this->add_undefined_symbol_from_command_line<size>(p->c_str());
|
||||||
|
}
|
||||||
|
|
||||||
|
template<int size>
|
||||||
|
void
|
||||||
|
Symbol_table::add_undefined_symbol_from_command_line(const char* name)
|
||||||
|
{
|
||||||
if (this->lookup(name) != NULL)
|
if (this->lookup(name) != NULL)
|
||||||
continue;
|
return;
|
||||||
|
|
||||||
const char* version = NULL;
|
const char* version = NULL;
|
||||||
|
|
||||||
|
@ -2233,7 +2265,6 @@ Symbol_table::do_add_undefined_symbols_from_command_line()
|
||||||
sym->init_undefined(name, version, elfcpp::STT_NOTYPE, elfcpp::STB_GLOBAL,
|
sym->init_undefined(name, version, elfcpp::STT_NOTYPE, elfcpp::STB_GLOBAL,
|
||||||
elfcpp::STV_DEFAULT, 0);
|
elfcpp::STV_DEFAULT, 0);
|
||||||
++this->saw_undefined_;
|
++this->saw_undefined_;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set the dynamic symbol indexes. INDEX is the index of the first
|
// Set the dynamic symbol indexes. INDEX is the index of the first
|
||||||
|
|
|
@ -1269,7 +1269,7 @@ class Symbol_table
|
||||||
|
|
||||||
// During garbage collection, this keeps undefined symbols.
|
// During garbage collection, this keeps undefined symbols.
|
||||||
void
|
void
|
||||||
gc_mark_undef_symbols();
|
gc_mark_undef_symbols(Layout*);
|
||||||
|
|
||||||
// During garbage collection, this ensures externally visible symbols
|
// During garbage collection, this ensures externally visible symbols
|
||||||
// are not treated as garbage while building shared objects.
|
// are not treated as garbage while building shared objects.
|
||||||
|
@ -1419,7 +1419,7 @@ class Symbol_table
|
||||||
// Add any undefined symbols named on the command line to the symbol
|
// Add any undefined symbols named on the command line to the symbol
|
||||||
// table.
|
// table.
|
||||||
void
|
void
|
||||||
add_undefined_symbols_from_command_line();
|
add_undefined_symbols_from_command_line(Layout*);
|
||||||
|
|
||||||
// SYM is defined using a COPY reloc. Return the dynamic object
|
// SYM is defined using a COPY reloc. Return the dynamic object
|
||||||
// where the original definition was found.
|
// where the original definition was found.
|
||||||
|
@ -1633,7 +1633,12 @@ class Symbol_table
|
||||||
// table, sized version.
|
// table, sized version.
|
||||||
template<int size>
|
template<int size>
|
||||||
void
|
void
|
||||||
do_add_undefined_symbols_from_command_line();
|
do_add_undefined_symbols_from_command_line(Layout*);
|
||||||
|
|
||||||
|
// Add one undefined symbol.
|
||||||
|
template<int size>
|
||||||
|
void
|
||||||
|
add_undefined_symbol_from_command_line(const char* name);
|
||||||
|
|
||||||
// Types of common symbols.
|
// Types of common symbols.
|
||||||
|
|
||||||
|
|
|
@ -867,7 +867,7 @@ exp:
|
||||||
| INTEGER
|
| INTEGER
|
||||||
{ $$ = script_exp_integer($1); }
|
{ $$ = script_exp_integer($1); }
|
||||||
| string
|
| string
|
||||||
{ $$ = script_exp_string($1.value, $1.length); }
|
{ $$ = script_symbol(closure, $1.value, $1.length); }
|
||||||
| MAX_K '(' exp ',' exp ')'
|
| MAX_K '(' exp ',' exp ')'
|
||||||
{ $$ = script_exp_function_max($3, $5); }
|
{ $$ = script_exp_function_max($3, $5); }
|
||||||
| MIN_K '(' exp ',' exp ')'
|
| MIN_K '(' exp ',' exp ')'
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue