This is the mail archive of the
binutils@sources.redhat.com
mailing list for the binutils project.
Re: PATCH: gas .incbin pseudo-op
- To: Anders Norlander <anorland at synergenix dot se>
- Subject: Re: PATCH: gas .incbin pseudo-op
- From: Daniel Jacobowitz <dmj+ at andrew dot cmu dot edu>
- Date: Fri, 6 Jul 2001 02:01:56 -0700
- Cc: Alan Modra <amodra at bigpond dot net dot au>,Binutils List <binutils at sources dot redhat dot com>
- References: <993829827.23471.10.camel@localhost> <20010705234829.U16275@bubble.sa.bigpond.net.au> <994408160.16847.0.camel@localhost>
On Fri, Jul 06, 2001 at 10:29:20AM +0200, Anders Norlander wrote:
> On 05 Jul 2001 23:48:29 +0930, Alan Modra wrote:
> > On Fri, Jun 29, 2001 at 05:52:34PM +0200, Anders Norlander wrote:
> > >
> > > this patch adds a .incbin directive to gas to include files
> > > verbatim at the current location, as found in many other assemblers.
> > > I'm a bit surprised this has not come up before, but the archives
> > > didn't reveal anything.
> >
> > Hi Anders,
> > It's already possible to include binary files using the linker, which
> > is probably why no one has found this feature necessary.
>
> Yeah, that's possible but not as flexible. With .incbin you can do
> it directly from C (or whatever), like this
> #define INCBIN(symname, filename) \
> __asm__ (".section .rodata ; .align 2; .globl " symname); \
> __asm__ (symname ":\n.incbin \"" filename "\""); \
> extern unsigned char symname[];
>
> INCBIN(resource, "resource.dat");
>
> This can be extremely useful to include graphics/sound/tables etc.
> and have full control over symbols, sections and data included
> from the file without having to modify your linker command and/or
> linker script. Many people use objcopy to convert the binary into
> a real object file, but that adds an extra conversion step to the
> procedure, so I think it can be really useful.
I'll add another use for this - one which would be properly solved
elsewhere, but this would at least be a convenient workaround. Many
ELF flags are set only by gas, and checked by the linker; objcopy has
no way to specify them. A good example are the e_flags ABI bits on
MIPS. It's tricky to link a piece of binary data into a -mips2 kernel;
we do it currently by editing the flags by hand. This would let us
leverage gas's command line to set them.
--
Daniel Jacobowitz Carnegie Mellon University
MontaVista Software Debian GNU/Linux Developer