binutils-2.18 and U-Boot
Tue Dec 11 03:00:00 GMT 2007

Hello Everybody,

I ran into 2 problems linking u-boot with binutils-2.18 for a 
target.  I need help with the first problem.  The second problem I fixed
and resolves bug 5205.

Problem 1:
Two segments are produced in linking u-boot.  The first segment begins 
address 0xfff80000 and is size 0x8a400.  This segment wraps past the
end of memory (0xfff80000 + 0x8a400 = 0x0000a400) and causes a link 
of the form "section .text can't be allocated in segment 0".  This error
makes sense. However, the .bss segment is what's pushing the size past
the end of memory.  The .bss section is size 0x50100.  We don't want the
.bss section to be stored in the image since u-boot is stored in flash 
0xfff80000 and then copies itself to RAM in low memory, such as address
0x0, fills out the GOT for data and bss access, and zeroes the .bss
itself.  How can we avoid the above error message?  The error is 
from line 4362 in elf.c in the binutils-2.18 release.  I don't quite
understand the intention of the error check.  In looking at it, the 
check is only done if the segment is a LOAD segment, so should we fill 
a PHDR table and put the .bss section in a no load phdr?  If it's only 
for a LOAD segment, that would suggest the check shouldn't include 
sections.  However, putting a NOLOAD in the link script for the .bss 
still has the error.  I guess I'm confused whether the link error is 
due to
a bug in the code or something I need to modify in the link script or 
just invliad to have the .bss wrap off memory?  Thanks for any help.

Problem 2:
The other segment produced in linking u-boot begins at address 
and is of size 0x1000.  This segment produces a link error, also 
 from line 4362 in elf.c, "section .prog can't be allocated in segment 
However, in this scenario all sections definitely fit within the 
but the macro ELF_IS_SECTION_IN_SEGMENT always returns 0.  This is 
the macro checks, among other things, whether (section address +
section size <= segment address + segment size).  Segment address + 
size is 0 because it wraps (0xfffff000 + 0x1000 = 0), so the check never
passes.  The fix is below.  I'm new at this, can I simply check it in or
do I need to follow a special process?  Also, this bug has been 
reported as
bug 5205  Can I
mark it as fixed, or again, do I need to follow a special process?  I
apologize if the process is posted somewhere, but I can't find it.

 diff -Naur a/include/elf/internal.h b/include/elf/internal.h
--- a/include/elf/internal.h    2007-08-06 12:59:47.000000000 -0700
+++ b/include/elf/internal.h    2007-12-06 18:36:50.062500000 -0800
@@ -278,13 +278,13 @@
       offset within the segment.  */                    \
    && (sec_hdr->sh_type == SHT_NOBITS                    \
        || ((bfd_vma) sec_hdr->sh_offset >= segment->p_offset        \
-       && (sec_hdr->sh_offset + ELF_SECTION_SIZE(sec_hdr, segment)    \
-           <= segment->p_offset + segment->p_filesz)))        \
+       && (sec_hdr->sh_offset + ELF_SECTION_SIZE(sec_hdr, segment) - 1 
+           <= segment->p_offset + segment->p_filesz - 1)))        \
     /* SHF_ALLOC sections must have VMAs within the segment.  */        
    && ((sec_hdr->sh_flags & SHF_ALLOC) == 0                \
        || (sec_hdr->sh_addr >= segment->p_vaddr                \
-       && (sec_hdr->sh_addr + ELF_SECTION_SIZE(sec_hdr, segment)    \
-           <= segment->p_vaddr + segment->p_memsz))))
+       && (sec_hdr->sh_addr + ELF_SECTION_SIZE(sec_hdr, segment) - 1   
+           <= segment->p_vaddr + segment->p_memsz - 1))))

 /* Decide if the given sec_hdr is in the given segment in file.  */
 #define ELF_IS_SECTION_IN_SEGMENT_FILE(sec_hdr, segment)


More new features than ever.  Check out the new AIM(R) Mail ! -

More information about the Binutils mailing list