Ulrich Drepper | a38998e | 2005-08-03 02:05:39 +0000 | [diff] [blame] | 1 | /* Copyright (C) 2002, 2004, 2005 Red Hat, Inc. |
Ulrich Drepper | b08d5a8 | 2005-07-26 05:00:05 +0000 | [diff] [blame] | 2 | 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 McGrath | d7f8d0c | 2005-11-17 02:32:03 +0000 | [diff] [blame^] | 14 | #ifdef HAVE_CONFIG_H |
| 15 | # include <config.h> |
| 16 | #endif |
| 17 | |
Ulrich Drepper | b08d5a8 | 2005-07-26 05:00:05 +0000 | [diff] [blame] | 18 | #include <fcntl.h> |
Roland McGrath | d7f8d0c | 2005-11-17 02:32:03 +0000 | [diff] [blame^] | 19 | #include ELFUTILS_HEADER(asm) |
Ulrich Drepper | b08d5a8 | 2005-07-26 05:00:05 +0000 | [diff] [blame] | 20 | #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 | |
| 28 | static const char fname[] = "asm-tst4-out.o"; |
| 29 | |
| 30 | |
| 31 | int |
| 32 | main (void) |
| 33 | { |
| 34 | AsmCtx_t *ctx; |
| 35 | int result = 0; |
| 36 | size_t cnt; |
| 37 | |
| 38 | elf_version (EV_CURRENT); |
| 39 | |
Ulrich Drepper | a38998e | 2005-08-03 02:05:39 +0000 | [diff] [blame] | 40 | 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 Drepper | b08d5a8 | 2005-07-26 05:00:05 +0000 | [diff] [blame] | 48 | 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 ("\ |
| 93 | env 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 Drepper | a38998e | 2005-08-03 02:05:39 +0000 | [diff] [blame] | 98 | ebl_closebackend (ebl); |
| 99 | |
Ulrich Drepper | b08d5a8 | 2005-07-26 05:00:05 +0000 | [diff] [blame] | 100 | return result; |
| 101 | } |