blob: 54d054c2dbea7ee59be70e03e03ec46bbb3cf51a [file] [log] [blame]
Ulrich Dreppera38998e2005-08-03 02:05:39 +00001/* Copyright (C) 2002, 2004, 2005 Red Hat, Inc.
Ulrich Drepper361df7d2006-04-04 21:38:57 +00002 This file is part of Red Hat elfutils.
Ulrich Drepperb08d5a82005-07-26 05:00:05 +00003 Written by Ulrich Drepper <drepper@redhat.com>, 2002.
4
Ulrich Drepper361df7d2006-04-04 21:38:57 +00005 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.
Ulrich Drepperb08d5a82005-07-26 05:00:05 +00008
Ulrich Drepper361df7d2006-04-04 21:38:57 +00009 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.
13
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,
Ulrich Drepper1e9ef502006-04-04 22:29:06 +000016 Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301 USA.
Ulrich Drepper361df7d2006-04-04 21:38:57 +000017
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>. */
Ulrich Drepperb08d5a82005-07-26 05:00:05 +000025
Roland McGrathd7f8d0c2005-11-17 02:32:03 +000026#ifdef HAVE_CONFIG_H
27# include <config.h>
28#endif
29
Ulrich Drepperb08d5a82005-07-26 05:00:05 +000030#include <fcntl.h>
Roland McGrathd7f8d0c2005-11-17 02:32:03 +000031#include ELFUTILS_HEADER(asm)
Ulrich Drepperb08d5a82005-07-26 05:00:05 +000032#include <libelf.h>
33#include <stdio.h>
34#include <stdlib.h>
35#include <string.h>
36#include <unistd.h>
37#include <sys/wait.h>
38
39
40static const char fname[] = "asm-tst4-out.o";
41
42
43int
44main (void)
45{
46 AsmCtx_t *ctx;
47 int result = 0;
48 size_t cnt;
49
50 elf_version (EV_CURRENT);
51
Ulrich Dreppera38998e2005-08-03 02:05:39 +000052 Ebl *ebl = ebl_openbackend_machine (EM_386);
53 if (ebl == NULL)
54 {
55 puts ("cannot open backend library");
56 return 1;
57 }
58
59 ctx = asm_begin (fname, ebl, false);
Ulrich Drepperb08d5a82005-07-26 05:00:05 +000060 if (ctx == NULL)
61 {
62 printf ("cannot create assembler context: %s\n", asm_errmsg (-1));
63 return 1;
64 }
65
66 /* Create 66000 sections. */
67 for (cnt = 0; cnt < 66000; ++cnt)
68 {
69 char buf[20];
70 AsmScn_t *scn;
71
72 /* Create a unique name. */
73 snprintf (buf, sizeof (buf), ".data.%Zu", cnt);
74
75 /* Create the section. */
76 scn = asm_newscn (ctx, buf, SHT_PROGBITS, SHF_ALLOC | SHF_WRITE);
77 if (scn == NULL)
78 {
79 printf ("cannot create section \"%s\" in output file: %s\n",
80 buf, asm_errmsg (-1));
81 asm_abort (ctx);
82 return 1;
83 }
84
85 /* Add some content. */
86 if (asm_adduint32 (scn, cnt) != 0)
87 {
88 printf ("cannot create content of section \"%s\": %s\n",
89 buf, asm_errmsg (-1));
90 asm_abort (ctx);
91 return 1;
92 }
93 }
94
95 /* Create the output file. */
96 if (asm_end (ctx) != 0)
97 {
98 printf ("cannot create output file: %s\n", asm_errmsg (-1));
99 asm_abort (ctx);
100 return 1;
101 }
102
103 if (result == 0)
104 result = WEXITSTATUS (system ("\
105env LD_LIBRARY_PATH=../libelf ../src/elflint -q asm-tst4-out.o"));
106
107 /* We don't need the file anymore. */
108 unlink (fname);
109
Ulrich Dreppera38998e2005-08-03 02:05:39 +0000110 ebl_closebackend (ebl);
111
Ulrich Drepperb08d5a82005-07-26 05:00:05 +0000112 return result;
113}