Skip to contentSkip to conversation

package/binutils+elf2flt: fix for noMMU targets

PATCH New Yann E. MORIN 2 participants 7 messages May 28, 2018 – Jun 18, 2018

lore
Share & tools
lore
#0 lore raw

v2 cover package/binutils+elf2flt: fix for noMMU targets

Hello All!

TL;DR: gcc gets confused by our symlinks trick that we use to fix the rpath handling. This series de-hardlinks using copies instead of symlinks.

See the first commit for the whole story.

Fixes #11031.

Regards,
Yann E. MORIN.

The following changes since commit d28591a2ee39704f6795c8aa1d0a3db7e909facc

poppler: link with libatomic when needed (2018-05-28 20:23:18 +0200)

are available in the git repository at:

git://git.buildroot.org/~ymorin/git/buildroot.git

for you to fetch changes up to 99b5f16248ada22680df533f78869bcf552e06d9

package/elf2flt: replace hard-links with copies to fix rpath (2018-05-28 21:22:22 +0200)

----------------------------------------------------------------
Yann E. MORIN (2):
package/binutils: switch from symlinks to copies to fix rpath package/elf2flt: replace hard-links with copies to fix rpath

 package/binutils/binutils.mk |  7 ++++---
 package/elf2flt/elf2flt.mk   | 16 ++++++++++++++++
 2 files changed, 20 insertions(+), 3 deletions(-)
