scripts/gen_offset_header/gen_offset_header.c
/**
 *
 * @brief search the section headers for the string table
 *
 * This routine searches the section headers for the string table associated
 * with the symbol names.
 *
 * Typically, there are two string tables defined in the section headers.  These
 * are ".shstrtbl" and ".strtbl" for section header names and symbol names
 * respectively.  It has been observed with the DIAB compiler (but not with
 * either the GCC nor ICC compilers) that the two tables may be mashed together
 * into one.  Consequently, the following algorithm is used to select the
 * appropriate string table.
 *
 * 1. Assume that the first found string table is valid.
 * 2. If another string table is found, use that only if its section header
 *    index does not match the index for ".shstrtbl" stored in the ELF header.
 *
 * @param pStrTblIx ptr to string table's index
 * @returns 0 if found, -1 if not
 */
@brief search the section headers for the string table
This routine searches the section headers for the string table associated
with the symbol names.

Typically, there are two string tables defined in the section headers.  These
are ".shstrtbl" and ".strtbl" for section header names and symbol names
respectively.  It has been observed with the DIAB compiler (but not with
either the GCC nor ICC compilers) that the two tables may be mashed together
into one.  Consequently, the following algorithm is used to select the
appropriate string table.

1. Assume that the first found string table is valid.
2. If another string table is found, use that only if its section header
index does not match the index for ".shstrtbl" stored in the ELF header.

@param pStrTblIx ptr to string table's index
@returns 0 if found, -1 if not
@brief search the section headers for the string table This routine searches the section headers for the string table associated with the symbol names . Typically there are two string tables defined in the section headers . These are " . shstrtbl " and " . strtbl " for section header names and symbol names respectively . It has been observed with the DIAB compiler ( but not with either the GCC nor ICC compilers ) that the two tables may be mashed together into one . Consequently the following algorithm is used to select the appropriate string table . 1 . Assume that the first found string table is valid . 2 . If another string table is found use that only if its section header index does not match the index for " . shstrtbl " stored in the ELF header . @param pStrTblIx ptr to string table ' s index @returns 0 if found - 1 if not
static int strTblFind(unsigned *pStrTblIx)
{
	unsigned  strTblIx = 0xffffffff;
	unsigned  ix;
	for (ix = 0; ix < ehdr.e_shnum; ++ix)
	{
		if (shdr[ix].sh_type == SHT_STRTAB)
		{
			if ((strTblIx == 0xffffffff) ||
					(ix != ehdr.e_shstrndx))
			{
				strTblIx = ix;
			}
		}
	}
	if (strTblIx == 0xffffffff)
	{
		fprintf(stderr, "Object module missing string table!\n");
		return -1;
	}
	*pStrTblIx = strTblIx;
	return 0;
}
static int strTblFind ( unsigned * pStrTblIx ) { unsigned strTblIx = 0xffffffff ; unsigned ix ; for ( ix = 0 ; ix < ehdr . e_shnum ; ++ ix ) { if ( shdr [ ix ] . sh_type == SHT_STRTAB ) { if ( ( strTblIx == 0xffffffff ) || ( ix != ehdr . e_shstrndx ) ) { strTblIx = ix ; } } } if ( strTblIx == 0xffffffff ) { fprintf ( stderr , " \n " ) ; return -1 ; } * pStrTblIx = strTblIx ; return 0 ; }
@brief search the section headers for the string table
 This routine searches the section headers for the string table associated
 with the symbol names.
@brief search the section headers for the string table This routine searches the section headers for the string table associated with the symbol names .