Commit 3bec79c5 by Dave Korn Committed by Dave Korn

re PR lto/42776 (LTO doesn't work on non-ELF platforms.)

ChangeLog:

	PR lto/42776
	* configure.ac (--enable-lto): Refactor handling so libelf tests
	are only performed inside then-clause of ACX_ELF_TARGET_IFELSE,
	and allow LTO to be explicitly enabled on non-ELF platforms that
	are known to support it inside else-clause.
	* configure: Regenerate.

gcc/ChangeLog:

	PR lto/42776
	* configure.ac (gcc_cv_as_section_has_align): Set if installed
	binutils supports extended .section directive needed by LTO, or
	warn if older binutils found.
	(LTO_BINARY_READER): New AC_SUBST'd variable.
	(LTO_USE_LIBELF): Likewise.
	* gcc/config.gcc (lto_binary_reader): New target-specific configure
	variable.
	* gcc/Makefile.in (LTO_BINARY_READER): Import AC_SUBST'd autoconf var.
	(LTO_USE_LIBELF): Likewise.
	* configure: Regenerate.

	* collect2.c (is_elf): Rename from this ...
	(is_elf_or_coff): ... to this, and recognize and allow i386 COFF
	 object files in addition to ELF-formatted ones.
	(scan_prog_file): Caller updated.  Also allow for LTO info marker
	symbol to be prefixed or not by an extra underscore.

	* config/i386/t-cygming (winnt.o): Also depend on LTO_STREAMER_H.
	* config/i386/winnt.c: Also #include lto-streamer.h
	(i386_pe_asm_named_section): Specify 1-byte section alignment for
	LTO named sections.
	(i386_pe_asm_output_aligned_decl_common): Add comment.
	(i386_pe_maybe_record_exported_symbol): Allow decl arg to be NULL.

gcc/lto/ChangeLog:

	PR lto/42776
	* Make-lang.in (LTO_OBJS): Use LTO_BINARY_READER instead of
	hardcoding 'lto-elf.o'.
	($(LTO_EXE)): Use LTO_USE_LIBELF instead of hardcoding '-lelf'.

	* lto-coff.h: New file.
	* lto-coff.c: Likewise.

gcc/testsuite/ChangeLog:

	PR lto/42776
	* lib/lto.exp (lto_prune_vis_warns): New function.
	(lto-link-and-maybe-run): Call it.

From-SVN: r158762
parent 45c384e3
2010-04-27 Dave Korn <dave.korn.cygwin@gmail.com>
PR lto/42776
* configure.ac (--enable-lto): Refactor handling so libelf tests
are only performed inside then-clause of ACX_ELF_TARGET_IFELSE,
and allow LTO to be explicitly enabled on non-ELF platforms that
are known to support it inside else-clause.
* configure: Regenerate.
2010-04-20 Eric Botcazou <ebotcazou@adacore.com>
* configure.ac (BUILD_CONFIG): Redirect output to /dev/null.
......
......@@ -1637,17 +1637,8 @@ AC_ARG_ENABLE(lto,
enable_lto=$enableval,
enable_lto=yes; default_enable_lto=yes)
ACX_ELF_TARGET_IFELSE([],
if test x"$default_enable_lto" = x"yes" ; then
enable_lto=no
else
if test x"$enable_lto" = x"yes"; then
AC_MSG_ERROR([LTO support requires an ELF target.])
fi
fi
default_enable_lto=no)
if test x"$enable_lto" = x"yes" ; then
ACX_ELF_TARGET_IFELSE([if test x"$enable_lto" = x"yes" ; then
# Make sure that libelf.h and gelf.h are available.
AC_ARG_WITH(libelf, [ --with-libelf=PATH Specify prefix directory for the installed libelf package
Equivalent to --with-libelf-include=PATH/include
......@@ -1783,7 +1774,24 @@ to specify its location.])
# Flags needed for libelf.
AC_SUBST(libelflibs)
AC_SUBST(libelfinc)
fi
fi],[if test x"$default_enable_lto" = x"yes" ; then
# On non-ELF platforms, LTO must be explicitly enabled.
enable_lto=no
else
# Apart from ELF platforms, only Windows supports LTO so far. It
# would also be nice to check the binutils support, but we don't
# have gcc_GAS_CHECK_FEATURE available here. For now, we'll just
# warn during gcc/ subconfigure; unless you're bootstrapping with
# -flto it won't be needed until after installation anyway.
case $target in
*-cygwin*|*-mingw*) ;;
*) if test x"$enable_lto" = x"yes"; then
AC_MSG_ERROR([LTO support is not enabled for this target.])
fi
;;
esac
fi
default_enable_lto=no])
# By default, C is the only stage 1 language.
......
......@@ -326,6 +326,10 @@ LIBELFINC = @LIBELFINC@
# Set to 'yes' if the LTO front end is enabled.
enable_lto = @enable_lto@
# Set according to LTO object file format.
LTO_BINARY_READER = @LTO_BINARY_READER@
LTO_USE_LIBELF = @LTO_USE_LIBELF@
# Compiler needed for plugin support
PLUGINCC = @CC@
......
......@@ -2548,19 +2548,21 @@ write_aix_file (FILE *stream, struct id *list)
be in ELF format. */
static bool
is_elf (const char *prog_name)
is_elf_or_coff (const char *prog_name)
{
FILE *f;
char buf[4];
static char magic[4] = { 0x7f, 'E', 'L', 'F' };
static char coffmag[2] = { 0x4c, 0x01 };
f = fopen (prog_name, "r");
f = fopen (prog_name, "rb");
if (f == NULL)
return false;
if (fread (buf, sizeof (buf), 1, f) != 1)
buf[0] = 0;
fclose (f);
return memcmp (buf, magic, sizeof (magic)) == 0;
return memcmp (buf, magic, sizeof (magic)) == 0
|| memcmp (buf, coffmag, sizeof (coffmag)) == 0;
}
/* Generic version to scan the name list of the loaded program for
......@@ -2587,10 +2589,10 @@ scan_prog_file (const char *prog_name, scanpass which_pass,
if (which_pass == PASS_SECOND)
return;
/* LTO objects must be in ELF format. This check prevents
/* LTO objects must be in a known format. This check prevents
us from accepting an archive containing LTO objects, which
gcc cannnot currently handle. */
if (which_pass == PASS_LTOINFO && !is_elf (prog_name))
if (which_pass == PASS_LTOINFO && !is_elf_or_coff (prog_name))
return;
/* If we do not have an `nm', complain. */
......@@ -2670,9 +2672,9 @@ scan_prog_file (const char *prog_name, scanpass which_pass,
/* Look for the LTO info marker symbol, and add filename to
the LTO objects list if found. */
for (p = buf; (ch = *p) != '\0' && ch != '\n'; p++)
if (ch == ' '
&& (strncmp (p + 1, "__gnu_lto_v1", 12) == 0)
&& ISSPACE (p[13]))
if (ch == ' ' && p[1] == '_' && p[2] == '_'
&& (strncmp (p + (p[3] == '_' ? 2 : 1), "__gnu_lto_v1", 12) == 0)
&& ISSPACE (p[p[3] == '_' ? 14 : 13]))
{
add_lto_object (&lto_objects, prog_name);
......
......@@ -200,6 +200,8 @@ default_use_cxa_atexit=no
target_gtfiles=
need_64bit_hwint=
need_64bit_isa=
# Selects the object file format reader/writer used by LTO.
lto_binary_reader=lto-elf
# Don't carry these over build->host->target. Please.
xm_file=
......@@ -1324,6 +1326,7 @@ i[34567]86-*-pe | i[34567]86-*-cygwin*)
thread_file='posix'
fi
use_gcc_stdint=wrap
lto_binary_reader=lto-coff
;;
i[34567]86-*-mingw* | x86_64-*-mingw*)
tm_file="${tm_file} i386/unix.h i386/bsd.h i386/gas.h dbxcoff.h i386/cygming.h i386/mingw32.h"
......@@ -1391,6 +1394,7 @@ i[34567]86-*-mingw* | x86_64-*-mingw*)
cxx_target_objs="${cxx_target_objs} winnt-cxx.o msformat-c.o"
default_use_cxa_atexit=yes
use_gcc_stdint=wrap
lto_binary_reader=lto-coff
case ${enable_threads} in
"" | yes | win32) thread_file='win32'
tmake_file="${tmake_file} i386/t-gthr-win32"
......
......@@ -30,7 +30,7 @@ LIBGCC2_INCLUDES = -I$(srcdir)/../winsup/w32api/include
winnt.o: $(srcdir)/config/i386/winnt.c $(CONFIG_H) $(SYSTEM_H) coretypes.h \
$(TM_H) $(RTL_H) $(REGS_H) hard-reg-set.h output.h $(TREE_H) flags.h \
$(TM_P_H) toplev.h $(HASHTAB_H) $(GGC_H)
$(TM_P_H) toplev.h $(HASHTAB_H) $(GGC_H) $(LTO_STREAMER_H)
$(COMPILER) -c $(ALL_COMPILERFLAGS) $(ALL_CPPFLAGS) $(INCLUDES) \
$(srcdir)/config/i386/winnt.c
......
......@@ -35,6 +35,7 @@ along with GCC; see the file COPYING3. If not see
#include "langhooks.h"
#include "ggc.h"
#include "target.h"
#include "lto-streamer.h"
/* i386/PE specific attribute support.
......@@ -465,6 +466,12 @@ i386_pe_asm_named_section (const char *name, unsigned int flags,
*f++ = 's';
}
/* LTO sections need 1-byte alignment to avoid confusing the
zlib decompression algorithm with trailing zero pad bytes. */
if (strncmp (name, LTO_SECTION_NAME_PREFIX,
strlen (LTO_SECTION_NAME_PREFIX)) == 0)
*f++ = '0';
*f = '\0';
fprintf (asm_out_file, "\t.section\t%s,\"%s\"\n", name, flagchars);
......@@ -485,6 +492,8 @@ i386_pe_asm_named_section (const char *name, unsigned int flags,
}
}
/* Beware, DECL may be NULL if compile_file() is emitting the LTO marker. */
void
i386_pe_asm_output_aligned_decl_common (FILE *stream, tree decl,
const char *name, HOST_WIDE_INT size,
......@@ -581,7 +590,8 @@ static GTY(()) struct export_list *export_head;
these, so that we can output the export list at the end of the
assembly. We used to output these export symbols in each function,
but that causes problems with GNU ld when the sections are
linkonce. */
linkonce. Beware, DECL may be NULL if compile_file() is emitting
the LTO marker. */
void
i386_pe_maybe_record_exported_symbol (tree decl, const char *name, int is_data)
......@@ -589,6 +599,9 @@ i386_pe_maybe_record_exported_symbol (tree decl, const char *name, int is_data)
rtx symbol;
struct export_list *p;
if (!decl)
return;
symbol = XEXP (DECL_RTL (decl), 0);
gcc_assert (GET_CODE (symbol) == SYMBOL_REF);
if (!SYMBOL_REF_DLLEXPORT_P (symbol))
......
......@@ -671,6 +671,8 @@ subdirs
slibdir
dollar
gcc_tooldir
LTO_USE_LIBELF
LTO_BINARY_READER
enable_lto
MAINT
zlibinc
......@@ -17092,7 +17094,7 @@ else
lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
lt_status=$lt_dlunknown
cat > conftest.$ac_ext <<_LT_EOF
#line 17095 "configure"
#line 17097 "configure"
#include "confdefs.h"
#if HAVE_DLFCN_H
......@@ -17198,7 +17200,7 @@ else
lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
lt_status=$lt_dlunknown
cat > conftest.$ac_ext <<_LT_EOF
#line 17201 "configure"
#line 17203 "configure"
#include "confdefs.h"
#if HAVE_DLFCN_H
......@@ -22942,6 +22944,48 @@ if test $gcc_cv_as_ix86_pe_secrel32 = yes; then
$as_echo "#define HAVE_GAS_PE_SECREL32_RELOC 1" >>confdefs.h
fi
# Test if the assembler supports the extended form of the .section
# directive that specifies section alignment. LTO support uses this,
# but normally only after installation, so we warn but don't fail the
# configure if LTO is enabled but the assembler does not support it.
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking assembler for .section with alignment" >&5
$as_echo_n "checking assembler for .section with alignment... " >&6; }
if test "${gcc_cv_as_section_has_align+set}" = set; then :
$as_echo_n "(cached) " >&6
else
gcc_cv_as_section_has_align=no
if test $in_tree_gas = yes; then
if test $gcc_cv_gas_vers -ge `expr \( \( 2 \* 1000 \) + 20 \) \* 1000 + 1`
then gcc_cv_as_section_has_align=yes
fi
elif test x$gcc_cv_as != x; then
echo '.section lto_test,"dr0"' > conftest.s
if { ac_try='$gcc_cv_as $gcc_cv_as_flags -fatal-warnings -o conftest.o conftest.s >&5'
{ { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$ac_try\""; } >&5
(eval $ac_try) 2>&5
ac_status=$?
$as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
test $ac_status = 0; }; }
then
gcc_cv_as_section_has_align=yes
else
echo "configure: failed program was" >&5
cat conftest.s >&5
fi
rm -f conftest.o conftest.s
fi
fi
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $gcc_cv_as_section_has_align" >&5
$as_echo "$gcc_cv_as_section_has_align" >&6; }
if test x$gcc_cv_as_section_has_align != xyes; then
case ",$enable_languages," in
*,lto,*)
{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: LTO for $target requires binutils >= 2.20.1, but version found appears insufficient; LTO will not work until binutils is upgraded." >&5
$as_echo "$as_me: WARNING: LTO for $target requires binutils >= 2.20.1, but version found appears insufficient; LTO will not work until binutils is upgraded." >&2;}
;;
esac
fi
;;
esac
......@@ -25078,6 +25122,17 @@ $as_echo "#define ENABLE_LTO 1" >>confdefs.h
enable_lto=yes
# LTO needs to speak the platform's object file format, and has a
# number of implementations of the required binary file access APIs.
# ELF is the most common, and default. We only link libelf if ELF
# is indeed the selected format.
LTO_BINARY_READER=${lto_binary_reader}
LTO_USE_LIBELF=-lelf
if test "x$lto_binary_reader" != "xlto-elf" ; then
LTO_USE_LIBELF=
fi
;;
*) ;;
esac
......
......@@ -3202,6 +3202,19 @@ foo: nop
rm -f conftest],
[AC_DEFINE(HAVE_GAS_PE_SECREL32_RELOC, 1,
[Define if your assembler and linker support 32-bit section relative relocs via '.secrel32 label'.])])
# Test if the assembler supports the extended form of the .section
# directive that specifies section alignment. LTO support uses this,
# but normally only after installation, so we warn but don't fail the
# configure if LTO is enabled but the assembler does not support it.
gcc_GAS_CHECK_FEATURE([.section with alignment], gcc_cv_as_section_has_align,
[2,20,1],-fatal-warnings,[.section lto_test,"dr0"])
if test x$gcc_cv_as_section_has_align != xyes; then
case ",$enable_languages," in
*,lto,*)
AC_MSG_WARN([LTO for $target requires binutils >= 2.20.1, but version found appears insufficient; LTO will not work until binutils is upgraded.])
;;
esac
fi
;;
esac
......@@ -4270,6 +4283,17 @@ changequote([,])dnl
AC_DEFINE(ENABLE_LTO, 1, [Define to enable LTO support.])
enable_lto=yes
AC_SUBST(enable_lto)
# LTO needs to speak the platform's object file format, and has a
# number of implementations of the required binary file access APIs.
# ELF is the most common, and default. We only link libelf if ELF
# is indeed the selected format.
LTO_BINARY_READER=${lto_binary_reader}
LTO_USE_LIBELF=-lelf
if test "x$lto_binary_reader" != "xlto-elf" ; then
LTO_USE_LIBELF=
fi
AC_SUBST(LTO_BINARY_READER)
AC_SUBST(LTO_USE_LIBELF)
;;
*) ;;
esac
......
2010-04-27 Dave Korn <dave.korn.cygwin@gmail.com>
PR lto/42776
* Make-lang.in (LTO_OBJS): Use LTO_BINARY_READER instead of
hardcoding 'lto-elf.o'.
($(LTO_EXE)): Use LTO_USE_LIBELF instead of hardcoding '-lelf'.
* lto-coff.h: New file.
* lto-coff.c: Likewise.
2010-04-26 Richard Guenther <rguenther@suse.de>
* lto.c (lto_fixup_type): Deal with non-type TYPE_CONTEXT.
......
......@@ -23,7 +23,7 @@
# The name of the LTO compiler.
LTO_EXE = lto1$(exeext)
# The LTO-specific object files inclued in $(LTO_EXE).
LTO_OBJS = lto/lto-lang.o lto/lto.o lto/lto-elf.o attribs.o
LTO_OBJS = lto/lto-lang.o lto/lto.o lto/$(LTO_BINARY_READER).o attribs.o
LTO_H = lto/lto.h $(HASHTAB_H)
LINKER_PLUGIN_API_H = $(srcdir)/../include/plugin-api.h
LTO_TREE_H = lto/lto-tree.h $(LINKER_PLUGIN_API_H)
......@@ -73,7 +73,7 @@ lto-warn = $(STRICT_WARN)
$(LTO_EXE): $(LTO_OBJS) $(BACKEND) $(LIBDEPS)
$(LINKER) $(ALL_LINKERFLAGS) $(LDFLAGS) -o $@ \
$(LTO_OBJS) $(BACKEND) $(BACKENDLIBS) $(LIBS) -lelf
$(LTO_OBJS) $(BACKEND) $(BACKENDLIBS) $(LIBS) $(LTO_USE_LIBELF)
# Dependencies
lto/lto-lang.o: lto/lto-lang.c $(CONFIG_H) coretypes.h debug.h \
......@@ -88,3 +88,6 @@ lto/lto.o: lto/lto.c $(CONFIG_H) $(SYSTEM_H) coretypes.h opts.h \
$(LTO_TAGS_H) $(LTO_STREAMER_H)
lto/lto-elf.o: lto/lto-elf.c $(CONFIG_H) coretypes.h $(SYSTEM_H) \
toplev.h $(LTO_H) $(TM_H) $(LIBIBERTY_H) $(GGC_H) $(LTO_STREAMER_H)
lto/lto-coff.o: lto/lto-coff.c $(CONFIG_H) coretypes.h $(SYSTEM_H) \
toplev.h $(LTO_H) $(TM_H) $(LIBIBERTY_H) $(GGC_H) $(LTO_STREAMER_H) \
lto/lto-coff.h
2010-04-27 Dave Korn <dave.korn.cygwin@gmail.com>
PR lto/42776
* lib/lto.exp (lto_prune_vis_warns): New function.
(lto-link-and-maybe-run): Call it.
2010-04-26 H.J. Lu <hongjiu.lu@intel.com>
PR tree-optimization/43904
......
......@@ -16,6 +16,19 @@
# Contributed by Diego Novillo <dnovillo@google.com>
# Prune messages from gcc that aren't useful.
proc lto_prune_vis_warns { text } {
# Many tests that use visibility will still pass on platforms that don't support it.
regsub -all "(^|\n)\[^\n\]*: warning: visibility attribute not supported in this configuration; ignored\[^\n\]*" $text "" text
# And any stray location lines.
regsub -all "(^|\n)\[^\n\]*: In function \[^\n\]*" $text "" text
regsub -all "(^|\n)In file included from :\[^\n\]*" $text "" text
return $text
}
# lto_init -- called at the start of each subdir of tests
......@@ -147,6 +160,10 @@ proc lto-link-and-maybe-run { testname objlist dest optall optfile optstr } {
# Link the objects into an executable.
set comp_output [${tool}_target_compile "$objlist" $dest executable \
"$options"]
# Prune unimportant visibility warnings before checking output.
set comp_output [lto_prune_vis_warns $comp_output]
if ![${tool}_check_compile "$testcase $testname link" "" \
$dest $comp_output] then {
unresolved "$testcase $testname execute $optstr"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment