Commits

a4z committed 68f4eda

elfio update

Comments (0)

Files changed (2)

include/elfio/elfio.hpp

             section* sec = create_section();
             sec->load( stream, (std::streamoff)offset + i * entry_size );
             sec->set_index( i );
+            // To mark that the section is not permitted to reassign address
+            // during layout calculation
+            sec->set_address( sec->get_address() );
         }
 
         Elf_Half shstrndx = get_section_name_str_index();
 
                 sections_[i]->save( f, headerPosition, (std::streamoff)current_file_pos );
 
-                if ( SHT_NOBITS != sections_[i]->get_type() ) {
+                if ( SHT_NOBITS != sections_[i]->get_type() &&
+                     SHT_NULL   != sections_[i]->get_type() ) {
                     current_file_pos += sections_[i]->get_size();
                 }
             }
                 current_file_pos += segment_align - current_file_pos % segment_align;
             }
 
-            Elf_Xword current_data_pos = current_file_pos;
+            Elf_Xword current_data_pos   = current_file_pos;
+            Elf_Xword add_to_memory_size = 0;
             // Write segment's data
             for ( unsigned int j = 0; j <segments[i]->get_sections_num(); ++j ) {
                 section* sec = sections[ segments[i]->get_section_index_at( j )];
                     sec->set_address( segments[i]->get_virtual_address() );
                 }
                 sec->save( f, headerPosition, (std::streamoff)current_data_pos );
-                current_data_pos += sec->get_size();
+
+                if ( SHT_NOBITS != sec->get_type() && SHT_NULL != sec->get_type() ) {
+                    current_data_pos += sec->get_size();
+                }
+                else {
+                    add_to_memory_size += sec->get_size();
+                }
             }
 
             segments[i]->set_file_size( current_data_pos - current_file_pos );
             segments[i]->set_memory_size( current_data_pos - current_file_pos +
-                                          segments[i]->get_memory_size() );
+                                          add_to_memory_size );
             segments[i]->save( f, (std::streamoff)segment_header_position, (std::streamoff)current_file_pos );
             current_file_pos = current_data_pos;
             segment_header_position += header->get_segment_entry_size();

include/elfio/elfio_segment.hpp

                std::streampos data_offset )
     {
         ph.p_offset = data_offset;
+        ph.p_offset = (*convertor)(ph.p_offset);
         f.seekp( header_offset );
         f.write( reinterpret_cast<const char*>( &ph ), sizeof( ph ) );
     }
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.