summaryrefslogtreecommitdiff
path: root/rld-elf.h
diff options
context:
space:
mode:
authorChris Johns <chrisj@rtems.org>2012-12-08 09:07:30 +1100
committerChris Johns <chrisj@rtems.org>2012-12-08 09:07:30 +1100
commit4c10232ae7298504c124c33a8c0dc27c86dad5b5 (patch)
treef2745cad4ebf5cb07111191fe6f0cd8b7dd22cd5 /rld-elf.h
parentc6add3b2f603f4cf9be8bfe4bb4c27ccf9c086fa (diff)
Add support to demand load relocation records.
Support has been added to load relocation record on demand. The relocation records are not read when the object file is first opened and read. They are read only when being written to the output file. This save loading lots of records into memory from libraries to be thrown away. The RAP format now supports writing out relocation records.
Diffstat (limited to 'rld-elf.h')
-rw-r--r--rld-elf.h114
1 files changed, 113 insertions, 1 deletions
diff --git a/rld-elf.h b/rld-elf.h
index a856892..780b486 100644
--- a/rld-elf.h
+++ b/rld-elf.h
@@ -27,6 +27,7 @@
#include <list>
#include <map>
+#include <vector>
#include <rld.h>
@@ -40,6 +41,66 @@ namespace rld
class file;
/**
+ * A relocation record.
+ */
+ class relocation
+ {
+ public:
+ /**
+ * Construct a relocation record.
+ *
+ * @param offset The offset in the section the relocation applies to.
+ * @param info The relocation info.
+ * @param addend The constant addend value.
+ */
+ relocation (const symbols::symbol& sym,
+ elf_addr offset,
+ elf_xword info,
+ elf_sxword addend = 0);
+
+ /**
+ * Default constructor.
+ */
+ relocation ();
+
+ /**
+ * The name of the symbol.
+ */
+ std::string name () const;
+
+ /**
+ * The offset.
+ */
+ elf_addr offset () const;
+
+ /**
+ * The type of the relocation record.
+ */
+ uint32_t type () const;
+
+ /**
+ * The info.
+ */
+ elf_xword info () const;
+
+ /**
+ * The constant addend.
+ */
+ elf_sxword addend () const;
+
+ private:
+ const symbols::symbol* sym; //< The symbol reference.
+ elf_addr offset_; //< The offset in the section.
+ elf_xword info_; //< The record's information.
+ elf_sxword addend_; //< The constant addend value.
+ };
+
+ /**
+ * A container of relocation records.
+ */
+ typedef std::vector < relocation > relocations;
+
+ /**
* An ELF Section. The current implementation only supports a single data
* descriptor with a section.
*/
@@ -233,11 +294,37 @@ namespace rld
int entries () const;
/**
+ * Return true if the relocation record have an addend field.
+ *
+ * @retval true The relocation record have the addend field.
+ */
+ bool get_reloc_type () const;
+
+ /**
* Set the name index if writable. This is normally done
* automatically when adding the section to the file.
*/
void set_name (unsigned int index);
+ /**
+ * Set the type of relocation records.
+ *
+ * @param rela If true the records are rela type.
+ */
+ void set_reloc_type (bool rela);
+
+ /**
+ * Add a relocation.
+ *
+ * @param reloc The relocation record to add.
+ */
+ void add (const relocation& reloc);
+
+ /**
+ * Get the relocations.
+ */
+ const relocations& get_relocations () const;
+
private:
/**
@@ -260,6 +347,8 @@ namespace rld
elf_scn* scn; //< ELF private section data.
elf_shdr shdr; //< The section header.
elf_data* data_; //< The section's data.
+ bool rela; //< The type of relocation records.
+ relocations relocs; //< The relocation records.
};
/**
@@ -318,7 +407,7 @@ namespace rld
*/
typedef std::list < program_header > program_headers;
- /**
+ /**
* An ELF file.
*/
class file
@@ -427,6 +516,14 @@ namespace rld
void get_sections (sections& filtered_secs, unsigned int type);
/**
+ * Return the section with given index.
+ *
+ * @param index The section's index to look for.
+ * @retval section The section matching the index.
+ */
+ section& get_section (int index);
+
+ /**
* Return the index of the string section.
*/
int strings_section () const;
@@ -472,6 +569,21 @@ namespace rld
bool global = true);
/**
+ * Get the symbol by index in the symtabl section.
+ */
+ const symbols::symbol& get_symbol (const int index) const;
+
+ /**
+ * Load the relocation records.
+ */
+ void load_relocations ();
+
+ /**
+ * Clear the relocation records.
+ */
+ void clear_relocations ();
+
+ /**
* Set the ELF header. Must be writable.
*
* The classes are: