Skip to contentSkip to conversation

linux-tools/perf: fix build for MIPS by using the right emulation on LD

PATCH New Vicente Olivert Riera 3 participants 4 messages Feb 17, 2017 – Oct 23, 2017

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 linux-tools/perf: fix build for MIPS by using the right emulation on LD

Passing just the endianness flag to LD is not enough. We need to pass the right emulation flag which will set everything for us, not only the endianness.

---
 package/linux-tools/linux-tool-perf.mk | 30 +++++++++++++++++++-----------
 1 file changed, 19 insertions(+), 11 deletions(-)
package/linux-tools/linux-tool-perf.mk +19 -11
index 16f3a58..69492ba 100644
@@ -28,17 +28,25 @@ PERF_MAKE_FLAGS = \
 	NO_LIBPYTHON=1 \
 	NO_LIBBIONIC=1
 
-# We need to pass an argument to ld for setting the endianness when
-# building it for MIPS architecture, otherwise the default one will
-# always be used (which is big endian) and the compilation for little
-# endian will always fail showing an error like this one:
-#  LD    foo.o
-# mips-linux-gnu-ld: foo.o: compiled for a little endian system and
-# target is big endian
-ifeq ($(BR2_mips)$(BR2_mips64),y)
-PERF_MAKE_FLAGS += LD="$(TARGET_LD) -EB"
-else ifeq ($(BR2_mipsel)$(BR2_mips64el),y)
-PERF_MAKE_FLAGS += LD="$(TARGET_LD) -EL"
+# We need to pass an argument to ld for setting the emulation when
+# building for MIPS architecture, otherwise the default one will always
+# be used and the compilation for most variants will fail.
+ifeq ($(BR2_mips),y)
+PERF_MAKE_FLAGS += LD="$(TARGET_LD) -m elf32btsmip"
+else ifeq ($(BR2_mipsel),y)
+PERF_MAKE_FLAGS += LD="$(TARGET_LD) -m elf32ltsmip"
+else ifeq ($(BR2_mips64),y)
+ifeq ($(BR2_MIPS_NABI32),y)
+PERF_MAKE_FLAGS += LD="$(TARGET_LD) -m elf32btsmipn32"
+else
+PERF_MAKE_FLAGS += LD="$(TARGET_LD) -m elf64btsmip"
+endif
+else ifeq ($(BR2_mips64el),y)
+ifeq ($(BR2_MIPS_NABI32),y)
+PERF_MAKE_FLAGS += LD="$(TARGET_LD) -m elf32ltsmipn32"
+else
+PERF_MAKE_FLAGS += LD="$(TARGET_LD) -m elf64ltsmip"
+endif
 endif
 
 # The call to backtrace() function fails for ARC, because for some
Signature · 1 line
2.10.2
#1 lore raw

PATCH 1/1 linux-tools/perf: fix build for MIPS by using the right emulation on LD

Hello,

Quoted 10 lines · Vicente Olivert Riera
package/linux-tools/linux-tool-perf.mk +10 -0
+# We need to pass an argument to ld for setting the emulation when
+# building for MIPS architecture, otherwise the default one will always
+# be used and the compilation for most variants will fail.
+ifeq ($(BR2_mips),y)
+PERF_MAKE_FLAGS += LD="$(TARGET_LD) -m elf32btsmip"
+else ifeq ($(BR2_mipsel),y)
+PERF_MAKE_FLAGS += LD="$(TARGET_LD) -m elf32ltsmip"
+else ifeq ($(BR2_mips64),y)
+ifeq ($(BR2_MIPS_NABI32),y)
+PERF_MAKE_FLAGS += LD="$(TARGET_LD) -m elf32btsmipn32"

package/linux-tools/linux-tool-perf.mk PERF_MAKE_FLAGS = \ · line 50

Quoted 10 lines
package/linux-tools/linux-tool-perf.mk +9 -0
+else
+PERF_MAKE_FLAGS += LD="$(TARGET_LD) -m elf64btsmip"
+endif
+else ifeq ($(BR2_mips64el),y)
+ifeq ($(BR2_MIPS_NABI32),y)
+PERF_MAKE_FLAGS += LD="$(TARGET_LD) -m elf32ltsmipn32"
+else
+PERF_MAKE_FLAGS += LD="$(TARGET_LD) -m elf64ltsmip"
+endif
 endif

This is really getting nasty, especially since gcc already knows about this. Why not use gcc instead of ld?

Thomas

Signature · 3 lines
Thomas Petazzoni, CTO, Free Electrons
Embedded Linux and Kernel engineering
http://free-electrons.com
#2 lore raw

PATCH 1/1 linux-tools/perf: fix build for MIPS by using the right emulation on LD

Hi Thomas,

Quoted 19 lines · Thomas Petazzoni

Hello,

