Skip to content

Commit 0ea6b8e

Browse files
committed
[clang-linker-wrapper] Use MapVector to stabilize iteration order
DenseMap iteration order is not guaranteed to be deterministic. Without the change, clang/test/Driver/linker-wrapper{,-libs}.c would fail when `combineHashValue` changes (#95970).
1 parent fb17bbc commit 0ea6b8e

File tree

3 files changed

+14
-13
lines changed

3 files changed

+14
-13
lines changed

clang/test/Driver/linker-wrapper-libs.c

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,8 @@ int bar() { return weak; }
4848
// RUN: --linker-path=/usr/bin/ld %t.a %t.o -o a.out 2>&1 \
4949
// RUN: | FileCheck %s --check-prefix=LIBRARY-RESOLVES
5050

51-
// LIBRARY-RESOLVES: clang{{.*}} -o {{.*}}.img --target=amdgcn-amd-amdhsa -mcpu=gfx1030 {{.*}}.o {{.*}}.o
5251
// LIBRARY-RESOLVES: clang{{.*}} -o {{.*}}.img --target=nvptx64-nvidia-cuda -march=sm_70 {{.*}}.s {{.*}}.o
52+
// LIBRARY-RESOLVES: clang{{.*}} -o {{.*}}.img --target=amdgcn-amd-amdhsa -mcpu=gfx1030 {{.*}}.o {{.*}}.o
5353

5454
//
5555
// Check that we extract a static library that defines a global visibile to the
@@ -72,8 +72,8 @@ int bar() { return weak; }
7272
// RUN: --linker-path=/usr/bin/ld %t.a %t.o -o a.out 2>&1 \
7373
// RUN: | FileCheck %s --check-prefix=LIBRARY-GLOBAL
7474

75-
// LIBRARY-GLOBAL: clang{{.*}} -o {{.*}}.img --target=amdgcn-amd-amdhsa -mcpu=gfx1030 {{.*}}.o {{.*}}.o
7675
// LIBRARY-GLOBAL: clang{{.*}} -o {{.*}}.img --target=nvptx64-nvidia-cuda -march=sm_70 {{.*}}.s {{.*}}.o
76+
// LIBRARY-GLOBAL: clang{{.*}} -o {{.*}}.img --target=amdgcn-amd-amdhsa -mcpu=gfx1030 {{.*}}.o {{.*}}.o
7777

7878
//
7979
// Check that we do not extract a global symbol if the source file was not
@@ -116,9 +116,9 @@ int bar() { return weak; }
116116
// RUN: --linker-path=/usr/bin/ld %t.o %t.a -o a.out 2>&1 \
117117
// RUN: | FileCheck %s --check-prefix=LIBRARY-WEAK
118118

119-
// LIBRARY-WEAK: clang{{.*}} -o {{.*}}.img --target=amdgcn-amd-amdhsa -mcpu=gfx1030
120-
// LIBRARY-WEAK-NOT: {{.*}}.o {{.*}}.o
121119
// LIBRARY-WEAK: clang{{.*}} -o {{.*}}.img --target=nvptx64-nvidia-cuda -march=sm_70
120+
// LIBRARY-WEAK-NOT: {{.*}}.o {{.*}}.o
121+
// LIBRARY-WEAK: clang{{.*}} -o {{.*}}.img --target=amdgcn-amd-amdhsa -mcpu=gfx1030
122122

123123
//
124124
// Check that we do not extract an unneeded hidden symbol.
@@ -138,9 +138,9 @@ int bar() { return weak; }
138138
// RUN: --linker-path=/usr/bin/ld %t.o %t.a -o a.out 2>&1 \
139139
// RUN: | FileCheck %s --check-prefix=LIBRARY-HIDDEN
140140

141-
// LIBRARY-HIDDEN: clang{{.*}} -o {{.*}}.img --target=amdgcn-amd-amdhsa -mcpu=gfx1030
142-
// LIBRARY-HIDDEN-NOT: {{.*}}.o {{.*}}.o
143141
// LIBRARY-HIDDEN: clang{{.*}} -o {{.*}}.img --target=nvptx64-nvidia-cuda -march=sm_70
142+
// LIBRARY-HIDDEN-NOT: {{.*}}.o {{.*}}.o
143+
// LIBRARY-HIDDEN: clang{{.*}} -o {{.*}}.img --target=amdgcn-amd-amdhsa -mcpu=gfx1030
144144

145145
//
146146
// Check that we do not extract a static library that defines a global visibile
@@ -161,9 +161,9 @@ int bar() { return weak; }
161161
// RUN: --linker-path=/usr/bin/ld %t.o %t.a %t.a -o a.out 2>&1 \
162162
// RUN: | FileCheck %s --check-prefix=LIBRARY-GLOBAL-DEFINED
163163

164-
// LIBRARY-GLOBAL-DEFINED: clang{{.*}} -o {{.*}}.img --target=amdgcn-amd-amdhsa -mcpu=gfx1030 {{.*}}.o {{.*}}.o
165-
// LIBRARY-GLOBAL-DEFINED-NOT: {{.*}}gfx1030{{.*}}.o
166164
// LIBRARY-GLOBAL-DEFINED: clang{{.*}} -o {{.*}}.img --target=nvptx64-nvidia-cuda -march=sm_70 {{.*}}.s {{.*}}.o
165+
// LIBRARY-GLOBAL-DEFINED-NOT: {{.*}}gfx1030{{.*}}.o
166+
// LIBRARY-GLOBAL-DEFINED: clang{{.*}} -o {{.*}}.img --target=amdgcn-amd-amdhsa -mcpu=gfx1030 {{.*}}.o {{.*}}.o
167167

168168
//
169169
// Check that we can use --[no-]whole-archive to control extraction.
@@ -185,7 +185,7 @@ int bar() { return weak; }
185185
// RUN: --linker-path=/usr/bin/ld %t.o --whole-archive %t.a -o a.out 2>&1 \
186186
// RUN: | FileCheck %s --check-prefix=LIBRARY-WHOLE-ARCHIVE
187187

188+
// LIBRARY-WHOLE-ARCHIVE: clang{{.*}} -o {{.*}}.img --target=nvptx64-nvidia-cuda -march=sm_70 {{.*}}.s {{.*}}.o
188189
// LIBRARY-WHOLE-ARCHIVE: clang{{.*}} -o {{.*}}.img --target=amdgcn-amd-amdhsa -mcpu=gfx1030 {{.*}}.o {{.*}}.o
189190
// LIBRARY-WHOLE-ARCHIVE: clang{{.*}} -o {{.*}}.img --target=nvptx64-nvidia-cuda -march=sm_52 {{.*}}.s
190191
// LIBRARY-WHOLE-ARCHIVE: clang{{.*}} -o {{.*}}.img --target=amdgcn-amd-amdhsa -mcpu=gfx90a {{.*}}.o
191-
// LIBRARY-WHOLE-ARCHIVE: clang{{.*}} -o {{.*}}.img --target=nvptx64-nvidia-cuda -march=sm_70 {{.*}}.s {{.*}}.o

clang/test/Driver/linker-wrapper.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,8 @@ __attribute__((visibility("protected"), used)) int x;
9191
// RUN: clang-linker-wrapper --dry-run --host-triple=x86_64-unknown-linux-gnu \
9292
// RUN: --linker-path=/usr/bin/ld %t.o -o a.out 2>&1 | FileCheck %s --check-prefix=CUDA
9393

94-
// CUDA: clang{{.*}} -o [[IMG_SM52:.+]] --target=nvptx64-nvidia-cuda -march=sm_52
9594
// CUDA: clang{{.*}} -o [[IMG_SM70:.+]] --target=nvptx64-nvidia-cuda -march=sm_70
95+
// CUDA: clang{{.*}} -o [[IMG_SM52:.+]] --target=nvptx64-nvidia-cuda -march=sm_52
9696
// CUDA: fatbinary{{.*}}-64 --create {{.*}}.fatbin --image=profile=sm_70,file=[[IMG_SM70]] --image=profile=sm_52,file=[[IMG_SM52]]
9797
// CUDA: usr/bin/ld{{.*}} {{.*}}.openmp.image.{{.*}}.o {{.*}}.cuda.image.{{.*}}.o
9898

@@ -118,8 +118,8 @@ __attribute__((visibility("protected"), used)) int x;
118118
// RUN: --compress --compression-level=6 \
119119
// RUN: --linker-path=/usr/bin/ld %t.o -o a.out 2>&1 | FileCheck %s --check-prefix=HIP
120120

121-
// HIP: clang{{.*}} -o [[IMG_GFX908:.+]] --target=amdgcn-amd-amdhsa -mcpu=gfx908
122121
// HIP: clang{{.*}} -o [[IMG_GFX90A:.+]] --target=amdgcn-amd-amdhsa -mcpu=gfx90a
122+
// HIP: clang{{.*}} -o [[IMG_GFX908:.+]] --target=amdgcn-amd-amdhsa -mcpu=gfx908
123123
// HIP: clang-offload-bundler{{.*}}-type=o -bundle-align=4096 -compress -compression-level=6 -targets=host-x86_64-unknown-linux,hip-amdgcn-amd-amdhsa--gfx90a,hip-amdgcn-amd-amdhsa--gfx908 -input=/dev/null -input=[[IMG_GFX90A]] -input=[[IMG_GFX908]] -output={{.*}}.hipfb
124124

125125
// RUN: clang-offload-packager -o %t.out \
@@ -186,8 +186,8 @@ __attribute__((visibility("protected"), used)) int x;
186186
// RUN: clang-linker-wrapper --host-triple=x86_64-unknown-linux-gnu --dry-run \
187187
// RUN: --linker-path=/usr/bin/ld %t1.o %t2.o %t.a -o a.out 2>&1 | FileCheck %s --check-prefix=ARCH-ALL
188188

189-
// ARCH-ALL: clang{{.*}} -o {{.*}}.img --target=amdgcn-amd-amdhsa -mcpu=gfx908 -O2 -Wl,--no-undefined {{.*}}.o {{.*}}.o
190189
// ARCH-ALL: clang{{.*}} -o {{.*}}.img --target=amdgcn-amd-amdhsa -mcpu=gfx90a -O2 -Wl,--no-undefined {{.*}}.o {{.*}}.o
190+
// ARCH-ALL: clang{{.*}} -o {{.*}}.img --target=amdgcn-amd-amdhsa -mcpu=gfx908 -O2 -Wl,--no-undefined {{.*}}.o {{.*}}.o
191191

192192
// RUN: clang-offload-packager -o %t.out \
193193
// RUN: --image=file=%t.elf.o,kind=openmp,triple=x86_64-unknown-linux-gnu \

clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
//===---------------------------------------------------------------------===//
1616

1717
#include "clang/Basic/Version.h"
18+
#include "llvm/ADT/MapVector.h"
1819
#include "llvm/BinaryFormat/Magic.h"
1920
#include "llvm/Bitcode/BitcodeWriter.h"
2021
#include "llvm/CodeGen/CommandFlags.h"
@@ -1539,7 +1540,7 @@ getDeviceInput(const ArgList &Args) {
15391540
}
15401541

15411542
// Link all standard input files and update the list of symbols.
1542-
DenseMap<OffloadFile::TargetID, SmallVector<OffloadFile>> InputFiles;
1543+
MapVector<OffloadFile::TargetID, SmallVector<OffloadFile, 0>> InputFiles;
15431544
DenseMap<OffloadFile::TargetID, DenseMap<StringRef, Symbol>> Syms;
15441545
for (OffloadFile &Binary : ObjectFilesToExtract) {
15451546
if (!Binary.getBinary())

0 commit comments

Comments
 (0)