#include #include #include #include static long int getauxval(unsigned int type) { const AuxInfo *aux; for (aux = _dlauxinfo(); aux->a_type != AT_NULL; ++aux) { if (type == aux->a_type) return aux->a_v; } return 0; } int main(int argc, char **argv) { const Elf_Phdr *phdr; Elf_Half phnum; const Elf_Phdr *phlimit; phdr = (void *)getauxval(AT_PHDR); phnum = (Elf_Half)getauxval(AT_PHNUM); bool dynamic = false; phlimit = phdr + phnum; for (; phdr < phlimit; ++phdr) { if (/* phdr->p_type == PT_DYNAMIC || */ phdr->p_type == PT_INTERP) { dynamic = true; break; } } printf("%s\n", dynamic ? "DYNAMIC" : "STATIC"); return 0; }