remove elf2flt

This commit is contained in:
Wolfgang Thaller 2017-10-07 02:08:05 +02:00
parent d464252791
commit 1d95fb6dd9
25 changed files with 0 additions and 16554 deletions

24
elf2flt/.gitignore vendored
View File

@ -1,24 +0,0 @@
# standard patterns
*.a
*.o
*~
*.orig
*.rej
*.patch
.deps
a.out
*.gdb
*.exe
# autotool files
autom4te.cache
config.log
config.status
Makefile
# our generated files
elf2flt
elf2flt.ld
flthdr
ld-elf2flt

Binary file not shown.

View File

@ -1,22 +0,0 @@
/.gitignore/1.2/Tue Jul 7 00:46:52 2009//
/LICENSE.TXT/1.1/Mon Apr 18 22:00:48 2005//
/Makefile.in/1.28/Wed Feb 3 22:32:46 2010/-ko/
/README/1.6/Wed Jan 20 02:28:18 2010/-ko/
/compress.c/1.3/Tue Jul 7 04:39:42 2009//
/compress.h/1.2/Sun Nov 2 23:10:52 2008//
/config.guess/1.2/Mon Jan 5 23:41:50 2004/-ko/
/config.sub/1.8/Wed Jan 11 03:39:16 2006/-ko/
/configure/1.21/Wed Feb 3 22:34:49 2010/-ko/
/configure.in/1.20/Wed Feb 3 22:34:49 2010/-ko/
/cygwin-elf.h/1.4/Wed Jan 11 03:39:16 2006//
/e1-elf2flt.ld/1.1/Tue Nov 11 07:23:04 2003//
/elf2flt.c/1.64/Wed Feb 3 22:32:46 2010/-ko/
/elf2flt.ld.in/1.5/Thu Dec 16 01:37:41 2010//
/flat.h/1.8/Mon Jul 6 04:45:16 2009/-ko/
/flthdr.c/1.17/Tue Jun 22 06:12:47 2010/-ko/
/install-sh/1.1.1.1/Thu Feb 14 01:40:55 2002/-ko/
/ld-elf2flt.c/1.6/Mon Apr 4 01:17:17 2011//
/ld-elf2flt.in/1.23/Sun Jul 12 23:28:58 2009//
/stubs.c/1.4/Sun Jul 12 23:28:58 2009//
/stubs.h/1.3/Fri Jan 22 01:54:20 2010//
D

View File

@ -1 +0,0 @@
elf2flt

View File

@ -1 +0,0 @@
:pserver:anonymous@cvs.uclinux.org:/var/cvs

View File

