Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add two small tooldir prefix patches to aid cross-compiling #8

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 44 additions & 0 deletions 14.2.0/gentoo/12_all_tooldir_prefix_lib.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
From 018edcc1c4649cccc86d9cb248efbc5ec9357293 Mon Sep 17 00:00:00 2001
From: James Le Cuirot <[email protected]>
Date: Thu, 2 Jan 2025 12:54:41 +0000
Subject: [PATCH 1/3] Do not search for libs relative to the driver when
sysroot is changed

When specifying a sysroot, the intention is to link against libraries in
that sysroot rather than the toolchain's default sysroot. Having the
toolchain default take priority is problematic, as libraries there may
not be ABI compatible or may even have different sonames altogether.
The desired sysroot is also not applied to ld scripts.

Gentoo previously got away with this because only the toolchain's /lib
was searched rather than /usr/lib, and the former did not contain many
*.so files. Now that Gentoo is migrating cross environments to a
merged-usr layout, these directories are the same, triggering the above
issues much more frequently.

In particular, the toolchain's /usr/lib/libc.so ld script is found
before the sysroot's. This includes a reference to /lib/libc.so.6. The
sysroot is only applied to this when the ld script itself is within that
sysroot, so /lib/libc.so.6 is taken literally, causing the build
machine's libc to be used instead, which immediately breaks any linking.

Signed-off-by: James Le Cuirot <[email protected]>
---
gcc/gcc.cc | 1 +
1 file changed, 1 insertion(+)

