[llvm] 350c89f - [llvm-lib] Write object files in reversed order.
Martin Storsjö via llvm-commits
llvm-commits at lists.llvm.org
Thu Feb 9 14:52:40 PST 2023
Author: Jacek Caban
Date: 2023-02-10T00:51:07+02:00
New Revision: 350c89fa75a089060baea83a7ed88ed360f6e918
URL: https://github.com/llvm/llvm-project/commit/350c89fa75a089060baea83a7ed88ed360f6e918
DIFF: https://github.com/llvm/llvm-project/commit/350c89fa75a089060baea83a7ed88ed360f6e918.diff
LOG: [llvm-lib] Write object files in reversed order.
This isn't strictly needed, but this matches how MSVC lib.exe writes to
archives, so this makes llvm-lib more compatible and simplifies comparing
output between tools.
Reviewed By: hans
Differential Revision: https://reviews.llvm.org/D143536
Added:
llvm/test/tools/llvm-lib/Inputs/abc.s
Modified:
llvm/lib/ToolDrivers/llvm-lib/LibDriver.cpp
llvm/test/tools/llvm-lib/duplicate.test
llvm/test/tools/llvm-lib/nest.test
llvm/test/tools/llvm-lib/use-paths.test
llvm/test/tools/llvm-lib/xfghashmap-list.test
Removed:
################################################################################
diff --git a/llvm/lib/ToolDrivers/llvm-lib/LibDriver.cpp b/llvm/lib/ToolDrivers/llvm-lib/LibDriver.cpp
index ade753ad89180..f92ff3d3873e0 100644
--- a/llvm/lib/ToolDrivers/llvm-lib/LibDriver.cpp
+++ b/llvm/lib/ToolDrivers/llvm-lib/LibDriver.cpp
@@ -133,12 +133,14 @@ static void doList(opt::InputArgList& Args) {
object::Archive Archive(B.get()->getMemBufferRef(), Err);
fatalOpenError(std::move(Err), B->getBufferIdentifier());
+ std::vector<StringRef> Names;
for (auto &C : Archive.children(Err)) {
Expected<StringRef> NameOrErr = C.getName();
fatalOpenError(NameOrErr.takeError(), B->getBufferIdentifier());
- StringRef Name = NameOrErr.get();
- llvm::outs() << Name << '\n';
+ Names.push_back(NameOrErr.get());
}
+ for (auto Name : reverse(Names))
+ llvm::outs() << Name << '\n';
fatalOpenError(std::move(Err), B->getBufferIdentifier());
}
@@ -392,6 +394,9 @@ int llvm::libDriverMain(ArrayRef<const char *> ArgsArr) {
}
}
+ // For compatibility with MSVC, reverse member vector after de-duplication.
+ std::reverse(Members.begin(), Members.end());
+
if (Error E =
writeArchive(OutputPath, Members,
/*WriteSymtab=*/true, object::Archive::K_GNU,
diff --git a/llvm/test/tools/llvm-lib/Inputs/abc.s b/llvm/test/tools/llvm-lib/Inputs/abc.s
new file mode 100644
index 0000000000000..1950ef9bb9a97
--- /dev/null
+++ b/llvm/test/tools/llvm-lib/Inputs/abc.s
@@ -0,0 +1,6 @@
+.globl c
+c:
+.globl a
+a:
+.globl b
+b:
diff --git a/llvm/test/tools/llvm-lib/duplicate.test b/llvm/test/tools/llvm-lib/duplicate.test
index 3c503ca7f58f2..098858d4fbcd1 100644
--- a/llvm/test/tools/llvm-lib/duplicate.test
+++ b/llvm/test/tools/llvm-lib/duplicate.test
@@ -6,9 +6,11 @@ RUN: mkdir -p %t
RUN: llvm-mc -triple=x86_64-pc-windows-msvc -filetype=obj -o %t/foo.o %S/Inputs/a.s
RUN: llvm-mc -triple=x86_64-pc-windows-msvc -filetype=obj -o %t/bar.o %S/Inputs/b.s
-RUN: llvm-lib -out:%t/foo.lib %t/foo.o %t/foo.o %t/bar.o
+RUN: llvm-mc -triple=x86_64-pc-windows-msvc -filetype=obj -o %t/abc.o %S/Inputs/abc.s
+RUN: llvm-lib -out:%t/foo.lib %t/foo.o %t/foo.o %t/abc.o %t/bar.o %t/foo.o %t/foo.o
RUN: llvm-ar t %t/foo.lib | FileCheck %s
-CHECK: foo.o
-CHECK-NOT: foo.o
CHECK: bar.o
+CHECK-NEXT: abc.o
+CHECK-NEXT: foo.o
+CHECK-NOT: foo.o
diff --git a/llvm/test/tools/llvm-lib/nest.test b/llvm/test/tools/llvm-lib/nest.test
index 627c847b13339..3b1c3b09b1a25 100644
--- a/llvm/test/tools/llvm-lib/nest.test
+++ b/llvm/test/tools/llvm-lib/nest.test
@@ -10,6 +10,6 @@ RUN: llvm-lib -out:%t/foo.lib %t/foo.o
RUN: llvm-mc -triple=x86_64-pc-windows-msvc -filetype=obj -o %t/bar.o %S/Inputs/b.s
RUN: llvm-lib -out:%t/bar.lib %t/foo.lib %t/bar.o
-RUN: llvm-ar t %t/bar.lib | FileCheck %s
+RUN: llvm-lib -list %t/bar.lib | FileCheck %s
CHECK: foo.o
CHECK: bar.o
diff --git a/llvm/test/tools/llvm-lib/use-paths.test b/llvm/test/tools/llvm-lib/use-paths.test
index 971c216127e6f..bc75ed8811771 100644
--- a/llvm/test/tools/llvm-lib/use-paths.test
+++ b/llvm/test/tools/llvm-lib/use-paths.test
@@ -13,12 +13,12 @@ RUN: llvm-lib -out:foo.lib foo/a.obj foo/b.obj
RUN: llvm-ar t foo.lib | FileCheck %s
FIXME: We should probably use backslashes on Windows to better match MSVC tools.
-CHECK: foo/a.obj
CHECK: foo/b.obj
+CHECK: foo/a.obj
Do it again with absolute paths and see that we get something.
RUN: llvm-lib -out:foo.lib %t/foo/a.obj %t/foo/b.obj
RUN: llvm-ar t foo.lib | FileCheck %s --check-prefix=ABS
-ABS: {{.*}}/foo/a.obj
ABS: {{.*}}/foo/b.obj
+ABS: {{.*}}/foo/a.obj
diff --git a/llvm/test/tools/llvm-lib/xfghashmap-list.test b/llvm/test/tools/llvm-lib/xfghashmap-list.test
index 333fc77a521d7..9cd2b73b62f6d 100644
--- a/llvm/test/tools/llvm-lib/xfghashmap-list.test
+++ b/llvm/test/tools/llvm-lib/xfghashmap-list.test
@@ -1,7 +1,7 @@
# RUN: rm -rf %t && mkdir -p %t && cd %t
# RUN: llvm-mc -triple=x86_64-pc-windows-msvc -filetype=obj -o a.obj %S/Inputs/a.s
# RUN: llvm-mc -triple=x86_64-pc-windows-msvc -filetype=obj -o b.obj %S/Inputs/b.s
-# RUN: llvm-lib /out:xfghashmap.lib a.obj b.obj
+# RUN: llvm-lib /out:xfghashmap.lib b.obj a.obj
## Replace a section in the library file with /<XFGHASHMAP>/ emulating
## a library from the Windows SDK for Windows 11.
@@ -10,9 +10,9 @@
## This should print the /<XFGHASHMAP>/ section as well as an .obj one.
# RUN: llvm-lib /list %t/xfghashmap.lib | FileCheck %s
-# CHECK: a.obj
# CHECK: /<XFGHASHMAP>/
# CHECK-NOT: b.obj
+# CHECK: a.obj
import sys
More information about the llvm-commits
mailing list