NAME elf_zscn_compress SYNOPSIS cc [ flag ... ] file ... -lelf [ library ... ] #include int elf_zscn_compress(Elf_Scn *scn, Elf_ZScn_Type ztype, const char *scn_name); DESCRIPTION elf_zscn_compress is used to compress a section using a specified compression type. The ztype argument specifies the desired compression type, and can be one of the following. ELF_ZSCN_T_ZLIB ZLIB compression, ELF ABI format. ELF_ZSCN_T_ZLIB_GNU ZLIB compression, in the original GNU format. See NOTES. scn_name is the name of the section. It can be set to NULL under some circumstances. See elf_zscn_compressible(3ELF). RETURN VALUE Upon failure, elf_zscn_compress returns -1 and sets elf_errno. Otherwise, 0 is returned. On success, elf_zscn_compress updates the section header, and the original data is replaced with the compressed data. Any information previously returned for the section by elf32_getshdr, elf64_shdr, or elf_getdata, is invalidated, and should no longer be referenced by the caller. The caller should defer calling those functions until after calling elf_zscn_compress, or should call them again afterwards in order to obtain the new information. EXAMPLES Example 1 Display compressible sections The following code fragment iterates over all the sections of an ELF object, and compresses all possible sections using the ELF_ZSCN_T_ZLIB compression type. The section index and name for each section is printed. The details of obtaining the section name, and error handling, are omitted in the interest of brevity. modified = 0; ndx = 1; for (scn = NULL; scn = elf_nextscn(elf, scn); ndx++) { scn_name = get_scn_name(...); status = elf_zscn_compressible(scn, ELF_ZSCN_T_ZLIB, scn_name); if (status == -1) error(...); if (status == 0) continue; ztype = elf_zscn_identify(scn, scn_name); if (ztype == -1) error(...); if (ztype != ELF_ZSCN_T_NONE) continue; (void) printf("[%d] %s\n", ndx, scn_name); if(elf_zscn_compress(scn, ELF_ZSCN_T_ZLIB, scn_name) == -1) error(...); modified = 1; } if (modified) elf_update(elf, ELF_C_WRITE); NOTES elf_zscn_compress will reject any compression attempt that would be rejected by elf_zscn_compressible. The use of elf_zscn_compressible to identify sections suitable for compression before calling elf_zscn_compress is recommended. Unlike elf_zscn_compressible, elf_zscn_compress will also reject a compression attempt for a section that is already compressed. The caller must first decompress the section, and then compress it into the desired format. In such situations, the use of elf_zscn_identify is recommended in conjunction with elf_zscn_compressible. The ELF_ZSCN_T_ZLIB_GNU compression type is deprecated, and is provided in order to support existing objects. The ELF_ZSCN_T_ZLIB type, which is not dependent on section name, is preferred. The ELF_ZSCN_T_ZLIB_GNU compression type can only be applied to sections with names that start with .debug. On compression, that type requires the name to be altered to start with .zdebug. elf_zscn_compress does not provide the replacement name. The caller is responsible for for providing the replacement name. See elf_zscn_compressible(3ELF). SEE ALSO elf32_getshdr(3ELF), elf64_getshdr(3ELF), elf_errno(3ELF), elf_getdata(3ELF), elf_zscn_compressible(3ELF), elf_zscn_decompress(3ELF), elf_zscn_identify(3ELF), libelf(3LIB)