[PATCH] D119278: [LLD] Fix issue in HIP toolchain due to unspecified order of evaluation of the function object
Alexandre Ganea via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue Feb 8 12:46:48 PST 2022
aganea created this revision.
aganea added reviewers: yaxunl, MaskRay, mstorsjo.
Herald added subscribers: kerbowa, jvesely, emaste.
aganea requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.
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` as 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 value of `args`.
Add coverage for `-flavor` which we didn't have before.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D119278
Files:
lld/test/ELF/amdgpu-duplicate-sym.s
lld/tools/lld/lld.cpp
Index: lld/tools/lld/lld.cpp
===================================================================
--- lld/tools/lld/lld.cpp
+++ lld/tools/lld/lld.cpp
@@ -159,9 +159,9 @@
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)
Index: lld/test/ELF/amdgpu-duplicate-sym.s
===================================================================
--- /dev/null
+++ lld/test/ELF/amdgpu-duplicate-sym.s
@@ -0,0 +1,32 @@
+# 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 excercice -flavor.
+# RUN: lld-link -flavor gnu -shared %t.o
+
+ .text
+ .amdgcn_target "amdgcn-amd-amdhsa--gfx1031"
+ .p2alignl 6, 3214868480
+ .fill 48, 4, 3214868480
+ .protected xxx ; @xxx
+ .type xxx, at object
+ .data
+ .globl xxx
+ .p2align 2
+xxx:
+ .long 123 ; 0x7b
+ .size xxx, 4
+
+ .ident "clang version 14.0.0 (git at github.amd.com:Compute-Mirrors/llvm-project.git ce53ba9aaee8d053604883d5befaf07bad60ba84)"
+ .section ".note.GNU-stack"
+ .addrsig
+ .amdgpu_metadata
+---
+amdhsa.kernels: []
+amdhsa.target: amdgcn-amd-amdhsa--gfx1031
+amdhsa.version:
+ - 1
+ - 1
+...
+
+ .end_amdgpu_metadata
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D119278.406938.patch
Type: text/x-patch
Size: 1797 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220208/6e1060cb/attachment.bin>
More information about the llvm-commits
mailing list