diff --git a/gcc/gcc.cc b/gcc/gcc.cc
index 728332b81..bef473939 100644
--- a/gcc/gcc.cc
+++ b/gcc/gcc.cc
@@ -5496,6 +5496,7 @@ process_command (unsigned int decoded_options_count,
add_prefix (&exec_prefixes,
concat (tooldir_prefix, "bin", dir_separator_str, NULL),
"BINUTILS", PREFIX_PRIORITY_LAST, 0, 0);
+ if (!target_system_root_changed)
add_prefix (&startfile_prefixes,
concat (tooldir_prefix, "lib", dir_separator_str, NULL),
"BINUTILS", PREFIX_PRIORITY_LAST, 0, 1);
--
2.47.1

35 changes: 35 additions & 0 deletions 14.2.0/gentoo/13_all_tooldir_prefix_bin.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
From 886520dcf2a59105cc78573f4c5a5cb34ad05579 Mon Sep 17 00:00:00 2001
From: James Le Cuirot <[email protected]>
Date: Thu, 2 Jan 2025 12:46:55 +0000
Subject: [PATCH 2/3] Do not search for tools relative to the driver when
cross-compiling

On Gentoo, this location is /usr/${CHOST}/bin. Native toolchains put
symlinks to the binutils tools here. Cross toolchains only put
non-native binaries here. The binutils symlinks live under
/usr/libexec/gcc/${CHOST} instead, and that location is already
searched.

It would be better to fail to find a given tool than inadvertently try
to execute a non-native build of it via QEMU.

Signed-off-by: James Le Cuirot <[email protected]>
---
gcc/gcc.cc | 1 +
1 file changed, 1 insertion(+)

diff --git a/gcc/gcc.cc b/gcc/gcc.cc
index bef473939..20044bc3a 100644
--- a/gcc/gcc.cc
+++ b/gcc/gcc.cc
@@ -5493,6 +5493,7 @@ process_command (unsigned int decoded_options_count,
accel_dir_suffix, dir_separator_str, tooldir_prefix2, NULL);
free (tooldir_prefix2);

+ if (*cross_compile == '0')
add_prefix (&exec_prefixes,
concat (tooldir_prefix, "bin", dir_separator_str, NULL),
"BINUTILS", PREFIX_PRIORITY_LAST, 0, 0);
--
2.47.1

5 changes: 5 additions & 0 deletions 14.2.0/gentoo/README.history
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
8 ????

+ 12_all_tooldir_prefix_lib.patch
+ 13_all_tooldir_prefix_bin.patch

7 24 Dec 2024

U 70_all_PR117854-config-nvptx-fix-bashisms-with-gen-copyright.sh-use.patch
Expand Down
44 changes: 44 additions & 0 deletions 15.0.0/gentoo/12_all_tooldir_prefix_lib.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
From dc817f621aa5a99ce05d9336aa8ef57835fc009b Mon Sep 17 00:00:00 2001
From: James Le Cuirot <[email protected]>
Date: Thu, 2 Jan 2025 12:54:41 +0000
Subject: [PATCH 1/3] Do not search for libs relative to the driver when
sysroot is changed

When specifying a sysroot, the intention is to link against libraries in
that sysroot rather than the toolchain's default sysroot. Having the
toolchain default take priority is problematic, as libraries there may
not be ABI compatible or may even have different sonames altogether.
The desired sysroot is also not applied to ld scripts.

Gentoo previously got away with this because only the toolchain's /lib
was searched rather than /usr/lib, and the former did not contain many
*.so files. Now that Gentoo is migrating cross environments to a
merged-usr layout, these directories are the same, triggering the above
issues much more frequently.

In particular, the toolchain's /usr/lib/libc.so ld script is found
before the sysroot's. This includes a reference to /lib/libc.so.6. The
sysroot is only applied to this when the ld script itself is within that
sysroot, so /lib/libc.so.6 is taken literally, causing the build
machine's libc to be used instead, which immediately breaks any linking.

Signed-off-by: James Le Cuirot <[email protected]>
---
gcc/gcc.cc | 1 +
1 file changed, 1 insertion(+)

diff --git a/gcc/gcc.cc b/gcc/gcc.cc
index 95b98eaa8..210991153 100644
--- a/gcc/gcc.cc
+++ b/gcc/gcc.cc
@@ -5522,6 +5522,7 @@ process_command (unsigned int decoded_options_count,
add_prefix (&exec_prefixes,
concat (tooldir_prefix, "bin", dir_separator_str, NULL),
"BINUTILS", PREFIX_PRIORITY_LAST, 0, 0);
+ if (!target_system_root_changed)
add_prefix (&startfile_prefixes,
concat (tooldir_prefix, "lib", dir_separator_str, NULL),
"BINUTILS", PREFIX_PRIORITY_LAST, 0, 1);
--
2.47.1

35 changes: 35 additions & 0 deletions 15.0.0/gentoo/13_all_tooldir_prefix_bin.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
From cef4c8559cf0a3523d5ff0ae91e56ea6652456c7 Mon Sep 17 00:00:00 2001
From: James Le Cuirot <[email protected]>
Date: Thu, 2 Jan 2025 12:46:55 +0000
Subject: [PATCH 2/3] Do not search for tools relative to the driver when
cross-compiling

On Gentoo, this location is /usr/${CHOST}/bin. Native toolchains put
symlinks to the binutils tools here. Cross toolchains only put
non-native binaries here. The binutils symlinks live under
/usr/libexec/gcc/${CHOST} instead, and that location is already
searched.

It would be better to fail to find a given tool than inadvertently try
to execute a non-native build of it via QEMU.

Signed-off-by: James Le Cuirot <[email protected]>
---
gcc/gcc.cc | 1 +
1 file changed, 1 insertion(+)

diff --git a/gcc/gcc.cc b/gcc/gcc.cc
index 210991153..4188f0049 100644
--- a/gcc/gcc.cc
+++ b/gcc/gcc.cc
@@ -5519,6 +5519,7 @@ process_command (unsigned int decoded_options_count,
accel_dir_suffix, dir_separator_str, tooldir_prefix2, NULL);
free (tooldir_prefix2);

+ if (*cross_compile == '0')
add_prefix (&exec_prefixes,
concat (tooldir_prefix, "bin", dir_separator_str, NULL),
"BINUTILS", PREFIX_PRIORITY_LAST, 0, 0);
--
2.47.1

2 changes: 2 additions & 0 deletions 15.0.0/gentoo/README.history
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
36 ????

- 73_all_PR117629-c-special-case-some-bool-errors-with-C23.patch
+ 12_all_tooldir_prefix_lib.patch
+ 13_all_tooldir_prefix_bin.patch

35 30 December 2024

Expand Down