2007-09-21 09:20:01 +02:00
|
|
|
// parameters.cc -- general parameters for a link using gold
|
|
|
|
|
2007-09-22 23:02:10 +02:00
|
|
|
// Copyright 2006, 2007 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.
|
|
|
|
|
2007-09-21 09:20:01 +02:00
|
|
|
#include "gold.h"
|
|
|
|
|
2008-03-05 00:10:38 +01:00
|
|
|
#include "debug.h"
|
2007-09-21 09:20:01 +02:00
|
|
|
#include "options.h"
|
2007-12-01 07:34:12 +01:00
|
|
|
#include "target.h"
|
2008-02-28 01:18:24 +01:00
|
|
|
#include "target-select.h"
|
2007-09-21 09:20:01 +02:00
|
|
|
|
|
|
|
namespace gold
|
|
|
|
{
|
|
|
|
|
2008-02-28 01:18:24 +01:00
|
|
|
void
|
|
|
|
Parameters::set_errors(Errors* errors)
|
2007-09-21 09:20:01 +02:00
|
|
|
{
|
2008-02-28 01:18:24 +01:00
|
|
|
gold_assert(this->errors_ == NULL);
|
|
|
|
this->errors_ = errors;
|
2007-10-27 02:29:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2008-02-28 01:18:24 +01:00
|
|
|
Parameters::set_options(const General_options* options)
|
2007-10-27 02:29:34 +02:00
|
|
|
{
|
2008-02-28 01:18:24 +01:00
|
|
|
gold_assert(!this->options_valid());
|
|
|
|
this->options_ = options;
|
2008-03-05 00:10:38 +01:00
|
|
|
// For speed, we convert the options() debug var from a string to an
|
|
|
|
// enum (from debug.h).
|
|
|
|
this->debug_ = debug_string_to_enum(this->options().debug());
|
2007-09-21 09:20:01 +02:00
|
|
|
}
|
|
|
|
|
2007-09-28 08:36:25 +02:00
|
|
|
void
|
|
|
|
Parameters::set_doing_static_link(bool doing_static_link)
|
|
|
|
{
|
2008-02-28 01:18:24 +01:00
|
|
|
gold_assert(!this->doing_static_link_valid_);
|
2007-09-28 08:36:25 +02:00
|
|
|
this->doing_static_link_ = doing_static_link;
|
2008-02-28 01:18:24 +01:00
|
|
|
this->doing_static_link_valid_ = true;
|
2007-09-28 08:36:25 +02:00
|
|
|
}
|
|
|
|
|
2007-09-26 09:01:35 +02:00
|
|
|
void
|
2008-02-28 01:18:24 +01:00
|
|
|
Parameters::set_target(const Target* target)
|
2007-09-26 09:01:35 +02:00
|
|
|
{
|
2008-02-28 01:18:24 +01:00
|
|
|
if (!this->target_valid())
|
|
|
|
this->target_ = target;
|
2007-09-26 09:01:35 +02:00
|
|
|
else
|
2007-12-01 07:34:12 +01:00
|
|
|
gold_assert(target == this->target_);
|
2007-09-26 09:01:35 +02:00
|
|
|
}
|
|
|
|
|
2008-02-28 01:18:24 +01:00
|
|
|
// The x86_64 kernel build converts a binary file to an object file
|
|
|
|
// using -r --format binary --oformat elf32-i386 foo.o. In order to
|
|
|
|
// support that for gold we support determining the default target
|
|
|
|
// choice from the output format. We recognize names that the GNU
|
|
|
|
// linker uses.
|
2007-09-26 09:01:35 +02:00
|
|
|
|
2008-02-28 01:18:24 +01:00
|
|
|
const Target&
|
|
|
|
Parameters::default_target() const
|
|
|
|
{
|
|
|
|
gold_assert(this->options_valid());
|
2008-03-04 19:21:43 +01:00
|
|
|
if (this->options().oformat() != NULL)
|
2008-02-28 01:18:24 +01:00
|
|
|
{
|
|
|
|
const Target* target
|
2008-03-04 19:21:43 +01:00
|
|
|
= select_target_by_name(this->options().oformat());
|
2008-02-28 01:18:24 +01:00
|
|
|
if (target != NULL)
|
|
|
|
return *target;
|
2007-09-21 09:20:01 +02:00
|
|
|
|
2008-02-28 01:18:24 +01:00
|
|
|
gold_error(_("unrecognized output format %s"),
|
2008-03-04 19:21:43 +01:00
|
|
|
this->options().oformat());
|
2008-02-28 01:18:24 +01:00
|
|
|
}
|
2007-09-21 09:20:01 +02:00
|
|
|
|
2008-02-28 01:18:24 +01:00
|
|
|
// The GOLD_DEFAULT_xx macros are defined by the configure script.
|
|
|
|
const Target* target = select_target(elfcpp::GOLD_DEFAULT_MACHINE,
|
|
|
|
GOLD_DEFAULT_SIZE,
|
|
|
|
GOLD_DEFAULT_BIG_ENDIAN,
|
|
|
|
0, 0);
|
|
|
|
gold_assert(target != NULL);
|
|
|
|
return *target;
|
|
|
|
}
|
2007-09-21 09:20:01 +02:00
|
|
|
|
2008-02-28 01:18:24 +01:00
|
|
|
Parameters::Target_size_endianness
|
|
|
|
Parameters::size_and_endianness() const
|
2007-10-27 02:29:34 +02:00
|
|
|
{
|
2008-02-28 01:18:24 +01:00
|
|
|
if (this->target().get_size() == 32)
|
|
|
|
{
|
|
|
|
if (!this->target().is_big_endian())
|
|
|
|
{
|
|
|
|
#ifdef HAVE_TARGET_32_LITTLE
|
|
|
|
return TARGET_32_LITTLE;
|
|
|
|
#else
|
|
|
|
gold_unreachable();
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
#ifdef HAVE_TARGET_32_BIG
|
|
|
|
return TARGET_32_BIG;
|
|
|
|
#else
|
|
|
|
gold_unreachable();
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (parameters->target().get_size() == 64)
|
|
|
|
{
|
|
|
|
if (!parameters->target().is_big_endian())
|
|
|
|
{
|
|
|
|
#ifdef HAVE_TARGET_64_LITTLE
|
|
|
|
return TARGET_64_LITTLE;
|
|
|
|
#else
|
|
|
|
gold_unreachable();
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
#ifdef HAVE_TARGET_64_BIG
|
|
|
|
return TARGET_64_BIG;
|
|
|
|
#else
|
|
|
|
gold_unreachable();
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
gold_unreachable();
|
2007-10-27 02:29:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-02-28 01:18:24 +01:00
|
|
|
// Our local version of the variable, which is not const.
|
|
|
|
|
|
|
|
static Parameters static_parameters;
|
|
|
|
|
|
|
|
// The global variable.
|
2007-09-26 09:01:35 +02:00
|
|
|
|
2008-02-28 01:18:24 +01:00
|
|
|
const Parameters* parameters = &static_parameters;
|
2007-09-28 08:36:25 +02:00
|
|
|
|
|
|
|
void
|
2008-02-28 01:18:24 +01:00
|
|
|
set_parameters_errors(Errors* errors)
|
|
|
|
{ static_parameters.set_errors(errors); }
|
2007-09-28 08:36:25 +02:00
|
|
|
|
2008-02-28 01:18:24 +01:00
|
|
|
void
|
|
|
|
set_parameters_options(const General_options* options)
|
|
|
|
{ static_parameters.set_options(options); }
|
2007-09-28 08:36:25 +02:00
|
|
|
|
2007-09-26 09:01:35 +02:00
|
|
|
void
|
2008-02-28 01:18:24 +01:00
|
|
|
set_parameters_target(const Target* target)
|
|
|
|
{ static_parameters.set_target(target); }
|
|
|
|
|
|
|
|
void
|
|
|
|
set_parameters_doing_static_link(bool doing_static_link)
|
|
|
|
{ static_parameters.set_doing_static_link(doing_static_link); }
|
2007-09-21 09:20:01 +02:00
|
|
|
|
|
|
|
} // End namespace gold.
|