build: use gcc-provided ar, nm and ranlib where appropriate

Since GCC 4.7, GCC provides its own wrappers around ar, nm and ranlib, which
should be used for builds with link-time optimization. Since GCC 4.9, using them
actually necessary for LTO builds using convenience libraries to succeed.

There are some packages which try to automatically detect if gcc-{ar,nm,ranlib}
exist (one example is my package "fastd" in the package repository, which tries
to use LTO). This breaks because the OpenWrt build system explicitly sets the
binutils versions of these tools.

As it doesn't cause any issues to use gcc-{ar,nm,ranlib} instead of
{ar,nm,ranlib} even without LTO, this patch just makes OpenWrt use the
GCC-provided versions by default, which fixes the build of such packages with
GCC 4.9.

(I know that builds fail though when clang is used with -flto and
gcc-{ar,nm,ranlib}, but as all OpenWrt toolchains are based on GCC, this isn't
a real issue.)

Completely cleaning the tree (or at least `make clean toolchain/clean`) is
necessary to get a consistent state after the binutils plugins support patch and
this one (as trying to use gcc-{ar,nm,ranlib} with a binutils built without
plugin support will definitely lead to a build failure).

Signed-off-by: Matthias Schiffer <mschiffer@universe-factory.net>

SVN-Revision: 43784
This commit is contained in:
Felix Fietkau 2014-12-27 12:59:59 +00:00
parent 7d808a325d
commit 9a46799804
2 changed files with 17 additions and 7 deletions

View File

@ -27,8 +27,9 @@ else
CMAKE_CXX_COMPILER:=$(CCACHE) CMAKE_CXX_COMPILER:=$(CCACHE)
CMAKE_CXX_COMPILER_ARG1:=$(TARGET_CXX_NOCACHE) CMAKE_CXX_COMPILER_ARG1:=$(TARGET_CXX_NOCACHE)
endif endif
CMAKE_AR:=$(call cmake_tool,$(TARGET_CROSS)ar) CMAKE_AR:=$(call cmake_tool,$(TARGET_AR))
CMAKE_RANLIB:=$(call cmake_tool,$(TARGET_CROSS)ranlib) CMAKE_NM:=$(call cmake_tool,$(TARGET_NM))
CMAKE_RANLIB:=$(call cmake_tool,$(TARGET_RANLIB))
define Build/Configure/Default define Build/Configure/Default
(cd $(PKG_BUILD_DIR); \ (cd $(PKG_BUILD_DIR); \
@ -50,6 +51,7 @@ define Build/Configure/Default
-DCMAKE_MODULE_LINKER_FLAGS:STRING="$(TARGET_LDFLAGS)" \ -DCMAKE_MODULE_LINKER_FLAGS:STRING="$(TARGET_LDFLAGS)" \
-DCMAKE_SHARED_LINKER_FLAGS:STRING="$(TARGET_LDFLAGS)" \ -DCMAKE_SHARED_LINKER_FLAGS:STRING="$(TARGET_LDFLAGS)" \
-DCMAKE_AR="$(CMAKE_AR)" \ -DCMAKE_AR="$(CMAKE_AR)" \
-DCMAKE_NM="$(CMAKE_NM)" \
-DCMAKE_RANLIB="$(CMAKE_RANLIB)" \ -DCMAKE_RANLIB="$(CMAKE_RANLIB)" \
-DCMAKE_FIND_ROOT_PATH="$(STAGING_DIR);$(TOOLCHAIN_DIR)" \ -DCMAKE_FIND_ROOT_PATH="$(STAGING_DIR);$(TOOLCHAIN_DIR)" \
-DCMAKE_FIND_ROOT_PATH_MODE_PROGRAM=BOTH \ -DCMAKE_FIND_ROOT_PATH_MODE_PROGRAM=BOTH \

View File

@ -192,9 +192,17 @@ HOST_CPPFLAGS:=-I$(STAGING_DIR_HOST)/include -I$(STAGING_DIR_HOST)/usr/include
HOST_CFLAGS:=-O2 $(HOST_CPPFLAGS) HOST_CFLAGS:=-O2 $(HOST_CPPFLAGS)
HOST_LDFLAGS:=-L$(STAGING_DIR_HOST)/lib -L$(STAGING_DIR_HOST)/usr/lib HOST_LDFLAGS:=-L$(STAGING_DIR_HOST)/lib -L$(STAGING_DIR_HOST)/usr/lib
ifeq ($(CONFIG_GCC_VERSION_4_4)$(CONFIG_GCC_VERSION_4_6),)
TARGET_AR:=$(TARGET_CROSS)gcc-ar
TARGET_RANLIB:=$(TARGET_CROSS)gcc-ranlib
TARGET_NM:=$(TARGET_CROSS)gcc-nm
else
TARGET_AR:=$(TARGET_CROSS)ar
TARGET_RANLIB:=$(TARGET_CROSS)ranlib
TARGET_NM:=$(TARGET_CROSS)nm
endif
TARGET_CC:=$(TARGET_CROSS)gcc TARGET_CC:=$(TARGET_CROSS)gcc
TARGET_AR:=$(TARGET_CROSS)ar
TARGET_RANLIB:=$(TARGET_CROSS)ranlib
TARGET_CXX:=$(TARGET_CROSS)g++ TARGET_CXX:=$(TARGET_CROSS)g++
KPATCH:=$(SCRIPT_DIR)/patch-kernel.sh KPATCH:=$(SCRIPT_DIR)/patch-kernel.sh
SED:=$(STAGING_DIR_HOST)/bin/sed -i -e SED:=$(STAGING_DIR_HOST)/bin/sed -i -e
@ -223,14 +231,14 @@ ifneq ($(CONFIG_CCACHE),)
endif endif
TARGET_CONFIGURE_OPTS = \ TARGET_CONFIGURE_OPTS = \
AR=$(TARGET_CROSS)ar \ AR="$(TARGET_AR)" \
AS="$(TARGET_CC) -c $(TARGET_ASFLAGS)" \ AS="$(TARGET_CC) -c $(TARGET_ASFLAGS)" \
LD=$(TARGET_CROSS)ld \ LD=$(TARGET_CROSS)ld \
NM=$(TARGET_CROSS)nm \ NM="$(TARGET_NM)" \
CC="$(TARGET_CC)" \ CC="$(TARGET_CC)" \
GCC="$(TARGET_CC)" \ GCC="$(TARGET_CC)" \
CXX="$(TARGET_CXX)" \ CXX="$(TARGET_CXX)" \
RANLIB=$(TARGET_CROSS)ranlib \ RANLIB="$(TARGET_RANLIB)" \
STRIP=$(TARGET_CROSS)strip \ STRIP=$(TARGET_CROSS)strip \
OBJCOPY=$(TARGET_CROSS)objcopy \ OBJCOPY=$(TARGET_CROSS)objcopy \
OBJDUMP=$(TARGET_CROSS)objdump \ OBJDUMP=$(TARGET_CROSS)objdump \