return false;
}
+// If NAME is the name of the special section which indicates that
+// this object was compiled with -fstack-split, mark it accordingly.
+
+bool
+Object::handle_split_stack_section(const char* name)
+{
+ if (strcmp(name, ".note.GNU-split-stack") == 0)
+ {
+ this->uses_split_stack_ = true;
+ return true;
+ }
+ if (strcmp(name, ".note.GNU-no-split-stack") == 0)
+ {
+ this->has_no_split_stack_ = true;
+ return true;
+ }
+ return false;
+}
+
// Class Relobj
// To copy the symbols data read from the file to a local data structure.
template<int size, bool big_endian>
void
-Sized_relobj<size, big_endian>::setup()
+Sized_relobj<size, big_endian>::do_setup()
{
const unsigned int shnum = this->elf_file_.shnum();
this->set_shnum(shnum);
omit[i] = true;
}
+ // The .note.GNU-split-stack section is also special. It
+ // indicates that the object was compiled with
+ // -fsplit-stack.
+ if (this->handle_split_stack_section(name))
+ {
+ if (!parameters->options().relocatable()
+ && !parameters->options().shared())
+ omit[i] = true;
+ }
+
bool discard = omit[i];
if (!discard)
{
const unsigned char** start, int *read_size)
{
off_t filesize = input_file->file().filesize();
- int want = elfcpp::Elf_sizes<64>::ehdr_size;
+ int want = elfcpp::Elf_recognizer::max_header_size;
if (filesize - offset < want)
want = filesize - offset;
*start = p;
*read_size = want;
- if (want < 4)
- return false;
-
- static unsigned char elfmagic[4] =
- {
- elfcpp::ELFMAG0, elfcpp::ELFMAG1,
- elfcpp::ELFMAG2, elfcpp::ELFMAG3
- };
- return memcmp(p, elfmagic, 4) == 0;
+ return elfcpp::Elf_recognizer::is_elf_file(p, want);
}
// Read an ELF file and return the appropriate instance of Object.
if (punconfigured != NULL)
*punconfigured = false;
- if (bytes < elfcpp::EI_NIDENT)
- {
- gold_error(_("%s: ELF file too short"), name.c_str());
- return NULL;
- }
-
- int v = p[elfcpp::EI_VERSION];
- if (v != elfcpp::EV_CURRENT)
- {
- if (v == elfcpp::EV_NONE)
- gold_error(_("%s: invalid ELF version 0"), name.c_str());
- else
- gold_error(_("%s: unsupported ELF version %d"), name.c_str(), v);
- return NULL;
- }
-
- int c = p[elfcpp::EI_CLASS];
- if (c == elfcpp::ELFCLASSNONE)
- {
- gold_error(_("%s: invalid ELF class 0"), name.c_str());
- return NULL;
- }
- else if (c != elfcpp::ELFCLASS32
- && c != elfcpp::ELFCLASS64)
+ std::string error;
+ bool big_endian;
+ int size;
+ if (!elfcpp::Elf_recognizer::is_valid_header(p, bytes, &size,
+ &big_endian, &error))
{
- gold_error(_("%s: unsupported ELF class %d"), name.c_str(), c);
+ gold_error(_("%s: %s"), name.c_str(), error.c_str());
return NULL;
}
- int d = p[elfcpp::EI_DATA];
- if (d == elfcpp::ELFDATANONE)
- {
- gold_error(_("%s: invalid ELF data encoding"), name.c_str());
- return NULL;
- }
- else if (d != elfcpp::ELFDATA2LSB
- && d != elfcpp::ELFDATA2MSB)
+ if (size == 32)
{
- gold_error(_("%s: unsupported ELF data encoding %d"), name.c_str(), d);
- return NULL;
- }
-
- bool big_endian = d == elfcpp::ELFDATA2MSB;
-
- if (c == elfcpp::ELFCLASS32)
- {
- if (bytes < elfcpp::Elf_sizes<32>::ehdr_size)
- {
- gold_error(_("%s: ELF file too short"), name.c_str());
- return NULL;
- }
if (big_endian)
{
#ifdef HAVE_TARGET_32_BIG
#endif
}
}
- else
+ else if (size == 64)
{
- if (bytes < elfcpp::Elf_sizes<64>::ehdr_size)
- {
- gold_error(_("%s: ELF file too short"), name.c_str());
- return NULL;
- }
if (big_endian)
{
#ifdef HAVE_TARGET_64_BIG
#endif
}
}
+ else
+ gold_unreachable();
}
// Instantiate the templates we need.