Created attachment 7659 [details] Patch that makes _bfd_elf_make_section_from_shdr() not fail when sh_addralign is 0 or 1 Preamble: I'm being a bit verbose here because it's the first time I dig deep into a toolchain and maybe I'm just too stupid to see the obvious... My goal is to build a toolchain for a little-endian ARM 926ej-s CPU. Buildsystem is a x86_64-pc-linux-gnu. I built the binutils 2.24.0 and gcc 4.9.0. Building glibc then failed in configure script with checking for .preinit_array/.init_array/.fini_array support... no configure: error: Need linker with .init_array/.fini_array support. It turned out that my gcc could not even compile the most simple file because a temporary file created by gas could later not be read by ld ("file not recognized: Bad value"). Digging deeper, I noticed that when doing "make check-gas" in binutils, almost half of the tests failed. Debugging the stuff, I found that _bfd_elf_make_section_from_shdr() fails when bfd_set_section_alignment() fails. That function however only returns the alignment found, and according to the description of sh_addralign in "man 5 elf", 0 is a valid value for that. With attached patch, "make check-gas" succeeds in all test cases and I can build a glibc. Due to other problems I could not build a full toolchain yet, so please be careful with the patch.. Thanks! PS: here's the configure line I used for binutils: ./configure --build=x86_64-pc-linux-gnu --host=x86_64-pc-linux-gnu --target=arm-926ejs-linux-gnueabi --prefix=/usr/local/arm/cross-gcc-4.9.0-armv5te-soft/x86_64-pc-linux-gnu --enable-serial-configure --with-sysroot=/usr/local/arm/cross-gcc-4.9.0-armv5te-soft/x86_64-pc-linux-gnu/arm-926ejs-linux-gnueabi/sys-root -v
bfd_set_section_alignment never fails, so either your analysis is wrong or you have applied some patches to 2.24
It does not fail, but it (correctly) returns 0. And when it does, _bfd_make_section_from_shdr() returns FALSE, which is the problem. Sorry for the unclear wording.
From binutils-2.24 bfd/bfd-in2.h: #define bfd_set_section_alignment(bfd, ptr, val) (((ptr)->alignment_power = (val)),TRUE) How can that possibly be zero? Ditto for the current binutils inline function.
ahhh ok I see, I removed the ",TRUE" part of the statement in an earlier step because of this compilation error: gcc -DHAVE_CONFIG_H -I. -I. -I. -I../bfd -I./config -I./../include -I./.. -I./../bfd -DLOCALEDIR="\"/usr/local/arm/cross-gcc-4.9.0-armv5te-soft/x86_64-pc-linux-gnu/share/locale\"" -W -Wall -Wstrict-prototypes -Wmissing-prototypes -Wshadow -Werror -g -O2 -MT write.o -MD -MP -MF .deps/write.Tpo -c -o write.o write.c In file included from as.h:95:0, from write.c:25: write.c: In function ‘record_alignment’: ../bfd/bfd.h:303:83: error: right-hand operand of comma expression has no effect [-Werror=unused-value] #define bfd_set_section_alignment(bfd, ptr, val) (((ptr)->alignment_power = (val)),TRUE) ^ write.c:366:5: note: in expansion of macro ‘bfd_set_section_alignment’ bfd_set_section_alignment (stdoutput, seg, align); ^ Sorry, my bad. Should I close this bug and open a new one for the compilation problem?
It seems that explicitly casting the result of bfd_set_section_alignment() and the other macros that have that ",TRUE" section to void calms down the compiler
The compilation problem has already been fixed on mainline, so opening a bug about that is not necessary.