Ulrich Drepper | b08d5a8 | 2005-07-26 05:00:05 +0000 | [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 <libasm.h> |
| 15 | #include <libelf.h> |
| 16 | #include <stdio.h> |
| 17 | #include <stdlib.h> |
| 18 | #include <unistd.h> |
| 19 | #include <sys/wait.h> |
| 20 | |
| 21 | #include <system.h> |
| 22 | |
| 23 | |
| 24 | static const char fname[] = "asm-tst6-out.o"; |
| 25 | |
| 26 | |
| 27 | int |
| 28 | main (void) |
| 29 | { |
| 30 | AsmCtx_t *ctx; |
| 31 | int result = 0; |
| 32 | size_t cnt; |
| 33 | |
| 34 | elf_version (EV_CURRENT); |
| 35 | |
| 36 | ctx = asm_begin (fname, false, EM_386, ELFCLASS32, ELFDATA2LSB); |
| 37 | if (ctx == NULL) |
| 38 | { |
| 39 | printf ("cannot create assembler context: %s\n", asm_errmsg (-1)); |
| 40 | return 1; |
| 41 | } |
| 42 | |
| 43 | for (cnt = 0; cnt < 22000; ++cnt) |
| 44 | { |
| 45 | char buf[512]; |
| 46 | AsmScnGrp_t *grp; |
| 47 | AsmScn_t *scn; |
| 48 | AsmSym_t *sym; |
| 49 | |
| 50 | snprintf (buf, sizeof (buf), ".grp%Zu", cnt); |
| 51 | grp = asm_newscngrp (ctx, buf, NULL, 0); |
| 52 | if (grp == NULL) |
| 53 | { |
| 54 | printf ("cannot section group %Zu: %s\n", cnt, asm_errmsg (-1)); |
| 55 | asm_abort (ctx); |
| 56 | return 1; |
| 57 | } |
| 58 | |
| 59 | scn = asm_newscn_ingrp (ctx, ".data", SHT_PROGBITS, |
| 60 | SHF_ALLOC | SHF_WRITE, grp); |
| 61 | if (scn == NULL) |
| 62 | { |
| 63 | printf ("cannot data section for group %Zu: %s\n", |
| 64 | cnt, asm_errmsg (-1)); |
| 65 | asm_abort (ctx); |
| 66 | return 1; |
| 67 | } |
| 68 | |
| 69 | /* Add a name. */ |
| 70 | snprintf (buf, sizeof (buf), "%Zu", cnt); |
| 71 | sym = asm_newsym (scn, buf, sizeof (uint32_t), STT_OBJECT, |
| 72 | STB_GLOBAL); |
| 73 | if (sym == NULL) |
| 74 | { |
| 75 | printf ("cannot create symbol \"%s\": %s\n", buf, asm_errmsg (-1)); |
| 76 | asm_abort (ctx); |
| 77 | return 1; |
| 78 | } |
| 79 | |
| 80 | /* Add some content. */ |
| 81 | if (asm_adduint32 (scn, cnt) != 0) |
| 82 | { |
| 83 | printf ("cannot create content of section \"%s\": %s\n", |
| 84 | buf, asm_errmsg (-1)); |
| 85 | asm_abort (ctx); |
| 86 | return 1; |
| 87 | } |
| 88 | |
| 89 | /* Now we have a symbol, use it as the signature. */ |
| 90 | if (asm_scngrp_newsignature (grp, sym) != 0) |
| 91 | { |
| 92 | printf ("cannot set signature for section group %Zu: %s\n", |
| 93 | cnt, asm_errmsg (-1)); |
| 94 | asm_abort (ctx); |
| 95 | return 1; |
| 96 | } |
| 97 | |
| 98 | /* Create a phony debug info section. */ |
| 99 | scn = asm_newscn_ingrp (ctx, ".stab", SHT_PROGBITS, 0, grp); |
| 100 | if (scn == NULL) |
| 101 | { |
| 102 | printf ("cannot stab section for group %Zu: %s\n", |
| 103 | cnt, asm_errmsg (-1)); |
| 104 | asm_abort (ctx); |
| 105 | return 1; |
| 106 | } |
| 107 | |
| 108 | /* Add some content. */ |
| 109 | if (asm_adduint32 (scn, cnt) != 0) |
| 110 | { |
| 111 | printf ("cannot create content of section \"%s\": %s\n", |
| 112 | buf, asm_errmsg (-1)); |
| 113 | asm_abort (ctx); |
| 114 | return 1; |
| 115 | } |
| 116 | } |
| 117 | |
| 118 | /* Create the output file. */ |
| 119 | if (asm_end (ctx) != 0) |
| 120 | { |
| 121 | printf ("cannot create output file: %s\n", asm_errmsg (-1)); |
| 122 | asm_abort (ctx); |
| 123 | return 1; |
| 124 | } |
| 125 | |
| 126 | if (result == 0) |
| 127 | result = WEXITSTATUS (system ("\ |
| 128 | env LD_LIBRARY_PATH=../libelf ../src/elflint -q asm-tst6-out.o")); |
| 129 | |
| 130 | /* We don't need the file anymore. */ |
| 131 | unlink (fname); |
| 132 | |
| 133 | return result; |
| 134 | } |