From 37b4493d05be97ecec83d814e65e77a2d11631d2 Mon Sep 17 00:00:00 2001 From: Ben Cressey Date: Sun, 6 Aug 2017 23:58:27 +0000 Subject: [PATCH] build gcc with TOOLS_DIR and SYSROOT_DIR Most of the changes here are to the second and final stage of our GCC build, so that the binaries are written to the new output path, and so that it can find the interim headers and libraries needed to build its C++ standard library for our target. Because GCC contains logic to find its configured sysroot relative to either its installed path or the overall filesystem root, we can rely on that logic and do not need wrappers that hardcode the path. Those wrappers would otherwise prevent us from relocating these tools into a different location from that of the build host. We build GCC with the linker build ID option so that all binaries get the unique ID that allows core dumps to be matched to debug symbols directly, rather than relying on filesystem layout. We also enable pie and ssp by default. Signed-off-by: Ben Cressey --- package/gcc/gcc-final/gcc-final.mk | 56 +++++++++++++++++++------- package/gcc/gcc-initial/gcc-initial.mk | 3 ++ package/gcc/gcc.mk | 2 +- 3 files changed, 46 insertions(+), 15 deletions(-) diff --git a/package/gcc/gcc-final/gcc-final.mk b/package/gcc/gcc-final/gcc-final.mk index aa883beb7b..0f61ff0df1 100644 --- a/package/gcc/gcc-final/gcc-final.mk +++ b/package/gcc/gcc-final/gcc-final.mk @@ -45,9 +45,16 @@ define HOST_GCC_FINAL_CONFIGURE_CMDS LDFLAGS="$(HOST_LDFLAGS)" \ $(HOST_GCC_FINAL_CONF_ENV) \ ./configure \ - --prefix="$(HOST_DIR)" \ - --sysconfdir="$(HOST_DIR)/etc" \ + --prefix="/usr" \ + --libdir="/usr/lib" \ + --sysconfdir="/etc" \ --enable-static \ + --disable-libcc1 \ + --with-sysroot=$(SYSROOT_DIR) \ + --with-build-sysroot=$(STAGING_DIR) \ + --with-gcc-major-version-only \ + --enable-default-pie \ + --enable-default-ssp \ $(QUIET) $(HOST_GCC_FINAL_CONF_OPTS) \ ) endef @@ -68,12 +75,12 @@ HOST_GCC_FINAL_CONF_OPTS = \ # doesn't use floating point operations. ifeq ($(BR2_sh4)$(BR2_sh4eb),y) HOST_GCC_FINAL_CONF_OPTS += "--with-multilib-list=m4,m4-nofpu" -HOST_GCC_FINAL_GCC_LIB_DIR = $(HOST_DIR)/$(GNU_TARGET_NAME)/lib/!m4* +HOST_GCC_FINAL_GCC_LIB_DIR = $(TOOLS_DIR)/usr/$(GNU_TARGET_NAME)/lib/!m4* else ifeq ($(BR2_sh4a)$(BR2_sh4aeb),y) HOST_GCC_FINAL_CONF_OPTS += "--with-multilib-list=m4a,m4a-nofpu" -HOST_GCC_FINAL_GCC_LIB_DIR = $(HOST_DIR)/$(GNU_TARGET_NAME)/lib/!m4* +HOST_GCC_FINAL_GCC_LIB_DIR = $(TOOLS_DIR)/usr/$(GNU_TARGET_NAME)/lib/!m4* else -HOST_GCC_FINAL_GCC_LIB_DIR = $(HOST_DIR)/$(GNU_TARGET_NAME)/lib* +HOST_GCC_FINAL_GCC_LIB_DIR = $(TOOLS_DIR)/usr/$(GNU_TARGET_NAME)/lib* endif ifeq ($(BR2_GCC_SUPPORTS_LIBCILKRTS),y) @@ -88,7 +95,7 @@ ifeq ($(BR2_PTHREADS_NONE),y) HOST_GCC_FINAL_CONF_OPTS += --disable-libcilkrts endif -ifeq ($(BR2_STATIC_LIBS),y) +ifeq (y,y) # disable libcilkrts as there is no static version HOST_GCC_FINAL_CONF_OPTS += --disable-libcilkrts endif @@ -96,10 +103,8 @@ endif endif # BR2_GCC_SUPPORTS_LIBCILKRTS # Disable shared libs like libstdc++ if we do static since it confuses linking -ifeq ($(BR2_STATIC_LIBS),y) -HOST_GCC_FINAL_CONF_OPTS += --disable-shared -else -HOST_GCC_FINAL_CONF_OPTS += --enable-shared +ifeq (y,y) +HOST_GCC_FINAL_CONF_OPTS += --enable-shared=libgcc endif ifeq ($(BR2_GCC_ENABLE_OPENMP),y) @@ -118,22 +123,27 @@ HOST_GCC_FINAL_CONF_ENV = \ HOST_GCC_FINAL_MAKE_OPTS += $(HOST_GCC_COMMON_MAKE_OPTS) +HOST_GCC_FINAL_INSTALL_OPTS = install +HOST_GCC_FINAL_INSTALL_OPTS += DESTDIR=$(TOOLS_DIR) + # Make sure we have 'cc' define HOST_GCC_FINAL_CREATE_CC_SYMLINKS - if [ ! -e $(HOST_DIR)/bin/$(GNU_TARGET_NAME)-cc ]; then \ - ln -f $(HOST_DIR)/bin/$(GNU_TARGET_NAME)-gcc \ - $(HOST_DIR)/bin/$(GNU_TARGET_NAME)-cc; \ + if [ ! -e $(TOOLS_DIR)/usr/bin/$(GNU_TARGET_NAME)-cc ]; then \ + ln -f $(TOOLS_DIR)/usr/bin/$(GNU_TARGET_NAME)-gcc \ + $(TOOLS_DIR)/usr/bin/$(GNU_TARGET_NAME)-cc; \ fi endef HOST_GCC_FINAL_POST_INSTALL_HOOKS += HOST_GCC_FINAL_CREATE_CC_SYMLINKS +ifeq ($(BR2_GCC_ENABLE_TOOLCHAIN_WRAPPER),y) HOST_GCC_FINAL_TOOLCHAIN_WRAPPER_ARGS += $(HOST_GCC_COMMON_TOOLCHAIN_WRAPPER_ARGS) HOST_GCC_FINAL_POST_BUILD_HOOKS += TOOLCHAIN_WRAPPER_BUILD HOST_GCC_FINAL_POST_INSTALL_HOOKS += TOOLCHAIN_WRAPPER_INSTALL # Note: this must be done after CREATE_CC_SYMLINKS, otherwise the # -cc symlink to the wrapper is not created. HOST_GCC_FINAL_POST_INSTALL_HOOKS += HOST_GCC_INSTALL_WRAPPER_AND_SIMPLE_SYMLINKS +endif # coldfire is not working without removing these object files from libgcc.a ifeq ($(BR2_m68k_cf),y) @@ -146,6 +156,7 @@ endif # Cannot use the HOST_GCC_FINAL_USR_LIBS mechanism below, because we want # libgcc_s to be installed in /lib and not /usr/lib. +ifeq (y,) define HOST_GCC_FINAL_INSTALL_LIBGCC -cp -dpf $(HOST_GCC_FINAL_GCC_LIB_DIR)/libgcc_s* \ $(STAGING_DIR)/lib/ @@ -154,6 +165,7 @@ define HOST_GCC_FINAL_INSTALL_LIBGCC endef HOST_GCC_FINAL_POST_INSTALL_HOOKS += HOST_GCC_FINAL_INSTALL_LIBGCC +endif define HOST_GCC_FINAL_INSTALL_LIBATOMIC -cp -dpf $(HOST_GCC_FINAL_GCC_LIB_DIR)/libatomic* \ @@ -197,7 +209,7 @@ define HOST_GCC_FINAL_INSTALL_STATIC_LIBS done endef -ifeq ($(BR2_STATIC_LIBS),) +ifeq (y,) define HOST_GCC_FINAL_INSTALL_SHARED_LIBS for i in $(HOST_GCC_FINAL_USR_LIBS) ; do \ cp -dpf $(HOST_GCC_FINAL_GCC_LIB_DIR)/$${i}.so* \ @@ -216,4 +228,20 @@ endef HOST_GCC_FINAL_POST_INSTALL_HOOKS += HOST_GCC_FINAL_INSTALL_USR_LIBS endif +define HOST_GCC_FINAL_TOOLS_DIR_CLEANUP + rm -rf $(TOOLS_DIR)/usr/share + find $(TOOLS_DIR) -name '*.la' -delete + find $(TOOLS_DIR) -name '*.py' -delete +endef + +define HOST_GCC_FINAL_TOOLS_DIR_SYSROOT + mkdir -p $(TOOLS_DIR)$(SYSROOT_DIR)/usr + test -d $(TOOLS_DIR)/usr/$(GNU_TARGET_NAME)/lib64 \ + && mv $(TOOLS_DIR)/usr/$(GNU_TARGET_NAME)/lib64 $(TOOLS_DIR)$(SYSROOT_DIR)/usr/lib \ + || mv $(TOOLS_DIR)/usr/$(GNU_TARGET_NAME)/lib $(TOOLS_DIR)$(SYSROOT_DIR)/usr/lib +endef + +HOST_GCC_FINAL_POST_INSTALL_HOOKS += HOST_GCC_FINAL_TOOLS_DIR_CLEANUP +HOST_GCC_FINAL_POST_INSTALL_HOOKS += HOST_GCC_FINAL_TOOLS_DIR_SYSROOT + $(eval $(host-autotools-package)) diff --git a/package/gcc/gcc-initial/gcc-initial.mk b/package/gcc/gcc-initial/gcc-initial.mk index ebd8e8f017..ec9fcd13c1 100644 --- a/package/gcc/gcc-initial/gcc-initial.mk +++ b/package/gcc/gcc-initial/gcc-initial.mk @@ -34,6 +34,7 @@ HOST_GCC_INITIAL_CONF_OPTS = \ $(HOST_GCC_COMMON_CONF_OPTS) \ --enable-languages=c \ --disable-shared \ + --with-sysroot=$(STAGING_DIR) \ --without-headers \ --disable-threads \ --with-newlib \ @@ -53,9 +54,11 @@ endif HOST_GCC_INITIAL_MAKE_OPTS = $(HOST_GCC_COMMON_MAKE_OPTS) all-gcc all-target-libgcc HOST_GCC_INITIAL_INSTALL_OPTS = install-gcc install-target-libgcc +ifeq ($(BR2_GCC_ENABLE_TOOLCHAIN_WRAPPER),y) HOST_GCC_INITIAL_TOOLCHAIN_WRAPPER_ARGS += $(HOST_GCC_COMMON_TOOLCHAIN_WRAPPER_ARGS) HOST_GCC_INITIAL_POST_BUILD_HOOKS += TOOLCHAIN_WRAPPER_BUILD HOST_GCC_INITIAL_POST_INSTALL_HOOKS += TOOLCHAIN_WRAPPER_INSTALL HOST_GCC_INITIAL_POST_INSTALL_HOOKS += HOST_GCC_INSTALL_WRAPPER_AND_SIMPLE_SYMLINKS +endif $(eval $(host-autotools-package)) diff --git a/package/gcc/gcc.mk b/package/gcc/gcc.mk index ec6f3b550a..6d4f6e0b20 100644 --- a/package/gcc/gcc.mk +++ b/package/gcc/gcc.mk @@ -69,7 +69,6 @@ HOST_GCC_COMMON_DEPENDENCIES = \ HOST_GCC_COMMON_CONF_OPTS = \ --target=$(GNU_TARGET_NAME) \ - --with-sysroot=$(STAGING_DIR) \ --enable-__cxa_atexit \ --with-gnu-ld \ --disable-libssp \ @@ -77,6 +76,7 @@ HOST_GCC_COMMON_CONF_OPTS = \ --disable-decimal-float \ --enable-plugins \ --enable-lto \ + --enable-linker-build-id \ --with-gmp=$(HOST_DIR) \ --with-mpc=$(HOST_DIR) \ --with-mpfr=$(HOST_DIR) \ -- 2.37.2