stripalign.c revision 7c478bd95313f5f23a4c958a745db2134aa03244
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (the "License"). You may not use this file except in compliance
* with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 1992-2003 Sun Microsystems, Inc.
* All rights reserved.
* Use is subject to license terms.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
#include <fcntl.h>
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <strings.h>
static Elf32_Ehdr elfhdr;
static int fd;
static char buf[4096];
static long lalignbuf[2];
int
{
int ifd;
int count;
int tot_write = 0;
long lalign;
int lbytes;
int text_written = 0;
int data_written = 0;
if (argc < 3) {
(void) printf("usage: stripalign elf_file a.outfile \n");
exit(1);
}
perror("open input");
exit(1);
}
perror("read elfhdr");
exit(1);
}
perror("open aout");
exit(1);
}
perror("elfmag");
exit(1);
}
perror("lseek");
exit(1);
}
perror("read phdr");
exit(1);
}
perror("read dphdr");
exit(1);
}
perror("write exec");
exit(1);
}
perror("lseek text");
exit(1);
}
/* do text section first */
perror("write text file");
exit(1);
}
text_written += count;
}
perror("lseek data");
exit(1);
}
perror("write data file");
exit(1);
}
data_written += count;
}
/*
* Round file size out to long word boundary.
* If the longword boundary is a multiple of 512 bytes,
* add another longword.
*/
lbytes = 0;
lbytes += sizeof (long);
if (lbytes != 0) {
perror("write (alignment) data file");
exit(1);
}
}
return (0);
}