[SeaBIOS] [PATCH] ld: fix .text section address alignment

Roger Pau Monné roger.pau at citrix.com
Mon Feb 22 12:07:00 CET 2016


El 20/2/16 a les 3:41, Kevin O'Connor ha escrit:
> On Tue, Feb 16, 2016 at 06:21:10PM +0100, Roger Pau Monné wrote:
>> El 16/2/16 a les 17:33, Kevin O'Connor ha escrit:
>>> On Tue, Feb 16, 2016 at 01:56:26PM +0100, Roger Pau Monne wrote:
>>>> According to the output from readelf, the .text section should be aligned to
>>>> 16:
>>>>
>>>> Section Headers:
>>>>   [Nr] Name              Type            Addr     Off    Size   ES Flg Lk Inf Al
>>>>   [ 0] (null)            NULL            00000000 000000 000000 00      0   0  0
>>>>   [ 1] .text             PROGBITS        000de300 000300 021d00 00  AX  0   0 16
>>>> [...]
>>>>
>>>> This however doesn't seem to be enforced when the relocations are generated.
>>>> The following patch tries to address this by making sure the space used for
>>>> the relocations it also aligned to the same value as the .text section.
>>>
>>> Thanks.  What goes wrong if the .text section is not aligned?  The
>>> code has already been assigned physical addresses by this point, so it
>>> should not impact the runtime code.
>>
>> It seems like ELF toolchain objcopy chokes if a section address is not
>> aligned to the alignment specified by the section, see:
>>
>> https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=207170
>>
>> The snippet shown above has addr aligned to 16 (which matches latest
>> upstream), so it's not a problem, but the current SeaBIOS version
>> shipped in Xen 4.5 (1.7.5 IIRC) ends up with an addr that's not a
>> multiple of 16, as shown in the bug report, and objcopy complains with:
>>
>> objcopy: elf_update() failed: Layout constraint violation
> 
> Thanks.  I agree it should be fixed.  However, I think there are a few
> other cases that could cause the ".text" section alignment to be off.
> Are you okay with the patch below instead?

Yes, looks fine to me. AFAICT SeaBIOS packs all the sections (.text,
.data, .rodata) ibnside of the .text section, which I didn't realize before.

Roger



More information about the SeaBIOS mailing list