Blame tests/asm-tst4.c

Packit 032894
/* Copyright (C) 2002-2012 Red Hat, Inc.
Packit 032894
   This file is part of elfutils.
Packit 032894
   Written by Ulrich Drepper <drepper@redhat.com>, 2002.
Packit 032894
Packit 032894
   This file is free software; you can redistribute it and/or modify
Packit 032894
   it under the terms of the GNU General Public License as published by
Packit 032894
   the Free Software Foundation; either version 3 of the License, or
Packit 032894
   (at your option) any later version.
Packit 032894
Packit 032894
   elfutils is distributed in the hope that it will be useful, but
Packit 032894
   WITHOUT ANY WARRANTY; without even the implied warranty of
Packit 032894
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
Packit 032894
   GNU General Public License for more details.
Packit 032894
Packit 032894
   You should have received a copy of the GNU General Public License
Packit 032894
   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
Packit 032894
Packit 032894
#ifdef HAVE_CONFIG_H
Packit 032894
# include <config.h>
Packit 032894
#endif
Packit 032894
Packit 032894
#include <fcntl.h>
Packit 032894
#include ELFUTILS_HEADER(asm)
Packit 032894
#include <libelf.h>
Packit 032894
#include <stdio.h>
Packit 032894
#include <stdlib.h>
Packit 032894
#include <string.h>
Packit 032894
#include <unistd.h>
Packit 032894
#include <sys/wait.h>
Packit 032894
Packit 032894
Packit 032894
static const char fname[] = "asm-tst4-out.o";
Packit 032894
Packit 032894
Packit 032894
int
Packit 032894
main (void)
Packit 032894
{
Packit 032894
  AsmCtx_t *ctx;
Packit 032894
  int result = 0;
Packit 032894
  size_t cnt;
Packit 032894
Packit 032894
  elf_version (EV_CURRENT);
Packit 032894
Packit 032894
  Ebl *ebl = ebl_openbackend_machine (EM_386);
Packit 032894
  if (ebl == NULL)
Packit 032894
    {
Packit 032894
      puts ("cannot open backend library");
Packit 032894
      return 1;
Packit 032894
    }
Packit 032894
Packit 032894
  ctx = asm_begin (fname, ebl, false);
Packit 032894
  if (ctx == NULL)
Packit 032894
    {
Packit 032894
      printf ("cannot create assembler context: %s\n", asm_errmsg (-1));
Packit 032894
      return 1;
Packit 032894
    }
Packit 032894
Packit 032894
  /* Create 66000 sections.  */
Packit 032894
  for (cnt = 0; cnt < 66000; ++cnt)
Packit 032894
    {
Packit 032894
      char buf[20];
Packit 032894
      AsmScn_t *scn;
Packit 032894
Packit 032894
      /* Create a unique name.  */
Packit 032894
      snprintf (buf, sizeof (buf), ".data.%zu", cnt);
Packit 032894
Packit 032894
      /* Create the section.  */
Packit 032894
      scn = asm_newscn (ctx, buf, SHT_PROGBITS, SHF_ALLOC | SHF_WRITE);
Packit 032894
      if (scn == NULL)
Packit 032894
	{
Packit 032894
	  printf ("cannot create section \"%s\" in output file: %s\n",
Packit 032894
		  buf, asm_errmsg (-1));
Packit 032894
	  asm_abort (ctx);
Packit 032894
	  return 1;
Packit 032894
	}
Packit 032894
Packit 032894
      /* Add some content.  */
Packit 032894
      if (asm_adduint32 (scn, cnt) != 0)
Packit 032894
	{
Packit 032894
	  printf ("cannot create content of section \"%s\": %s\n",
Packit 032894
		  buf, asm_errmsg (-1));
Packit 032894
	  asm_abort (ctx);
Packit 032894
	  return 1;
Packit 032894
	}
Packit 032894
    }
Packit 032894
Packit 032894
  /* Create the output file.  */
Packit 032894
  if (asm_end (ctx) != 0)
Packit 032894
    {
Packit 032894
      printf ("cannot create output file: %s\n", asm_errmsg (-1));
Packit 032894
      asm_abort (ctx);
Packit 032894
      return 1;
Packit 032894
    }
Packit 032894
Packit 032894
  if (result == 0)
Packit 032894
    result = WEXITSTATUS (system ("../src/elflint -q asm-tst4-out.o"));
Packit 032894
Packit 032894
  /* We don't need the file anymore.  */
Packit 032894
  unlink (fname);
Packit 032894
Packit 032894
  ebl_closebackend (ebl);
Packit 032894
Packit 032894
  return result;
Packit 032894
}