@ -1,340 +0,0 @@
GNU GENERAL PUBLIC LICENSE
Version 2, June 1991
Copyright (C) 1989, 1991 Free Software Foundation, Inc.
59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
Preamble
The licenses for most software are designed to take away your
freedom to share and change it. By contrast, the GNU General Public
License is intended to guarantee your freedom to share and change free
software--to make sure the software is free for all its users. This
General Public License applies to most of the Free Software
Foundation's software and to any other program whose authors commit to
using it. (Some other Free Software Foundation software is covered by
the GNU Library General Public License instead.) You can apply it to
your programs, too.
When we speak of free software, we are referring to freedom, not
price. Our General Public Licenses are designed to make sure that you
have the freedom to distribute copies of free software (and charge for
this service if you wish), that you receive source code or can get it
if you want it, that you can change the software or use pieces of it
in new free programs; and that you know you can do these things.
To protect your rights, we need to make restrictions that forbid
anyone to deny you these rights or to ask you to surrender the rights.
These restrictions translate to certain responsibilities for you if you
distribute copies of the software, or if you modify it.
For example, if you distribute copies of such a program, whether
gratis or for a fee, you must give the recipients all the rights that
you have. You must make sure that they, too, receive or can get the
source code. And you must show them these terms so they know their
rights.
We protect your rights with two steps: (1) copyright the software, and
(2) offer you this license which gives you legal permission to copy,
distribute and/or modify the software.
Also, for each author's protection and ours, we want to make certain
that everyone understands that there is no warranty for this free
software. If the software is modified by someone else and passed on, we
want its recipients to know that what they have is not the original, so
that any problems introduced by others will not reflect on the original
authors' reputations.
Finally, any free program is threatened constantly by software
patents. We wish to avoid the danger that redistributors of a free
program will individually obtain patent licenses, in effect making the
program proprietary. To prevent this, we have made it clear that any
patent must be licensed for everyone's free use or not licensed at all.
The precise terms and conditions for copying, distribution and
modification follow.
GNU GENERAL PUBLIC LICENSE
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
0. This License applies to any program or other work which contains
a notice placed by the copyright holder saying it may be distributed
under the terms of this General Public License. The "Program", below,
refers to any such program or work, and a "work based on the Program"
means either the Program or any derivative work under copyright law:
that is to say, a work containing the Program or a portion of it,
either verbatim or with modifications and/or translated into another
language. (Hereinafter, translation is included without limitation in
the term "modification".) Each licensee is addressed as "you".
Activities other than copying, distribution and modification are not
covered by this License; they are outside its scope. The act of
running the Program is not restricted, and the output from the Program
is covered only if its contents constitute a work based on the
Program (independent of having been made by running the Program).
Whether that is true depends on what the Program does.
1. You may copy and distribute verbatim copies of the Program's
source code as you receive it, in any medium, provided that you
conspicuously and appropriately publish on each copy an appropriate
copyright notice and disclaimer of warranty; keep intact all the
notices that refer to this License and to the absence of any warranty;
and give any other recipients of the Program a copy of this License
along with the Program.
You may charge a fee for the physical act of transferring a copy, and
you may at your option offer warranty protection in exchange for a fee.
2. You may modify your copy or copies of the Program or any portion
of it, thus forming a work based on the Program, and copy and
distribute such modifications or work under the terms of Section 1
above, provided that you also meet all of these conditions:
a) You must cause the modified files to carry prominent notices
stating that you changed the files and the date of any change.
b) You must cause any work that you distribute or publish, that in
whole or in part contains or is derived from the Program or any
part thereof, to be licensed as a whole at no charge to all third
parties under the terms of this License.
c) If the modified program normally reads commands interactively
when run, you must cause it, when started running for such
interactive use in the most ordinary way, to print or display an
announcement including an appropriate copyright notice and a
notice that there is no warranty (or else, saying that you provide
a warranty) and that users may redistribute the program under
these conditions, and telling the user how to view a copy of this
License. (Exception: if the Program itself is interactive but
does not normally print such an announcement, your work based on
the Program is not required to print an announcement.)
These requirements apply to the modified work as a whole. If
identifiable sections of that work are not derived from the Program,
and can be reasonably considered independent and separate works in
themselves, then this License, and its terms, do not apply to those
sections when you distribute them as separate works. But when you
distribute the same sections as part of a whole which is a work based
on the Program, the distribution of the whole must be on the terms of
this License, whose permissions for other licensees extend to the
entire whole, and thus to each and every part regardless of who wrote it.
Thus, it is not the intent of this section to claim rights or contest
your rights to work written entirely by you; rather, the intent is to
exercise the right to control the distribution of derivative or
collective works based on the Program.
In addition, mere aggregation of another work not based on the Program
with the Program (or with a work based on the Program) on a volume of
a storage or distribution medium does not bring the other work under
the scope of this License.
3. You may copy and distribute the Program (or a work based on it,
under Section 2) in object code or executable form under the terms of
Sections 1 and 2 above provided that you also do one of the following:
a) Accompany it with the complete corresponding machine-readable
source code, which must be distributed under the terms of Sections
1 and 2 above on a medium customarily used for software interchange; or,
b) Accompany it with a written offer, valid for at least three
years, to give any third party, for a charge no more than your
cost of physically performing source distribution, a complete
machine-readable copy of the corresponding source code, to be
distributed under the terms of Sections 1 and 2 above on a medium
customarily used for software interchange; or,
c) Accompany it with the information you received as to the offer
to distribute corresponding source code. (This alternative is
allowed only for noncommercial distribution and only if you
received the program in object code or executable form with such
an offer, in accord with Subsection b above.)
The source code for a work means the preferred form of the work for
making modifications to it. For an executable work, complete source
code means all the source code for all modules it contains, plus any
associated interface definition files, plus the scripts used to
control compilation and installation of the executable. However, as a
special exception, the source code distributed need not include
anything that is normally distributed (in either source or binary
form) with the major components (compiler, kernel, and so on) of the
operating system on which the executable runs, unless that component
itself accompanies the executable.
If distribution of executable or object code is made by offering
access to copy from a designated place, then offering equivalent
access to copy the source code from the same place counts as
distribution of the source code, even though third parties are not
compelled to copy the source along with the object code.
4. You may not copy, modify, sublicense, or distribute the Program
except as expressly provided under this License. Any attempt
otherwise to copy, modify, sublicense or distribute the Program is
void, and will automatically terminate your rights under this License.
However, parties who have received copies, or rights, from you under
this License will not have their licenses terminated so long as such
parties remain in full compliance.
5. You are not required to accept this License, since you have not
signed it. However, nothing else grants you permission to modify or
distribute the Program or its derivative works. These actions are
prohibited by law if you do not accept this License. Therefore, by
modifying or distributing the Program (or any work based on the
Program), you indicate your acceptance of this License to do so, and
all its terms and conditions for copying, distributing or modifying
the Program or works based on it.
6. Each time you redistribute the Program (or any work based on the
Program), the recipient automatically receives a license from the
original licensor to copy, distribute or modify the Program subject to
these terms and conditions. You may not impose any further
restrictions on the recipients' exercise of the rights granted herein.
You are not responsible for enforcing compliance by third parties to
this License.
7. If, as a consequence of a court judgment or allegation of patent
infringement or for any other reason (not limited to patent issues),
conditions are imposed on you (whether by court order, agreement or
otherwise) that contradict the conditions of this License, they do not
excuse you from the conditions of this License. If you cannot
distribute so as to satisfy simultaneously your obligations under this
License and any other pertinent obligations, then as a consequence you
may not distribute the Program at all. For example, if a patent
license would not permit royalty-free redistribution of the Program by
all those who receive copies directly or indirectly through you, then
the only way you could satisfy both it and this License would be to
refrain entirely from distribution of the Program.
If any portion of this section is held invalid or unenforceable under
any particular circumstance, the balance of the section is intended to
apply and the section as a whole is intended to apply in other
circumstances.
It is not the purpose of this section to induce you to infringe any
patents or other property right claims or to contest validity of any
such claims; this section has the sole purpose of protecting the
integrity of the free software distribution system, which is
implemented by public license practices. Many people have made
generous contributions to the wide range of software distributed
through that system in reliance on consistent application of that
system; it is up to the author/donor to decide if he or she is willing
to distribute software through any other system and a licensee cannot
impose that choice.
This section is intended to make thoroughly clear what is believed to
be a consequence of the rest of this License.
8. If the distribution and/or use of the Program is restricted in
certain countries either by patents or by copyrighted interfaces, the
original copyright holder who places the Program under this License
may add an explicit geographical distribution limitation excluding
those countries, so that distribution is permitted only in or among
countries not thus excluded. In such case, this License incorporates
the limitation as if written in the body of this License.
9. The Free Software Foundation may publish revised and/or new versions
of the General Public License from time to time. Such new versions will
be similar in spirit to the present version, but may differ in detail to
address new problems or concerns.
Each version is given a distinguishing version number. If the Program
specifies a version number of this License which applies to it and "any
later version", you have the option of following the terms and conditions
either of that version or of any later version published by the Free
Software Foundation. If the Program does not specify a version number of
this License, you may choose any version ever published by the Free Software
Foundation.
10. If you wish to incorporate parts of the Program into other free
programs whose distribution conditions are different, write to the author
to ask for permission. For software which is copyrighted by the Free
Software Foundation, write to the Free Software Foundation; we sometimes
make exceptions for this. Our decision will be guided by the two goals
of preserving the free status of all derivatives of our free software and
of promoting the sharing and reuse of software generally.
NO WARRANTY
11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
REPAIR OR CORRECTION.
12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
POSSIBILITY OF SUCH DAMAGES.
END OF TERMS AND CONDITIONS
How to Apply These Terms to Your New Programs
If you develop a new program, and you want it to be of the greatest
possible use to the public, the best way to achieve this is to make it
free software which everyone can redistribute and change under these terms.
To do so, attach the following notices to the program. It is safest
to attach them to the start of each source file to most effectively
convey the exclusion of warranty; and each file should have at least
the "copyright" line and a pointer to where the full notice is found.
<one line to give the program's name and a brief idea of what it does.>
Copyright (C) <year> <name of author>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Also add information on how to contact you by electronic and paper mail.
If the program is interactive, make it output a short notice like this
when it starts in an interactive mode:
Gnomovision version 69, Copyright (C) year name of author
Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
This is free software, and you are welcome to redistribute it
under certain conditions; type `show c' for details.
The hypothetical commands `show w' and `show c' should show the appropriate
parts of the General Public License. Of course, the commands you use may
be called something other than `show w' and `show c'; they could even be
mouse-clicks or menu items--whatever suits your program.
You should also get your employer (if you work as a programmer) or your
school, if any, to sign a "copyright disclaimer" for the program, if
necessary. Here is a sample; alter the names:
Yoyodyne, Inc., hereby disclaims all copyright interest in the program
`Gnomovision' (which makes passes at compilers) written by James Hacker.
<signature of Ty Coon>, 1 April 1989
Ty Coon, President of Vice
This General Public License does not permit incorporating your program into
proprietary programs. If your program is a subroutine library, you may
consider it more useful to permit linking proprietary applications with the
library. If this is what you want to do, use the GNU Library General
Public License instead of this License.

View File

@ -1,114 +0,0 @@
srcdir = @srcdir@
VPATH = @srcdir@
prefix = @prefix@
exec_prefix = @exec_prefix@
bindir = @bindir@
libdir = @libdir@
includedir = @includedir@
CC = @CC@
CPU = @target_cpu@
TARGET = @target_alias@
SYMBOL_PREFIX = @SYMBOL_PREFIX@
CFLAGS = @CFLAGS@
INCLUDES = -I$(srcdir) @bfd_include_dir@ @binutils_include_dir@ @zlib_include_dir@
CPPFLAGS = @CPPFLAGS@ $(DEFS) $(INCLUDES)
LDFLAGS = @LDFLAGS@
LDLIBS = @LIBS@
INSTALL = @INSTALL@
DEFS = @DEFS@ \
-DTARGET_$(CPU) \
-DTARGET_CPU=\"$(CPU)\" \
-DSYMBOL_PREFIX=\"$(SYMBOL_PREFIX)\" \
-DBINUTILS_LDSCRIPTDIR=\"@binutils_ldscript_dir@\" \
-DTARGET_ALIAS=\"$(TARGET)\" \
-DNO_GOT_CHECK=@got_check@ \
-DUSE_EMIT_RELOCS=@emit_relocs@ \
-DEMIT_CTOR_DTOR=@emit_ctor_dtor@ \
-DALWAYS_RELOC_TEXT=@always_reloc_text@
EXEEXT = @EXEEXT@
OBJEXT = @OBJEXT@
HOST = @host_alias@
ifneq (,$(findstring mingw32,$(HOST)))
LDLIBS += -lws2_32
endif
# force link order under cygwin to avoid getopts / libiberty clash
ifneq ($(strip $(shell gcc -v 2>&1 | grep "cygwin")),)
LDLIBS := -lcygwin $(LDLIBS)
endif
LDFILE= elf2flt.ld
ifeq ($(strip $(CPU)),e1)
SRC_LDFILE= $(srcdir)/$(CPU)-elf2flt.ld
else
SRC_LDFILE= elf2flt.ld
endif
target_bindir = $(prefix)/$(TARGET)/bin
target_libdir = $(prefix)/$(TARGET)/lib
PROG_ELF2FLT = elf2flt$(EXEEXT)
PROG_FLTHDR = flthdr$(EXEEXT)
PROG_LD_ELF2FLT_C = ld-elf2flt$(EXEEXT)
PROG_LD_ELF2FLT_SH = ld-elf2flt.sh
ifeq (@use_ld_elf2flt_binary@,yes)
PROG_LD_ELF2FLT = $(PROG_LD_ELF2FLT_C)
else
PROG_LD_ELF2FLT = $(PROG_LD_ELF2FLT_SH)
endif
PROGS = $(PROG_ELF2FLT) $(PROG_FLTHDR) $(PROG_LD_ELF2FLT_C) $(PROG_LD_ELF2FLT_SH)
all: $(PROGS)
# We need to declare the link explicitly because make only provides
# implicit rules when EXEEXT is set to nothing
link = $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $^ $(LDLIBS)
$(PROG_ELF2FLT): elf2flt.o compress.o stubs.o
$(link)
$(PROG_FLTHDR): flthdr.o compress.o stubs.o
$(link)
ld-elf2flt$(EXEEXT): ld-elf2flt.o stubs.o
$(link)
ld-elf2flt.sh: $(srcdir)/ld-elf2flt.in
./config.status $@
chmod 755 $@
Makefile: $(srcdir)/Makefile.in
./config.status $@
clean:
-rm -f $(PROGS) *.$(OBJEXT) .deps
distclean: clean
-rm -f Makefile config.log config.status config.cache ld-elf2flt
install:
$(INSTALL) -d $(bindir)
$(INSTALL) -d $(target_bindir)
$(INSTALL) -d $(target_libdir)
$(INSTALL) -m 755 $(PROG_FLTHDR) $(bindir)/$(TARGET)-$(PROG_FLTHDR)
$(INSTALL) -m 755 $(PROG_FLTHDR) $(target_bindir)/$(PROG_FLTHDR)
$(INSTALL) -m 755 $(PROG_ELF2FLT) $(bindir)/$(TARGET)-$(PROG_ELF2FLT)
$(INSTALL) -m 755 $(PROG_ELF2FLT) $(target_bindir)/$(PROG_ELF2FLT)
[ -f $(bindir)/$(TARGET)-ld.real$(EXEEXT) ] || \
mv $(bindir)/$(TARGET)-ld$(EXEEXT) $(bindir)/$(TARGET)-ld.real$(EXEEXT)
[ -f $(target_bindir)/ld.real$(EXEEXT) ] || \
mv $(target_bindir)/ld$(EXEEXT) $(target_bindir)/ld.real$(EXEEXT)
$(INSTALL) -m 755 $(PROG_LD_ELF2FLT) $(bindir)/$(TARGET)-ld$(EXEEXT)
$(INSTALL) -m 755 $(PROG_LD_ELF2FLT) $(target_bindir)/ld$(EXEEXT)
$(INSTALL) -m 644 $(SRC_LDFILE) $(target_libdir)/$(LDFILE)
sinclude .deps
.deps:
$(CC) -MM $(CPPFLAGS) $(srcdir)/*.c > .deps

View File

@ -1,62 +0,0 @@
README - elf2flt
----------------
Copyright (C) 2001-2003, SnapGear (www.snapgear.com)
davidm@snapgear.com
gerg@snapgear.com
This is Free Software, under the GNU Public Licence v2 or greater. See
LICENSE.TXT for more details.
Elf2flt with PIC, ZFLAT and full reloc support. Currently supported
targets include: m68k/ColdFire, ARM, Sparc, NEC v850, MicroBlaze,
h8300, SuperH, and Blackfin.
COMPILING:
You need an appropriate libbfd.a and libiberty.a for your target to
build this tool. They are normally part of the binutils package.
To compile elf2flt do:
./configure --target=<ARCH> --with-libbfd=<libbfd.a> --with-libiberty=<libiberty.a>
make
make install
The <ARCH> argument to configure specifies what the target architecture is.
This should be the same target as you used to build the binutils and gcc
cross development tools. The --with-libbfd and --with-libiberty arguments
specify where the libbfd.a and libiberty.a library files are to use.
FILES:
README - this file
configure - autoconf configuration shell script
configure.in- original autoconf file
config.* - autoconf support scripts
Makefile.in - Makefile template used by configure
elf2flt.c - the source
flthdr.c - flat header manipulation program
flat.h - header from uClinux kernel sources
elf2flt.ld - an example linker script that works for C/C++ and uClinux
ld-elf2flt - A linker replacement that implements a -elf2flt option for the
linker and runs elf2flt automatically for you. It auto
detects PIC/non-PIC code and adjusts its option accordingly.
It uses the environment variable FLTFLAGS when running
elf2flt. It runs /.../m68k-elf-ld.real to do the actual
linking.
TIPS:
The ld-elf2flt produces 2 files as output. The binary flat file X, and
X.gdb which is used for debugging and PIC purposes.
The '-p' option requires an elf executable linked at address 0. The
elf2flt.ld provided will generate the correct format binary when linked
with the real linker with *no* '-r' option for the linker.
The '-r' flag can be added to PIC builds to get contiguous code/data. This
is good for loading application symbols into gdb (add-symbol-file XXX.gdb).

View File

@ -1,198 +0,0 @@
/*
* Helper functions to handle compression via zlib
*
* Copyright (C) 2007-2008 Julian Brown
* Copyright (C) 2008 Mike Frysinger
*
* Licensed under the GPL-2 or later.
*/
#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
#include <zlib.h>
#include "compress.h"
#include "stubs.h"
/* Open an (uncompressed) file as a stream. Return 0 on success, 1 on
error.
NOTE: The MODE argument must remain valid for the lifetime of the stream,
because it is referred to by reopen_stream_compressed() if it is called.
String constants work fine. */
int
fopen_stream_u(stream *fp, const char *path, const char *mode)
{
fp->u.filep = fopen(path, mode);
fp->type = (fp->u.filep) ? UNCOMPRESSED : INVALID;
fp->mode = mode;
return (fp->u.filep) ? 0 : 1;
}
/* Read from stream. Return number of elements read. */
size_t
fread_stream(void *ptr, size_t size, size_t nmemb, stream *str)
{
size_t read;
switch (str->type) {
case UNCOMPRESSED:
read = fread(ptr, size, nmemb, str->u.filep);
break;
case COMPRESSED:
read = gzread(str->u.gzfilep, ptr, size * nmemb) / size;
break;
default:
abort();
}
return read;
}
/* Write to stream. Return number of elements written. */
size_t
fwrite_stream(const void *ptr, size_t size, size_t nmemb, stream *str)
{
size_t written;
switch (str->type) {
case UNCOMPRESSED:
written = fwrite(ptr, size, nmemb, str->u.filep);
break;
case COMPRESSED:
written = gzwrite(str->u.gzfilep, ptr, size * nmemb) / size;
break;
default:
abort();
}
return written;
}
/* Close stream. */
int
fclose_stream(stream *str)
{
switch (str->type) {
case UNCOMPRESSED:
return fclose(str->u.filep);
case COMPRESSED:
return gzclose(str->u.gzfilep);
default:
abort();
}
return 0;
}
int
ferror_stream(stream *str)
{
switch (str->type) {
case UNCOMPRESSED:
return ferror(str->u.filep);
case COMPRESSED:
{
const char *err;
int errno;
err = gzerror(str->u.gzfilep, &errno);
if (errno == Z_OK || errno == Z_STREAM_END)
return 0;
else if (errno == Z_ERRNO)
return 1;
else {
fprintf(stderr, "%s\n", err);
return 1;
}
}
break;
default:
abort();
}
return 0;
}
int
fseek_stream(stream *str, long offset, int whence)
{
switch (str->type) {
case UNCOMPRESSED:
return fseek(str->u.filep, offset, whence);
case COMPRESSED:
return gzseek(str->u.gzfilep, offset, whence);
default:
abort();
}
}
/* Reopen a stream at the current file position. */
void
reopen_stream_compressed(stream *str)
{
int fd;
long offset, roffset;
/* Already a compressed stream, return immediately */
if (str->type == COMPRESSED)
return;
if (str->type == INVALID)
abort();
fd = fileno(str->u.filep);
/* Get current (buffered) file position. */
offset = ftell(str->u.filep);
/* Make sure there's nothing left in buffers. */
fflush(str->u.filep);
/* Reposition underlying FD. (Might be unnecessary?) */
roffset = lseek(fd, offset, SEEK_SET);
assert(roffset == offset);
/* Reopen as compressed stream. */
str->u.gzfilep = gzdopen(fd, str->mode);
gzsetparams(str->u.gzfilep, 9, Z_DEFAULT_STRATEGY);
str->type = COMPRESSED;
}
void
transfer(stream *ifp, stream *ofp, int count)
{
char cmd[1024];
int n, num;
while (count == -1 || count > 0) {
if (count == -1 || count > sizeof(cmd))
num = sizeof(cmd);
else
num = count;
n = fread_stream(cmd, 1, num, ifp);
if (n == 0)
break;
if (fwrite_stream(cmd, n, 1, ofp) != 1)
fatal_perror("Write failed :-(\n");
if (count != -1)
count -= n;
}
if (count > 0)
fatal("Failed to transfer %d bytes\n", count);
}

View File

@ -1,44 +0,0 @@
/*
* Helper functions to handle compression via zlib
*
* Copyright (C) 2007-2008 Julian Brown
* Copyright (C) 2008 Mike Frysinger
*
* Licensed under the GPL-2 or later.
*/
#ifndef __ELF2FLT_COMPRESS_H__
#define __ELF2FLT_COMPRESS_H__
#include <zlib.h>
typedef enum
{
INVALID,
UNCOMPRESSED,
COMPRESSED
} stream_type;
/* Tagged union holding either a regular FILE* handle or a zlib gzFile
handle. */
typedef struct
{
stream_type type;
const char *mode;
union
{
FILE *filep;
gzFile gzfilep;
} u;
} stream;
int fopen_stream_u(stream *fp, const char *path, const char *mode);
size_t fread_stream(void *ptr, size_t size, size_t nmemb, stream *str);
size_t fwrite_stream(const void *ptr, size_t size, size_t nmemb, stream *str);
int fclose_stream(stream *str);
int ferror_stream(stream *str);
int fseek_stream(stream *str, long offset, int whence);
void reopen_stream_compressed(stream *str);
void transfer(stream *ifp, stream *ofp, int count);
#endif

1418
elf2flt/config.guess vendored

File diff suppressed because it is too large Load Diff

1577
elf2flt/config.sub vendored

File diff suppressed because it is too large Load Diff

6277
elf2flt/configure vendored

File diff suppressed because it is too large Load Diff

View File

@ -1,226 +0,0 @@
dnl Process this file with autoconf to produce a configure script.
AC_INIT(elf2flt.c)
AC_ARG_WITH(zlib-prefix,
AS_HELP_STRING([--with-zlib-prefix=<dir>], [path to installed zlib]),
[ ac_zlib_prefix=$withval ],
[ ac_zlib_prefix=NONE ]
)
AC_ARG_WITH(libbfd,
AS_HELP_STRING([--with-libbfd=<file>], [path to libbfd.a library to use]),
[ ac_libbfd=$withval ],
[ ac_libbfd=NONE ]
)
AC_ARG_WITH(libiberty,
AS_HELP_STRING([--with-libiberty=<file>], [path to libiberty.a library to use]),
[ ac_libiberty=$withval ],
[ ac_libiberty=NONE ]
)
AC_ARG_WITH(bfd-include-dir,
AS_HELP_STRING([--with-bfd-include-dir=<dir>], [include path for correct bfd.h]),
[ ac_bfd_include_dir=$withval ],
[ ac_bfd_include_dir=NONE ]
)
AC_ARG_WITH(binutils-include-dir,
AS_HELP_STRING([--with-binutils-include-dir=<dir>], [include path for binutils headers]),
[ ac_binutils_include_dir=$withval ],
[ ac_binutils_include_dir=NONE ]
)
AC_ARG_WITH(binutils-ldscript-dir,
AS_HELP_STRING([--with-binutils-ldscript-dir=<dir>], [path to install elf2flt.ld]),
[ ac_binutils_ldscript_dir=$withval ],
[ ac_binutils_ldscript_dir=NONE ]
)
AC_ARG_WITH(binutils-build-dir,
AS_HELP_STRING([--with-binutils-build-dir=<dir>], [path to compiled binutils tree]),
[ ac_binutils_build_dir=$withval ],
[ ac_binutils_build_dir=NONE ]
)
AC_ARG_ENABLE(ld-elf2flt-binary,
AS_HELP_STRING([--disable-ld-elf2flt-binary], [use ld-elf2flt shell script]),
[ use_ld_elf2flt_binary=$enableval ],
[ use_ld_elf2flt_binary=yes ]
)
dnl convert a yes/no variable to 1/0 for C code
var_yn_to_10() {
if eval test \"\$$1\" = yes ; then
eval $1=1
else
eval $1=0
fi
}
AC_ARG_ENABLE(got-check,
AS_HELP_STRING([--disable-got-check], [disable check for GOT (needed on H8)]),
[ got_check=$enableval ],
[ got_check=yes ]
)
var_yn_to_10 got_check
AC_ARG_ENABLE(emit-relocs,
AS_HELP_STRING([--disable-emit-relocs], [don't use the --emit-relocs (-q) linker option]),
[ emit_relocs=$enableval ],
[ emit_relocs=yes ]
)
var_yn_to_10 emit_relocs
AC_ARG_ENABLE(emit-ctor-dtor,
AS_HELP_STRING([--enable-emit-ctor-dtor], [manually create ctor/dtor list]),
[ emit_ctor_dtor=$enableval ],
[ emit_ctor_dtor=no ]
)
var_yn_to_10 emit_ctor_dtor
AC_ARG_ENABLE(always-reloc-text,
AS_HELP_STRING([--enable-always-reloc-text], [always process text relocs ignoring pic/got (needed on Blackfin)]),
[ always_reloc_text=$enableval ],
[
case $target in
bfin*) always_reloc_text=yes;;
*) always_reloc_text=no;;
esac
]
)
var_yn_to_10 always_reloc_text
AC_CANONICAL_HOST
AC_CANONICAL_TARGET
dnl Checks for programs.
AC_PROG_CC
AC_USE_SYSTEM_EXTENSIONS
AC_PROG_INSTALL
if test "$ac_binutils_build_dir" != "NONE"; then
test "$ac_libbfd" = "NONE" && ac_libbfd="$ac_binutils_build_dir/bfd/libbfd.a"
test "$ac_libiberty" = "NONE" && ac_libiberty="$ac_binutils_build_dir/libiberty/libiberty.a"
test "$ac_bfd_include_dir" = "NONE" && ac_bfd_include_dir="$ac_binutils_build_dir/bfd"
test "$ac_binutils_include_dir" = "NONE" && ac_binutils_include_dir="$ac_binutils_build_dir/include"
fi
dnl Checks for libraries.
if test "$ac_libiberty" = "NONE"; then
AC_CHECK_LIB(iberty, objalloc_create)
ac_libiberty=auto
else
LIBS="$ac_libiberty $LIBS"
fi
if test "$ac_libbfd" = "NONE"; then
AC_CHECK_LIB(bfd, bfd_openr)
ac_libbfd=auto
else
LIBS="$ac_libbfd $LIBS"
fi
if test "$ac_zlib_prefix" = "NONE"; then
AC_CHECK_LIB(z, deflate)
else
LIBS="-L$ac_zlib_prefix/lib -lz $LIBS"
fi
bfd_include_dir=
if test "$ac_bfd_include_dir" != "NONE"; then
bfd_include_dir="-I$ac_bfd_include_dir"
fi
binutils_include_dir=
if test "$ac_binutils_include_dir" != "NONE"; then
binutils_include_dir="-I$ac_binutils_include_dir"
fi
zlib_include_dir=
if test "$ac_zlib_prefix" != "NONE"; then
zlib_include_dir="-I$ac_zlib_prefix/include"
fi
binutils_ldscript_dir=
if test "$ac_binutils_ldscript_dir" = "NONE"; then
ac_binutils_ldscript_dir="\${TOOLDIR}/../${target_alias}/lib"
fi
binutils_ldscript_dir="$ac_binutils_ldscript_dir"
if test "$ac_libbfd" = "NONE" -o "$ac_libiberty" = "NONE" ; then
AC_MSG_ERROR([
You need to specify the location of the libfd.a and libiberty.a
host libraries from the binutils package.
Run configure again specifying these options:
./configure --target=<ARCH> --with-bfd-include-dir=<dir> --with-libbfd=<libbfd.a> --with-libiberty=<libiberty.a>
])
fi
if test "$ac_bfd_include_dir" = "NONE" ; then
AC_MSG_ERROR([
You need to specify the location of the bfd.h header from a
configured/compiled version of the binutils package for your target.
Without this your elf2flt may crash as it will try to use the
systems bfd.h which may be from a different binutils package.
Run configure again specifying these options:
./configure --target=<ARCH> --with-bfd-include-dir=<dir> --with-libbfd=<libbfd.a> --with-libiberty=<libiberty.a>
])
fi
SYMBOL_PREFIX=
case $target in
h8300|bfin*)
SYMBOL_PREFIX=_
;;
esac
dnl Make sure we resolve system symbols before libiberty/libbfd ones.
dnl Otherwise, things like getopt get screwed up because the system headers
dnl redirect some functions to the system symbols, but other local symbols
dnl come from libiberty/libbfd.
dnl int getopt(int, char * const [], const char *) __asm("_" "getopt" "$UNIX2003");
AC_CHECK_LIB(c, malloc, LIBS="-lc $LIBS")
dnl Checks for header files.
AC_HEADER_STDC
AC_CHECK_HEADERS(fcntl.h unistd.h bfd.h)
dnl Checks for typedefs, structures, and compiler characteristics.
AC_C_CONST
dnl Checks for library functions.
AC_FUNC_VPRINTF
AC_CHECK_FUNCS([ \
dcgettext \
getline \
libintl_dgettext \
strsignal \
])
test "$GCC" = yes && CFLAGS="-Wall $CFLAGS"
dnl Subsitute values
AC_SUBST(target)
AC_SUBST(target_alias)
AC_SUBST(target_cpu)
AC_SUBST(target_os)
AC_SUBST(target_vendor)
AC_SUBST(bfd_include_dir)
AC_SUBST(binutils_include_dir)
AC_SUBST(zlib_include_dir)
AC_SUBST(binutils_ldscript_dir)
AC_SUBST(use_ld_elf2flt_binary)
AC_SUBST(got_check)
AC_SUBST(emit_relocs)
AC_SUBST(emit_ctor_dtor)
AC_SUBST(always_reloc_text)
AC_SUBST(SYMBOL_PREFIX)
AC_OUTPUT(ld-elf2flt.sh:ld-elf2flt.in Makefile elf2flt.ld)

File diff suppressed because it is too large Load Diff

View File

@ -1,161 +0,0 @@
ENTRY (__start)
MEMORY {
flatmem : ORIGIN = 0x0, LENGTH = 0xfffffff
}
SECTIONS {
.G6 (DEFINED(G6Base) ? G6Base : 0x0) : {
*(.G6)
}
.G7 (DEFINED(G7Base) ? G7Base : 0x0) : {
*(.G7)
}
.G8 (DEFINED(G8Base) ? G8Base : 0x0) : {
*(.G8)
}
.G9 (DEFINED(G9Base) ? G9Base : 0) : {
*(.G9)
}
.G10 (DEFINED(G10Base) ? G10Base : 0) : {
*(.G10)
}
.G11 (DEFINED(G11Base) ? G11Base : 0) : {
*(.G11)
}
.G12 (DEFINED(G12Base) ? G12Base : 0) : {
*(.G12)
}
.G13 (DEFINED(G13Base) ? G13Base : 0) : {
*(.G13)
}
.text 0x0 : {
. = . + 4;
. = ALIGN(0x4) ;
_stext = . ;
*(.text)
*(.text.*)
*(.gnu.warning)
*(.stub)
*(.gnu.linkonce.t*)
*(.glue_7t)
*(.glue_7)
*(.jcr)
*(.init)
*(.fini)
W_RODAT *(.rodata)
W_RODAT *(.rodata1)
W_RODAT *(.rodata.*)
/* This is special code area at the end of the normal
text section. It contains a small lookup table at
the start followed by the code pointed to by entries
in the lookup table. */
. = ALIGN (4) ;
PROVIDE(__ctbp = .);
*(.call_table_data)
*(.call_table_text)
. = ALIGN(0x20) ;
_etext = . ;
} > flatmem
.data : {
. = ALIGN(0x4) ;
_sdata = . ;
__data_start = . ;
data_start = . ;
*(.got.plt)
*(.got)
FILL(0) ;
. = ALIGN(0x20) ;
LONG(-1)
. = ALIGN(0x20) ;
R_RODAT *(.rodata)
R_RODAT *(.rodata1)
R_RODAT *(.rodata.*)
*(.gnu.linkonce.r*)
*(.data)
*(.data1)
*(.data.*)
*(.gnu.linkonce.d*)
*(.data1)
*(.eh_frame)
*(.gcc_except_table)
/* Microblaze has .sdata and .sbss (small bss). They must
be contiguous, so please don't move any of this. JW */
_ssrw = . ;
*(.sdata)
*(.sdata.*)
*(.sbss) /* Don't move this! */
_essrw = . ;
_ssrw_size = _essrw - _ssrw;
PROVIDE(_SDA_BASE_ = _ssrw + (_ssrw_size / 2));
*(.gnu.linkonce.s.*)
*(__libc_atexit)
*(__libc_subinit)
*(__libc_subfreeres)
*(.note.ABI-tag)
/* microblaze-specific read-only small data area
and associated locating symbols */
_ssro = . ;
*(.sdata2)
_essro = . ;
_ssro_size = _essro - _ssro;
PROVIDE(_SDA2_BASE_ = _ssro + (_ssro_size / 2));
. = ALIGN(4) ;
__CTOR_LIST__ = .;
LONG((__CTOR_END__ - __CTOR_LIST__) / 4 - 2)
*(.ctors)
LONG(0)
__CTOR_END__ = .;
__DTOR_LIST__ = .;
LONG((__DTOR_END__ - __DTOR_LIST__) / 4 - 2)
*(.dtors)
LONG(0)
__DTOR_END__ = .;
. = ALIGN(0x10) ;
_edata = . ;
} > flatmem
.bss : {
. = ALIGN(0x4) ;
_sbss = ALIGN(0x4) ;
__bss_start = . ;
*(.dynsbss)
*(.sbss)
*(.sbss.*)
*(.scommon)
*(.dynbss)
*(.bss)
*(.bss.*)
*(.bss*)
*(.gnu.linkonce.b*)
*(COMMON)
. = ALIGN(0x10) ;
_ebss = . ;
_end = . ;
end = . ;
} > flatmem
.junk 0 : { *(.rel*) *(.rela*) }
/* Stabs debugging sections. */
.stab 0 : { *(.stab) }
.stabstr 0 : { *(.stabstr) }
.stab.excl 0 : { *(.stab.excl) }
.stab.exclstr 0 : { *(.stab.exclstr) }
.stab.index 0 : { *(.stab.index) }
.stab.indexstr 0 : { *(.stab.indexstr) }
.comment 0 : { *(.comment) }
.debug_abbrev 0 : { *(.debug_abbrev) }
.debug_info 0 : { *(.debug_info) }
.debug_line 0 : { *(.debug_line) }
.debug_pubnames 0 : { *(.debug_pubnames) }
.debug_aranges 0 : { *(.debug_aranges) }
}

File diff suppressed because it is too large Load Diff

View File

@ -1,210 +0,0 @@
ENTRY (@SYMBOL_PREFIX@_start)
MEMORY {
flatmem : ORIGIN = 0x0, LENGTH = 0xfffffff
}
PHDRS {
text PT_LOAD ;
data PT_LOAD ;
}
SECTIONS {
.text 0x0 : {
. = . + 4;
. = ALIGN(0x4) ;
@SYMBOL_PREFIX@_stext = . ;
*(.text)
*(.text.*)
*(.gnu.warning)
*(.stub)
*(.gnu.linkonce.t*)
*(.glue_7t)
*(.glue_7)
*(.jcr)
KEEP (*(.init))
KEEP (*(.fini))
W_RODAT *(.rodata)
W_RODAT *(.rodata1)
W_RODAT *(.rodata.*)
W_RODAT *(.gnu.linkonce.r*)
/* This is special code area at the end of the normal
text section. It contains a small lookup table at
the start followed by the code pointed to by entries
in the lookup table. */
. = ALIGN (4) ;
PROVIDE(@SYMBOL_PREFIX@__ctbp = .);
*(.call_table_data)
*(.call_table_text)
. = ALIGN(0x20) ;
@SYMBOL_PREFIX@_etext = . ;
} > flatmem :text
.data : {
. = ALIGN(0x4) ;
@SYMBOL_PREFIX@_sdata = . ;
@SYMBOL_PREFIX@__data_start = . ;
@SYMBOL_PREFIX@data_start = . ;
*(.got.plt)
*(.got)
FILL(0) ;
. = ALIGN(0x20) ;
LONG(-1)
. = ALIGN(0x20) ;
R_RODAT *(.rodata)
R_RODAT *(.rodata1)
R_RODAT *(.rodata.*)
R_RODAT *(.gnu.linkonce.r*)
*(.data)
*(.data1)
*(.data.*)
*(.gnu.linkonce.d*)
/* Microblaze has .sdata and .sbss (small bss). They must
be contiguous, so please don't move any of this. JW */
@SYMBOL_PREFIX@_ssrw = . ;
*(.sdata)
*(.sdata.*)
*(.sbss) /* Don't move this! */
*(.gnu.linkonce.sb*)
@SYMBOL_PREFIX@_essrw = . ;
@SYMBOL_PREFIX@_ssrw_size = @SYMBOL_PREFIX@_essrw - @SYMBOL_PREFIX@_ssrw;
PROVIDE(@SYMBOL_PREFIX@_SDA_BASE_ = @SYMBOL_PREFIX@_ssrw + (@SYMBOL_PREFIX@_ssrw_size / 2));
*(.gnu.linkonce.s.*)
*(__libc_atexit)
*(__libc_subinit)
*(__libc_subfreeres)
/* microblaze-specific read-only small data area
and associated locating symbols */
@SYMBOL_PREFIX@_ssro = . ;
*(.sdata2)
@SYMBOL_PREFIX@_essro = . ;
@SYMBOL_PREFIX@_ssro_size = @SYMBOL_PREFIX@_essro - @SYMBOL_PREFIX@_ssro;
PROVIDE(@SYMBOL_PREFIX@_SDA2_BASE_ = @SYMBOL_PREFIX@_ssro + (@SYMBOL_PREFIX@_ssro_size / 2));
. = ALIGN(4) ;
TOR: @SYMBOL_PREFIX@__CTOR_LIST__ = .;
TOR: LONG((@SYMBOL_PREFIX@__CTOR_END__ - @SYMBOL_PREFIX@__CTOR_LIST__) / 4 - 2)
SINGLE_LINK: /* gcc uses crtbegin.o to find the start of
SINGLE_LINK: the constructors, so we make sure it is
SINGLE_LINK: first. Because this is a wildcard, it
SINGLE_LINK: doesn't matter if the user does not
SINGLE_LINK: actually link against crtbegin.o; the
SINGLE_LINK: linker won't look for a file to match a
SINGLE_LINK: wildcard. The wildcard also means that it
SINGLE_LINK: doesn't matter which directory crtbegin.o
SINGLE_LINK: is in. */
SINGLE_LINK: KEEP (*crtbegin*.o(.ctors))
SINGLE_LINK: /* We don't want to include the .ctor section from
SINGLE_LINK: from the crtend.o file until after the sorted ctors.
SINGLE_LINK: The .ctor section from the crtend file contains the
SINGLE_LINK: end of ctors marker and it must be last */
SINGLE_LINK: KEEP (*(EXCLUDE_FILE (*crtend*.o ) .ctors))
SINGLE_LINK: KEEP (*(SORT(.ctors.*)))
KEEP (*(.ctors))
TOR: LONG(0)
TOR: @SYMBOL_PREFIX@__CTOR_END__ = .;
TOR: @SYMBOL_PREFIX@__DTOR_LIST__ = .;
TOR: LONG((@SYMBOL_PREFIX@__DTOR_END__ - @SYMBOL_PREFIX@__DTOR_LIST__) / 4 - 2)
SINGLE_LINK: KEEP (*crtbegin*.o(.dtors))
SINGLE_LINK: KEEP (*(EXCLUDE_FILE (*crtend*.o ) .dtors))
SINGLE_LINK: KEEP (*(SORT(.dtors.*)))
KEEP (*(.dtors))
TOR: LONG(0)
TOR: @SYMBOL_PREFIX@__DTOR_END__ = .;
PROVIDE (@SYMBOL_PREFIX@__preinit_array_start = .);
KEEP (*(.preinit_array))
PROVIDE (@SYMBOL_PREFIX@__preinit_array_end = .);
PROVIDE (@SYMBOL_PREFIX@__init_array_start = .);
KEEP (*(SORT(.init_array.*)))
KEEP (*(.init_array))
PROVIDE (@SYMBOL_PREFIX@__init_array_end = .);
PROVIDE (@SYMBOL_PREFIX@__fini_array_start = .);
KEEP (*(.fini_array))
KEEP (*(SORT(.fini_array.*)))
PROVIDE (@SYMBOL_PREFIX@__fini_array_end = .);
} > flatmem :data
.note.ABI-tag : { *(.note.ABI-tag) } > flatmem
.eh_frame_hdr : { *(.eh_frame_hdr) } > flatmem
.eh_frame : { KEEP(*(.eh_frame)) } > flatmem
.gcc_except_table : {
KEEP(*(.gcc_except_table))
KEEP(*(.gcc_except_table.*))
} >flatmem
. = ALIGN(0x10) ;
@SYMBOL_PREFIX@_edata = . ;
.bss : {
. = ALIGN(0x4) ;
@SYMBOL_PREFIX@_sbss = ALIGN(0x4) ;
@SYMBOL_PREFIX@__bss_start = . ;
*(.dynsbss)
*(.sbss)
*(.sbss.*)
*(.scommon)
*(.dynbss)
*(.bss)
*(.bss.*)
*(.bss*)
*(.gnu.linkonce.b*)
*(COMMON)
. = ALIGN(0x10) ;
@SYMBOL_PREFIX@_ebss = . ;
@SYMBOL_PREFIX@_end = . ;
@SYMBOL_PREFIX@end = . ;
} > flatmem
.stack : {
. = ALIGN(0x4);
@SYMBOL_PREFIX@_stack_start = .;
}
.junk 0 : { *(.rel*) *(.rela*) }
/DISCARD/ : { *(.note.GNU-stack) }
/* Stabs debugging sections. */
.stab 0 : { *(.stab) }
.stabstr 0 : { *(.stabstr) }
.stab.excl 0 : { *(.stab.excl) }
.stab.exclstr 0 : { *(.stab.exclstr) }
.stab.index 0 : { *(.stab.index) }
.stab.indexstr 0 : { *(.stab.indexstr) }
.comment 0 : { *(.comment) }
/* DWARF debug sections.
Symbols in the DWARF debugging sections are relative to the beginning
of the section so we begin them at 0. */
/* DWARF 1 */
.debug 0 : { *(.debug) }
.line 0 : { *(.line) }
/* GNU DWARF 1 extensions */
.debug_srcinfo 0 : { *(.debug_srcinfo) }
.debug_sfnames 0 : { *(.debug_sfnames) }
/* DWARF 1.1 and DWARF 2 */
.debug_aranges 0 : { *(.debug_aranges) }
.debug_pubnames 0 : { *(.debug_pubnames) }
/* DWARF 2 */
.debug_info 0 : { *(.debug_info .gnu.linkonce.wi.*) }
.debug_abbrev 0 : { *(.debug_abbrev) }
.debug_line 0 : { *(.debug_line) }
.debug_frame 0 : { *(.debug_frame) }
.debug_str 0 : { *(.debug_str) }
.debug_loc 0 : { *(.debug_loc) }
.debug_macinfo 0 : { *(.debug_macinfo) }
/* SGI/MIPS DWARF 2 extensions */
.debug_weaknames 0 : { *(.debug_weaknames) }
.debug_funcnames 0 : { *(.debug_funcnames) }
.debug_typenames 0 : { *(.debug_typenames) }
.debug_varnames 0 : { *(.debug_varnames) }
}

View File

@ -1,113 +0,0 @@
/*
* Copyright (C) 2002-2005 David McCullough <davidm@snapgear.com>
* Copyright (C) 1998 Kenneth Albanowski <kjahds@kjahds.com>
* The Silver Hammer Group, Ltd.
*
* This file provides the definitions and structures needed to
* support uClinux flat-format executables.
*
* This is Free Software, under the GNU Public Licence v2 or greater.
*
*/
#ifndef _LINUX_FLAT_H
#define _LINUX_FLAT_H
#ifdef __KERNEL__
#include <linux/types.h>
#include <asm/flat.h>
#endif
#include <stdint.h>
#define FLAT_VERSION 0x00000004L
#ifdef CONFIG_BINFMT_SHARED_FLAT
#define MAX_SHARED_LIBS (4)
#else
#define MAX_SHARED_LIBS (1)
#endif
/*
* To make everything easier to port and manage cross platform
* development, all fields are in network byte order.
*/
struct flat_hdr {
char magic[4];
uint32_t rev; /* version (as above) */
uint32_t entry; /* Offset of first executable instruction
with text segment from beginning of file */
uint32_t data_start; /* Offset of data segment from beginning of
file */
uint32_t data_end; /* Offset of end of data segment from beginning
of file */
uint32_t bss_end; /* Offset of end of bss segment from beginning
of file */
/* (It is assumed that data_end through bss_end forms the bss segment.) */
uint32_t stack_size; /* Size of stack, in bytes */
uint32_t reloc_start; /* Offset of relocation records from beginning
of file */
uint32_t reloc_count; /* Number of relocation records */
uint32_t flags;
uint32_t build_date; /* When the program/library was built */
uint32_t filler[5]; /* Reservered, set to zero */
};
#define FLAT_FLAG_RAM 0x0001 /* load program entirely into RAM */
#define FLAT_FLAG_GOTPIC 0x0002 /* program is PIC with GOT */
#define FLAT_FLAG_GZIP 0x0004 /* all but the header is compressed */
#define FLAT_FLAG_GZDATA 0x0008 /* only data/relocs are compressed (for XIP) */
#define FLAT_FLAG_KTRACE 0x0010 /* output useful kernel trace for debugging */
#define FLAT_FLAG_L1STK 0x0020 /* use a 4k stack in L1 scratch memory. */
#ifdef __KERNEL__ /* so systems without linux headers can compile the apps */
/*
* While it would be nice to keep this header clean, users of older
* tools still need this support in the kernel. So this section is
* purely for compatibility with old tool chains.
*
* DO NOT make changes or enhancements to the old format please, just work
* with the format above, except to fix bugs with old format support.
*/
#include <asm/byteorder.h>
#define OLD_FLAT_VERSION 0x00000002L
#define OLD_FLAT_RELOC_TYPE_TEXT 0
#define OLD_FLAT_RELOC_TYPE_DATA 1
#define OLD_FLAT_RELOC_TYPE_BSS 2
typedef union {
uint32_t value;
struct {
# if defined(mc68000) && !defined(CONFIG_COLDFIRE)
int32_t offset : 30;
uint32_t type : 2;
# define OLD_FLAT_FLAG_RAM 0x1 /* load program entirely into RAM */
# elif defined(__BIG_ENDIAN_BITFIELD)
uint32_t type : 2;
int32_t offset : 30;
# define OLD_FLAT_FLAG_RAM 0x1 /* load program entirely into RAM */
# elif defined(__LITTLE_ENDIAN_BITFIELD)
int32_t offset : 30;
uint32_t type : 2;
# define OLD_FLAT_FLAG_RAM 0x1 /* load program entirely into RAM */
# else
# error "Unknown bitfield order for flat files."
# endif
} reloc;
} flat_v2_reloc_t;
#endif /* __KERNEL__ */
#endif /* _LINUX_FLAT_H */
/* this __MUST__ be at the VERY end of the file - do NOT move!!
* Local Variables:
* c-basic-offset: 4
* tab-width: 8
* end:
* vi: tabstop=8 shiftwidth=4 textwidth=79 noexpandtab
*/

View File

@ -1,380 +0,0 @@
/****************************************************************************/
/*
* A simple program to manipulate flat files
*
* Copyright (C) 2001-2003 SnapGear Inc, davidm@snapgear.com
* Copyright (C) 2001 Lineo, davidm@lineo.com
*
* This is Free Software, under the GNU Public Licence v2 or greater.
*
*/
/****************************************************************************/
#include <stdio.h> /* Userland pieces of the ANSI C standard I/O package */
#include <unistd.h> /* Userland prototypes of the Unix std system calls */
#include <time.h>
#include <stdlib.h> /* exit() */
#include <string.h> /* strcat(), strcpy() */
#include <inttypes.h>
#include <assert.h>
#include "compress.h"
#include <libiberty.h>
#include "stubs.h"
const char *elf2flt_progname;
/* from uClinux-x.x.x/include/linux */
#include "flat.h" /* Binary flat header description */
#if defined(__MINGW32__)
#include <getopt.h>
#define mkstemp(p) mktemp(p)
#endif
#if defined TARGET_bfin
# define flat_get_relocate_addr(addr) (addr & 0x03ffffff)
#else
# define flat_get_relocate_addr(addr) (addr)
#endif
/****************************************************************************/
static int print = 0, print_relocs = 0, docompress = 0, ramload = 0,
stacksize = 0, ktrace = 0, l1stack = 0;
/****************************************************************************/
void
process_file(char *ifile, char *ofile)
{
int old_flags, old_stack, new_flags, new_stack;
stream ifp, ofp;
struct flat_hdr old_hdr, new_hdr;
char *tfile, tmpbuf[256];
int input_error, output_error;
*tmpbuf = '\0';
if (fopen_stream_u(&ifp, ifile, "r" BINARY_FILE_OPTS)) {
fprintf(stderr, "Cannot open %s\n", ifile);
return;
}
if (fread_stream(&old_hdr, sizeof(old_hdr), 1, &ifp) != 1) {
fprintf(stderr, "Cannot read header of %s\n", ifile);
fclose_stream(&ifp);
return;
}
if (strncmp(old_hdr.magic, "bFLT", 4) != 0) {
fprintf(stderr, "Cannot read header of %s\n", ifile);
fclose_stream(&ifp);
return;
}
new_flags = old_flags = ntohl(old_hdr.flags);
new_stack = old_stack = ntohl(old_hdr.stack_size);
new_hdr = old_hdr;
if (docompress == 1) {
new_flags |= FLAT_FLAG_GZIP;
new_flags &= ~FLAT_FLAG_GZDATA;
} else if (docompress == 2) {
new_flags |= FLAT_FLAG_GZDATA;
new_flags &= ~FLAT_FLAG_GZIP;
} else if (docompress < 0)
new_flags &= ~(FLAT_FLAG_GZIP|FLAT_FLAG_GZDATA);
if (ramload > 0)
new_flags |= FLAT_FLAG_RAM;
else if (ramload < 0)
new_flags &= ~FLAT_FLAG_RAM;
if (ktrace > 0)
new_flags |= FLAT_FLAG_KTRACE;
else if (ktrace < 0)
new_flags &= ~FLAT_FLAG_KTRACE;
if (l1stack > 0)
new_flags |= FLAT_FLAG_L1STK;
else if (l1stack < 0)
new_flags &= ~FLAT_FLAG_L1STK;
if (stacksize)
new_stack = stacksize;
if (print == 1) {
time_t t;
uint32_t reloc_count, reloc_start;
printf("%s\n", ifile);
printf(" Magic: %4.4s\n", old_hdr.magic);
printf(" Rev: %d\n", ntohl(old_hdr.rev));
t = (time_t) htonl(old_hdr.build_date);
printf(" Build Date: %s", t?ctime(&t):"not specified\n");
printf(" Entry: 0x%x\n", ntohl(old_hdr.entry));
printf(" Data Start: 0x%x\n", ntohl(old_hdr.data_start));
printf(" Data End: 0x%x\n", ntohl(old_hdr.data_end));
printf(" BSS End: 0x%x\n", ntohl(old_hdr.bss_end));
printf(" Stack Size: 0x%x\n", ntohl(old_hdr.stack_size));
reloc_start = ntohl(old_hdr.reloc_start);
printf(" Reloc Start: 0x%x\n", reloc_start);
reloc_count = ntohl(old_hdr.reloc_count);
printf(" Reloc Count: 0x%x\n", reloc_count);
printf(" Flags: 0x%x ( ", ntohl(old_hdr.flags));
if (old_flags) {
if (old_flags & FLAT_FLAG_RAM)
printf("Load-to-Ram ");
if (old_flags & FLAT_FLAG_GOTPIC)
printf("Has-PIC-GOT ");
if (old_flags & FLAT_FLAG_GZIP)
printf("Gzip-Compressed ");
if (old_flags & FLAT_FLAG_GZDATA)
printf("Gzip-Data-Compressed ");
if (old_flags & FLAT_FLAG_KTRACE)
printf("Kernel-Traced-Load ");
if (old_flags & FLAT_FLAG_L1STK)
printf("L1-Scratch-Stack ");
printf(")\n");
}
if (print_relocs) {
uint32_t *relocs = xcalloc(reloc_count, sizeof(uint32_t));
uint32_t i;
unsigned long r;
printf(" Relocs:\n");
printf(" #\treloc ( address )\tdata\n");
if (old_flags & FLAT_FLAG_GZIP)
reopen_stream_compressed(&ifp);
if (fseek_stream(&ifp, reloc_start, SEEK_SET)) {
fprintf(stderr, "Cannot seek to relocs of %s\n", ifile);
fclose_stream(&ifp);
return;
}
if (fread_stream(relocs, sizeof(uint32_t), reloc_count, &ifp) == -1) {
fprintf(stderr, "Cannot read relocs of %s\n", ifile);
fclose_stream(&ifp);
return;
}
for (i = 0; i < reloc_count; ++i) {
uint32_t raddr, addr;
r = ntohl(relocs[i]);
raddr = flat_get_relocate_addr(r);
printf(" %u\t0x%08lx (0x%08"PRIx32")\t", i, r, raddr);
fseek_stream(&ifp, sizeof(old_hdr) + raddr, SEEK_SET);
fread_stream(&addr, sizeof(addr), 1, &ifp);
printf("%"PRIx32"\n", addr);
}
/* reset file position for below */
fseek_stream(&ifp, sizeof(old_hdr), SEEK_SET);
}
} else if (print > 1) {
static int first = 1;
unsigned int text, data, bss, stk, rel, tot;
if (first) {
printf("Flag Rev Text Data BSS Stack Relocs RAM Filename\n");
printf("-----------------------------------------------------------\n");
first = 0;
}
*tmpbuf = '\0';
strcat(tmpbuf, (old_flags & FLAT_FLAG_KTRACE) ? "k" : "");
strcat(tmpbuf, (old_flags & FLAT_FLAG_RAM) ? "r" : "");
strcat(tmpbuf, (old_flags & FLAT_FLAG_GOTPIC) ? "p" : "");
strcat(tmpbuf, (old_flags & FLAT_FLAG_GZIP) ? "z" :
((old_flags & FLAT_FLAG_GZDATA) ? "d" : ""));
printf("-%-3.3s ", tmpbuf);
printf("%3d ", ntohl(old_hdr.rev));
printf("%6d ", text=ntohl(old_hdr.data_start)-sizeof(struct flat_hdr));
printf("%6d ", data=ntohl(old_hdr.data_end)-ntohl(old_hdr.data_start));
printf("%6d ", bss=ntohl(old_hdr.bss_end)-ntohl(old_hdr.data_end));
printf("%6d ", stk=ntohl(old_hdr.stack_size));
printf("%6d ", rel=ntohl(old_hdr.reloc_count) * 4);
/*
* work out how much RAM is needed per invocation, this
* calculation is dependent on the binfmt_flat implementation
*/
tot = data; /* always need data */
if (old_flags & (FLAT_FLAG_RAM|FLAT_FLAG_GZIP))
tot += text + sizeof(struct flat_hdr);
if (bss + stk > rel) /* which is bigger ? */
tot += bss + stk;
else
tot += rel;
printf("%6d ", tot);
/*
* the total depends on whether the relocs are smaller/bigger than
* the BSS
*/
printf("%s\n", ifile);
}
/* if there is nothing else to do, leave */
if (new_flags == old_flags && new_stack == old_stack) {
fclose_stream(&ifp);
return;
}
new_hdr.flags = htonl(new_flags);
new_hdr.stack_size = htonl(new_stack);
tfile = make_temp_file("flthdr");
if (fopen_stream_u(&ofp, tfile, "w" BINARY_FILE_OPTS)) {
unlink(tfile);
fatal("Failed to open %s for writing\n", tfile);
}
/* Copy header (always uncompressed). */
if (fwrite_stream(&new_hdr, sizeof(new_hdr), 1, &ofp) != 1) {
unlink(tfile);
fatal("Failed to write to %s\n", tfile);
}
/* Whole input file (including text) is compressed: start decompressing
now. */
if (old_flags & FLAT_FLAG_GZIP)
reopen_stream_compressed(&ifp);
/* Likewise, output file is compressed. Start compressing now. */
if (new_flags & FLAT_FLAG_GZIP) {
printf("zflat %s --> %s\n", ifile, ofile);
reopen_stream_compressed(&ofp);
}
transfer(&ifp, &ofp,
ntohl(old_hdr.data_start) - sizeof(struct flat_hdr));
/* Only data and relocs were compressed in input. Start decompressing
from here. */
if (old_flags & FLAT_FLAG_GZDATA)
reopen_stream_compressed(&ifp);
/* Only data/relocs to be compressed in output. Start compressing
from here. */
if (new_flags & FLAT_FLAG_GZDATA) {
printf("zflat-data %s --> %s\n", ifile, ofile);
reopen_stream_compressed(&ofp);
}
transfer(&ifp, &ofp, -1);
input_error = ferror_stream(&ifp);
output_error = ferror_stream(&ofp);
if (input_error || output_error) {
unlink(tfile);
fatal("Error on file pointer%s%s\n",
input_error ? " input" : "",
output_error ? " output" : "");
}
fclose_stream(&ifp);
fclose_stream(&ofp);
/* Copy temporary file to output location. */
fopen_stream_u(&ifp, tfile, "r" BINARY_FILE_OPTS);
fopen_stream_u(&ofp, ofile, "w" BINARY_FILE_OPTS);
transfer(&ifp, &ofp, -1);
fclose_stream(&ifp);
fclose_stream(&ofp);
unlink(tfile);
free(tfile);
}
/****************************************************************************/
void
usage(char *s)
{
if (s)
fprintf(stderr, "%s\n", s);
fprintf(stderr, "usage: %s [options] flat-file\n", elf2flt_progname);
fprintf(stderr, " Allows you to change an existing flat file\n\n");
fprintf(stderr, " -p : print current settings\n");
fprintf(stderr, " -P : print relocations\n");
fprintf(stderr, " -z : compressed flat file\n");
fprintf(stderr, " -d : compressed data-only flat file\n");
fprintf(stderr, " -Z : un-compressed flat file\n");
fprintf(stderr, " -r : ram load\n");
fprintf(stderr, " -R : do not RAM load\n");
fprintf(stderr, " -k : kernel traced load (for debug)\n");
fprintf(stderr, " -K : normal non-kernel traced load\n");
fprintf(stderr, " -u : place stack in L1 scratchpad memory\n");
fprintf(stderr, " -U : place stack in normal SDRAM memory\n");
fprintf(stderr, " -s size : stack size\n");
fprintf(stderr, " -o file : output-file\n"
" (default is to modify input file)\n");
exit(1);
}
/****************************************************************************/
int
main(int argc, char *argv[])
{
int c, noargs;
char *ofile = NULL, *ifile;
elf2flt_progname = argv[0];
noargs = 1;
while ((c = getopt(argc, argv, "pPdzZrRuUkKs:o:")) != EOF) {
switch (c) {
case 'p': print = 1; break;
case 'P': print_relocs = 1; break;
case 'z': docompress = 1; break;
case 'd': docompress = 2; break;
case 'Z': docompress = -1; break;
case 'r': ramload = 1; break;
case 'R': ramload = -1; break;
case 'k': ktrace = 1; break;
case 'K': ktrace = -1; break;
case 'u': l1stack = 1; break;
case 'U': l1stack = -1; break;
case 'o': ofile = optarg; break;
case 's':
if (sscanf(optarg, "%i", &stacksize) != 1)
usage("invalid stack size");
break;
default:
usage("invalid option");
break;
}
noargs = 0;
}
if (optind >= argc)
usage("No input files provided");
if (ofile && argc - optind > 1)
usage("-o can only be used with a single file");
if (!print && noargs) /* no args == print */
print = argc - optind; /* greater than 1 is short format */
for (c = optind; c < argc; c++) {
ifile = argv[c];
if (!ofile)
ofile = ifile;
process_file(ifile, ofile);
ofile = NULL;
}
exit(0);
}
/****************************************************************************/

View File

@ -1,251 +0,0 @@
#!/bin/sh
#
# install - install a program, script, or datafile
# This comes from X11R5 (mit/util/scripts/install.sh).
#
# Copyright 1991 by the Massachusetts Institute of Technology
#
# Permission to use, copy, modify, distribute, and sell this software and its
# documentation for any purpose is hereby granted without fee, provided that
# the above copyright notice appear in all copies and that both that
# copyright notice and this permission notice appear in supporting
# documentation, and that the name of M.I.T. not be used in advertising or
# publicity pertaining to distribution of the software without specific,
# written prior permission. M.I.T. makes no representations about the
# suitability of this software for any purpose. It is provided "as is"
# without express or implied warranty.
#
# Calling this script install-sh is preferred over install.sh, to prevent
# `make' implicit rules from creating a file called install from it
# when there is no Makefile.
#
# This script is compatible with the BSD install script, but was written
# from scratch. It can only install one file at a time, a restriction
# shared with many OS's install programs.
# set DOITPROG to echo to test this script
# Don't use :- since 4.3BSD and earlier shells don't like it.
doit="${DOITPROG-}"
# put in absolute paths if you don't have them in your path; or use env. vars.
mvprog="${MVPROG-mv}"
cpprog="${CPPROG-cp}"
chmodprog="${CHMODPROG-chmod}"
chownprog="${CHOWNPROG-chown}"
chgrpprog="${CHGRPPROG-chgrp}"
stripprog="${STRIPPROG-strip}"
rmprog="${RMPROG-rm}"
mkdirprog="${MKDIRPROG-mkdir}"
transformbasename=""
transform_arg=""
instcmd="$mvprog"
chmodcmd="$chmodprog 0755"
chowncmd=""
chgrpcmd=""
stripcmd=""
rmcmd="$rmprog -f"
mvcmd="$mvprog"
src=""
dst=""
dir_arg=""
while [ x"$1" != x ]; do
case $1 in
-c) instcmd="$cpprog"
shift
continue;;
-d) dir_arg=true
shift
continue;;
-m) chmodcmd="$chmodprog $2"
shift
shift
continue;;
-o) chowncmd="$chownprog $2"
shift
shift
continue;;
-g) chgrpcmd="$chgrpprog $2"
shift
shift
continue;;
-s) stripcmd="$stripprog"
shift
continue;;
-t=*) transformarg=`echo $1 | sed 's/-t=//'`
shift
continue;;
-b=*) transformbasename=`echo $1 | sed 's/-b=//'`
shift
continue;;
*) if [ x"$src" = x ]
then
src=$1
else
# this colon is to work around a 386BSD /bin/sh bug
:
dst=$1
fi
shift
continue;;
esac
done
if [ x"$src" = x ]
then
echo "install: no input file specified"
exit 1
else
:
fi
if [ x"$dir_arg" != x ]; then
dst=$src
src=""
if [ -d $dst ]; then
instcmd=:
chmodcmd=""
else
instcmd=$mkdirprog
fi
else
# Waiting for this to be detected by the "$instcmd $src $dsttmp" command
# might cause directories to be created, which would be especially bad
# if $src (and thus $dsttmp) contains '*'.
if [ -f $src -o -d $src ]
then
:
else
echo "install: $src does not exist"
exit 1
fi
if [ x"$dst" = x ]
then
echo "install: no destination specified"
exit 1
else
:
fi
# If destination is a directory, append the input filename; if your system
# does not like double slashes in filenames, you may need to add some logic
if [ -d $dst ]
then
dst="$dst"/`basename $src`
else
:
fi
fi
## this sed command emulates the dirname command
dstdir=`echo $dst | sed -e 's,[^/]*$,,;s,/$,,;s,^$,.,'`
# Make sure that the destination directory exists.
# this part is taken from Noah Friedman's mkinstalldirs script
# Skip lots of stat calls in the usual case.
if [ ! -d "$dstdir" ]; then
defaultIFS='
'
IFS="${IFS-${defaultIFS}}"
oIFS="${IFS}"
# Some sh's can't handle IFS=/ for some reason.
IFS='%'
set - `echo ${dstdir} | sed -e 's@/@%@g' -e 's@^%@/@'`
IFS="${oIFS}"
pathcomp=''
while [ $# -ne 0 ] ; do
pathcomp="${pathcomp}${1}"
shift
if [ ! -d "${pathcomp}" ] ;
then
$mkdirprog "${pathcomp}"
else
:
fi
pathcomp="${pathcomp}/"
done
fi
if [ x"$dir_arg" != x ]
then
$doit $instcmd $dst &&
if [ x"$chowncmd" != x ]; then $doit $chowncmd $dst; else : ; fi &&
if [ x"$chgrpcmd" != x ]; then $doit $chgrpcmd $dst; else : ; fi &&
if [ x"$stripcmd" != x ]; then $doit $stripcmd $dst; else : ; fi &&
if [ x"$chmodcmd" != x ]; then $doit $chmodcmd $dst; else : ; fi
else
# If we're going to rename the final executable, determine the name now.
if [ x"$transformarg" = x ]
then
dstfile=`basename $dst`
else
dstfile=`basename $dst $transformbasename |
sed $transformarg`$transformbasename
fi
# don't allow the sed command to completely eliminate the filename
if [ x"$dstfile" = x ]
then
dstfile=`basename $dst`
else
:
fi
# Make a temp file name in the proper directory.
dsttmp=$dstdir/#inst.$$#
# Move or copy the file name to the temp name
$doit $instcmd $src $dsttmp &&
trap "rm -f ${dsttmp}" 0 &&
# and set any options; do chmod last to preserve setuid bits
# If any of these fail, we abort the whole thing. If we want to
# ignore errors from any of these, just make sure not to ignore
# errors from the above "$doit $instcmd $src $dsttmp" command.
if [ x"$chowncmd" != x ]; then $doit $chowncmd $dsttmp; else :;fi &&
if [ x"$chgrpcmd" != x ]; then $doit $chgrpcmd $dsttmp; else :;fi &&
if [ x"$stripcmd" != x ]; then $doit $stripcmd $dsttmp; else :;fi &&
if [ x"$chmodcmd" != x ]; then $doit $chmodcmd $dsttmp; else :;fi &&
# Now rename the file to the real destination.
$doit $rmcmd -f $dstdir/$dstfile &&
$doit $mvcmd $dsttmp $dstdir/$dstfile
fi &&
exit 0

View File

@ -1,580 +0,0 @@
/*
* Wrapper for the real linker and the elf2flt converter. This was
* originally a simple shell script, but that doesn't work on a
* Windows host without cygwin.
* The proper long term solution is to add FLT as a BFD output format.
*
* Converted from ld-elf2flt.in by Nathan Sidwell, nathan@codesourcery.com.
* Updated to latest elf2flt code by Mike Frysinger, vapier@gentoo.org.
*
* This is Free Software, under the GNU General Public License V2 or greater.
*
* Copyright (C) 2006, CodeSourcery Inc.
* Copyright (C) 2009, Analog Devices, Inc.
* Copyright (C) 2002-2003 David McCullough <davidm@snapgear.com>
* Copyright (C) 2000, Lineo. <davidm@lineo.com>
*/
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <errno.h>
#include <libiberty.h>
#include <filenames.h>
#include "stubs.h"
const char *elf2flt_progname;
static int flag_verbose = 0, flag_final = 1, have_elf2flt_options = 0,
flag_move_data = 0, want_shared = 0;
static const char *shared_lib_id = NULL;
static const char *output_file = "a.out";
static const char *linker_script = NULL;
static const char *emulation = NULL;
static const char *tmp_file = NULL;
static const char *output_gdb = NULL;
static const char *output_elf = NULL;
static const char *output_flt = NULL;
static options_t search_dirs, all_options, other_options, flt_options;
static const char *linker = NULL;
static const char *elf2flt = NULL;
static const char *nm = NULL;
static const char *objdump = NULL;
static const char *objcopy = NULL;
static const char *ldscriptpath = BINUTILS_LDSCRIPTDIR;
/* A list of sed commands */
typedef struct {
options_t *pattern; /* '^' for start of line match, everything else verbatim */
options_t *replacement; /* Delete line, if NULL */
} sed_commands_t;
/* Initialize a sed structure */
#define init_sed(DST) ( \
(DST)->pattern = xmalloc(sizeof(*(DST)->pattern)), \
(DST)->replacement = xmalloc(sizeof(*(DST)->replacement)), \
init_options((DST)->pattern), \
init_options((DST)->replacement) \
)
#define free_sed(DST) (free((DST)->pattern), free((DST)->replacement))
/* Append a slot for a new sed command. */
static void append_sed(sed_commands_t *dst, const char *pattern,
const char *replacement)
{
debug1("adding pattern '%s' with replacement '%s'\n",
pattern, replacement);
append_option(dst->pattern, pattern);
append_option(dst->replacement, replacement);
}
/* Execute an external program COMMAND. Write its stdout to OUTPUT,
unless that is NULL. Pass the trailing NULL terminated list of
options, followed by all those in OPTIONS, if that is non-NULL.
Order of options is important here as we may run on systems that
do not allow options after non-options (i.e. many BSDs). So the
final command line will look like:
<command> [options] [... va args ...]
This is because [options] will (should?) never contain non-options,
while non-options will always be passed via the [va args].
*/
static int
execute(const char *command, const char *output, const options_t *options, ...)
{
struct pex_obj *pex;
const char *errmsg;
int err;
int status;
va_list args;
const char *opt;
options_t opts;
debug("command=%s\n", command);
init_options(&opts);
append_option(&opts, command);
if (options)
append_options(&opts, options);
va_start(args, options);
while ((opt = va_arg(args, const char *)))
append_option(&opts, opt);
va_end(args);
append_option(&opts, NULL);
fflush(stdout);
fflush(stderr);
pex = pex_init(0, elf2flt_progname, NULL);
if (pex == NULL)
fatal_perror("pex_init failed");
if (flag_verbose) {
unsigned ix;
fprintf(stderr, "Invoking:");
for (ix = 0; ix != opts.num - 1; ix++)
fprintf(stderr, " '%s'", opts.options[ix]);
if (output)
fprintf(stderr, " > '%s'", output);
fprintf(stderr, "\n");
}
errmsg = pex_run(pex, PEX_LAST | PEX_SEARCH, command,
(char *const *)opts.options, output, NULL, &err);
if (errmsg != NULL) {
if (err != 0) {
errno = err;
fatal_perror(errmsg);
} else
fatal(errmsg);
}
if (!pex_get_status(pex, 1, &status))
fatal_perror("can't get program status");
pex_free(pex);
if (status) {
if (WIFSIGNALED(status)) {
int sig = WTERMSIG(status);
fatal("%s terminated with signal %d [%s]%s",
command, sig, strsignal(sig),
WCOREDUMP(status) ? ", core dumped" : "");
}
if (WIFEXITED(status))
return WEXITSTATUS(status);
}
return 0;
}
/* Auto NULL terminate */
#define execute(...) execute(__VA_ARGS__, NULL)
/* Apply the sed commands in SED to file NAME_IN producing file NAME_OUT */
static void
do_sed(const sed_commands_t *sed, const char *name_in, const char *name_out)
{
FILE *in, *out;
size_t alloc = 0;
char *line = NULL;
ssize_t len;
const char *pattern, *replacement;
int ix;
if (flag_verbose) {
fprintf(stderr, "emulating: sed \\\n");
for (ix = 0; ix != sed->pattern->num; ix++) {
pattern = sed->pattern->options[ix];
replacement = sed->replacement->options[ix];
if (replacement)
fprintf(stderr, "\t-e 's/%s/%s/' \\\n", pattern, replacement);
else
fprintf(stderr, "\t-e '/%s/d' \\\n", pattern);
}
fprintf(stderr, "\t%s > %s\n", name_in, name_out);
}
in = xfopen(name_in, "r");
out = xfopen(name_out, "w");
while ((len = getline(&line, &alloc, in)) > 0) {
debug2("len=%2zi line=%s", len, line);
for (ix = 0; ix != sed->pattern->num; ix++) {
const char *ptr;
int bol;
size_t pat_len;
pattern = sed->pattern->options[ix];
replacement = sed->replacement->options[ix];
ptr = line;
bol = pattern[0] == '^';
pattern += bol;
pat_len = strlen(pattern);
if (!bol) {
do {
ptr = strchr(ptr, pattern[0]);
if (!ptr) ;
else if (!strncmp(ptr, pattern, pat_len))
goto found;
else
ptr++;
}
while (ptr);
} else if (!strncmp(ptr, pattern, pat_len)) {
found:
if (replacement) {
debug2(" [modified]\n");
fwrite(line, 1, ptr - line, out);
fwrite(replacement, 1, strlen(replacement), out);
fwrite(ptr + pat_len, 1,
len - pat_len - (ptr - line),
out);
} else
debug2(" {dropped}\n");
goto next_line;
}
}
debug2("(untouched)\n");
fwrite(line, 1, len, out);
next_line:
;
}
fclose(in);
if (fclose(out))
fatal_perror("error writing temporary script '%s'", name_out);
free(line);
}
/* Generate the flt binary along with any other necessary pieces. */
#define exec_or_ret(...) \
do { \
int status = execute(__VA_ARGS__); \
if (status) return status; \
} while (0)
static int do_final_link(void)
{
sed_commands_t sed;
struct stat buf;
const char *script;
const char *rel_output;
int have_got = 0;
FILE *in;
char *line = NULL;
size_t alloc = 0;
ssize_t len;
init_sed(&sed);
if (flag_move_data) {
FILE *in;
/* See if the .rodata section contains any relocations. */
if (!output_flt)
output_flt = make_temp_file(NULL);
exec_or_ret(linker, NULL, &other_options, "-r", "-d", "-o", output_flt);
exec_or_ret(objdump, tmp_file, NULL, "-h", output_flt);
in = xfopen(tmp_file, "r");
while ((len = getline(&line, &alloc, in)) > 0) {
const char *ptr = line;
while (1) {
ptr = strchr(ptr, '.');
if (!ptr)
break;
if (streqn(ptr, ".rodata")) {
getline(&line, &alloc, in);
ptr = line;
while (1) {
ptr = strchr(ptr, 'R');
if (!ptr)
break;
if (streqn(ptr, "RELOC")) {
flag_move_data = 0;
fprintf(stderr, "warning: .rodata section contains relocations");
break;
} else
ptr++;
}
break;
} else
ptr++;
}
}
fclose(in);
}
append_sed(&sed, "^R_RODAT", flag_move_data ? NULL : "");
append_sed(&sed, "^W_RODAT", flag_move_data ? "" : NULL);
append_sed(&sed, "^SINGLE_LINK:", USE_EMIT_RELOCS ? "" : NULL);
append_sed(&sed, "^TOR:", EMIT_CTOR_DTOR ? "" : NULL);
if (shared_lib_id) {
const char *got_offset;
int adj, id = strtol(shared_lib_id, NULL, 0);
char buf[30];
/* Replace addresses using the shared object id. */
sprintf(buf, "%.2X", id);
append_sed(&sed, "ORIGIN = 0x0,", concat("ORIGIN = 0x", buf, "000000,", NULL));
append_sed(&sed, ".text 0x0 :", concat(".text 0x0", buf, "000000 :", NULL));
if (id)
append_sed(&sed, "ENTRY (" SYMBOL_PREFIX "_start)", "ENTRY (lib_main)");
/* Provide the symbol specifying the library's data segment
pointer offset. */
adj = 4;
if (streq(TARGET_CPU, "h8300"))
got_offset = "__current_shared_library_er5_offset_";
else if (streq(TARGET_CPU, "bfin"))
got_offset = "_current_shared_library_p5_offset_", adj = 1;
else
got_offset = "_current_shared_library_a5_offset_";
append_option(&other_options, "-defsym");
sprintf(buf, "%d", id * -adj - adj);
append_option(&other_options, concat(got_offset, "=", buf, NULL));
}
/* Locate the default linker script, if we don't have one provided. */
if (!linker_script)
linker_script = concat(ldscriptpath, "/elf2flt.ld", NULL);
/* Try and locate the linker script. */
script = linker_script;
if (stat(script, &buf) || !S_ISREG(buf.st_mode)) {
script = concat(ldscriptpath, "/", linker_script, NULL);
if (stat(script, &buf) || !S_ISREG(buf.st_mode)) {
script = concat(ldscriptpath, "/ldscripts/", linker_script, NULL);
if (stat(script, &buf) || !S_ISREG(buf.st_mode))
script = NULL;
}
}
/* And process it if we can -- if we can't find it, the user must
know what they are doing. */
if (script) {
do_sed(&sed, linker_script, tmp_file);
linker_script = tmp_file;
}
free_sed(&sed);
if (USE_EMIT_RELOCS) {
exec_or_ret(linker, NULL, &other_options,
"-T", linker_script, "-q", "-o", output_gdb, emulation);
append_option(&flt_options, "-a");
rel_output = output_gdb;
} else if (NO_GOT_CHECK) {
output_elf = make_temp_file(NULL);
exec_or_ret(linker, NULL, &other_options,
"-T", linker_script, "-Ur", "-d", "-o", output_elf, emulation);
exec_or_ret(linker, NULL, &other_options,
"-T", linker_script, "-o", output_gdb, emulation);
rel_output = output_elf;
} else {
output_flt = make_temp_file(NULL);
exec_or_ret(linker, NULL, &other_options,
"-r", "-d", "-o", output_flt, emulation);
output_elf = make_temp_file(NULL);
exec_or_ret(linker, NULL, &search_dirs,
"-T", linker_script, "-Ur", "-o", output_elf, output_flt, emulation);
exec_or_ret(linker, NULL, &search_dirs,
"-T", linker_script, "-o", output_gdb, output_flt, emulation);
rel_output = output_elf;
}
if (shared_lib_id && strtol(shared_lib_id, NULL, 0) != 0)
exec_or_ret(objcopy, NULL, NULL, "--localize-hidden", "--weaken", output_gdb);
exec_or_ret(nm, tmp_file, NULL, "-p", output_gdb);
in = xfopen(tmp_file, "r");
while ((len = getline(&line, &alloc, in)) > 0) {
const char *ptr = strchr(line, '_');
if (ptr && streqn(ptr, "_GLOBAL_OFFSET_TABLE")) {
have_got = 1;
break;
}
}
fclose(in);
if (have_got)
exec_or_ret(elf2flt, NULL, &flt_options,
"-o", output_file, "-p", output_gdb, rel_output);
else
exec_or_ret(elf2flt, NULL, &flt_options,
"-o", output_file, "-r", rel_output);
return 0;
}
/* parse all the arguments provided to us */
static void parse_args(int argc, char **argv)
{
char *fltflags;
int argno;
for (argno = 1; argno < argc; argno++) {
char const *arg = argv[argno];
int to_all = argno;
if (streq(arg, "-elf2flt")) {
have_elf2flt_options = 1;
to_all++;
} else if (streqn(arg, "-elf2flt=")) {
have_elf2flt_options = 1;
append_option_str(&flt_options, &arg[9], "\t ");
to_all++;
} else if (streq(arg, "-move-rodata")) {
flag_move_data = 1;
} else if (streq(arg, "-shared-lib-id")) {
shared_lib_id = argv[++argno];
} else if (streq(arg, "-shared") || streq(arg, "-G")) {
want_shared = 1;
} else if (streqn(arg, "-o")) {
output_file = arg[2] ? &arg[2] : argv[++argno];
} else if (streqn(arg, "-T")) {
linker_script = arg[2] ? &arg[2] : argv[++argno];
} else if (streq(arg, "-c")) {
linker_script = argv[++argno];
} else if (streqn(arg, "-L")) {
const char *merged =
(arg[2] ? arg : concat("-L", argv[++argno], NULL));
append_option(&other_options, merged);
append_option(&search_dirs, merged);
} else if (streq(arg, "-EB")) {
append_option(&other_options, arg);
append_option(&search_dirs, arg);
} else if (streq(arg, "-relax")) {
;
} else if (streq(arg, "-s") || streq(arg, "--strip-all") ||
streq(arg, "-S") || streq(arg, "--strip-debug")) {
/* Ignore these strip options for links involving elf2flt.
The final flat output will be stripped by definition, and we
don't want to strip the .gdb helper file. The strip options
are also incompatible with -r and --emit-relocs. */
;
} else if (streq(arg, "-r") || streq(arg, "-Ur")) {
flag_final = 0;
append_option(&other_options, arg);
} else if (streq(arg, "--verbose")) {
flag_verbose = 1;
append_option(&other_options, arg);
} else if (streqn(arg, "-m")) {
emulation = arg[2] ? arg : concat("-m", argv[++argno], NULL);
} else
append_option(&other_options, arg);
while (to_all <= argno)
append_option(&all_options, argv[to_all++]);
}
fltflags = getenv("FLTFLAGS");
if (fltflags)
append_option_str(&flt_options, fltflags, "\t ");
}
int main(int argc, char *argv[])
{
const char *argv0 = argv[0];
const char *argv0_dir = make_relative_prefix(argv0, "/", "/");
char *tooldir = argv0_dir;
char *bindir = argv0_dir;
char *tmp;
struct stat buf;
const char *have_exe = NULL;
int status;
#ifdef __WIN32
/* Remove the .exe extension, if it's there. */
size_t len = strlen(argv0);
if (len > 4 && streq(&argv0[len - 4], ".exe")) {
have_exe = ".exe";
len -= 4;
argv0 = tmp = xstrdup(argv0);
tmp[len] = 0;
argv[0][len] = '\0';
}
#endif
elf2flt_progname = lbasename(argv0);
/* The standard binutils tool layout has:
bin/<TARGET_ALIAS>-foo
lib/
<TARGET_ALIAS>/bin/foo
<TARGET_ALIAS>/lib
It's <TARGET_ALIAS>/ that we want here: files in lib/ are for
the host while those in <TARGET_ALIAS>/lib are for the target.
Make bindir point to the bin dir for bin/<TARGET_ALIAS>-foo.
Make tooldir point to the bin dir for <TARGET_ALIAS>/bin/foo. */
if (streqn(elf2flt_progname, TARGET_ALIAS)) {
tmp = concat(argv0_dir, "../" TARGET_ALIAS "/bin", NULL);
if (stat(tmp, &buf) == 0 && S_ISDIR(buf.st_mode)) {
tooldir = concat(tmp, "/", NULL);
}
} else {
tmp = concat(argv0_dir, "../../bin", NULL);
if (stat(tmp, &buf) == 0 && S_ISDIR(buf.st_mode)) {
bindir = concat(tmp, "/", NULL);
}
}
/* Typically ld-elf2flt is invoked as `ld` which means error
* messages from it will look like "ld: " which is completely
* confusing. So append an identifier to keep things clear.
*/
elf2flt_progname = concat(elf2flt_progname, " (ld-elf2flt)", NULL);
xmalloc_set_program_name(elf2flt_progname);
linker = concat(tooldir, "ld.real", have_exe, NULL);
elf2flt = concat(tooldir, "elf2flt", have_exe, NULL);
nm = concat(tooldir, "nm", have_exe, NULL);
objdump = concat(bindir, TARGET_ALIAS "-objdump", have_exe, NULL);
objcopy = concat(bindir, TARGET_ALIAS "-objcopy", have_exe, NULL);
if (stat(ldscriptpath, &buf) || !S_ISDIR(buf.st_mode))
ldscriptpath = concat(tooldir, "../lib", NULL);
parse_args(argc, argv);
if (flag_verbose) {
fprintf(stderr, "argv[0] = '%s'\n", argv[0]);
fprintf(stderr, "bindir = '%s'\n", bindir);
fprintf(stderr, "tooldir = '%s'\n", tooldir);
fprintf(stderr, "linker = '%s'\n", linker);
fprintf(stderr, "elf2flt = '%s'\n", elf2flt);
fprintf(stderr, "nm = '%s'\n", nm);
fprintf(stderr, "objdump = '%s'\n", objdump);
fprintf(stderr, "objcopy = '%s'\n", objcopy);
fprintf(stderr, "ldscriptpath = '%s'\n", ldscriptpath);
}
/* Pass off to regular linker, if there's nothing elf2flt-like */
if (!have_elf2flt_options)
return execute(linker, NULL, &all_options);
/* Pass off to regular linker, minus the elf2flt options, if it's
not the final link. */
if (!flag_final)
return execute(linker, NULL, &other_options, "-o", output_file);
if (want_shared && !shared_lib_id)
fatal("-shared used without passing a shared library ID");
/* Otherwise link & convert to flt. */
output_gdb = concat(output_file, ".gdb", NULL);
tmp_file = make_temp_file(NULL);
status = do_final_link();
if (!flag_verbose) {
unlink(tmp_file);
unlink(output_flt);
unlink(output_elf);
} else {
fprintf(stderr,
"leaving elf2flt temp files behind:\n"
"tmp_file = %s\n"
"output_flt = %s\n"
"output_elf = %s\n",
tmp_file, output_flt, output_elf);
}
return status;
}

