1 /* Copyright (C) 2002, 2005 Red Hat, Inc.
2 Written by Ulrich Drepper <drepper@redhat.com>, 2002.
4 This program is Open Source software; you can redistribute it and/or
5 modify it under the terms of the Open Software License version 1.0 as
6 published by the Open Source Initiative.
8 You should have received a copy of the Open Software License along
9 with this program; if not, you may obtain a copy of the Open Software
10 License version 1.0 from http://www.opensource.org/licenses/osl.php or
11 by writing the Open Source Initiative c/o Lawrence Rosen, Esq.,
12 3001 King Ranch Road, Ukiah, CA 95482. */
22 static const char fname[] = "asm-tst8-out.o";
34 elf_version (EV_CURRENT);
36 Ebl *ebl = ebl_openbackend_machine (EM_386);
39 puts ("cannot open backend library");
43 ctx = asm_begin (fname, ebl, false);
46 printf ("cannot create assembler context: %s\n", asm_errmsg (-1));
50 if (asm_newabssym (ctx, "tst8-out.s", 4, 0xfeedbeef, STT_FILE, STB_LOCAL)
53 printf ("cannot create absolute symbol: %s\n", asm_errmsg (-1));
58 /* Create the output file. */
59 if (asm_end (ctx) != 0)
61 printf ("cannot create output file: %s\n", asm_errmsg (-1));
67 fd = open (fname, O_RDONLY);
70 printf ("cannot open generated file: %m\n");
75 elf = elf_begin (fd, ELF_C_READ, NULL);
78 printf ("cannot create ELF descriptor: %s\n", elf_errmsg (-1));
82 if (elf_kind (elf) != ELF_K_ELF)
84 puts ("not a valid ELF file");
89 for (cnt = 1; 1; ++cnt)
95 scn = elf_getscn (elf, cnt);
98 printf ("cannot get section %Zd: %s\n", cnt, elf_errmsg (-1));
103 shdr = gelf_getshdr (scn, &shdr_mem);
106 printf ("cannot get section header for section %Zd: %s\n",
107 cnt, elf_errmsg (-1));
111 /* We are looking for the symbol table. */
112 if (shdr->sh_type != SHT_SYMTAB)
115 for (cnt = 1; cnt< (shdr->sh_size
116 / gelf_fsize (elf, ELF_T_SYM, 1, EV_CURRENT));
124 puts ("too many symbol");
129 sym = gelf_getsym (elf_getdata (scn, NULL), cnt, &sym_mem);
132 printf ("cannot get symbol %zu: %s\n", cnt, elf_errmsg (-1));
137 if (sym->st_shndx != SHN_ABS)
139 printf ("expected common symbol, got section %u\n",
140 (unsigned int) sym->st_shndx);
144 if (sym->st_value != 0xfeedbeef)
146 printf ("requested value 0xfeedbeef, is %#" PRIxMAX "\n",
147 (uintmax_t) sym->st_value);
151 if (sym->st_size != 4)
153 printf ("requested size 4, is %" PRIuMAX "\n",
154 (uintmax_t) sym->st_value);
158 if (GELF_ST_TYPE (sym->st_info) != STT_FILE)
160 printf ("requested type FILE, is %u\n",
161 (unsigned int) GELF_ST_TYPE (sym->st_info));
175 /* We don't need the file anymore. */
178 ebl_closebackend (ebl);