From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 9FF333858C74; Wed, 27 Sep 2023 04:31:12 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 9FF333858C74 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1695789072; bh=FZd05Son2eodn4xk/C1G3rCSv6fDMqFJm4lNXdOELfU=; h=From:To:Subject:Date:From; b=wFvZR+NfHzytP9h4bI5cCWSnWvUvbhJXHg/G9qfivsVM0V8Ie5PWwq576e7NMdZpx s+kNKS97fDxVJGxnzqSAKDYVIOFWPp97VXpKxPX4oFButDqMBS/XrJncPNb/eLzvl7 mVby1x3qWp8hZgicSj2AILxpKXEYVge0WvunYnfE= From: "rui314 at gmail dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/111605] New: Cross compilation doesn't work with `-fuse-ld=mold` Date: Wed, 27 Sep 2023 04:31:12 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: c++ X-Bugzilla-Version: unknown X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: rui314 at gmail dot com X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: bug_id short_desc product version bug_status bug_severity priority component assigned_to reporter target_milestone Message-ID: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 List-Id: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D111605 Bug ID: 111605 Summary: Cross compilation doesn't work with `-fuse-ld=3Dmold` Product: gcc Version: unknown Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: rui314 at gmail dot com Target Milestone: --- When I pass `-fuse-ld=3Dmold` to a gcc cross compiler, gcc searches for `ld= .mold` from the crosstool's bin directories and then looks for `-ld.mold` = from $PATH. Here is a gcc's strace when invoked with `-fuse-ld=3Dmold`. [pid 3905484] newfstatat(AT_FDCWD, "/usr/lib/gcc-cross/riscv64-linux-gnu/11/ld.mold", 0x7ffdd5a491a0, 0) =3D -1 ENOENT (No such file or directory) [pid 3905484] newfstatat(AT_FDCWD, "/usr/lib/gcc-cross/riscv64-linux-gnu/11/ld.mold", 0x7ffdd5a491a0, 0) =3D -1 ENOENT (No such file or directory) [pid 3905484] newfstatat(AT_FDCWD, "/usr/lib/gcc-cross/riscv64-linux-gnu/ld.mold", 0x7ffdd5a491a0, 0) =3D -1 E= NOENT (No such file or directory) [pid 3905484] newfstatat(AT_FDCWD, "/usr/lib/gcc-cross/riscv64-linux-gnu/11/ld.mold", 0x7ffdd5a491a0, 0) =3D -1 ENOENT (No such file or directory) [pid 3905484] newfstatat(AT_FDCWD, "/usr/lib/gcc-cross/riscv64-linux-gnu/ld.mold", 0x7ffdd5a491a0, 0) =3D -1 E= NOENT (No such file or directory) [pid 3905484] newfstatat(AT_FDCWD, "/usr/lib/gcc-cross/riscv64-linux-gnu/11/../../../../riscv64-linux-gnu/bin/= ld.mold", 0x7ffdd5a491a0, 0) =3D -1 ENOENT (No such file or directory) [pid 3905484] newfstatat(AT_FDCWD, "/home/ruiu/.cargo/bin/riscv64-linux-gnu-ld.mold", 0x7ffdd5a491a0, 0) =3D -1 ENOENT (No such file or directory) [pid 3905484] newfstatat(AT_FDCWD, "/home/ruiu/.local/bin/riscv64-linux-gnu-ld.mold", 0x7ffdd5a491a0, 0) =3D -1 ENOENT (No such file or directory) [pid 3905484] newfstatat(AT_FDCWD, "/home/ruiu/bin/riscv64-linux-gnu-ld.mol= d", 0x7ffdd5a491a0, 0) =3D -1 ENOENT (No such file or directory) [pid 3905484] newfstatat(AT_FDCWD, "/home/ruiu/.cabal/bin/riscv64-linux-gnu-ld.mold", 0x7ffdd5a491a0, 0) =3D -1 ENOENT (No such file or directory) [pid 3905484] newfstatat(AT_FDCWD, "/home/ruiu/prefix/bin/riscv64-linux-gnu-ld.mold", 0x7ffdd5a491a0, 0) =3D -1 ENOENT (No such file or directory) [pid 3905484] newfstatat(AT_FDCWD, "/home/ruiu/bin/qemu/bin/riscv64-linux-gnu-ld.mold", 0x7ffdd5a491a0, 0) =3D= -1 ENOENT (No such file or directory) [pid 3905484] newfstatat(AT_FDCWD, "/usr/lib/ccache/riscv64-linux-gnu-ld.mo= ld", 0x7ffdd5a491a0, 0) =3D -1 ENOENT (No such file or directory) [pid 3905484] newfstatat(AT_FDCWD, "/home/ruiu/bin/riscv64-linux-gnu-ld.mol= d", 0x7ffdd5a491a0, 0) =3D -1 ENOENT (No such file or directory) [pid 3905484] newfstatat(AT_FDCWD, "/home/ruiu/golang/bin/riscv64-linux-gnu-ld.mold", 0x7ffdd5a491a0, 0) =3D -1 ENOENT (No such file or directory) [pid 3905484] newfstatat(AT_FDCWD, "/home/ruiu/.mozbuild/node/bin/riscv64-linux-gnu-ld.mold", 0x7ffdd5a491a0, = 0) =3D -1 ENOENT (No such file or directory) [pid 3905484] newfstatat(AT_FDCWD, "/home/ruiu/bin/depot_tools/riscv64-linux-gnu-ld.mold", 0x7ffdd5a491a0, 0) = =3D -1 ENOENT (No such file or directory) [pid 3905484] newfstatat(AT_FDCWD, "/usr/local/sbin/riscv64-linux-gnu-ld.mo= ld", 0x7ffdd5a491a0, 0) =3D -1 ENOENT (No such file or directory) [pid 3905484] newfstatat(AT_FDCWD, "/usr/local/bin/riscv64-linux-gnu-ld.mol= d", 0x7ffdd5a491a0, 0) =3D -1 ENOENT (No such file or directory) [pid 3905484] newfstatat(AT_FDCWD, "/usr/sbin/riscv64-linux-gnu-ld.mold", 0x7ffdd5a491a0, 0) =3D -1 ENOENT (No such file or directory) [pid 3905484] newfstatat(AT_FDCWD, "/usr/bin/riscv64-linux-gnu-ld.mold", 0x7ffdd5a491a0, 0) =3D -1 ENOENT (No such file or directory) [pid 3905484] newfstatat(AT_FDCWD, "/sbin/riscv64-linux-gnu-ld.mold", 0x7ffdd5a491a0, 0) =3D -1 ENOENT (No such file or directory) [pid 3905484] newfstatat(AT_FDCWD, "/bin/riscv64-linux-gnu-ld.mold", 0x7ffdd5a491a0, 0) =3D -1 ENOENT (No such file or directory) [pid 3905484] newfstatat(AT_FDCWD, "/usr/games/riscv64-linux-gnu-ld.mold", 0x7ffdd5a491a0, 0) =3D -1 ENOENT (No such file or directory) [pid 3905484] newfstatat(AT_FDCWD, "/usr/local/games/riscv64-linux-gnu-ld.mold", 0x7ffdd5a491a0, 0) =3D -1 ENO= ENT (No such file or directory) [pid 3905484] newfstatat(AT_FDCWD, "/snap/bin/riscv64-linux-gnu-ld.mold", 0x7ffdd5a491a0, 0) =3D -1 ENOENT (No such file or directory) This behavior is appropriate for BFD linker which has one executable for ea= ch cross target. However, it's incorrect for the mold linker because mold supp= orts all targets by a single executable. Therefore, when gcc searches mold from $PATH, it should look for just `ld.mold`, without the triple. The same is true for LLD. The link to the upstream bug: https://github.com/rui314/mold/issues/1114=