View File

@ -1,241 +0,0 @@
#!/bin/sh
#
# allow us to do flat processing if the flag -Wl,-elf2flt or -elf2flt to
# the 'C' compiler or linker respectively
#
# uses the env. var FLTFLAGS as extra parameters to pass to elf2flt
# arguments given like -Wl,-elf2flt="-b 10000 -v" are given before FLTFLAGS
#
# Copyright (C) 2002,2003 David McCullough <davidm@snapgear.com>
# Copyright (C) 2000, Lineo. davidm@lineo.com
#
# This is Free Software, under the GNU Public Licence v2 or greater.
#
LINKER="$0.real" # the original renamed-linker
ELF2FLT="`expr $0 : '\(.*\)ld'`elf2flt"
NM="`expr $0 : '\(.*\)ld'`nm"
TOOLDIR="`dirname $0`" # let gcc find the tools for us
OBJCOPY="`expr $0 : '\(.*\)ld'`objcopy"
[ -f "$OBJCOPY" ] || OBJCOPY="$TOOLDIR/../../bin/@target_alias@-objcopy"
OBJDUMP="`expr $OBJCOPY : '\(.*\)objcopy'`objdump"
LDSCRIPTPATH="@binutils_ldscript_dir@" # and the scripts
SHARED_ID=""
NEWLDSCRIPT=""
WANT_SHARED=""
# check TOOLDIR from prefix/bin/ or prefix/target-alias/bin/
[ -d "${LDSCRIPTPATH}" ] || LDSCRIPTPATH="${TOOLDIR}/../lib"
#
# if we have the elf2flt options, run it
#
if expr "$*" : ".*-elf2flt.*" > /dev/null
then
ARG1=
ARG2=
OFILE="a.out"
PIC=
SDIRS=
LDSCRIPT=
FINAL="yes"
FINAL_ONLY=
MOVDAT=
VERBOSE=
while [ $# -ne 0 ]
do
case "$1" in
-elf2flt) ;; # we already know this
-elf2flt*)FLTFLAGS="`expr \"$1\" : '-elf2flt=\(.*\)'` $FLTFLAGS";;
-move-rodata)
MOVDAT="y";; # Put rodata in ROM if possible
-s|-S|--strip-all|--strip-debug)
;; # Ignore strip flags
-shared-lib-id)
shift; SHARED_ID="$1";; # Shared library ID
-shared|-G)
WANT_SHARED="y";; # Shared library
-o) shift; OFILE="$1";; # the final outfile
-o*) OFILE="`expr \"$1\" : '-o\(.*\)'`";;
-T) shift; LDSCRIPT="$1";; # they have a linker script
-c) shift; LDSCRIPT="$1";;
-L) ARG1="$ARG1 $1" # remember search dirs
shift;
ARG1="$ARG1 $1"
SDIRS="$SDIRS -L$1"
;;
-L*) ARG1="$ARG1 $1"; SDIRS="$SDIRS $1";;
-EB) ARG1="$ARG1 $1"; SDIRS="$SDIRS $1";; # arm big endian
-relax) ;; # eat this for microblaze
-r|-Ur) FINAL="" # this is not a final link
ARG1="$ARG1 $1"
;;
-v|--verbose)
ARG1="$ARG1 $1"
VERBOSE="y"
;;
-m) shift; EMUL="-m $1";; # ld emulations for h8300
-m*) EMUL=$1;;
*) ARG1="$ARG1 $1"
;;
esac
shift
done
if [ "$WANT_SHARED" = "y" ]
then
if [ -z "$SHARED_ID" ]
then
echo "-shared used without passing a shared library ID"
exit 1
fi
fi
if [ "$FINAL" = "yes" ]
then
[ "$VERBOSE" = "y" ] && set -x
ARG1="$ARG1 $FINAL_ONLY"
NEWLDSCRIPT=`mktemp /tmp/flt-XXXXXX`
trap 'rm -f "$NEWLDSCRIPT"' EXIT
SEDOP=" -e s/^R_RODAT// -e /^W_RODAT/d"
OBJCOPYOP=""
if [ "$MOVDAT" ]
then
$LINKER -r -d -o "$OFILE.elf2flt" $ARG1 || exit $?
if [ "`$OBJDUMP -h "$OFILE.elf2flt" | \
egrep -A1 '[.]rodata' | grep RELOC`" ]
then
echo "warning: .rodata section contains relocations"
else
SEDOP="-e /^R_RODAT/d -e s/^W_RODAT//"
fi
fi
if [ "$SHARED_ID" ]
then
# Massage the linker script into something useful. These
# regexps are ugly due to some bizzare shell quoting rules.
# SEDOP="$SEDOP -e \"s/ORIGIN = 0x0,/ORIGIN = 0x${SHARED_ID}000000,/\""
# SEDOP="$SEDOP -e \"s/.text 0x0 :/.text 0x${SHARED_ID}000000 :/\""
SEDOP="$SEDOP -e s/\\(ORIGIN.=.0\\)x0,/\\1x${SHARED_ID}000000,/"
SEDOP="$SEDOP -e s/\\([.]text.0\\)x0[^0-9]:/\\1x${SHARED_ID}000000:/"
if [ "$SHARED_ID" -gt 0 ]
then
# Non application modules enter via main not _start
# SEDOP="$SEDOP -e 's/ENTRY (_start)/ENTRY (main)/'"
SEDOP="$SEDOP -e s/\\(ENTRY.\\)(@SYMBOL_PREFIX@_start)/\1(lib_main)/"
OBJCOPYOP="--localize-hidden --weaken"
fi
# Provide the magic parameter that defines the library data segment pointer offset
GOT_ADJ=4
case "@target_cpu@" in
bfin) GOT_OFFSET="_current_shared_library_p5_offset_" GOT_ADJ=1;;
h8300) GOT_OFFSET="__current_shared_library_er5_offset_";;
*) GOT_OFFSET="_current_shared_library_a5_offset_";;
esac
ARG1="$ARG1 -defsym $GOT_OFFSET=`expr ${SHARED_ID} '*' -${GOT_ADJ} - ${GOT_ADJ}`"
fi
if [ "@emit_relocs@" = "1" ]
then
SEDOP="$SEDOP -e s/^SINGLE_LINK://"
else
SEDOP="$SEDOP -e /^SINGLE_LINK:/d"
fi
if [ "@emit_ctor_dtor@" = "1" ]
then
SEDOP="$SEDOP -e s/^TOR://"
else
SEDOP="$SEDOP -e /^TOR:/d"
fi
# provide a default linker script, we usually need one
[ -z "$LDSCRIPT" ] && LDSCRIPT="${LDSCRIPTPATH}/elf2flt.ld"
# if we can find the linker script we preprocess it, otherwise
# we assume the user knows what they are doing
if [ -f "$LDSCRIPT" ]; then
sed $SEDOP < "$LDSCRIPT" > "$NEWLDSCRIPT"
LDSCRIPT="$NEWLDSCRIPT"
elif [ -f "${LDSCRIPTPATH}/$LDSCRIPT" ]; then
sed $SEDOP < "${LDSCRIPTPATH}/$LDSCRIPT" > "$NEWLDSCRIPT"
LDSCRIPT="$NEWLDSCRIPT"
elif [ -f "${LDSCRIPTPATH}/ldscripts/$LDSCRIPT" ]; then
sed $SEDOP < "${LDSCRIPTPATH}/ldscripts/$LDSCRIPT" > "$NEWLDSCRIPT"
LDSCRIPT="$NEWLDSCRIPT"
fi
if [ "@emit_relocs@" = "1" ]
then
$LINKER $EMUL $SDIRS -T $LDSCRIPT -q -o "$OFILE.gdb" $ARG1 ||exit $?
RFILE="$OFILE.gdb"
FLTFLAGS="$FLTFLAGS -a"
else
if [ "@got_check@" = "0" ]
then
$LINKER $EMUL $SDIRS -T $LDSCRIPT -Ur -d -o "$OFILE.elf" $ARG1 ||exit $?
$LINKER $EMUL $SDIRS -T $LDSCRIPT -o "$OFILE.gdb" $ARG1 ||exit $?
else
$LINKER $EMUL -r -d -o "$OFILE.elf2flt" $ARG1 ||exit $?
$LINKER $EMUL $SDIRS -T $LDSCRIPT -Ur -o "$OFILE.elf" "$OFILE.elf2flt" ||exit $?
$LINKER $EMUL $SDIRS -T $LDSCRIPT -o "$OFILE.gdb" "$OFILE.elf2flt" ||exit $?
rm -f "$OFILE.elf2flt"
fi
RFILE="$OFILE.elf"
fi
if $NM "$OFILE.gdb" | grep _GLOBAL_OFFSET_TABLE_ > /dev/null
then
$ELF2FLT $FLTFLAGS -o "$OFILE" -p "$OFILE.gdb" "$RFILE" || exit $?
else
$ELF2FLT $FLTFLAGS -o "$OFILE" -r "$RFILE" || exit $?
fi
if [ "$OBJCOPYOP" ]
then
if $OBJCOPY $OBJCOPYOP --help > /dev/null 2>&1
then
$OBJCOPY $OBJCOPYOP "$OFILE.gdb" ||exit $?
else
case " $OBJCOPYOP " in
*" --localize-hidden "*)
SYMS=`mktemp /tmp/flt-XXXXXX`
$OBJDUMP --syms "$OFILE.gdb" > "$SYMS" ||exit $?
sed -n 's/.*\(\.hidden\|\.internal\) \(.*\)/-L \2/p' < "$SYMS" > "$SYMS.hidden" ||exit $?
if [ -s "$SYMS.hidden" ]
then
xargs ${VERBOSE:+-t} $OBJCOPY "$OFILE.gdb" < "$SYMS.hidden" ||exit $?
fi
rm -f "$SYMS" "$SYMS.hidden"
;;
esac
case " $OBJCOPYOP " in
*" --weaken "*)
$OBJCOPY --weaken "$OFILE.gdb" ||exit $?
;;
esac
fi
fi
[ "$RFILE" = "$OFILE.gdb" ] || rm -f "$RFILE" # not needed for any reason
exit 0
fi
exec $LINKER -o "$OFILE" $ARG1
fi
#
# otherwise pretend we aren't here
#
exec $LINKER "$@"

