Set header length. Make sections public.

Set the compressed file length in the RAP header. Move
the string from the outputter to the RAP file.

Make the sections public by moving to the RAP header.
This commit is contained in:
Chris Johns 2012-12-21 17:10:18 +11:00
parent 4e9b3247a6
commit 6c28ffbf01
3 changed files with 53 additions and 21 deletions

View File

@ -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
{

View File

@ -38,20 +38,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.
*/
@ -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 ();

View File

@ -31,6 +31,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.
*