blob: bd6a71df671d5f3509d7e75ff0cd353ab3f11190 [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
30#include ELFUTILS_HEADER(asm)
Ulrich Drepperb08d5a82005-07-26 05:00:05 +000031#include <libelf.h>
32#include <stdio.h>
33#include <stdlib.h>
34#include <unistd.h>
35#include <sys/wait.h>
36
37#include <system.h>
38
39
40static const char fname[] = "asm-tst6-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 for (cnt = 0; cnt < 22000; ++cnt)
67 {
68 char buf[512];
69 AsmScnGrp_t *grp;
70 AsmScn_t *scn;
71 AsmSym_t *sym;
72
73 snprintf (buf, sizeof (buf), ".grp%Zu", cnt);
74 grp = asm_newscngrp (ctx, buf, NULL, 0);
75 if (grp == NULL)
76 {
77 printf ("cannot section group %Zu: %s\n", cnt, asm_errmsg (-1));
78 asm_abort (ctx);
79 return 1;
80 }
81
82 scn = asm_newscn_ingrp (ctx, ".data", SHT_PROGBITS,
83 SHF_ALLOC | SHF_WRITE, grp);
84 if (scn == NULL)
85 {
86 printf ("cannot data section for group %Zu: %s\n",
87 cnt, asm_errmsg (-1));
88 asm_abort (ctx);
89 return 1;
90 }
91
92 /* Add a name. */
93 snprintf (buf, sizeof (buf), "%Zu", cnt);
94 sym = asm_newsym (scn, buf, sizeof (uint32_t), STT_OBJECT,
95 STB_GLOBAL);
96 if (sym == NULL)
97 {
98 printf ("cannot create symbol \"%s\": %s\n", buf, asm_errmsg (-1));
99 asm_abort (ctx);
100 return 1;
101 }
102
103 /* Add some content. */
104 if (asm_adduint32 (scn, cnt) != 0)
105 {
106 printf ("cannot create content of section \"%s\": %s\n",
107 buf, asm_errmsg (-1));
108 asm_abort (ctx);
109 return 1;
110 }
111
112 /* Now we have a symbol, use it as the signature. */
113 if (asm_scngrp_newsignature (grp, sym) != 0)
114 {
115 printf ("cannot set signature for section group %Zu: %s\n",
116 cnt, asm_errmsg (-1));
117 asm_abort (ctx);
118 return 1;
119 }
120
121 /* Create a phony debug info section. */
122 scn = asm_newscn_ingrp (ctx, ".stab", SHT_PROGBITS, 0, grp);
123 if (scn == NULL)
124 {
125 printf ("cannot stab section for group %Zu: %s\n",
126 cnt, asm_errmsg (-1));
127 asm_abort (ctx);
128 return 1;
129 }
130
131 /* Add some content. */
132 if (asm_adduint32 (scn, cnt) != 0)
133 {
134 printf ("cannot create content of section \"%s\": %s\n",
135 buf, asm_errmsg (-1));
136 asm_abort (ctx);
137 return 1;
138 }
139 }
140
141 /* Create the output file. */
142 if (asm_end (ctx) != 0)
143 {
144 printf ("cannot create output file: %s\n", asm_errmsg (-1));
145 asm_abort (ctx);
146 return 1;
147 }
148
149 if (result == 0)
150 result = WEXITSTATUS (system ("\
151env LD_LIBRARY_PATH=../libelf ../src/elflint -q asm-tst6-out.o"));
152
153 /* We don't need the file anymore. */
154 unlink (fname);
155
Ulrich Dreppera38998e2005-08-03 02:05:39 +0000156 ebl_closebackend (ebl);
157
Ulrich Drepperb08d5a82005-07-26 05:00:05 +0000158 return result;
159}