Home | History | Annotate | Download | only in tests
      1 /* Copyright (C) 2000, 2002, 2005 Red Hat, Inc.
      2    This file is part of elfutils.
      3    Written by Ulrich Drepper <drepper (at) redhat.com>, 2000.
      4 
      5    This file is free software; you can redistribute it and/or modify
      6    it under the terms of the GNU General Public License as published by
      7    the Free Software Foundation; either version 3 of the License, or
      8    (at your option) any later version.
      9 
     10    elfutils is distributed in the hope that it will be useful, but
     11    WITHOUT ANY WARRANTY; without even the implied warranty of
     12    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     13    GNU General Public License for more details.
     14 
     15    You should have received a copy of the GNU General Public License
     16    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
     17 
     18 #include <nlist.h>
     19 #include <stdio.h>
     20 #include <stdlib.h>
     21 
     22 
     23 int var = 1;
     24 
     25 int bss;
     26 
     27 
     28 int
     29 foo (int a)
     30 {
     31   return a;
     32 }
     33 
     34 int
     35 main (int argc, char *argv[] __attribute__ ((unused)))
     36 {
     37   struct nlist nl[6] =
     38   {
     39     [0] = { .n_name = "var" },
     40     [1] = { .n_name = "bss" },
     41     [2] = { .n_name = "main" },
     42     [3] = { .n_name = "foo" },
     43     [4] = { .n_name = "not-there" },
     44     [5] = { .n_name = NULL },
     45   };
     46   int cnt;
     47   int result = 0;
     48 
     49   if (nlist (".libs/test-nlist", nl) != 0
     50       && nlist ("./test-nlist", nl) != 0)
     51     {
     52       puts ("nlist failed");
     53       exit (1);
     54     }
     55 
     56   for (cnt = 0; nl[cnt].n_name != NULL; ++cnt)
     57     {
     58       if (argc > 1)
     59 	/* For debugging.  */
     60 	printf ("nl[%d].n_name = \"%s\"\n"
     61 		"nl[%d].n_value = %ld\n"
     62 		"nl[%d].n_scnum = %d\n"
     63 		"nl[%d].n_type = %u\n"
     64 		"nl[%d].n_sclass = %d\n"
     65 		"nl[%d].n_numaux = %d\n\n",
     66 		cnt, nl[cnt].n_name,
     67 		cnt, nl[cnt].n_value,
     68 		cnt, nl[cnt].n_scnum,
     69 		cnt, nl[cnt].n_type,
     70 		cnt, nl[cnt].n_sclass,
     71 		cnt, nl[cnt].n_numaux);
     72 
     73       if ((cnt != 4 && nl[cnt].n_value == 0 && nl[cnt].n_scnum == 0
     74 	   && nl[cnt].n_type == 0 && nl[cnt].n_sclass == 0
     75 	   && nl[cnt].n_numaux == 0)
     76 	  || (cnt == 4 && (nl[cnt].n_value != 0 || nl[cnt].n_scnum != 0
     77 			   || nl[cnt].n_type != 0 || nl[cnt].n_sclass != 0
     78 			   || nl[cnt].n_numaux != 0)))
     79 	result = 1;
     80     }
     81 
     82   return foo (result);
     83 }
     84