blob: d97d4be93d37dee611a48c014263765c2c1d3a7d [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
Ulrich Drepperb08d5a82005-07-26 05:00:05 +000022#include <fcntl.h>
Roland McGrathd7f8d0c2005-11-17 02:32:03 +000023#include ELFUTILS_HEADER(asm)
Ulrich Drepperb08d5a82005-07-26 05:00:05 +000024#include <libelf.h>
25#include <stdio.h>
26#include <stdlib.h>
27#include <string.h>
28#include <unistd.h>
29#include <sys/wait.h>
30
31#include "system.h"
32
33
34static const char fname[] = "asm-tst5-out.o";
35
36
37int
38main (void)
39{
40 AsmCtx_t *ctx;
41 int result = 0;
42 size_t cnt;
43
44 elf_version (EV_CURRENT);
45
Ulrich Dreppera38998e2005-08-03 02:05:39 +000046 Ebl *ebl = ebl_openbackend_machine (EM_386);
47 if (ebl == NULL)
48 {
49 puts ("cannot open backend library");
50 return 1;
51 }
52
53 ctx = asm_begin (fname, ebl, false);
Ulrich Drepperb08d5a82005-07-26 05:00:05 +000054 if (ctx == NULL)
55 {
56 printf ("cannot create assembler context: %s\n", asm_errmsg (-1));
57 return 1;
58 }
59
60 /* Create 66000 sections. */
61 for (cnt = 0; cnt < 66000; ++cnt)
62 {
63 char buf[20];
64 AsmScn_t *scn;
65
66 /* Create a unique name. */
67 snprintf (buf, sizeof (buf), ".data.%Zu", cnt);
68
69 /* Create the section. */
70 scn = asm_newscn (ctx, buf, SHT_PROGBITS, SHF_ALLOC | SHF_WRITE);
71 if (scn == NULL)
72 {
73 printf ("cannot create section \"%s\" in output file: %s\n",
74 buf, asm_errmsg (-1));
75 asm_abort (ctx);
76 return 1;
77 }
78
79 /* Add a name. */
80 snprintf (buf, sizeof (buf), "%Zu", cnt);
81 if (asm_newsym (scn, buf, sizeof (uint32_t), STT_OBJECT,
82 STB_GLOBAL) == NULL)
83 {
84 printf ("cannot create symbol \"%s\": %s\n", buf, asm_errmsg (-1));
85 asm_abort (ctx);
86 return 1;
87 }
88
89 /* Add some content. */
90 if (asm_adduint32 (scn, cnt) != 0)
91 {
92 printf ("cannot create content of section \"%s\": %s\n",
93 buf, asm_errmsg (-1));
94 asm_abort (ctx);
95 return 1;
96 }
97 }
98
99 /* Create the output file. */
100 if (asm_end (ctx) != 0)
101 {
102 printf ("cannot create output file: %s\n", asm_errmsg (-1));
103 asm_abort (ctx);
104 return 1;
105 }
106
107 if (result == 0)
Roland McGrathb8ff18e2012-01-18 13:57:08 -0800108 result = WEXITSTATUS (system ("../src/elflint -q asm-tst5-out.o"));
Ulrich Drepperb08d5a82005-07-26 05:00:05 +0000109
110 /* We don't need the file anymore. */
111 unlink (fname);
112
Ulrich Dreppera38998e2005-08-03 02:05:39 +0000113 ebl_closebackend (ebl);
114
Ulrich Drepperb08d5a82005-07-26 05:00:05 +0000115 return result;
116}