1 /* Copyright (C) 2002, 2005 Red Hat, Inc.
2 This file is part of Red Hat elfutils.
3 Written by Ulrich Drepper <drepper@redhat.com>, 2002.
5 Red Hat elfutils is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by the
7 Free Software Foundation; version 2 of the License.
9 Red Hat elfutils is distributed in the hope that it will be useful, but
10 WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 General Public License for more details.
14 You should have received a copy of the GNU General Public License along
15 with Red Hat elfutils; if not, write to the Free Software Foundation,
16 Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301 USA.
18 Red Hat elfutils is an included package of the Open Invention Network.
19 An included package of the Open Invention Network is a package for which
20 Open Invention Network licensees cross-license their patents. No patent
21 license is granted, either expressly or impliedly, by designation as an
22 included package. Should you wish to participate in the Open Invention
23 Network licensing program, please visit www.openinventionnetwork.com
24 <http://www.openinventionnetwork.com>. */
32 #include ELFUTILS_HEADER(asm)
38 static const char fname[] = "asm-tst7-out.o";
50 elf_version (EV_CURRENT);
52 Ebl *ebl = ebl_openbackend_machine (EM_386);
55 puts ("cannot open backend library");
59 ctx = asm_begin (fname, ebl, false);
62 printf ("cannot create assembler context: %s\n", asm_errmsg (-1));
66 if (asm_newcomsym (ctx, "commsym", 4, 16) == NULL)
68 printf ("cannot create common symbol: %s\n", asm_errmsg (-1));
73 /* Create the output file. */
74 if (asm_end (ctx) != 0)
76 printf ("cannot create output file: %s\n", asm_errmsg (-1));
82 fd = open (fname, O_RDONLY);
85 printf ("cannot open generated file: %m\n");
90 elf = elf_begin (fd, ELF_C_READ, NULL);
93 printf ("cannot create ELF descriptor: %s\n", elf_errmsg (-1));
97 if (elf_kind (elf) != ELF_K_ELF)
99 puts ("not a valid ELF file");
104 for (cnt = 1; 1; ++cnt)
110 scn = elf_getscn (elf, cnt);
113 printf ("cannot get section %Zd: %s\n", cnt, elf_errmsg (-1));
118 shdr = gelf_getshdr (scn, &shdr_mem);
121 printf ("cannot get section header for section %Zd: %s\n",
122 cnt, elf_errmsg (-1));
126 /* We are looking for the symbol table. */
127 if (shdr->sh_type != SHT_SYMTAB)
130 for (cnt = 1; cnt< (shdr->sh_size
131 / gelf_fsize (elf, ELF_T_SYM, 1, EV_CURRENT));
139 puts ("too many symbol");
144 sym = gelf_getsym (elf_getdata (scn, NULL), cnt, &sym_mem);
147 printf ("cannot get symbol %zu: %s\n", cnt, elf_errmsg (-1));
152 if (sym->st_shndx != SHN_COMMON)
154 printf ("expected common symbol, got section %u\n",
155 (unsigned int) sym->st_shndx);
159 if (sym->st_value != 16)
161 printf ("requested alignment 16, is %" PRIuMAX "\n",
162 (uintmax_t) sym->st_value);
166 if (sym->st_size != 4)
168 printf ("requested size 4, is %" PRIuMAX "\n",
169 (uintmax_t) sym->st_value);
183 /* We don't need the file anymore. */
186 ebl_closebackend (ebl);