1 /* Copyright (C) 2002-2012 Red Hat, Inc.
2 This file is part of elfutils.
3 Written by Ulrich Drepper <drepper@redhat.com>, 2002.
4
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.
9
10 elfutils is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
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/>. */
17
18 #ifdef HAVE_CONFIG_H
19 # include <config.h>
20 #endif
21
22 #include <fcntl.h>
23 #include ELFUTILS_HEADER(asm)
24 #include ELFUTILS_HEADER(ebl)
25 #include <libelf.h>
26 #include <stdio.h>
27 #include <stdlib.h>
28 #include <string.h>
29 #include <unistd.h>
30 #include <sys/wait.h>
31
32
33 static const char fname[] = "asm-tst4-out.o";
34
35
36 int
main(void)37 main (void)
38 {
39 AsmCtx_t *ctx;
40 int result = 0;
41 size_t cnt;
42
43 elf_version (EV_CURRENT);
44
45 Ebl *ebl = ebl_openbackend_machine (EM_386);
46 if (ebl == NULL)
47 {
48 puts ("cannot open backend library");
49 return 1;
50 }
51
52 ctx = asm_begin (fname, ebl, false);
53 if (ctx == NULL)
54 {
55 printf ("cannot create assembler context: %s\n", asm_errmsg (-1));
56 return 1;
57 }
58
59 /* Create 66000 sections. */
60 for (cnt = 0; cnt < 66000; ++cnt)
61 {
62 char buf[20];
63 AsmScn_t *scn;
64
65 /* Create a unique name. */
66 snprintf (buf, sizeof (buf), ".data.%zu", cnt);
67
68 /* Create the section. */
69 scn = asm_newscn (ctx, buf, SHT_PROGBITS, SHF_ALLOC | SHF_WRITE);
70 if (scn == NULL)
71 {
72 printf ("cannot create section \"%s\" in output file: %s\n",
73 buf, asm_errmsg (-1));
74 asm_abort (ctx);
75 return 1;
76 }
77
78 /* Add some content. */
79 if (asm_adduint32 (scn, cnt) != 0)
80 {
81 printf ("cannot create content of section \"%s\": %s\n",
82 buf, asm_errmsg (-1));
83 asm_abort (ctx);
84 return 1;
85 }
86 }
87
88 /* Create the output file. */
89 if (asm_end (ctx) != 0)
90 {
91 printf ("cannot create output file: %s\n", asm_errmsg (-1));
92 asm_abort (ctx);
93 return 1;
94 }
95
96 if (result == 0)
97 result = WEXITSTATUS (system ("../src/elflint -q asm-tst4-out.o"));
98
99 /* We don't need the file anymore. */
100 unlink (fname);
101
102 ebl_closebackend (ebl);
103
104 return result;
105 }
106