inline void more ()
{
+ off_t off = _m_data == NULL ? 0 : _m_data->d_off + _m_data->d_size;
_m_data = elf_newdata (_m_scn);
if (_m_data == NULL)
throw std::runtime_error (std::string ("Error while creating section data: ")
_m_data->d_type = ELF_T_BYTE;
_m_data->d_align = 1;
_m_data->d_size = 0;
+ _m_data->d_off = off;
}
public:
typedef value_type const &const_reference;
section_appender (Elf_Scn *scn, size_t alloc_unit)
- : _m_alloc_unit (alloc_unit)
+ : _m_data (NULL)
+ , _m_alloc_unit (alloc_unit)
, _m_scn (scn)
, _m_totsize (0)
{
more ();
}
- unsigned char *alloc(size_t a_size)
+ unsigned char *alloc (size_t a_size)
{
size_t ns = _m_data->d_size + a_size;
if (ns > _m_alloc_unit)
// Remember where the unit started for back-patching of size.
size_t cu_start = appender.size ();
- // Unit length. Put zeroes for now, patch later.
- unsigned char *length_data = appender.alloc (4);
- ::dw_write<4> (length_data, 0, big_endian);
+ // Unit length.
+ gap length_gap (appender, 4 /*XXX dwarf64*/, big_endian);
// Version.
::dw_write<2> (appender.alloc (2), 3, big_endian);
// emit at offset 0.
::dw_write<4> (appender.alloc (4), 0, big_endian);
- // XXX size in bytes of an address on the target architecture.
+ // Size in bytes of an address on the target architecture.
*inserter++ = addr_64 ? 8 : 4;
die_off_map die_off;
/* Back-patch length. */
size_t length = appender.size () - cu_start - 4; // -4 for length info. XXX dwarf64
assert (length < (uint32_t)-1); // XXX temporary XXX dwarf64
- ::dw_write<4> (length_data, length, big_endian); // XXX dwarf64
+ length_gap.patch (length);
}
}