HomePhabricator

clang+lld: Improve clang+ld.darwinnew.lld interaction, pass -demangle

Authored by thakis on Nov 20 2020, 10:57 AM.

Description

clang+lld: Improve clang+ld.darwinnew.lld interaction, pass -demangle

This patch:

  • adds an ld64.lld.darwinnew symlink for lld, to go with f2710d4b576, so that clang -fuse-ld=lld.darwinnew can be used to test new Mach-O lld while it's in bring-up. (The expectation is that we'll remove this again once new Mach-O lld is the defauld and only Mach-O lld.)
  • lets the clang driver know if the linker is lld (currently only triggered if -fuse-ld=lld or -fuse-ld=lld.darwinnew is passed). Currently only used for the next point, but could be used to implement other features that need close coordination between compiler and linker, e.g. having a diag for calling clang++ instead of clang when link errors are caused by a missing C++ stdlib.
  • lets the clang driver pass -demangle to Mach-O lld (both old and new), in addition to ld64
  • implements -demangle for new Mach-O lld
  • changes demangleItanium() to accept _Z, Z, _Z, ____Z prefixes (and updates one test added in D68014). Mach-O has an extra underscore for symbols, and the three (or, on Mach-O, four) underscores are used for block names.

Differential Revision: https://reviews.llvm.org/D91884

Event Timeline

lei added a subscriber: lei.Nov 24 2020, 11:15 AM

This patch broke our rhel bot: clang-ppc64le-rhel
The subsequent patch to fix symlink name did not fix the original failure seen:

Command Output (stdout):
--
 "/home/buildbots/docker-RHEL-buildbot/SetupBot/worker_env/ppc64le-clang-rhel-test/clang-ppc64le-rhel/stage1/bin/ld64.lld" "-demangle" "-dynamic" "-arch" "i386" "-macosx_version_min" "10.5.0" "-o" "/tmp/darwin-ld-78f2d4.out" "-lcrt1.10.5.o" "/tmp/darwin-ld-7cc88f.o" "-arch_multiple" "-final_output" "foo" "-lSystem"
 "/home/buildbots/docker-RHEL-buildbot/SetupBot/worker_env/ppc64le-clang-rhel-test/clang-ppc64le-rhel/stage1/bin/ld64.lld" "-demangle" "-dynamic" "-arch" "x86_64" "-macosx_version_min" "10.5.0" "-o" "/tmp/darwin-ld-67c679.out" "-lcrt1.10.5.o" "/tmp/darwin-ld-aceb8d.o" "-arch_multiple" "-final_output" "foo" "-lSystem"
 "/home/buildbots/docker-RHEL-buildbot/SetupBot/worker_env/ppc64le-clang-rhel-test/clang-ppc64le-rhel/stage1/bin/dsymutil" "-o" "BAR.dSYM" "BAR"
 "/home/buildbots/docker-RHEL-buildbot/SetupBot/worker_env/ppc64le-clang-rhel-test/clang-ppc64le-rhel/stage1/bin/dsymutil" "-o" "BAR.dSYM" "BAR"
--
Command Output (stderr):
--
/home/buildbots/docker-RHEL-buildbot/SetupBot/worker_env/ppc64le-clang-rhel-test/clang-ppc64le-rhel/llvm/clang/test/Driver/darwin-ld.c:102:31: error: LINK_OLDER_NODEMANGLE-NOT: excluded string found in input
// LINK_OLDER_NODEMANGLE-NOT: "-demangle"
                              ^
<stdin>:5:124: note: found here
 "/home/buildbots/docker-RHEL-buildbot/SetupBot/worker_env/ppc64le-clang-rhel-test/clang-ppc64le-rhel/stage1/bin/ld64.lld" "-demangle" "-dynamic" "-arch" "x86_64" "-macosx_version_min" "10.6.0" "-o" "a.out" "-lcrt1.10.6.o" "/home/buildbots/docker-RHEL-buildbot/SetupBot/worker_env/ppc64le-clang-rhel-test/clang-ppc64le-rhel/stage1/tools/clang/test/Driver/Output/darwin-ld.c.tmp.o" "-lSystem"
                                                                                                                           ^~~~~~~~~~~
