[PATCH] Fail on erroneous linker script

Maxim Kuvyrkov maxim@codesourcery.com
Fri Dec 4 17:04:00 GMT 2009


Hello,

The attached patch fixes a linker problem that may cause the linker to 
accept an erroneous linker script and produce a broken binary.

The essence of the problem is that any PROGBITS section that follows a 
NOBITS section in a PT_LOAD segment will end up at the wrong offset when 
loaded into memory.

In most valid cases NOBITS sections (.bss, usually) are placed at the 
end of the loaded segments.  However, if a user provides a custom linker 
scripts which puts, a .bss section in the middle of the data segment, 
the linker will produce a broken binary.  The proper behavior for linker 
is to fail with appropriate error message.

One exception to the above rule is a .tbss section in a PT_LOAD segment, 
such a section doesn't take space in neither file nor the memory 
segment, so it is OK.

To fix the problem the patch places the sanity check into the code that 
assigns file offsets to the LOAD sections: when a NOBITS section is 
seen, the file offset is assumed to be invalid for any subsequent 
PROGBITS section within the current segment.  The error is then thrown 
if an attempt to use the invalid offset is made.

This patch was tested on i686-linux-gnu with no fails.  Also, it fixes 
the motivating case which is building 2.6.23 version of the linux kernel 
for ColdFire.

OK for mainline?

Regards,

-- 
Maxim Kuvyrkov
CodeSourcery
maxim@codesourcery.com
(650) 331-3385 x724
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: fsf-binutils-nobits.ChangeLog
URL: <https://sourceware.org/pipermail/binutils/attachments/20091204/e0c47c64/attachment.ksh>
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: fsf-binutils-nobits.patch
URL: <https://sourceware.org/pipermail/binutils/attachments/20091204/e0c47c64/attachment-0001.ksh>


More information about the Binutils mailing list