How to make section take no space in output file?

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

How to make section take no space in output file?

Rick Mann
I'm building an embedded target binary that has a couple of large data  
structures (frame buffers and MMU tables). In the C code they're  
represented as arrays, and they're assigned to their own sections,  
which the linker script ensures are properly aligned. Two problems  
arise: the alignment introduces very large gaps in the file (corrected  
with the AT linker script directive), and they are large themselves  
(each framebuffer structure is nearly a megabyte in size).

As you can imagine, this makes downloads to the target time consuming.

I can (rather clumsily) deal with the alignment issue (the  
aforementioned AT), but how do I keep the sections from taking up any  
space? I could even make them overlap, but the largest one will still  
use up space. Since these have no data that needs to be written to the  
output file, it seems like there'd be an easy way to just say "this  
section shouldn't take up space in the file, and neither should the  
sections that follow".

If I understand ld correctly, this is how the .bss section behaves. It  
consumes no space in the resulting output file. How does the linker  
know to do this for .bss, and how do I get it to treat my other  
sections similarly?

Thanks very much!

--
Rick

Reply | Threaded
Open this post in threaded view
|

Re: How to make section take no space in output file?

DJ Delorie-2

If they're memory mapped devices, I think a better approach is to make
them "extern" in your C program, and assign them values in the linker
script or an auxiliary asm file, like this:

        .global framebuffer
framebuffer = 0xc8000000

If your C sources create data, the linker has to put it somewhere.
The solution is to not create data.

You could also try the DISCARD section, but whether it's useful or not
depends on your specific situation.
Reply | Threaded
Open this post in threaded view
|

Re: How to make section take no space in output file?

Rick Mann

On Jan 11, 2008, at 12:43 PM, DJ Delorie wrote:

>
> If they're memory mapped devices, I think a better approach is to make
> them "extern" in your C program, and assign them values in the linker
> script or an auxiliary asm file, like this:
>
>        .global framebuffer
> framebuffer = 0xc8000000
>
> If your C sources create data, the linker has to put it somewhere.
> The solution is to not create data.
>
> You could also try the DISCARD section, but whether it's useful or not
> depends on your specific situation.

They are not memory-mapped devices; they're strictly allocated RAM.  
The only requirement is that they be of specific size and alignment,  
and I'd like for the linker to just assign addresses accordingly.  
However, in the output file, they don't need to exist at all; I just  
want references to the symbols to have the right values at run time.

--
Rick

Reply | Threaded
Open this post in threaded view
|

Re: How to make section take no space in output file?

Daniel Jacobowitz-2
On Fri, Jan 11, 2008 at 02:11:31PM -0800, Rick Mann wrote:
> They are not memory-mapped devices; they're strictly allocated RAM. The
> only requirement is that they be of specific size and alignment, and I'd
> like for the linker to just assign addresses accordingly. However, in the
> output file, they don't need to exist at all; I just want references to
> the symbols to have the right values at run time.

I do not believe GCC offers an attribute to do what you want.  But
it's easy to do in assembly.  Look at the gcc -S output for a large
uninitialized array in .bss, and do it just like that with a different
section name.

--
Daniel Jacobowitz
CodeSourcery
Reply | Threaded
Open this post in threaded view
|

Re: How to make section take no space in output file?

H.J. Lu-27
In reply to this post by Rick Mann
On Fri, Jan 11, 2008 at 02:11:31PM -0800, Rick Mann wrote:

>
> On Jan 11, 2008, at 12:43 PM, DJ Delorie wrote:
>
>>
>> If they're memory mapped devices, I think a better approach is to make
>> them "extern" in your C program, and assign them values in the linker
>> script or an auxiliary asm file, like this:
>>
>>        .global framebuffer
>> framebuffer = 0xc8000000
>>
>> If your C sources create data, the linker has to put it somewhere.
>> The solution is to not create data.
>>
>> You could also try the DISCARD section, but whether it's useful or not
>> depends on your specific situation.
>
> They are not memory-mapped devices; they're strictly allocated RAM. The
> only requirement is that they be of specific size and alignment, and I'd
> like for the linker to just assign addresses accordingly. However, in the
> output file, they don't need to exist at all; I just want references to the
> symbols to have the right values at run time.

Have you tried "NOLOAD"? See

http://www.sourceware.org/bugzilla/show_bug.cgi?id=5522

However, this feature may a bug in linker:

http://sourceware.org/ml/binutils/2008-01/msg00083.html



H.J.
Reply | Threaded
Open this post in threaded view
|

Re: How to make section take no space in output file?

Alexander Neundorf
On Saturday 12 January 2008, H.J. Lu wrote:

> On Fri, Jan 11, 2008 at 02:11:31PM -0800, Rick Mann wrote:
> > On Jan 11, 2008, at 12:43 PM, DJ Delorie wrote:
> >> If they're memory mapped devices, I think a better approach is to make
> >> them "extern" in your C program, and assign them values in the linker
> >> script or an auxiliary asm file, like this:
> >>
> >>        .global framebuffer
> >> framebuffer = 0xc8000000
> >>
> >> If your C sources create data, the linker has to put it somewhere.
> >> The solution is to not create data.
> >>
> >> You could also try the DISCARD section, but whether it's useful or not
> >> depends on your specific situation.
> >
> > They are not memory-mapped devices; they're strictly allocated RAM. The
> > only requirement is that they be of specific size and alignment, and I'd
> > like for the linker to just assign addresses accordingly. However, in the
> > output file, they don't need to exist at all; I just want references to
> > the symbols to have the right values at run time.
>
> Have you tried "NOLOAD"? See
>
> http://www.sourceware.org/bugzilla/show_bug.cgi?id=5522
>
> However, this feature may a bug in linker:
>
> http://sourceware.org/ml/binutils/2008-01/msg00083.html

I had to do the same in an embedded system. I think I used something like
DISCARD or NOLOAD in the linker script, but with some version of binutils the
behaviour changed, and while this section wasn't loaded anymore, it was still
present in the output file (the section was around 60 MB big, so this was an
issue).
I think then I used objcopy --remove-section=<sectionname> to get completely
rid of the section.

Alex