Index: gcc/config/rs6000/x-rs6000 =================================================================== --- gcc/config/rs6000/x-rs6000 (revision 193063) +++ gcc/config/rs6000/x-rs6000 (working copy) @@ -1,3 +1,3 @@ driver-rs6000.o : $(srcdir)/config/rs6000/driver-rs6000.c \ - $(CONFIG_H) $(SYSTEM_H) $(TM_H) coretypes.h + $(CONFIG_H) $(SYSTEM_H) $(TM_H) coretypes.h $(GCC_H) $(COMPILER) -c $(ALL_COMPILERFLAGS) $(ALL_CPPFLAGS) $(INCLUDES) $< Index: gcc/config/rs6000/linux64.h =================================================================== --- gcc/config/rs6000/linux64.h (revision 193063) +++ gcc/config/rs6000/linux64.h (working copy) @@ -1,7 +1,7 @@ /* Definitions of target machine for GNU compiler, for 64 bit PowerPC linux. Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, - 2009, 2010, 2011 Free Software Foundation, Inc. + 2009, 2010, 2011, 2012 Free Software Foundation, Inc. This file is part of GCC. @@ -361,8 +361,14 @@ extern int dot_symbols; #undef LINK_OS_DEFAULT_SPEC #define LINK_OS_DEFAULT_SPEC "%(link_os_linux)" +#ifdef CONFIGURE_STARTFILE_PREFIX +#define GLIBC_DYNAMIC_LINKER32 "%:find-dynamic-linker(/lib/ld.so.1)" +#define GLIBC_DYNAMIC_LINKER64 "%:find-dynamic-linker(/lib64/ld64.so.1)" +#else #define GLIBC_DYNAMIC_LINKER32 "/lib/ld.so.1" #define GLIBC_DYNAMIC_LINKER64 "/lib64/ld64.so.1" +#endif + #define UCLIBC_DYNAMIC_LINKER32 "/lib/ld-uClibc.so.0" #define UCLIBC_DYNAMIC_LINKER64 "/lib/ld64-uClibc.so.0" #if DEFAULT_LIBC == LIBC_UCLIBC @@ -372,17 +378,39 @@ extern int dot_symbols; #else #error "Unsupported DEFAULT_LIBC" #endif + #define GNU_USER_DYNAMIC_LINKER32 \ CHOOSE_DYNAMIC_LINKER (GLIBC_DYNAMIC_LINKER32, UCLIBC_DYNAMIC_LINKER32) #define GNU_USER_DYNAMIC_LINKER64 \ CHOOSE_DYNAMIC_LINKER (GLIBC_DYNAMIC_LINKER64, UCLIBC_DYNAMIC_LINKER64) +#ifdef CONFIGURE_STARTFILE_PREFIX +#ifdef HAVE_LOCAL_CPU_DETECT +#define LINUX_EXTRA_STATIC_LIBDIRS64 \ +"%{static: \ +%{mcpu=native: %:linux_extra_static_libdirs(%:local_cpu_detect(cpu))} \ +%{!mcpu=native: %{mcpu=*: %:linux_extra_static_libdirs(%{mcpu=*}) }}} " + +#else +#define LINUX_EXTRA_STATIC_LIBDIRS64 \ +"%{static: \ +%{mcpu=: %:linux_extra_static_libdirs(%{mcpu=*}) }} " +#endif + +#else +#define LINUX_EXTRA_STATIC_LIBDIRS64 +#endif + -#define LINK_OS_LINUX_SPEC32 "-m elf32ppclinux %{!shared: %{!static: \ +#define LINK_OS_LINUX_SPEC32 "-m elf32ppclinux " \ +LINUX_EXTRA_STATIC_LIBDIRS32 \ +"%{!shared: %{!static: \ %{rdynamic:-export-dynamic} \ -dynamic-linker " GNU_USER_DYNAMIC_LINKER32 "}}" -#define LINK_OS_LINUX_SPEC64 "-m elf64ppc %{!shared: %{!static: \ +#define LINK_OS_LINUX_SPEC64 "-m elf64ppc " \ +LINUX_EXTRA_STATIC_LIBDIRS64 \ +"%{!shared: %{!static: \ %{rdynamic:-export-dynamic} \ -dynamic-linker " GNU_USER_DYNAMIC_LINKER64 "}}" Index: gcc/config/rs6000/rs6000.h =================================================================== --- gcc/config/rs6000/rs6000.h (revision 193063) +++ gcc/config/rs6000/rs6000.h (working copy) @@ -193,15 +193,21 @@ #if defined(__powerpc__) || defined(__POWERPC__) || defined(_AIX) /* In driver-rs6000.c. */ extern const char *host_detect_local_cpu (int argc, const char **argv); -#define EXTRA_SPEC_FUNCTIONS \ +#define LOCAL_CPU_EXTRA_SPEC_FUNCTIONS \ { "local_cpu_detect", host_detect_local_cpu }, #define HAVE_LOCAL_CPU_DETECT #define ASM_CPU_NATIVE_SPEC "%:local_cpu_detect(asm)" #else #define ASM_CPU_NATIVE_SPEC "%(asm_default)" +#define LOCAL_CPU_EXTR_SPEC_FUNCTIONS #endif +#define SUBTARGET_EXTRA_SPEC_FUNCTIONS +#define EXTRA_SPEC_FUNCTIONS \ + SUBTARGET_EXTRA_SPEC_FUNCTIONS \ + LOCAL_CPU_EXTRA_SPEC_FUNCTIONS + #ifndef CC1_CPU_SPEC #ifdef HAVE_LOCAL_CPU_DETECT #define CC1_CPU_SPEC \ Index: gcc/config/rs6000/driver-rs6000.c =================================================================== --- gcc/config/rs6000/driver-rs6000.c (revision 193063) +++ gcc/config/rs6000/driver-rs6000.c (working copy) @@ -22,6 +22,7 @@ along with GCC; see the file COPYING3. #include "coretypes.h" #include "tm.h" #include +#include "gcc.h" #ifdef _AIX # include @@ -524,3 +525,32 @@ host_detect_local_cpu (int argc, const c #endif /* GCC_VERSION */ + +#ifdef CONFIGURE_STARTFILE_PREFIX +/* Add -L for all of the machine dependent directories found in the extra rpath + directories. We don't need to do this for dynamic links, since the dynamic + linker will pick up the right library based on the machine that is currently + running. */ + +const char * +rs6000_extra_static_libdirs (int argc, const char **argv) +{ + const char *new_argv[2]; + const char *cpu; + + if (argc == 1 && strncmp (argv[0], "mcpu=", sizeof ("-mcpu=")-1) == 0) + cpu = argv[0] + sizeof ("-mcpu=") - 1; + + else if (argc == 2 && strcmp (argv[0], "-") == 0 + && strncmp (argv[1], "mcpu=", sizeof ("mcpu=")-1) == 0) + cpu = argv[1] + sizeof ("mcpu=") - 1; + + else + abort (); + + new_argv[0] = cpu; + new_argv[1] = NULL; + return extra_cpu_dirs_spec_function (1, new_argv); +} + +#endif /* !CONFIGURE_STARTFILE_PREFIX */ Index: gcc/config/rs6000/sysv4.h =================================================================== --- gcc/config/rs6000/sysv4.h (revision 193063) +++ gcc/config/rs6000/sysv4.h (working copy) @@ -787,7 +787,12 @@ extern int fixuplabelno; #define LINK_START_LINUX_SPEC "" +#ifdef CONFIGURE_STARTFILE_PREFIX +#define GLIBC_DYNAMIC_LINKER "%:find-dynamic-linker(/lib/ld.so.1)" +#else #define GLIBC_DYNAMIC_LINKER "/lib/ld.so.1" +#endif + #define UCLIBC_DYNAMIC_LINKER "/lib/ld-uClibc.so.0" #if DEFAULT_LIBC == LIBC_UCLIBC #define CHOOSE_DYNAMIC_LINKER(G, U) "%{mglibc:" G ";:" U "}" @@ -796,10 +801,30 @@ extern int fixuplabelno; #else #error "Unsupported DEFAULT_LIBC" #endif + #define GNU_USER_DYNAMIC_LINKER \ CHOOSE_DYNAMIC_LINKER (GLIBC_DYNAMIC_LINKER, UCLIBC_DYNAMIC_LINKER) -#define LINK_OS_LINUX_SPEC "-m elf32ppclinux %{!shared: %{!static: \ +#ifdef CONFIGURE_STARTFILE_PREFIX +#ifdef HAVE_LOCAL_CPU_DETECT +#define LINUX_EXTRA_STATIC_LIBDIRS32 \ +"%{static: \ +%{mcpu=native: %:linux_extra_static_libdirs(%:local_cpu_detect(cpu))} \ +%{!mcpu=native: %{mcpu=*: %:linux_extra_static_libdirs(%{mcpu=*}) }}} " + +#else +#define LINUX_EXTRA_STATIC_LIBDIRS32 \ +"%{static: \ +%{mcpu=: %:linux_extra_static_libdirs(%{mcpu=*}) }} " +#endif + +#else +#define LINUX_EXTRA_STATIC_LIBDIRS32 "" +#endif + +#define LINK_OS_LINUX_SPEC "-m elf32ppclinux " \ +LINUX_EXTRA_STATIC_LIBDIRS32 \ +"%{!shared: %{!static: \ %{rdynamic:-export-dynamic} \ -dynamic-linker " GNU_USER_DYNAMIC_LINKER "}}" @@ -865,6 +890,22 @@ ncrtn.o%s" #define CPP_OS_OPENBSD_SPEC "%{posix:-D_POSIX_SOURCE} %{pthread:-D_POSIX_THREADS}" #endif +/* If we have additional startfiles, we want to use the dynamic linker from the + directories those startfiles are in. We also want to set the -rpath for + those directories. + + Also if this is a static link, see if we have any processor specific + directories in the extra startfiles directories. We don't have to worry + about dynamic libraries, since the dynamic linker will include them + automatically. */ +#ifdef CONFIGURE_STARTFILE_PREFIX +extern const char *rs6000_extra_static_libdirs (int argc, const char **argv); + +#undef SUBTARGET_EXTRA_SPEC_FUNCTIONS +#define SUBTARGET_EXTRA_SPEC_FUNCTIONS \ + { "linux_extra_static_libdirs", rs6000_extra_static_libdirs }, +#endif + /* Define any extra SPECS that the compiler needs to generate. */ /* Override rs6000.h definition. */ #undef SUBTARGET_EXTRA_SPECS