Signature · 6 lines
.-----------------.--------------------.------------------.--------------------.
|  Yann E. MORIN  | Real-Time Embedded | /"\ ASCII RIBBON | Erics' conspiracy: |
| +33 662 376 056 | Software  Designer | \ / CAMPAIGN     |  ___               |
| +33 223 225 172 `------------.-------:  X  AGAINST      |  \e/  There is no  |
| http://ymorin.is-a-geek.org/ | _/*\_ | / \ HTML MAIL    |   v   conspiracy.  |
'------------------------------^-------^------------------^--------------------'
#1 lore raw

PATCH v2 1/2 package/binutils: switch from symlinks to copies to fix rpath

Commit f9cffb6af464 (binutils: replace hard-links with soft-links to fix rpath) has a side effect that when we build for a noMMU target, elf2flt will in turn replace some of the programs installed by binutils, with its own wrappers.

For example, it will rename host/TUPLE/bin/ld to ld.real, and add its own wrapper in place of the original. It does the same for host/bin/TUPLE-ld and host/bin/TUPLE-ld.real.

However, we had already made ld a symlink to ../../bin/TUPLE-ld, so host/TUPLE/bin/ld.real will still point to host/bin/TUPLE-ld when we want it to point to ld.real instead...

This ultimately confuses gcc later on.

Of course, the culprit is also elf2flt, which also installs similar hardlinks that would ultimately exhibit the same rpath issue as the one fixed by f9cffb6af464. Note: we haven't had an issue so far with that, because those tools installed by elf2flt only link with libz, which is most often present on the host system. So, all seem well, but is nonetheless broken; this will be fixed in a subsequent commit.

But back on topic. If we were to fix elf2flt with similar symlinks, gcc still gets confused. The underlying reason for this confusion is not entirely clear, though... It looks like something is trying to dereference symlinks and gets confused by the result somehow...

So, in an attempt to restore some sanity in all this mess, we try to restore the previous behaviour, we no longer use symlinks but just copy the individual tools.

Fixes #11031.
Cc Christophe Priouzeau <[email protected]>
Cc Thomas Petazzoni <[email protected]>
Cc Peter Korsgaard <[email protected]>
Cc Arnout Vandecappelle <[email protected]>

---
Changes v1 -> v2:
- use copies, not shell wrappers (Arnout)

---
 package/binutils/binutils.mk | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
package/binutils/binutils.mk +4 -3
index be9e652e10..1c05958f9c 100644
@@ -132,12 +132,13 @@ endif
 
 # Hardlinks between binaries in different directories cause a problem
 # with rpath fixup, so we de-hardlink those binaries, and replace them
-# with symbolic links.
+# with copies instead.
 BINUTILS_TOOLS = ar as ld ld.bfd nm objcopy objdump ranlib readelf strip
 define HOST_BINUTILS_FIXUP_HARDLINKS
 	$(foreach tool,$(BINUTILS_TOOLS),\
-		rm -f $(HOST_DIR)/$(GNU_TARGET_NAME)/bin/$(tool) ; \
-		ln -s ../../bin/$(GNU_TARGET_NAME)-$(tool) $(HOST_DIR)/$(GNU_TARGET_NAME)/bin/$(tool)
+		rm -f $(HOST_DIR)/$(GNU_TARGET_NAME)/bin/$(tool) && \
+		cp -a $(HOST_DIR)/bin/$(GNU_TARGET_NAME)-$(tool) \
+			$(HOST_DIR)/$(GNU_TARGET_NAME)/bin/$(tool)
 	)
 endef
 HOST_BINUTILS_POST_INSTALL_HOOKS += HOST_BINUTILS_FIXUP_HARDLINKS
Signature · 1 line
2.14.1
#2 lore raw

PATCH v2 1/2 package/binutils: switch from symlinks to copies to fix rpath

Quoted 41 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

"Yann" == Yann E MORIN <[email protected]> writes:

Commit f9cffb6af464 (binutils: replace hard-links with soft-links to fix rpath) has a side effect that when we build for a noMMU target, elf2flt will in turn replace some of the programs installed by binutils, with its own wrappers.

For example, it will rename host/TUPLE/bin/ld to ld.real, and add its own wrapper in place of the original. It does the same for host/bin/TUPLE-ld and host/bin/TUPLE-ld.real.

However, we had already made ld a symlink to ../../bin/TUPLE-ld, so host/TUPLE/bin/ld.real will still point to host/bin/TUPLE-ld when we want it to point to ld.real instead...

This ultimately confuses gcc later on.

Of course, the culprit is also elf2flt, which also installs similar hardlinks that would ultimately exhibit the same rpath issue as the one fixed by f9cffb6af464. Note: we haven't had an issue so far with that, because those tools installed by elf2flt only link with libz, which is most often present on the host system. So, all seem well, but is nonetheless broken; this will be fixed in a subsequent commit.

But back on topic. If we were to fix elf2flt with similar symlinks, gcc still gets confused. The underlying reason for this confusion is not entirely clear, though... It looks like something is trying to dereference symlinks and gets confused by the result somehow...

So, in an attempt to restore some sanity in all this mess, we try to restore the previous behaviour, we no longer use symlinks but just copy the individual tools.

Fixes #11031.
Cc Christophe Priouzeau <[email protected]>
Cc Thomas Petazzoni <[email protected]>
Cc Peter Korsgaard <[email protected]>
Cc Arnout Vandecappelle <[email protected]>
Quoted 3 lines

---
Changes v1 -> v2:
- use copies, not shell wrappers (Arnout)

Committed, thanks.

Signature · 1 line
Bye, Peter Korsgaard
#3 lore raw

PATCH v2 1/2 package/binutils: switch from symlinks to copies to fix rpath

In reply to Yann E. MORIN
Quoted 41 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

"Yann" == Yann E MORIN <[email protected]> writes:

Commit f9cffb6af464 (binutils: replace hard-links with soft-links to fix rpath) has a side effect that when we build for a noMMU target, elf2flt will in turn replace some of the programs installed by binutils, with its own wrappers.

For example, it will rename host/TUPLE/bin/ld to ld.real, and add its own wrapper in place of the original. It does the same for host/bin/TUPLE-ld and host/bin/TUPLE-ld.real.

However, we had already made ld a symlink to ../../bin/TUPLE-ld, so host/TUPLE/bin/ld.real will still point to host/bin/TUPLE-ld when we want it to point to ld.real instead...

This ultimately confuses gcc later on.

Of course, the culprit is also elf2flt, which also installs similar hardlinks that would ultimately exhibit the same rpath issue as the one fixed by f9cffb6af464. Note: we haven't had an issue so far with that, because those tools installed by elf2flt only link with libz, which is most often present on the host system. So, all seem well, but is nonetheless broken; this will be fixed in a subsequent commit.

But back on topic. If we were to fix elf2flt with similar symlinks, gcc still gets confused. The underlying reason for this confusion is not entirely clear, though... It looks like something is trying to dereference symlinks and gets confused by the result somehow...

So, in an attempt to restore some sanity in all this mess, we try to restore the previous behaviour, we no longer use symlinks but just copy the individual tools.

Fixes #11031.
Cc Christophe Priouzeau <[email protected]>
Cc Thomas Petazzoni <[email protected]>
Cc Peter Korsgaard <[email protected]>
Cc Arnout Vandecappelle <[email protected]>
Quoted 3 lines

---
Changes v1 -> v2:
- use copies, not shell wrappers (Arnout)

Committed to 2018.02.x, thanks.

Signature · 1 line
Bye, Peter Korsgaard
#4 lore raw

PATCH v2 2/2 package/elf2flt: replace hard-links with copies to fix rpath

In reply to Yann E. MORIN

Do for elf2flt what we did for binutils: replace the hardlinks (which break rpath handling) with copies of the individaul tools.

See previous commit (package/binutils: switch from symlinks to copies and commit f9cffb6af4 (binutils: replace hard-links with soft-links to fix rpath) for the complete story.

Fixes #11031.
Cc Christophe Priouzeau <[email protected]>
Cc Thomas Petazzoni <[email protected]>
Cc Peter Korsgaard <[email protected]>
Cc Arnout Vandecappelle <[email protected]>

---
Changes v1 -> v2:
- use copies, not shell wrappers (Arnout)

---
 package/elf2flt/elf2flt.mk | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)
package/elf2flt/elf2flt.mk +16 -0
index 995dfedebd..557f94d338 100644
@@ -29,4 +29,20 @@ endif
 
 HOST_ELF2FLT_CONF_ENV = LIBS="$(HOST_ELF2FLT_LIBS)"
 
+# Hardlinks between binaries in different directories cause a problem
+# with rpath fixup, so we de-hardlink those binaries, and replace them
+# with copies instead. Note that elf2flt will rename ld to ld.real
+# before installing its own ld, but we already took care of the
+# original ld from binutils so that it is already de-hardlinked. So
+# ld is now the one from elf2flt, and we want to de-hardlinke it.
+ELF2FLT_TOOLS = elf2flt flthdr ld
+define HOST_ELF2FLT_FIXUP_HARDLINKS
+	$(foreach tool,$(ELF2FLT_TOOLS),\
+		rm -f $(HOST_DIR)/$(GNU_TARGET_NAME)/bin/$(tool) && \
+		cp -a $(HOST_DIR)/bin/$(GNU_TARGET_NAME)-$(tool) \
+			$(HOST_DIR)/$(GNU_TARGET_NAME)/bin/$(tool)
+	)
+endef
+HOST_ELF2FLT_POST_INSTALL_HOOKS += HOST_ELF2FLT_FIXUP_HARDLINKS
+
 $(eval $(host-autotools-package))
Signature · 1 line
2.14.1
#5 lore raw

PATCH v2 2/2 package/elf2flt: replace hard-links with copies to fix rpath

Quoted 18 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

"Yann" == Yann E MORIN <[email protected]> writes:

Do for elf2flt what we did for binutils: replace the hardlinks (which break rpath handling) with copies of the individaul tools.

See previous commit (package/binutils: switch from symlinks to copies and commit f9cffb6af4 (binutils: replace hard-links with soft-links to fix rpath) for the complete story.

Fixes #11031.
Cc Christophe Priouzeau <[email protected]>
Cc Thomas Petazzoni <[email protected]>
Cc Peter Korsgaard <[email protected]>
Cc Arnout Vandecappelle <[email protected]>
Quoted 3 lines

---
Changes v1 -> v2:
- use copies, not shell wrappers (Arnout)

Committed, thanks.

Signature · 1 line
Bye, Peter Korsgaard
#6 lore raw

PATCH v2 2/2 package/elf2flt: replace hard-links with copies to fix rpath

In reply to Yann E. MORIN
Quoted 18 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

"Yann" == Yann E MORIN <[email protected]> writes:

Do for elf2flt what we did for binutils: replace the hardlinks (which break rpath handling) with copies of the individaul tools.

See previous commit (package/binutils: switch from symlinks to copies and commit f9cffb6af4 (binutils: replace hard-links with soft-links to fix rpath) for the complete story.

Fixes #11031.
Cc Christophe Priouzeau <[email protected]>
Cc Thomas Petazzoni <[email protected]>
Cc Peter Korsgaard <[email protected]>
Cc Arnout Vandecappelle <[email protected]>
Quoted 3 lines

---
Changes v1 -> v2:
- use copies, not shell wrappers (Arnout)

Committed to 2018.02.x, thanks.

Signature · 1 line
Bye, Peter Korsgaard