Blame tests/test-nlist.c

Packit 032894
/* Copyright (C) 2000, 2002, 2005 Red Hat, Inc.
Packit 032894
   This file is part of elfutils.
Packit 032894
   Written by Ulrich Drepper <drepper@redhat.com>, 2000.
Packit 032894
Packit 032894
   This file is free software; you can redistribute it and/or modify
Packit 032894
   it under the terms of the GNU General Public License as published by
Packit 032894
   the Free Software Foundation; either version 3 of the License, or
Packit 032894
   (at your option) any later version.
Packit 032894
Packit 032894
   elfutils is distributed in the hope that it will be useful, but
Packit 032894
   WITHOUT ANY WARRANTY; without even the implied warranty of
Packit 032894
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
Packit 032894
   GNU General Public License for more details.
Packit 032894
Packit 032894
   You should have received a copy of the GNU General Public License
Packit 032894
   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
Packit 032894
Packit 032894
#include <nlist.h>
Packit 032894
#include <stdio.h>
Packit 032894
#include <stdlib.h>
Packit 032894
Packit 032894
Packit 032894
int var = 1;
Packit 032894
Packit 032894
int bss;
Packit 032894
Packit 032894
Packit 032894
int
Packit 032894
foo (int a)
Packit 032894
{
Packit 032894
  return a;
Packit 032894
}
Packit 032894
Packit 032894
int
Packit 032894
main (int argc, char *argv[] __attribute__ ((unused)))
Packit 032894
{
Packit 032894
  struct nlist nl[6] =
Packit 032894
  {
Packit 032894
    [0] = { .n_name = "var" },
Packit 032894
    [1] = { .n_name = "bss" },
Packit 032894
    [2] = { .n_name = "main" },
Packit 032894
    [3] = { .n_name = "foo" },
Packit 032894
    [4] = { .n_name = "not-there" },
Packit 032894
    [5] = { .n_name = NULL },
Packit 032894
  };
Packit 032894
  int cnt;
Packit 032894
  int result = 0;
Packit 032894
Packit 032894
  if (nlist (".libs/test-nlist", nl) != 0
Packit 032894
      && nlist ("./test-nlist", nl) != 0)
Packit 032894
    {
Packit 032894
      puts ("nlist failed");
Packit 032894
      exit (1);
Packit 032894
    }
Packit 032894
Packit 032894
  for (cnt = 0; nl[cnt].n_name != NULL; ++cnt)
Packit 032894
    {
Packit 032894
      if (argc > 1)
Packit 032894
	/* For debugging.  */
Packit 032894
	printf ("nl[%d].n_name = \"%s\"\n"
Packit 032894
		"nl[%d].n_value = %ld\n"
Packit 032894
		"nl[%d].n_scnum = %d\n"
Packit 032894
		"nl[%d].n_type = %u\n"
Packit 032894
		"nl[%d].n_sclass = %d\n"
Packit 032894
		"nl[%d].n_numaux = %d\n\n",
Packit 032894
		cnt, nl[cnt].n_name,
Packit 032894
		cnt, nl[cnt].n_value,
Packit 032894
		cnt, nl[cnt].n_scnum,
Packit 032894
		cnt, nl[cnt].n_type,
Packit 032894
		cnt, nl[cnt].n_sclass,
Packit 032894
		cnt, nl[cnt].n_numaux);
Packit 032894
Packit 032894
      if ((cnt != 4 && nl[cnt].n_value == 0 && nl[cnt].n_scnum == 0
Packit 032894
	   && nl[cnt].n_type == 0 && nl[cnt].n_sclass == 0
Packit 032894
	   && nl[cnt].n_numaux == 0)
Packit 032894
	  || (cnt == 4 && (nl[cnt].n_value != 0 || nl[cnt].n_scnum != 0
Packit 032894
			   || nl[cnt].n_type != 0 || nl[cnt].n_sclass != 0
Packit 032894
			   || nl[cnt].n_numaux != 0)))
Packit 032894
	result = 1;
Packit 032894
    }
Packit 032894
Packit 032894
  return foo (result);
Packit 032894
}