blob: 35854d52031c987f446a963f5e1017088fd5e523 [file] [log] [blame]
Roland McGrathb8ff18e2012-01-18 13:57:08 -08001/* Copyright (C) 2002-2012 Red Hat, Inc.
Mark Wielaardde2ed972012-06-05 17:15:16 +02002 This file is part of elfutils.
Ulrich Drepperb08d5a82005-07-26 05:00:05 +00003 Written by Ulrich Drepper <drepper@redhat.com>, 2002.
4
Mark Wielaardde2ed972012-06-05 17:15:16 +02005 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.
Ulrich Drepperb08d5a82005-07-26 05:00:05 +00009
Mark Wielaardde2ed972012-06-05 17:15:16 +020010 elfutils is distributed in the hope that it will be useful, but
Ulrich Drepper361df7d2006-04-04 21:38:57 +000011 WITHOUT ANY WARRANTY; without even the implied warranty of
Mark Wielaardde2ed972012-06-05 17:15:16 +020012 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
Ulrich Drepper361df7d2006-04-04 21:38:57 +000014
Mark Wielaardde2ed972012-06-05 17:15:16 +020015 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/>. */
Ulrich Drepperb08d5a82005-07-26 05:00:05 +000017
Roland McGrathd7f8d0c2005-11-17 02:32:03 +000018#ifdef HAVE_CONFIG_H
19# include <config.h>
20#endif
21
22#include ELFUTILS_HEADER(asm)
Ulrich Drepperb08d5a82005-07-26 05:00:05 +000023#include <libelf.h>
24#include <stdio.h>
25#include <stdlib.h>
26#include <unistd.h>
27#include <sys/wait.h>
28
29#include <system.h>
30
31
32static const char fname[] = "asm-tst6-out.o";
33
34
35int
36main (void)
37{
38 AsmCtx_t *ctx;
39 int result = 0;
40 size_t cnt;
41
42 elf_version (EV_CURRENT);
43
Ulrich Dreppera38998e2005-08-03 02:05:39 +000044 Ebl *ebl = ebl_openbackend_machine (EM_386);
45 if (ebl == NULL)
46 {
47 puts ("cannot open backend library");
48 return 1;
49 }
50
51 ctx = asm_begin (fname, ebl, false);
Ulrich Drepperb08d5a82005-07-26 05:00:05 +000052 if (ctx == NULL)
53 {
54 printf ("cannot create assembler context: %s\n", asm_errmsg (-1));
55 return 1;
56 }
57
58 for (cnt = 0; cnt < 22000; ++cnt)
59 {
60 char buf[512];
61 AsmScnGrp_t *grp;
62 AsmScn_t *scn;
63 AsmSym_t *sym;
64
65 snprintf (buf, sizeof (buf), ".grp%Zu", cnt);
66 grp = asm_newscngrp (ctx, buf, NULL, 0);
67 if (grp == NULL)
68 {
69 printf ("cannot section group %Zu: %s\n", cnt, asm_errmsg (-1));
70 asm_abort (ctx);
71 return 1;
72 }
73
74 scn = asm_newscn_ingrp (ctx, ".data", SHT_PROGBITS,
75 SHF_ALLOC | SHF_WRITE, grp);
76 if (scn == NULL)
77 {
78 printf ("cannot data section for group %Zu: %s\n",
79 cnt, asm_errmsg (-1));
80 asm_abort (ctx);
81 return 1;
82 }
83
84 /* Add a name. */
85 snprintf (buf, sizeof (buf), "%Zu", cnt);
86 sym = asm_newsym (scn, buf, sizeof (uint32_t), STT_OBJECT,
87 STB_GLOBAL);
88 if (sym == NULL)
89 {
90 printf ("cannot create symbol \"%s\": %s\n", buf, asm_errmsg (-1));
91 asm_abort (ctx);
92 return 1;
93 }
94
95 /* Add some content. */
96 if (asm_adduint32 (scn, cnt) != 0)
97 {
98 printf ("cannot create content of section \"%s\": %s\n",
99 buf, asm_errmsg (-1));
100 asm_abort (ctx);
101 return 1;
102 }
103
104 /* Now we have a symbol, use it as the signature. */
105 if (asm_scngrp_newsignature (grp, sym) != 0)
106 {
107 printf ("cannot set signature for section group %Zu: %s\n",
108 cnt, asm_errmsg (-1));
109 asm_abort (ctx);
110 return 1;
111 }
112
113 /* Create a phony debug info section. */
114 scn = asm_newscn_ingrp (ctx, ".stab", SHT_PROGBITS, 0, grp);
115 if (scn == NULL)
116 {
117 printf ("cannot stab section for group %Zu: %s\n",
118 cnt, asm_errmsg (-1));
119 asm_abort (ctx);
120 return 1;
121 }
122
123 /* Add some content. */
124 if (asm_adduint32 (scn, cnt) != 0)
125 {
126 printf ("cannot create content of section \"%s\": %s\n",
127 buf, asm_errmsg (-1));
128 asm_abort (ctx);
129 return 1;
130 }
131 }
132
133 /* Create the output file. */
134 if (asm_end (ctx) != 0)
135 {
136 printf ("cannot create output file: %s\n", asm_errmsg (-1));
137 asm_abort (ctx);
138 return 1;
139 }
140
141 if (result == 0)
Roland McGrathb8ff18e2012-01-18 13:57:08 -0800142 result = WEXITSTATUS (system ("../src/elflint -q asm-tst6-out.o"));
Ulrich Drepperb08d5a82005-07-26 05:00:05 +0000143
144 /* We don't need the file anymore. */
145 unlink (fname);
146
Ulrich Dreppera38998e2005-08-03 02:05:39 +0000147 ebl_closebackend (ebl);
148
Ulrich Drepperb08d5a82005-07-26 05:00:05 +0000149 return result;
150}