From 6c28ffbf012644e633f6804a8f4d6bbb35f53c67 Mon Sep 17 00:00:00 2001 From: Chris Johns Date: Fri, 21 Dec 2012 17:10:18 +1100 Subject: 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. --- linkers/rld-outputter.cpp | 4 ---- linkers/rld-rap.cpp | 44 +++++++++++++++++++++++++++----------------- linkers/rld-rap.h | 26 ++++++++++++++++++++++++++ 3 files changed, 53 insertions(+), 21 deletions(-) (limited to 'linkers') diff --git a/linkers/rld-outputter.cpp b/linkers/rld-outputter.cpp index 40acb8a..7925743 100644 --- a/linkers/rld-outputter.cpp +++ b/linkers/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/linkers/rld-rap.cpp b/linkers/rld-rap.cpp index 0fde70c..1eecb5d 100644 --- a/linkers/rld-rap.cpp +++ b/linkers/rld-rap.cpp @@ -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 (); diff --git a/linkers/rld-rap.h b/linkers/rld-rap.h index d29272c..2e42619 100644 --- a/linkers/rld-rap.h +++ b/linkers/rld-rap.h @@ -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. * -- cgit v1.2.3