Skip to content

Commit 711eccb

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 c95daac commit 711eccb

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
@@ -1636,9 +1636,10 @@ template <class ELFT> void SharedFile::parse() {
16361636
}
16371637

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

16441645
static uint16_t getBitcodeMachineKind(Ctx &ctx, StringRef path,
@@ -1731,10 +1732,11 @@ BitcodeFile::BitcodeFile(Ctx &ctx, MemoryBufferRef mb, StringRef archiveName,
17311732

17321733
obj = CHECK(lto::InputFile::create(mbref), this);
17331734

1734-
Triple t(obj->getTargetTriple());
1735-
ekind = getBitcodeELFKind(t);
1736-
emachine = getBitcodeMachineKind(ctx, mb.getBufferIdentifier(), t);
1737-
osabi = getOsAbi(t);
1735+
this->triple = Triple(obj->getTargetTriple());
1736+
1737+
ekind = getBitcodeELFKind(this->triple);
1738+
emachine = getBitcodeMachineKind(ctx, mb.getBufferIdentifier(), this->triple);
1739+
osabi = getOsAbi(this->triple);
17381740
}
17391741

17401742
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;
@@ -335,6 +336,8 @@ class BitcodeFile : public InputFile {
335336
void postParse();
336337
std::unique_ptr<llvm::lto::InputFile> obj;
337338
std::vector<bool> keptComdats;
339+
340+
llvm::Triple triple;
338341
};
339342

340343
// .so file.

0 commit comments

Comments
 (0)