On Thu, 20 May 2010, Kai Wang wrote: > The elf_getbase() API in FreeBSD libelf can only be called using an > archive member ELF descriptor. It will return -1 (indicates an error) > when called with a "regular" ELF object. > > The lto_obj_build_section_table() function in lto-elf.c calls > elf_getbase() to get the offset base for a "regular" ELF object. On > FreeBSD it gets -1. (Side notes: lto-elf.c should really check return > values of libelf APIs) And later it uses -1 as base_offset for all the > ELF sections thus results in an off-by-one error when passing the > section data to zlib to inflate. > > Could you please try applying the attached patch to the libelf in > FreeBSD 7.3 and see if it fixes gcc4.6 lto?
Thanks, Kai! This patch to FreeBSD's libelf significantly improves test results from http://gcc.gnu.org/ml/gcc-testresults/2010-05/msg02081.html to http://gcc.gnu.org/ml/gcc-testresults/2010-05/msg02150.html Some detailed numbers: === g++ Summary === vanilla patched libelf # of expected passes 22876 23118 # of unexpected failures 425 142 # of expected failures 151 151 # of unresolved testcases 124 66 # of unsupported tests 150 150 === gcc Summary === # of expected passes 64021 67099 # of unexpected failures 3806 1667 # of unexpected successes 1 1 # of expected failures 171 171 # of unresolved testcases 2580 1292 # of unsupported tests 1284 1284 === gfortran Summary === # of expected passes 34094 34122 # of unexpected failures 48 27 # of expected failures 22 22 # of unresolved testcases 37 16 # of unsupported tests 266 266 Based on this, it will be great if you can apply your patch to -CURRENT, 8-STABLE and 7-STABLE. >From what I can tell, this patch of yours fixes LTO in GCC. Looking at the remaining failures, it is now only the somewhat related WHOPR optimization in GCC that remains broken: % cat x.c int main() { } % gccvs -flto x.c % gccvs -fwhopr x.c lto1: fatal error: elf_update() failed: Layout constraint violation compilation terminated. lto-wrapper: gccvs returned 1 exit status collect2: lto-wrapper returned 1 exit status Gerald