103333823c75a1c1887e923828113a1b0fd12020cElliott Hughes/* Copyright (C) 2000, 2002, 2005 Red Hat, Inc.
203333823c75a1c1887e923828113a1b0fd12020cElliott Hughes   This file is part of elfutils.
303333823c75a1c1887e923828113a1b0fd12020cElliott Hughes   Written by Ulrich Drepper <drepper@redhat.com>, 2000.
403333823c75a1c1887e923828113a1b0fd12020cElliott Hughes
503333823c75a1c1887e923828113a1b0fd12020cElliott Hughes   This file is free software; you can redistribute it and/or modify
603333823c75a1c1887e923828113a1b0fd12020cElliott Hughes   it under the terms of the GNU General Public License as published by
703333823c75a1c1887e923828113a1b0fd12020cElliott Hughes   the Free Software Foundation; either version 3 of the License, or
803333823c75a1c1887e923828113a1b0fd12020cElliott Hughes   (at your option) any later version.
903333823c75a1c1887e923828113a1b0fd12020cElliott Hughes
1003333823c75a1c1887e923828113a1b0fd12020cElliott Hughes   elfutils is distributed in the hope that it will be useful, but
1103333823c75a1c1887e923828113a1b0fd12020cElliott Hughes   WITHOUT ANY WARRANTY; without even the implied warranty of
1203333823c75a1c1887e923828113a1b0fd12020cElliott Hughes   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
1303333823c75a1c1887e923828113a1b0fd12020cElliott Hughes   GNU General Public License for more details.
1403333823c75a1c1887e923828113a1b0fd12020cElliott Hughes
1503333823c75a1c1887e923828113a1b0fd12020cElliott Hughes   You should have received a copy of the GNU General Public License
1603333823c75a1c1887e923828113a1b0fd12020cElliott Hughes   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
1703333823c75a1c1887e923828113a1b0fd12020cElliott Hughes
1803333823c75a1c1887e923828113a1b0fd12020cElliott Hughes#include <nlist.h>
1903333823c75a1c1887e923828113a1b0fd12020cElliott Hughes#include <stdio.h>
2003333823c75a1c1887e923828113a1b0fd12020cElliott Hughes#include <stdlib.h>
2103333823c75a1c1887e923828113a1b0fd12020cElliott Hughes
2203333823c75a1c1887e923828113a1b0fd12020cElliott Hughes
2303333823c75a1c1887e923828113a1b0fd12020cElliott Hughesint var = 1;
2403333823c75a1c1887e923828113a1b0fd12020cElliott Hughes
2503333823c75a1c1887e923828113a1b0fd12020cElliott Hughesint bss;
2603333823c75a1c1887e923828113a1b0fd12020cElliott Hughes
2703333823c75a1c1887e923828113a1b0fd12020cElliott Hughes
2803333823c75a1c1887e923828113a1b0fd12020cElliott Hughesint
2903333823c75a1c1887e923828113a1b0fd12020cElliott Hughesfoo (int a)
3003333823c75a1c1887e923828113a1b0fd12020cElliott Hughes{
3103333823c75a1c1887e923828113a1b0fd12020cElliott Hughes  return a;
3203333823c75a1c1887e923828113a1b0fd12020cElliott Hughes}
3303333823c75a1c1887e923828113a1b0fd12020cElliott Hughes
3403333823c75a1c1887e923828113a1b0fd12020cElliott Hughesint
3503333823c75a1c1887e923828113a1b0fd12020cElliott Hughesmain (int argc, char *argv[] __attribute__ ((unused)))
3603333823c75a1c1887e923828113a1b0fd12020cElliott Hughes{
3703333823c75a1c1887e923828113a1b0fd12020cElliott Hughes  struct nlist nl[6] =
3803333823c75a1c1887e923828113a1b0fd12020cElliott Hughes  {
3903333823c75a1c1887e923828113a1b0fd12020cElliott Hughes    [0] = { .n_name = "var" },
4003333823c75a1c1887e923828113a1b0fd12020cElliott Hughes    [1] = { .n_name = "bss" },
4103333823c75a1c1887e923828113a1b0fd12020cElliott Hughes    [2] = { .n_name = "main" },
4203333823c75a1c1887e923828113a1b0fd12020cElliott Hughes    [3] = { .n_name = "foo" },
4303333823c75a1c1887e923828113a1b0fd12020cElliott Hughes    [4] = { .n_name = "not-there" },
4403333823c75a1c1887e923828113a1b0fd12020cElliott Hughes    [5] = { .n_name = NULL },
4503333823c75a1c1887e923828113a1b0fd12020cElliott Hughes  };
4603333823c75a1c1887e923828113a1b0fd12020cElliott Hughes  int cnt;
4703333823c75a1c1887e923828113a1b0fd12020cElliott Hughes  int result = 0;
4803333823c75a1c1887e923828113a1b0fd12020cElliott Hughes
4903333823c75a1c1887e923828113a1b0fd12020cElliott Hughes  if (nlist (".libs/test-nlist", nl) != 0
5003333823c75a1c1887e923828113a1b0fd12020cElliott Hughes      && nlist ("./test-nlist", nl) != 0)
5103333823c75a1c1887e923828113a1b0fd12020cElliott Hughes    {
5203333823c75a1c1887e923828113a1b0fd12020cElliott Hughes      puts ("nlist failed");
5303333823c75a1c1887e923828113a1b0fd12020cElliott Hughes      exit (1);
5403333823c75a1c1887e923828113a1b0fd12020cElliott Hughes    }
5503333823c75a1c1887e923828113a1b0fd12020cElliott Hughes
5603333823c75a1c1887e923828113a1b0fd12020cElliott Hughes  for (cnt = 0; nl[cnt].n_name != NULL; ++cnt)
5703333823c75a1c1887e923828113a1b0fd12020cElliott Hughes    {
5803333823c75a1c1887e923828113a1b0fd12020cElliott Hughes      if (argc > 1)
5903333823c75a1c1887e923828113a1b0fd12020cElliott Hughes	/* For debugging.  */
6003333823c75a1c1887e923828113a1b0fd12020cElliott Hughes	printf ("nl[%d].n_name = \"%s\"\n"
6103333823c75a1c1887e923828113a1b0fd12020cElliott Hughes		"nl[%d].n_value = %ld\n"
6203333823c75a1c1887e923828113a1b0fd12020cElliott Hughes		"nl[%d].n_scnum = %d\n"
6303333823c75a1c1887e923828113a1b0fd12020cElliott Hughes		"nl[%d].n_type = %u\n"
6403333823c75a1c1887e923828113a1b0fd12020cElliott Hughes		"nl[%d].n_sclass = %d\n"
6503333823c75a1c1887e923828113a1b0fd12020cElliott Hughes		"nl[%d].n_numaux = %d\n\n",
6603333823c75a1c1887e923828113a1b0fd12020cElliott Hughes		cnt, nl[cnt].n_name,
6703333823c75a1c1887e923828113a1b0fd12020cElliott Hughes		cnt, nl[cnt].n_value,
6803333823c75a1c1887e923828113a1b0fd12020cElliott Hughes		cnt, nl[cnt].n_scnum,
6903333823c75a1c1887e923828113a1b0fd12020cElliott Hughes		cnt, nl[cnt].n_type,
7003333823c75a1c1887e923828113a1b0fd12020cElliott Hughes		cnt, nl[cnt].n_sclass,
7103333823c75a1c1887e923828113a1b0fd12020cElliott Hughes		cnt, nl[cnt].n_numaux);
7203333823c75a1c1887e923828113a1b0fd12020cElliott Hughes
7303333823c75a1c1887e923828113a1b0fd12020cElliott Hughes      if ((cnt != 4 && nl[cnt].n_value == 0 && nl[cnt].n_scnum == 0
7403333823c75a1c1887e923828113a1b0fd12020cElliott Hughes	   && nl[cnt].n_type == 0 && nl[cnt].n_sclass == 0
7503333823c75a1c1887e923828113a1b0fd12020cElliott Hughes	   && nl[cnt].n_numaux == 0)
7603333823c75a1c1887e923828113a1b0fd12020cElliott Hughes	  || (cnt == 4 && (nl[cnt].n_value != 0 || nl[cnt].n_scnum != 0
7703333823c75a1c1887e923828113a1b0fd12020cElliott Hughes			   || nl[cnt].n_type != 0 || nl[cnt].n_sclass != 0
7803333823c75a1c1887e923828113a1b0fd12020cElliott Hughes			   || nl[cnt].n_numaux != 0)))
7903333823c75a1c1887e923828113a1b0fd12020cElliott Hughes	result = 1;
8003333823c75a1c1887e923828113a1b0fd12020cElliott Hughes    }
8103333823c75a1c1887e923828113a1b0fd12020cElliott Hughes
8203333823c75a1c1887e923828113a1b0fd12020cElliott Hughes  return foo (result);
8303333823c75a1c1887e923828113a1b0fd12020cElliott Hughes}
84