aboutsummaryrefslogtreecommitdiff
path: root/elfcpp
diff options
context:
space:
mode:
authorIan Lance Taylor <ian@airs.com>2009-10-09 22:38:07 +0000
committerIan Lance Taylor <ian@airs.com>2009-10-09 22:38:07 +0000
commitc4aa1e2d740d76a37730514749c6ff2ef9f748f1 (patch)
tree1a65a3a215ee78941e8c64f57305980a55cefdc2 /elfcpp
parentc549a6949c8cbbbeafa79ab903b172bbc5f2b8ea (diff)
downloadgdb-c4aa1e2d740d76a37730514749c6ff2ef9f748f1.zip
gdb-c4aa1e2d740d76a37730514749c6ff2ef9f748f1.tar.gz
gdb-c4aa1e2d740d76a37730514749c6ff2ef9f748f1.tar.bz2
elfcpp/:
* elf_file.h: (class Elf_strtab): New class. gold/: * gold.cc: (queue_initial_tasks): Pass incremental_inputs to Incremental_checker. * incremental.cc: (INCREMENTAL_LINK_VERSION): Change type to unsigned int. (class Incremental_inputs_header): New class. (Incremental_inputs_header_writer): Edit comment. (Incremental_inputs_entry): New class. (Incremental_inputs_entry_writer): Edit comment. (Sized_incremental_binary::do_find_incremental_inputs_section): Add *strtab_shndx parameter, fill it. (Sized_incremental_binary::do_check_inputs): New method. (Incremental_checker::can_incrementally_link_output_file): Use Sized_incremental_binary::check_inputs. (Incremental_inputs::report_command_line): Save command line in command_line_. * incremental.h: (Incremental_binary::find_incremental_inputs_section): New method. (Incremental_binary::do_find_incremental_inputs_section): Add strtab_shndx parameter. (Incremental_binary::do_check_inputs): New pure virtual method. (Sized_incremental_binary::do_check_inputs): Declare. (Incremental_checker::Incremental_checker): Add incremental_inputs parameter, use it to initialize incremental_inputs_. (Incremental_checker::incremental_inputs_): New field. (Incremental_checker::command_line): New method. (Incremental_checker::inputs): New method. (Incremental_checker::command_line_): New field.
Diffstat (limited to 'elfcpp')
-rw-r--r--elfcpp/ChangeLog4
-rw-r--r--elfcpp/elfcpp_file.h39
2 files changed, 43 insertions, 0 deletions
diff --git a/elfcpp/ChangeLog b/elfcpp/ChangeLog
index 7569cbd..8aeb513 100644
--- a/elfcpp/ChangeLog
+++ b/elfcpp/ChangeLog
@@ -1,5 +1,9 @@
2009-10-09 Mikolaj Zalewski <mikolajz@google.com>
+ * elf_file.h: (class Elf_strtab): New class.
+
+2009-10-09 Mikolaj Zalewski <mikolajz@google.com>
+
* elfcpp_file.h: Fix header guard. Include <cstdio>.
(class Elf_recognizer): New class, code from gold/object.cc.
(Elf_file::find_section_by_type): New method.
diff --git a/elfcpp/elfcpp_file.h b/elfcpp/elfcpp_file.h
index 00ab28b..12f0925 100644
--- a/elfcpp/elfcpp_file.h
+++ b/elfcpp/elfcpp_file.h
@@ -228,6 +228,33 @@ class Elf_file
int large_shndx_offset_;
};
+// A small wrapper around SHT_STRTAB data mapped to memory. It checks that the
+// index is not out of bounds and the string is NULL-terminated.
+
+class Elf_strtab
+{
+ public:
+ // Construct an Elf_strtab for a section with contents *P and size SIZE.
+ Elf_strtab(const unsigned char* p, size_t size);
+
+ // Return the file offset to the section headers.
+ bool
+ get_c_string(size_t offset, const char** cstring) const
+ {
+ if (offset >= this->usable_size_)
+ return false;
+ *cstring = this->base_ + offset;
+ return true;
+ }
+
+ private:
+ // Contents of the section mapped to memory.
+ const char* base_;
+ // One larger that the position of the last NULL character in the section.
+ // For valid SHT_STRTAB sections, this is the size of the section.
+ size_t usable_size_;
+};
+
// Inline function definitions.
// Check for presence of the ELF magic number.
@@ -642,6 +669,18 @@ Elf_file<size, big_endian, File>::section_addralign(unsigned int shndx)
return shdr.get_sh_addralign();
}
+inline
+Elf_strtab::Elf_strtab(const unsigned char* p, size_t size)
+{
+ // Check if the section is NUL-terminated. If it isn't, we ignore
+ // the last part to make sure we don't return non-NUL-terminated
+ // strings.
+ while (size > 0 && p[size - 1] != 0)
+ size--;
+ this->base_ = reinterpret_cast<const char*>(p);
+ this->usable_size_ = size;
+}
+
} // End namespace elfcpp.
#endif // !defined(ELFCPP_FILE_H)