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.
Signed-off-by: Roger Pau Monné firstname.lastname@example.org Reported by: Ed Maste emaste@FreeBSD.org
Cc: Kevin O'Connor email@example.com
scripts/layoutrom.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/scripts/layoutrom.py b/scripts/layoutrom.py index b976fb0..5534a9e 100755 --- a/scripts/layoutrom.py +++ b/scripts/layoutrom.py @@ -397,7 +397,7 @@ def writeLinkerScripts(li, out16, out32seg, out32flat): + strRelocs("_reloc_rel", "code32init_start", relrelocs) + strRelocs("_reloc_init", "code32flat_start", initrelocs)) numrelocs = len(absrelocs + relrelocs + initrelocs)
sec32all_start -= numrelocs * 4
sec32all_start -= alignpos(numrelocs * 4, li.sec32low_align)
I think this would need to find and use the maximum alignment of every section that goes into ".text" and not just the alignment of "sec32low" sections.