From 900092572d961b720a75c08ad56afdac47dee090 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=ABl=20Porquet-Lupine?= Date: Thu, 16 Dec 2021 18:13:39 -0800 Subject: [PATCH 1/3] Introduce new gcc-target package MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Build a toolchain on target using the same version as the internal buildroot toolchain. This way, all the programs (either build by buildroot or compiled at runtime) are built in the same way and use the same libraries. Signed-off-by: Joël Porquet-Lupine --- package/gcc/Config.in | 21 +++++++ package/gcc/gcc-target/gcc-target.hash | 1 + package/gcc/gcc-target/gcc-target.mk | 78 ++++++++++++++++++++++++++ 3 files changed, 100 insertions(+) create mode 100644 package/gcc/Config.in create mode 120000 package/gcc/gcc-target/gcc-target.hash create mode 100644 package/gcc/gcc-target/gcc-target.mk diff --git a/package/gcc/Config.in b/package/gcc/Config.in new file mode 100644 index 0000000000..40cd1730a1 --- /dev/null +++ b/package/gcc/Config.in @@ -0,0 +1,21 @@ +config BR2_PACKAGE_GCC_TARGET + bool "gcc" + depends on BR2_TOOLCHAIN_BUILDROOT + select BR2_PACKAGE_BINUTILS + select BR2_PACKAGE_BINUTILS_TARGET + select BR2_PACKAGE_GMP + select BR2_PACKAGE_MPFR + select BR2_PACKAGE_MPC + help + If you want the target system to be able to run + binutils/gcc and compile native code, say Y here. + +config BR2_EXTRA_TARGET_GCC_CONFIG_OPTIONS + string "Additional target gcc options" + default "" + depends on BR2_PACKAGE_GCC_TARGET + help + Any additional target gcc options you may want to include.... + Including, but not limited to --disable-checking etc. + Refer to */configure in your gcc sources. + diff --git a/package/gcc/gcc-target/gcc-target.hash b/package/gcc/gcc-target/gcc-target.hash new file mode 120000 index 0000000000..7ac9361ab2 --- /dev/null +++ b/package/gcc/gcc-target/gcc-target.hash @@ -0,0 +1 @@ +../gcc.hash \ No newline at end of file diff --git a/package/gcc/gcc-target/gcc-target.mk b/package/gcc/gcc-target/gcc-target.mk new file mode 100644 index 0000000000..56673f390c --- /dev/null +++ b/package/gcc/gcc-target/gcc-target.mk @@ -0,0 +1,78 @@ +################################################################################ +# +# gcc-target +# +################################################################################ + +GCC_TARGET_VERSION = $(GCC_VERSION) +GCC_TARGET_SITE = $(GCC_SITE) +GCC_TARGET_SOURCE = $(GCC_SOURCE) + +# Use the same archive as gcc-initial and gcc-final +GCC_TARGET_DL_SUBDIR = gcc + +GCC_TARGET_DEPENDENCIES = gmp mpfr mpc + +# First, we use HOST_GCC_COMMON_MAKE_OPTS to get a lot of correct flags (such as +# the arch, abi, float support, etc.) which are based on the config used to +# build the internal toolchain +GCC_TARGET_CONF_OPTS = $(HOST_GCC_COMMON_CONF_OPTS) +# Then, we modify incorrect flags from HOST_GCC_COMMON_CONF_OPTS +GCC_TARGET_CONF_OPTS += \ + --with-sysroot=/ \ + --with-build-sysroot=$(STAGING_DIR) \ + --disable-__cxa_atexit \ + --with-gmp=$(STAGING_DIR) \ + --with-mpc=$(STAGING_DIR) \ + --with-mpfr=$(STAGING_DIR) +# Then, we force certain flags that may appear in HOST_GCC_COMMON_CONF_OPTS +GCC_TARGET_CONF_OPTS += \ + --disable-libquadmath \ + --disable-libsanitizer \ + --disable-plugin \ + --disable-lto +# Finally, we add some of our own flags +GCC_TARGET_CONF_OPTS += \ + --enable-languages=c \ + --disable-boostrap \ + --disable-libgomp \ + --disable-nls \ + --disable-libmpx \ + --disable-gcov \ + $(EXTRA_TARGET_GCC_CONFIG_OPTIONS) + +GCC_TARGET_CONF_ENV = $(HOST_GCC_COMMON_CONF_ENV) + +GCC_TARGET_MAKE_OPTS += $(HOST_GCC_COMMON_MAKE_OPTS) + +# Install standard C headers (from glibc) +define GCC_TARGET_INSTALL_HEADERS + cp -r $(STAGING_DIR)/usr/include $(TARGET_DIR)/usr +endef +GCC_TARGET_POST_INSTALL_TARGET_HOOKS += GCC_TARGET_INSTALL_HEADERS + +# Install standard C libraries (from glibc) +GCC_TARGET_GLIBC_LIBS = \ + *crt*.o *_nonshared.a \ + libBrokenLocale.so libanl.so libbfd.so libc.so libcrypt.so libdl.so \ + libm.so libnss_compat.so libnss_db.so libnss_files.so libnss_hesiod.so \ + libpthread.so libresolv.so librt.so libthread_db.so libutil.so + +define GCC_TARGET_INSTALL_LIBS + for libpattern in $(GCC_TARGET_GLIBC_LIBS); do \ + $(call copy_toolchain_lib_root,$$libpattern) ; \ + done +endef +GCC_TARGET_POST_INSTALL_TARGET_HOOKS += GCC_TARGET_INSTALL_LIBS + +# Remove unnecessary files (extra links to gcc binaries, and libgcc which is +# already in `/lib`) +define GCC_TARGET_RM_FILES + rm -f $(TARGET_DIR)/usr/bin/$(ARCH)-buildroot-linux-gnu-gcc* + rm -f $(TARGET_DIR)/usr/lib/libgcc_s*.so* + rm -f $(TARGET_DIR)/usr/$(ARCH)-buildroot-linux-gnu/lib/ldscripts/elf32* + rm -f $(TARGET_DIR)/usr/$(ARCH)-buildroot-linux-gnu/lib/ldscripts/elf64b* +endef +GCC_TARGET_POST_INSTALL_TARGET_HOOKS += GCC_TARGET_RM_FILES + +$(eval $(autotools-package)) -- 2.34.1 From 41de9c1de3ecddcca5b43f2a41d055add99ffc4c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=ABl=20Porquet-Lupine?= Date: Thu, 16 Dec 2021 18:14:58 -0800 Subject: [PATCH 2/3] Add gcc-target to buildroot config system MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Joël Porquet-Lupine --- package/Config.in | 1 + 1 file changed, 1 insertion(+) diff --git a/package/Config.in b/package/Config.in index e4a66273e1..b8cc9d86a5 100644 --- a/package/Config.in +++ b/package/Config.in @@ -171,6 +171,7 @@ menu "Development tools" source "package/flex/Config.in" source "package/gawk/Config.in" source "package/gcc-target/Config.in" + source "package/gcc/Config.in" source "package/gettext/Config.in" source "package/gettext-gnu/Config.in" source "package/gettext-tiny/Config.in" -- 2.34.1 From e0e4ca0f6e11f30cf12e8bda6f9488af0c305c4e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=ABl=20Porquet-Lupine?= Date: Thu, 16 Dec 2021 18:10:09 -0800 Subject: [PATCH 3/3] Makefile: don't remove files necessary for gcc-target MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit For gcc-target to work, we need the headers and the libraries from the compiler/libc. By default, Buildroot unfortunately removes them out of the target. Signed-off-by: Joël Porquet-Lupine --- Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 3923e5875f..af031a4c5a 100644 --- a/Makefile +++ b/Makefile @@ -738,13 +738,13 @@ target-finalize: $(PACKAGES) $(TARGET_DIR) host-finalize @$(call MESSAGE,"Finalizing target directory") $(call per-package-rsync,$(sort $(PACKAGES)),target,$(TARGET_DIR)) $(foreach hook,$(TARGET_FINALIZE_HOOKS),$($(hook))$(sep)) - rm -rf $(TARGET_DIR)/usr/include $(TARGET_DIR)/usr/share/aclocal \ + rm -rf $(TARGET_DIR)/usr/share/aclocal \ $(TARGET_DIR)/usr/lib/pkgconfig $(TARGET_DIR)/usr/share/pkgconfig \ $(TARGET_DIR)/usr/lib/cmake $(TARGET_DIR)/usr/share/cmake \ $(TARGET_DIR)/usr/doc find $(TARGET_DIR)/usr/{lib,share}/ -name '*.cmake' -print0 | xargs -0 rm -f find $(TARGET_DIR)/lib/ $(TARGET_DIR)/usr/lib/ $(TARGET_DIR)/usr/libexec/ \ - \( -name '*.a' -o -name '*.la' -o -name '*.prl' \) -print0 | xargs -0 rm -f + \( -name '*.la' -o -name '*.prl' \) -print0 | xargs -0 rm -f ifneq ($(BR2_PACKAGE_GDB),y) rm -rf $(TARGET_DIR)/usr/share/gdb endif -- 2.34.1