public inbox for elfutils@sourceware.org
 help / color / mirror / Atom feed
* Re: [patch] libelf: Consider sh_addralign 0 as 1
@ 2015-02-06  8:04 Mark Wielaard
  0 siblings, 0 replies; 2+ messages in thread
From: Mark Wielaard @ 2015-02-06  8:04 UTC (permalink / raw)
  To: elfutils-devel

[-- Attachment #1: Type: text/plain, Size: 1649 bytes --]

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.

^ permalink raw reply	[flat|nested] 2+ messages in thread

* [patch] libelf: Consider sh_addralign 0 as 1
@ 2015-02-05 20:42 Jan Kratochvil
  0 siblings, 0 replies; 2+ messages in thread
From: Jan Kratochvil @ 2015-02-05 20:42 UTC (permalink / raw)
  To: elfutils-devel

[-- Attachment #1: Type: text/plain, Size: 3282 bytes --]

Hi,

jankratochvil/addralignzero

for
	etcd: missing debug info
	https://bugzilla.redhat.com/show_bug.cgi?id=1184257
I need this fix as currently the Koji build for arm32 fails with:
	https://kojipkgs.fedoraproject.org//work/tasks/1910/8721910/build.log
	extracting debug info from /builddir/build/BUILDROOT/etcd-2.0.0-0.3.rc1.fc22.arm/usr/bin/etcd
	Failed to write file: invalid section alignment

This is because the binary etcd
	http://people.redhat.com/jkratoch/etcdctl.xz
contains:
	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>

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.

Anyway I find the fix obvious enough it could possibly go even without
a testcase?

Commandline for easier reproducibility with debugedit, to be adjusted as needed:
	cd fedora/rpm/master/rpm-4.12.0.1
	depbase=`echo tools/debugedit.o | sed 's|[^/]*$|.deps/&|;s|\.o$||'`;gcc -std=gnu99 -DHAVE_CONFIG_H   -I. -I. -I./include/ -I./build -I./lib -I./rpmio -I./misc -DLOCALEDIR="\"/usr/share/locale\"" -DLIBRPMALIAS_FILENAME="\"rpmpopt-4.12.0.1\"" -I/usr/include/nss3 -I/usr/include/nspr4  -DLUA_COMPAT_APIINTCASTS  -g -pipe -Wall -Werror=format-security -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches  -m64 -mtune=generic  -DLUA_COMPAT_APIINTCASTS -fPIC -DPIC -D_REENTRANT -Wall -Wpointer-arith -Wmissing-prototypes -Wstrict-prototypes  -fno-strict-aliasing -fstack-protector -Wempty-body -MT tools/debugedit.o -MD -MP -MF $depbase.Tpo -c -o tools/debugedit.o tools/debugedit.c &&mv -f $depbase.Tpo $depbase.Po;gcc -std=gnu99 -g -pipe -Wall -Werror=format-security -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic -DLUA_COMPAT_APIINTCASTS -fPIC -DPIC -D_REENTRANT -Wall -Wpointer-arith -Wmissing-prototypes -Wstrict-prototypes -fno-strict-aliasing -fstack-protector -Wempty-body -o .libs/debugedit tools/debugedit.o tools/hashtab.o  rpmio/.libs/librpmio.so -lnss3 -lbz2 -lz -llzma -llua -lm -lelf -lpopt -ldl -lpthread
	cp -p ~/t/etcdctl-orig ~/t/etcdctl;LD_LIBRARY_PATH=$HOME/redhat/elfutils/backends:$HOME/redhat/elfutils/libdw:$HOME/redhat/elfutils/libelf:$HOME/redhat/elfutils/libasm gdb -q -ex start -ex 'b elf_update' -ex c -ex 'adv __libelf_seterrno' -ex up --args ./.libs/debugedit -b /root/jkratoch/redhat/etcd/master -d /usr/src/debug -i -l /tmp/debugsources.list ~/t/etcdctl 


Thanks,
Jan

[-- Attachment #2: attachment.mht --]
[-- Type: message/rfc822, Size: 47 bytes --]


WzxlbWFpbC5tZXNzYWdlLk1lc3NhZ2UgaW5zdGFuY2UgYXQgMHgxNTRhMDUwPl0=

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2015-02-06  8:04 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-02-06  8:04 [patch] libelf: Consider sh_addralign 0 as 1 Mark Wielaard
  -- strict thread matches above, loose matches on Subject: below --
2015-02-05 20:42 Jan Kratochvil

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).