This is the mail archive of the
elfutils-devel@sourceware.org
mailing list for the elfutils project.
Re: [patch] libelf: Consider sh_addralign 0 as 1
- From: Mark Wielaard <mjw at redhat dot com>
- To: elfutils-devel at lists dot fedorahosted dot org
- Date: Fri, 06 Feb 2015 09:04:25 +0100
- Subject: Re: [patch] libelf: Consider sh_addralign 0 as 1
On Thu, 2015-02-05 at 21:42 +0100, Jan Kratochvil wrote:
> Section Headers:
> [Nr] Name Type Addr Off Size ES Flg Lk Inf Al
> [11] .rel.plt REL 00459ee0 449ee0 000088 08 A 13 0 0
> ^
> which corresponds to golang's code:
> go/src/cmd/ld/elf.c
> case EM_X86_64:
> sh = elfshname(".rela.plt");
> sh->addralign = RegSize;
> default:
> sh = elfshname(".rel.plt");
> <nothing>
I do think that is by accident, and actually a bug. It might be that no
alignment works here because the result isn't relinked ever and they
make sure the ELF file they write out is hand aligned. But it is at
least a little sloppy. If nothing else a comment why this is fine would
be a good idea.
> ELF spec says:
> Values 0 and 1 mean the section has no alignment constraints.
> and libelf/elf32_updatenull.c really parses it that way at line 204
> ElfW2(LIBELFBITS,Word) sh_align = shdr->sh_addralign ?: 1;
> but unfortunately the later line being patched no longer does.
>
> The problem is that the reproducer is 1.5MB as .xz and with some reasonable
> effort I have not found a smaller one. golang builds everything statically
> and this .rel.plt seems to me rather as a bug but I do not know it so much.
Agreed that is is most likely a bug in golang. But your analyzes that we
do something wrong in elfutils by not handling sh_addralign consistently
is correct.
> Anyway I find the fix obvious enough it could possibly go even without
> a testcase?
Yes, thanks.