Ulrich Drepper | b08d5a8 | 2005-07-26 05:00:05 +0000 | [diff] [blame] | 1 | /* Copyright (C) 2000, 2002, 2005 Red Hat, Inc. |
Mark Wielaard | de2ed97 | 2012-06-05 17:15:16 +0200 | [diff] [blame] | 2 | This file is part of elfutils. |
Ulrich Drepper | b08d5a8 | 2005-07-26 05:00:05 +0000 | [diff] [blame] | 3 | Written by Ulrich Drepper <drepper@redhat.com>, 2000. |
| 4 | |
Mark Wielaard | de2ed97 | 2012-06-05 17:15:16 +0200 | [diff] [blame] | 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. |
Ulrich Drepper | b08d5a8 | 2005-07-26 05:00:05 +0000 | [diff] [blame] | 9 | |
Mark Wielaard | de2ed97 | 2012-06-05 17:15:16 +0200 | [diff] [blame] | 10 | elfutils is distributed in the hope that it will be useful, but |
Ulrich Drepper | 361df7d | 2006-04-04 21:38:57 +0000 | [diff] [blame] | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
Mark Wielaard | de2ed97 | 2012-06-05 17:15:16 +0200 | [diff] [blame] | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | GNU General Public License for more details. |
Ulrich Drepper | 361df7d | 2006-04-04 21:38:57 +0000 | [diff] [blame] | 14 | |
Mark Wielaard | de2ed97 | 2012-06-05 17:15:16 +0200 | [diff] [blame] | 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/>. */ |
Ulrich Drepper | b08d5a8 | 2005-07-26 05:00:05 +0000 | [diff] [blame] | 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 | } |