Quoted 15 lines · Vicente Olivert Riera
package/linux-tools/linux-tool-perf.mk +15 -0
+# We need to pass an argument to ld for setting the emulation when
+# building for MIPS architecture, otherwise the default one will always
+# be used and the compilation for most variants will fail.
+ifeq ($(BR2_mips),y)
+PERF_MAKE_FLAGS += LD="$(TARGET_LD) -m elf32btsmip"
+else ifeq ($(BR2_mipsel),y)
+PERF_MAKE_FLAGS += LD="$(TARGET_LD) -m elf32ltsmip"
+else ifeq ($(BR2_mips64),y)
+ifeq ($(BR2_MIPS_NABI32),y)
+PERF_MAKE_FLAGS += LD="$(TARGET_LD) -m elf32btsmipn32"
+else
+PERF_MAKE_FLAGS += LD="$(TARGET_LD) -m elf64btsmip"
+endif
+else ifeq ($(BR2_mips64el),y)
+ifeq ($(BR2_MIPS_NABI32),y)
Quoted 8 lines

package/linux-tools/linux-tool-perf.mk PERF_MAKE_FLAGS = \ · line 50

Quoted 5 lines
package/linux-tools/linux-tool-perf.mk +4 -0
+PERF_MAKE_FLAGS += LD="$(TARGET_LD) -m elf32ltsmipn32"
+else
+PERF_MAKE_FLAGS += LD="$(TARGET_LD) -m elf64ltsmip"
+endif
 endif

This is really getting nasty, especially since gcc already knows about this. Why not use gcc instead of ld?

Ideally, perf's build system would use gcc for linking instead of ld, but that's not the case.

This is something we discussed in the past when we were talking about creating a wrapper for ld, as we already have for gcc. We decided to not do it and instead let those packages that were using ld for linking to fail, so we could identify them and fix their build system in order to link with gcc instead.

But, what happen when you really need to fix the problem and you don't have the time/skills/whatever to modify the package's build system to make it link with gcc?

Regards,

Vincent

Quoted 3 lines

Thomas

#3 lore raw

PATCH 1/1 linux-tools/perf: fix build for MIPS by using the right emulation on LD

In reply to Vicente Olivert Riera
Quoted 5 lines · Vicente Olivert Riera

Passing just the endianness flag to LD is not enough. We need to pass the right emulation flag which will set everything for us, not only the endianness.

Since there really is no other way to fix this problem, even if the fix is
ugly, I've applied to master, thanks.

If anyone can come up with a better way (not involving an LD wrapper - just a
few places need it so it's not worth it), please speak up!

Regards,
Arnout

Quoted 46 lines
---
 package/linux-tools/linux-tool-perf.mk | 30 +++++++++++++++++++-----------
 1 file changed, 19 insertions(+), 11 deletions(-)
package/linux-tools/linux-tool-perf.mk +19 -11
index 16f3a58..69492ba 100644
@@ -28,17 +28,25 @@ PERF_MAKE_FLAGS = \
 	NO_LIBPYTHON=1 \
 	NO_LIBBIONIC=1
 
-# We need to pass an argument to ld for setting the endianness when
-# building it for MIPS architecture, otherwise the default one will
-# always be used (which is big endian) and the compilation for little
-# endian will always fail showing an error like this one:
-#  LD    foo.o
-# mips-linux-gnu-ld: foo.o: compiled for a little endian system and
-# target is big endian
-ifeq ($(BR2_mips)$(BR2_mips64),y)
-PERF_MAKE_FLAGS += LD="$(TARGET_LD) -EB"
-else ifeq ($(BR2_mipsel)$(BR2_mips64el),y)
-PERF_MAKE_FLAGS += LD="$(TARGET_LD) -EL"
+# We need to pass an argument to ld for setting the emulation when
+# building for MIPS architecture, otherwise the default one will always
+# be used and the compilation for most variants will fail.
+ifeq ($(BR2_mips),y)
+PERF_MAKE_FLAGS += LD="$(TARGET_LD) -m elf32btsmip"
+else ifeq ($(BR2_mipsel),y)
+PERF_MAKE_FLAGS += LD="$(TARGET_LD) -m elf32ltsmip"
+else ifeq ($(BR2_mips64),y)
+ifeq ($(BR2_MIPS_NABI32),y)
+PERF_MAKE_FLAGS += LD="$(TARGET_LD) -m elf32btsmipn32"
+else
+PERF_MAKE_FLAGS += LD="$(TARGET_LD) -m elf64btsmip"
+endif
+else ifeq ($(BR2_mips64el),y)
+ifeq ($(BR2_MIPS_NABI32),y)
+PERF_MAKE_FLAGS += LD="$(TARGET_LD) -m elf32ltsmipn32"
+else
+PERF_MAKE_FLAGS += LD="$(TARGET_LD) -m elf64ltsmip"
+endif
 endif
 
 # The call to backtrace() function fails for ARC, because for some
Signature · 6 lines
Arnout Vandecappelle                          arnout at mind be
Senior Embedded Software Architect            +32-16-286500
Essensium/Mind                                http://www.mind.be
G.Geenslaan 9, 3001 Leuven, Belgium           BE 872 984 063 RPR Leuven
LinkedIn profile: http://www.linkedin.com/in/arnoutvandecappelle
GPG fingerprint:  7493 020B C7E3 8618 8DEC 222C 82EB F404 F9AC 0DDF