Mark Wielaard 94ab0ae
commit 6f5934c1afa8f34bfb8f86b191ded9af854e757f
Mark Wielaard 94ab0ae
Author: Jan Kratochvil <jan.kratochvil@redhat.com>
Mark Wielaard 94ab0ae
Date:   Sat Feb 7 15:08:20 2015 +0100
Mark Wielaard 94ab0ae
Mark Wielaard 94ab0ae
    libelf: Consider sh_addralign 0 as 1
Mark Wielaard 94ab0ae
    
Mark Wielaard 94ab0ae
    Currently the Koji build for arm32 fails with:
Mark Wielaard 94ab0ae
    	extracting debug info from /builddir/build/BUILDROOT/etcd-2.0.0-0.3.rc1.fc22.arm/usr/bin/etcd
Mark Wielaard 94ab0ae
    	Failed to write file: invalid section alignment
Mark Wielaard 94ab0ae
    
Mark Wielaard 94ab0ae
    This is because the binary etcd
Mark Wielaard 94ab0ae
    	http://people.redhat.com/jkratoch/etcdctl.xz
Mark Wielaard 94ab0ae
    contains:
Mark Wielaard 94ab0ae
    	Section Headers:
Mark Wielaard 94ab0ae
    	  [Nr] Name              Type            Addr     Off    Size   ES Flg Lk Inf Al
Mark Wielaard 94ab0ae
    	  [11] .rel.plt          REL             00459ee0 449ee0 000088 08   A 13   0  0
Mark Wielaard 94ab0ae
    	                                                                               ^
Mark Wielaard 94ab0ae
    which corresponds to golang's code:
Mark Wielaard 94ab0ae
    	go/src/cmd/ld/elf.c
Mark Wielaard 94ab0ae
    		case EM_X86_64:
Mark Wielaard 94ab0ae
    			sh = elfshname(".rela.plt");
Mark Wielaard 94ab0ae
    			sh->addralign = RegSize;
Mark Wielaard 94ab0ae
    		default:
Mark Wielaard 94ab0ae
    			sh = elfshname(".rel.plt");
Mark Wielaard 94ab0ae
    			<nothing>
Mark Wielaard 94ab0ae
    
Mark Wielaard 94ab0ae
    ELF spec says:
Mark Wielaard 94ab0ae
    	Values 0 and 1 mean the section has no alignment constraints.
Mark Wielaard 94ab0ae
    and libelf/elf32_updatenull.c really parses it that way at line 204
Mark Wielaard 94ab0ae
    	ElfW2(LIBELFBITS,Word) sh_align = shdr->sh_addralign ?: 1;
Mark Wielaard 94ab0ae
    but unfortunately the later line being patched no longer does.
Mark Wielaard 94ab0ae
    
Mark Wielaard 94ab0ae
    libelf/
Mark Wielaard 94ab0ae
    2015-02-07  Jan Kratochvil  <jan.kratochvil@redhat.com>
Mark Wielaard 94ab0ae
    
Mark Wielaard 94ab0ae
    	* elf32_updatenull.c (__elfw2(LIBELFBITS,updatenull_wrlock)): Consider
Mark Wielaard 94ab0ae
    	sh_addralign 0 as 1.
Mark Wielaard 94ab0ae
    
Mark Wielaard 94ab0ae
    Signed-off-by: Jan Kratochvil <jan.kratochvil@redhat.com>
Mark Wielaard 94ab0ae
Mark Wielaard 94ab0ae
diff --git a/libelf/elf32_updatenull.c b/libelf/elf32_updatenull.c
Mark Wielaard 94ab0ae
index be4cea0..5e809b7 100644
Mark Wielaard 94ab0ae
--- a/libelf/elf32_updatenull.c
Mark Wielaard 94ab0ae
+++ b/libelf/elf32_updatenull.c
Mark Wielaard 94ab0ae
@@ -328,7 +328,7 @@ __elfw2(LIBELFBITS,updatenull_wrlock) (Elf *elf, int *change_bop, size_t shnum)
Mark Wielaard 94ab0ae
 		     enough for the largest alignment required by a data
Mark Wielaard 94ab0ae
 		     block.  */
Mark Wielaard 94ab0ae
 		  if (unlikely (! powerof2 (shdr->sh_addralign))
Mark Wielaard 94ab0ae
-		      || unlikely (shdr->sh_addralign < sh_align))
Mark Wielaard 94ab0ae
+		      || unlikely ((shdr->sh_addralign ?: 1) < sh_align))
Mark Wielaard 94ab0ae
 		    {
Mark Wielaard 94ab0ae
 		      __libelf_seterrno (ELF_E_INVALID_ALIGN);
Mark Wielaard 94ab0ae
 		      return -1;