Roland McGrath | b8ff18e | 2012-01-18 13:57:08 -0800 | [diff] [blame] | 1 | /* Copyright (C) 2002-2012 Red Hat, Inc. |
Mark Wielaard | de2ed97 | 2012-06-05 17:15:16 +0200 | [diff] [blame^] | 2 | This file is part of elfutils. |
Ulrich Drepper | b08d5a8 | 2005-07-26 05:00:05 +0000 | [diff] [blame] | 3 | Written by Ulrich Drepper <drepper@redhat.com>, 2002. |
| 4 | |
Mark Wielaard | de2ed97 | 2012-06-05 17:15:16 +0200 | [diff] [blame^] | 5 | 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 Drepper | b08d5a8 | 2005-07-26 05:00:05 +0000 | [diff] [blame] | 9 | |
Mark Wielaard | de2ed97 | 2012-06-05 17:15:16 +0200 | [diff] [blame^] | 10 | elfutils is distributed in the hope that it will be useful, but |
Ulrich Drepper | 361df7d | 2006-04-04 21:38:57 +0000 | [diff] [blame] | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
Mark Wielaard | de2ed97 | 2012-06-05 17:15:16 +0200 | [diff] [blame^] | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | GNU General Public License for more details. |
Ulrich Drepper | 361df7d | 2006-04-04 21:38:57 +0000 | [diff] [blame] | 14 | |
Mark Wielaard | de2ed97 | 2012-06-05 17:15:16 +0200 | [diff] [blame^] | 15 | 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 Drepper | b08d5a8 | 2005-07-26 05:00:05 +0000 | [diff] [blame] | 17 | |
Roland McGrath | d7f8d0c | 2005-11-17 02:32:03 +0000 | [diff] [blame] | 18 | #ifdef HAVE_CONFIG_H |
| 19 | # include <config.h> |
| 20 | #endif |
| 21 | |
Ulrich Drepper | b08d5a8 | 2005-07-26 05:00:05 +0000 | [diff] [blame] | 22 | #include <fcntl.h> |
Roland McGrath | d7f8d0c | 2005-11-17 02:32:03 +0000 | [diff] [blame] | 23 | #include ELFUTILS_HEADER(asm) |
Ulrich Drepper | b08d5a8 | 2005-07-26 05:00:05 +0000 | [diff] [blame] | 24 | #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 | |
| 32 | static const char fname[] = "asm-tst4-out.o"; |
| 33 | |
| 34 | |
| 35 | int |
| 36 | main (void) |
| 37 | { |
| 38 | AsmCtx_t *ctx; |
| 39 | int result = 0; |
| 40 | size_t cnt; |
| 41 | |
| 42 | elf_version (EV_CURRENT); |
| 43 | |
Ulrich Drepper | a38998e | 2005-08-03 02:05:39 +0000 | [diff] [blame] | 44 | 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 Drepper | b08d5a8 | 2005-07-26 05:00:05 +0000 | [diff] [blame] | 52 | if (ctx == NULL) |
| 53 | { |
| 54 | printf ("cannot create assembler context: %s\n", asm_errmsg (-1)); |
| 55 | return 1; |
| 56 | } |
| 57 | |
| 58 | /* Create 66000 sections. */ |
| 59 | for (cnt = 0; cnt < 66000; ++cnt) |
| 60 | { |
| 61 | char buf[20]; |
| 62 | AsmScn_t *scn; |
| 63 | |
| 64 | /* Create a unique name. */ |
| 65 | snprintf (buf, sizeof (buf), ".data.%Zu", cnt); |
| 66 | |
| 67 | /* Create the section. */ |
| 68 | scn = asm_newscn (ctx, buf, SHT_PROGBITS, SHF_ALLOC | SHF_WRITE); |
| 69 | if (scn == NULL) |
| 70 | { |
| 71 | printf ("cannot create section \"%s\" in output file: %s\n", |
| 72 | buf, asm_errmsg (-1)); |
| 73 | asm_abort (ctx); |
| 74 | return 1; |
| 75 | } |
| 76 | |
| 77 | /* Add some content. */ |
| 78 | if (asm_adduint32 (scn, cnt) != 0) |
| 79 | { |
| 80 | printf ("cannot create content of section \"%s\": %s\n", |
| 81 | buf, asm_errmsg (-1)); |
| 82 | asm_abort (ctx); |
| 83 | return 1; |
| 84 | } |
| 85 | } |
| 86 | |
| 87 | /* Create the output file. */ |
| 88 | if (asm_end (ctx) != 0) |
| 89 | { |
| 90 | printf ("cannot create output file: %s\n", asm_errmsg (-1)); |
| 91 | asm_abort (ctx); |
| 92 | return 1; |
| 93 | } |
| 94 | |
| 95 | if (result == 0) |
Roland McGrath | b8ff18e | 2012-01-18 13:57:08 -0800 | [diff] [blame] | 96 | result = WEXITSTATUS (system ("../src/elflint -q asm-tst4-out.o")); |
Ulrich Drepper | b08d5a8 | 2005-07-26 05:00:05 +0000 | [diff] [blame] | 97 | |
| 98 | /* We don't need the file anymore. */ |
| 99 | unlink (fname); |
| 100 | |
Ulrich Drepper | a38998e | 2005-08-03 02:05:39 +0000 | [diff] [blame] | 101 | ebl_closebackend (ebl); |
| 102 | |
Ulrich Drepper | b08d5a8 | 2005-07-26 05:00:05 +0000 | [diff] [blame] | 103 | return result; |
| 104 | } |