Skip to content

Commit 13fd4bf

Browse files
authored
[llvm-ar][Archive] Use getDefaultTargetTriple instead of host triple for the fallback archive format. (#82888)
1 parent f44c3fa commit 13fd4bf

File tree

7 files changed

+19
-16
lines changed

7 files changed

+19
-16
lines changed

clang/tools/clang-offload-packager/ClangOffloadPackager.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ static Error unbundleImages() {
197197

198198
if (Error E = writeArchive(
199199
Args["file"], Members, SymtabWritingMode::NormalSymtab,
200-
Archive::getDefaultKindForHost(), true, false, nullptr))
200+
Archive::getDefaultKind(), true, false, nullptr))
201201
return E;
202202
} else if (Args.count("file")) {
203203
if (Extracted.size() > 1)

llvm/docs/CommandGuide/llvm-ar.rst

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -262,8 +262,9 @@ Other
262262
.. option:: --format=<type>
263263

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

268269
.. option:: -h, --help
269270

llvm/docs/ReleaseNotes.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,10 @@ Changes to the LLVM tools
143143
files using reference types and GC are also supported (but also only for
144144
functions, globals, and data, and only for listing symbols and names).
145145

146+
* llvm-ar now utilizes LLVM_DEFAULT_TARGET_TRIPLE to determine the archive format
147+
if it's not specified with the ``--format`` argument and cannot be inferred from
148+
input files.
149+
146150
Changes to LLDB
147151
---------------------------------
148152

llvm/include/llvm/Object/Archive.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,7 @@ class Archive : public Binary {
338338

339339
Kind kind() const { return (Kind)Format; }
340340
bool isThin() const { return IsThin; }
341-
static object::Archive::Kind getDefaultKindForHost();
341+
static object::Archive::Kind getDefaultKind();
342342

343343
child_iterator child_begin(Error &Err, bool SkipInternal = true) const;
344344
child_iterator child_end() const;

llvm/lib/Object/Archive.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -969,8 +969,8 @@ Archive::Archive(MemoryBufferRef Source, Error &Err)
969969
Err = Error::success();
970970
}
971971

972-
object::Archive::Kind Archive::getDefaultKindForHost() {
973-
Triple HostTriple(sys::getProcessTriple());
972+
object::Archive::Kind Archive::getDefaultKind() {
973+
Triple HostTriple(sys::getDefaultTargetTriple());
974974
return HostTriple.isOSDarwin()
975975
? object::Archive::K_DARWIN
976976
: (HostTriple.isOSAIX() ? object::Archive::K_AIXBIG

llvm/lib/Object/ArchiveWriter.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ object::Archive::Kind NewArchiveMember::detectKindFromObject() const {
9090
}
9191
}
9292

93-
return object::Archive::getDefaultKindForHost();
93+
return object::Archive::getDefaultKind();
9494
}
9595

9696
Expected<NewArchiveMember>

llvm/tools/llvm-ar/llvm-ar.cpp

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -670,7 +670,7 @@ Expected<std::unique_ptr<Binary>> getAsBinary(const Archive::Child &C,
670670
}
671671

672672
template <class A> static bool isValidInBitMode(const A &Member) {
673-
if (object::Archive::getDefaultKindForHost() != object::Archive::K_AIXBIG)
673+
if (object::Archive::getDefaultKind() != object::Archive::K_AIXBIG)
674674
return true;
675675
LLVMContext Context;
676676
Expected<std::unique_ptr<Binary>> BinOrErr = getAsBinary(Member, &Context);
@@ -1036,10 +1036,10 @@ static void performWriteOperation(ArchiveOperation Operation,
10361036
}
10371037
} else if (NewMembersP)
10381038
Kind = !NewMembersP->empty() ? NewMembersP->front().detectKindFromObject()
1039-
: object::Archive::getDefaultKindForHost();
1039+
: object::Archive::getDefaultKind();
10401040
else
10411041
Kind = !NewMembers.empty() ? NewMembers.front().detectKindFromObject()
1042-
: object::Archive::getDefaultKindForHost();
1042+
: object::Archive::getDefaultKind();
10431043
break;
10441044
case GNU:
10451045
Kind = object::Archive::K_GNU;
@@ -1331,7 +1331,7 @@ static int ar_main(int argc, char **argv) {
13311331

13321332
// Get BitMode from enviorment variable "OBJECT_MODE" for AIX OS, if
13331333
// specified.
1334-
if (object::Archive::getDefaultKindForHost() == object::Archive::K_AIXBIG) {
1334+
if (object::Archive::getDefaultKind() == object::Archive::K_AIXBIG) {
13351335
BitMode = getBitMode(getenv("OBJECT_MODE"));
13361336
if (BitMode == BitModeTy::Unknown)
13371337
BitMode = BitModeTy::Bit32;
@@ -1392,8 +1392,7 @@ static int ar_main(int argc, char **argv) {
13921392
continue;
13931393

13941394
if (strncmp(*ArgIt, "-X", 2) == 0) {
1395-
if (object::Archive::getDefaultKindForHost() ==
1396-
object::Archive::K_AIXBIG) {
1395+
if (object::Archive::getDefaultKind() == object::Archive::K_AIXBIG) {
13971396
Match = *(*ArgIt + 2) != '\0' ? *ArgIt + 2 : *(++ArgIt);
13981397
BitMode = getBitMode(Match);
13991398
if (BitMode == BitModeTy::Unknown)
@@ -1432,8 +1431,7 @@ static int ranlib_main(int argc, char **argv) {
14321431
cl::PrintVersionMessage();
14331432
return 0;
14341433
} else if (arg.front() == 'X') {
1435-
if (object::Archive::getDefaultKindForHost() ==
1436-
object::Archive::K_AIXBIG) {
1434+
if (object::Archive::getDefaultKind() == object::Archive::K_AIXBIG) {
14371435
HasAIXXOption = true;
14381436
arg.consume_front("X");
14391437
const char *Xarg = arg.data();
@@ -1464,7 +1462,7 @@ static int ranlib_main(int argc, char **argv) {
14641462
}
14651463
}
14661464

1467-
if (object::Archive::getDefaultKindForHost() == object::Archive::K_AIXBIG) {
1465+
if (object::Archive::getDefaultKind() == object::Archive::K_AIXBIG) {
14681466
// If not specify -X option, get BitMode from enviorment variable
14691467
// "OBJECT_MODE" for AIX OS if specify.
14701468
if (!HasAIXXOption) {

0 commit comments

Comments
 (0)