Skip to content

Commit 066b9c8

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 a0ef12c commit 066b9c8

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
@@ -365,6 +365,8 @@ uint8_t elf::getMipsFpAbiFlag(Ctx &ctx, uint8_t oldFlag, uint8_t newFlag,
365365
template <class ELFT> static bool isN32Abi(const InputFile &f) {
366366
if (auto *ef = dyn_cast<ELFFileBase>(&f))
367367
return ef->template getObj<ELFT>().getHeader().e_flags & EF_MIPS_ABI2;
368+
if (auto *bc = dyn_cast<BitcodeFile>(&f))
369+
return bc->triple.isABIN32();
368370
return false;
369371
}
370372

lld/ELF/InputFiles.cpp

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

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

16461647
static uint16_t getBitcodeMachineKind(Ctx &ctx, StringRef path,
@@ -1734,10 +1735,11 @@ BitcodeFile::BitcodeFile(Ctx &ctx, MemoryBufferRef mb, StringRef archiveName,
17341735

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

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

17431745
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)