View File

@ -1,133 +0,0 @@
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include "libiberty.h"
#include "stubs.h"
#ifndef HAVE_DCGETTEXT
const char *dcgettext(const char *domain, const char *msg, int category)
{
return msg;
}
#endif /* !HAVE_DCGETTEXT */
#ifndef HAVE_LIBINTL_DGETTEXT
const char *libintl_dgettext(const char *domain, const char *msg)
{
return msg;
}
#endif /* !HAVE_LIBINTL_DGETTEXT */
#ifndef HAVE_GETLINE
/* Read a line from IN. LINE points to a malloc'd buffer that is extended as
necessary. ALLOC points to the allocated length of LINE. Returns
the length of the string read (including any trailing \n) */
ssize_t getline(char **line, size_t *alloc, FILE *in)
{
size_t len = 0;
if (!*alloc) {
*alloc = 200;
*line = xmalloc(*alloc);
}
while (1) {
if (!fgets(*line + len, *alloc - len, in))
return 0;
len += strlen(*line + len);
if (len && (*line)[len - 1] == '\n')
return len;
*alloc *= 2;
*line = xrealloc(*line, *alloc);
}
}
#endif
/* fatal error & exit */
void fatal(const char *format, ...)
{
va_list args;
va_start(args, format);
fprintf(stderr, "%s: ", elf2flt_progname);
vfprintf(stderr, format, args);
fprintf(stderr, "\n");
va_end(args);
exit(1);
}
/* fatal error, perror & exit */
void fatal_perror(const char *format, ...)
{
int e = errno;
va_list args;
va_start(args, format);
fprintf(stderr, "%s: ", elf2flt_progname);
vfprintf(stderr, format, args);
fprintf(stderr, ": %s\n", strerror(e));
va_end(args);
exit(1);
}
/* open a file or fail */
FILE *xfopen(const char *path, const char *mode)
{
FILE *ret = fopen(path, mode);
if (!ret)
fatal_perror("Unable to open '%s'", path);
return ret;
}
/* Append a string SRC to an options array DST */
void append_option(options_t *dst, const char *src)
{
if (dst->alloc == dst->num) {
size_t a = (dst->num + 2) * 2;
void *o = xmalloc(sizeof(*dst->options) * a);
memcpy(o, dst->options, sizeof(*dst->options) * dst->num);
free(dst->options);
dst->options = o;
dst->alloc = a;
}
dst->options[dst->num] = src;
dst->num++;
}
/* Split and append a string SRC to an options array DST */
void append_option_str(options_t *dst, const char *src, const char *delim)
{
char *tok_src = xstrdup(src);
char *tok = strtok(tok_src, delim);
while (tok) {
append_option(dst, tok);
tok = strtok(NULL, delim);
}
/* don't free tok_src since options_t now points to it */
}
/* Append an options array SRC to another options array DST */
void append_options(options_t *dst, const options_t *src)
{
if (dst->alloc < dst->num + src->num) {
size_t a = (dst->num + src->num + 2) * 2;
void *o = xmalloc(sizeof(*dst->options) * a);
memcpy(o, dst->options, sizeof(*dst->options) * dst->num);
free(dst->options);
dst->options = o;
dst->alloc = a;
}
memcpy(&dst->options[dst->num], &src->options[0],
sizeof(*dst->options) * src->num);
dst->num += src->num;
}

