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 24static const char fname[] = "asm-tst4-out.o"; 25 26 27int 28main (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 /* Create 66000 sections. */ 44 for (cnt = 0; cnt < 66000; ++cnt) 45 { 46 char buf[20]; 47 AsmScn_t *scn; 48 49 /* Create a unique name. */ 50 snprintf (buf, sizeof (buf), ".data.%Zu", cnt); 51 52 /* Create the section. */ 53 scn = asm_newscn (ctx, buf, SHT_PROGBITS, SHF_ALLOC | SHF_WRITE); 54 if (scn == NULL) 55 { 56 printf ("cannot create section \"%s\" in output file: %s\n", 57 buf, asm_errmsg (-1)); 58 asm_abort (ctx); 59 return 1; 60 } 61 62 /* Add some content. */ 63 if (asm_adduint32 (scn, cnt) != 0) 64 { 65 printf ("cannot create content of section \"%s\": %s\n", 66 buf, asm_errmsg (-1)); 67 asm_abort (ctx); 68 return 1; 69 } 70 } 71 72 /* Create the output file. */ 73 if (asm_end (ctx) != 0) 74 { 75 printf ("cannot create output file: %s\n", asm_errmsg (-1)); 76 asm_abort (ctx); 77 return 1; 78 } 79 80 if (result == 0) 81 result = WEXITSTATUS (system ("\ 82env LD_LIBRARY_PATH=../libelf ../src/elflint -q asm-tst4-out.o")); 83 84 /* We don't need the file anymore. */ 85 unlink (fname); 86 87 return result; 88} 89