Skip to content
Open
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
2 changes: 2 additions & 0 deletions lld/ELF/Arch/MipsArchTree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,8 @@ uint8_t elf::getMipsFpAbiFlag(Ctx &ctx, InputFile *file, uint8_t oldFlag,
template <class ELFT> static bool isN32Abi(const InputFile &f) {
if (auto *ef = dyn_cast<ELFFileBase>(&f))
return ef->template getObj<ELFT>().getHeader().e_flags & EF_MIPS_ABI2;
if (auto *bc = dyn_cast<BitcodeFile>(&f))
return bc->triple.isABIN32();
return false;
}

Expand Down
16 changes: 9 additions & 7 deletions lld/ELF/InputFiles.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1637,9 +1637,10 @@ template <class ELFT> void SharedFile::parse() {
}

static ELFKind getBitcodeELFKind(const Triple &t) {
if (t.isLittleEndian())
return t.isArch64Bit() ? ELF64LEKind : ELF32LEKind;
return t.isArch64Bit() ? ELF64BEKind : ELF32BEKind;
if (t.isArch64Bit() && !t.isABIN32() && !t.isX32() &&
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add a test to cover every condition here? lld/ELF has very rigid test coverage requirement to ensure refactoring would not regress.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would you mind pointing me in the right direction for how the test should be done? I'm not as familiar with LLD's testing infrastructure as LLVM's.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The tests are in lld/test/ELF. Many LTO tests are in lld/test/ELF/lto. Run them with ninja check-lld-elf.

lld/test/ELF/lto/aarch64.ll may be useful.

t.getEnvironment() != Triple::GNUILP32)
return t.isLittleEndian() ? ELF64LEKind : ELF64BEKind;
return t.isLittleEndian() ? ELF32LEKind : ELF32BEKind;
}

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

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

Triple t(obj->getTargetTriple());
ekind = getBitcodeELFKind(t);
emachine = getBitcodeMachineKind(ctx, mb.getBufferIdentifier(), t);
osabi = getOsAbi(t);
this->triple = Triple(obj->getTargetTriple());

ekind = getBitcodeELFKind(this->triple);
emachine = getBitcodeMachineKind(ctx, mb.getBufferIdentifier(), this->triple);
osabi = getOsAbi(this->triple);
}

static uint8_t mapVisibility(GlobalValue::VisibilityTypes gvVisibility) {
Expand Down
3 changes: 3 additions & 0 deletions lld/ELF/InputFiles.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include "llvm/Object/ELF.h"
#include "llvm/Support/MemoryBufferRef.h"
#include "llvm/Support/Threading.h"
#include "llvm/TargetParser/Triple.h"

namespace llvm {
struct DILineInfo;
Expand Down Expand Up @@ -337,6 +338,8 @@ class BitcodeFile : public InputFile {
void postParse();
std::unique_ptr<llvm::lto::InputFile> obj;
std::vector<bool> keptComdats;

llvm::Triple triple;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of adding a Triple and an llvm/TargetParser include to this header file, you can compute and cache the getBitcodeELFKind value instead.

};

// .so file.
Expand Down