Home | History | Annotate | Download | only in tests
      1 /* Copyright (C) 2002, 2004, 2005 Red Hat, Inc.
      2    This file is part of Red Hat elfutils.
      3    Written by Ulrich Drepper <drepper (at) redhat.com>, 2002.
      4 
      5    Red Hat elfutils is free software; you can redistribute it and/or modify
      6    it under the terms of the GNU General Public License as published by the
      7    Free Software Foundation; version 2 of the License.
      8 
      9    Red Hat elfutils is distributed in the hope that it will be useful, but
     10    WITHOUT ANY WARRANTY; without even the implied warranty of
     11    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
     12    General Public License for more details.
     13 
     14    You should have received a copy of the GNU General Public License along
     15    with Red Hat elfutils; if not, write to the Free Software Foundation,
     16    Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301 USA.
     17 
     18    Red Hat elfutils is an included package of the Open Invention Network.
     19    An included package of the Open Invention Network is a package for which
     20    Open Invention Network licensees cross-license their patents.  No patent
     21    license is granted, either expressly or impliedly, by designation as an
     22    included package.  Should you wish to participate in the Open Invention
     23    Network licensing program, please visit www.openinventionnetwork.com
     24    <http://www.openinventionnetwork.com>.  */
     25 
     26 #ifdef HAVE_CONFIG_H
     27 # include <config.h>
     28 #endif
     29 
     30 #include <fcntl.h>
     31 #include ELFUTILS_HEADER(asm)
     32 #include <libelf.h>
     33 #include <stdio.h>
     34 #include <stdlib.h>
     35 #include <string.h>
     36 #include <unistd.h>
     37 #include <sys/wait.h>
     38 
     39 
     40 static const char fname[] = "asm-tst4-out.o";
     41 
     42 
     43 int
     44 main (void)
     45 {
     46   AsmCtx_t *ctx;
     47   int result = 0;
     48   size_t cnt;
     49 
     50   elf_version (EV_CURRENT);
     51 
     52   Ebl *ebl = ebl_openbackend_machine (EM_386);
     53   if (ebl == NULL)
     54     {
     55       puts ("cannot open backend library");
     56       return 1;
     57     }
     58 
     59   ctx = asm_begin (fname, ebl, false);
     60   if (ctx == NULL)
     61     {
     62       printf ("cannot create assembler context: %s\n", asm_errmsg (-1));
     63       return 1;
     64     }
     65 
     66   /* Create 66000 sections.  */
     67   for (cnt = 0; cnt < 66000; ++cnt)
     68     {
     69       char buf[20];
     70       AsmScn_t *scn;
     71 
     72       /* Create a unique name.  */
     73       snprintf (buf, sizeof (buf), ".data.%Zu", cnt);
     74 
     75       /* Create the section.  */
     76       scn = asm_newscn (ctx, buf, SHT_PROGBITS, SHF_ALLOC | SHF_WRITE);
     77       if (scn == NULL)
     78 	{
     79 	  printf ("cannot create section \"%s\" in output file: %s\n",
     80 		  buf, asm_errmsg (-1));
     81 	  asm_abort (ctx);
     82 	  return 1;
     83 	}
     84 
     85       /* Add some content.  */
     86       if (asm_adduint32 (scn, cnt) != 0)
     87 	{
     88 	  printf ("cannot create content of section \"%s\": %s\n",
     89 		  buf, asm_errmsg (-1));
     90 	  asm_abort (ctx);
     91 	  return 1;
     92 	}
     93     }
     94 
     95   /* Create the output file.  */
     96   if (asm_end (ctx) != 0)
     97     {
     98       printf ("cannot create output file: %s\n", asm_errmsg (-1));
     99       asm_abort (ctx);
    100       return 1;
    101     }
    102 
    103   if (result == 0)
    104     result = WEXITSTATUS (system ("\
    105 env LD_LIBRARY_PATH=../libelf ../src/elflint -q asm-tst4-out.o"));
    106 
    107   /* We don't need the file anymore.  */
    108   unlink (fname);
    109 
    110   ebl_closebackend (ebl);
    111 
    112   return result;
    113 }
    114