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-tst8-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_newabssym (ctx, "tst8-out.s", 4, 0xfeedbeef, STT_FILE, STB_LOCAL)
69 printf ("cannot create absolute symbol: %s\n", asm_errmsg (-1));
74 /* Create the output file. */
75 if (asm_end (ctx) != 0)
77 printf ("cannot create output file: %s\n", asm_errmsg (-1));
83 fd = open (fname, O_RDONLY);
86 printf ("cannot open generated file: %m\n");
91 elf = elf_begin (fd, ELF_C_READ, NULL);
94 printf ("cannot create ELF descriptor: %s\n", elf_errmsg (-1));
98 if (elf_kind (elf) != ELF_K_ELF)
100 puts ("not a valid ELF file");
105 for (cnt = 1; 1; ++cnt)
111 scn = elf_getscn (elf, cnt);
114 printf ("cannot get section %Zd: %s\n", cnt, elf_errmsg (-1));
119 shdr = gelf_getshdr (scn, &shdr_mem);
122 printf ("cannot get section header for section %Zd: %s\n",
123 cnt, elf_errmsg (-1));
127 /* We are looking for the symbol table. */
128 if (shdr->sh_type != SHT_SYMTAB)
131 for (cnt = 1; cnt< (shdr->sh_size
132 / gelf_fsize (elf, ELF_T_SYM, 1, EV_CURRENT));
140 puts ("too many symbol");
145 sym = gelf_getsym (elf_getdata (scn, NULL), cnt, &sym_mem);
148 printf ("cannot get symbol %zu: %s\n", cnt, elf_errmsg (-1));
153 if (sym->st_shndx != SHN_ABS)
155 printf ("expected common symbol, got section %u\n",
156 (unsigned int) sym->st_shndx);
160 if (sym->st_value != 0xfeedbeef)
162 printf ("requested value 0xfeedbeef, is %#" PRIxMAX "\n",
163 (uintmax_t) sym->st_value);
167 if (sym->st_size != 4)
169 printf ("requested size 4, is %" PRIuMAX "\n",
170 (uintmax_t) sym->st_value);
174 if (GELF_ST_TYPE (sym->st_info) != STT_FILE)
176 printf ("requested type FILE, is %u\n",
177 (unsigned int) GELF_ST_TYPE (sym->st_info));
191 /* We don't need the file anymore. */
194 ebl_closebackend (ebl);