The Android Open Source Project | 593c365 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 1 | /* Copyright (C) 2002, 2004 Red Hat, Inc. |
| 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 | |
| 14 | #include <fcntl.h> |
| 15 | #include <libasm.h> |
| 16 | #include <libelf.h> |
| 17 | #include <stdio.h> |
| 18 | #include <stdlib.h> |
| 19 | #include <string.h> |
| 20 | #include <unistd.h> |
| 21 | #include <sys/wait.h> |
| 22 | |
| 23 | #include "system.h" |
| 24 | |
| 25 | |
| 26 | static const char fname[] = "asm-tst5-out.o"; |
| 27 | |
| 28 | |
| 29 | int |
| 30 | main (void) |
| 31 | { |
| 32 | AsmCtx_t *ctx; |
| 33 | int result = 0; |
| 34 | size_t cnt; |
| 35 | |
| 36 | elf_version (EV_CURRENT); |
| 37 | |
| 38 | ctx = asm_begin (fname, false, EM_386, ELFCLASS32, ELFDATA2LSB); |
| 39 | if (ctx == NULL) |
| 40 | { |
| 41 | printf ("cannot create assembler context: %s\n", asm_errmsg (-1)); |
| 42 | return 1; |
| 43 | } |
| 44 | |
| 45 | /* Create 66000 sections. */ |
| 46 | for (cnt = 0; cnt < 66000; ++cnt) |
| 47 | { |
| 48 | char buf[20]; |
| 49 | AsmScn_t *scn; |
| 50 | |
| 51 | /* Create a unique name. */ |
| 52 | snprintf (buf, sizeof (buf), ".data.%Zu", cnt); |
| 53 | |
| 54 | /* Create the section. */ |
| 55 | scn = asm_newscn (ctx, buf, SHT_PROGBITS, SHF_ALLOC | SHF_WRITE); |
| 56 | if (scn == NULL) |
| 57 | { |
| 58 | printf ("cannot create section \"%s\" in output file: %s\n", |
| 59 | buf, asm_errmsg (-1)); |
| 60 | asm_abort (ctx); |
| 61 | return 1; |
| 62 | } |
| 63 | |
| 64 | /* Add a name. */ |
| 65 | snprintf (buf, sizeof (buf), "%Zu", cnt); |
| 66 | if (asm_newsym (scn, buf, sizeof (uint32_t), STT_OBJECT, |
| 67 | STB_GLOBAL) == NULL) |
| 68 | { |
| 69 | printf ("cannot create symbol \"%s\": %s\n", buf, asm_errmsg (-1)); |
| 70 | asm_abort (ctx); |
| 71 | return 1; |
| 72 | } |
| 73 | |
| 74 | /* Add some content. */ |
| 75 | if (asm_adduint32 (scn, cnt) != 0) |
| 76 | { |
| 77 | printf ("cannot create content of section \"%s\": %s\n", |
| 78 | buf, asm_errmsg (-1)); |
| 79 | asm_abort (ctx); |
| 80 | return 1; |
| 81 | } |
| 82 | } |
| 83 | |
| 84 | /* Create the output file. */ |
| 85 | if (asm_end (ctx) != 0) |
| 86 | { |
| 87 | printf ("cannot create output file: %s\n", asm_errmsg (-1)); |
| 88 | asm_abort (ctx); |
| 89 | return 1; |
| 90 | } |
| 91 | |
| 92 | if (result == 0) |
| 93 | result = WEXITSTATUS (system ("\ |
| 94 | env LD_LIBRARY_PATH=../libelf ../src/elflint -q asm-tst5-out.o")); |
| 95 | |
| 96 | /* We don't need the file anymore. */ |
| 97 | unlink (fname); |
| 98 | |
| 99 | return result; |
| 100 | } |