blob: affc0c90f73a7fdb0b2419eeaea16a594f72a3c4 [file] [log] [blame]
Ulrich Dreppera38998e2005-08-03 02:05:39 +00001/* Copyright (C) 2002, 2004, 2005 Red Hat, Inc.
Ulrich Drepperb08d5a82005-07-26 05:00:05 +00002 Written by Ulrich Drepper <drepper@redhat.com>, 2002.
3
4 This program is Open Source software; you can redistribute it and/or
5 modify it under the terms of the Open Software License version 1.0 as
6 published by the Open Source Initiative.
7
8 You should have received a copy of the Open Software License along
9 with this program; if not, you may obtain a copy of the Open Software
10 License version 1.0 from http://www.opensource.org/licenses/osl.php or
11 by writing the Open Source Initiative c/o Lawrence Rosen, Esq.,
12 3001 King Ranch Road, Ukiah, CA 95482. */
13
Roland McGrathd7f8d0c2005-11-17 02:32:03 +000014#ifdef HAVE_CONFIG_H
15# include <config.h>
16#endif
17
Ulrich Drepperb08d5a82005-07-26 05:00:05 +000018#include <fcntl.h>
Roland McGrathd7f8d0c2005-11-17 02:32:03 +000019#include ELFUTILS_HEADER(asm)
Ulrich Drepperb08d5a82005-07-26 05:00:05 +000020#include <libelf.h>
21#include <stdio.h>
22#include <stdlib.h>
23#include <string.h>
24#include <unistd.h>
25#include <sys/wait.h>
26
27
28static const char fname[] = "asm-tst4-out.o";
29
30
31int
32main (void)
33{
34 AsmCtx_t *ctx;
35 int result = 0;
36 size_t cnt;
37
38 elf_version (EV_CURRENT);
39
Ulrich Dreppera38998e2005-08-03 02:05:39 +000040 Ebl *ebl = ebl_openbackend_machine (EM_386);
41 if (ebl == NULL)
42 {
43 puts ("cannot open backend library");
44 return 1;
45 }
46
47 ctx = asm_begin (fname, ebl, false);
Ulrich Drepperb08d5a82005-07-26 05:00:05 +000048 if (ctx == NULL)
49 {
50 printf ("cannot create assembler context: %s\n", asm_errmsg (-1));
51 return 1;
52 }
53
54 /* Create 66000 sections. */
55 for (cnt = 0; cnt < 66000; ++cnt)
56 {
57 char buf[20];
58 AsmScn_t *scn;
59
60 /* Create a unique name. */
61 snprintf (buf, sizeof (buf), ".data.%Zu", cnt);
62
63 /* Create the section. */
64 scn = asm_newscn (ctx, buf, SHT_PROGBITS, SHF_ALLOC | SHF_WRITE);
65 if (scn == NULL)
66 {
67 printf ("cannot create section \"%s\" in output file: %s\n",
68 buf, asm_errmsg (-1));
69 asm_abort (ctx);
70 return 1;
71 }
72
73 /* Add some content. */
74 if (asm_adduint32 (scn, cnt) != 0)
75 {
76 printf ("cannot create content of section \"%s\": %s\n",
77 buf, asm_errmsg (-1));
78 asm_abort (ctx);
79 return 1;
80 }
81 }
82
83 /* Create the output file. */
84 if (asm_end (ctx) != 0)
85 {
86 printf ("cannot create output file: %s\n", asm_errmsg (-1));
87 asm_abort (ctx);
88 return 1;
89 }
90
91 if (result == 0)
92 result = WEXITSTATUS (system ("\
93env LD_LIBRARY_PATH=../libelf ../src/elflint -q asm-tst4-out.o"));
94
95 /* We don't need the file anymore. */
96 unlink (fname);
97
Ulrich Dreppera38998e2005-08-03 02:05:39 +000098 ebl_closebackend (ebl);
99
Ulrich Drepperb08d5a82005-07-26 05:00:05 +0000100 return result;
101}