This is an archive of the discontinued LLVM Phabricator instance.

Support -fuse-ld=lld for riscv
ClosedPublic

Authored by serge-sans-paille on Feb 17 2020, 5:02 AM.

Diff Detail

Event Timeline

Add test case. This test fails with current master, see https://bugzilla.redhat.com/show_bug.cgi?id=1803698

I am worried about the interaction between -fuse-ld=lld and linker relaxation (which is not supported by LLD, as I understand it)

  1. clang could ignore -fuse-ld=lld when linker relaxation is enabled
  2. clang could ignore (disable) linker relaxation if -fuse-ld=lld is used

At the very least, a warning of some kind should be emitted if linker relaxation is combined with -fuse-ld=lld.

I am worried about the interaction between -fuse-ld=lld and linker relaxation (which is not supported by LLD, as I understand it)

  1. clang could ignore -fuse-ld=lld when linker relaxation is enabled
  2. clang could ignore (disable) linker relaxation if -fuse-ld=lld is used

At the very least, a warning of some kind should be emitted if linker relaxation is combined with -fuse-ld=lld.

This isn't a new problem. The Linux and FreeBSD toolchains already support -fuse-ld=lld properly, it's just the bare metal one that didn't. People also generally don't include -fuse-ld=lld in CFLAGS, only LDFLAGS, and there's no need to include -mno-relax in LDFLAGS, so I suspect you wouldn't catch many issues. These days (https://reviews.llvm.org/D71820), LLD will give you an informative error (rather than silently mis-linking) if you forget -mno-relax.

lenary accepted this revision.Feb 17 2020, 6:50 AM

This isn't a new problem. The Linux and FreeBSD toolchains already support -fuse-ld=lld properly, it's just the bare metal one that didn't. People also generally don't include -fuse-ld=lld in CFLAGS, only LDFLAGS, and there's no need to include -mno-relax in LDFLAGS, so I suspect you wouldn't catch many issues. These days (https://reviews.llvm.org/D71820), LLD will give you an informative error (rather than silently mis-linking) if you forget -mno-relax.

Ah, ok, I see how these parts fit together now.

LGTM!

This revision is now accepted and ready to land.Feb 17 2020, 6:50 AM
This revision was automatically updated to reflect the committed changes.

Hello @serge-sans-paille,

looks like these changes broke the ARM builders:
http://lab.llvm.org:8011/builders/llvm-clang-win-x-armv7l/builds/4749
http://lab.llvm.org:8011/builders/llvm-clang-win-x-aarch64/builds/4752

failed tests:

  • FAIL: Clang::riscv64-toolchain.c
  • FAIL: Clang::riscv32-toolchain.c

with the following error:

C:\buildbot\as-builder-1\llvm-clang-win-x-armv7l\llvm-project\clang\test\Driver\riscv64-toolchain.c:15:27: error: C-RV64-BAREMETAL-LP64: expected string not found in input

would you fix the problem or revert the commit?

Hello @serge-sans-paille,

looks like these changes broke the ARM builders:
http://lab.llvm.org:8011/builders/llvm-clang-win-x-armv7l/builds/4749
http://lab.llvm.org:8011/builders/llvm-clang-win-x-aarch64/builds/4752

failed tests:

  • FAIL: Clang::riscv64-toolchain.c
  • FAIL: Clang::riscv32-toolchain.c

with the following error:

C:\buildbot\as-builder-1\llvm-clang-win-x-armv7l\llvm-project\clang\test\Driver\riscv64-toolchain.c:15:27: error: C-RV64-BAREMETAL-LP64: expected string not found in input

would you fix the problem or revert the commit?

*Bump* We're also seeing this for our clang bots:

Failing Tests (4):
    Clang :: Driver/riscv32-toolchain-extra.c
    Clang :: Driver/riscv32-toolchain.c
    Clang :: Driver/riscv64-toolchain-extra.c
    Clang :: Driver/riscv64-toolchain.c

Would you mind addressing this or reverting? Thanks.

Builder log: https://luci-milo.appspot.com/p/fuchsia/builders/ci/clang-linux-x64/b8888123323499438832

I'll revert and propose an updated patch then.

The problem may be -DCLANG_DEFAULT_LINKER=lld.

(FWIW I really don't like supporting numerous -D configurations and ask authors to revert because of some weird -D configurations.)

jrtc27 reopened this revision.Feb 20 2020, 9:58 AM
This revision is now accepted and ready to land.Feb 20 2020, 9:58 AM
jrtc27 requested changes to this revision.Feb 20 2020, 9:58 AM
This revision now requires changes to proceed.Feb 20 2020, 9:58 AM

Add a configure feature test to filter out tests that depend on platform linker, as hinted by @MaskRay

MaskRay accepted this revision.Feb 21 2020, 9:37 AM
This revision was not accepted when it landed; it landed in state Needs Review.Feb 26 2020, 1:21 AM
This revision was automatically updated to reflect the committed changes.

Hi again, I think e058667a2e017d3225a9bb067dbac7f2159576f7 might've broken our toolchain again:

FAIL: Clang :: Driver/riscv32-toolchain-extra.c (5723 of 17018)
******************** TEST 'Clang :: Driver/riscv32-toolchain-extra.c' FAILED ********************
Script:
--
: 'RUN: at line 14';   mkdir -p /b/fuchsia-x86_64-linux/llvm.obj/tools/clang/stage2-bins/tools/clang/test/Driver/Output/testroot-riscv32-baremetal-nogcc/bin
: 'RUN: at line 15';   [ ! -s /b/fuchsia-x86_64-linux/llvm.obj/tools/clang/stage2-bins/tools/clang/test/Driver/Output/testroot-riscv32-baremetal-nogcc/bin/clang ] || rm /b/fuchsia-x86_64-linux/llvm.obj/tools/clang/stage2-bins/tools/clang/test/Driver/Output/testroot-riscv32-baremetal-nogcc/bin/clang
: 'RUN: at line 16';   [ ! -s /b/fuchsia-x86_64-linux/llvm.obj/tools/clang/stage2-bins/tools/clang/test/Driver/Output/testroot-riscv32-baremetal-nogcc/bin/riscv32-unknown-elf-ld ] || rm /b/fuchsia-x86_64-linux/llvm.obj/tools/clang/stage2-bins/tools/clang/test/Driver/Output/testroot-riscv32-baremetal-nogcc/bin/riscv32-unknown-elf-ld
: 'RUN: at line 17';   [ ! -s /b/fuchsia-x86_64-linux/llvm.obj/tools/clang/stage2-bins/tools/clang/test/Driver/Output/testroot-riscv32-baremetal-nogcc/riscv32-unknown-elf ] || rm /b/fuchsia-x86_64-linux/llvm.obj/tools/clang/stage2-bins/tools/clang/test/Driver/Output/testroot-riscv32-baremetal-nogcc/riscv32-unknown-elf
: 'RUN: at line 18';   ln -s /b/fuchsia-x86_64-linux/llvm.obj/tools/clang/stage2-bins/bin/clang /b/fuchsia-x86_64-linux/llvm.obj/tools/clang/stage2-bins/tools/clang/test/Driver/Output/testroot-riscv32-baremetal-nogcc/bin/clang
: 'RUN: at line 19';   ln -s /b/fuchsia-x86_64-linux/llvm.src/clang/test/Driver/Inputs/basic_riscv32_nogcc_tree/bin/riscv32-unknown-elf-ld /b/fuchsia-x86_64-linux/llvm.obj/tools/clang/stage2-bins/tools/clang/test/Driver/Output/testroot-riscv32-baremetal-nogcc/bin/riscv32-unknown-elf-ld
: 'RUN: at line 20';   ln -s /b/fuchsia-x86_64-linux/llvm.src/clang/test/Driver/Inputs/basic_riscv32_nogcc_tree/riscv32-unknown-elf /b/fuchsia-x86_64-linux/llvm.obj/tools/clang/stage2-bins/tools/clang/test/Driver/Output/testroot-riscv32-baremetal-nogcc/riscv32-unknown-elf
: 'RUN: at line 21';   /b/fuchsia-x86_64-linux/llvm.obj/tools/clang/stage2-bins/tools/clang/test/Driver/Output/testroot-riscv32-baremetal-nogcc/bin/clang /b/fuchsia-x86_64-linux/llvm.src/clang/test/Driver/riscv32-toolchain-extra.c -### -no-canonical-prefixes     --gcc-toolchain=/b/fuchsia-x86_64-linux/llvm.obj/tools/clang/stage2-bins/tools/clang/test/Driver/Output/testroot-riscv32-baremetal-nogcc/invalid     -target riscv32-unknown-elf --rtlib=platform 2>&1     | /b/fuchsia-x86_64-linux/llvm.obj/tools/clang/stage2-bins/bin/FileCheck -check-prefix=C-RV32-BAREMETAL-ILP32-NOGCC /b/fuchsia-x86_64-linux/llvm.src/clang/test/Driver/riscv32-toolchain-extra.c
--
Exit Code: 1

Command Output (stderr):
--
/b/fuchsia-x86_64-linux/llvm.src/clang/test/Driver/riscv32-toolchain-extra.c:27:34: error: C-RV32-BAREMETAL-ILP32-NOGCC: expected string not found in input
// C-RV32-BAREMETAL-ILP32-NOGCC: "{{.*}}Output/testroot-riscv32-baremetal-nogcc/bin/riscv32-unknown-elf-ld"
                                 ^
<stdin>:5:1070: note: scanning from here
 "/b/fuchsia-x86_64-linux/llvm.obj/tools/clang/stage2-bins/tools/clang/test/Driver/Output/testroot-riscv32-baremetal-nogcc/bin/clang" "-cc1" "-triple" "riscv32-unknown-unknown-elf" "-emit-obj" "-mrelax-all" "--mrelax-relocations" "-disable-free" "-disable-llvm-verifier" "-discard-value-names" "-main-file-name" "riscv32-toolchain-extra.c" "-mrelocation-model" "static" "-mthread-model" "posix" "-mframe-pointer=all" "-fmath-errno" "-fno-rounding-math" "-masm-verbose" "-mconstructor-aliases" "-nostdsysteminc" "-target-feature" "+m" "-target-feature" "+a" "-target-feature" "+c" "-target-feature" "+relax" "-target-feature" "-save-restore" "-target-abi" "ilp32" "-dwarf-column-info" "-fno-split-dwarf-inlining" "-debugger-tuning=gdb" "-resource-dir" "/b/fuchsia-x86_64-linux/llvm.obj/tools/clang/stage2-bins/tools/clang/test/Driver/Output/testroot-riscv32-baremetal-nogcc/lib/clang/11.0.0" "-internal-isystem" "/b/fuchsia-x86_64-linux/llvm.obj/tools/clang/stage2-bins/tools/clang/test/Driver/Output/testroot-riscv32-baremetal-nogcc/bin/../riscv32-unknown-elf/include" "-fdebug-compilation-dir" "/b/fuchsia-x86_64-linux/llvm.obj/tools/clang/stage2-bins/tools/clang/test/Driver" "-ferror-limit" "19" "-fmessage-length" "0" "-fno-signed-char" "-fgnuc-version=4.2.1" "-fobjc-runtime=gcc" "-fdiagnostics-show-option" "-faddrsig" "-o" "/tmp/riscv32-toolchain-extra-b2b7d0.o" "-x" "c" "/b/fuchsia-x86_64-linux/llvm.src/clang/test/Driver/riscv32-toolchain-extra.c"
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             ^
<stdin>:6:169: note: possible intended match here
 "/b/fuchsia-x86_64-linux/llvm.obj/tools/clang/stage2-bins/bin/ld.lld" "-m" "elf32lriscv" "/b/fuchsia-x86_64-linux/llvm.obj/tools/clang/stage2-bins/tools/clang/test/Driver/Output/testroot-riscv32-baremetal-nogcc/bin/../riscv32-unknown-elf/lib/crt0.o" "/b/fuchsia-x86_64-linux/llvm.obj/tools/clang/stage2-bins/tools/clang/test/Driver/Output/testroot-riscv32-baremetal-nogcc/lib/clang/11.0.0/lib/clang_rt.crtbegin-riscv32.o" "-L/b/fuchsia-x86_64-linux/llvm.obj/tools/clang/stage2-bins/tools/clang/test/Driver/Output/testroot-riscv32-baremetal-nogcc/bin/../riscv32-unknown-elf/lib" "/tmp/riscv32-toolchain-extra-b2b7d0.o" "--start-group" "-lc" "-lgloss" "--end-group" "/b/fuchsia-x86_64-linux/llvm.obj/tools/clang/stage2-bins/tools/clang/test/Driver/Output/testroot-riscv32-baremetal-nogcc/lib/clang/11.0.0/lib/libclang_rt.builtins-riscv32.a" "/b/fuchsia-x86_64-linux/llvm.obj/tools/clang/stage2-bins/tools/clang/test/Driver/Output/testroot-riscv32-baremetal-nogcc/lib/clang/11.0.0/lib/clang_rt.crtend-riscv32.o" "-o" "a.out"
                                                                                                                                                                        ^

--

********************
Testing:  0.. 10.. 20.. 30
FAIL: Clang :: Driver/riscv64-toolchain-extra.c (5733 of 17018)
******************** TEST 'Clang :: Driver/riscv64-toolchain-extra.c' FAILED ********************
Script:
--
: 'RUN: at line 14';   mkdir -p /b/fuchsia-x86_64-linux/llvm.obj/tools/clang/stage2-bins/tools/clang/test/Driver/Output/testroot-riscv64-baremetal-nogcc/bin
: 'RUN: at line 15';   [ ! -s /b/fuchsia-x86_64-linux/llvm.obj/tools/clang/stage2-bins/tools/clang/test/Driver/Output/testroot-riscv64-baremetal-nogcc/bin/clang ] || rm /b/fuchsia-x86_64-linux/llvm.obj/tools/clang/stage2-bins/tools/clang/test/Driver/Output/testroot-riscv64-baremetal-nogcc/bin/clang
: 'RUN: at line 16';   [ ! -s /b/fuchsia-x86_64-linux/llvm.obj/tools/clang/stage2-bins/tools/clang/test/Driver/Output/testroot-riscv64-baremetal-nogcc/bin/riscv64-unknown-elf-ld ] || rm /b/fuchsia-x86_64-linux/llvm.obj/tools/clang/stage2-bins/tools/clang/test/Driver/Output/testroot-riscv64-baremetal-nogcc/bin/riscv64-unknown-elf-ld
: 'RUN: at line 17';   [ ! -s /b/fuchsia-x86_64-linux/llvm.obj/tools/clang/stage2-bins/tools/clang/test/Driver/Output/testroot-riscv64-baremetal-nogcc/riscv64-unknown-elf ] || rm /b/fuchsia-x86_64-linux/llvm.obj/tools/clang/stage2-bins/tools/clang/test/Driver/Output/testroot-riscv64-baremetal-nogcc/riscv64-unknown-elf
: 'RUN: at line 18';   ln -s /b/fuchsia-x86_64-linux/llvm.obj/tools/clang/stage2-bins/bin/clang /b/fuchsia-x86_64-linux/llvm.obj/tools/clang/stage2-bins/tools/clang/test/Driver/Output/testroot-riscv64-baremetal-nogcc/bin/clang
: 'RUN: at line 19';   ln -s /b/fuchsia-x86_64-linux/llvm.src/clang/test/Driver/Inputs/basic_riscv64_nogcc_tree/bin/riscv64-unknown-elf-ld /b/fuchsia-x86_64-linux/llvm.obj/tools/clang/stage2-bins/tools/clang/test/Driver/Output/testroot-riscv64-baremetal-nogcc/bin/riscv64-unknown-elf-ld
: 'RUN: at line 20';   ln -s /b/fuchsia-x86_64-linux/llvm.src/clang/test/Driver/Inputs/basic_riscv64_nogcc_tree/riscv64-unknown-elf /b/fuchsia-x86_64-linux/llvm.obj/tools/clang/stage2-bins/tools/clang/test/Driver/Output/testroot-riscv64-baremetal-nogcc/riscv64-unknown-elf
: 'RUN: at line 21';   /b/fuchsia-x86_64-linux/llvm.obj/tools/clang/stage2-bins/tools/clang/test/Driver/Output/testroot-riscv64-baremetal-nogcc/bin/clang /b/fuchsia-x86_64-linux/llvm.src/clang/test/Driver/riscv64-toolchain-extra.c -### -no-canonical-prefixes     --gcc-toolchain=/b/fuchsia-x86_64-linux/llvm.obj/tools/clang/stage2-bins/tools/clang/test/Driver/Output/testroot-riscv64-baremetal-nogcc/invalid     -target riscv64-unknown-elf --rtlib=platform 2>&1     | /b/fuchsia-x86_64-linux/llvm.obj/tools/clang/stage2-bins/bin/FileCheck -check-prefix=C-RV64-BAREMETAL-LP64-NOGCC /b/fuchsia-x86_64-linux/llvm.src/clang/test/Driver/riscv64-toolchain-extra.c
--
Exit Code: 1

Command Output (stderr):
--
/b/fuchsia-x86_64-linux/llvm.src/clang/test/Driver/riscv64-toolchain-extra.c:27:33: error: C-RV64-BAREMETAL-LP64-NOGCC: expected string not found in input
// C-RV64-BAREMETAL-LP64-NOGCC: "{{.*}}Output/testroot-riscv64-baremetal-nogcc/bin/riscv64-unknown-elf-ld"
                                ^
<stdin>:5:1069: note: scanning from here
 "/b/fuchsia-x86_64-linux/llvm.obj/tools/clang/stage2-bins/tools/clang/test/Driver/Output/testroot-riscv64-baremetal-nogcc/bin/clang" "-cc1" "-triple" "riscv64-unknown-unknown-elf" "-emit-obj" "-mrelax-all" "--mrelax-relocations" "-disable-free" "-disable-llvm-verifier" "-discard-value-names" "-main-file-name" "riscv64-toolchain-extra.c" "-mrelocation-model" "static" "-mthread-model" "posix" "-mframe-pointer=all" "-fmath-errno" "-fno-rounding-math" "-masm-verbose" "-mconstructor-aliases" "-nostdsysteminc" "-target-feature" "+m" "-target-feature" "+a" "-target-feature" "+c" "-target-feature" "+relax" "-target-feature" "-save-restore" "-target-abi" "lp64" "-dwarf-column-info" "-fno-split-dwarf-inlining" "-debugger-tuning=gdb" "-resource-dir" "/b/fuchsia-x86_64-linux/llvm.obj/tools/clang/stage2-bins/tools/clang/test/Driver/Output/testroot-riscv64-baremetal-nogcc/lib/clang/11.0.0" "-internal-isystem" "/b/fuchsia-x86_64-linux/llvm.obj/tools/clang/stage2-bins/tools/clang/test/Driver/Output/testroot-riscv64-baremetal-nogcc/bin/../riscv64-unknown-elf/include" "-fdebug-compilation-dir" "/b/fuchsia-x86_64-linux/llvm.obj/tools/clang/stage2-bins/tools/clang/test/Driver" "-ferror-limit" "19" "-fmessage-length" "0" "-fno-signed-char" "-fgnuc-version=4.2.1" "-fobjc-runtime=gcc" "-fdiagnostics-show-option" "-faddrsig" "-o" "/tmp/riscv64-toolchain-extra-0b21db.o" "-x" "c" "/b/fuchsia-x86_64-linux/llvm.src/clang/test/Driver/riscv64-toolchain-extra.c"
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            ^
<stdin>:6:169: note: possible intended match here
 "/b/fuchsia-x86_64-linux/llvm.obj/tools/clang/stage2-bins/bin/ld.lld" "-m" "elf64lriscv" "/b/fuchsia-x86_64-linux/llvm.obj/tools/clang/stage2-bins/tools/clang/test/Driver/Output/testroot-riscv64-baremetal-nogcc/bin/../riscv64-unknown-elf/lib/crt0.o" "/b/fuchsia-x86_64-linux/llvm.obj/tools/clang/stage2-bins/tools/clang/test/Driver/Output/testroot-riscv64-baremetal-nogcc/lib/clang/11.0.0/lib/clang_rt.crtbegin-riscv64.o" "-L/b/fuchsia-x86_64-linux/llvm.obj/tools/clang/stage2-bins/tools/clang/test/Driver/Output/testroot-riscv64-baremetal-nogcc/bin/../riscv64-unknown-elf/lib" "/tmp/riscv64-toolchain-extra-0b21db.o" "--start-group" "-lc" "-lgloss" "--end-group" "/b/fuchsia-x86_64-linux/llvm.obj/tools/clang/stage2-bins/tools/clang/test/Driver/Output/testroot-riscv64-baremetal-nogcc/lib/clang/11.0.0/lib/libclang_rt.builtins-riscv64.a" "/b/fuchsia-x86_64-linux/llvm.obj/tools/clang/stage2-bins/tools/clang/test/Driver/Output/testroot-riscv64-baremetal-nogcc/lib/clang/11.0.0/lib/clang_rt.crtend-riscv64.o" "-o" "a.out"
                                                                                                                                                                        ^

--

********************
Testing:  0.. 10.. 20.. 30.. 40.. 50.. 60.. 70.. 80.. 90.. 

Testing Time: 44.02s
********************
Failing Tests (2):
    Clang :: Driver/riscv32-toolchain-extra.c
    Clang :: Driver/riscv64-toolchain-extra.c

Could you take a look? Thanks.

Log: http://lab.llvm.org:8011/builders/fuchsia-x86_64-linux/builds/613/steps/check/logs/stdio

Unsure if my reply was sent over email so copying it here.

Yup, adding // REQUIRES: platform-linker to both *-extra.c files seems to fix it. Thanks. Will you be sending out the fix?

thakis added a subscriber: thakis.Nov 24 2020, 8:05 PM
thakis added inline comments.
clang/test/lit.site.cfg.py.in
50

Why do you need this feature? clang invocations that want to use the platform linker can just pass -fuse-ld= or -fuse-ld=ld, no?

clang/test/lit.site.cfg.py.in
50

I think the RISCV tests are partly responsible from that dubious test: in riscv64-toolchain.c:27 the test explicitly checks for a custom linker path, just like the one passed through -DCLANG_DEFAULT_LINKER. We should probably make this more narrow.