[lld] bb8be26 - [LLD] Fix issue in HIP due to unspecified order of evaluation of the function object

Alexandre Ganea via llvm-commits llvm-commits at lists.llvm.org
Tue Feb 8 16:12:24 PST 2022


Author: Alexandre Ganea
Date: 2022-02-08T19:12:15-05:00
New Revision: bb8be26a7ec36d32c605a5a15b92b5614453391f

URL: https://github.com/llvm/llvm-project/commit/bb8be26a7ec36d32c605a5a15b92b5614453391f
DIFF: https://github.com/llvm/llvm-project/commit/bb8be26a7ec36d32c605a5a15b92b5614453391f.diff

LOG: [LLD] Fix issue in HIP due to unspecified order of evaluation of the function object

This fixes the issue raised in https://reviews.llvm.org/D108850#3303452

Before C++17, the function object is evaluated in a unspecified order. In the following example: https://godbolt.org/z/8ao4vdsr7 the function object is either evaluated before or after the arguments, depending on the compiler. With MSVC and /std:c++14 the function object is evaluated after the arguments; with clang and gcc, it is evaluated before. With C++17, the function object is guaranteed to be evaluated before the arguments, see: https://riptutorial.com/cplusplus/example/19369/evaluation-order-of-function-arguments

In our case, the issue was that the `args` conversion to `ArrayRef` was evaluated before the lambda call `link`, which internally was calling `parseFlavor()`, which in turned modified `args`. We ended with an `ArrayRef` argument that reflected the previous contents of `args`.

Add coverage for `-flavor` which we didn't have before.

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

Added: 
    lld/test/ELF/amdgpu-duplicate-sym.s

Modified: 
    lld/tools/lld/lld.cpp

Removed: 
    


################################################################################
diff  --git a/lld/test/ELF/amdgpu-duplicate-sym.s b/lld/test/ELF/amdgpu-duplicate-sym.s
new file mode 100644
index 0000000000000..6c7a81dbdd5bf
--- /dev/null
+++ b/lld/test/ELF/amdgpu-duplicate-sym.s
@@ -0,0 +1,26 @@
+# REQUIRES: amdgpu
+# RUN: llvm-mc -filetype=obj -triple amdgcn-amd-amdhsa -mcpu=gfx1031 --position-independent --relax-relocations %s -o %t.o
+
+# We use lld-link on purpose to exercise -flavor.
+# RUN: lld-link -flavor gnu -shared %t.o
+
+        .text
+        .amdgcn_target "amdgcn-amd-amdhsa--gfx1031"
+        .protected      xxx                     ; @xxx
+        .type   xxx, at object
+        .data
+        .globl  xxx
+xxx:
+        .long   123                             ; 0x7b
+
+        .addrsig
+        .amdgpu_metadata
+---
+amdhsa.kernels:  []
+amdhsa.target:   amdgcn-amd-amdhsa--gfx1031
+amdhsa.version:
+  - 1
+  - 1
+...
+
+        .end_amdgpu_metadata

diff  --git a/lld/tools/lld/lld.cpp b/lld/tools/lld/lld.cpp
index 0a6439fff2a27..d6c39fa7cce47 100644
--- a/lld/tools/lld/lld.cpp
+++ b/lld/tools/lld/lld.cpp
@@ -159,9 +159,9 @@ static int lldMain(int argc, const char **argv, llvm::raw_ostream &stdoutOS,
       die("lld is a generic driver.\n"
           "Invoke ld.lld (Unix), ld64.lld (macOS), lld-link (Windows), wasm-ld"
           " (WebAssembly) instead");
-  };
+  }();
   // Run the driver. If an error occurs, false will be returned.
-  bool r = link()(args, stdoutOS, stderrOS, exitEarly, inTestOutputDisabled);
+  bool r = link(args, stdoutOS, stderrOS, exitEarly, inTestOutputDisabled);
 
   // Call exit() if we can to avoid calling destructors.
   if (exitEarly)


        


More information about the llvm-commits mailing list