Input file: <stdin>
Check file: /home/buildbots/docker-RHEL-buildbot/SetupBot/worker_env/ppc64le-clang-rhel-test/clang-ppc64le-rhel/llvm/clang/test/Driver/darwin-ld.c
-dump-input=help explains the following input dump.
Input was:
<<<<<<
         1: clang version 12.0.0 (/home/buildbots/docker-RHEL-buildbot/SetupBot/worker_env/ppc64le-clang-rhel-test/clang-ppc64le-rhel/llvm/clang c8414fa9410841da20964758c89bf9e312941dfa)
         2: Target: x86_64-apple-darwin10
         3: Thread model: posix
         4: InstalledDir: /home/buildbots/docker-RHEL-buildbot/SetupBot/worker_env/ppc64le-clang-rhel-test/clang-ppc64le-rhel/stage1/bin
         5:  "/home/buildbots/docker-RHEL-buildbot/SetupBot/worker_env/ppc64le-clang-rhel-test/clang-ppc64le-rhel/stage1/bin/ld64.lld" "-demangle" "-dynamic" "-arch" "x86_64" "-macosx_version_min" "10.6.0" "-o" "a.out" "-lcrt1.10.6.o" "/home/buildbots/docker-RHEL-buildbot/SetupBot/worker_env/ppc64le-clang-rhel-test/clang-ppc64le-rhel/stage1/tools/clang/test/Driver/Output/darwin-ld.c.tmp.o" "-lSystem"
not:102                                                                                                                                !~~~~~~~~~~                                                                                                                                                                                                                                                                  error: no match expected
>>>>>>
lei added a comment.Nov 24 2020, 11:34 AM

Testscase is expecting

According to this tc, -demangle should not be passed for liner verison 95.

 97 // RUN: %clang -target x86_64-apple-darwin10 -### %t.o \
 98 // RUN:   -mlinker-version=95 2> %t.log
 99 // RUN: FileCheck -check-prefix=LINK_OLDER_NODEMANGLE %s < %t.log
100 //
101 // LINK_OLDER_NODEMANGLE: {{ld(.exe)?"}}
102 // LINK_OLDER_NODEMANGLE-NOT: "-demangle"
103 // LINK_OLDER_NODEMANGLE: "-lSystem"

According to your code change:

if ((Version[0] >= 100 || LinkerIsLLD) &&

You meant to change this for all versions of LLD. If that is the case, then it's a simple tc update.

Testscase is expecting

According to this tc, -demangle should not be passed for liner verison 95.

 97 // RUN: %clang -target x86_64-apple-darwin10 -### %t.o \
 98 // RUN:   -mlinker-version=95 2> %t.log
 99 // RUN: FileCheck -check-prefix=LINK_OLDER_NODEMANGLE %s < %t.log
100 //
101 // LINK_OLDER_NODEMANGLE: {{ld(.exe)?"}}
102 // LINK_OLDER_NODEMANGLE-NOT: "-demangle"
103 // LINK_OLDER_NODEMANGLE: "-lSystem"

According to your code change:

if ((Version[0] >= 100 || LinkerIsLLD) &&

You meant to change this for all versions of LLD. If that is the case, then it's a simple tc update.

Did https://reviews.llvm.org/rG5ce85e66358a69e786093756c77fae2e140947c1 help?

Link to bot: http://lab.llvm.org:8011/#/builders/57

Looks like it's still red, checking...

I'm guessing your bot sets CLANG_DEFAULT_LINKER to lld?

lei added a comment.Nov 24 2020, 12:49 PM

This seem to be only failing for our bot that uses the lld linker. Does not affect bots using the ld linker.

lei added a comment.EditedNov 24 2020, 12:49 PM

I'm guessing your bot sets CLANG_DEFAULT_LINKER to lld?

we specify the default linker through cmake.

a9eaf8435d9204f5d71a08cfd7c574e92d434871 might help. (Sorry, I wrote it right after my question about CLANG_DEFAULT_LINKER=lld but then forgot to push it.)

lei added a comment.Nov 25 2020, 8:28 AM

Thank-you!