Re: [PATCH 3/12] i386: Force section size to be non-zero to prevent a symbol becoming absolute

Vivek Goyal
2006-10-04T14:46:26Z

On Wed, Oct 04, 2006 at 08:07:36AM -0600, Eric W. Biederman wrote:
> Andi Kleen <ak@suse.de> writes:
>
> >> /* writeable */
> >> @@ -64,6 +66,7 @@ SECTIONS
> >> *(.data.nosave)
> >> . = ALIGN(4096);
> >> __nosave_end = .;
> >> + LONG(0)
> >> }
> >>
> >> . = ALIGN(4096);
> >
> > You're wasting one full page once for each of these LONG(0)s because
> > of the following 4096 alignment.
> >
> > Isn't there some way to do this less wastefull?
>
> So the problem is that we have sections that don't get relocated which
> confuses things. If the first that happened was that the size was
> check to see if it was non-zero before we did anything I think we
> wouldn't care if the linker messed up in this way.
>

Actually in this case if section size is zero, linker does not even
output that section and simply gets rid of it. What is left behind is
just the symbols (which were supposed to be section relative) and linker
just makes those symbols as absolute symbols. Absolute symbols are not
to be relocated so patch just filters out those symbols and they don't
get relocated. So I am not sure where can I check the section size?

One other possible solution is that kernel code is written carefully
so that we don't run into such problems even if absolute symbols don't
get relocated. For example, if there are two symbols A and B denoting
section start and end, always check if (A<B) before doing anything. Also
make sure that one is not trying to handle multiple sections at the same
time. For example, if A and B represents start and end for section 1
and C and D represent start and end for section 2 then one wants to
free memory between A and D , then it should be done in two steps.

if (A<B)
free_memory(A,B)
if (C<D)
free_memory(C,D)

So this code will become safe even if symbols for empty sections become
absolute.

But this looks to be very awkward solution.

Thanks
Vivek