Skip to contentSkip to conversation

package/Makefile.in: use gcc wrappers for binutils tools

PATCH Superseded Norbert Lange 2 participants 4 messages Oct 14, 2020 – Oct 17, 2020

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/3 package/Makefile.in: use gcc wrappers for binutils tools

This will use gcc-ar, gcc-nm and gcc-ranlib instead of the normal binutils tools. The difference is that with the wrappers, gcc plugins will be automatically picked up.

I dont think there are any toolchains still supported that lack those wrappers, so it should be safe to use unconditionally. Otherwise an option needs to be added.

Note that binutils added some automatic loading with the 'bfd-plugins' directory (somewhere around 2.28), but the first implementation had issues, and generally depends on correctly setup symlinks (often broken, may point to some other gcc's library). The wrappers always work painless.

The original motivation (now ~2 years in use) was to add "-flto -ffat-lto-objects" to both BR2_TARGET_OPTIMIZATION and BR2_TARGET_LDFLAGS, and have target binaries lto optimized.

Not all packages will compile with this option, further work could white/blacklist packages (adding -fno-lto to the options).

---
 package/Makefile.in | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
package/Makefile.in +3 -3
index 51f5cbce4f..a03f0304d5 100644
@@ -198,15 +198,15 @@ TARGET_CROSS = $(HOST_DIR)/bin/$(TOOLCHAIN_EXTERNAL_PREFIX)-
 endif
 
 # Define TARGET_xx variables for all common binutils/gcc
-TARGET_AR       = $(TARGET_CROSS)ar
+TARGET_AR       = $(TARGET_CROSS)gcc-ar
 TARGET_AS       = $(TARGET_CROSS)as
 TARGET_CC       = $(TARGET_CROSS)gcc
 TARGET_CPP      = $(TARGET_CROSS)cpp
 TARGET_CXX      = $(TARGET_CROSS)g++
 TARGET_FC       = $(TARGET_CROSS)gfortran
 TARGET_LD       = $(TARGET_CROSS)ld
-TARGET_NM       = $(TARGET_CROSS)nm
-TARGET_RANLIB   = $(TARGET_CROSS)ranlib
+TARGET_NM       = $(TARGET_CROSS)gcc-nm
+TARGET_RANLIB   = $(TARGET_CROSS)gcc-ranlib
 TARGET_READELF  = $(TARGET_CROSS)readelf
 TARGET_OBJCOPY  = $(TARGET_CROSS)objcopy
 TARGET_OBJDUMP  = $(TARGET_CROSS)objdump
Signature · 1 line
2.28.0
#1 lore raw

PATCH 2/3 package/gcc: use binutils wrappers for target libs

This will use gcc-ar, gcc-nm and gcc-ranlib instead of the normal binutils tools. The difference is that with the wrappers, gcc plugins will be automatically picked up, which might be necessary with some flags.

---
 package/gcc/gcc.mk | 1 +
 1 file changed, 1 insertion(+)
package/gcc/gcc.mk +1 -0
index 114c2887a0..9be155c3ff 100644
@@ -99,6 +99,7 @@ GCC_COMMON_TARGET_CFLAGS += -Wno-error
 endif
 
 # Propagate options used for target software building to GCC target libs
+HOST_GCC_COMMON_CONF_ENV += AR_FOR_TARGET=gcc-ar NM_FOR_TARGET=gcc-nm RANLIB_FOR_TARGET=gcc-ranlib
 HOST_GCC_COMMON_CONF_ENV += CFLAGS_FOR_TARGET="$(GCC_COMMON_TARGET_CFLAGS)"
 HOST_GCC_COMMON_CONF_ENV += CXXFLAGS_FOR_TARGET="$(GCC_COMMON_TARGET_CXXFLAGS)"
 
Signature · 1 line
2.28.0
#2 lore raw

PATCH 3/3 package/busybox: explicitly state binutil paths

In reply to Norbert Lange

Pass paths to ar, nm, ranlib binaries. This allows linker-plugins to be used.

---
 package/busybox/busybox.mk | 3 +++
 1 file changed, 3 insertions(+)
package/busybox/busybox.mk +3 -0
index 7862beb790..ddac4070d6 100644
@@ -93,6 +93,9 @@ BUSYBOX_MAKE_ENV += \
 endif
 
 BUSYBOX_MAKE_OPTS = \
+	AR="$(TARGET_AR)" \
+	NM="$(TARGET_NM)" \
+	RANLIB="$(TARGET_RANLIB)" \
 	CC="$(TARGET_CC)" \
 	ARCH=$(KERNEL_ARCH) \
 	PREFIX="$(TARGET_DIR)" \
Signature · 1 line
2.28.0
#3 lore raw

PATCH 1/3 package/Makefile.in: use gcc wrappers for binutils tools

In reply to Norbert Lange

Norbert, All,

On 2020-10-14 21:39 +0200, Norbert Lange spake thusly:

Quoted 7 lines

This will use gcc-ar, gcc-nm and gcc-ranlib instead of the normal binutils tools. The difference is that with the wrappers, gcc plugins will be automatically picked up.

I dont think there are any toolchains still supported that lack those wrappers, so it should be safe to use unconditionally. Otherwise an option needs to be added.

When were they added? We are supposed to still support building with at least back to gcc-4.3:

https://git.buildroot.org/buildroot/tree/toolchain/Config.in#n557

Regards,
Yann E. MORIN.

Quoted 49 lines

Note that binutils added some automatic loading with the 'bfd-plugins' directory (somewhere around 2.28), but the first implementation had issues, and generally depends on correctly setup symlinks (often broken, may point to some other gcc's library). The wrappers always work painless.

The original motivation (now ~2 years in use) was to add "-flto -ffat-lto-objects" to both BR2_TARGET_OPTIMIZATION and BR2_TARGET_LDFLAGS, and have target binaries lto optimized.

Not all packages will compile with this option, further work could white/blacklist packages (adding -fno-lto to the options).

---
 package/Makefile.in | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
package/Makefile.in +3 -3
index 51f5cbce4f..a03f0304d5 100644
@@ -198,15 +198,15 @@ TARGET_CROSS = $(HOST_DIR)/bin/$(TOOLCHAIN_EXTERNAL_PREFIX)-
 endif
 
 # Define TARGET_xx variables for all common binutils/gcc
-TARGET_AR       = $(TARGET_CROSS)ar
+TARGET_AR       = $(TARGET_CROSS)gcc-ar
 TARGET_AS       = $(TARGET_CROSS)as
 TARGET_CC       = $(TARGET_CROSS)gcc
 TARGET_CPP      = $(TARGET_CROSS)cpp
 TARGET_CXX      = $(TARGET_CROSS)g++
 TARGET_FC       = $(TARGET_CROSS)gfortran
 TARGET_LD       = $(TARGET_CROSS)ld
-TARGET_NM       = $(TARGET_CROSS)nm
-TARGET_RANLIB   = $(TARGET_CROSS)ranlib
+TARGET_NM       = $(TARGET_CROSS)gcc-nm
+TARGET_RANLIB   = $(TARGET_CROSS)gcc-ranlib
 TARGET_READELF  = $(TARGET_CROSS)readelf
 TARGET_OBJCOPY  = $(TARGET_CROSS)objcopy
 TARGET_OBJDUMP  = $(TARGET_CROSS)objdump
Signature · 6 lines
2.28.0

_______________________________________________
buildroot mailing list
buildroot at busybox.net
http://lists.busybox.net/mailman/listinfo/buildroot
Signature · 6 lines
.-----------------.--------------------.------------------.--------------------.
|  Yann E. MORIN  | Real-Time Embedded | /"\ ASCII RIBBON | Erics' conspiracy: |
| +33 662 376 056 | Software  Designer | \ / CAMPAIGN     |  ___               |
| +33 561 099 427 `------------.-------:  X  AGAINST      |  \e/  There is no  |
| http://ymorin.is-a-geek.org/ | _/*\_ | / \ HTML MAIL    |   v   conspiracy.  |
'------------------------------^-------^------------------^--------------------'