9 static const char fname[] = "asm-tst7-out.o";
21 elf_version (EV_CURRENT);
23 ctx = asm_begin (fname, false, EM_386, ELFCLASS32, ELFDATA2LSB);
26 printf ("cannot create assembler context: %s\n", asm_errmsg (-1));
30 if (asm_newcomsym (ctx, "commsym", 4, 16) == NULL)
32 printf ("cannot create common symbol: %s\n", asm_errmsg (-1));
37 /* Create the output file. */
38 if (asm_end (ctx) != 0)
40 printf ("cannot create output file: %s\n", asm_errmsg (-1));
46 fd = open (fname, O_RDONLY);
49 printf ("cannot open generated file: %m\n");
54 elf = elf_begin (fd, ELF_C_READ, NULL);
57 printf ("cannot create ELF descriptor: %s\n", elf_errmsg (-1));
61 if (elf_kind (elf) != ELF_K_ELF)
63 puts ("not a valid ELF file");
68 for (cnt = 1; 1; ++cnt)
74 scn = elf_getscn (elf, cnt);
77 printf ("cannot get section %Zd: %s\n", cnt, elf_errmsg (-1));
82 shdr = gelf_getshdr (scn, &shdr_mem);
85 printf ("cannot get section header for section %Zd: %s\n",
86 cnt, elf_errmsg (-1));
90 /* We are looking for the symbol table. */
91 if (shdr->sh_type != SHT_SYMTAB)
94 for (cnt = 1; cnt< (shdr->sh_size
95 / gelf_fsize (elf, ELF_T_SYM, 1, EV_CURRENT));
103 puts ("too many symbol");
108 sym = gelf_getsym (elf_getdata (scn, NULL), cnt, &sym_mem);
111 printf ("cannot get symbol %Zd: %s\n", cnt, elf_errmsg (-1));
116 if (sym->st_shndx != SHN_COMMON)
118 printf ("expected common symbol, got section %u\n",
119 (unsigned int) sym->st_shndx);
123 if (sym->st_value != 16)
125 printf ("requested alignment 16, is %" PRIuMAX "\n",
126 (uintmax_t) sym->st_value);
130 if (sym->st_size != 4)
132 printf ("requested size 4, is %" PRIuMAX "\n",
133 (uintmax_t) sym->st_value);
147 /* We don't need the file anymore. */