-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[llvm-ar][Archive] Use getDefaultTargetTriple instead of host triple for the fallback archive format. #82888
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
@llvm/pr-subscribers-llvm-binary-utilities @llvm/pr-subscribers-clang Author: Jacek Caban (cjacek) ChangesAs suggested by @gbreynoo in #82642. Full diff: https://github.com/llvm/llvm-project/pull/82888.diff 5 Files Affected:
diff --git a/clang/tools/clang-offload-packager/ClangOffloadPackager.cpp b/clang/tools/clang-offload-packager/ClangOffloadPackager.cpp
index c36a5aa58cee50..c6d5b31ab512cb 100644
--- a/clang/tools/clang-offload-packager/ClangOffloadPackager.cpp
+++ b/clang/tools/clang-offload-packager/ClangOffloadPackager.cpp
@@ -197,7 +197,7 @@ static Error unbundleImages() {
if (Error E = writeArchive(
Args["file"], Members, SymtabWritingMode::NormalSymtab,
- Archive::getDefaultKindForHost(), true, false, nullptr))
+ Archive::getDefaultKind(), true, false, nullptr))
return E;
} else if (Args.count("file")) {
if (Extracted.size() > 1)
diff --git a/llvm/include/llvm/Object/Archive.h b/llvm/include/llvm/Object/Archive.h
index 66f07939b11050..a3165c3235e0ed 100644
--- a/llvm/include/llvm/Object/Archive.h
+++ b/llvm/include/llvm/Object/Archive.h
@@ -338,7 +338,7 @@ class Archive : public Binary {
Kind kind() const { return (Kind)Format; }
bool isThin() const { return IsThin; }
- static object::Archive::Kind getDefaultKindForHost();
+ static object::Archive::Kind getDefaultKind();
static object::Archive::Kind getDefaultKindForTriple(Triple &T);
child_iterator child_begin(Error &Err, bool SkipInternal = true) const;
diff --git a/llvm/lib/Object/Archive.cpp b/llvm/lib/Object/Archive.cpp
index d3fdcd9ee88111..6139d9996bdad3 100644
--- a/llvm/lib/Object/Archive.cpp
+++ b/llvm/lib/Object/Archive.cpp
@@ -979,8 +979,8 @@ object::Archive::Kind Archive::getDefaultKindForTriple(Triple &T) {
return object::Archive::K_GNU;
}
-object::Archive::Kind Archive::getDefaultKindForHost() {
- Triple HostTriple(sys::getProcessTriple());
+object::Archive::Kind Archive::getDefaultKind() {
+ Triple HostTriple(sys::getDefaultTargetTriple());
return getDefaultKindForTriple(HostTriple);
}
diff --git a/llvm/lib/Object/ArchiveWriter.cpp b/llvm/lib/Object/ArchiveWriter.cpp
index 02f72521c8b544..978eff64e5ee7d 100644
--- a/llvm/lib/Object/ArchiveWriter.cpp
+++ b/llvm/lib/Object/ArchiveWriter.cpp
@@ -91,7 +91,7 @@ object::Archive::Kind NewArchiveMember::detectKindFromObject() const {
}
}
- return object::Archive::getDefaultKindForHost();
+ return object::Archive::getDefaultKind();
}
Expected<NewArchiveMember>
diff --git a/llvm/tools/llvm-ar/llvm-ar.cpp b/llvm/tools/llvm-ar/llvm-ar.cpp
index c58a85c695dacf..0c4392baacd052 100644
--- a/llvm/tools/llvm-ar/llvm-ar.cpp
+++ b/llvm/tools/llvm-ar/llvm-ar.cpp
@@ -671,7 +671,7 @@ Expected<std::unique_ptr<Binary>> getAsBinary(const Archive::Child &C,
}
template <class A> static bool isValidInBitMode(const A &Member) {
- if (object::Archive::getDefaultKindForHost() != object::Archive::K_AIXBIG)
+ if (object::Archive::getDefaultKind() != object::Archive::K_AIXBIG)
return true;
LLVMContext Context;
Expected<std::unique_ptr<Binary>> BinOrErr = getAsBinary(Member, &Context);
@@ -1037,10 +1037,10 @@ static void performWriteOperation(ArchiveOperation Operation,
}
} else if (NewMembersP)
Kind = !NewMembersP->empty() ? NewMembersP->front().detectKindFromObject()
- : object::Archive::getDefaultKindForHost();
+ : object::Archive::getDefaultKind();
else
Kind = !NewMembers.empty() ? NewMembers.front().detectKindFromObject()
- : object::Archive::getDefaultKindForHost();
+ : object::Archive::getDefaultKind();
break;
case GNU:
Kind = object::Archive::K_GNU;
@@ -1335,7 +1335,7 @@ static int ar_main(int argc, char **argv) {
// Get BitMode from enviorment variable "OBJECT_MODE" for AIX OS, if
// specified.
- if (object::Archive::getDefaultKindForHost() == object::Archive::K_AIXBIG) {
+ if (object::Archive::getDefaultKind() == object::Archive::K_AIXBIG) {
BitMode = getBitMode(getenv("OBJECT_MODE"));
if (BitMode == BitModeTy::Unknown)
BitMode = BitModeTy::Bit32;
@@ -1397,8 +1397,7 @@ static int ar_main(int argc, char **argv) {
continue;
if (strncmp(*ArgIt, "-X", 2) == 0) {
- if (object::Archive::getDefaultKindForHost() ==
- object::Archive::K_AIXBIG) {
+ if (object::Archive::getDefaultKind() == object::Archive::K_AIXBIG) {
Match = *(*ArgIt + 2) != '\0' ? *ArgIt + 2 : *(++ArgIt);
BitMode = getBitMode(Match);
if (BitMode == BitModeTy::Unknown)
@@ -1437,8 +1436,7 @@ static int ranlib_main(int argc, char **argv) {
cl::PrintVersionMessage();
return 0;
} else if (arg.front() == 'X') {
- if (object::Archive::getDefaultKindForHost() ==
- object::Archive::K_AIXBIG) {
+ if (object::Archive::getDefaultKind() == object::Archive::K_AIXBIG) {
HasAIXXOption = true;
arg.consume_front("X");
const char *Xarg = arg.data();
@@ -1469,7 +1467,7 @@ static int ranlib_main(int argc, char **argv) {
}
}
- if (object::Archive::getDefaultKindForHost() == object::Archive::K_AIXBIG) {
+ if (object::Archive::getDefaultKind() == object::Archive::K_AIXBIG) {
// If not specify -X option, get BitMode from enviorment variable
// "OBJECT_MODE" for AIX OS if specify.
if (!HasAIXXOption) {
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the new behaviour makes more sense to me than the old one, thanks, but I think it should be documented both in the release notes and the llvm-ar Command Guide document.
Thanks @cjacek, LGTM once James' comment has been covered. |
I added documentation and rebased, thanks. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. I considered if there was any way of testing this, but the only way I could think of was to have lit know the default target triple (it might well know that already) and then somehow leverage that to convert to a check for the "expected" format for an empty archive. I guess a python script that takes the default triple and inspects the output archive might be possible, but it's may not be worth it. If you want to go down that route, feel free (and I'd be happy to review), but I'm not going to require it.
…for the fallback archive format.
Thanks. I pushed without tests. |
As suggested by @gbreynoo in #82642.