1441f72d43a9b550baa779fc82f70816da5f74f0eThe Android Open Source Project/* Copyright (C) 2002, 2004 Red Hat, Inc. 2441f72d43a9b550baa779fc82f70816da5f74f0eThe Android Open Source Project Written by Ulrich Drepper <drepper@redhat.com>, 2002. 3441f72d43a9b550baa779fc82f70816da5f74f0eThe Android Open Source Project 4441f72d43a9b550baa779fc82f70816da5f74f0eThe Android Open Source Project This program is Open Source software; you can redistribute it and/or 5441f72d43a9b550baa779fc82f70816da5f74f0eThe Android Open Source Project modify it under the terms of the Open Software License version 1.0 as 6441f72d43a9b550baa779fc82f70816da5f74f0eThe Android Open Source Project published by the Open Source Initiative. 7441f72d43a9b550baa779fc82f70816da5f74f0eThe Android Open Source Project 8441f72d43a9b550baa779fc82f70816da5f74f0eThe Android Open Source Project You should have received a copy of the Open Software License along 9441f72d43a9b550baa779fc82f70816da5f74f0eThe Android Open Source Project with this program; if not, you may obtain a copy of the Open Software 10441f72d43a9b550baa779fc82f70816da5f74f0eThe Android Open Source Project License version 1.0 from http://www.opensource.org/licenses/osl.php or 11441f72d43a9b550baa779fc82f70816da5f74f0eThe Android Open Source Project by writing the Open Source Initiative c/o Lawrence Rosen, Esq., 12441f72d43a9b550baa779fc82f70816da5f74f0eThe Android Open Source Project 3001 King Ranch Road, Ukiah, CA 95482. */ 13441f72d43a9b550baa779fc82f70816da5f74f0eThe Android Open Source Project 14441f72d43a9b550baa779fc82f70816da5f74f0eThe Android Open Source Project#include <libasm.h> 15441f72d43a9b550baa779fc82f70816da5f74f0eThe Android Open Source Project#include <libelf.h> 16441f72d43a9b550baa779fc82f70816da5f74f0eThe Android Open Source Project#include <stdio.h> 17441f72d43a9b550baa779fc82f70816da5f74f0eThe Android Open Source Project#include <stdlib.h> 18441f72d43a9b550baa779fc82f70816da5f74f0eThe Android Open Source Project#include <unistd.h> 19441f72d43a9b550baa779fc82f70816da5f74f0eThe Android Open Source Project#include <sys/wait.h> 20441f72d43a9b550baa779fc82f70816da5f74f0eThe Android Open Source Project 21441f72d43a9b550baa779fc82f70816da5f74f0eThe Android Open Source Project#include <system.h> 22441f72d43a9b550baa779fc82f70816da5f74f0eThe Android Open Source Project 23441f72d43a9b550baa779fc82f70816da5f74f0eThe Android Open Source Project 24441f72d43a9b550baa779fc82f70816da5f74f0eThe Android Open Source Projectstatic const char fname[] = "asm-tst6-out.o"; 25441f72d43a9b550baa779fc82f70816da5f74f0eThe Android Open Source Project 26441f72d43a9b550baa779fc82f70816da5f74f0eThe Android Open Source Project 27441f72d43a9b550baa779fc82f70816da5f74f0eThe Android Open Source Projectint 28441f72d43a9b550baa779fc82f70816da5f74f0eThe Android Open Source Projectmain (void) 29441f72d43a9b550baa779fc82f70816da5f74f0eThe Android Open Source Project{ 30441f72d43a9b550baa779fc82f70816da5f74f0eThe Android Open Source Project AsmCtx_t *ctx; 31441f72d43a9b550baa779fc82f70816da5f74f0eThe Android Open Source Project int result = 0; 32441f72d43a9b550baa779fc82f70816da5f74f0eThe Android Open Source Project size_t cnt; 33441f72d43a9b550baa779fc82f70816da5f74f0eThe Android Open Source Project 34441f72d43a9b550baa779fc82f70816da5f74f0eThe Android Open Source Project elf_version (EV_CURRENT); 35441f72d43a9b550baa779fc82f70816da5f74f0eThe Android Open Source Project 36441f72d43a9b550baa779fc82f70816da5f74f0eThe Android Open Source Project ctx = asm_begin (fname, false, EM_386, ELFCLASS32, ELFDATA2LSB); 37441f72d43a9b550baa779fc82f70816da5f74f0eThe Android Open Source Project if (ctx == NULL) 38441f72d43a9b550baa779fc82f70816da5f74f0eThe Android Open Source Project { 39441f72d43a9b550baa779fc82f70816da5f74f0eThe Android Open Source Project printf ("cannot create assembler context: %s\n", asm_errmsg (-1)); 40441f72d43a9b550baa779fc82f70816da5f74f0eThe Android Open Source Project return 1; 41441f72d43a9b550baa779fc82f70816da5f74f0eThe Android Open Source Project } 42441f72d43a9b550baa779fc82f70816da5f74f0eThe Android Open Source Project 43441f72d43a9b550baa779fc82f70816da5f74f0eThe Android Open Source Project for (cnt = 0; cnt < 22000; ++cnt) 44441f72d43a9b550baa779fc82f70816da5f74f0eThe Android Open Source Project { 45441f72d43a9b550baa779fc82f70816da5f74f0eThe Android Open Source Project char buf[512]; 46441f72d43a9b550baa779fc82f70816da5f74f0eThe Android Open Source Project AsmScnGrp_t *grp; 47441f72d43a9b550baa779fc82f70816da5f74f0eThe Android Open Source Project AsmScn_t *scn; 48441f72d43a9b550baa779fc82f70816da5f74f0eThe Android Open Source Project AsmSym_t *sym; 49441f72d43a9b550baa779fc82f70816da5f74f0eThe Android Open Source Project 50441f72d43a9b550baa779fc82f70816da5f74f0eThe Android Open Source Project snprintf (buf, sizeof (buf), ".grp%Zu", cnt); 51441f72d43a9b550baa779fc82f70816da5f74f0eThe Android Open Source Project grp = asm_newscngrp (ctx, buf, NULL, 0); 52441f72d43a9b550baa779fc82f70816da5f74f0eThe Android Open Source Project if (grp == NULL) 53441f72d43a9b550baa779fc82f70816da5f74f0eThe Android Open Source Project { 54441f72d43a9b550baa779fc82f70816da5f74f0eThe Android Open Source Project printf ("cannot section group %Zu: %s\n", cnt, asm_errmsg (-1)); 55441f72d43a9b550baa779fc82f70816da5f74f0eThe Android Open Source Project asm_abort (ctx); 56441f72d43a9b550baa779fc82f70816da5f74f0eThe Android Open Source Project return 1; 57441f72d43a9b550baa779fc82f70816da5f74f0eThe Android Open Source Project } 58441f72d43a9b550baa779fc82f70816da5f74f0eThe Android Open Source Project 59441f72d43a9b550baa779fc82f70816da5f74f0eThe Android Open Source Project scn = asm_newscn_ingrp (ctx, ".data", SHT_PROGBITS, 60441f72d43a9b550baa779fc82f70816da5f74f0eThe Android Open Source Project SHF_ALLOC | SHF_WRITE, grp); 61441f72d43a9b550baa779fc82f70816da5f74f0eThe Android Open Source Project if (scn == NULL) 62441f72d43a9b550baa779fc82f70816da5f74f0eThe Android Open Source Project { 63441f72d43a9b550baa779fc82f70816da5f74f0eThe Android Open Source Project printf ("cannot data section for group %Zu: %s\n", 64441f72d43a9b550baa779fc82f70816da5f74f0eThe Android Open Source Project cnt, asm_errmsg (-1)); 65441f72d43a9b550baa779fc82f70816da5f74f0eThe Android Open Source Project asm_abort (ctx); 66441f72d43a9b550baa779fc82f70816da5f74f0eThe Android Open Source Project return 1; 67441f72d43a9b550baa779fc82f70816da5f74f0eThe Android Open Source Project } 68441f72d43a9b550baa779fc82f70816da5f74f0eThe Android Open Source Project 69441f72d43a9b550baa779fc82f70816da5f74f0eThe Android Open Source Project /* Add a name. */ 70441f72d43a9b550baa779fc82f70816da5f74f0eThe Android Open Source Project snprintf (buf, sizeof (buf), "%Zu", cnt); 71441f72d43a9b550baa779fc82f70816da5f74f0eThe Android Open Source Project sym = asm_newsym (scn, buf, sizeof (uint32_t), STT_OBJECT, 72441f72d43a9b550baa779fc82f70816da5f74f0eThe Android Open Source Project STB_GLOBAL); 73441f72d43a9b550baa779fc82f70816da5f74f0eThe Android Open Source Project if (sym == NULL) 74441f72d43a9b550baa779fc82f70816da5f74f0eThe Android Open Source Project { 75441f72d43a9b550baa779fc82f70816da5f74f0eThe Android Open Source Project printf ("cannot create symbol \"%s\": %s\n", buf, asm_errmsg (-1)); 76441f72d43a9b550baa779fc82f70816da5f74f0eThe Android Open Source Project asm_abort (ctx); 77441f72d43a9b550baa779fc82f70816da5f74f0eThe Android Open Source Project return 1; 78441f72d43a9b550baa779fc82f70816da5f74f0eThe Android Open Source Project } 79441f72d43a9b550baa779fc82f70816da5f74f0eThe Android Open Source Project 80441f72d43a9b550baa779fc82f70816da5f74f0eThe Android Open Source Project /* Add some content. */ 81441f72d43a9b550baa779fc82f70816da5f74f0eThe Android Open Source Project if (asm_adduint32 (scn, cnt) != 0) 82441f72d43a9b550baa779fc82f70816da5f74f0eThe Android Open Source Project { 83441f72d43a9b550baa779fc82f70816da5f74f0eThe Android Open Source Project printf ("cannot create content of section \"%s\": %s\n", 84441f72d43a9b550baa779fc82f70816da5f74f0eThe Android Open Source Project buf, asm_errmsg (-1)); 85441f72d43a9b550baa779fc82f70816da5f74f0eThe Android Open Source Project asm_abort (ctx); 86441f72d43a9b550baa779fc82f70816da5f74f0eThe Android Open Source Project return 1; 87441f72d43a9b550baa779fc82f70816da5f74f0eThe Android Open Source Project } 88441f72d43a9b550baa779fc82f70816da5f74f0eThe Android Open Source Project 89441f72d43a9b550baa779fc82f70816da5f74f0eThe Android Open Source Project /* Now we have a symbol, use it as the signature. */ 90441f72d43a9b550baa779fc82f70816da5f74f0eThe Android Open Source Project if (asm_scngrp_newsignature (grp, sym) != 0) 91441f72d43a9b550baa779fc82f70816da5f74f0eThe Android Open Source Project { 92441f72d43a9b550baa779fc82f70816da5f74f0eThe Android Open Source Project printf ("cannot set signature for section group %Zu: %s\n", 93441f72d43a9b550baa779fc82f70816da5f74f0eThe Android Open Source Project cnt, asm_errmsg (-1)); 94441f72d43a9b550baa779fc82f70816da5f74f0eThe Android Open Source Project asm_abort (ctx); 95441f72d43a9b550baa779fc82f70816da5f74f0eThe Android Open Source Project return 1; 96441f72d43a9b550baa779fc82f70816da5f74f0eThe Android Open Source Project } 97441f72d43a9b550baa779fc82f70816da5f74f0eThe Android Open Source Project 98441f72d43a9b550baa779fc82f70816da5f74f0eThe Android Open Source Project /* Create a phony debug info section. */ 99441f72d43a9b550baa779fc82f70816da5f74f0eThe Android Open Source Project scn = asm_newscn_ingrp (ctx, ".stab", SHT_PROGBITS, 0, grp); 100441f72d43a9b550baa779fc82f70816da5f74f0eThe Android Open Source Project if (scn == NULL) 101441f72d43a9b550baa779fc82f70816da5f74f0eThe Android Open Source Project { 102441f72d43a9b550baa779fc82f70816da5f74f0eThe Android Open Source Project printf ("cannot stab section for group %Zu: %s\n", 103441f72d43a9b550baa779fc82f70816da5f74f0eThe Android Open Source Project cnt, asm_errmsg (-1)); 104441f72d43a9b550baa779fc82f70816da5f74f0eThe Android Open Source Project asm_abort (ctx); 105441f72d43a9b550baa779fc82f70816da5f74f0eThe Android Open Source Project return 1; 106441f72d43a9b550baa779fc82f70816da5f74f0eThe Android Open Source Project } 107441f72d43a9b550baa779fc82f70816da5f74f0eThe Android Open Source Project 108441f72d43a9b550baa779fc82f70816da5f74f0eThe Android Open Source Project /* Add some content. */ 109441f72d43a9b550baa779fc82f70816da5f74f0eThe Android Open Source Project if (asm_adduint32 (scn, cnt) != 0) 110441f72d43a9b550baa779fc82f70816da5f74f0eThe Android Open Source Project { 111441f72d43a9b550baa779fc82f70816da5f74f0eThe Android Open Source Project printf ("cannot create content of section \"%s\": %s\n", 112441f72d43a9b550baa779fc82f70816da5f74f0eThe Android Open Source Project buf, asm_errmsg (-1)); 113441f72d43a9b550baa779fc82f70816da5f74f0eThe Android Open Source Project asm_abort (ctx); 114441f72d43a9b550baa779fc82f70816da5f74f0eThe Android Open Source Project return 1; 115441f72d43a9b550baa779fc82f70816da5f74f0eThe Android Open Source Project } 116441f72d43a9b550baa779fc82f70816da5f74f0eThe Android Open Source Project } 117441f72d43a9b550baa779fc82f70816da5f74f0eThe Android Open Source Project 118441f72d43a9b550baa779fc82f70816da5f74f0eThe Android Open Source Project /* Create the output file. */ 119441f72d43a9b550baa779fc82f70816da5f74f0eThe Android Open Source Project if (asm_end (ctx) != 0) 120441f72d43a9b550baa779fc82f70816da5f74f0eThe Android Open Source Project { 121441f72d43a9b550baa779fc82f70816da5f74f0eThe Android Open Source Project printf ("cannot create output file: %s\n", asm_errmsg (-1)); 122441f72d43a9b550baa779fc82f70816da5f74f0eThe Android Open Source Project asm_abort (ctx); 123441f72d43a9b550baa779fc82f70816da5f74f0eThe Android Open Source Project return 1; 124441f72d43a9b550baa779fc82f70816da5f74f0eThe Android Open Source Project } 125441f72d43a9b550baa779fc82f70816da5f74f0eThe Android Open Source Project 126441f72d43a9b550baa779fc82f70816da5f74f0eThe Android Open Source Project if (result == 0) 127441f72d43a9b550baa779fc82f70816da5f74f0eThe Android Open Source Project result = WEXITSTATUS (system ("\ 128441f72d43a9b550baa779fc82f70816da5f74f0eThe Android Open Source Projectenv LD_LIBRARY_PATH=../libelf ../src/elflint -q asm-tst6-out.o")); 129441f72d43a9b550baa779fc82f70816da5f74f0eThe Android Open Source Project 130441f72d43a9b550baa779fc82f70816da5f74f0eThe Android Open Source Project /* We don't need the file anymore. */ 131441f72d43a9b550baa779fc82f70816da5f74f0eThe Android Open Source Project unlink (fname); 132441f72d43a9b550baa779fc82f70816da5f74f0eThe Android Open Source Project 133441f72d43a9b550baa779fc82f70816da5f74f0eThe Android Open Source Project return result; 134441f72d43a9b550baa779fc82f70816da5f74f0eThe Android Open Source Project} 135