diff options
author | Martin Storsjö <martin@martin.st> | 2025-01-21 23:56:56 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-01-21 23:56:56 +0200 |
commit | c912e98e8ea3678bf8344199a97530f7a310aed7 (patch) | |
tree | 6da3cbf8f453d401804170cd370660d65ada810d /llvm/lib/ToolDrivers/llvm-lib/LibDriver.cpp | |
parent | 671ec34fb2d6b2cb1f82a69991d2aebb3bdc24bd (diff) | |
download | llvm-c912e98e8ea3678bf8344199a97530f7a310aed7.zip llvm-c912e98e8ea3678bf8344199a97530f7a310aed7.tar.gz llvm-c912e98e8ea3678bf8344199a97530f7a310aed7.tar.bz2 |
[llvm-lib] Don't rewrite paths for members in non-thin archives (#123416)
This matches what MS lib.exe does (and llvm-ar too); when adding files
to an archive, MS lib.exe stores the file name as it was given on the
command line, whereas llvm-lib rewrote it into a relative path name,
relative to the archive location. Such a rewrite makes sense for thin
archives, but not for regular archives. (MS lib.exe doesn't support
producing thin archives; that's an LLVM extension - see the
thin-relative.test testcase.)
The behaviour to rewrite these paths was added in
451c2ef199e9c5163007ac32e2d426fbfb37e664; it is unclear why it was
chosen to do the rewriting for non-thin archives as well. This quirk is
even pointed out in a code comment - but neither the code review at
https://reviews.llvm.org/D57842 nor the linked bug report at
https://crbug.com/41440160 mentions why this is done for all archives,
not only thin ones.
Therefore, assume that this only was done out of convenience, and change
llvm-lib to not adjust the paths for non-thin archives.
Normally, the actual member names doesn't matter for non-thin archives;
however for short import libraries, where each member is named e.g.
"foo.dll", the names do matter. If using llvm-lib to merge two import
libraries (as a non-thin library), preserve the original names rather
than making the member names relative.
Diffstat (limited to 'llvm/lib/ToolDrivers/llvm-lib/LibDriver.cpp')
-rw-r--r-- | llvm/lib/ToolDrivers/llvm-lib/LibDriver.cpp | 21 |
1 files changed, 10 insertions, 11 deletions
diff --git a/llvm/lib/ToolDrivers/llvm-lib/LibDriver.cpp b/llvm/lib/ToolDrivers/llvm-lib/LibDriver.cpp index 6ce06b4..15d959d 100644 --- a/llvm/lib/ToolDrivers/llvm-lib/LibDriver.cpp +++ b/llvm/lib/ToolDrivers/llvm-lib/LibDriver.cpp @@ -503,23 +503,22 @@ int llvm::libDriverMain(ArrayRef<const char *> ArgsArr) { return 1; } } - // llvm-lib uses relative paths for both regular and thin archives, unlike - // standard GNU ar, which only uses relative paths for thin archives and - // basenames for regular archives. - for (NewArchiveMember &Member : Members) { - if (sys::path::is_relative(Member.MemberName)) { - Expected<std::string> PathOrErr = - computeArchiveRelativePath(OutputPath, Member.MemberName); - if (PathOrErr) - Member.MemberName = Saver.save(*PathOrErr); + + bool Thin = Args.hasArg(OPT_llvmlibthin); + if (Thin) { + for (NewArchiveMember &Member : Members) { + if (sys::path::is_relative(Member.MemberName)) { + Expected<std::string> PathOrErr = + computeArchiveRelativePath(OutputPath, Member.MemberName); + if (PathOrErr) + Member.MemberName = Saver.save(*PathOrErr); + } } } // For compatibility with MSVC, reverse member vector after de-duplication. std::reverse(Members.begin(), Members.end()); - bool Thin = Args.hasArg(OPT_llvmlibthin); - auto Symtab = Args.hasFlag(OPT_llvmlibindex, OPT_llvmlibindex_no, /*default=*/true) ? SymtabWritingMode::NormalSymtab |