View File

@ -1,75 +0,0 @@
/* macros for conversion between host and (internet) network byte order */
#ifndef WIN32
# include <netinet/in.h> /* Consts and structs defined by the internet system */
# define BINARY_FILE_OPTS
#else
# include <winsock2.h>
# define BINARY_FILE_OPTS "b"
#endif
#ifndef __WIN32
# include <sys/wait.h>
#endif
#ifndef WIFSIGNALED
# define WIFSIGNALED(S) (((S) & 0xff) != 0 && ((S) & 0xff) != 0x7f)
#endif
#ifndef WTERMSIG
# define WTERMSIG(S) ((S) & 0x7f)
#endif
#ifndef WIFEXITED
# define WIFEXITED(S) (((S) & 0xff) == 0)
#endif
#ifndef WEXITSTATUS
# define WEXITSTATUS(S) (((S) & 0xff00) >> 8)
#endif
#ifndef WCOREDUMP
# define WCOREDUMP(S) ((S) & WCOREFLG)
#endif
#ifndef WCOREFLG
# define WCOREFLG 0200
#endif
#ifndef HAVE_STRSIGNAL
# define strsignal(sig) "SIG???"
#endif
#define streq(str1, str2) (strcmp(str1, str2) == 0)
#define streqn(str1, str2) (strncmp(str1, str2, strlen(str2)) == 0)
#ifndef DEBUG
# define DEBUG -1
#endif
#define _debug(lvl, fmt, args...) \
do { \
if (lvl <= DEBUG) { \
fprintf(stderr, "%s:%i: " fmt, __func__, __LINE__ , ## args); \
fflush(stderr); \
} \
} while (0)
#define debug2(...) _debug(2, __VA_ARGS__)
#define debug1(...) _debug(1, __VA_ARGS__)
#define debug0(...) _debug(0, __VA_ARGS__)
#define debug(...) debug0(__VA_ARGS__)
#ifndef HAVE_GETLINE
ssize_t getline(char **line, size_t *alloc, FILE *in);
#endif
extern const char *elf2flt_progname;
void fatal(const char *, ...);
void fatal_perror(const char *, ...);
FILE *xfopen(const char *path, const char *mode);
/* Structure to hold a list of options */
typedef struct
{
const char **options;
size_t num;
size_t alloc;
} options_t;
/* Initialize an options structure */
#define init_options(DST) ((DST)->options = NULL, (DST)->num = (DST)->alloc = 0)
void append_options(options_t *dst, const options_t *src);
void append_option(options_t *dst, const char *src);
void append_option_str(options_t *dst, const char *src, const char *delim);