Skip to content

Commit 59c50cf

Browse files
committed
[lld] Fix ILP32 ABI checks for bitcode files.
Previously, using LTO with the MIPS N32 ABI and (e.g.) -m elf32btsmipn32 would fail because isN32Abi() made no effort to check whether a bitcode file is using the N32 ABI. Additionally, getBitcodeELFKind() would incorrectly pick 64-bit ELF for all ILP32 ABIs (not just N32).
1 parent d681e10 commit 59c50cf

File tree

3 files changed

+14
-7
lines changed

3 files changed

+14
-7
lines changed

lld/ELF/Arch/MipsArchTree.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -363,6 +363,8 @@ uint8_t elf::getMipsFpAbiFlag(Ctx &ctx, InputFile *file, uint8_t oldFlag,
363363
template <class ELFT> static bool isN32Abi(const InputFile &f) {
364364
if (auto *ef = dyn_cast<ELFFileBase>(&f))
365365
return ef->template getObj<ELFT>().getHeader().e_flags & EF_MIPS_ABI2;
366+
if (auto *bc = dyn_cast<BitcodeFile>(&f))
367+
return bc->triple.isABIN32();
366368
return false;
367369
}
368370

lld/ELF/InputFiles.cpp

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1637,9 +1637,10 @@ template <class ELFT> void SharedFile::parse() {
16371637
}
16381638

16391639
static ELFKind getBitcodeELFKind(const Triple &t) {
1640-
if (t.isLittleEndian())
1641-
return t.isArch64Bit() ? ELF64LEKind : ELF32LEKind;
1642-
return t.isArch64Bit() ? ELF64BEKind : ELF32BEKind;
1640+
if (t.isArch64Bit() && !t.isABIN32() && !t.isX32() &&
1641+
t.getEnvironment() != Triple::GNUILP32)
1642+
return t.isLittleEndian() ? ELF64LEKind : ELF64BEKind;
1643+
return t.isLittleEndian() ? ELF32LEKind : ELF32BEKind;
16431644
}
16441645

16451646
static uint16_t getBitcodeMachineKind(Ctx &ctx, StringRef path,
@@ -1733,10 +1734,11 @@ BitcodeFile::BitcodeFile(Ctx &ctx, MemoryBufferRef mb, StringRef archiveName,
17331734

17341735
obj = CHECK2(lto::InputFile::create(mbref), this);
17351736

1736-
Triple t(obj->getTargetTriple());
1737-
ekind = getBitcodeELFKind(t);
1738-
emachine = getBitcodeMachineKind(ctx, mb.getBufferIdentifier(), t);
1739-
osabi = getOsAbi(t);
1737+
this->triple = Triple(obj->getTargetTriple());
1738+
1739+
ekind = getBitcodeELFKind(this->triple);
1740+
emachine = getBitcodeMachineKind(ctx, mb.getBufferIdentifier(), this->triple);
1741+
osabi = getOsAbi(this->triple);
17401742
}
17411743

17421744
static uint8_t mapVisibility(GlobalValue::VisibilityTypes gvVisibility) {

lld/ELF/InputFiles.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include "llvm/Object/ELF.h"
2020
#include "llvm/Support/MemoryBufferRef.h"
2121
#include "llvm/Support/Threading.h"
22+
#include "llvm/TargetParser/Triple.h"
2223

2324
namespace llvm {
2425
struct DILineInfo;
@@ -337,6 +338,8 @@ class BitcodeFile : public InputFile {
337338
void postParse();
338339
std::unique_ptr<llvm::lto::InputFile> obj;
339340
std::vector<bool> keptComdats;
341+
342+
llvm::Triple triple;
340343
};
341344

342345
// .so file.

0 commit comments

Comments
 (0)