Skip to content

[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

Merged
merged 1 commit into from
Feb 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
5 changes: 3 additions & 2 deletions llvm/docs/CommandGuide/llvm-ar.rst
Original file line number Diff line number Diff line change
Expand Up @@ -262,8 +262,9 @@ Other
.. option:: --format=<type>

This option allows for default, gnu, darwin or bsd ``<type>`` to be selected.
When creating an ``archive``, ``<type>`` will default to that of the host
machine.
When creating an ``archive`` with the default ``<type>``, :program:``llvm-ar``
will attempt to infer it from the input files and fallback to the default
toolchain target if unable to do so.

.. option:: -h, --help

Expand Down
4 changes: 4 additions & 0 deletions llvm/docs/ReleaseNotes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,10 @@ Changes to the LLVM tools
files using reference types and GC are also supported (but also only for
functions, globals, and data, and only for listing symbols and names).

* llvm-ar now utilizes LLVM_DEFAULT_TARGET_TRIPLE to determine the archive format
if it's not specified with the ``--format`` argument and cannot be inferred from
input files.

Changes to LLDB
---------------------------------

Expand Down
2 changes: 1 addition & 1 deletion llvm/include/llvm/Object/Archive.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();

child_iterator child_begin(Error &Err, bool SkipInternal = true) const;
child_iterator child_end() const;
Expand Down
4 changes: 2 additions & 2 deletions llvm/lib/Object/Archive.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -969,8 +969,8 @@ Archive::Archive(MemoryBufferRef Source, Error &Err)
Err = Error::success();
}

object::Archive::Kind Archive::getDefaultKindForHost() {
Triple HostTriple(sys::getProcessTriple());
object::Archive::Kind Archive::getDefaultKind() {
Triple HostTriple(sys::getDefaultTargetTriple());
return HostTriple.isOSDarwin()
? object::Archive::K_DARWIN
: (HostTriple.isOSAIX() ? object::Archive::K_AIXBIG
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/Object/ArchiveWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ object::Archive::Kind NewArchiveMember::detectKindFromObject() const {
}
}

return object::Archive::getDefaultKindForHost();
return object::Archive::getDefaultKind();
}

Expected<NewArchiveMember>
Expand Down
16 changes: 7 additions & 9 deletions llvm/tools/llvm-ar/llvm-ar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -670,7 +670,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);
Expand Down Expand Up @@ -1036,10 +1036,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;
Expand Down Expand Up @@ -1331,7 +1331,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;
Expand Down Expand Up @@ -1392,8 +1392,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)
Expand Down Expand Up @@ -1432,8 +1431,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();
Expand Down Expand Up @@ -1464,7 +1462,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) {
Expand Down