summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--rld-outputter.cpp4
-rw-r--r--rld-rap.cpp44
-rw-r--r--rld-rap.h26
3 files changed, 53 insertions, 21 deletions
diff --git a/rld-outputter.cpp b/rld-outputter.cpp
index 40acb8a..7925743 100644
--- a/rld-outputter.cpp
+++ b/rld-outputter.cpp
@@ -310,17 +310,13 @@ namespace rld
files::object_list dep_copy (dependents);
files::object_list objects;
- std::string header;
files::image app (name);
- header = "RAP,00000000,0001,LZ77,00000000\n";
-
cache.get_objects (objects);
objects.merge (dep_copy);
objects.unique ();
app.open (true);
- app.write (header.c_str (), header.size ());
try
{
diff --git a/rld-rap.cpp b/rld-rap.cpp
index 0fde70c..1eecb5d 100644
--- a/rld-rap.cpp
+++ b/rld-rap.cpp
@@ -39,20 +39,6 @@ namespace rld
namespace rap
{
/**
- * The sections of interest in a RAP file.
- */
- enum sections
- {
- rap_text = 0,
- rap_const = 1,
- rap_ctor = 2,
- rap_dtor = 3,
- rap_data = 4,
- rap_bss = 5,
- rap_secs = 6
- };
-
- /**
* The names of the RAP sections.
*/
static const char* section_names[rap_secs] =
@@ -327,6 +313,15 @@ namespace rld
uint32_t fini_off; //< The strtab offset to the fini label.
};
+ const char*
+ section_name (int sec)
+ {
+ if (sec < rap_secs)
+ return section_names[sec];
+ throw rld::error ("Invalid section '" + rld::to_string (sec) + "'",
+ "rap::section-name");
+ }
+
/**
* Update the offset taking into account the alignment.
*
@@ -1082,7 +1077,7 @@ namespace rld
<< std::endl;
header = count;
- header |= sec_rela[s] ? (1UL << 31) : 0;
+ header |= sec_rela[s] ? RAP_RELOC_RELA : 0;
comp << header;
@@ -1149,7 +1144,7 @@ namespace rld
* string.
*/
- info |= 1 << 31;
+ info |= RAP_RELOC_STRING;
std::size_t size = strtab.find (reloc.symname);
@@ -1166,7 +1161,7 @@ namespace rld
/*
* Bit 30 set, the offset in the strtab.
*/
- info |= (1 << 30) | (size << 8);
+ info |= RAP_RELOC_STRING_EMBED | (size << 8);
}
}
@@ -1252,6 +1247,11 @@ namespace rld
const symbols::table& /* symbols */) /* Add back for incremental
* linking */
{
+ std::string header;
+
+ header = "RAP,00000000,0001,LZ77,00000000\n";
+ app.write (header.c_str (), header.size ());
+
compress::compressor compressor (app, 2 * 1024);
image rap;
@@ -1260,6 +1260,16 @@ namespace rld
compressor.flush ();
+ std::ostringstream length;
+
+ length << std::setfill ('0') << std::setw (8)
+ << header.size () + compressor.compressed ();
+
+ header.replace (4, 8, length.str ());
+
+ app.seek (0);
+ app.write (header.c_str (), header.size ());
+
if (rld::verbose () >= RLD_VERBOSE_INFO)
{
int pcent = (compressor.compressed () * 100) / compressor.transferred ();
diff --git a/rld-rap.h b/rld-rap.h
index d29272c..2e42619 100644
--- a/rld-rap.h
+++ b/rld-rap.h
@@ -32,6 +32,32 @@ namespace rld
namespace rap
{
/**
+ * The RAP relocation bit masks.
+ */
+ #define RAP_RELOC_RELA (1UL << 31)
+ #define RAP_RELOC_STRING (1UL << 31)
+ #define RAP_RELOC_STRING_EMBED (1UL << 30)
+
+ /**
+ * The sections of interest in a RAP file.
+ */
+ enum sections
+ {
+ rap_text = 0,
+ rap_const = 1,
+ rap_ctor = 2,
+ rap_dtor = 3,
+ rap_data = 4,
+ rap_bss = 5,
+ rap_secs = 6
+ };
+
+ /**
+ * Return the name of a section.
+ */
+ const char* section_name (int sec);
+
+ /**
* Write a RAP format file.
*
* The symbol table is provided to allow incremental linking at some point