A new section can be created using the function
t_section * SectionCreateForObject (t_object * obj, char type, t_section * parent, t_address size, t_string name)
There are two possiblities, depending on whether you want to add a subsection or a parent section. An explanation of sections and subsections can be found here
1. you want to add a new subsection to an existing parent section:
As you want to add a subsection, it has to be attached to a subobject. A special subobject, the linker subobject, can be used to add sections at link time. This linker subobject can be obtained from the parent object through the function
t_object * ObjectGetLinkerSubObject (t_object * obj)
The type should be identical to the type of the parent section.
In the following example, a zero-initialized (type = BSS_SECTION) subsection "new" of size 5000 is added to the program
SectionCreateForObject(ObjectGetLinkerSubObject(obj), BSS_SECTION, OBJECT_BSS(obj)[0], 5000, "new");
2. you want to a a new parent section to the parent object:
In this case, the section is added to the parent object and the parent section is therefore NULL
SectionCreateForObject(obj, BSS_SECTION, NULL, 0, "new");
The size doesn't really matter for parent sections, as it will be computed as the sum of the sizes of its subsections. As a result, as long as no subsection has been added to a new parent section, it will not end up in the binary, as it is of size 0. A subsection can be added to this new parent section as described above