blob: 629ec67f73f1d88e09a0402d4dbd3035fe60c047 [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#include "system.h"
28
29
30static const char fname[] = "asm-tst5-out.o";
31
32
33int
34main (void)
35{
36 AsmCtx_t *ctx;
37 int result = 0;
38 size_t cnt;
39
40 elf_version (EV_CURRENT);
41
Ulrich Dreppera38998e2005-08-03 02:05:39 +000042 Ebl *ebl = ebl_openbackend_machine (EM_386);
43 if (ebl == NULL)
44 {
45 puts ("cannot open backend library");
46 return 1;
47 }
48
49 ctx = asm_begin (fname, ebl, false);
Ulrich Drepperb08d5a82005-07-26 05:00:05 +000050 if (ctx == NULL)
51 {
52 printf ("cannot create assembler context: %s\n", asm_errmsg (-1));
53 return 1;
54 }
55
56 /* Create 66000 sections. */
57 for (cnt = 0; cnt < 66000; ++cnt)
58 {
59 char buf[20];
60 AsmScn_t *scn;
61
62 /* Create a unique name. */
63 snprintf (buf, sizeof (buf), ".data.%Zu", cnt);
64
65 /* Create the section. */
66 scn = asm_newscn (ctx, buf, SHT_PROGBITS, SHF_ALLOC | SHF_WRITE);
67 if (scn == NULL)
68 {
69 printf ("cannot create section \"%s\" in output file: %s\n",
70 buf, asm_errmsg (-1));
71 asm_abort (ctx);
72 return 1;
73 }
74
75 /* Add a name. */
76 snprintf (buf, sizeof (buf), "%Zu", cnt);
77 if (asm_newsym (scn, buf, sizeof (uint32_t), STT_OBJECT,
78 STB_GLOBAL) == NULL)
79 {
80 printf ("cannot create symbol \"%s\": %s\n", 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-tst5-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}